Commit 39e4112e by tonihei Committed by Oliver Woodman

Add proper live stream clipping.

This adds two options to the ClippingMediaSource which allow proper clipping
of live streams:
 1. The clipping stays fixed relative to already created media periods. That
    means that playback actually progresses through the clipped media and
    eventually reaches the end of the clipping. The window is also marked
    as non-dynamic to let playback end in this case.
 2. Allow to specify a clipping duration relative to the default position to
    be able to specify the duration of live stream which is to be played.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=190911049
parent 09cf9277
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
media sources including composite sources. media sources including composite sources.
* Added callbacks to `MediaSourceEventListener` to get notified when media * Added callbacks to `MediaSourceEventListener` to get notified when media
periods are created, released and being read from. periods are created, released and being read from.
* Support live stream clipping with `ClippingMediaSource`.
* Audio: * Audio:
* Factor out `AudioTrack` position tracking from `DefaultAudioSink`. * Factor out `AudioTrack` position tracking from `DefaultAudioSink`.
* Fix an issue where the playback position would pause just after playback * Fix an issue where the playback position would pause just after playback
......
...@@ -23,6 +23,7 @@ import com.google.android.exoplayer2.decoder.DecoderInputBuffer; ...@@ -23,6 +23,7 @@ import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
/** /**
...@@ -221,11 +222,14 @@ public final class ClippingMediaPeriod implements MediaPeriod, MediaPeriod.Callb ...@@ -221,11 +222,14 @@ public final class ClippingMediaPeriod implements MediaPeriod, MediaPeriod.Callb
} }
private SeekParameters clipSeekParameters(long positionUs, SeekParameters seekParameters) { private SeekParameters clipSeekParameters(long positionUs, SeekParameters seekParameters) {
long toleranceBeforeUs = Math.min(positionUs - startUs, seekParameters.toleranceBeforeUs); long toleranceBeforeUs =
Util.constrainValue(
seekParameters.toleranceBeforeUs, /* min= */ 0, /* max= */ positionUs - startUs);
long toleranceAfterUs = long toleranceAfterUs =
endUs == C.TIME_END_OF_SOURCE Util.constrainValue(
? seekParameters.toleranceAfterUs seekParameters.toleranceAfterUs,
: Math.min(endUs - positionUs, seekParameters.toleranceAfterUs); /* min= */ 0,
/* max= */ endUs == C.TIME_END_OF_SOURCE ? Long.MAX_VALUE : endUs - positionUs);
if (toleranceBeforeUs == seekParameters.toleranceBeforeUs if (toleranceBeforeUs == seekParameters.toleranceBeforeUs
&& toleranceAfterUs == seekParameters.toleranceAfterUs) { && toleranceAfterUs == seekParameters.toleranceAfterUs) {
return seekParameters; return seekParameters;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment