com.google.android.exoplayer2.source.SampleQueue Java Examples
The following examples show how to use
com.google.android.exoplayer2.source.SampleQueue.
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: ChunkSampleStream.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@Override public int skipData(long positionUs) { if (isPendingReset()) { return 0; } int skipCount; if (loadingFinished && positionUs > primarySampleQueue.getLargestQueuedTimestampUs()) { skipCount = primarySampleQueue.advanceToEnd(); } else { skipCount = primarySampleQueue.advanceTo(positionUs, true, true); if (skipCount == SampleQueue.ADVANCE_FAILED) { skipCount = 0; } } maybeNotifyPrimaryTrackFormatChanged(); return skipCount; }
Example #2
Source File: ChunkSampleStream.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override public int skipData(long positionUs) { if (isPendingReset()) { return 0; } maybeNotifyDownstreamFormat(); int skipCount; if (loadingFinished && positionUs > sampleQueue.getLargestQueuedTimestampUs()) { skipCount = sampleQueue.advanceToEnd(); } else { skipCount = sampleQueue.advanceTo(positionUs, true, true); if (skipCount == SampleQueue.ADVANCE_FAILED) { skipCount = 0; } } return skipCount; }
Example #3
Source File: ChunkSampleStream.java From MediaSDK with Apache License 2.0 | 6 votes |
@Override public int skipData(long positionUs) { if (isPendingReset()) { return 0; } int skipCount; if (loadingFinished && positionUs > primarySampleQueue.getLargestQueuedTimestampUs()) { skipCount = primarySampleQueue.advanceToEnd(); } else { skipCount = primarySampleQueue.advanceTo(positionUs, true, true); if (skipCount == SampleQueue.ADVANCE_FAILED) { skipCount = 0; } } maybeNotifyPrimaryTrackFormatChanged(); return skipCount; }
Example #4
Source File: HlsSampleStreamWrapper.java From MediaSDK with Apache License 2.0 | 6 votes |
@Override public long getBufferedPositionUs() { if (loadingFinished) { return C.TIME_END_OF_SOURCE; } else if (isPendingReset()) { return pendingResetPositionUs; } else { long bufferedPositionUs = lastSeekPositionUs; HlsMediaChunk lastMediaChunk = getLastMediaChunk(); HlsMediaChunk lastCompletedMediaChunk = lastMediaChunk.isLoadCompleted() ? lastMediaChunk : mediaChunks.size() > 1 ? mediaChunks.get(mediaChunks.size() - 2) : null; if (lastCompletedMediaChunk != null) { bufferedPositionUs = Math.max(bufferedPositionUs, lastCompletedMediaChunk.endTimeUs); } if (sampleQueuesBuilt) { for (SampleQueue sampleQueue : sampleQueues) { bufferedPositionUs = Math.max(bufferedPositionUs, sampleQueue.getLargestQueuedTimestampUs()); } } return bufferedPositionUs; } }
Example #5
Source File: HlsSampleStreamWrapper.java From MediaSDK with Apache License 2.0 | 6 votes |
private SampleQueue createSampleQueue(int id, int type) { int trackCount = sampleQueues.length; SampleQueue trackOutput = new FormatAdjustingSampleQueue(allocator, drmSessionManager, overridingDrmInitData); trackOutput.setSampleOffsetUs(sampleOffsetUs); trackOutput.sourceId(chunkUid); trackOutput.setUpstreamFormatChangeListener(this); sampleQueueTrackIds = Arrays.copyOf(sampleQueueTrackIds, trackCount + 1); sampleQueueTrackIds[trackCount] = id; sampleQueues = Util.nullSafeArrayAppend(sampleQueues, trackOutput); sampleQueueIsAudioVideoFlags = Arrays.copyOf(sampleQueueIsAudioVideoFlags, trackCount + 1); sampleQueueIsAudioVideoFlags[trackCount] = type == C.TRACK_TYPE_AUDIO || type == C.TRACK_TYPE_VIDEO; haveAudioVideoSampleQueues |= sampleQueueIsAudioVideoFlags[trackCount]; sampleQueueMappingDoneByType.add(type); sampleQueueIndicesByType.append(type, trackCount); if (getTrackTypeScore(type) > getTrackTypeScore(primarySampleQueueType)) { primarySampleQueueIndex = trackCount; primarySampleQueueType = type; } sampleQueuesEnabledStates = Arrays.copyOf(sampleQueuesEnabledStates, trackCount + 1); return trackOutput; }
Example #6
Source File: HlsSampleStreamWrapper.java From MediaSDK with Apache License 2.0 | 6 votes |
@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]; if (formatsMatch(sampleQueue.getUpstreamFormat(), trackGroups.get(i).getFormat(0))) { trackGroupToSampleQueueIndex[i] = queueIndex; break; } } } for (HlsSampleStream sampleStream : hlsSampleStreams) { sampleStream.bindSampleQueue(); } }
Example #7
Source File: HlsSampleStreamWrapper.java From MediaSDK with Apache License 2.0 | 6 votes |
/** * Attempts to seek to the specified position within the sample queues. * * @param positionUs The seek position in microseconds. * @return Whether the in-buffer seek was successful. */ private boolean seekInsideBufferUs(long positionUs) { int sampleQueueCount = sampleQueues.length; for (int i = 0; i < sampleQueueCount; i++) { SampleQueue sampleQueue = sampleQueues[i]; sampleQueue.rewind(); boolean seekInsideQueue = sampleQueue.advanceTo(positionUs, true, false) != SampleQueue.ADVANCE_FAILED; // If we have AV tracks then an in-queue seek is successful if the seek into every AV queue // is successful. We ignore whether seeks within non-AV queues are successful in this case, as // they may be sparse or poorly interleaved. If we only have non-AV tracks then a seek is // successful only if the seek into every queue succeeds. if (!seekInsideQueue && (sampleQueueIsAudioVideoFlags[i] || !haveAudioVideoSampleQueues)) { return false; } } return true; }
Example #8
Source File: HlsSampleStreamWrapper.java From Telegram with GNU General Public License v2.0 | 6 votes |
private void maybeFinishPrepare() { if (released || trackGroupToSampleQueueIndex != null || !sampleQueuesBuilt) { return; } for (SampleQueue sampleQueue : sampleQueues) { if (sampleQueue.getUpstreamFormat() == null) { return; } } if (trackGroups != null) { // The track groups were created with master playlist information. They only need to be mapped // to a sample queue. mapSampleQueuesToMatchTrackGroups(); } else { // Tracks are created using media segment information. buildTracksFromSampleStreams(); prepared = true; callback.onPrepared(); } }
Example #9
Source File: ChunkSampleStream.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@Override public int skipData(long positionUs) { if (isPendingReset()) { return 0; } maybeNotifyDownstreamFormat(); int skipCount; if (loadingFinished && positionUs > sampleQueue.getLargestQueuedTimestampUs()) { skipCount = sampleQueue.advanceToEnd(); } else { skipCount = sampleQueue.advanceTo(positionUs, true, true); if (skipCount == SampleQueue.ADVANCE_FAILED) { skipCount = 0; } } return skipCount; }
Example #10
Source File: ChunkSampleStream.java From MediaSDK with Apache License 2.0 | 6 votes |
@Override public int skipData(long positionUs) { if (isPendingReset()) { return 0; } maybeNotifyDownstreamFormat(); int skipCount; if (loadingFinished && positionUs > sampleQueue.getLargestQueuedTimestampUs()) { skipCount = sampleQueue.advanceToEnd(); } else { skipCount = sampleQueue.advanceTo(positionUs, true, true); if (skipCount == SampleQueue.ADVANCE_FAILED) { skipCount = 0; } } return skipCount; }
Example #11
Source File: HlsSampleStreamWrapper.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override public long getBufferedPositionUs() { if (loadingFinished) { return C.TIME_END_OF_SOURCE; } else if (isPendingReset()) { return pendingResetPositionUs; } else { long bufferedPositionUs = lastSeekPositionUs; HlsMediaChunk lastMediaChunk = getLastMediaChunk(); HlsMediaChunk lastCompletedMediaChunk = lastMediaChunk.isLoadCompleted() ? lastMediaChunk : mediaChunks.size() > 1 ? mediaChunks.get(mediaChunks.size() - 2) : null; if (lastCompletedMediaChunk != null) { bufferedPositionUs = Math.max(bufferedPositionUs, lastCompletedMediaChunk.endTimeUs); } if (sampleQueuesBuilt) { for (SampleQueue sampleQueue : sampleQueues) { bufferedPositionUs = Math.max(bufferedPositionUs, sampleQueue.getLargestQueuedTimestampUs()); } } return bufferedPositionUs; } }
Example #12
Source File: HlsSampleStreamWrapper.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private void maybeFinishPrepare() { if (released || trackGroupToSampleQueueIndex != null || !sampleQueuesBuilt) { return; } for (SampleQueue sampleQueue : sampleQueues) { if (sampleQueue.getUpstreamFormat() == null) { return; } } if (trackGroups != null) { // The track groups were created with master playlist information. They only need to be mapped // to a sample queue. mapSampleQueuesToMatchTrackGroups(); } else { // Tracks are created using media segment information. buildTracksFromSampleStreams(); prepared = true; callback.onPrepared(); } }
Example #13
Source File: HlsSampleStreamWrapper.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
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]; if (formatsMatch(sampleQueue.getUpstreamFormat(), trackGroups.get(i).getFormat(0))) { trackGroupToSampleQueueIndex[i] = queueIndex; break; } } } for (HlsSampleStream sampleStream : hlsSampleStreams) { sampleStream.bindSampleQueue(); } }
Example #14
Source File: ChunkSampleStream.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override public void onLoadCanceled(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs, boolean released) { eventDispatcher.loadCanceled( loadable.dataSpec, loadable.getUri(), loadable.type, primaryTrackType, loadable.trackFormat, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs, loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded()); if (!released) { primarySampleQueue.reset(); for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) { embeddedSampleQueue.reset(); } callback.onContinueLoadingRequested(this); } }
Example #15
Source File: ChunkSampleStream.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override public int skipData(long positionUs) { int skipCount; if (loadingFinished && positionUs > sampleQueue.getLargestQueuedTimestampUs()) { skipCount = sampleQueue.advanceToEnd(); } else { skipCount = sampleQueue.advanceTo(positionUs, true, true); if (skipCount == SampleQueue.ADVANCE_FAILED) { skipCount = 0; } } if (skipCount > 0) { maybeNotifyTrackFormatChanged(); } return skipCount; }
Example #16
Source File: HlsSampleStreamWrapper.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * Attempts to seek to the specified position within the sample queues. * * @param positionUs The seek position in microseconds. * @return Whether the in-buffer seek was successful. */ private boolean seekInsideBufferUs(long positionUs) { int sampleQueueCount = sampleQueues.length; for (int i = 0; i < sampleQueueCount; i++) { SampleQueue sampleQueue = sampleQueues[i]; sampleQueue.rewind(); boolean seekInsideQueue = sampleQueue.advanceTo(positionUs, true, false) != SampleQueue.ADVANCE_FAILED; // If we have AV tracks then an in-queue seek is successful if the seek into every AV queue // is successful. We ignore whether seeks within non-AV queues are successful in this case, as // they may be sparse or poorly interleaved. If we only have non-AV tracks then a seek is // successful only if the seek into every queue succeeds. if (!seekInsideQueue && (sampleQueueIsAudioVideoFlags[i] || !haveAudioVideoSampleQueues)) { return false; } } return true; }
Example #17
Source File: HlsSampleStreamWrapper.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
private void maybeFinishPrepare() { if (released || trackGroupToSampleQueueIndex != null || !sampleQueuesBuilt) { return; } for (SampleQueue sampleQueue : sampleQueues) { if (sampleQueue.getUpstreamFormat() == null) { return; } } if (trackGroups != null) { // The track groups were created with master playlist information. They only need to be mapped // to a sample queue. mapSampleQueuesToMatchTrackGroups(); } else { // Tracks are created using media segment information. buildTracksFromSampleStreams(); prepared = true; callback.onPrepared(); } }
Example #18
Source File: ChunkSampleStream.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override public int skipData(long positionUs) { if (isPendingReset()) { return 0; } int skipCount; if (loadingFinished && positionUs > primarySampleQueue.getLargestQueuedTimestampUs()) { skipCount = primarySampleQueue.advanceToEnd(); } else { skipCount = primarySampleQueue.advanceTo(positionUs, true, true); if (skipCount == SampleQueue.ADVANCE_FAILED) { skipCount = 0; } } maybeNotifyPrimaryTrackFormatChanged(); return skipCount; }
Example #19
Source File: HlsSampleStreamWrapper.java From Telegram with GNU General Public License v2.0 | 6 votes |
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]; if (formatsMatch(sampleQueue.getUpstreamFormat(), trackGroups.get(i).getFormat(0))) { trackGroupToSampleQueueIndex[i] = queueIndex; break; } } } for (HlsSampleStream sampleStream : hlsSampleStreams) { sampleStream.bindSampleQueue(); } }
Example #20
Source File: HlsSampleStreamWrapper.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override public long getBufferedPositionUs() { if (loadingFinished) { return C.TIME_END_OF_SOURCE; } else if (isPendingReset()) { return pendingResetPositionUs; } else { long bufferedPositionUs = lastSeekPositionUs; HlsMediaChunk lastMediaChunk = getLastMediaChunk(); HlsMediaChunk lastCompletedMediaChunk = lastMediaChunk.isLoadCompleted() ? lastMediaChunk : mediaChunks.size() > 1 ? mediaChunks.get(mediaChunks.size() - 2) : null; if (lastCompletedMediaChunk != null) { bufferedPositionUs = Math.max(bufferedPositionUs, lastCompletedMediaChunk.endTimeUs); } if (sampleQueuesBuilt) { for (SampleQueue sampleQueue : sampleQueues) { bufferedPositionUs = Math.max(bufferedPositionUs, sampleQueue.getLargestQueuedTimestampUs()); } } return bufferedPositionUs; } }
Example #21
Source File: HlsSampleStreamWrapper.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@Override public long getBufferedPositionUs() { if (loadingFinished) { return C.TIME_END_OF_SOURCE; } else if (isPendingReset()) { return pendingResetPositionUs; } else { long bufferedPositionUs = lastSeekPositionUs; HlsMediaChunk lastMediaChunk = getLastMediaChunk(); HlsMediaChunk lastCompletedMediaChunk = lastMediaChunk.isLoadCompleted() ? lastMediaChunk : mediaChunks.size() > 1 ? mediaChunks.get(mediaChunks.size() - 2) : null; if (lastCompletedMediaChunk != null) { bufferedPositionUs = Math.max(bufferedPositionUs, lastCompletedMediaChunk.endTimeUs); } if (sampleQueuesBuilt) { for (SampleQueue sampleQueue : sampleQueues) { bufferedPositionUs = Math.max(bufferedPositionUs, sampleQueue.getLargestQueuedTimestampUs()); } } return bufferedPositionUs; } }
Example #22
Source File: ChunkSampleStream.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override public void onLoadCanceled(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs, boolean released) { eventDispatcher.loadCanceled( loadable.dataSpec, loadable.getUri(), loadable.type, primaryTrackType, loadable.trackFormat, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs, loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded()); if (!released) { primarySampleQueue.reset(); for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) { embeddedSampleQueue.reset(); } callback.onContinueLoadingRequested(this); } }
Example #23
Source File: ChunkSampleStream.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override public int skipData(long positionUs) { if (isPendingReset()) { return 0; } int skipCount; if (loadingFinished && positionUs > primarySampleQueue.getLargestQueuedTimestampUs()) { skipCount = primarySampleQueue.advanceToEnd(); } else { skipCount = primarySampleQueue.advanceTo(positionUs, true, true); if (skipCount == SampleQueue.ADVANCE_FAILED) { skipCount = 0; } } if (skipCount > 0) { maybeNotifyPrimaryTrackFormatChanged(primarySampleQueue.getReadIndex(), skipCount); } return skipCount; }
Example #24
Source File: HlsSampleStreamWrapper.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
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]; if (formatsMatch(sampleQueue.getUpstreamFormat(), trackGroups.get(i).getFormat(0))) { trackGroupToSampleQueueIndex[i] = queueIndex; break; } } } for (HlsSampleStream sampleStream : hlsSampleStreams) { sampleStream.bindSampleQueue(); } }
Example #25
Source File: HlsSampleStreamWrapper.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override public long getBufferedPositionUs() { if (loadingFinished) { return C.TIME_END_OF_SOURCE; } else if (isPendingReset()) { return pendingResetPositionUs; } else { long bufferedPositionUs = lastSeekPositionUs; HlsMediaChunk lastMediaChunk = getLastMediaChunk(); HlsMediaChunk lastCompletedMediaChunk = lastMediaChunk.isLoadCompleted() ? lastMediaChunk : mediaChunks.size() > 1 ? mediaChunks.get(mediaChunks.size() - 2) : null; if (lastCompletedMediaChunk != null) { bufferedPositionUs = Math.max(bufferedPositionUs, lastCompletedMediaChunk.endTimeUs); } if (sampleQueuesBuilt) { for (SampleQueue sampleQueue : sampleQueues) { bufferedPositionUs = Math.max(bufferedPositionUs, sampleQueue.getLargestQueuedTimestampUs()); } } return bufferedPositionUs; } }
Example #26
Source File: HlsSampleStreamWrapper.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Attempts to seek to the specified position within the sample queues. * * @param positionUs The seek position in microseconds. * @return Whether the in-buffer seek was successful. */ private boolean seekInsideBufferUs(long positionUs) { int sampleQueueCount = sampleQueues.length; for (int i = 0; i < sampleQueueCount; i++) { SampleQueue sampleQueue = sampleQueues[i]; sampleQueue.rewind(); boolean seekInsideQueue = sampleQueue.advanceTo(positionUs, true, false) != SampleQueue.ADVANCE_FAILED; // If we have AV tracks then an in-queue seek is successful if the seek into every AV queue // is successful. We ignore whether seeks within non-AV queues are successful in this case, as // they may be sparse or poorly interleaved. If we only have non-AV tracks then a seek is // successful only if the seek into every queue succeeds. if (!seekInsideQueue && (sampleQueueIsAudioVideoFlags[i] || !haveAudioVideoSampleQueues)) { return false; } } return true; }
Example #27
Source File: HlsSampleStreamWrapper.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
public int skipData(int sampleQueueIndex, long positionUs) { if (isPendingReset()) { return 0; } SampleQueue sampleQueue = sampleQueues[sampleQueueIndex]; if (loadingFinished && positionUs > sampleQueue.getLargestQueuedTimestampUs()) { return sampleQueue.advanceToEnd(); } else { int skipCount = sampleQueue.advanceTo(positionUs, true, true); return skipCount == SampleQueue.ADVANCE_FAILED ? 0 : skipCount; } }
Example #28
Source File: ChunkSampleStream.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
@Override public void onLoaderReleased() { primarySampleQueue.reset(); for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) { embeddedSampleQueue.reset(); } if (releaseCallback != null) { releaseCallback.onSampleStreamReleased(this); } }
Example #29
Source File: ChunkSampleStream.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * Releases the stream. * * <p>This method should be called when the stream is no longer required. Either this method or * {@link #release()} can be used to release this stream. * * @param callback An optional callback to be called on the loading thread once the loader has * been released. */ public void release(@Nullable ReleaseCallback<T> callback) { this.releaseCallback = callback; // Discard as much as we can synchronously. primarySampleQueue.discardToEnd(); for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) { embeddedSampleQueue.discardToEnd(); } loader.release(this); }
Example #30
Source File: HlsSampleStreamWrapper.java From MediaSDK with Apache License 2.0 | 5 votes |
public void release() { if (prepared) { // Discard as much as we can synchronously. We only do this if we're prepared, since otherwise // 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(); }