Various small improvements in Transformer
PiperOrigin-RevId: 414428415
This commit is contained in:
parent
59d98b9a4e
commit
5264da59b3
@ -98,12 +98,14 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void release() {
|
@Nullable
|
||||||
sonicAudioProcessor.reset();
|
public DecoderInputBuffer dequeueInputBuffer() {
|
||||||
decoder.release();
|
return decoder.maybeDequeueInputBuffer(decoderInputBuffer) ? decoderInputBuffer : null;
|
||||||
if (encoder != null) {
|
}
|
||||||
encoder.release();
|
|
||||||
}
|
@Override
|
||||||
|
public void queueInputBuffer() {
|
||||||
|
decoder.queueInputBuffer(decoderInputBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Format getOutputFormat() {
|
public Format getOutputFormat() {
|
||||||
return encoder != null ? encoder.getOutputFormat() : null;
|
return encoder != null ? encoder.getOutputFormat() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEnded() {
|
|
||||||
return encoder != null && encoder.isEnded();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public DecoderInputBuffer getOutputBuffer() {
|
public DecoderInputBuffer getOutputBuffer() {
|
||||||
@ -159,6 +145,20 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
checkStateNotNull(encoder).releaseOutputBuffer();
|
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
|
* 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.
|
* 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
|
* 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.
|
* 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];
|
float[] matrix3x3Array = new float[9];
|
||||||
matrix.getValues(matrix3x3Array);
|
matrix.getValues(matrix3x3Array);
|
||||||
float[] matrix4x4Array = getMatrix4x4Array(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>
|
* 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]
|
* 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];
|
float[] matrix4x4Array = new float[16];
|
||||||
matrix4x4Array[10] = 1;
|
matrix4x4Array[10] = 1;
|
||||||
for (int inputRow = 0; inputRow < 3; inputRow++) {
|
for (int inputRow = 0; inputRow < 3; inputRow++) {
|
||||||
|
@ -41,7 +41,7 @@ import androidx.media3.exoplayer.ExoPlaybackException;
|
|||||||
void queueInputBuffer();
|
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.
|
* again.
|
||||||
*/
|
*/
|
||||||
boolean processData() throws ExoPlaybackException;
|
boolean processData() throws ExoPlaybackException;
|
||||||
|
@ -60,12 +60,7 @@ import androidx.media3.extractor.metadata.mp4.SlowMotionData;
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Format inputFormat = checkNotNull(formatHolder.format);
|
Format inputFormat = checkNotNull(formatHolder.format);
|
||||||
boolean shouldChangeMimeType =
|
if (shouldTranscode(inputFormat)) {
|
||||||
transformation.audioMimeType != null
|
|
||||||
&& !transformation.audioMimeType.equals(inputFormat.sampleMimeType);
|
|
||||||
boolean shouldFlattenForSlowMotion =
|
|
||||||
transformation.flattenForSlowMotion && isSlowMotion(inputFormat);
|
|
||||||
if (shouldChangeMimeType || shouldFlattenForSlowMotion) {
|
|
||||||
samplePipeline = new AudioSamplePipeline(inputFormat, transformation, getIndex());
|
samplePipeline = new AudioSamplePipeline(inputFormat, transformation, getIndex());
|
||||||
} else {
|
} else {
|
||||||
samplePipeline = new PassthroughSamplePipeline(inputFormat);
|
samplePipeline = new PassthroughSamplePipeline(inputFormat);
|
||||||
@ -73,6 +68,17 @@ import androidx.media3.extractor.metadata.mp4.SlowMotionData;
|
|||||||
return true;
|
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) {
|
private static boolean isSlowMotion(Format format) {
|
||||||
@Nullable Metadata metadata = format.metadata;
|
@Nullable Metadata metadata = format.metadata;
|
||||||
if (metadata == null) {
|
if (metadata == null) {
|
||||||
|
@ -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
|
@Override
|
||||||
public boolean processData() {
|
public boolean processData() {
|
||||||
if (decoder.isEnded()) {
|
if (decoder.isEnded()) {
|
||||||
@ -131,28 +142,12 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
return decoderHasOutputBuffer && !waitingForFrameEditorInput;
|
return decoderHasOutputBuffer && !waitingForFrameEditorInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public DecoderInputBuffer dequeueInputBuffer() {
|
|
||||||
return decoder.maybeDequeueInputBuffer(decoderInputBuffer) ? decoderInputBuffer : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void queueInputBuffer() {
|
|
||||||
decoder.queueInputBuffer(decoderInputBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Format getOutputFormat() {
|
public Format getOutputFormat() {
|
||||||
return encoder.getOutputFormat();
|
return encoder.getOutputFormat();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEnded() {
|
|
||||||
return encoder.isEnded();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public DecoderInputBuffer getOutputBuffer() {
|
public DecoderInputBuffer getOutputBuffer() {
|
||||||
@ -171,6 +166,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
encoder.releaseOutputBuffer();
|
encoder.releaseOutputBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnded() {
|
||||||
|
return encoder.isEnded();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void release() {
|
public void release() {
|
||||||
if (frameEditor != null) {
|
if (frameEditor != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user