mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Remove workaround for FrameworkSampleSource.
FrameworkSampleSource will still be useful for audio, where sample interleaving isn't an issue. We could optionally add a "don't wait for first frame" boolean to the video renderer if we *really* need to keep some form of this workaround in place, but I'd rather not do so for now. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=119733224
This commit is contained in:
parent
35e0dd8401
commit
730e4ac953
8 changed files with 21 additions and 83 deletions
|
|
@ -90,7 +90,6 @@ public final class LibflacAudioTrackRenderer extends SampleSourceTrackRenderer
|
||||||
private boolean allowPositionDiscontinuity;
|
private boolean allowPositionDiscontinuity;
|
||||||
private boolean inputStreamEnded;
|
private boolean inputStreamEnded;
|
||||||
private boolean outputStreamEnded;
|
private boolean outputStreamEnded;
|
||||||
private boolean sourceIsReady;
|
|
||||||
|
|
||||||
private final AudioTrack audioTrack;
|
private final AudioTrack audioTrack;
|
||||||
private int audioSessionId;
|
private int audioSessionId;
|
||||||
|
|
@ -131,12 +130,10 @@ public final class LibflacAudioTrackRenderer extends SampleSourceTrackRenderer
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void render(long positionUs, long elapsedRealtimeUs, boolean sourceIsReady)
|
protected void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
|
||||||
throws ExoPlaybackException {
|
|
||||||
if (outputStreamEnded) {
|
if (outputStreamEnded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.sourceIsReady = sourceIsReady;
|
|
||||||
|
|
||||||
// Try and read a format if we don't have one already.
|
// Try and read a format if we don't have one already.
|
||||||
if (format == null && !readFormat()) {
|
if (format == null && !readFormat()) {
|
||||||
|
|
@ -275,7 +272,7 @@ public final class LibflacAudioTrackRenderer extends SampleSourceTrackRenderer
|
||||||
@Override
|
@Override
|
||||||
protected boolean isReady() {
|
protected boolean isReady() {
|
||||||
return audioTrack.hasPendingData()
|
return audioTrack.hasPendingData()
|
||||||
|| (format != null && (sourceIsReady || outputBuffer != null));
|
|| (format != null && (isSourceReady() || outputBuffer != null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -296,7 +293,6 @@ public final class LibflacAudioTrackRenderer extends SampleSourceTrackRenderer
|
||||||
allowPositionDiscontinuity = true;
|
allowPositionDiscontinuity = true;
|
||||||
inputStreamEnded = false;
|
inputStreamEnded = false;
|
||||||
outputStreamEnded = false;
|
outputStreamEnded = false;
|
||||||
sourceIsReady = false;
|
|
||||||
if (decoder != null) {
|
if (decoder != null) {
|
||||||
flushDecoder();
|
flushDecoder();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,6 @@ public final class LibopusAudioTrackRenderer extends SampleSourceTrackRenderer
|
||||||
private boolean allowPositionDiscontinuity;
|
private boolean allowPositionDiscontinuity;
|
||||||
private boolean inputStreamEnded;
|
private boolean inputStreamEnded;
|
||||||
private boolean outputStreamEnded;
|
private boolean outputStreamEnded;
|
||||||
private boolean sourceIsReady;
|
|
||||||
|
|
||||||
private int audioSessionId;
|
private int audioSessionId;
|
||||||
|
|
||||||
|
|
@ -139,12 +138,10 @@ public final class LibopusAudioTrackRenderer extends SampleSourceTrackRenderer
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void render(long positionUs, long elapsedRealtimeUs, boolean sourceIsReady)
|
protected void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
|
||||||
throws ExoPlaybackException {
|
|
||||||
if (outputStreamEnded) {
|
if (outputStreamEnded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.sourceIsReady = sourceIsReady;
|
|
||||||
|
|
||||||
// Try and read a format if we don't have one already.
|
// Try and read a format if we don't have one already.
|
||||||
if (format == null && !readFormat()) {
|
if (format == null && !readFormat()) {
|
||||||
|
|
@ -287,7 +284,7 @@ public final class LibopusAudioTrackRenderer extends SampleSourceTrackRenderer
|
||||||
@Override
|
@Override
|
||||||
protected boolean isReady() {
|
protected boolean isReady() {
|
||||||
return audioTrack.hasPendingData()
|
return audioTrack.hasPendingData()
|
||||||
|| (format != null && (sourceIsReady || outputBuffer != null));
|
|| (format != null && (isSourceReady() || outputBuffer != null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -308,7 +305,6 @@ public final class LibopusAudioTrackRenderer extends SampleSourceTrackRenderer
|
||||||
allowPositionDiscontinuity = true;
|
allowPositionDiscontinuity = true;
|
||||||
inputStreamEnded = false;
|
inputStreamEnded = false;
|
||||||
outputStreamEnded = false;
|
outputStreamEnded = false;
|
||||||
sourceIsReady = false;
|
|
||||||
if (decoder != null) {
|
if (decoder != null) {
|
||||||
flushDecoder();
|
flushDecoder();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,23 +136,6 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Value returned by {@link #getSourceState()} when the source is not ready.
|
|
||||||
*/
|
|
||||||
protected static final int SOURCE_STATE_NOT_READY = 0;
|
|
||||||
/**
|
|
||||||
* Value returned by {@link #getSourceState()} when the source is ready and we're able to read
|
|
||||||
* from it.
|
|
||||||
*/
|
|
||||||
protected static final int SOURCE_STATE_READY = 1;
|
|
||||||
/**
|
|
||||||
* Value returned by {@link #getSourceState()} when the source is ready but we might not be able
|
|
||||||
* to read from it. We transition to this state when an attempt to read a sample fails despite the
|
|
||||||
* source reporting that samples are available. This can occur when the next sample to be provided
|
|
||||||
* by the source is for another renderer.
|
|
||||||
*/
|
|
||||||
protected static final int SOURCE_STATE_READY_READ_MAY_FAIL = 2;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the {@link MediaCodec} is hotswapped (i.e. replaced during playback), this is the period of
|
* If the {@link MediaCodec} is hotswapped (i.e. replaced during playback), this is the period of
|
||||||
* time during which {@link #isReady()} will report true regardless of whether the new codec has
|
* time during which {@link #isReady()} will report true regardless of whether the new codec has
|
||||||
|
|
@ -227,7 +210,6 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
|
||||||
private boolean codecReceivedBuffers;
|
private boolean codecReceivedBuffers;
|
||||||
private boolean codecReceivedEos;
|
private boolean codecReceivedEos;
|
||||||
|
|
||||||
private int sourceState;
|
|
||||||
private boolean inputStreamEnded;
|
private boolean inputStreamEnded;
|
||||||
private boolean outputStreamEnded;
|
private boolean outputStreamEnded;
|
||||||
private boolean waitingForKeys;
|
private boolean waitingForKeys;
|
||||||
|
|
@ -462,7 +444,6 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void reset(long positionUs) throws ExoPlaybackException {
|
protected void reset(long positionUs) throws ExoPlaybackException {
|
||||||
sourceState = SOURCE_STATE_NOT_READY;
|
|
||||||
inputStreamEnded = false;
|
inputStreamEnded = false;
|
||||||
outputStreamEnded = false;
|
outputStreamEnded = false;
|
||||||
if (codec != null) {
|
if (codec != null) {
|
||||||
|
|
@ -481,11 +462,7 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void render(long positionUs, long elapsedRealtimeUs, boolean sourceIsReady)
|
protected void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
|
||||||
throws ExoPlaybackException {
|
|
||||||
sourceState = sourceIsReady
|
|
||||||
? (sourceState == SOURCE_STATE_NOT_READY ? SOURCE_STATE_READY : sourceState)
|
|
||||||
: SOURCE_STATE_NOT_READY;
|
|
||||||
if (format == null) {
|
if (format == null) {
|
||||||
readFormat();
|
readFormat();
|
||||||
}
|
}
|
||||||
|
|
@ -493,9 +470,7 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
|
||||||
if (codec != null) {
|
if (codec != null) {
|
||||||
TraceUtil.beginSection("drainAndFeed");
|
TraceUtil.beginSection("drainAndFeed");
|
||||||
while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {}
|
while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {}
|
||||||
if (feedInputBuffer(true)) {
|
while (feedInputBuffer()) {}
|
||||||
while (feedInputBuffer(false)) {}
|
|
||||||
}
|
|
||||||
TraceUtil.endSection();
|
TraceUtil.endSection();
|
||||||
}
|
}
|
||||||
codecCounters.ensureUpdated();
|
codecCounters.ensureUpdated();
|
||||||
|
|
@ -536,12 +511,10 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param firstFeed True if this is the first call to this method from the current invocation of
|
|
||||||
* {@link #render(long, long)}. False otherwise.
|
|
||||||
* @return True if it may be possible to feed more input data. False otherwise.
|
* @return True if it may be possible to feed more input data. False otherwise.
|
||||||
* @throws ExoPlaybackException If an error occurs feeding the input buffer.
|
* @throws ExoPlaybackException If an error occurs feeding the input buffer.
|
||||||
*/
|
*/
|
||||||
private boolean feedInputBuffer(boolean firstFeed) throws ExoPlaybackException {
|
private boolean feedInputBuffer() throws ExoPlaybackException {
|
||||||
if (inputStreamEnded
|
if (inputStreamEnded
|
||||||
|| codecReinitializationState == REINITIALIZATION_STATE_WAIT_END_OF_STREAM) {
|
|| codecReinitializationState == REINITIALIZATION_STATE_WAIT_END_OF_STREAM) {
|
||||||
// The input stream has ended, or we need to re-initialize the codec but are still waiting
|
// The input stream has ended, or we need to re-initialize the codec but are still waiting
|
||||||
|
|
@ -587,9 +560,6 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
|
||||||
codecReconfigurationState = RECONFIGURATION_STATE_QUEUE_PENDING;
|
codecReconfigurationState = RECONFIGURATION_STATE_QUEUE_PENDING;
|
||||||
}
|
}
|
||||||
result = readSource(formatHolder, buffer);
|
result = readSource(formatHolder, buffer);
|
||||||
if (firstFeed && sourceState == SOURCE_STATE_READY && result == TrackStream.NOTHING_READ) {
|
|
||||||
sourceState = SOURCE_STATE_READY_READ_MAY_FAIL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == TrackStream.NOTHING_READ) {
|
if (result == TrackStream.NOTHING_READ) {
|
||||||
|
|
@ -807,17 +777,7 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
|
||||||
@Override
|
@Override
|
||||||
protected boolean isReady() {
|
protected boolean isReady() {
|
||||||
return format != null && !waitingForKeys
|
return format != null && !waitingForKeys
|
||||||
&& (sourceState != SOURCE_STATE_NOT_READY || outputIndex >= 0 || isWithinHotswapPeriod());
|
&& (isSourceReady() || outputIndex >= 0 || isWithinHotswapPeriod());
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the source state.
|
|
||||||
*
|
|
||||||
* @return One of {@link #SOURCE_STATE_NOT_READY}, {@link #SOURCE_STATE_READY} and
|
|
||||||
* {@link #SOURCE_STATE_READY_READ_MAY_FAIL}.
|
|
||||||
*/
|
|
||||||
protected final int getSourceState() {
|
|
||||||
return sourceState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isWithinHotswapPeriod() {
|
private boolean isWithinHotswapPeriod() {
|
||||||
|
|
|
||||||
|
|
@ -293,8 +293,7 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isReady() {
|
protected boolean isReady() {
|
||||||
if (super.isReady()
|
if (renderedFirstFrame && super.isReady()) {
|
||||||
&& (renderedFirstFrame || getSourceState() == SOURCE_STATE_READY_READ_MAY_FAIL)) {
|
|
||||||
// Ready. If we were joining then we've now joined, so clear the joining deadline.
|
// Ready. If we were joining then we've now joined, so clear the joining deadline.
|
||||||
joiningDeadlineUs = -1;
|
joiningDeadlineUs = -1;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -43,12 +43,6 @@ public abstract class SampleSourceTrackRenderer extends TrackRenderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final void render(long positionUs, long elapsedRealtimeUs)
|
|
||||||
throws ExoPlaybackException {
|
|
||||||
render(positionUs, elapsedRealtimeUs, trackStream.isReady());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final void maybeThrowError() throws IOException {
|
protected final void maybeThrowError() throws IOException {
|
||||||
trackStream.maybeThrowError();
|
trackStream.maybeThrowError();
|
||||||
|
|
@ -70,6 +64,15 @@ public abstract class SampleSourceTrackRenderer extends TrackRenderer {
|
||||||
return trackStream.readData(formatHolder, buffer);
|
return trackStream.readData(formatHolder, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the upstream source is ready.
|
||||||
|
*
|
||||||
|
* @return True if the source is ready. False otherwise.
|
||||||
|
*/
|
||||||
|
protected final boolean isSourceReady() {
|
||||||
|
return trackStream.isReady();
|
||||||
|
}
|
||||||
|
|
||||||
// Abstract methods.
|
// Abstract methods.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -80,17 +83,4 @@ public abstract class SampleSourceTrackRenderer extends TrackRenderer {
|
||||||
*/
|
*/
|
||||||
protected abstract void reset(long positionUs) throws ExoPlaybackException;
|
protected abstract void reset(long positionUs) throws ExoPlaybackException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Called by {@link #render(long, long)}.
|
|
||||||
*
|
|
||||||
* @param positionUs The current media time in microseconds, measured at the start of the
|
|
||||||
* current iteration of the rendering loop.
|
|
||||||
* @param elapsedRealtimeUs {@link android.os.SystemClock#elapsedRealtime()} in microseconds,
|
|
||||||
* measured at the start of the current iteration of the rendering loop.
|
|
||||||
* @param sourceIsReady The result of the most recent call to {@link TrackStream#isReady()}.
|
|
||||||
* @throws ExoPlaybackException If an error occurs.
|
|
||||||
*/
|
|
||||||
protected abstract void render(long positionUs, long elapsedRealtimeUs, boolean sourceIsReady)
|
|
||||||
throws ExoPlaybackException;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,8 +98,7 @@ public final class MetadataTrackRenderer<T> extends SampleSourceTrackRenderer im
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void render(long positionUs, long elapsedRealtimeUs, boolean sourceIsReady)
|
protected void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
|
||||||
throws ExoPlaybackException {
|
|
||||||
if (!inputStreamEnded && pendingMetadata == null) {
|
if (!inputStreamEnded && pendingMetadata == null) {
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
int result = readSource(formatHolder, buffer);
|
int result = readSource(formatHolder, buffer);
|
||||||
|
|
|
||||||
|
|
@ -126,8 +126,7 @@ public final class TextTrackRenderer extends SampleSourceTrackRenderer implement
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void render(long positionUs, long elapsedRealtimeUs, boolean sourceIsReady)
|
protected void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
|
||||||
throws ExoPlaybackException {
|
|
||||||
if (outputStreamEnded) {
|
if (outputStreamEnded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,8 +104,7 @@ public final class Eia608TrackRenderer extends SampleSourceTrackRenderer impleme
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void render(long positionUs, long elapsedRealtimeUs, boolean sourceIsReady)
|
protected void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
|
||||||
throws ExoPlaybackException {
|
|
||||||
if (isBufferPending()) {
|
if (isBufferPending()) {
|
||||||
maybeParsePendingBuffer(positionUs);
|
maybeParsePendingBuffer(positionUs);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue