Commit 20daaa20 by hschlueter Committed by Ian Baker

Move OpenGL setup to FrameProcessorChain#configure().

The factory method is replaced by a public constructor and
configure() method which configures the input/output surfaces
and handles the OpenGL setup.

This is a prerequisite for removing the responsibility of the
caller to configureSizes() before creating the chain in a follow-up.

PiperOrigin-RevId: 437028882
parent da3cb63c
...@@ -251,31 +251,27 @@ public final class FrameProcessorChainPixelTest { ...@@ -251,31 +251,27 @@ public final class FrameProcessorChainPixelTest {
List<Size> sizes = List<Size> sizes =
FrameProcessorChain.configureSizes(inputWidth, inputHeight, frameProcessorsList); FrameProcessorChain.configureSizes(inputWidth, inputHeight, frameProcessorsList);
assertThat(sizes).isNotEmpty(); assertThat(sizes).isNotEmpty();
int outputWidth = Iterables.getLast(sizes).getWidth();
int outputHeight = Iterables.getLast(sizes).getHeight();
outputImageReader = outputImageReader =
ImageReader.newInstance( ImageReader.newInstance(
Iterables.getLast(sizes).getWidth(), outputWidth, outputHeight, PixelFormat.RGBA_8888, /* maxImages= */ 1);
Iterables.getLast(sizes).getHeight(),
PixelFormat.RGBA_8888,
/* maxImages= */ 1);
frameProcessorChain = frameProcessorChain =
FrameProcessorChain.create( new FrameProcessorChain(
context, context,
PIXEL_WIDTH_HEIGHT_RATIO, PIXEL_WIDTH_HEIGHT_RATIO,
frameProcessorsList, frameProcessorsList,
sizes, sizes,
outputImageReader.getSurface(), /* enableExperimentalHdrEditing= */ false);
/* enableExperimentalHdrEditing= */ false, frameProcessorChain.configure(
Transformer.DebugViewProvider.NONE); outputImageReader.getSurface(), outputWidth, outputHeight, /* debugSurfaceView= */ null);
frameProcessorChain.registerInputFrame(); frameProcessorChain.registerInputFrame();
// Queue the first video frame from the extractor. // Queue the first video frame from the extractor.
String mimeType = checkNotNull(mediaFormat.getString(MediaFormat.KEY_MIME)); String mimeType = checkNotNull(mediaFormat.getString(MediaFormat.KEY_MIME));
mediaCodec = MediaCodec.createDecoderByType(mimeType); mediaCodec = MediaCodec.createDecoderByType(mimeType);
mediaCodec.configure( mediaCodec.configure(
mediaFormat, mediaFormat, frameProcessorChain.getInputSurface(), /* crypto= */ null, /* flags= */ 0);
frameProcessorChain.createInputSurface(),
/* crypto= */ null,
/* flags= */ 0);
mediaCodec.start(); mediaCodec.start();
int inputBufferIndex = mediaCodec.dequeueInputBuffer(DEQUEUE_TIMEOUT_US); int inputBufferIndex = mediaCodec.dequeueInputBuffer(DEQUEUE_TIMEOUT_US);
assertThat(inputBufferIndex).isNotEqualTo(MediaCodec.INFO_TRY_AGAIN_LATER); assertThat(inputBufferIndex).isNotEqualTo(MediaCodec.INFO_TRY_AGAIN_LATER);
......
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package androidx.media3.transformer;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import android.content.Context;
import android.graphics.SurfaceTexture;
import android.util.Size;
import android.view.Surface;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.collect.ImmutableList;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Test for {@link FrameProcessorChain#create(Context, float, List, List, Surface, boolean,
* Transformer.DebugViewProvider) creating} a {@link FrameProcessorChain}.
*/
@RunWith(AndroidJUnit4.class)
public final class FrameProcessorChainTest {
// TODO(b/212539951): Make this a robolectric test by e.g. updating shadows or adding a
// wrapper around GlUtil to allow the usage of mocks or fakes which don't need (Shadow)GLES20.
@Test
public void create_withSupportedPixelWidthHeightRatio_completesSuccessfully()
throws TransformationException {
Context context = getApplicationContext();
FrameProcessorChain.create(
context,
/* pixelWidthHeightRatio= */ 1,
/* frameProcessors= */ ImmutableList.of(),
/* sizes= */ ImmutableList.of(new Size(200, 100)),
/* outputSurface= */ new Surface(new SurfaceTexture(false)),
/* enableExperimentalHdrEditing= */ false,
Transformer.DebugViewProvider.NONE);
}
@Test
public void create_withUnsupportedPixelWidthHeightRatio_throwsException() {
Context context = getApplicationContext();
TransformationException exception =
assertThrows(
TransformationException.class,
() ->
FrameProcessorChain.create(
context,
/* pixelWidthHeightRatio= */ 2,
/* frameProcessors= */ ImmutableList.of(),
/* sizes= */ ImmutableList.of(new Size(200, 100)),
/* outputSurface= */ new Surface(new SurfaceTexture(false)),
/* enableExperimentalHdrEditing= */ false,
Transformer.DebugViewProvider.NONE));
assertThat(exception).hasCauseThat().isInstanceOf(UnsupportedOperationException.class);
assertThat(exception).hasCauseThat().hasMessageThat().contains("pixelWidthHeightRatio");
}
}
...@@ -110,24 +110,22 @@ import org.checkerframework.dataflow.qual.Pure; ...@@ -110,24 +110,22 @@ import org.checkerframework.dataflow.qual.Pure;
requestedEncoderFormat, requestedEncoderFormat,
encoderSupportedFormat)); encoderSupportedFormat));
// TODO(b/218488308): Allow the final GlFrameProcessor to be re-configured if its output size
// has to change due to encoder fallback or append another GlFrameProcessor.
frameProcessorSizes.set(
frameProcessorSizes.size() - 1,
new Size(encoderSupportedFormat.width, encoderSupportedFormat.height));
frameProcessorChain = frameProcessorChain =
FrameProcessorChain.create( new FrameProcessorChain(
context, context,
inputFormat.pixelWidthHeightRatio, inputFormat.pixelWidthHeightRatio,
frameProcessors, frameProcessors,
frameProcessorSizes, frameProcessorSizes,
/* outputSurface= */ encoder.getInputSurface(), transformationRequest.enableHdrEditing);
transformationRequest.enableHdrEditing, frameProcessorChain.configure(
debugViewProvider); /* outputSurface= */ encoder.getInputSurface(),
/* outputWidth= */ encoderSupportedFormat.width,
/* outputHeight= */ encoderSupportedFormat.height,
debugViewProvider.getDebugPreviewSurfaceView(
encoderSupportedFormat.width, encoderSupportedFormat.height));
decoder = decoder =
decoderFactory.createForVideoDecoding( decoderFactory.createForVideoDecoding(inputFormat, frameProcessorChain.getInputSurface());
inputFormat, frameProcessorChain.createInputSurface());
} }
@Override @Override
......
...@@ -15,8 +15,11 @@ ...@@ -15,8 +15,11 @@
*/ */
package androidx.media3.transformer; package androidx.media3.transformer;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import android.content.Context;
import android.util.Size; import android.util.Size;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
...@@ -27,11 +30,42 @@ import org.junit.runner.RunWith; ...@@ -27,11 +30,42 @@ import org.junit.runner.RunWith;
/** /**
* Robolectric tests for {@link FrameProcessorChain}. * Robolectric tests for {@link FrameProcessorChain}.
* *
* <p>See {@code FrameProcessorChainTest} and {@code FrameProcessorChainPixelTest} in the * <p>See {@code FrameProcessorChainPixelTest} in the androidTest directory for instrumentation
* androidTest directory for instrumentation tests. * tests.
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public final class FrameProcessorChainTest { public final class FrameProcessorChainTest {
@Test
public void construct_withSupportedPixelWidthHeightRatio_completesSuccessfully()
throws TransformationException {
Context context = getApplicationContext();
new FrameProcessorChain(
context,
/* pixelWidthHeightRatio= */ 1,
/* frameProcessors= */ ImmutableList.of(),
/* sizes= */ ImmutableList.of(new Size(200, 100)),
/* enableExperimentalHdrEditing= */ false);
}
@Test
public void construct_withUnsupportedPixelWidthHeightRatio_throwsException() {
Context context = getApplicationContext();
TransformationException exception =
assertThrows(
TransformationException.class,
() ->
new FrameProcessorChain(
context,
/* pixelWidthHeightRatio= */ 2,
/* frameProcessors= */ ImmutableList.of(),
/* sizes= */ ImmutableList.of(new Size(200, 100)),
/* enableExperimentalHdrEditing= */ false));
assertThat(exception).hasCauseThat().isInstanceOf(UnsupportedOperationException.class);
assertThat(exception).hasCauseThat().hasMessageThat().contains("pixelWidthHeightRatio");
}
@Test @Test
public void configureOutputDimensions_withEmptyList_returnsInputSize() { public void configureOutputDimensions_withEmptyList_returnsInputSize() {
......
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