Commit 94ef005b by kimvde Committed by kim-vde

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
parent 8d5b3689
...@@ -47,8 +47,11 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -47,8 +47,11 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
private static final String TAG = "AudioSamplePipeline"; private static final String TAG = "AudioSamplePipeline";
private static final int DEFAULT_ENCODER_BITRATE = 128 * 1024; 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 MediaCodecAdapterWrapper decoder;
private final Format decoderInputFormat;
private final DecoderInputBuffer decoderInputBuffer; private final DecoderInputBuffer decoderInputBuffer;
private final SonicAudioProcessor sonicAudioProcessor; private final SonicAudioProcessor sonicAudioProcessor;
...@@ -57,9 +60,6 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -57,9 +60,6 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
private final DecoderInputBuffer encoderInputBuffer; private final DecoderInputBuffer encoderInputBuffer;
private final DecoderInputBuffer encoderOutputBuffer; private final DecoderInputBuffer encoderOutputBuffer;
private final Transformation transformation;
private final int rendererIndex;
private @MonotonicNonNull AudioFormat encoderInputAudioFormat; private @MonotonicNonNull AudioFormat encoderInputAudioFormat;
private @MonotonicNonNull MediaCodecAdapterWrapper encoder; private @MonotonicNonNull MediaCodecAdapterWrapper encoder;
private long nextEncoderInputBufferTimeUs; private long nextEncoderInputBufferTimeUs;
...@@ -69,10 +69,9 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -69,10 +69,9 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
private boolean drainingSonicForSpeedChange; private boolean drainingSonicForSpeedChange;
private float currentSpeed; private float currentSpeed;
public AudioSamplePipeline( public AudioSamplePipeline(Format inputFormat, Transformation transformation, int rendererIndex)
Format decoderInputFormat, Transformation transformation, int rendererIndex)
throws ExoPlaybackException { throws ExoPlaybackException {
this.decoderInputFormat = decoderInputFormat; this.inputFormat = inputFormat;
this.transformation = transformation; this.transformation = transformation;
this.rendererIndex = rendererIndex; this.rendererIndex = rendererIndex;
decoderInputBuffer = decoderInputBuffer =
...@@ -83,17 +82,17 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -83,17 +82,17 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED); new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED);
sonicAudioProcessor = new SonicAudioProcessor(); sonicAudioProcessor = new SonicAudioProcessor();
sonicOutputBuffer = AudioProcessor.EMPTY_BUFFER; sonicOutputBuffer = AudioProcessor.EMPTY_BUFFER;
speedProvider = new SegmentSpeedProvider(decoderInputFormat); speedProvider = new SegmentSpeedProvider(inputFormat);
currentSpeed = speedProvider.getSpeed(0); currentSpeed = speedProvider.getSpeed(0);
try { try {
this.decoder = MediaCodecAdapterWrapper.createForAudioDecoding(decoderInputFormat); this.decoder = MediaCodecAdapterWrapper.createForAudioDecoding(inputFormat);
} catch (IOException e) { } catch (IOException e) {
// TODO(internal b/192864511): Assign a specific error code. // TODO(internal b/192864511): Assign a specific error code.
throw ExoPlaybackException.createForRenderer( throw ExoPlaybackException.createForRenderer(
e, e,
TAG, TAG,
rendererIndex, rendererIndex,
decoderInputFormat, inputFormat,
/* rendererFormatSupport= */ C.FORMAT_HANDLED, /* rendererFormatSupport= */ C.FORMAT_HANDLED,
/* isRecoverable= */ false, /* isRecoverable= */ false,
PlaybackException.ERROR_CODE_UNSPECIFIED); PlaybackException.ERROR_CODE_UNSPECIFIED);
...@@ -319,7 +318,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -319,7 +318,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
} }
String audioMimeType = String audioMimeType =
transformation.audioMimeType == null transformation.audioMimeType == null
? decoderInputFormat.sampleMimeType ? inputFormat.sampleMimeType
: transformation.audioMimeType; : transformation.audioMimeType;
try { try {
encoder = encoder =
...@@ -359,7 +358,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -359,7 +358,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
cause, cause,
TAG, TAG,
rendererIndex, rendererIndex,
decoderInputFormat, inputFormat,
/* rendererFormatSupport= */ C.FORMAT_HANDLED, /* rendererFormatSupport= */ C.FORMAT_HANDLED,
/* isRecoverable= */ false, /* isRecoverable= */ false,
errorCode); errorCode);
......
...@@ -58,13 +58,13 @@ import com.google.android.exoplayer2.source.SampleStream.ReadDataResult; ...@@ -58,13 +58,13 @@ import com.google.android.exoplayer2.source.SampleStream.ReadDataResult;
if (result != C.RESULT_FORMAT_READ) { if (result != C.RESULT_FORMAT_READ) {
return false; return false;
} }
Format decoderInputFormat = checkNotNull(formatHolder.format); Format inputFormat = checkNotNull(formatHolder.format);
if ((transformation.audioMimeType != null if ((transformation.audioMimeType != null
&& !transformation.audioMimeType.equals(decoderInputFormat.sampleMimeType)) && !transformation.audioMimeType.equals(inputFormat.sampleMimeType))
|| transformation.flattenForSlowMotion) { || transformation.flattenForSlowMotion) {
samplePipeline = new AudioSamplePipeline(decoderInputFormat, transformation, getIndex()); samplePipeline = new AudioSamplePipeline(inputFormat, transformation, getIndex());
} else { } else {
samplePipeline = new PassthroughSamplePipeline(decoderInputFormat); samplePipeline = new PassthroughSamplePipeline(inputFormat);
} }
return true; return true;
} }
......
...@@ -69,18 +69,17 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -69,18 +69,17 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
if (result != C.RESULT_FORMAT_READ) { if (result != C.RESULT_FORMAT_READ) {
return false; return false;
} }
Format decoderInputFormat = checkNotNull(formatHolder.format); Format inputFormat = checkNotNull(formatHolder.format);
if ((transformation.videoMimeType != null if ((transformation.videoMimeType != null
&& !transformation.videoMimeType.equals(decoderInputFormat.sampleMimeType)) && !transformation.videoMimeType.equals(inputFormat.sampleMimeType))
|| (transformation.outputHeight != Transformation.NO_VALUE || (transformation.outputHeight != Transformation.NO_VALUE
&& transformation.outputHeight != decoderInputFormat.height)) { && transformation.outputHeight != inputFormat.height)) {
samplePipeline = samplePipeline = new VideoSamplePipeline(context, inputFormat, transformation, getIndex());
new VideoSamplePipeline(context, decoderInputFormat, transformation, getIndex());
} else { } else {
samplePipeline = new PassthroughSamplePipeline(decoderInputFormat); samplePipeline = new PassthroughSamplePipeline(inputFormat);
} }
if (transformation.flattenForSlowMotion) { if (transformation.flattenForSlowMotion) {
sefSlowMotionFlattener = new SefSlowMotionFlattener(decoderInputFormat); sefSlowMotionFlattener = new SefSlowMotionFlattener(inputFormat);
} }
return true; return true;
} }
......
...@@ -38,32 +38,29 @@ import java.io.IOException; ...@@ -38,32 +38,29 @@ import java.io.IOException;
private static final String TAG = "VideoSamplePipeline"; private static final String TAG = "VideoSamplePipeline";
private final MediaCodecAdapterWrapper encoder;
private final DecoderInputBuffer encoderOutputBuffer;
private final DecoderInputBuffer decoderInputBuffer; private final DecoderInputBuffer decoderInputBuffer;
private final MediaCodecAdapterWrapper decoder; private final MediaCodecAdapterWrapper decoder;
private final FrameEditor frameEditor; private final FrameEditor frameEditor;
private final MediaCodecAdapterWrapper encoder;
private final DecoderInputBuffer encoderOutputBuffer;
private boolean waitingForPopulatedDecoderSurface; private boolean waitingForPopulatedDecoderSurface;
public VideoSamplePipeline( public VideoSamplePipeline(
Context context, Format decoderInputFormat, Transformation transformation, int rendererIndex) Context context, Format inputFormat, Transformation transformation, int rendererIndex)
throws ExoPlaybackException { throws ExoPlaybackException {
decoderInputBuffer = decoderInputBuffer =
new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED); new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED);
encoderOutputBuffer = encoderOutputBuffer =
new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED); new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED);
int outputWidth = decoderInputFormat.width; int outputWidth = inputFormat.width;
int outputHeight = decoderInputFormat.height; int outputHeight = inputFormat.height;
if (transformation.outputHeight != Transformation.NO_VALUE if (transformation.outputHeight != Transformation.NO_VALUE
&& transformation.outputHeight != decoderInputFormat.height) { && transformation.outputHeight != inputFormat.height) {
outputWidth = outputWidth = inputFormat.width * transformation.outputHeight / inputFormat.height;
decoderInputFormat.width * transformation.outputHeight / decoderInputFormat.height;
outputHeight = transformation.outputHeight; outputHeight = transformation.outputHeight;
} }
...@@ -76,13 +73,13 @@ import java.io.IOException; ...@@ -76,13 +73,13 @@ import java.io.IOException;
.setSampleMimeType( .setSampleMimeType(
transformation.videoMimeType != null transformation.videoMimeType != null
? transformation.videoMimeType ? transformation.videoMimeType
: decoderInputFormat.sampleMimeType) : inputFormat.sampleMimeType)
.build(), .build(),
ImmutableMap.of()); ImmutableMap.of());
} catch (IOException e) { } catch (IOException e) {
// TODO(internal b/192864511): Assign a specific error code. // TODO(internal b/192864511): Assign a specific error code.
throw createRendererException( throw createRendererException(
e, rendererIndex, decoderInputFormat, PlaybackException.ERROR_CODE_UNSPECIFIED); e, rendererIndex, inputFormat, PlaybackException.ERROR_CODE_UNSPECIFIED);
} }
frameEditor = frameEditor =
FrameEditor.create( FrameEditor.create(
...@@ -93,10 +90,10 @@ import java.io.IOException; ...@@ -93,10 +90,10 @@ import java.io.IOException;
try { try {
decoder = decoder =
MediaCodecAdapterWrapper.createForVideoDecoding( MediaCodecAdapterWrapper.createForVideoDecoding(
decoderInputFormat, frameEditor.getInputSurface()); inputFormat, frameEditor.getInputSurface());
} catch (IOException e) { } catch (IOException e) {
throw createRendererException( 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; ...@@ -172,12 +169,12 @@ import java.io.IOException;
} }
private static ExoPlaybackException createRendererException( private static ExoPlaybackException createRendererException(
Throwable cause, int rendererIndex, Format decoderInputFormat, int errorCode) { Throwable cause, int rendererIndex, Format inputFormat, int errorCode) {
return ExoPlaybackException.createForRenderer( return ExoPlaybackException.createForRenderer(
cause, cause,
TAG, TAG,
rendererIndex, rendererIndex,
decoderInputFormat, inputFormat,
/* rendererFormatSupport= */ C.FORMAT_HANDLED, /* rendererFormatSupport= */ C.FORMAT_HANDLED,
/* isRecoverable= */ false, /* isRecoverable= */ false,
errorCode); errorCode);
......
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