Skip to content

Commit

Permalink
Remove ability to disable frame accurate seek.
Browse files Browse the repository at this point in the history
Everything I've seen that uses ExoPlayer sets it to true, and
setting it to false is poorly supported / likely to result in
bad initial A/V sync after each seek.
  • Loading branch information
ojw28 committed Jul 30, 2015
1 parent e90ad9c commit a56c002
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private void buildRenderers() {
new AdaptiveEvaluator(bandwidthMeter), LIVE_EDGE_LATENCY_MS, elapsedRealtimeOffset,
mainHandler, player);
ChunkSampleSource videoSampleSource = new ChunkSampleSource(videoChunkSource, loadControl,
VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, true, mainHandler, player,
VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
DemoPlayer.TYPE_VIDEO);
videoRenderer = new MediaCodecVideoTrackRenderer(videoSampleSource, drmSessionManager, true,
MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000, null, mainHandler, player, 50);
Expand Down Expand Up @@ -332,7 +332,7 @@ private void buildRenderers() {
audioTrackNameList.toArray(audioTrackNames);
audioChunkSource = new MultiTrackChunkSource(audioChunkSourceList);
SampleSource audioSampleSource = new ChunkSampleSource(audioChunkSource, loadControl,
AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, true, mainHandler, player,
AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
DemoPlayer.TYPE_AUDIO);
audioRenderer = new MediaCodecAudioTrackRenderer(audioSampleSource, drmSessionManager, true,
mainHandler, player);
Expand Down Expand Up @@ -370,7 +370,7 @@ private void buildRenderers() {
textTrackNameList.toArray(textTrackNames);
textChunkSource = new MultiTrackChunkSource(textChunkSourceList);
SampleSource textSampleSource = new ChunkSampleSource(textChunkSource, loadControl,
TEXT_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, true, mainHandler, player,
TEXT_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
DemoPlayer.TYPE_TEXT);
textRenderer = new TextTrackRenderer(textSampleSource, player, mainHandler.getLooper(),
new TtmlParser(), new WebvttParser());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void onSingleManifest(HlsPlaylist manifest) {
HlsChunkSource chunkSource = new HlsChunkSource(dataSource, url, manifest, bandwidthMeter,
variantIndices, HlsChunkSource.ADAPTIVE_MODE_SPLICE, audioCapabilities);
HlsSampleSource sampleSource = new HlsSampleSource(chunkSource, loadControl,
BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, true, mainHandler, player, DemoPlayer.TYPE_VIDEO);
BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player, DemoPlayer.TYPE_VIDEO);
MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource,
MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000, mainHandler, player, 50);
MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void onSingleManifest(SmoothStreamingManifest manifest) {
videoStreamElementIndex, videoTrackIndices, videoDataSource,
new AdaptiveEvaluator(bandwidthMeter), LIVE_EDGE_LATENCY_MS);
ChunkSampleSource videoSampleSource = new ChunkSampleSource(videoChunkSource, loadControl,
VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, true, mainHandler, player,
VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
DemoPlayer.TYPE_VIDEO);
videoRenderer = new MediaCodecVideoTrackRenderer(videoSampleSource, drmSessionManager, true,
MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000, null, mainHandler, player, 50);
Expand Down Expand Up @@ -227,7 +227,7 @@ public void onSingleManifest(SmoothStreamingManifest manifest) {
}
audioChunkSource = new MultiTrackChunkSource(audioChunkSources);
ChunkSampleSource audioSampleSource = new ChunkSampleSource(audioChunkSource, loadControl,
AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, true, mainHandler, player,
AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
DemoPlayer.TYPE_AUDIO);
audioRenderer = new MediaCodecAudioTrackRenderer(audioSampleSource, drmSessionManager, true,
mainHandler, player);
Expand Down Expand Up @@ -258,7 +258,7 @@ public void onSingleManifest(SmoothStreamingManifest manifest) {
}
textChunkSource = new MultiTrackChunkSource(textChunkSources);
ChunkSampleSource ttmlSampleSource = new ChunkSampleSource(textChunkSource, loadControl,
TEXT_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, true, mainHandler, player,
TEXT_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
DemoPlayer.TYPE_TEXT);
textRenderer = new TextTrackRenderer(ttmlSampleSource, player, mainHandler.getLooper(),
new TtmlParser());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void onSingleManifest(MediaPresentationDescription manifest) {
throw new IllegalStateException("Unexpected mime type: " + mimeType);
}
ChunkSampleSource videoSampleSource = new ChunkSampleSource(videoChunkSource, loadControl,
VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, true);
VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE);
videoRenderer = new LibvpxVideoTrackRenderer(videoSampleSource,
true, player.getMainHandler(), player, 50);
}
Expand All @@ -133,7 +133,7 @@ public void onSingleManifest(MediaPresentationDescription manifest) {
}
audioChunkSource = new MultiTrackChunkSource(audioChunkSources);
SampleSource audioSampleSource = new ChunkSampleSource(audioChunkSource, loadControl,
AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, true);
AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE);
if (manifestUrl.contains("opus")) { // TODO: Need a better logic here.
audioRenderer = new LibopusAudioTrackRenderer(audioSampleSource);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public interface EventListener extends BaseChunkSampleSourceEventListener {}
private final List<BaseMediaChunk> readOnlyMediaChunks;
private final DefaultTrackOutput sampleQueue;
private final int bufferSizeContribution;
private final boolean frameAccurateSeeking;
private final Handler eventHandler;
private final EventListener eventListener;
private final int minLoadableRetryCount;
Expand All @@ -91,24 +90,23 @@ public interface EventListener extends BaseChunkSampleSourceEventListener {}
private Format downstreamFormat;

public ChunkSampleSource(ChunkSource chunkSource, LoadControl loadControl,
int bufferSizeContribution, boolean frameAccurateSeeking) {
this(chunkSource, loadControl, bufferSizeContribution, frameAccurateSeeking, null, null, 0);
int bufferSizeContribution) {
this(chunkSource, loadControl, bufferSizeContribution, null, null, 0);
}

public ChunkSampleSource(ChunkSource chunkSource, LoadControl loadControl,
int bufferSizeContribution, boolean frameAccurateSeeking, Handler eventHandler,
EventListener eventListener, int eventSourceId) {
this(chunkSource, loadControl, bufferSizeContribution, frameAccurateSeeking, eventHandler,
eventListener, eventSourceId, DEFAULT_MIN_LOADABLE_RETRY_COUNT);
int bufferSizeContribution, Handler eventHandler, EventListener eventListener,
int eventSourceId) {
this(chunkSource, loadControl, bufferSizeContribution, eventHandler, eventListener,
eventSourceId, DEFAULT_MIN_LOADABLE_RETRY_COUNT);
}

public ChunkSampleSource(ChunkSource chunkSource, LoadControl loadControl,
int bufferSizeContribution, boolean frameAccurateSeeking, Handler eventHandler,
EventListener eventListener, int eventSourceId, int minLoadableRetryCount) {
int bufferSizeContribution, Handler eventHandler, EventListener eventListener,
int eventSourceId, int minLoadableRetryCount) {
this.chunkSource = chunkSource;
this.loadControl = loadControl;
this.bufferSizeContribution = bufferSizeContribution;
this.frameAccurateSeeking = frameAccurateSeeking;
this.eventHandler = eventHandler;
this.eventListener = eventListener;
this.eventSourceId = eventSourceId;
Expand Down Expand Up @@ -250,7 +248,7 @@ public int readData(int track, long positionUs, MediaFormatHolder formatHolder,
}

if (sampleQueue.getSample(sampleHolder)) {
boolean decodeOnly = frameAccurateSeeking && sampleHolder.timeUs < lastSeekPositionUs;
boolean decodeOnly = sampleHolder.timeUs < lastSeekPositionUs;
sampleHolder.flags |= decodeOnly ? C.SAMPLE_FLAG_DECODE_ONLY : 0;
onSampleRead(currentChunk, sampleHolder);
return SAMPLE_READ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ public UnrecognizedInputFormatException(Extractor[] extractors) {
private final int requestedBufferSize;
private final SparseArray<InternalTrackOutput> sampleQueues;
private final int minLoadableRetryCount;
private final boolean frameAccurateSeeking;
private final Uri uri;
private final DataSource dataSource;

Expand Down Expand Up @@ -269,7 +268,6 @@ public ExtractorSampleSource(Uri uri, DataSource dataSource, Allocator allocator
extractorHolder = new ExtractorHolder(extractors, this);
sampleQueues = new SparseArray<>();
pendingResetPositionUs = NO_RESET_PENDING;
frameAccurateSeeking = true;
}

@Override
Expand Down Expand Up @@ -390,7 +388,7 @@ public int readData(int track, long playbackPositionUs, MediaFormatHolder format
}

if (sampleQueue.getSample(sampleHolder)) {
boolean decodeOnly = frameAccurateSeeking && sampleHolder.timeUs < lastSeekPositionUs;
boolean decodeOnly = sampleHolder.timeUs < lastSeekPositionUs;
sampleHolder.flags |= decodeOnly ? C.SAMPLE_FLAG_DECODE_ONLY : 0;
if (havePendingNextSampleUs) {
// Set the offset to make the timestamp of this sample equal to pendingNextSampleUs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public interface EventListener extends BaseChunkSampleSourceEventListener {}

private final HlsChunkSource chunkSource;
private final LinkedList<HlsExtractorWrapper> extractors;
private final boolean frameAccurateSeeking;
private final int minLoadableRetryCount;
private final int bufferSizeContribution;

Expand Down Expand Up @@ -92,24 +91,23 @@ public interface EventListener extends BaseChunkSampleSourceEventListener {}
private long currentLoadStartTimeMs;

public HlsSampleSource(HlsChunkSource chunkSource, LoadControl loadControl,
int bufferSizeContribution, boolean frameAccurateSeeking) {
this(chunkSource, loadControl, bufferSizeContribution, frameAccurateSeeking, null, null, 0);
int bufferSizeContribution) {
this(chunkSource, loadControl, bufferSizeContribution, null, null, 0);
}

public HlsSampleSource(HlsChunkSource chunkSource, LoadControl loadControl,
int bufferSizeContribution, boolean frameAccurateSeeking, Handler eventHandler,
EventListener eventListener, int eventSourceId) {
this(chunkSource, loadControl, bufferSizeContribution, frameAccurateSeeking, eventHandler,
eventListener, eventSourceId, DEFAULT_MIN_LOADABLE_RETRY_COUNT);
int bufferSizeContribution, Handler eventHandler, EventListener eventListener,
int eventSourceId) {
this(chunkSource, loadControl, bufferSizeContribution, eventHandler, eventListener,
eventSourceId, DEFAULT_MIN_LOADABLE_RETRY_COUNT);
}

public HlsSampleSource(HlsChunkSource chunkSource, LoadControl loadControl,
int bufferSizeContribution, boolean frameAccurateSeeking, Handler eventHandler,
EventListener eventListener, int eventSourceId, int minLoadableRetryCount) {
int bufferSizeContribution, Handler eventHandler, EventListener eventListener,
int eventSourceId, int minLoadableRetryCount) {
this.chunkSource = chunkSource;
this.loadControl = loadControl;
this.bufferSizeContribution = bufferSizeContribution;
this.frameAccurateSeeking = frameAccurateSeeking;
this.minLoadableRetryCount = minLoadableRetryCount;
this.eventHandler = eventHandler;
this.eventListener = eventListener;
Expand Down Expand Up @@ -298,7 +296,7 @@ public int readData(int track, long playbackPositionUs, MediaFormatHolder format
}

if (extractor.getSample(track, sampleHolder)) {
boolean decodeOnly = frameAccurateSeeking && sampleHolder.timeUs < lastSeekPositionUs;
boolean decodeOnly = sampleHolder.timeUs < lastSeekPositionUs;
sampleHolder.flags |= decodeOnly ? C.SAMPLE_FLAG_DECODE_ONLY : 0;
return SAMPLE_READ;
}
Expand Down

0 comments on commit a56c002

Please sign in to comment.