use of com.google.android.exoplayer2.source.SampleQueue in project ExoPlayer by google.
the class HlsSampleStreamWrapper method continueLoading.
@Override
public boolean continueLoading(long positionUs) {
if (loadingFinished || loader.isLoading() || loader.hasFatalError()) {
return false;
}
List<HlsMediaChunk> chunkQueue;
long loadPositionUs;
if (isPendingReset()) {
chunkQueue = Collections.emptyList();
loadPositionUs = pendingResetPositionUs;
for (SampleQueue sampleQueue : sampleQueues) {
sampleQueue.setStartTimeUs(pendingResetPositionUs);
}
} else {
chunkQueue = readOnlyMediaChunks;
HlsMediaChunk lastMediaChunk = getLastMediaChunk();
loadPositionUs = lastMediaChunk.isLoadCompleted() ? lastMediaChunk.endTimeUs : max(lastSeekPositionUs, lastMediaChunk.startTimeUs);
}
nextChunkHolder.clear();
chunkSource.getNextChunk(positionUs, loadPositionUs, chunkQueue, /* allowEndOfStream= */
prepared || !chunkQueue.isEmpty(), nextChunkHolder);
boolean endOfStream = nextChunkHolder.endOfStream;
@Nullable Chunk loadable = nextChunkHolder.chunk;
@Nullable Uri playlistUrlToLoad = nextChunkHolder.playlistUrl;
if (endOfStream) {
pendingResetPositionUs = C.TIME_UNSET;
loadingFinished = true;
return true;
}
if (loadable == null) {
if (playlistUrlToLoad != null) {
callback.onPlaylistRefreshRequired(playlistUrlToLoad);
}
return false;
}
if (isMediaChunk(loadable)) {
initMediaChunkLoad((HlsMediaChunk) loadable);
}
loadingChunk = loadable;
long elapsedRealtimeMs = loader.startLoading(loadable, this, loadErrorHandlingPolicy.getMinimumLoadableRetryCount(loadable.type));
mediaSourceEventDispatcher.loadStarted(new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, elapsedRealtimeMs), loadable.type, trackType, loadable.trackFormat, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs, loadable.endTimeUs);
return true;
}
use of com.google.android.exoplayer2.source.SampleQueue in project ExoPlayer by google.
the class HlsSampleStreamWrapper method seekToUs.
/**
* Attempts to seek to the specified position in microseconds.
*
* @param positionUs The seek position in microseconds.
* @param forceReset If true then a reset is forced (i.e. in-buffer seeking is disabled).
* @return Whether the wrapper was reset, meaning the wrapped sample queues were reset. If false,
* an in-buffer seek was performed.
*/
public boolean seekToUs(long positionUs, boolean forceReset) {
lastSeekPositionUs = positionUs;
if (isPendingReset()) {
// A reset is already pending. We only need to update its position.
pendingResetPositionUs = positionUs;
return true;
}
// If we're not forced to reset, try and seek within the buffer.
if (sampleQueuesBuilt && !forceReset && seekInsideBufferUs(positionUs)) {
return false;
}
// We can't seek inside the buffer, and so need to reset.
pendingResetPositionUs = positionUs;
loadingFinished = false;
mediaChunks.clear();
if (loader.isLoading()) {
if (sampleQueuesBuilt) {
// Discard as much as we can synchronously.
for (SampleQueue sampleQueue : sampleQueues) {
sampleQueue.discardToEnd();
}
}
loader.cancelLoading();
} else {
loader.clearFatalError();
resetSampleQueues();
}
return true;
}
use of com.google.android.exoplayer2.source.SampleQueue in project ExoPlayer by google.
the class HlsSampleStreamWrapper method mapSampleQueuesToMatchTrackGroups.
@RequiresNonNull("trackGroups")
@EnsuresNonNull("trackGroupToSampleQueueIndex")
private void mapSampleQueuesToMatchTrackGroups() {
int trackGroupCount = trackGroups.length;
trackGroupToSampleQueueIndex = new int[trackGroupCount];
Arrays.fill(trackGroupToSampleQueueIndex, C.INDEX_UNSET);
for (int i = 0; i < trackGroupCount; i++) {
for (int queueIndex = 0; queueIndex < sampleQueues.length; queueIndex++) {
SampleQueue sampleQueue = sampleQueues[queueIndex];
Format upstreamFormat = Assertions.checkStateNotNull(sampleQueue.getUpstreamFormat());
if (formatsMatch(upstreamFormat, trackGroups.get(i).getFormat(0))) {
trackGroupToSampleQueueIndex[i] = queueIndex;
break;
}
}
}
for (HlsSampleStream sampleStream : hlsSampleStreams) {
sampleStream.bindSampleQueue();
}
}
use of com.google.android.exoplayer2.source.SampleQueue in project ExoPlayer by google.
the class HlsSampleStreamWrapper method release.
public void release() {
if (prepared) {
// sampleQueues may still be being modified by the loading thread.
for (SampleQueue sampleQueue : sampleQueues) {
sampleQueue.preRelease();
}
}
loader.release(this);
handler.removeCallbacksAndMessages(null);
released = true;
hlsSampleStreams.clear();
}
use of com.google.android.exoplayer2.source.SampleQueue in project ExoPlayer by google.
the class HlsSampleStreamWrapper method skipData.
public int skipData(int sampleQueueIndex, long positionUs) {
if (isPendingReset()) {
return 0;
}
SampleQueue sampleQueue = sampleQueues[sampleQueueIndex];
int skipCount = sampleQueue.getSkipCount(positionUs, loadingFinished);
// Ensure we don't skip into preload chunks until we can be sure they are permanently published.
@Nullable HlsMediaChunk lastChunk = Iterables.getLast(mediaChunks, /* defaultValue= */
null);
if (lastChunk != null && !lastChunk.isPublished()) {
int readIndex = sampleQueue.getReadIndex();
int firstSampleIndex = lastChunk.getFirstSampleIndex(sampleQueueIndex);
skipCount = min(skipCount, firstSampleIndex - readIndex);
}
sampleQueue.skip(skipCount);
return skipCount;
}
Aggregations