Commit d37cf341 by hschlueter Committed by Marc Baechinger

Rename GlFrameProcessor to SingleFrameGlTextureProcessor.

Also update names of implementations to match design doc.
In follow-ups, SingleFrameGlTextureProcessor will become
an abstract implementation of a new GlTextureProcessor
interface.

Texture processor makes sense as it processes OpenGL textures.
The term frame processor will be used for something else in
follow-ups.

PiperOrigin-RevId: 451142085
parent 53b44524
Showing with 94 additions and 97 deletions
...@@ -30,7 +30,7 @@ import android.opengl.GLUtils; ...@@ -30,7 +30,7 @@ import android.opengl.GLUtils;
import android.util.Size; import android.util.Size;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.transformer.FrameProcessingException; import com.google.android.exoplayer2.transformer.FrameProcessingException;
import com.google.android.exoplayer2.transformer.GlFrameProcessor; import com.google.android.exoplayer2.transformer.SingleFrameGlTextureProcessor;
import com.google.android.exoplayer2.util.GlProgram; import com.google.android.exoplayer2.util.GlProgram;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import java.io.IOException; import java.io.IOException;
...@@ -38,13 +38,14 @@ import java.util.Locale; ...@@ -38,13 +38,14 @@ import java.util.Locale;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/** /**
* A {@link GlFrameProcessor} that overlays a bitmap with a logo and timer on each frame. * A {@link SingleFrameGlTextureProcessor} that overlays a bitmap with a logo and timer on each
* frame.
* *
* <p>The bitmap is drawn using an Android {@link Canvas}. * <p>The bitmap is drawn using an Android {@link Canvas}.
*/ */
// TODO(b/227625365): Delete this class and use a frame processor from the Transformer library, once // TODO(b/227625365): Delete this class and use a texture processor from the Transformer library,
// overlaying a bitmap and text is supported in Transformer. // once overlaying a bitmap and text is supported in Transformer.
/* package */ final class BitmapOverlayFrameProcessor implements GlFrameProcessor { /* package */ final class BitmapOverlayProcessor implements SingleFrameGlTextureProcessor {
static { static {
GlUtil.glAssertionsEnabled = true; GlUtil.glAssertionsEnabled = true;
} }
...@@ -65,7 +66,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -65,7 +66,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private @MonotonicNonNull Bitmap logoBitmap; private @MonotonicNonNull Bitmap logoBitmap;
private @MonotonicNonNull GlProgram glProgram; private @MonotonicNonNull GlProgram glProgram;
public BitmapOverlayFrameProcessor() { public BitmapOverlayProcessor() {
paint = new Paint(); paint = new Paint();
paint.setTextSize(64); paint.setTextSize(64);
paint.setAntiAlias(true); paint.setAntiAlias(true);
......
...@@ -22,17 +22,17 @@ import android.content.Context; ...@@ -22,17 +22,17 @@ import android.content.Context;
import android.opengl.GLES20; import android.opengl.GLES20;
import android.util.Size; import android.util.Size;
import com.google.android.exoplayer2.transformer.FrameProcessingException; import com.google.android.exoplayer2.transformer.FrameProcessingException;
import com.google.android.exoplayer2.transformer.GlFrameProcessor; import com.google.android.exoplayer2.transformer.SingleFrameGlTextureProcessor;
import com.google.android.exoplayer2.util.GlProgram; import com.google.android.exoplayer2.util.GlProgram;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import java.io.IOException; import java.io.IOException;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/** /**
* A {@link GlFrameProcessor} that periodically dims the frames such that pixels are darker the * A {@link SingleFrameGlTextureProcessor} that periodically dims the frames such that pixels are
* further they are away from the frame center. * darker the further they are away from the frame center.
*/ */
/* package */ final class PeriodicVignetteFrameProcessor implements GlFrameProcessor { /* package */ final class PeriodicVignetteProcessor implements SingleFrameGlTextureProcessor {
static { static {
GlUtil.glAssertionsEnabled = true; GlUtil.glAssertionsEnabled = true;
} }
...@@ -67,7 +67,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -67,7 +67,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
* @param maxInnerRadius The upper bound of the radius that is unaffected by the effect. * @param maxInnerRadius The upper bound of the radius that is unaffected by the effect.
* @param outerRadius The radius after which all pixels are black. * @param outerRadius The radius after which all pixels are black.
*/ */
public PeriodicVignetteFrameProcessor( public PeriodicVignetteProcessor(
float centerX, float centerY, float minInnerRadius, float maxInnerRadius, float outerRadius) { float centerX, float centerY, float minInnerRadius, float maxInnerRadius, float outerRadius) {
checkArgument(minInnerRadius <= maxInnerRadius); checkArgument(minInnerRadius <= maxInnerRadius);
checkArgument(maxInnerRadius <= outerRadius); checkArgument(maxInnerRadius <= outerRadius);
......
...@@ -39,8 +39,8 @@ import com.google.android.exoplayer2.MediaItem; ...@@ -39,8 +39,8 @@ import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.transformer.DefaultEncoderFactory; import com.google.android.exoplayer2.transformer.DefaultEncoderFactory;
import com.google.android.exoplayer2.transformer.EncoderSelector; import com.google.android.exoplayer2.transformer.EncoderSelector;
import com.google.android.exoplayer2.transformer.GlEffect; import com.google.android.exoplayer2.transformer.GlEffect;
import com.google.android.exoplayer2.transformer.GlFrameProcessor;
import com.google.android.exoplayer2.transformer.ProgressHolder; import com.google.android.exoplayer2.transformer.ProgressHolder;
import com.google.android.exoplayer2.transformer.SingleFrameGlTextureProcessor;
import com.google.android.exoplayer2.transformer.TransformationException; import com.google.android.exoplayer2.transformer.TransformationException;
import com.google.android.exoplayer2.transformer.TransformationRequest; import com.google.android.exoplayer2.transformer.TransformationRequest;
import com.google.android.exoplayer2.transformer.TransformationResult; import com.google.android.exoplayer2.transformer.TransformationResult;
...@@ -254,14 +254,13 @@ public final class TransformerActivity extends AppCompatActivity { ...@@ -254,14 +254,13 @@ public final class TransformerActivity extends AppCompatActivity {
if (selectedEffects[1]) { if (selectedEffects[1]) {
try { try {
Class<?> clazz = Class<?> clazz =
Class.forName( Class.forName("com.google.android.exoplayer2.transformerdemo.MediaPipeProcessor");
"com.google.android.exoplayer2.transformerdemo.MediaPipeFrameProcessor");
Constructor<?> constructor = Constructor<?> constructor =
clazz.getConstructor(String.class, String.class, String.class); clazz.getConstructor(String.class, String.class, String.class);
effects.add( effects.add(
() -> { () -> {
try { try {
return (GlFrameProcessor) return (SingleFrameGlTextureProcessor)
constructor.newInstance( constructor.newInstance(
/* graphName= */ "edge_detector_mediapipe_graph.binarypb", /* graphName= */ "edge_detector_mediapipe_graph.binarypb",
/* inputStreamName= */ "input_video", /* inputStreamName= */ "input_video",
...@@ -278,7 +277,7 @@ public final class TransformerActivity extends AppCompatActivity { ...@@ -278,7 +277,7 @@ public final class TransformerActivity extends AppCompatActivity {
if (selectedEffects[2]) { if (selectedEffects[2]) {
effects.add( effects.add(
() -> () ->
new PeriodicVignetteFrameProcessor( new PeriodicVignetteProcessor(
bundle.getFloat(ConfigurationActivity.PERIODIC_VIGNETTE_CENTER_X), bundle.getFloat(ConfigurationActivity.PERIODIC_VIGNETTE_CENTER_X),
bundle.getFloat(ConfigurationActivity.PERIODIC_VIGNETTE_CENTER_Y), bundle.getFloat(ConfigurationActivity.PERIODIC_VIGNETTE_CENTER_Y),
/* minInnerRadius= */ bundle.getFloat( /* minInnerRadius= */ bundle.getFloat(
...@@ -291,7 +290,7 @@ public final class TransformerActivity extends AppCompatActivity { ...@@ -291,7 +290,7 @@ public final class TransformerActivity extends AppCompatActivity {
effects.add(MatrixTransformationFactory.createSpin3dEffect()); effects.add(MatrixTransformationFactory.createSpin3dEffect());
} }
if (selectedEffects[4]) { if (selectedEffects[4]) {
effects.add(BitmapOverlayFrameProcessor::new); effects.add(BitmapOverlayProcessor::new);
} }
if (selectedEffects[5]) { if (selectedEffects[5]) {
effects.add(MatrixTransformationFactory.createZoomInTransition()); effects.add(MatrixTransformationFactory.createZoomInTransition());
......
...@@ -23,7 +23,7 @@ import android.opengl.EGL14; ...@@ -23,7 +23,7 @@ import android.opengl.EGL14;
import android.opengl.GLES20; import android.opengl.GLES20;
import android.util.Size; import android.util.Size;
import com.google.android.exoplayer2.transformer.FrameProcessingException; import com.google.android.exoplayer2.transformer.FrameProcessingException;
import com.google.android.exoplayer2.transformer.GlFrameProcessor; import com.google.android.exoplayer2.transformer.SingleFrameGlTextureProcessor;
import com.google.android.exoplayer2.util.ConditionVariable; import com.google.android.exoplayer2.util.ConditionVariable;
import com.google.android.exoplayer2.util.GlProgram; import com.google.android.exoplayer2.util.GlProgram;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
...@@ -40,7 +40,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -40,7 +40,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
* Runs a MediaPipe graph on input frames. The implementation is currently limited to graphs that * Runs a MediaPipe graph on input frames. The implementation is currently limited to graphs that
* can immediately produce one output frame per input frame. * can immediately produce one output frame per input frame.
*/ */
/* package */ final class MediaPipeFrameProcessor implements GlFrameProcessor { /* package */ final class MediaPipeProcessor implements SingleFrameGlTextureProcessor {
private static final LibraryLoader LOADER = private static final LibraryLoader LOADER =
new LibraryLoader("mediapipe_jni") { new LibraryLoader("mediapipe_jni") {
...@@ -77,14 +77,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -77,14 +77,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private @MonotonicNonNull RuntimeException frameProcessorPendingError; private @MonotonicNonNull RuntimeException frameProcessorPendingError;
/** /**
* Creates a new frame processor that wraps a MediaPipe graph. * Creates a new texture processor that wraps a MediaPipe graph.
* *
* @param graphName Name of a MediaPipe graph asset to load. * @param graphName Name of a MediaPipe graph asset to load.
* @param inputStreamName Name of the input video stream in the graph. * @param inputStreamName Name of the input video stream in the graph.
* @param outputStreamName Name of the input video stream in the graph. * @param outputStreamName Name of the input video stream in the graph.
*/ */
public MediaPipeFrameProcessor( public MediaPipeProcessor(String graphName, String inputStreamName, String outputStreamName) {
String graphName, String inputStreamName, String outputStreamName) {
checkState(LOADER.isAvailable()); checkState(LOADER.isAvailable());
this.graphName = graphName; this.graphName = graphName;
this.inputStreamName = inputStreamName; this.inputStreamName = inputStreamName;
...@@ -141,7 +140,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -141,7 +140,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
// Propagate the interrupted flag so the next blocking operation will throw. // Propagate the interrupted flag so the next blocking operation will throw.
// TODO(b/230469581): The next processor that runs will not have valid input due to returning // TODO(b/230469581): The next processor that runs will not have valid input due to returning
// early here. This could be fixed by checking for interruption in the outer loop that runs // early here. This could be fixed by checking for interruption in the outer loop that runs
// through the frame processors. // through the texture processors.
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
return; return;
} }
......
...@@ -40,7 +40,7 @@ import java.nio.ByteBuffer; ...@@ -40,7 +40,7 @@ import java.nio.ByteBuffer;
/** /**
* Utilities for instrumentation tests for the {@link FrameProcessorChain} and {@link * Utilities for instrumentation tests for the {@link FrameProcessorChain} and {@link
* GlFrameProcessor GlFrameProcessors}. * SingleFrameGlTextureProcessor SingleFrameGlTextureProcessors}.
*/ */
public class BitmapTestUtil { public class BitmapTestUtil {
...@@ -50,15 +50,15 @@ public class BitmapTestUtil { ...@@ -50,15 +50,15 @@ public class BitmapTestUtil {
* Maximum allowed average pixel difference between the expected and actual edited images in pixel * Maximum allowed average pixel difference between the expected and actual edited images in pixel
* difference-based tests. The value is chosen so that differences in decoder behavior across * difference-based tests. The value is chosen so that differences in decoder behavior across
* emulator versions don't affect whether the test passes for most emulators, but substantial * emulator versions don't affect whether the test passes for most emulators, but substantial
* distortions introduced by changes in the behavior of the {@link GlFrameProcessor * distortions introduced by changes in the behavior of the {@link SingleFrameGlTextureProcessor
* GlFrameProcessors} will cause the test to fail. * SingleFrameGlTextureProcessors} will cause the test to fail.
* *
* <p>To run pixel difference-based tests on physical devices, please use a value of 5f, rather * <p>To run pixel difference-based tests on physical devices, please use a value of 5f, rather
* than 0.1f. This higher value will ignore some very small errors, but will allow for some * than 0.1f. This higher value will ignore some very small errors, but will allow for some
* differences caused by graphics implementations to be ignored. When the difference is close to * differences caused by graphics implementations to be ignored. When the difference is close to
* the threshold, manually inspect expected/actual bitmaps to confirm failure, as it's possible * the threshold, manually inspect expected/actual bitmaps to confirm failure, as it's possible
* this is caused by a difference in the codec or graphics implementation as opposed to a {@link * this is caused by a difference in the codec or graphics implementation as opposed to a {@link
* GlFrameProcessor} issue. * SingleFrameGlTextureProcessor} issue.
*/ */
public static final float MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE = 0.1f; public static final float MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE = 0.1f;
......
...@@ -41,10 +41,10 @@ public final class FrameProcessorChainTest { ...@@ -41,10 +41,10 @@ public final class FrameProcessorChainTest {
public void getOutputSize_noOperation_returnsInputSize() throws Exception { public void getOutputSize_noOperation_returnsInputSize() throws Exception {
Size inputSize = new Size(200, 100); Size inputSize = new Size(200, 100);
FrameProcessorChain frameProcessorChain = FrameProcessorChain frameProcessorChain =
createFrameProcessorChainWithFakeFrameProcessors( createFrameProcessorChainWithFakeTextureProcessors(
/* pixelWidthHeightRatio= */ 1f, /* pixelWidthHeightRatio= */ 1f,
inputSize, inputSize,
/* frameProcessorOutputSizes= */ ImmutableList.of()); /* textureProcessorOutputSizes= */ ImmutableList.of());
Size outputSize = frameProcessorChain.getOutputSize(); Size outputSize = frameProcessorChain.getOutputSize();
...@@ -56,10 +56,10 @@ public final class FrameProcessorChainTest { ...@@ -56,10 +56,10 @@ public final class FrameProcessorChainTest {
public void getOutputSize_withWidePixels_returnsWiderOutputSize() throws Exception { public void getOutputSize_withWidePixels_returnsWiderOutputSize() throws Exception {
Size inputSize = new Size(200, 100); Size inputSize = new Size(200, 100);
FrameProcessorChain frameProcessorChain = FrameProcessorChain frameProcessorChain =
createFrameProcessorChainWithFakeFrameProcessors( createFrameProcessorChainWithFakeTextureProcessors(
/* pixelWidthHeightRatio= */ 2f, /* pixelWidthHeightRatio= */ 2f,
inputSize, inputSize,
/* frameProcessorOutputSizes= */ ImmutableList.of()); /* textureProcessorOutputSizes= */ ImmutableList.of());
Size outputSize = frameProcessorChain.getOutputSize(); Size outputSize = frameProcessorChain.getOutputSize();
...@@ -71,10 +71,10 @@ public final class FrameProcessorChainTest { ...@@ -71,10 +71,10 @@ public final class FrameProcessorChainTest {
public void getOutputSize_withTallPixels_returnsTallerOutputSize() throws Exception { public void getOutputSize_withTallPixels_returnsTallerOutputSize() throws Exception {
Size inputSize = new Size(200, 100); Size inputSize = new Size(200, 100);
FrameProcessorChain frameProcessorChain = FrameProcessorChain frameProcessorChain =
createFrameProcessorChainWithFakeFrameProcessors( createFrameProcessorChainWithFakeTextureProcessors(
/* pixelWidthHeightRatio= */ .5f, /* pixelWidthHeightRatio= */ .5f,
inputSize, inputSize,
/* frameProcessorOutputSizes= */ ImmutableList.of()); /* textureProcessorOutputSizes= */ ImmutableList.of());
Size outputSize = frameProcessorChain.getOutputSize(); Size outputSize = frameProcessorChain.getOutputSize();
...@@ -83,32 +83,32 @@ public final class FrameProcessorChainTest { ...@@ -83,32 +83,32 @@ public final class FrameProcessorChainTest {
} }
@Test @Test
public void getOutputSize_withOneFrameProcessor_returnsItsOutputSize() throws Exception { public void getOutputSize_withOneTextureProcessor_returnsItsOutputSize() throws Exception {
Size inputSize = new Size(200, 100); Size inputSize = new Size(200, 100);
Size frameProcessorOutputSize = new Size(300, 250); Size textureProcessorOutputSize = new Size(300, 250);
FrameProcessorChain frameProcessorChain = FrameProcessorChain frameProcessorChain =
createFrameProcessorChainWithFakeFrameProcessors( createFrameProcessorChainWithFakeTextureProcessors(
/* pixelWidthHeightRatio= */ 1f, /* pixelWidthHeightRatio= */ 1f,
inputSize, inputSize,
/* frameProcessorOutputSizes= */ ImmutableList.of(frameProcessorOutputSize)); /* textureProcessorOutputSizes= */ ImmutableList.of(textureProcessorOutputSize));
Size frameProcessorChainOutputSize = frameProcessorChain.getOutputSize(); Size frameProcessorChainOutputSize = frameProcessorChain.getOutputSize();
assertThat(frameProcessorChainOutputSize).isEqualTo(frameProcessorOutputSize); assertThat(frameProcessorChainOutputSize).isEqualTo(textureProcessorOutputSize);
assertThat(frameProcessingException.get()).isNull(); assertThat(frameProcessingException.get()).isNull();
} }
@Test @Test
public void getOutputSize_withThreeFrameProcessors_returnsLastOutputSize() throws Exception { public void getOutputSize_withThreeTextureProcessors_returnsLastOutputSize() throws Exception {
Size inputSize = new Size(200, 100); Size inputSize = new Size(200, 100);
Size outputSize1 = new Size(300, 250); Size outputSize1 = new Size(300, 250);
Size outputSize2 = new Size(400, 244); Size outputSize2 = new Size(400, 244);
Size outputSize3 = new Size(150, 160); Size outputSize3 = new Size(150, 160);
FrameProcessorChain frameProcessorChain = FrameProcessorChain frameProcessorChain =
createFrameProcessorChainWithFakeFrameProcessors( createFrameProcessorChainWithFakeTextureProcessors(
/* pixelWidthHeightRatio= */ 1f, /* pixelWidthHeightRatio= */ 1f,
inputSize, inputSize,
/* frameProcessorOutputSizes= */ ImmutableList.of( /* textureProcessorOutputSizes= */ ImmutableList.of(
outputSize1, outputSize2, outputSize3)); outputSize1, outputSize2, outputSize3));
Size frameProcessorChainOutputSize = frameProcessorChain.getOutputSize(); Size frameProcessorChainOutputSize = frameProcessorChain.getOutputSize();
...@@ -117,12 +117,12 @@ public final class FrameProcessorChainTest { ...@@ -117,12 +117,12 @@ public final class FrameProcessorChainTest {
assertThat(frameProcessingException.get()).isNull(); assertThat(frameProcessingException.get()).isNull();
} }
private FrameProcessorChain createFrameProcessorChainWithFakeFrameProcessors( private FrameProcessorChain createFrameProcessorChainWithFakeTextureProcessors(
float pixelWidthHeightRatio, Size inputSize, List<Size> frameProcessorOutputSizes) float pixelWidthHeightRatio, Size inputSize, List<Size> textureProcessorOutputSizes)
throws FrameProcessingException { throws FrameProcessingException {
ImmutableList.Builder<GlEffect> effects = new ImmutableList.Builder<>(); ImmutableList.Builder<GlEffect> effects = new ImmutableList.Builder<>();
for (Size element : frameProcessorOutputSizes) { for (Size element : textureProcessorOutputSizes) {
effects.add(() -> new FakeFrameProcessor(element)); effects.add(() -> new FakeTextureProcessor(element));
} }
return FrameProcessorChain.create( return FrameProcessorChain.create(
getApplicationContext(), getApplicationContext(),
...@@ -134,11 +134,11 @@ public final class FrameProcessorChainTest { ...@@ -134,11 +134,11 @@ public final class FrameProcessorChainTest {
/* enableExperimentalHdrEditing= */ false); /* enableExperimentalHdrEditing= */ false);
} }
private static class FakeFrameProcessor implements GlFrameProcessor { private static class FakeTextureProcessor implements SingleFrameGlTextureProcessor {
private final Size outputSize; private final Size outputSize;
private FakeFrameProcessor(Size outputSize) { private FakeTextureProcessor(Size outputSize) {
this.outputSize = outputSize; this.outputSize = outputSize;
} }
......
...@@ -34,7 +34,7 @@ import org.junit.Test; ...@@ -34,7 +34,7 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** /**
* Pixel test for frame processing via {@link MatrixTransformationFrameProcessor}. * Pixel test for texture processing via {@link MatrixTransformationProcessor}.
* *
* <p>Expected images are taken from an emulator, so tests on different emulators or physical * <p>Expected images are taken from an emulator, so tests on different emulators or physical
* devices may fail. To test on other devices, please increase the {@link * devices may fail. To test on other devices, please increase the {@link
...@@ -42,7 +42,7 @@ import org.junit.runner.RunWith; ...@@ -42,7 +42,7 @@ import org.junit.runner.RunWith;
* as recommended in {@link FrameProcessorChainPixelTest}. * as recommended in {@link FrameProcessorChainPixelTest}.
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public final class MatrixTransformationFrameProcessorPixelTest { public final class MatrixTransformationProcessorPixelTest {
public static final String ORIGINAL_PNG_ASSET_PATH = public static final String ORIGINAL_PNG_ASSET_PATH =
"media/bitmap/sample_mp4_first_frame/original.png"; "media/bitmap/sample_mp4_first_frame/original.png";
public static final String TRANSLATE_RIGHT_PNG_ASSET_PATH = public static final String TRANSLATE_RIGHT_PNG_ASSET_PATH =
...@@ -58,7 +58,7 @@ public final class MatrixTransformationFrameProcessorPixelTest { ...@@ -58,7 +58,7 @@ public final class MatrixTransformationFrameProcessorPixelTest {
private final EGLDisplay eglDisplay = GlUtil.createEglDisplay(); private final EGLDisplay eglDisplay = GlUtil.createEglDisplay();
private final EGLContext eglContext = GlUtil.createEglContext(eglDisplay); private final EGLContext eglContext = GlUtil.createEglContext(eglDisplay);
private @MonotonicNonNull GlFrameProcessor matrixTransformationFrameProcessor; private @MonotonicNonNull SingleFrameGlTextureProcessor matrixTransformationProcessor;
private int inputTexId; private int inputTexId;
private int outputTexId; private int outputTexId;
private int width; private int width;
...@@ -80,8 +80,8 @@ public final class MatrixTransformationFrameProcessorPixelTest { ...@@ -80,8 +80,8 @@ public final class MatrixTransformationFrameProcessorPixelTest {
@After @After
public void release() { public void release() {
if (matrixTransformationFrameProcessor != null) { if (matrixTransformationProcessor != null) {
matrixTransformationFrameProcessor.release(); matrixTransformationProcessor.release();
} }
GlUtil.destroyEglContext(eglDisplay, eglContext); GlUtil.destroyEglContext(eglDisplay, eglContext);
} }
...@@ -90,13 +90,12 @@ public final class MatrixTransformationFrameProcessorPixelTest { ...@@ -90,13 +90,12 @@ public final class MatrixTransformationFrameProcessorPixelTest {
public void drawFrame_noEdits_producesExpectedOutput() throws Exception { public void drawFrame_noEdits_producesExpectedOutput() throws Exception {
String testId = "drawFrame_noEdits"; String testId = "drawFrame_noEdits";
Matrix identityMatrix = new Matrix(); Matrix identityMatrix = new Matrix();
matrixTransformationFrameProcessor = matrixTransformationProcessor =
new MatrixTransformationFrameProcessor((long presentationTimeUs) -> identityMatrix); new MatrixTransformationProcessor((long presentationTimeUs) -> identityMatrix);
matrixTransformationFrameProcessor.initialize( matrixTransformationProcessor.initialize(getApplicationContext(), inputTexId, width, height);
getApplicationContext(), inputTexId, width, height);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH); Bitmap expectedBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH);
matrixTransformationFrameProcessor.drawFrame(/* presentationTimeUs= */ 0); matrixTransformationProcessor.drawFrame(/* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height); BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height);
...@@ -114,13 +113,12 @@ public final class MatrixTransformationFrameProcessorPixelTest { ...@@ -114,13 +113,12 @@ public final class MatrixTransformationFrameProcessorPixelTest {
String testId = "drawFrame_translateRight"; String testId = "drawFrame_translateRight";
Matrix translateRightMatrix = new Matrix(); Matrix translateRightMatrix = new Matrix();
translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0); translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0);
matrixTransformationFrameProcessor = matrixTransformationProcessor =
new MatrixTransformationFrameProcessor((long presentationTimeUs) -> translateRightMatrix); new MatrixTransformationProcessor((long presentationTimeUs) -> translateRightMatrix);
matrixTransformationFrameProcessor.initialize( matrixTransformationProcessor.initialize(getApplicationContext(), inputTexId, width, height);
getApplicationContext(), inputTexId, width, height);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(TRANSLATE_RIGHT_PNG_ASSET_PATH); Bitmap expectedBitmap = BitmapTestUtil.readBitmap(TRANSLATE_RIGHT_PNG_ASSET_PATH);
matrixTransformationFrameProcessor.drawFrame(/* presentationTimeUs= */ 0); matrixTransformationProcessor.drawFrame(/* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height); BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height);
...@@ -138,13 +136,12 @@ public final class MatrixTransformationFrameProcessorPixelTest { ...@@ -138,13 +136,12 @@ public final class MatrixTransformationFrameProcessorPixelTest {
String testId = "drawFrame_scaleNarrow"; String testId = "drawFrame_scaleNarrow";
Matrix scaleNarrowMatrix = new Matrix(); Matrix scaleNarrowMatrix = new Matrix();
scaleNarrowMatrix.postScale(.5f, 1.2f); scaleNarrowMatrix.postScale(.5f, 1.2f);
matrixTransformationFrameProcessor = matrixTransformationProcessor =
new MatrixTransformationFrameProcessor((long presentationTimeUs) -> scaleNarrowMatrix); new MatrixTransformationProcessor((long presentationTimeUs) -> scaleNarrowMatrix);
matrixTransformationFrameProcessor.initialize( matrixTransformationProcessor.initialize(getApplicationContext(), inputTexId, width, height);
getApplicationContext(), inputTexId, width, height);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(SCALE_NARROW_PNG_ASSET_PATH); Bitmap expectedBitmap = BitmapTestUtil.readBitmap(SCALE_NARROW_PNG_ASSET_PATH);
matrixTransformationFrameProcessor.drawFrame(/* presentationTimeUs= */ 0); matrixTransformationProcessor.drawFrame(/* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height); BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height);
...@@ -162,13 +159,12 @@ public final class MatrixTransformationFrameProcessorPixelTest { ...@@ -162,13 +159,12 @@ public final class MatrixTransformationFrameProcessorPixelTest {
String testId = "drawFrame_rotate90"; String testId = "drawFrame_rotate90";
Matrix rotate90Matrix = new Matrix(); Matrix rotate90Matrix = new Matrix();
rotate90Matrix.postRotate(/* degrees= */ 90); rotate90Matrix.postRotate(/* degrees= */ 90);
matrixTransformationFrameProcessor = matrixTransformationProcessor =
new MatrixTransformationFrameProcessor((long presentationTimeUs) -> rotate90Matrix); new MatrixTransformationProcessor((long presentationTimeUs) -> rotate90Matrix);
matrixTransformationFrameProcessor.initialize( matrixTransformationProcessor.initialize(getApplicationContext(), inputTexId, width, height);
getApplicationContext(), inputTexId, width, height);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(ROTATE_90_PNG_ASSET_PATH); Bitmap expectedBitmap = BitmapTestUtil.readBitmap(ROTATE_90_PNG_ASSET_PATH);
matrixTransformationFrameProcessor.drawFrame(/* presentationTimeUs= */ 0); matrixTransformationProcessor.drawFrame(/* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height); BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height);
......
...@@ -19,7 +19,6 @@ import static com.google.android.exoplayer2.util.Assertions.checkArgument; ...@@ -19,7 +19,6 @@ import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import static com.google.android.exoplayer2.util.Assertions.checkState; import static com.google.android.exoplayer2.util.Assertions.checkState;
import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull; import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull;
import android.content.Context;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.util.Size; import android.util.Size;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
...@@ -77,8 +76,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -77,8 +76,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
* *
* <p>Return values may be {@code 0} or {@code 90} degrees. * <p>Return values may be {@code 0} or {@code 90} degrees.
* *
* <p>The frame processor must be {@linkplain GlFrameProcessor#initialize(Context, int, int, int) * <p>Should only be called after {@linkplain #configure(int, int) configuration}.
* initialized}.
*/ */
public int getOutputRotationDegrees() { public int getOutputRotationDegrees() {
checkState( checkState(
......
...@@ -27,7 +27,7 @@ import java.io.IOException; ...@@ -27,7 +27,7 @@ import java.io.IOException;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/** Copies frames from an external texture and applies color transformations for HDR if needed. */ /** Copies frames from an external texture and applies color transformations for HDR if needed. */
/* package */ class ExternalCopyFrameProcessor implements GlFrameProcessor { /* package */ class ExternalTextureProcessor implements SingleFrameGlTextureProcessor {
static { static {
GlUtil.glAssertionsEnabled = true; GlUtil.glAssertionsEnabled = true;
...@@ -54,7 +54,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -54,7 +54,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private @MonotonicNonNull Size size; private @MonotonicNonNull Size size;
private @MonotonicNonNull GlProgram glProgram; private @MonotonicNonNull GlProgram glProgram;
public ExternalCopyFrameProcessor(boolean enableExperimentalHdrEditing) { public ExternalTextureProcessor(boolean enableExperimentalHdrEditing) {
this.enableExperimentalHdrEditing = enableExperimentalHdrEditing; this.enableExperimentalHdrEditing = enableExperimentalHdrEditing;
} }
......
...@@ -16,13 +16,15 @@ ...@@ -16,13 +16,15 @@
package com.google.android.exoplayer2.transformer; package com.google.android.exoplayer2.transformer;
/** /**
* Interface for a video frame effect with a {@link GlFrameProcessor} implementation. * Interface for a video frame effect with a {@link SingleFrameGlTextureProcessor} implementation.
* *
* <p>Implementations contain information specifying the effect and can be {@linkplain * <p>Implementations contain information specifying the effect and can be {@linkplain
* #toGlFrameProcessor() converted} to a {@link GlFrameProcessor} which applies the effect. * #toGlTextureProcessor() converted} to a {@link SingleFrameGlTextureProcessor} which applies the
* effect.
*/ */
public interface GlEffect { public interface GlEffect {
/** Returns a {@link GlFrameProcessor} that applies the the effect. */ /** Returns a {@link SingleFrameGlTextureProcessor} that applies the effect. */
GlFrameProcessor toGlFrameProcessor(); // TODO(b/227625423): use GlTextureProcessor here once this interface exists.
SingleFrameGlTextureProcessor toGlTextureProcessor();
} }
...@@ -47,7 +47,7 @@ public interface GlMatrixTransformation extends GlEffect { ...@@ -47,7 +47,7 @@ public interface GlMatrixTransformation extends GlEffect {
float[] getGlMatrixArray(long presentationTimeUs); float[] getGlMatrixArray(long presentationTimeUs);
@Override @Override
default GlFrameProcessor toGlFrameProcessor() { default SingleFrameGlTextureProcessor toGlTextureProcessor() {
return new MatrixTransformationFrameProcessor(this); return new MatrixTransformationProcessor(this);
} }
} }
...@@ -41,7 +41,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -41,7 +41,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
* <p>The background color of the output frame will be black. * <p>The background color of the output frame will be black.
*/ */
@SuppressWarnings("FunctionalInterfaceClash") // b/228192298 @SuppressWarnings("FunctionalInterfaceClash") // b/228192298
/* package */ final class MatrixTransformationFrameProcessor implements GlFrameProcessor { /* package */ final class MatrixTransformationProcessor implements SingleFrameGlTextureProcessor {
static { static {
GlUtil.glAssertionsEnabled = true; GlUtil.glAssertionsEnabled = true;
...@@ -91,7 +91,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -91,7 +91,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
* @param matrixTransformation A {@link MatrixTransformation} that specifies the transformation * @param matrixTransformation A {@link MatrixTransformation} that specifies the transformation
* matrix to use for each frame. * matrix to use for each frame.
*/ */
public MatrixTransformationFrameProcessor(MatrixTransformation matrixTransformation) { public MatrixTransformationProcessor(MatrixTransformation matrixTransformation) {
this(ImmutableList.of(matrixTransformation)); this(ImmutableList.of(matrixTransformation));
} }
...@@ -101,7 +101,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -101,7 +101,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
* @param matrixTransformation A {@link GlMatrixTransformation} that specifies the transformation * @param matrixTransformation A {@link GlMatrixTransformation} that specifies the transformation
* matrix to use for each frame. * matrix to use for each frame.
*/ */
public MatrixTransformationFrameProcessor(GlMatrixTransformation matrixTransformation) { public MatrixTransformationProcessor(GlMatrixTransformation matrixTransformation) {
this(ImmutableList.of(matrixTransformation)); this(ImmutableList.of(matrixTransformation));
} }
...@@ -111,7 +111,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -111,7 +111,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
* @param matrixTransformations The {@link GlMatrixTransformation GlMatrixTransformations} to * @param matrixTransformations The {@link GlMatrixTransformation GlMatrixTransformations} to
* apply to each frame in order. * apply to each frame in order.
*/ */
public MatrixTransformationFrameProcessor( public MatrixTransformationProcessor(
ImmutableList<GlMatrixTransformation> matrixTransformations) { ImmutableList<GlMatrixTransformation> matrixTransformations) {
this.matrixTransformations = matrixTransformations; this.matrixTransformations = matrixTransformations;
......
...@@ -32,7 +32,9 @@ import java.io.IOException; ...@@ -32,7 +32,9 @@ import java.io.IOException;
* <li>{@link #release()}, upon conclusion of processing. * <li>{@link #release()}, upon conclusion of processing.
* </ol> * </ol>
*/ */
public interface GlFrameProcessor { // TODO(b/227625423): Add GlTextureProcessor interface for async texture processors and make this an
// abstract class with a default implementation of GlTextureProcessor methods.
public interface SingleFrameGlTextureProcessor {
/** /**
* Performs all initialization that requires OpenGL, such as, loading and compiling a GLSL shader * Performs all initialization that requires OpenGL, such as, loading and compiling a GLSL shader
...@@ -52,7 +54,7 @@ public interface GlFrameProcessor { ...@@ -52,7 +54,7 @@ public interface GlFrameProcessor {
/** /**
* Returns the output {@link Size} of frames processed through {@link #drawFrame(long)}. * Returns the output {@link Size} of frames processed through {@link #drawFrame(long)}.
* *
* <p>This method may only be called after the frame processor has been {@link * <p>This method may only be called after the texture processor has been {@link
* #initialize(Context, int, int, int) initialized}. * #initialize(Context, int, int, int) initialized}.
*/ */
Size getOutputSize(); Size getOutputSize();
...@@ -60,7 +62,7 @@ public interface GlFrameProcessor { ...@@ -60,7 +62,7 @@ public interface GlFrameProcessor {
/** /**
* Draws one frame. * Draws one frame.
* *
* <p>This method may only be called after the frame processor has been {@link * <p>This method may only be called after the texture processor has been {@link
* #initialize(Context, int, int, int) initialized}. The caller is responsible for focussing the * #initialize(Context, int, int, int) initialized}. The caller is responsible for focussing the
* correct render target before calling this method. * correct render target before calling this method.
* *
......
...@@ -27,7 +27,7 @@ import org.junit.runner.RunWith; ...@@ -27,7 +27,7 @@ import org.junit.runner.RunWith;
/** /**
* Unit tests for {@link Presentation}. * Unit tests for {@link Presentation}.
* *
* <p>See {@code PresentationFrameProcessorPixelTest} for pixel tests testing {@link Presentation}. * <p>See {@code PresentationPixelTest} for pixel tests testing {@link Presentation}.
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public final class PresentationTest { public final class PresentationTest {
...@@ -161,27 +161,27 @@ public final class PresentationTest { ...@@ -161,27 +161,27 @@ public final class PresentationTest {
@Test @Test
public void configure_setAspectRatioAndCrop_throwsIllegalStateException() { public void configure_setAspectRatioAndCrop_throwsIllegalStateException() {
Presentation.Builder presentationFrameProcessor = Presentation.Builder presentationBuilder =
new Presentation.Builder() new Presentation.Builder()
.setAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT); .setAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT);
assertThrows( assertThrows(
IllegalStateException.class, IllegalStateException.class,
() -> () ->
presentationFrameProcessor.setCrop( presentationBuilder.setCrop(
/* left= */ -.5f, /* right= */ .5f, /* bottom= */ .5f, /* top= */ 1f)); /* left= */ -.5f, /* right= */ .5f, /* bottom= */ .5f, /* top= */ 1f));
} }
@Test @Test
public void configure_setCropAndAspectRatio_throwsIllegalStateException() { public void configure_setCropAndAspectRatio_throwsIllegalStateException() {
Presentation.Builder presentationFrameProcessor = Presentation.Builder presentationBuilder =
new Presentation.Builder() new Presentation.Builder()
.setCrop(/* left= */ -.5f, /* right= */ .5f, /* bottom= */ .5f, /* top= */ 1f); .setCrop(/* left= */ -.5f, /* right= */ .5f, /* bottom= */ .5f, /* top= */ 1f);
assertThrows( assertThrows(
IllegalStateException.class, IllegalStateException.class,
() -> () ->
presentationFrameProcessor.setAspectRatio( presentationBuilder.setAspectRatio(
/* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT)); /* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT));
} }
} }
...@@ -25,8 +25,8 @@ import org.junit.runner.RunWith; ...@@ -25,8 +25,8 @@ import org.junit.runner.RunWith;
/** /**
* Unit tests for {@link ScaleToFitTransformation}. * Unit tests for {@link ScaleToFitTransformation}.
* *
* <p>See {@code MatrixTransformationFrameProcessorPixelTest} for pixel tests testing {@link * <p>See {@code MatrixTransformationPixelTest} for pixel tests testing {@link
* MatrixTransformationFrameProcessor} given a transformation matrix. * MatrixTransformationProcessor} given a transformation matrix.
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public final class ScaleToFitTransformationTest { public final class ScaleToFitTransformationTest {
......
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