Replace Size with Pair in effects.

Size requires API 21. Using Pair instead will allow effects to be
used from API 18 during previewing once they are moved out of
transformer.

PiperOrigin-RevId: 463206474
This commit is contained in:
Googler 2022-07-25 23:39:59 +00:00 committed by Marc Baechinger
parent 4ac177c337
commit b994f8bfa0
18 changed files with 146 additions and 139 deletions

View file

@ -28,7 +28,7 @@ import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.opengl.GLES20;
import android.opengl.GLUtils;
import android.util.Size;
import android.util.Pair;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.transformer.FrameProcessingException;
import com.google.android.exoplayer2.transformer.SingleFrameGlTextureProcessor;
@ -111,7 +111,7 @@ import java.util.Locale;
}
@Override
public Size configure(int inputWidth, int inputHeight) {
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
if (inputWidth > inputHeight) {
bitmapScaleX = inputWidth / (float) inputHeight;
bitmapScaleY = 1f;
@ -123,7 +123,7 @@ import java.util.Locale;
glProgram.setFloatUniform("uScaleX", bitmapScaleX);
glProgram.setFloatUniform("uScaleY", bitmapScaleY);
return new Size(inputWidth, inputHeight);
return Pair.create(inputWidth, inputHeight);
}
@Override

View file

@ -19,7 +19,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import android.content.Context;
import android.opengl.GLES20;
import android.util.Size;
import android.util.Pair;
import com.google.android.exoplayer2.transformer.FrameProcessingException;
import com.google.android.exoplayer2.transformer.SingleFrameGlTextureProcessor;
import com.google.android.exoplayer2.util.GlProgram;
@ -90,8 +90,8 @@ import java.io.IOException;
}
@Override
public Size configure(int inputWidth, int inputHeight) {
return new Size(inputWidth, inputHeight);
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
return Pair.create(inputWidth, inputHeight);
}
@Override

View file

@ -27,7 +27,7 @@ import android.graphics.Color;
import android.opengl.EGLContext;
import android.opengl.EGLDisplay;
import android.opengl.EGLSurface;
import android.util.Size;
import android.util.Pair;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.util.GlUtil;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@ -93,14 +93,14 @@ public class ContrastProcessorPixelTest {
String testId = "drawFrame_noContrastChange";
contrastProcessor =
new Contrast(/* contrast= */ 0.0f).toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(EXOPLAYER_LOGO_PNG_ASSET_PATH);
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs = */ 0);
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
float averagePixelAbsoluteDifference =
@ -114,8 +114,8 @@ public class ContrastProcessorPixelTest {
String testId = "drawFrame_minimumContrast";
contrastProcessor =
new Contrast(/* contrast= */ -1.0f).toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap =
BitmapTestUtil.createArgb8888BitmapWithSolidColor(
inputWidth,
@ -126,7 +126,7 @@ public class ContrastProcessorPixelTest {
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs = */ 0);
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
float averagePixelAbsoluteDifference =
@ -141,14 +141,14 @@ public class ContrastProcessorPixelTest {
String testId = "drawFrame_decreaseContrast";
contrastProcessor =
new Contrast(/* contrast= */ -0.75f).toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap originalBitmap = BitmapTestUtil.readBitmap(EXOPLAYER_LOGO_PNG_ASSET_PATH);
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
assertIncreasedOrDecreasedContrast(originalBitmap, actualBitmap, /* increased= */ false);
@ -160,14 +160,14 @@ public class ContrastProcessorPixelTest {
String testId = "drawFrame_increaseContrast";
contrastProcessor =
new Contrast(/* contrast= */ 0.75f).toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap originalBitmap = BitmapTestUtil.readBitmap(EXOPLAYER_LOGO_PNG_ASSET_PATH);
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
assertIncreasedOrDecreasedContrast(originalBitmap, actualBitmap, /* increased= */ true);
@ -178,14 +178,14 @@ public class ContrastProcessorPixelTest {
String testId = "drawFrame_maximumContrast";
contrastProcessor =
new Contrast(/* contrast= */ 1.0f).toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(MAXIMUM_CONTRAST_PNG_ASSET_PATH);
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs = */ 0);
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
float averagePixelAbsoluteDifference =

View file

@ -25,7 +25,7 @@ import android.graphics.Bitmap;
import android.opengl.EGLContext;
import android.opengl.EGLDisplay;
import android.opengl.EGLSurface;
import android.util.Size;
import android.util.Pair;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.util.GlUtil;
import java.io.IOException;
@ -90,14 +90,14 @@ public final class CropPixelTest {
cropTextureProcessor =
new Crop(/* left= */ -1, /* right= */ 1, /* bottom= */ -1, /* top= */ 1)
.toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Pair<Integer, Integer> outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH);
cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap);
@ -114,14 +114,14 @@ public final class CropPixelTest {
cropTextureProcessor =
new Crop(/* left= */ -.9f, /* right= */ .1f, /* bottom= */ -1f, /* top= */ .5f)
.toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Pair<Integer, Integer> outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(CROP_SMALLER_PNG_ASSET_PATH);
cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap);
@ -138,14 +138,14 @@ public final class CropPixelTest {
cropTextureProcessor =
new Crop(/* left= */ -2f, /* right= */ 2f, /* bottom= */ -1f, /* top= */ 2f)
.toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Pair<Integer, Integer> outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(CROP_LARGER_PNG_ASSET_PATH);
cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap);

View file

@ -32,7 +32,7 @@ import android.media.ImageReader;
import android.media.MediaCodec;
import android.media.MediaExtractor;
import android.media.MediaFormat;
import android.util.Size;
import android.util.Pair;
import androidx.annotation.Nullable;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.util.MimeTypes;
@ -463,14 +463,14 @@ public final class GlEffectsFrameProcessorPixelTest {
}
@Override
public Size configure(int inputWidth, int inputHeight) {
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
adjustedTransformationMatrix = new Matrix();
adjustedTransformationMatrix.postRotate(degrees);
float inputAspectRatio = (float) inputWidth / inputHeight;
adjustedTransformationMatrix.preScale(/* sx= */ inputAspectRatio, /* sy= */ 1f);
adjustedTransformationMatrix.postScale(/* sx= */ 1f / inputAspectRatio, /* sy= */ 1f);
return new Size(inputWidth, inputHeight);
return Pair.create(inputWidth, inputHeight);
}
@Override

View file

@ -25,7 +25,7 @@ import android.graphics.Bitmap;
import android.opengl.EGLContext;
import android.opengl.EGLDisplay;
import android.opengl.EGLSurface;
import android.util.Size;
import android.util.Pair;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.GlUtil;
@ -99,14 +99,15 @@ public final class PresentationPixelTest {
presentationTextureProcessor =
Presentation.createForHeight(C.LENGTH_UNSET)
.toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Pair<Integer, Integer> outputSize =
presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH);
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap);
@ -124,15 +125,16 @@ public final class PresentationPixelTest {
presentationTextureProcessor =
Presentation.createForAspectRatio(/* aspectRatio= */ 1f, Presentation.LAYOUT_SCALE_TO_FIT)
.toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Pair<Integer, Integer> outputSize =
presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap =
BitmapTestUtil.readBitmap(ASPECT_RATIO_SCALE_TO_FIT_NARROW_PNG_ASSET_PATH);
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap);
@ -150,15 +152,16 @@ public final class PresentationPixelTest {
presentationTextureProcessor =
Presentation.createForAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT)
.toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Pair<Integer, Integer> outputSize =
presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap =
BitmapTestUtil.readBitmap(ASPECT_RATIO_SCALE_TO_FIT_WIDE_PNG_ASSET_PATH);
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap);
@ -177,15 +180,16 @@ public final class PresentationPixelTest {
Presentation.createForAspectRatio(
/* aspectRatio= */ 1f, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP)
.toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Pair<Integer, Integer> outputSize =
presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap =
BitmapTestUtil.readBitmap(ASPECT_RATIO_SCALE_TO_FIT_WITH_CROP_NARROW_PNG_ASSET_PATH);
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap);
@ -204,15 +208,16 @@ public final class PresentationPixelTest {
Presentation.createForAspectRatio(
/* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP)
.toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Pair<Integer, Integer> outputSize =
presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap =
BitmapTestUtil.readBitmap(ASPECT_RATIO_SCALE_TO_FIT_WITH_CROP_WIDE_PNG_ASSET_PATH);
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap);
@ -230,15 +235,16 @@ public final class PresentationPixelTest {
presentationTextureProcessor =
Presentation.createForAspectRatio(/* aspectRatio= */ 1f, Presentation.LAYOUT_STRETCH_TO_FIT)
.toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Pair<Integer, Integer> outputSize =
presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap =
BitmapTestUtil.readBitmap(ASPECT_RATIO_STRETCH_TO_FIT_NARROW_PNG_ASSET_PATH);
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap);
@ -256,15 +262,16 @@ public final class PresentationPixelTest {
presentationTextureProcessor =
Presentation.createForAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_STRETCH_TO_FIT)
.toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Pair<Integer, Integer> outputSize =
presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap =
BitmapTestUtil.readBitmap(ASPECT_RATIO_STRETCH_TO_FIT_WIDE_PNG_ASSET_PATH);
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap);

View file

@ -19,7 +19,7 @@ package com.google.android.exoplayer2.transformer;
import android.content.Context;
import android.opengl.GLES20;
import android.opengl.Matrix;
import android.util.Size;
import android.util.Pair;
import com.google.android.exoplayer2.util.GlProgram;
import com.google.android.exoplayer2.util.GlUtil;
import java.io.IOException;
@ -57,8 +57,8 @@ import java.io.IOException;
}
@Override
public Size configure(int inputWidth, int inputHeight) {
return new Size(inputWidth, inputHeight);
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
return Pair.create(inputWidth, inputHeight);
}
@Override

View file

@ -19,7 +19,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull;
import android.graphics.Matrix;
import android.util.Size;
import android.util.Pair;
import com.google.android.exoplayer2.util.GlUtil;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@ -64,14 +64,14 @@ public final class Crop implements MatrixTransformation {
}
@Override
public Size configure(int inputWidth, int inputHeight) {
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
checkArgument(inputWidth > 0, "inputWidth must be positive");
checkArgument(inputHeight > 0, "inputHeight must be positive");
transformationMatrix = new Matrix();
if (left == -1f && right == 1f && bottom == -1f && top == 1f) {
// No crop needed.
return new Size(inputWidth, inputHeight);
return Pair.create(inputWidth, inputHeight);
}
float scaleX = (right - left) / GlUtil.LENGTH_NDC;
@ -84,7 +84,7 @@ public final class Crop implements MatrixTransformation {
int outputWidth = Math.round(inputWidth * scaleX);
int outputHeight = Math.round(inputHeight * scaleY);
return new Size(outputWidth, outputHeight);
return Pair.create(outputWidth, outputHeight);
}
@Override

View file

@ -25,7 +25,7 @@ import android.opengl.EGLExt;
import android.opengl.EGLSurface;
import android.opengl.GLES20;
import android.opengl.Matrix;
import android.util.Size;
import android.util.Pair;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
@ -74,7 +74,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Nullable private MatrixTransformationProcessor matrixTransformationProcessor;
@Nullable private SurfaceViewWrapper debugSurfaceViewWrapper;
private @MonotonicNonNull Listener listener;
private @MonotonicNonNull Size outputSizeBeforeSurfaceTransformation;
private @MonotonicNonNull Pair<Integer, Integer> outputSizeBeforeSurfaceTransformation;
private @MonotonicNonNull SurfaceView debugSurfaceView;
private volatile boolean outputSizeOrRotationChanged;
@ -188,14 +188,14 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|| this.outputSizeBeforeSurfaceTransformation == null) {
this.inputWidth = inputWidth;
this.inputHeight = inputHeight;
Size outputSizeBeforeSurfaceTransformation =
Pair<Integer, Integer> outputSizeBeforeSurfaceTransformation =
MatrixUtils.configureAndGetOutputSize(inputWidth, inputHeight, matrixTransformations);
if (!Util.areEqual(
this.outputSizeBeforeSurfaceTransformation, outputSizeBeforeSurfaceTransformation)) {
this.outputSizeBeforeSurfaceTransformation = outputSizeBeforeSurfaceTransformation;
frameProcessorListener.onOutputSizeChanged(
outputSizeBeforeSurfaceTransformation.getWidth(),
outputSizeBeforeSurfaceTransformation.getHeight());
outputSizeBeforeSurfaceTransformation.first,
outputSizeBeforeSurfaceTransformation.second);
}
}
@ -264,9 +264,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
useHdr,
/* outputOpticalColors= */ true);
matrixTransformationProcessor.setTextureTransformMatrix(textureTransformMatrix);
Size outputSize = matrixTransformationProcessor.configure(inputWidth, inputHeight);
checkState(outputSize.getWidth() == outputSurfaceInfo.width);
checkState(outputSize.getHeight() == outputSurfaceInfo.height);
Pair<Integer, Integer> outputSize =
matrixTransformationProcessor.configure(inputWidth, inputHeight);
checkState(outputSize.first == outputSurfaceInfo.width);
checkState(outputSize.second == outputSurfaceInfo.height);
return matrixTransformationProcessor;
}

View file

@ -17,7 +17,7 @@ package com.google.android.exoplayer2.transformer;
import android.content.Context;
import android.opengl.Matrix;
import android.util.Size;
import android.util.Pair;
/**
* Specifies a 4x4 transformation {@link Matrix} to apply in the vertex shader for each frame.
@ -37,10 +37,10 @@ public interface GlMatrixTransformation extends GlEffect {
*
* @param inputWidth The input frame width, in pixels.
* @param inputHeight The input frame height, in pixels.
* @return The output frame {@link Size}, in pixels.
* @return The output frame width and height, in pixels.
*/
default Size configure(int inputWidth, int inputHeight) {
return new Size(inputWidth, inputHeight);
default Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
return Pair.create(inputWidth, inputHeight);
}
/**

View file

@ -20,7 +20,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkState;
import android.content.Context;
import android.opengl.GLES20;
import android.opengl.Matrix;
import android.util.Size;
import android.util.Pair;
import com.google.android.exoplayer2.util.GlProgram;
import com.google.android.exoplayer2.util.GlUtil;
import com.google.common.collect.ImmutableList;
@ -218,7 +218,7 @@ import java.util.Arrays;
}
@Override
public Size configure(int inputWidth, int inputHeight) {
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
return MatrixUtils.configureAndGetOutputSize(inputWidth, inputHeight, matrixTransformations);
}

View file

@ -18,7 +18,7 @@ package com.google.android.exoplayer2.transformer;
import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import android.opengl.Matrix;
import android.util.Size;
import android.util.Pair;
import com.google.common.collect.ImmutableList;
import java.util.Arrays;
@ -219,20 +219,19 @@ import java.util.Arrays;
}
/**
* Returns the output frame {@link Size} after applying the given list of {@link
* GlMatrixTransformation GlMatrixTransformations} to an input frame with the given size.
* Returns the output frame size after applying the given list of {@link GlMatrixTransformation
* GlMatrixTransformations} to an input frame with the given size.
*/
public static Size configureAndGetOutputSize(
public static Pair<Integer, Integer> configureAndGetOutputSize(
int inputWidth,
int inputHeight,
ImmutableList<GlMatrixTransformation> matrixTransformations) {
checkArgument(inputWidth > 0, "inputWidth must be positive");
checkArgument(inputHeight > 0, "inputHeight must be positive");
Size outputSize = new Size(inputWidth, inputHeight);
Pair<Integer, Integer> outputSize = Pair.create(inputWidth, inputHeight);
for (int i = 0; i < matrixTransformations.size(); i++) {
outputSize =
matrixTransformations.get(i).configure(outputSize.getWidth(), outputSize.getHeight());
outputSize = matrixTransformations.get(i).configure(outputSize.first, outputSize.second);
}
return outputSize;

View file

@ -21,7 +21,7 @@ import static java.lang.annotation.ElementType.TYPE_USE;
import static java.lang.annotation.RetentionPolicy.SOURCE;
import android.graphics.Matrix;
import android.util.Size;
import android.util.Pair;
import androidx.annotation.IntDef;
import com.google.android.exoplayer2.C;
import java.lang.annotation.Documented;
@ -179,7 +179,7 @@ public final class Presentation implements MatrixTransformation {
}
@Override
public Size configure(int inputWidth, int inputHeight) {
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
checkArgument(inputWidth > 0, "inputWidth must be positive");
checkArgument(inputHeight > 0, "inputHeight must be positive");
@ -204,7 +204,7 @@ public final class Presentation implements MatrixTransformation {
}
outputHeight = requestedHeightPixels;
}
return new Size(Math.round(outputWidth), Math.round(outputHeight));
return Pair.create(Math.round(outputWidth), Math.round(outputHeight));
}
@Override

View file

@ -21,7 +21,7 @@ import static java.lang.Math.max;
import static java.lang.Math.min;
import android.graphics.Matrix;
import android.util.Size;
import android.util.Pair;
import com.google.android.exoplayer2.util.GlUtil;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@ -103,14 +103,14 @@ public final class ScaleToFitTransformation implements MatrixTransformation {
}
@Override
public Size configure(int inputWidth, int inputHeight) {
public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
checkArgument(inputWidth > 0, "inputWidth must be positive");
checkArgument(inputHeight > 0, "inputHeight must be positive");
adjustedTransformationMatrix = new Matrix(transformationMatrix);
if (transformationMatrix.isIdentity()) {
return new Size(inputWidth, inputHeight);
return Pair.create(inputWidth, inputHeight);
}
float inputAspectRatio = (float) inputWidth / inputHeight;
@ -139,7 +139,7 @@ public final class ScaleToFitTransformation implements MatrixTransformation {
float scaleX = (maxX - minX) / GlUtil.LENGTH_NDC;
float scaleY = (maxY - minY) / GlUtil.LENGTH_NDC;
adjustedTransformationMatrix.postScale(1f / scaleX, 1f / scaleY);
return new Size(Math.round(inputWidth * scaleX), Math.round(inputHeight * scaleY));
return Pair.create(Math.round(inputWidth * scaleX), Math.round(inputHeight * scaleY));
}
@Override

View file

@ -15,7 +15,7 @@
*/
package com.google.android.exoplayer2.transformer;
import android.util.Size;
import android.util.Pair;
import androidx.annotation.CallSuper;
import com.google.android.exoplayer2.util.GlUtil;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
@ -58,9 +58,9 @@ public abstract class SingleFrameGlTextureProcessor implements GlTextureProcesso
*
* @param inputWidth The input width, in pixels.
* @param inputHeight The input height, in pixels.
* @return The output {@link Size} of frames processed through {@link #drawFrame(int, long)}.
* @return The output width and height of frames processed through {@link #drawFrame(int, long)}.
*/
public abstract Size configure(int inputWidth, int inputHeight);
public abstract Pair<Integer, Integer> configure(int inputWidth, int inputHeight);
/**
* Draws one frame.
@ -120,17 +120,17 @@ public abstract class SingleFrameGlTextureProcessor implements GlTextureProcesso
private void configureOutputTexture(int inputWidth, int inputHeight) throws GlUtil.GlException {
this.inputWidth = inputWidth;
this.inputHeight = inputHeight;
Size outputSize = configure(inputWidth, inputHeight);
Pair<Integer, Integer> outputSize = configure(inputWidth, inputHeight);
if (outputTexture == null
|| outputSize.getWidth() != outputTexture.width
|| outputSize.getHeight() != outputTexture.height) {
|| outputSize.first != outputTexture.width
|| outputSize.second != outputTexture.height) {
if (outputTexture != null) {
GlUtil.deleteTexture(outputTexture.texId);
}
int outputTexId = GlUtil.createTexture(outputSize.getWidth(), outputSize.getHeight(), useHdr);
int outputTexId = GlUtil.createTexture(outputSize.first, outputSize.second, useHdr);
int outputFboId = GlUtil.createFboForTexture(outputTexId);
outputTexture =
new TextureInfo(outputTexId, outputFboId, outputSize.getWidth(), outputSize.getHeight());
new TextureInfo(outputTexId, outputFboId, outputSize.first, outputSize.second);
}
}

View file

@ -17,7 +17,7 @@ package com.google.android.exoplayer2.transformer;
import static com.google.common.truth.Truth.assertThat;
import android.util.Size;
import android.util.Pair;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.util.GlUtil;
import org.junit.Test;
@ -36,10 +36,10 @@ public final class CropTest {
int inputHeight = 150;
Crop crop = new Crop(/* left= */ -1, /* right= */ 1, /* bottom= */ -1, /* top= */ 1);
Size outputSize = crop.configure(inputWidth, inputHeight);
Pair<Integer, Integer> outputSize = crop.configure(inputWidth, inputHeight);
assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
assertThat(outputSize.first).isEqualTo(inputWidth);
assertThat(outputSize.second).isEqualTo(inputHeight);
}
@Test
@ -52,11 +52,11 @@ public final class CropTest {
float top = 1f;
Crop crop = new Crop(left, right, bottom, top);
Size outputSize = crop.configure(inputWidth, inputHeight);
Pair<Integer, Integer> outputSize = crop.configure(inputWidth, inputHeight);
int expectedPostCropWidth = Math.round(inputWidth * (right - left) / GlUtil.LENGTH_NDC);
int expectedPostCropHeight = Math.round(inputHeight * (top - bottom) / GlUtil.LENGTH_NDC);
assertThat(outputSize.getWidth()).isEqualTo(expectedPostCropWidth);
assertThat(outputSize.getHeight()).isEqualTo(expectedPostCropHeight);
assertThat(outputSize.first).isEqualTo(expectedPostCropWidth);
assertThat(outputSize.second).isEqualTo(expectedPostCropHeight);
}
}

View file

@ -17,7 +17,7 @@ package com.google.android.exoplayer2.transformer;
import static com.google.common.truth.Truth.assertThat;
import android.util.Size;
import android.util.Pair;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C;
import org.junit.Test;
@ -36,10 +36,10 @@ public final class PresentationTest {
int inputHeight = 150;
Presentation presentation = Presentation.createForHeight(C.LENGTH_UNSET);
Size outputSize = presentation.configure(inputWidth, inputHeight);
Pair<Integer, Integer> outputSize = presentation.configure(inputWidth, inputHeight);
assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
assertThat(outputSize.first).isEqualTo(inputWidth);
assertThat(outputSize.second).isEqualTo(inputHeight);
}
@Test
@ -49,10 +49,10 @@ public final class PresentationTest {
int requestedHeight = 300;
Presentation presentation = Presentation.createForHeight(requestedHeight);
Size outputSize = presentation.configure(inputWidth, inputHeight);
Pair<Integer, Integer> outputSize = presentation.configure(inputWidth, inputHeight);
assertThat(outputSize.getWidth()).isEqualTo(requestedHeight * inputWidth / inputHeight);
assertThat(outputSize.getHeight()).isEqualTo(requestedHeight);
assertThat(outputSize.first).isEqualTo(requestedHeight * inputWidth / inputHeight);
assertThat(outputSize.second).isEqualTo(requestedHeight);
}
@Test
@ -63,10 +63,10 @@ public final class PresentationTest {
Presentation presentation =
Presentation.createForAspectRatio(aspectRatio, Presentation.LAYOUT_SCALE_TO_FIT);
Size outputSize = presentation.configure(inputWidth, inputHeight);
Pair<Integer, Integer> outputSize = presentation.configure(inputWidth, inputHeight);
assertThat(outputSize.getWidth()).isEqualTo(Math.round(aspectRatio * inputHeight));
assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
assertThat(outputSize.first).isEqualTo(Math.round(aspectRatio * inputHeight));
assertThat(outputSize.second).isEqualTo(inputHeight);
}
@Test
@ -79,9 +79,9 @@ public final class PresentationTest {
Presentation.createForWidthAndHeight(
requestedWidth, requestedHeight, Presentation.LAYOUT_SCALE_TO_FIT);
Size outputSize = presentation.configure(inputWidth, inputHeight);
Pair<Integer, Integer> outputSize = presentation.configure(inputWidth, inputHeight);
assertThat(outputSize.getWidth()).isEqualTo(requestedWidth);
assertThat(outputSize.getHeight()).isEqualTo(requestedHeight);
assertThat(outputSize.first).isEqualTo(requestedWidth);
assertThat(outputSize.second).isEqualTo(requestedHeight);
}
}

View file

@ -17,7 +17,7 @@ package com.google.android.exoplayer2.transformer;
import static com.google.common.truth.Truth.assertThat;
import android.util.Size;
import android.util.Pair;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -38,10 +38,10 @@ public final class ScaleToFitTransformationTest {
ScaleToFitTransformation scaleToFitTransformation =
new ScaleToFitTransformation.Builder().build();
Size outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
Pair<Integer, Integer> outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
assertThat(outputSize.first).isEqualTo(inputWidth);
assertThat(outputSize.second).isEqualTo(inputHeight);
}
@Test
@ -53,10 +53,10 @@ public final class ScaleToFitTransformationTest {
.setScale(/* scaleX= */ .5f, /* scaleY= */ 1f)
.build();
Size outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
Pair<Integer, Integer> outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
assertThat(outputSize.getWidth()).isEqualTo(Math.round(inputWidth * .5f));
assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
assertThat(outputSize.first).isEqualTo(Math.round(inputWidth * .5f));
assertThat(outputSize.second).isEqualTo(inputHeight);
}
@Test
@ -66,10 +66,10 @@ public final class ScaleToFitTransformationTest {
ScaleToFitTransformation scaleToFitTransformation =
new ScaleToFitTransformation.Builder().setScale(/* scaleX= */ 2f, /* scaleY= */ 1f).build();
Size outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
Pair<Integer, Integer> outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
assertThat(outputSize.getWidth()).isEqualTo(inputWidth * 2);
assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
assertThat(outputSize.first).isEqualTo(inputWidth * 2);
assertThat(outputSize.second).isEqualTo(inputHeight);
}
@Test
@ -79,10 +79,10 @@ public final class ScaleToFitTransformationTest {
ScaleToFitTransformation scaleToFitTransformation =
new ScaleToFitTransformation.Builder().setScale(/* scaleX= */ 1f, /* scaleY= */ 2f).build();
Size outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
Pair<Integer, Integer> outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
assertThat(outputSize.getHeight()).isEqualTo(inputHeight * 2);
assertThat(outputSize.first).isEqualTo(inputWidth);
assertThat(outputSize.second).isEqualTo(inputHeight * 2);
}
@Test
@ -92,10 +92,10 @@ public final class ScaleToFitTransformationTest {
ScaleToFitTransformation scaleToFitTransformation =
new ScaleToFitTransformation.Builder().setRotationDegrees(90).build();
Size outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
Pair<Integer, Integer> outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
assertThat(outputSize.getWidth()).isEqualTo(inputHeight);
assertThat(outputSize.getHeight()).isEqualTo(inputWidth);
assertThat(outputSize.first).isEqualTo(inputHeight);
assertThat(outputSize.second).isEqualTo(inputWidth);
}
@Test
@ -106,9 +106,9 @@ public final class ScaleToFitTransformationTest {
new ScaleToFitTransformation.Builder().setRotationDegrees(45).build();
long expectedOutputWidthHeight = 247;
Size outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
Pair<Integer, Integer> outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
assertThat(outputSize.getWidth()).isEqualTo(expectedOutputWidthHeight);
assertThat(outputSize.getHeight()).isEqualTo(expectedOutputWidthHeight);
assertThat(outputSize.first).isEqualTo(expectedOutputWidthHeight);
assertThat(outputSize.second).isEqualTo(expectedOutputWidthHeight);
}
}