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.checkNotNull;
|
||||||
import static androidx.media3.common.util.Assertions.checkState;
|
import static androidx.media3.common.util.Assertions.checkState;
|
||||||
import static androidx.media3.common.util.Assertions.checkStateNotNull;
|
|
||||||
import static java.lang.Math.min;
|
import static java.lang.Math.min;
|
||||||
|
|
||||||
import android.media.MediaCodec.BufferInfo;
|
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.
|
* 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 static final int DEFAULT_ENCODER_BITRATE = 128 * 1024;
|
||||||
|
|
||||||
private final Codec decoder;
|
private final Codec decoder;
|
||||||
@ -61,7 +59,7 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||||||
private boolean drainingSonicForSpeedChange;
|
private boolean drainingSonicForSpeedChange;
|
||||||
private float currentSpeed;
|
private float currentSpeed;
|
||||||
|
|
||||||
public AudioSamplePipeline(
|
public AudioTranscodingSamplePipeline(
|
||||||
Format inputFormat,
|
Format inputFormat,
|
||||||
TransformationRequest transformationRequest,
|
TransformationRequest transformationRequest,
|
||||||
Codec.DecoderFactory decoderFactory,
|
Codec.DecoderFactory decoderFactory,
|
||||||
@ -142,41 +140,37 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Format getOutputFormat() throws TransformationException {
|
public Format getOutputFormat() throws TransformationException {
|
||||||
return encoder != null ? encoder.getOutputFormat() : null;
|
return encoder.getOutputFormat();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public DecoderInputBuffer getOutputBuffer() throws TransformationException {
|
public DecoderInputBuffer getOutputBuffer() throws TransformationException {
|
||||||
if (encoder != null) {
|
|
||||||
encoderOutputBuffer.data = encoder.getOutputBuffer();
|
encoderOutputBuffer.data = encoder.getOutputBuffer();
|
||||||
if (encoderOutputBuffer.data != null) {
|
if (encoderOutputBuffer.data == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
encoderOutputBuffer.timeUs = checkNotNull(encoder.getOutputBufferInfo()).presentationTimeUs;
|
encoderOutputBuffer.timeUs = checkNotNull(encoder.getOutputBufferInfo()).presentationTimeUs;
|
||||||
encoderOutputBuffer.setFlags(C.BUFFER_FLAG_KEY_FRAME);
|
encoderOutputBuffer.setFlags(C.BUFFER_FLAG_KEY_FRAME);
|
||||||
return encoderOutputBuffer;
|
return encoderOutputBuffer;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void releaseOutputBuffer() throws TransformationException {
|
public void releaseOutputBuffer() throws TransformationException {
|
||||||
checkStateNotNull(encoder).releaseOutputBuffer();
|
encoder.releaseOutputBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnded() {
|
public boolean isEnded() {
|
||||||
return encoder != null && encoder.isEnded();
|
return encoder.isEnded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void release() {
|
public void release() {
|
||||||
sonicAudioProcessor.reset();
|
sonicAudioProcessor.reset();
|
||||||
decoder.release();
|
decoder.release();
|
||||||
if (encoder != null) {
|
|
||||||
encoder.release();
|
encoder.release();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to pass decoder output data to the encoder, and returns whether it may be possible to
|
* Attempts to pass decoder output data to the encoder, and returns whether it may be possible to
|
@ -919,7 +919,7 @@ public final class Transformer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerError(PlaybackException error) {
|
public void onPlayerError(PlaybackException error) {
|
||||||
Throwable cause = error.getCause();
|
@Nullable Throwable cause = error.getCause();
|
||||||
handleTransformationEnded(
|
handleTransformationEnded(
|
||||||
cause instanceof TransformationException
|
cause instanceof TransformationException
|
||||||
? (TransformationException) cause
|
? (TransformationException) cause
|
||||||
|
@ -73,7 +73,7 @@ import androidx.media3.extractor.metadata.mp4.SlowMotionData;
|
|||||||
new PassthroughSamplePipeline(inputFormat, transformationRequest, fallbackListener);
|
new PassthroughSamplePipeline(inputFormat, transformationRequest, fallbackListener);
|
||||||
} else {
|
} else {
|
||||||
samplePipeline =
|
samplePipeline =
|
||||||
new AudioSamplePipeline(
|
new AudioTranscodingSamplePipeline(
|
||||||
inputFormat,
|
inputFormat,
|
||||||
transformationRequest,
|
transformationRequest,
|
||||||
decoderFactory,
|
decoderFactory,
|
||||||
|
@ -82,7 +82,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
new PassthroughSamplePipeline(inputFormat, transformationRequest, fallbackListener);
|
new PassthroughSamplePipeline(inputFormat, transformationRequest, fallbackListener);
|
||||||
} else {
|
} else {
|
||||||
samplePipeline =
|
samplePipeline =
|
||||||
new VideoSamplePipeline(
|
new VideoTranscodingSamplePipeline(
|
||||||
context,
|
context,
|
||||||
inputFormat,
|
inputFormat,
|
||||||
transformationRequest,
|
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.
|
* Pipeline to decode video samples, apply transformations on the raw samples, and re-encode them.
|
||||||
*/
|
*/
|
||||||
/* package */ final class VideoSamplePipeline implements SamplePipeline {
|
/* package */ final class VideoTranscodingSamplePipeline implements SamplePipeline {
|
||||||
|
|
||||||
private static final String TAG = "VideoSamplePipeline";
|
|
||||||
|
|
||||||
private final int outputRotationDegrees;
|
private final int outputRotationDegrees;
|
||||||
private final DecoderInputBuffer decoderInputBuffer;
|
private final DecoderInputBuffer decoderInputBuffer;
|
||||||
@ -51,7 +49,7 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||||||
|
|
||||||
private boolean waitingForFrameEditorInput;
|
private boolean waitingForFrameEditorInput;
|
||||||
|
|
||||||
public VideoSamplePipeline(
|
public VideoTranscodingSamplePipeline(
|
||||||
Context context,
|
Context context,
|
||||||
Format inputFormat,
|
Format inputFormat,
|
||||||
TransformationRequest transformationRequest,
|
TransformationRequest transformationRequest,
|
||||||
@ -233,7 +231,7 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Format getOutputFormat() throws TransformationException {
|
public Format getOutputFormat() throws TransformationException {
|
||||||
Format format = encoder.getOutputFormat();
|
@Nullable Format format = encoder.getOutputFormat();
|
||||||
return format == null
|
return format == null
|
||||||
? null
|
? null
|
||||||
: format.buildUpon().setRotationDegrees(outputRotationDegrees).build();
|
: format.buildUpon().setRotationDegrees(outputRotationDegrees).build();
|
Loading…
x
Reference in New Issue
Block a user