Java Code Examples for com.google.android.exoplayer2.upstream.DataSpec#FLAG_ALLOW_GZIP

The following examples show how to use com.google.android.exoplayer2.upstream.DataSpec#FLAG_ALLOW_GZIP . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HlsChunkSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Nullable
private Chunk maybeCreateEncryptionChunkFor(@Nullable Uri keyUri, int selectedTrackIndex) {
  if (keyUri == null) {
    return null;
  }

  byte[] encryptionKey = keyCache.remove(keyUri);
  if (encryptionKey != null) {
    // The key was present in the key cache. We re-insert it to prevent it from being evicted by
    // the following key addition. Note that removal of the key is necessary to affect the
    // eviction order.
    keyCache.put(keyUri, encryptionKey);
    return null;
  }
  DataSpec dataSpec = new DataSpec(keyUri, 0, C.LENGTH_UNSET, null, DataSpec.FLAG_ALLOW_GZIP);
  return new EncryptionKeyChunk(
      encryptionDataSource,
      dataSpec,
      playlistFormats[selectedTrackIndex],
      trackSelection.getSelectionReason(),
      trackSelection.getSelectionData(),
      scratchSpace);
}
 
Example 2
Source File: SingleSampleMediaSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private SingleSampleMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    Format format,
    long durationUs,
    LoadErrorHandlingPolicy loadErrorHandlingPolicy,
    boolean treatLoadErrorsAsEndOfStream,
    @Nullable Object tag) {
  this.dataSourceFactory = dataSourceFactory;
  this.format = format;
  this.durationUs = durationUs;
  this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
  this.treatLoadErrorsAsEndOfStream = treatLoadErrorsAsEndOfStream;
  this.tag = tag;
  dataSpec = new DataSpec(uri, DataSpec.FLAG_ALLOW_GZIP);
  timeline =
      new SinglePeriodTimeline(durationUs, /* isSeekable= */ true, /* isDynamic= */ false, tag);
}
 
Example 3
Source File: HlsChunkSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Nullable
private Chunk maybeCreateEncryptionChunkFor(@Nullable Uri keyUri, int selectedTrackIndex) {
  if (keyUri == null) {
    return null;
  }
  if (keyCache.containsKey(keyUri)) {
    // The key is present in the key cache. We re-insert it to prevent it from being evicted by
    // the following key addition. Note that removal of the key is necessary to affect the
    // eviction order.
    keyCache.put(keyUri, keyCache.remove(keyUri));
    return null;
  }
  DataSpec dataSpec = new DataSpec(keyUri, 0, C.LENGTH_UNSET, null, DataSpec.FLAG_ALLOW_GZIP);
  return new EncryptionKeyChunk(
      encryptionDataSource,
      dataSpec,
      playlistFormats[selectedTrackIndex],
      trackSelection.getSelectionReason(),
      trackSelection.getSelectionData(),
      scratchSpace);
}
 
Example 4
Source File: SingleSampleMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private SingleSampleMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    Format format,
    long durationUs,
    LoadErrorHandlingPolicy loadErrorHandlingPolicy,
    boolean treatLoadErrorsAsEndOfStream,
    @Nullable Object tag) {
  this.dataSourceFactory = dataSourceFactory;
  this.format = format;
  this.durationUs = durationUs;
  this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
  this.treatLoadErrorsAsEndOfStream = treatLoadErrorsAsEndOfStream;
  this.tag = tag;
  dataSpec = new DataSpec(uri, DataSpec.FLAG_ALLOW_GZIP);
  timeline =
      new SinglePeriodTimeline(durationUs, /* isSeekable= */ true, /* isDynamic= */ false, tag);
}
 
Example 5
Source File: HlsChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Nullable
private Chunk maybeCreateEncryptionChunkFor(@Nullable Uri keyUri, int selectedTrackIndex) {
  if (keyUri == null) {
    return null;
  }
  if (keyCache.containsKey(keyUri)) {
    // The key is present in the key cache. We re-insert it to prevent it from being evicted by
    // the following key addition. Note that removal of the key is necessary to affect the
    // eviction order.
    keyCache.put(keyUri, keyCache.remove(keyUri));
    return null;
  }
  DataSpec dataSpec = new DataSpec(keyUri, 0, C.LENGTH_UNSET, null, DataSpec.FLAG_ALLOW_GZIP);
  return new EncryptionKeyChunk(
      encryptionDataSource,
      dataSpec,
      playlistFormats[selectedTrackIndex],
      trackSelection.getSelectionReason(),
      trackSelection.getSelectionData(),
      scratchSpace);
}
 
Example 6
Source File: HttpMediaDrmCallback.java    From K-Sonic with MIT License 6 votes vote down vote up
private static byte[] executePost(HttpDataSource.Factory dataSourceFactory, String url,
    byte[] data, Map<String, String> requestProperties) throws IOException {
  HttpDataSource dataSource = dataSourceFactory.createDataSource();
  if (requestProperties != null) {
    for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
      dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
    }
  }
  DataSpec dataSpec = new DataSpec(Uri.parse(url), data, 0, 0, C.LENGTH_UNSET, null,
      DataSpec.FLAG_ALLOW_GZIP);
  DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
  try {
    return Util.toByteArray(inputStream);
  } finally {
    Util.closeQuietly(inputStream);
  }
}
 
Example 7
Source File: CustomDrmCallback.java    From ExoPlayer-Offline with Apache License 2.0 6 votes vote down vote up
private byte[] executePost(String url, byte[] data, Map<String, String> requestProperties)
        throws IOException {
    HttpDataSource dataSource = dataSourceFactory.createDataSource();
    if (requestProperties != null) {
        for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
            dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
        }
    }
    DataSpec dataSpec = new DataSpec(Uri.parse(url), data, 0, 0, C.LENGTH_UNSET, null,
            DataSpec.FLAG_ALLOW_GZIP);
    DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
    try {
        return Util.toByteArray(inputStream);
    } finally {
        Util.closeQuietly(inputStream);
    }
}
 
Example 8
Source File: SingleSampleMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private SingleSampleMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    Format format,
    long durationUs,
    LoadErrorHandlingPolicy loadErrorHandlingPolicy,
    boolean treatLoadErrorsAsEndOfStream,
    @Nullable Object tag) {
  this.dataSourceFactory = dataSourceFactory;
  this.format = format;
  this.durationUs = durationUs;
  this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
  this.treatLoadErrorsAsEndOfStream = treatLoadErrorsAsEndOfStream;
  this.tag = tag;
  dataSpec = new DataSpec(uri, DataSpec.FLAG_ALLOW_GZIP);
  timeline =
      new SinglePeriodTimeline(
          durationUs,
          /* isSeekable= */ true,
          /* isDynamic= */ false,
          /* isLive= */ false,
          /* manifest= */ null,
          tag);
}
 
Example 9
Source File: HttpMediaDrmCallback.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static byte[] executePost(HttpDataSource.Factory dataSourceFactory, String url,
    byte[] data, Map<String, String> requestProperties) throws IOException {
  HttpDataSource dataSource = dataSourceFactory.createDataSource();
  if (requestProperties != null) {
    for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
      dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
    }
  }

  int manualRedirectCount = 0;
  while (true) {
    DataSpec dataSpec =
        new DataSpec(
            Uri.parse(url),
            data,
            /* absoluteStreamPosition= */ 0,
            /* position= */ 0,
            /* length= */ C.LENGTH_UNSET,
            /* key= */ null,
            DataSpec.FLAG_ALLOW_GZIP);
    DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
    try {
      return Util.toByteArray(inputStream);
    } catch (InvalidResponseCodeException e) {
      // For POST requests, the underlying network stack will not normally follow 307 or 308
      // redirects automatically. Do so manually here.
      boolean manuallyRedirect =
          (e.responseCode == 307 || e.responseCode == 308)
              && manualRedirectCount++ < MAX_MANUAL_REDIRECTS;
      url = manuallyRedirect ? getRedirectUrl(e) : null;
      if (url == null) {
        throw e;
      }
    } finally {
      Util.closeQuietly(inputStream);
    }
  }
}
 
Example 10
Source File: HttpMediaDrmCallback.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static byte[] executePost(HttpDataSource.Factory dataSourceFactory, String url,
    byte[] data, Map<String, String> requestProperties) throws IOException {
  HttpDataSource dataSource = dataSourceFactory.createDataSource();
  if (requestProperties != null) {
    for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
      dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
    }
  }

  int manualRedirectCount = 0;
  while (true) {
    DataSpec dataSpec =
        new DataSpec(
            Uri.parse(url),
            data,
            /* absoluteStreamPosition= */ 0,
            /* position= */ 0,
            /* length= */ C.LENGTH_UNSET,
            /* key= */ null,
            DataSpec.FLAG_ALLOW_GZIP);
    DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
    try {
      return Util.toByteArray(inputStream);
    } catch (InvalidResponseCodeException e) {
      // For POST requests, the underlying network stack will not normally follow 307 or 308
      // redirects automatically. Do so manually here.
      boolean manuallyRedirect =
          (e.responseCode == 307 || e.responseCode == 308)
              && manualRedirectCount++ < MAX_MANUAL_REDIRECTS;
      url = manuallyRedirect ? getRedirectUrl(e) : null;
      if (url == null) {
        throw e;
      }
    } finally {
      Util.closeQuietly(inputStream);
    }
  }
}
 
Example 11
Source File: SegmentDownloader.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
protected static DataSpec getCompressibleDataSpec(Uri uri) {
  return new DataSpec(
      uri,
      /* absoluteStreamPosition= */ 0,
      /* length= */ C.LENGTH_UNSET,
      /* key= */ null,
      /* flags= */ DataSpec.FLAG_ALLOW_GZIP);
}
 
Example 12
Source File: SegmentDownloader.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
protected static DataSpec getCompressibleDataSpec(Uri uri) {
  return new DataSpec(
      uri,
      /* absoluteStreamPosition= */ 0,
      /* length= */ C.LENGTH_UNSET,
      /* key= */ null,
      /* flags= */ DataSpec.FLAG_ALLOW_GZIP);
}
 
Example 13
Source File: SegmentDownloader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
protected static DataSpec getCompressibleDataSpec(Uri uri) {
  return new DataSpec(
      uri,
      /* absoluteStreamPosition= */ 0,
      /* length= */ C.LENGTH_UNSET,
      /* key= */ null,
      /* flags= */ DataSpec.FLAG_ALLOW_GZIP);
}
 
Example 14
Source File: HlsChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private EncryptionKeyChunk newEncryptionKeyChunk(Uri keyUri, String iv, int variantIndex,
    int trackSelectionReason, Object trackSelectionData) {
  DataSpec dataSpec = new DataSpec(keyUri, 0, C.LENGTH_UNSET, null, DataSpec.FLAG_ALLOW_GZIP);
  return new EncryptionKeyChunk(encryptionDataSource, dataSpec, variants[variantIndex].format,
      trackSelectionReason, trackSelectionData, scratchSpace, iv);
}
 
Example 15
Source File: HlsChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private EncryptionKeyChunk newEncryptionKeyChunk(Uri keyUri, String iv, int variantIndex,
    int trackSelectionReason, Object trackSelectionData) {
  DataSpec dataSpec = new DataSpec(keyUri, 0, C.LENGTH_UNSET, null, DataSpec.FLAG_ALLOW_GZIP);
  return new EncryptionKeyChunk(encryptionDataSource, dataSpec, variants[variantIndex].format,
      trackSelectionReason, trackSelectionData, scratchSpace, iv);
}
 
Example 16
Source File: HlsChunkSource.java    From K-Sonic with MIT License 4 votes vote down vote up
private EncryptionKeyChunk newEncryptionKeyChunk(Uri keyUri, String iv, int variantIndex,
    int trackSelectionReason, Object trackSelectionData) {
  DataSpec dataSpec = new DataSpec(keyUri, 0, C.LENGTH_UNSET, null, DataSpec.FLAG_ALLOW_GZIP);
  return new EncryptionKeyChunk(encryptionDataSource, dataSpec, variants[variantIndex].format,
      trackSelectionReason, trackSelectionData, scratchSpace, iv);
}
 
Example 17
Source File: HttpMediaDrmCallback.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private static byte[] executePost(
    HttpDataSource.Factory dataSourceFactory,
    String url,
    byte[] data,
    @Nullable Map<String, String> requestProperties)
    throws IOException {
  HttpDataSource dataSource = dataSourceFactory.createDataSource();
  if (requestProperties != null) {
    for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
      dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
    }
  }

  int manualRedirectCount = 0;
  while (true) {
    DataSpec dataSpec =
        new DataSpec(
            Uri.parse(url),
            data,
            /* absoluteStreamPosition= */ 0,
            /* position= */ 0,
            /* length= */ C.LENGTH_UNSET,
            /* key= */ null,
            DataSpec.FLAG_ALLOW_GZIP);
    DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
    try {
      return Util.toByteArray(inputStream);
    } catch (InvalidResponseCodeException e) {
      // For POST requests, the underlying network stack will not normally follow 307 or 308
      // redirects automatically. Do so manually here.
      boolean manuallyRedirect =
          (e.responseCode == 307 || e.responseCode == 308)
              && manualRedirectCount++ < MAX_MANUAL_REDIRECTS;
      String redirectUrl = manuallyRedirect ? getRedirectUrl(e) : null;
      if (redirectUrl == null) {
        throw e;
      }
      url = redirectUrl;
    } finally {
      Util.closeQuietly(inputStream);
    }
  }
}
 
Example 18
Source File: HttpMediaDrmCallback.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private static byte[] executePost(
    HttpDataSource.Factory dataSourceFactory,
    String url,
    byte[] data,
    @Nullable Map<String, String> requestProperties)
    throws IOException {
  HttpDataSource dataSource = dataSourceFactory.createDataSource();
  if (requestProperties != null) {
    for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
      dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
    }
  }

  int manualRedirectCount = 0;
  while (true) {
    DataSpec dataSpec =
        new DataSpec(
            Uri.parse(url),
            data,
            /* absoluteStreamPosition= */ 0,
            /* position= */ 0,
            /* length= */ C.LENGTH_UNSET,
            /* key= */ null,
            DataSpec.FLAG_ALLOW_GZIP);
    DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
    try {
      return Util.toByteArray(inputStream);
    } catch (InvalidResponseCodeException e) {
      // For POST requests, the underlying network stack will not normally follow 307 or 308
      // redirects automatically. Do so manually here.
      boolean manuallyRedirect =
          (e.responseCode == 307 || e.responseCode == 308)
              && manualRedirectCount++ < MAX_MANUAL_REDIRECTS;
      String redirectUrl = manuallyRedirect ? getRedirectUrl(e) : null;
      if (redirectUrl == null) {
        throw e;
      }
      url = redirectUrl;
    } finally {
      Util.closeQuietly(inputStream);
    }
  }
}
 
Example 19
Source File: HttpMediaDrmCallback.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private static byte[] executePost(
    HttpDataSource.Factory dataSourceFactory,
    String url,
    @Nullable byte[] httpBody,
    @Nullable Map<String, String> requestProperties)
    throws IOException {
  HttpDataSource dataSource = dataSourceFactory.createDataSource();
  if (requestProperties != null) {
    for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
      dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
    }
  }

  int manualRedirectCount = 0;
  while (true) {
    DataSpec dataSpec =
        new DataSpec(
            Uri.parse(url),
            DataSpec.HTTP_METHOD_POST,
            httpBody,
            /* absoluteStreamPosition= */ 0,
            /* position= */ 0,
            /* length= */ C.LENGTH_UNSET,
            /* key= */ null,
            DataSpec.FLAG_ALLOW_GZIP);
    DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
    try {
      return Util.toByteArray(inputStream);
    } catch (InvalidResponseCodeException e) {
      // For POST requests, the underlying network stack will not normally follow 307 or 308
      // redirects automatically. Do so manually here.
      boolean manuallyRedirect =
          (e.responseCode == 307 || e.responseCode == 308)
              && manualRedirectCount++ < MAX_MANUAL_REDIRECTS;
      String redirectUrl = manuallyRedirect ? getRedirectUrl(e) : null;
      if (redirectUrl == null) {
        throw e;
      }
      url = redirectUrl;
    } finally {
      Util.closeQuietly(inputStream);
    }
  }
}