mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Various nits in Transformer
PiperOrigin-RevId: 423822317
This commit is contained in:
parent
8f3439ae78
commit
7b8f33e848
@ -18,7 +18,6 @@ package androidx.media3.transformer;
|
||||
|
||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||
import static androidx.media3.common.util.Assertions.checkState;
|
||||
import static androidx.media3.common.util.Assertions.checkStateNotNull;
|
||||
import static java.lang.Math.min;
|
||||
|
||||
import android.media.MediaCodec.BufferInfo;
|
||||
@ -37,9 +36,8 @@ import org.checkerframework.dataflow.qual.Pure;
|
||||
/**
|
||||
* Pipeline to decode audio samples, apply transformations on the raw samples, and re-encode them.
|
||||
*/
|
||||
/* package */ final class AudioSamplePipeline implements SamplePipeline {
|
||||
/* package */ final class AudioTranscodingSamplePipeline implements SamplePipeline {
|
||||
|
||||
private static final String TAG = "AudioSamplePipeline";
|
||||
private static final int DEFAULT_ENCODER_BITRATE = 128 * 1024;
|
||||
|
||||
private final Codec decoder;
|
||||
@ -61,7 +59,7 @@ import org.checkerframework.dataflow.qual.Pure;
|
||||
private boolean drainingSonicForSpeedChange;
|
||||
private float currentSpeed;
|
||||
|
||||
public AudioSamplePipeline(
|
||||
public AudioTranscodingSamplePipeline(
|
||||
Format inputFormat,
|
||||
TransformationRequest transformationRequest,
|
||||
Codec.DecoderFactory decoderFactory,
|
||||
@ -142,40 +140,36 @@ import org.checkerframework.dataflow.qual.Pure;
|
||||
@Override
|
||||
@Nullable
|
||||
public Format getOutputFormat() throws TransformationException {
|
||||
return encoder != null ? encoder.getOutputFormat() : null;
|
||||
return encoder.getOutputFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public DecoderInputBuffer getOutputBuffer() throws TransformationException {
|
||||
if (encoder != null) {
|
||||
encoderOutputBuffer.data = encoder.getOutputBuffer();
|
||||
if (encoderOutputBuffer.data != null) {
|
||||
encoderOutputBuffer.timeUs = checkNotNull(encoder.getOutputBufferInfo()).presentationTimeUs;
|
||||
encoderOutputBuffer.setFlags(C.BUFFER_FLAG_KEY_FRAME);
|
||||
return encoderOutputBuffer;
|
||||
}
|
||||
encoderOutputBuffer.data = encoder.getOutputBuffer();
|
||||
if (encoderOutputBuffer.data == null) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
encoderOutputBuffer.timeUs = checkNotNull(encoder.getOutputBufferInfo()).presentationTimeUs;
|
||||
encoderOutputBuffer.setFlags(C.BUFFER_FLAG_KEY_FRAME);
|
||||
return encoderOutputBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseOutputBuffer() throws TransformationException {
|
||||
checkStateNotNull(encoder).releaseOutputBuffer();
|
||||
encoder.releaseOutputBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnded() {
|
||||
return encoder != null && encoder.isEnded();
|
||||
return encoder.isEnded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
sonicAudioProcessor.reset();
|
||||
decoder.release();
|
||||
if (encoder != null) {
|
||||
encoder.release();
|
||||
}
|
||||
encoder.release();
|
||||
}
|
||||
|
||||
/**
|
@ -919,7 +919,7 @@ public final class Transformer {
|
||||
|
||||
@Override
|
||||
public void onPlayerError(PlaybackException error) {
|
||||
Throwable cause = error.getCause();
|
||||
@Nullable Throwable cause = error.getCause();
|
||||
handleTransformationEnded(
|
||||
cause instanceof TransformationException
|
||||
? (TransformationException) cause
|
||||
|
@ -73,7 +73,7 @@ import androidx.media3.extractor.metadata.mp4.SlowMotionData;
|
||||
new PassthroughSamplePipeline(inputFormat, transformationRequest, fallbackListener);
|
||||
} else {
|
||||
samplePipeline =
|
||||
new AudioSamplePipeline(
|
||||
new AudioTranscodingSamplePipeline(
|
||||
inputFormat,
|
||||
transformationRequest,
|
||||
decoderFactory,
|
||||
|
@ -82,7 +82,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
new PassthroughSamplePipeline(inputFormat, transformationRequest, fallbackListener);
|
||||
} else {
|
||||
samplePipeline =
|
||||
new VideoSamplePipeline(
|
||||
new VideoTranscodingSamplePipeline(
|
||||
context,
|
||||
inputFormat,
|
||||
transformationRequest,
|
||||
|
@ -36,9 +36,7 @@ import org.checkerframework.dataflow.qual.Pure;
|
||||
/**
|
||||
* Pipeline to decode video samples, apply transformations on the raw samples, and re-encode them.
|
||||
*/
|
||||
/* package */ final class VideoSamplePipeline implements SamplePipeline {
|
||||
|
||||
private static final String TAG = "VideoSamplePipeline";
|
||||
/* package */ final class VideoTranscodingSamplePipeline implements SamplePipeline {
|
||||
|
||||
private final int outputRotationDegrees;
|
||||
private final DecoderInputBuffer decoderInputBuffer;
|
||||
@ -51,7 +49,7 @@ import org.checkerframework.dataflow.qual.Pure;
|
||||
|
||||
private boolean waitingForFrameEditorInput;
|
||||
|
||||
public VideoSamplePipeline(
|
||||
public VideoTranscodingSamplePipeline(
|
||||
Context context,
|
||||
Format inputFormat,
|
||||
TransformationRequest transformationRequest,
|
||||
@ -233,7 +231,7 @@ import org.checkerframework.dataflow.qual.Pure;
|
||||
@Override
|
||||
@Nullable
|
||||
public Format getOutputFormat() throws TransformationException {
|
||||
Format format = encoder.getOutputFormat();
|
||||
@Nullable Format format = encoder.getOutputFormat();
|
||||
return format == null
|
||||
? null
|
||||
: format.buildUpon().setRotationDegrees(outputRotationDegrees).build();
|
Loading…
x
Reference in New Issue
Block a user