Commit 9e4d0db2 by kimvde Committed by Ian Baker

Various small improvements in Transformer

PiperOrigin-RevId: 414428415
parent 2e55643f
......@@ -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
......@@ -120,27 +122,11 @@ 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() {
if (encoder != null) {
......@@ -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.
......
......@@ -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++) {
......
......@@ -41,7 +41,7 @@ import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
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;
......
......@@ -60,12 +60,7 @@ import com.google.android.exoplayer2.source.SampleStream.ReadDataResult;
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 com.google.android.exoplayer2.source.SampleStream.ReadDataResult;
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) {
......
......@@ -103,6 +103,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()) {
return false;
......@@ -133,27 +144,11 @@ 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
@Nullable
public Format getOutputFormat() {
return encoder.getOutputFormat();
}
@Override
public boolean isEnded() {
return encoder.isEnded();
}
@Override
@Nullable
public DecoderInputBuffer getOutputBuffer() {
encoderOutputBuffer.data = encoder.getOutputBuffer();
......@@ -172,6 +167,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
}
@Override
public boolean isEnded() {
return encoder.isEnded();
}
@Override
public void release() {
if (frameEditor != null) {
frameEditor.release();
......
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