Rename decoderInputFormat in transformer renderers

- This format is passed to the PassthroughPipeline, which doesn't use
  any decoder.
- In most other cases where it is used, it is not relevant that this
  format will be or has been passed to the decoder. What's relevant is
  that it is the format of the input.

PiperOrigin-RevId: 412093371
This commit is contained in:
kimvde 2021-11-24 18:52:55 +00:00 committed by tonihei
parent e45140871e
commit b7f0071e8c
4 changed files with 35 additions and 40 deletions

View File

@ -47,8 +47,11 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
private static final String TAG = "AudioSamplePipeline";
private static final int DEFAULT_ENCODER_BITRATE = 128 * 1024;
private final Format inputFormat;
private final Transformation transformation;
private final int rendererIndex;
private final MediaCodecAdapterWrapper decoder;
private final Format decoderInputFormat;
private final DecoderInputBuffer decoderInputBuffer;
private final SonicAudioProcessor sonicAudioProcessor;
@ -57,9 +60,6 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
private final DecoderInputBuffer encoderInputBuffer;
private final DecoderInputBuffer encoderOutputBuffer;
private final Transformation transformation;
private final int rendererIndex;
private @MonotonicNonNull AudioFormat encoderInputAudioFormat;
private @MonotonicNonNull MediaCodecAdapterWrapper encoder;
private long nextEncoderInputBufferTimeUs;
@ -69,10 +69,9 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
private boolean drainingSonicForSpeedChange;
private float currentSpeed;
public AudioSamplePipeline(
Format decoderInputFormat, Transformation transformation, int rendererIndex)
public AudioSamplePipeline(Format inputFormat, Transformation transformation, int rendererIndex)
throws ExoPlaybackException {
this.decoderInputFormat = decoderInputFormat;
this.inputFormat = inputFormat;
this.transformation = transformation;
this.rendererIndex = rendererIndex;
decoderInputBuffer =
@ -83,17 +82,17 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED);
sonicAudioProcessor = new SonicAudioProcessor();
sonicOutputBuffer = AudioProcessor.EMPTY_BUFFER;
speedProvider = new SegmentSpeedProvider(decoderInputFormat);
speedProvider = new SegmentSpeedProvider(inputFormat);
currentSpeed = speedProvider.getSpeed(0);
try {
this.decoder = MediaCodecAdapterWrapper.createForAudioDecoding(decoderInputFormat);
this.decoder = MediaCodecAdapterWrapper.createForAudioDecoding(inputFormat);
} catch (IOException e) {
// TODO(internal b/192864511): Assign a specific error code.
throw ExoPlaybackException.createForRenderer(
e,
TAG,
rendererIndex,
decoderInputFormat,
inputFormat,
/* rendererFormatSupport= */ C.FORMAT_HANDLED,
/* isRecoverable= */ false,
PlaybackException.ERROR_CODE_UNSPECIFIED);
@ -319,7 +318,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
}
String audioMimeType =
transformation.audioMimeType == null
? decoderInputFormat.sampleMimeType
? inputFormat.sampleMimeType
: transformation.audioMimeType;
try {
encoder =
@ -359,7 +358,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
cause,
TAG,
rendererIndex,
decoderInputFormat,
inputFormat,
/* rendererFormatSupport= */ C.FORMAT_HANDLED,
/* isRecoverable= */ false,
errorCode);

View File

@ -58,13 +58,13 @@ import androidx.media3.exoplayer.source.SampleStream.ReadDataResult;
if (result != C.RESULT_FORMAT_READ) {
return false;
}
Format decoderInputFormat = checkNotNull(formatHolder.format);
Format inputFormat = checkNotNull(formatHolder.format);
if ((transformation.audioMimeType != null
&& !transformation.audioMimeType.equals(decoderInputFormat.sampleMimeType))
&& !transformation.audioMimeType.equals(inputFormat.sampleMimeType))
|| transformation.flattenForSlowMotion) {
samplePipeline = new AudioSamplePipeline(decoderInputFormat, transformation, getIndex());
samplePipeline = new AudioSamplePipeline(inputFormat, transformation, getIndex());
} else {
samplePipeline = new PassthroughSamplePipeline(decoderInputFormat);
samplePipeline = new PassthroughSamplePipeline(inputFormat);
}
return true;
}

View File

@ -69,18 +69,17 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
if (result != C.RESULT_FORMAT_READ) {
return false;
}
Format decoderInputFormat = checkNotNull(formatHolder.format);
Format inputFormat = checkNotNull(formatHolder.format);
if ((transformation.videoMimeType != null
&& !transformation.videoMimeType.equals(decoderInputFormat.sampleMimeType))
&& !transformation.videoMimeType.equals(inputFormat.sampleMimeType))
|| (transformation.outputHeight != Transformation.NO_VALUE
&& transformation.outputHeight != decoderInputFormat.height)) {
samplePipeline =
new VideoSamplePipeline(context, decoderInputFormat, transformation, getIndex());
&& transformation.outputHeight != inputFormat.height)) {
samplePipeline = new VideoSamplePipeline(context, inputFormat, transformation, getIndex());
} else {
samplePipeline = new PassthroughSamplePipeline(decoderInputFormat);
samplePipeline = new PassthroughSamplePipeline(inputFormat);
}
if (transformation.flattenForSlowMotion) {
sefSlowMotionFlattener = new SefSlowMotionFlattener(decoderInputFormat);
sefSlowMotionFlattener = new SefSlowMotionFlattener(inputFormat);
}
return true;
}

View File

@ -38,32 +38,29 @@ import java.io.IOException;
private static final String TAG = "VideoSamplePipeline";
private final MediaCodecAdapterWrapper encoder;
private final DecoderInputBuffer encoderOutputBuffer;
private final DecoderInputBuffer decoderInputBuffer;
private final MediaCodecAdapterWrapper decoder;
private final FrameEditor frameEditor;
private final MediaCodecAdapterWrapper encoder;
private final DecoderInputBuffer encoderOutputBuffer;
private boolean waitingForPopulatedDecoderSurface;
public VideoSamplePipeline(
Context context, Format decoderInputFormat, Transformation transformation, int rendererIndex)
Context context, Format inputFormat, Transformation transformation, int rendererIndex)
throws ExoPlaybackException {
decoderInputBuffer =
new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED);
encoderOutputBuffer =
new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED);
int outputWidth = decoderInputFormat.width;
int outputHeight = decoderInputFormat.height;
int outputWidth = inputFormat.width;
int outputHeight = inputFormat.height;
if (transformation.outputHeight != Transformation.NO_VALUE
&& transformation.outputHeight != decoderInputFormat.height) {
outputWidth =
decoderInputFormat.width * transformation.outputHeight / decoderInputFormat.height;
&& transformation.outputHeight != inputFormat.height) {
outputWidth = inputFormat.width * transformation.outputHeight / inputFormat.height;
outputHeight = transformation.outputHeight;
}
@ -76,13 +73,13 @@ import java.io.IOException;
.setSampleMimeType(
transformation.videoMimeType != null
? transformation.videoMimeType
: decoderInputFormat.sampleMimeType)
: inputFormat.sampleMimeType)
.build(),
ImmutableMap.of());
} catch (IOException e) {
// TODO(internal b/192864511): Assign a specific error code.
throw createRendererException(
e, rendererIndex, decoderInputFormat, PlaybackException.ERROR_CODE_UNSPECIFIED);
e, rendererIndex, inputFormat, PlaybackException.ERROR_CODE_UNSPECIFIED);
}
frameEditor =
FrameEditor.create(
@ -93,10 +90,10 @@ import java.io.IOException;
try {
decoder =
MediaCodecAdapterWrapper.createForVideoDecoding(
decoderInputFormat, frameEditor.getInputSurface());
inputFormat, frameEditor.getInputSurface());
} catch (IOException e) {
throw createRendererException(
e, rendererIndex, decoderInputFormat, PlaybackException.ERROR_CODE_DECODER_INIT_FAILED);
e, rendererIndex, inputFormat, PlaybackException.ERROR_CODE_DECODER_INIT_FAILED);
}
}
@ -172,12 +169,12 @@ import java.io.IOException;
}
private static ExoPlaybackException createRendererException(
Throwable cause, int rendererIndex, Format decoderInputFormat, int errorCode) {
Throwable cause, int rendererIndex, Format inputFormat, int errorCode) {
return ExoPlaybackException.createForRenderer(
cause,
TAG,
rendererIndex,
decoderInputFormat,
inputFormat,
/* rendererFormatSupport= */ C.FORMAT_HANDLED,
/* isRecoverable= */ false,
errorCode);