Commit 059c359f by samrobinson Committed by Ian Baker

Revert of 8c07f1e1

PiperOrigin-RevId: 444347415
parent d536fe35
......@@ -137,7 +137,7 @@ public abstract class DecoderAudioRenderer<
private @ReinitializationState int decoderReinitializationState;
private boolean decoderReceivedBuffers;
private boolean audioSinkNeedsConfigure;
private boolean audioTrackNeedsConfigure;
private long currentPositionUs;
private boolean allowFirstBufferPositionDiscontinuity;
......@@ -202,7 +202,7 @@ public abstract class DecoderAudioRenderer<
audioSink.setListener(new AudioSinkListener());
flagsOnlyBuffer = DecoderInputBuffer.newNoDataInstance();
decoderReinitializationState = REINITIALIZATION_STATE_NONE;
audioSinkNeedsConfigure = true;
audioTrackNeedsConfigure = true;
}
/**
......@@ -397,7 +397,7 @@ public abstract class DecoderAudioRenderer<
releaseDecoder();
maybeInitDecoder();
// The audio track may need to be recreated once the new output format is known.
audioSinkNeedsConfigure = true;
audioTrackNeedsConfigure = true;
} else {
outputBuffer.release();
outputBuffer = null;
......@@ -411,7 +411,7 @@ public abstract class DecoderAudioRenderer<
return false;
}
if (audioSinkNeedsConfigure) {
if (audioTrackNeedsConfigure) {
Format outputFormat =
getOutputFormat(decoder)
.buildUpon()
......@@ -419,7 +419,7 @@ public abstract class DecoderAudioRenderer<
.setEncoderPadding(encoderPadding)
.build();
audioSink.configure(outputFormat, /* specifiedBufferSize= */ 0, /* outputChannels= */ null);
audioSinkNeedsConfigure = false;
audioTrackNeedsConfigure = false;
}
if (audioSink.handleBuffer(
......@@ -581,7 +581,7 @@ public abstract class DecoderAudioRenderer<
@Override
protected void onDisabled() {
inputFormat = null;
audioSinkNeedsConfigure = true;
audioTrackNeedsConfigure = true;
try {
setSourceDrmSession(null);
releaseDecoder();
......@@ -734,7 +734,7 @@ public abstract class DecoderAudioRenderer<
// There aren't any final output buffers, so release the decoder immediately.
releaseDecoder();
maybeInitDecoder();
audioSinkNeedsConfigure = true;
audioTrackNeedsConfigure = true;
}
}
eventDispatcher.inputFormatChanged(inputFormat, evaluation);
......
......@@ -103,7 +103,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
private long currentPositionUs;
private boolean allowFirstBufferPositionDiscontinuity;
private boolean allowPositionDiscontinuity;
private boolean audioSinkNeedsConfigure;
private boolean audioSinkNeedsReset;
private boolean experimentalKeepAudioTrackOnSeek;
......@@ -254,7 +254,6 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
this.audioSink = audioSink;
eventDispatcher = new EventDispatcher(eventHandler, eventListener);
audioSink.setListener(new AudioSinkListener());
audioSinkNeedsConfigure = true;
}
@Override
......@@ -501,7 +500,50 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
@Override
protected void onOutputFormatChanged(Format format, @Nullable MediaFormat mediaFormat)
throws ExoPlaybackException {
audioSinkNeedsConfigure = true;
Format audioSinkInputFormat;
@Nullable int[] channelMap = null;
if (decryptOnlyCodecFormat != null) { // Direct playback with a codec for decryption.
audioSinkInputFormat = decryptOnlyCodecFormat;
} else if (getCodec() == null) { // Direct playback with codec bypass.
audioSinkInputFormat = format;
} else {
@C.PcmEncoding int pcmEncoding;
if (MimeTypes.AUDIO_RAW.equals(format.sampleMimeType)) {
// For PCM streams, the encoder passes through int samples despite set to float mode.
pcmEncoding = format.pcmEncoding;
} else if (Util.SDK_INT >= 24 && mediaFormat.containsKey(MediaFormat.KEY_PCM_ENCODING)) {
pcmEncoding = mediaFormat.getInteger(MediaFormat.KEY_PCM_ENCODING);
} else if (mediaFormat.containsKey(VIVO_BITS_PER_SAMPLE_KEY)) {
pcmEncoding = Util.getPcmEncoding(mediaFormat.getInteger(VIVO_BITS_PER_SAMPLE_KEY));
} else {
// If the format is anything other than PCM then we assume that the audio decoder will
// output 16-bit PCM.
pcmEncoding = C.ENCODING_PCM_16BIT;
}
audioSinkInputFormat =
new Format.Builder()
.setSampleMimeType(MimeTypes.AUDIO_RAW)
.setPcmEncoding(pcmEncoding)
.setEncoderDelay(format.encoderDelay)
.setEncoderPadding(format.encoderPadding)
.setChannelCount(mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT))
.setSampleRate(mediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE))
.build();
if (codecNeedsDiscardChannelsWorkaround
&& audioSinkInputFormat.channelCount == 6
&& format.channelCount < 6) {
channelMap = new int[format.channelCount];
for (int i = 0; i < format.channelCount; i++) {
channelMap[i] = i;
}
}
}
try {
audioSink.configure(audioSinkInputFormat, /* specifiedBufferSize= */ 0, channelMap);
} catch (AudioSink.ConfigurationException e) {
throw createRendererException(
e, e.format, PlaybackException.ERROR_CODE_AUDIO_TRACK_INIT_FAILED);
}
}
/** See {@link AudioSink.Listener#onPositionDiscontinuity()}. */
......@@ -553,9 +595,9 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
@Override
protected void onDisabled() {
audioSinkNeedsConfigure = true;
audioSinkNeedsReset = true;
try {
audioSink.reset();
audioSink.flush();
} finally {
try {
super.onDisabled();
......@@ -566,6 +608,18 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
}
@Override
protected void onReset() {
try {
super.onReset();
} finally {
if (audioSinkNeedsReset) {
audioSinkNeedsReset = false;
audioSink.reset();
}
}
}
@Override
public boolean isEnded() {
return super.isEnded() && audioSink.isEnded();
}
......@@ -635,8 +689,6 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
return true;
}
maybeConfigureAudioSink(format, getCodecOutputMediaFormat());
if (isDecodeOnlyBuffer) {
if (codec != null) {
codec.releaseOutputBuffer(bufferIndex, false);
......@@ -819,58 +871,6 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
}
}
private void maybeConfigureAudioSink(Format format, @Nullable MediaFormat mediaFormat)
throws ExoPlaybackException {
if (!audioSinkNeedsConfigure) {
return;
}
Format audioSinkInputFormat;
@Nullable int[] channelMap = null;
if (decryptOnlyCodecFormat != null) { // Direct playback with a codec for decryption.
audioSinkInputFormat = decryptOnlyCodecFormat;
} else if (getCodec() == null) { // Direct playback with codec bypass.
audioSinkInputFormat = format;
} else {
@C.PcmEncoding int pcmEncoding;
if (MimeTypes.AUDIO_RAW.equals(format.sampleMimeType)) {
// For PCM streams, the encoder passes through int samples despite set to float mode.
pcmEncoding = format.pcmEncoding;
} else if (Util.SDK_INT >= 24 && mediaFormat.containsKey(MediaFormat.KEY_PCM_ENCODING)) {
pcmEncoding = mediaFormat.getInteger(MediaFormat.KEY_PCM_ENCODING);
} else if (mediaFormat.containsKey(VIVO_BITS_PER_SAMPLE_KEY)) {
pcmEncoding = Util.getPcmEncoding(mediaFormat.getInteger(VIVO_BITS_PER_SAMPLE_KEY));
} else {
// If the format is anything other than PCM then we assume that the audio decoder will
// output 16-bit PCM.
pcmEncoding = C.ENCODING_PCM_16BIT;
}
audioSinkInputFormat =
new Format.Builder()
.setSampleMimeType(MimeTypes.AUDIO_RAW)
.setPcmEncoding(pcmEncoding)
.setEncoderDelay(format.encoderDelay)
.setEncoderPadding(format.encoderPadding)
.setChannelCount(mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT))
.setSampleRate(mediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE))
.build();
if (codecNeedsDiscardChannelsWorkaround
&& audioSinkInputFormat.channelCount == 6
&& format.channelCount < 6) {
channelMap = new int[format.channelCount];
for (int i = 0; i < format.channelCount; i++) {
channelMap[i] = i;
}
}
}
try {
audioSink.configure(audioSinkInputFormat, /* specifiedBufferSize= */ 0, channelMap);
audioSinkNeedsConfigure = false;
} catch (AudioSink.ConfigurationException e) {
throw createRendererException(
e, e.format, PlaybackException.ERROR_CODE_AUDIO_TRACK_INIT_FAILED);
}
}
/**
* Returns whether the device's decoders are known to not support setting the codec operating
* rate.
......
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