com.google.android.exoplayer2.source.chunk.Chunk Java Examples

The following examples show how to use com.google.android.exoplayer2.source.chunk.Chunk. 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: DefaultDashChunkSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
protected Chunk newInitializationChunk(
    RepresentationHolder representationHolder,
    DataSource dataSource,
    Format trackFormat,
    int trackSelectionReason,
    Object trackSelectionData,
    RangedUri initializationUri,
    RangedUri indexUri) {
  RangedUri requestUri;
  String baseUrl = representationHolder.representation.baseUrl;
  if (initializationUri != null) {
    // It's common for initialization and index data to be stored adjacently. Attempt to merge
    // the two requests together to request both at once.
    requestUri = initializationUri.attemptMerge(indexUri, baseUrl);
    if (requestUri == null) {
      requestUri = initializationUri;
    }
  } else {
    requestUri = indexUri;
  }
  DataSpec dataSpec = new DataSpec(requestUri.resolveUri(baseUrl), requestUri.start,
      requestUri.length, representationHolder.representation.getCacheKey());
  return new InitializationChunk(dataSource, dataSpec, trackFormat,
      trackSelectionReason, trackSelectionData, representationHolder.extractorWrapper);
}
 
Example #2
Source File: DefaultDashChunkSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public void onChunkLoadCompleted(Chunk chunk) {
  if (chunk instanceof InitializationChunk) {
    InitializationChunk initializationChunk = (InitializationChunk) chunk;
    int trackIndex = trackSelection.indexOf(initializationChunk.trackFormat);
    RepresentationHolder representationHolder = representationHolders[trackIndex];
    // The null check avoids overwriting an index obtained from the manifest with one obtained
    // from the stream. If the manifest defines an index then the stream shouldn't, but in cases
    // where it does we should ignore it.
    if (representationHolder.segmentIndex == null) {
      SeekMap seekMap = representationHolder.extractorWrapper.getSeekMap();
      if (seekMap != null) {
        representationHolders[trackIndex] =
            representationHolder.copyWithNewSegmentIndex(
                new DashWrappingSegmentIndex(
                    (ChunkIndex) seekMap,
                    representationHolder.representation.presentationTimeOffsetUs));
      }
    }
  }
  if (playerTrackEmsgHandler != null) {
    playerTrackEmsgHandler.onChunkLoadCompleted(chunk);
  }
}
 
Example #3
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 #4
Source File: DefaultDashChunkSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
protected Chunk newInitializationChunk(
    RepresentationHolder representationHolder,
    DataSource dataSource,
    Format trackFormat,
    int trackSelectionReason,
    Object trackSelectionData,
    RangedUri initializationUri,
    RangedUri indexUri) {
  RangedUri requestUri;
  String baseUrl = representationHolder.representation.baseUrl;
  if (initializationUri != null) {
    // It's common for initialization and index data to be stored adjacently. Attempt to merge
    // the two requests together to request both at once.
    requestUri = initializationUri.attemptMerge(indexUri, baseUrl);
    if (requestUri == null) {
      requestUri = initializationUri;
    }
  } else {
    requestUri = indexUri;
  }
  DataSpec dataSpec = new DataSpec(requestUri.resolveUri(baseUrl), requestUri.start,
      requestUri.length, representationHolder.representation.getCacheKey());
  return new InitializationChunk(dataSource, dataSpec, trackFormat,
      trackSelectionReason, trackSelectionData, representationHolder.extractorWrapper);
}
 
Example #5
Source File: HlsSampleStreamWrapper.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onLoadCompleted(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs) {
  chunkSource.onChunkLoadCompleted(loadable);
  eventDispatcher.loadCompleted(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      loadable.type,
      trackType,
      loadable.trackFormat,
      loadable.trackSelectionReason,
      loadable.trackSelectionData,
      loadable.startTimeUs,
      loadable.endTimeUs,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded());
  if (!prepared) {
    continueLoading(lastSeekPositionUs);
  } else {
    callback.onContinueLoadingRequested(this);
  }
}
 
Example #6
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 #7
Source File: HlsSampleStreamWrapper.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public void onLoadCanceled(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs,
    boolean released) {
  eventDispatcher.loadCanceled(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      loadable.type,
      trackType,
      loadable.trackFormat,
      loadable.trackSelectionReason,
      loadable.trackSelectionData,
      loadable.startTimeUs,
      loadable.endTimeUs,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded());
  if (!released) {
    resetSampleQueues();
    if (enabledTrackGroupCount > 0) {
      callback.onContinueLoadingRequested(this);
    }
  }
}
 
Example #8
Source File: HlsSampleStreamWrapper.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public void onLoadCompleted(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs) {
  chunkSource.onChunkLoadCompleted(loadable);
  eventDispatcher.loadCompleted(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      loadable.type,
      trackType,
      loadable.trackFormat,
      loadable.trackSelectionReason,
      loadable.trackSelectionData,
      loadable.startTimeUs,
      loadable.endTimeUs,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded());
  if (!prepared) {
    continueLoading(lastSeekPositionUs);
  } else {
    callback.onContinueLoadingRequested(this);
  }
}
 
Example #9
Source File: DefaultDashChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onChunkLoadCompleted(Chunk chunk) {
  if (chunk instanceof InitializationChunk) {
    InitializationChunk initializationChunk = (InitializationChunk) chunk;
    int trackIndex = trackSelection.indexOf(initializationChunk.trackFormat);
    RepresentationHolder representationHolder = representationHolders[trackIndex];
    // The null check avoids overwriting an index obtained from the manifest with one obtained
    // from the stream. If the manifest defines an index then the stream shouldn't, but in cases
    // where it does we should ignore it.
    if (representationHolder.segmentIndex == null) {
      SeekMap seekMap = representationHolder.extractorWrapper.getSeekMap();
      if (seekMap != null) {
        representationHolders[trackIndex] =
            representationHolder.copyWithNewSegmentIndex(
                new DashWrappingSegmentIndex(
                    (ChunkIndex) seekMap,
                    representationHolder.representation.presentationTimeOffsetUs));
      }
    }
  }
  if (playerTrackEmsgHandler != null) {
    playerTrackEmsgHandler.onChunkLoadCompleted(chunk);
  }
}
 
Example #10
Source File: PlayerEmsgHandler.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * For live streaming with emsg event stream, forward seeking can seek pass the emsg messages that
 * signals end-of-stream or Manifest expiry, which results in load error. In this case, we should
 * notify the Dash media source to refresh its manifest.
 *
 * @param chunk The chunk whose load encountered the error.
 * @return True if manifest refresh has been requested, false otherwise.
 */
/* package */ boolean maybeRefreshManifestOnLoadingError(Chunk chunk) {
  if (!manifest.dynamic) {
    return false;
  }
  if (isWaitingForManifestRefresh) {
    return true;
  }
  boolean isAfterForwardSeek =
      lastLoadedChunkEndTimeUs != C.TIME_UNSET && lastLoadedChunkEndTimeUs < chunk.startTimeUs;
  if (isAfterForwardSeek) {
    // if we are after a forward seek, and the playback is dynamic with embedded emsg stream,
    // there's a chance that we have seek over the emsg messages, in which case we should ask
    // media source for a refresh.
    maybeNotifyDashManifestRefreshNeeded();
    return true;
  }
  return false;
}
 
Example #11
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 #12
Source File: DefaultDashChunkSource.java    From K-Sonic with MIT License 6 votes vote down vote up
private static Chunk newInitializationChunk(RepresentationHolder representationHolder,
    DataSource dataSource, Format trackFormat, int trackSelectionReason,
    Object trackSelectionData, RangedUri initializationUri, RangedUri indexUri) {
  RangedUri requestUri;
  String baseUrl = representationHolder.representation.baseUrl;
  if (initializationUri != null) {
    // It's common for initialization and index data to be stored adjacently. Attempt to merge
    // the two requests together to request both at once.
    requestUri = initializationUri.attemptMerge(indexUri, baseUrl);
    if (requestUri == null) {
      requestUri = initializationUri;
    }
  } else {
    requestUri = indexUri;
  }
  DataSpec dataSpec = new DataSpec(requestUri.resolveUri(baseUrl), requestUri.start,
      requestUri.length, representationHolder.representation.getCacheKey());
  return new InitializationChunk(dataSource, dataSpec, trackFormat,
      trackSelectionReason, trackSelectionData, representationHolder.extractorWrapper);
}
 
Example #13
Source File: DefaultDashChunkSource.java    From K-Sonic with MIT License 6 votes vote down vote up
@Override
public boolean onChunkLoadError(Chunk chunk, boolean cancelable, Exception e) {
  if (!cancelable) {
    return false;
  }
  // Workaround for missing segment at the end of the period
  if (!manifest.dynamic && chunk instanceof MediaChunk
      && e instanceof InvalidResponseCodeException
      && ((InvalidResponseCodeException) e).responseCode == 404) {
    RepresentationHolder representationHolder =
        representationHolders[trackSelection.indexOf(chunk.trackFormat)];
    int segmentCount = representationHolder.getSegmentCount();
    if (segmentCount != DashSegmentIndex.INDEX_UNBOUNDED && segmentCount != 0) {
      int lastAvailableSegmentNum = representationHolder.getFirstSegmentNum() + segmentCount - 1;
      if (((MediaChunk) chunk).getNextChunkIndex() > lastAvailableSegmentNum) {
        missingLastSegment = true;
        return true;
      }
    }
  }
  // Blacklist if appropriate.
  return ChunkedTrackBlacklistUtil.maybeBlacklistTrack(trackSelection,
      trackSelection.indexOf(chunk.trackFormat), e);
}
 
Example #14
Source File: HlsSampleStreamWrapper.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onLoadCanceled(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs,
    boolean released) {
  eventDispatcher.loadCanceled(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      loadable.type,
      trackType,
      loadable.trackFormat,
      loadable.trackSelectionReason,
      loadable.trackSelectionData,
      loadable.startTimeUs,
      loadable.endTimeUs,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded());
  if (!released) {
    resetSampleQueues();
    if (enabledTrackGroupCount > 0) {
      callback.onContinueLoadingRequested(this);
    }
  }
}
 
Example #15
Source File: DefaultDashChunkSource.java    From K-Sonic with MIT License 6 votes vote down vote up
@Override
public void onChunkLoadCompleted(Chunk chunk) {
  if (chunk instanceof InitializationChunk) {
    InitializationChunk initializationChunk = (InitializationChunk) chunk;
    RepresentationHolder representationHolder =
        representationHolders[trackSelection.indexOf(initializationChunk.trackFormat)];
    // The null check avoids overwriting an index obtained from the manifest with one obtained
    // from the stream. If the manifest defines an index then the stream shouldn't, but in cases
    // where it does we should ignore it.
    if (representationHolder.segmentIndex == null) {
      SeekMap seekMap = representationHolder.extractorWrapper.getSeekMap();
      if (seekMap != null) {
        representationHolder.segmentIndex = new DashWrappingSegmentIndex((ChunkIndex) seekMap);
      }
    }
  }
}
 
Example #16
Source File: HlsSampleStreamWrapper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onLoadCompleted(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs) {
  chunkSource.onChunkLoadCompleted(loadable);
  eventDispatcher.loadCompleted(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.type,
      trackType,
      loadable.trackFormat,
      loadable.trackSelectionReason,
      loadable.trackSelectionData,
      loadable.startTimeUs,
      loadable.endTimeUs,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded());
  if (!prepared) {
    continueLoading(lastSeekPositionUs);
  } else {
    callback.onContinueLoadingRequested(this);
  }
}
 
Example #17
Source File: DefaultDashChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
protected Chunk newInitializationChunk(
    RepresentationHolder representationHolder,
    DataSource dataSource,
    Format trackFormat,
    int trackSelectionReason,
    Object trackSelectionData,
    RangedUri initializationUri,
    RangedUri indexUri) {
  RangedUri requestUri;
  String baseUrl = representationHolder.representation.baseUrl;
  if (initializationUri != null) {
    // It's common for initialization and index data to be stored adjacently. Attempt to merge
    // the two requests together to request both at once.
    requestUri = initializationUri.attemptMerge(indexUri, baseUrl);
    if (requestUri == null) {
      requestUri = initializationUri;
    }
  } else {
    requestUri = indexUri;
  }
  DataSpec dataSpec = new DataSpec(requestUri.resolveUri(baseUrl), requestUri.start,
      requestUri.length, representationHolder.representation.getCacheKey());
  return new InitializationChunk(dataSource, dataSpec, trackFormat,
      trackSelectionReason, trackSelectionData, representationHolder.extractorWrapper);
}
 
Example #18
Source File: HlsSampleStreamWrapper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onLoadCanceled(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs,
    boolean released) {
  eventDispatcher.loadCanceled(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.type,
      trackType,
      loadable.trackFormat,
      loadable.trackSelectionReason,
      loadable.trackSelectionData,
      loadable.startTimeUs,
      loadable.endTimeUs,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded());
  if (!released) {
    resetSampleQueues();
    if (enabledTrackGroupCount > 0) {
      callback.onContinueLoadingRequested(this);
    }
  }
}
 
Example #19
Source File: DefaultDashChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onChunkLoadCompleted(Chunk chunk) {
  if (chunk instanceof InitializationChunk) {
    InitializationChunk initializationChunk = (InitializationChunk) chunk;
    int trackIndex = trackSelection.indexOf(initializationChunk.trackFormat);
    RepresentationHolder representationHolder = representationHolders[trackIndex];
    // The null check avoids overwriting an index obtained from the manifest with one obtained
    // from the stream. If the manifest defines an index then the stream shouldn't, but in cases
    // where it does we should ignore it.
    if (representationHolder.segmentIndex == null) {
      SeekMap seekMap = representationHolder.extractorWrapper.getSeekMap();
      if (seekMap != null) {
        representationHolders[trackIndex] =
            representationHolder.copyWithNewSegmentIndex(
                new DashWrappingSegmentIndex(
                    (ChunkIndex) seekMap,
                    representationHolder.representation.presentationTimeOffsetUs));
      }
    }
  }
  if (playerTrackEmsgHandler != null) {
    playerTrackEmsgHandler.onChunkLoadCompleted(chunk);
  }
}
 
Example #20
Source File: HlsSampleStreamWrapper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onLoadCompleted(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs) {
  chunkSource.onChunkLoadCompleted(loadable);
  eventDispatcher.loadCompleted(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.type,
      trackType,
      loadable.trackFormat,
      loadable.trackSelectionReason,
      loadable.trackSelectionData,
      loadable.startTimeUs,
      loadable.endTimeUs,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded());
  if (!prepared) {
    continueLoading(lastSeekPositionUs);
  } else {
    callback.onContinueLoadingRequested(this);
  }
}
 
Example #21
Source File: PlayerEmsgHandler.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For live streaming with emsg event stream, forward seeking can seek pass the emsg messages that
 * signals end-of-stream or Manifest expiry, which results in load error. In this case, we should
 * notify the Dash media source to refresh its manifest.
 *
 * @param chunk The chunk whose load encountered the error.
 * @return True if manifest refresh has been requested, false otherwise.
 */
/* package */ boolean maybeRefreshManifestOnLoadingError(Chunk chunk) {
  if (!manifest.dynamic) {
    return false;
  }
  if (isWaitingForManifestRefresh) {
    return true;
  }
  boolean isAfterForwardSeek =
      lastLoadedChunkEndTimeUs != C.TIME_UNSET && lastLoadedChunkEndTimeUs < chunk.startTimeUs;
  if (isAfterForwardSeek) {
    // if we are after a forward seek, and the playback is dynamic with embedded emsg stream,
    // there's a chance that we have seek over the emsg messages, in which case we should ask
    // media source for a refresh.
    maybeNotifyDashManifestRefreshNeeded();
    return true;
  }
  return false;
}
 
Example #22
Source File: PlayerEmsgHandler.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For live streaming with emsg event stream, forward seeking can seek pass the emsg messages that
 * signals end-of-stream or Manifest expiry, which results in load error. In this case, we should
 * notify the Dash media source to refresh its manifest.
 *
 * @param chunk The chunk whose load encountered the error.
 * @return True if manifest refresh has been requested, false otherwise.
 */
/* package */ boolean maybeRefreshManifestOnLoadingError(Chunk chunk) {
  if (!manifest.dynamic) {
    return false;
  }
  if (isWaitingForManifestRefresh) {
    return true;
  }
  boolean isAfterForwardSeek =
      lastLoadedChunkEndTimeUs != C.TIME_UNSET && lastLoadedChunkEndTimeUs < chunk.startTimeUs;
  if (isAfterForwardSeek) {
    // if we are after a forward seek, and the playback is dynamic with embedded emsg stream,
    // there's a chance that we have seek over the emsg messages, in which case we should ask
    // media source for a refresh.
    maybeNotifyDashManifestRefreshNeeded();
    return true;
  }
  return false;
}
 
Example #23
Source File: HlsSampleStreamWrapper.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onLoadCompleted(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs) {
  chunkSource.onChunkLoadCompleted(loadable);
  eventDispatcher.loadCompleted(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      loadable.type,
      trackType,
      loadable.trackFormat,
      loadable.trackSelectionReason,
      loadable.trackSelectionData,
      loadable.startTimeUs,
      loadable.endTimeUs,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded());
  if (!prepared) {
    continueLoading(lastSeekPositionUs);
  } else {
    callback.onContinueLoadingRequested(this);
  }
}
 
Example #24
Source File: HlsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private HlsMediaSource(
    Uri manifestUri,
    HlsDataSourceFactory dataSourceFactory,
    HlsExtractorFactory extractorFactory,
    CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
    LoadErrorHandlingPolicy<Chunk> chunkLoadErrorHandlingPolicy,
    int minLoadableRetryCount,
    HlsPlaylistTracker playlistTracker,
    boolean allowChunklessPreparation,
    @Nullable Object tag) {
  this.manifestUri = manifestUri;
  this.dataSourceFactory = dataSourceFactory;
  this.extractorFactory = extractorFactory;
  this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
  this.chunkLoadErrorHandlingPolicy = chunkLoadErrorHandlingPolicy;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.playlistTracker = playlistTracker;
  this.allowChunklessPreparation = allowChunklessPreparation;
  this.tag = tag;
}
 
Example #25
Source File: DefaultDashChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
protected Chunk newInitializationChunk(
    RepresentationHolder representationHolder,
    DataSource dataSource,
    Format trackFormat,
    int trackSelectionReason,
    Object trackSelectionData,
    RangedUri initializationUri,
    RangedUri indexUri) {
  RangedUri requestUri;
  String baseUrl = representationHolder.representation.baseUrl;
  if (initializationUri != null) {
    // It's common for initialization and index data to be stored adjacently. Attempt to merge
    // the two requests together to request both at once.
    requestUri = initializationUri.attemptMerge(indexUri, baseUrl);
    if (requestUri == null) {
      requestUri = initializationUri;
    }
  } else {
    requestUri = indexUri;
  }
  DataSpec dataSpec = new DataSpec(requestUri.resolveUri(baseUrl), requestUri.start,
      requestUri.length, representationHolder.representation.getCacheKey());
  return new InitializationChunk(dataSource, dataSpec, trackFormat,
      trackSelectionReason, trackSelectionData, representationHolder.extractorWrapper);
}
 
Example #26
Source File: HlsSampleStreamWrapper.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public int onLoadError(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs,
    IOException error) {
  long bytesLoaded = loadable.bytesLoaded();
  boolean isMediaChunk = isMediaChunk(loadable);
  boolean cancelable = !isMediaChunk || bytesLoaded == 0;
  boolean canceled = false;
  if (chunkSource.onChunkLoadError(loadable, cancelable, error)) {
    if (isMediaChunk) {
      HlsMediaChunk removed = mediaChunks.removeLast();
      Assertions.checkState(removed == loadable);
      if (mediaChunks.isEmpty()) {
        pendingResetPositionUs = lastSeekPositionUs;
      }
    }
    canceled = true;
  }
  eventDispatcher.loadError(loadable.dataSpec, loadable.type, trackType, loadable.trackFormat,
      loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs,
      loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded(), error,
      canceled);
  if (canceled) {
    if (!prepared) {
      continueLoading(lastSeekPositionUs);
    } else {
      callback.onContinueLoadingRequested(this);
    }
    return Loader.DONT_RETRY;
  } else {
    return Loader.RETRY;
  }
}
 
Example #27
Source File: HlsSampleStreamWrapper.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public void onLoadCanceled(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs,
    boolean released) {
  eventDispatcher.loadCanceled(loadable.dataSpec, loadable.type, trackType, loadable.trackFormat,
      loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs,
      loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded());
  if (!released) {
    int sampleQueueCount = sampleQueues.size();
    for (int i = 0; i < sampleQueueCount; i++) {
      sampleQueues.valueAt(i).reset(groupEnabledStates[i]);
    }
    callback.onContinueLoadingRequested(this);
  }
}
 
Example #28
Source File: HlsChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when the {@link HlsSampleStreamWrapper} has finished loading a chunk obtained from this
 * source.
 *
 * @param chunk The chunk whose load has been completed.
 */
public void onChunkLoadCompleted(Chunk chunk) {
  if (chunk instanceof EncryptionKeyChunk) {
    EncryptionKeyChunk encryptionKeyChunk = (EncryptionKeyChunk) chunk;
    scratchSpace = encryptionKeyChunk.getDataHolder();
    keyCache.put(encryptionKeyChunk.dataSpec.uri, encryptionKeyChunk.getResult());
  }
}
 
Example #29
Source File: HlsSampleStreamWrapper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param trackType The type of the track. One of the {@link C} {@code TRACK_TYPE_*} constants.
 * @param callback A callback for the wrapper.
 * @param chunkSource A {@link HlsChunkSource} from which chunks to load are obtained.
 * @param allocator An {@link Allocator} from which to obtain media buffer allocations.
 * @param positionUs The position from which to start loading media.
 * @param muxedAudioFormat Optional muxed audio {@link Format} as defined by the master playlist.
 * @param chunkLoadErrorHandlingPolicy The {@link LoadErrorHandlingPolicy} for chunk loads.
 * @param minLoadableRetryCount The minimum number of times that the source should retry a load
 *     before propagating an error.
 * @param eventDispatcher A dispatcher to notify of events.
 */
public HlsSampleStreamWrapper(
    int trackType,
    Callback callback,
    HlsChunkSource chunkSource,
    Allocator allocator,
    long positionUs,
    Format muxedAudioFormat,
    LoadErrorHandlingPolicy<Chunk> chunkLoadErrorHandlingPolicy,
    int minLoadableRetryCount,
    EventDispatcher eventDispatcher) {
  this.trackType = trackType;
  this.callback = callback;
  this.chunkSource = chunkSource;
  this.allocator = allocator;
  this.muxedAudioFormat = muxedAudioFormat;
  this.chunkLoadErrorHandlingPolicy = chunkLoadErrorHandlingPolicy;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.eventDispatcher = eventDispatcher;
  loader = new Loader("Loader:HlsSampleStreamWrapper");
  nextChunkHolder = new HlsChunkSource.HlsChunkHolder();
  sampleQueueTrackIds = new int[0];
  audioSampleQueueIndex = C.INDEX_UNSET;
  videoSampleQueueIndex = C.INDEX_UNSET;
  sampleQueues = new SampleQueue[0];
  sampleQueueIsAudioVideoFlags = new boolean[0];
  sampleQueuesEnabledStates = new boolean[0];
  mediaChunks = new ArrayList<>();
  readOnlyMediaChunks = Collections.unmodifiableList(mediaChunks);
  hlsSampleStreams = new ArrayList<>();
  maybeFinishPrepareRunnable = this::maybeFinishPrepare;
  onTracksEndedRunnable = this::onTracksEnded;
  handler = new Handler();
  lastSeekPositionUs = positionUs;
  pendingResetPositionUs = positionUs;
}
 
Example #30
Source File: HlsChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when the {@link HlsSampleStreamWrapper} has finished loading a chunk obtained from this
 * source.
 *
 * @param chunk The chunk whose load has been completed.
 */
public void onChunkLoadCompleted(Chunk chunk) {
  if (chunk instanceof EncryptionKeyChunk) {
    EncryptionKeyChunk encryptionKeyChunk = (EncryptionKeyChunk) chunk;
    scratchSpace = encryptionKeyChunk.getDataHolder();
    setEncryptionData(encryptionKeyChunk.dataSpec.uri, encryptionKeyChunk.iv,
        encryptionKeyChunk.getResult());
  }
}