Trigger reconfiguration on newly obtained MediaCodecAdapters

Add the `needsReconfiguration` API on the `MediaCodecAdapter` interface so that `MediaCodecRenderer` can reconfigure the `MediaCodec` in case a `MediaCodecAdapter` needs to be reconfigured immediately after being obtained from the `MediaCodecAdapter.Factory`.

PiperOrigin-RevId: 376944334
This commit is contained in:
olly 2021-06-02 00:36:20 +01:00 committed by bachinger
parent 2fb61b8ab5
commit 08c882a6ae
6 changed files with 25 additions and 0 deletions

View file

@ -6,6 +6,7 @@
* Fix gradle config to allow specifying a relative path for
`exoplayerRoot` when [depending on ExoPlayer locally](README.md#locally)
([#8927](https://github.com/google/ExoPlayer/issues/8927)).
* Add `needsReconfiguration` API to the `MediaCodecAdapter` interface.
* Update `MediaItem.Builder` javadoc to discourage calling setters that
will be (currently) ignored if another setter is not also called.
* Extractors:

View file

@ -184,6 +184,11 @@ import java.nio.ByteBuffer;
state = STATE_STARTED;
}
@Override
public boolean needsReconfiguration() {
return false;
}
@Override
public void queueInputBuffer(
int index, int offset, int size, long presentationTimeUs, int flags) {

View file

@ -214,4 +214,7 @@ public interface MediaCodecAdapter {
* @see MediaCodec#setVideoScalingMode(int)
*/
void setVideoScalingMode(@C.VideoScalingMode int scalingMode);
/** Whether the adapter needs to be reconfigured before it is used. */
boolean needsReconfiguration();
}

View file

@ -1141,6 +1141,12 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
codecNeedsMonoChannelCountWorkaround(codecName, codecInputFormat);
codecNeedsEosPropagation =
codecNeedsEosPropagationWorkaround(codecInfo) || getCodecNeedsEosPropagation();
if (codecAdapter.needsReconfiguration()) {
this.codecReconfigured = true;
this.codecReconfigurationState = RECONFIGURATION_STATE_WRITE_PENDING;
this.codecNeedsAdaptationWorkaroundBuffer =
codecAdaptationWorkaroundMode != ADAPTATION_WORKAROUND_MODE_NEVER;
}
if ("c2.android.mp3.decoder".equals(codecInfo.name)) {
c2Mp3TimestampTracker = new C2Mp3TimestampTracker();
}

View file

@ -88,6 +88,11 @@ public class SynchronousMediaCodecAdapter implements MediaCodecAdapter {
}
}
@Override
public boolean needsReconfiguration() {
return false;
}
@Override
public int dequeueInputBufferIndex() {
return codec.dequeueInputBuffer(0);

View file

@ -278,6 +278,11 @@ public class CapturingRenderersFactory implements RenderersFactory, Dumper.Dumpa
dumper.endBlock();
}
@Override
public boolean needsReconfiguration() {
return false;
}
private static byte[] peekBytes(ByteBuffer buffer, int offset, int size) {
int originalPosition = buffer.position();
buffer.position(offset);