Various small improvements in Transformer

PiperOrigin-RevId: 414428415
This commit is contained in:
kimvde 2021-12-06 14:44:51 +00:00 committed by Ian Baker
parent 59d98b9a4e
commit 5264da59b3
5 changed files with 53 additions and 47 deletions

View File

@ -98,12 +98,14 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
}
@Override
public void release() {
sonicAudioProcessor.reset();
decoder.release();
if (encoder != null) {
encoder.release();
@Nullable
public DecoderInputBuffer dequeueInputBuffer() {
return decoder.maybeDequeueInputBuffer(decoderInputBuffer) ? decoderInputBuffer : null;
}
@Override
public void queueInputBuffer() {
decoder.queueInputBuffer(decoderInputBuffer);
}
@Override
@ -118,28 +120,12 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
}
}
@Override
@Nullable
public DecoderInputBuffer dequeueInputBuffer() {
return decoder.maybeDequeueInputBuffer(decoderInputBuffer) ? decoderInputBuffer : null;
}
@Override
public void queueInputBuffer() {
decoder.queueInputBuffer(decoderInputBuffer);
}
@Override
@Nullable
public Format getOutputFormat() {
return encoder != null ? encoder.getOutputFormat() : null;
}
@Override
public boolean isEnded() {
return encoder != null && encoder.isEnded();
}
@Override
@Nullable
public DecoderInputBuffer getOutputBuffer() {
@ -159,6 +145,20 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
checkStateNotNull(encoder).releaseOutputBuffer();
}
@Override
public boolean isEnded() {
return encoder != null && encoder.isEnded();
}
@Override
public void release() {
sonicAudioProcessor.reset();
decoder.release();
if (encoder != null) {
encoder.release();
}
}
/**
* Attempts to pass decoder output data to the encoder, and returns whether it may be possible to
* pass more data immediately by calling this method again.

View File

@ -100,7 +100,7 @@ import java.io.IOException;
* Returns a 4x4, column-major Matrix float array, from an input {@link Matrix}. This is useful
* for converting to the 4x4 column-major format commonly used in OpenGL.
*/
private static final float[] getGlMatrixArray(Matrix matrix) {
private static float[] getGlMatrixArray(Matrix matrix) {
float[] matrix3x3Array = new float[9];
matrix.getValues(matrix3x3Array);
float[] matrix4x4Array = getMatrix4x4Array(matrix3x3Array);
@ -123,7 +123,7 @@ import java.io.IOException;
* Input format: [a, b, c, d, e, f, g, h, i] <br>
* Output format: [a, b, 0, c, d, e, 0, f, 0, 0, 1, 0, g, h, 0, i]
*/
private static final float[] getMatrix4x4Array(float[] matrix3x3Array) {
private static float[] getMatrix4x4Array(float[] matrix3x3Array) {
float[] matrix4x4Array = new float[16];
matrix4x4Array[10] = 1;
for (int inputRow = 0; inputRow < 3; inputRow++) {

View File

@ -41,7 +41,7 @@ import androidx.media3.exoplayer.ExoPlaybackException;
void queueInputBuffer();
/**
* Process the input data and returns whether more data can be processed by calling this method
* Processes the input data and returns whether more data can be processed by calling this method
* again.
*/
boolean processData() throws ExoPlaybackException;

View File

@ -60,12 +60,7 @@ import androidx.media3.extractor.metadata.mp4.SlowMotionData;
return false;
}
Format inputFormat = checkNotNull(formatHolder.format);
boolean shouldChangeMimeType =
transformation.audioMimeType != null
&& !transformation.audioMimeType.equals(inputFormat.sampleMimeType);
boolean shouldFlattenForSlowMotion =
transformation.flattenForSlowMotion && isSlowMotion(inputFormat);
if (shouldChangeMimeType || shouldFlattenForSlowMotion) {
if (shouldTranscode(inputFormat)) {
samplePipeline = new AudioSamplePipeline(inputFormat, transformation, getIndex());
} else {
samplePipeline = new PassthroughSamplePipeline(inputFormat);
@ -73,6 +68,17 @@ import androidx.media3.extractor.metadata.mp4.SlowMotionData;
return true;
}
private boolean shouldTranscode(Format inputFormat) {
if (transformation.audioMimeType != null
&& !transformation.audioMimeType.equals(inputFormat.sampleMimeType)) {
return true;
}
if (transformation.flattenForSlowMotion && isSlowMotion(inputFormat)) {
return true;
}
return false;
}
private static boolean isSlowMotion(Format format) {
@Nullable Metadata metadata = format.metadata;
if (metadata == null) {

View File

@ -102,6 +102,17 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
}
}
@Override
@Nullable
public DecoderInputBuffer dequeueInputBuffer() {
return decoder.maybeDequeueInputBuffer(decoderInputBuffer) ? decoderInputBuffer : null;
}
@Override
public void queueInputBuffer() {
decoder.queueInputBuffer(decoderInputBuffer);
}
@Override
public boolean processData() {
if (decoder.isEnded()) {
@ -131,28 +142,12 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
return decoderHasOutputBuffer && !waitingForFrameEditorInput;
}
@Override
@Nullable
public DecoderInputBuffer dequeueInputBuffer() {
return decoder.maybeDequeueInputBuffer(decoderInputBuffer) ? decoderInputBuffer : null;
}
@Override
public void queueInputBuffer() {
decoder.queueInputBuffer(decoderInputBuffer);
}
@Override
@Nullable
public Format getOutputFormat() {
return encoder.getOutputFormat();
}
@Override
public boolean isEnded() {
return encoder.isEnded();
}
@Override
@Nullable
public DecoderInputBuffer getOutputBuffer() {
@ -171,6 +166,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
encoder.releaseOutputBuffer();
}
@Override
public boolean isEnded() {
return encoder.isEnded();
}
@Override
public void release() {
if (frameEditor != null) {