Commit b994f8bf by Googler Committed by Marc Baechinger

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
parent 4ac177c3
Showing with 146 additions and 139 deletions
...@@ -28,7 +28,7 @@ import android.graphics.Paint; ...@@ -28,7 +28,7 @@ import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.opengl.GLES20; import android.opengl.GLES20;
import android.opengl.GLUtils; import android.opengl.GLUtils;
import android.util.Size; import android.util.Pair;
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.SingleFrameGlTextureProcessor; import com.google.android.exoplayer2.transformer.SingleFrameGlTextureProcessor;
...@@ -111,7 +111,7 @@ import java.util.Locale; ...@@ -111,7 +111,7 @@ import java.util.Locale;
} }
@Override @Override
public Size configure(int inputWidth, int inputHeight) { public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
if (inputWidth > inputHeight) { if (inputWidth > inputHeight) {
bitmapScaleX = inputWidth / (float) inputHeight; bitmapScaleX = inputWidth / (float) inputHeight;
bitmapScaleY = 1f; bitmapScaleY = 1f;
...@@ -123,7 +123,7 @@ import java.util.Locale; ...@@ -123,7 +123,7 @@ import java.util.Locale;
glProgram.setFloatUniform("uScaleX", bitmapScaleX); glProgram.setFloatUniform("uScaleX", bitmapScaleX);
glProgram.setFloatUniform("uScaleY", bitmapScaleY); glProgram.setFloatUniform("uScaleY", bitmapScaleY);
return new Size(inputWidth, inputHeight); return Pair.create(inputWidth, inputHeight);
} }
@Override @Override
......
...@@ -19,7 +19,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkArgument; ...@@ -19,7 +19,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import android.content.Context; import android.content.Context;
import android.opengl.GLES20; 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.FrameProcessingException;
import com.google.android.exoplayer2.transformer.SingleFrameGlTextureProcessor; import com.google.android.exoplayer2.transformer.SingleFrameGlTextureProcessor;
import com.google.android.exoplayer2.util.GlProgram; import com.google.android.exoplayer2.util.GlProgram;
...@@ -90,8 +90,8 @@ import java.io.IOException; ...@@ -90,8 +90,8 @@ import java.io.IOException;
} }
@Override @Override
public Size configure(int inputWidth, int inputHeight) { public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
return new Size(inputWidth, inputHeight); return Pair.create(inputWidth, inputHeight);
} }
@Override @Override
......
...@@ -27,7 +27,7 @@ import android.graphics.Color; ...@@ -27,7 +27,7 @@ import android.graphics.Color;
import android.opengl.EGLContext; import android.opengl.EGLContext;
import android.opengl.EGLDisplay; import android.opengl.EGLDisplay;
import android.opengl.EGLSurface; import android.opengl.EGLSurface;
import android.util.Size; import android.util.Pair;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
...@@ -93,14 +93,14 @@ public class ContrastProcessorPixelTest { ...@@ -93,14 +93,14 @@ public class ContrastProcessorPixelTest {
String testId = "drawFrame_noContrastChange"; String testId = "drawFrame_noContrastChange";
contrastProcessor = contrastProcessor =
new Contrast(/* contrast= */ 0.0f).toGlTextureProcessor(context, /* useHdr= */ false); new Contrast(/* contrast= */ 0.0f).toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight()); setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(EXOPLAYER_LOGO_PNG_ASSET_PATH); Bitmap expectedBitmap = BitmapTestUtil.readBitmap(EXOPLAYER_LOGO_PNG_ASSET_PATH);
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs = */ 0); contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs = */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight()); outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap); BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
...@@ -114,8 +114,8 @@ public class ContrastProcessorPixelTest { ...@@ -114,8 +114,8 @@ public class ContrastProcessorPixelTest {
String testId = "drawFrame_minimumContrast"; String testId = "drawFrame_minimumContrast";
contrastProcessor = contrastProcessor =
new Contrast(/* contrast= */ -1.0f).toGlTextureProcessor(context, /* useHdr= */ false); new Contrast(/* contrast= */ -1.0f).toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight()); setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = Bitmap expectedBitmap =
BitmapTestUtil.createArgb8888BitmapWithSolidColor( BitmapTestUtil.createArgb8888BitmapWithSolidColor(
inputWidth, inputWidth,
...@@ -126,7 +126,7 @@ public class ContrastProcessorPixelTest { ...@@ -126,7 +126,7 @@ public class ContrastProcessorPixelTest {
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs = */ 0); contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs = */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight()); outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap); BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
...@@ -141,14 +141,14 @@ public class ContrastProcessorPixelTest { ...@@ -141,14 +141,14 @@ public class ContrastProcessorPixelTest {
String testId = "drawFrame_decreaseContrast"; String testId = "drawFrame_decreaseContrast";
contrastProcessor = contrastProcessor =
new Contrast(/* contrast= */ -0.75f).toGlTextureProcessor(context, /* useHdr= */ false); new Contrast(/* contrast= */ -0.75f).toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight()); setupOutputTexture(outputSize.first, outputSize.second);
Bitmap originalBitmap = BitmapTestUtil.readBitmap(EXOPLAYER_LOGO_PNG_ASSET_PATH); Bitmap originalBitmap = BitmapTestUtil.readBitmap(EXOPLAYER_LOGO_PNG_ASSET_PATH);
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0); contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight()); outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap); BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
assertIncreasedOrDecreasedContrast(originalBitmap, actualBitmap, /* increased= */ false); assertIncreasedOrDecreasedContrast(originalBitmap, actualBitmap, /* increased= */ false);
...@@ -160,14 +160,14 @@ public class ContrastProcessorPixelTest { ...@@ -160,14 +160,14 @@ public class ContrastProcessorPixelTest {
String testId = "drawFrame_increaseContrast"; String testId = "drawFrame_increaseContrast";
contrastProcessor = contrastProcessor =
new Contrast(/* contrast= */ 0.75f).toGlTextureProcessor(context, /* useHdr= */ false); new Contrast(/* contrast= */ 0.75f).toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight()); setupOutputTexture(outputSize.first, outputSize.second);
Bitmap originalBitmap = BitmapTestUtil.readBitmap(EXOPLAYER_LOGO_PNG_ASSET_PATH); Bitmap originalBitmap = BitmapTestUtil.readBitmap(EXOPLAYER_LOGO_PNG_ASSET_PATH);
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0); contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight()); outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap); BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
assertIncreasedOrDecreasedContrast(originalBitmap, actualBitmap, /* increased= */ true); assertIncreasedOrDecreasedContrast(originalBitmap, actualBitmap, /* increased= */ true);
...@@ -178,14 +178,14 @@ public class ContrastProcessorPixelTest { ...@@ -178,14 +178,14 @@ public class ContrastProcessorPixelTest {
String testId = "drawFrame_maximumContrast"; String testId = "drawFrame_maximumContrast";
contrastProcessor = contrastProcessor =
new Contrast(/* contrast= */ 1.0f).toGlTextureProcessor(context, /* useHdr= */ false); new Contrast(/* contrast= */ 1.0f).toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize = contrastProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight()); setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(MAXIMUM_CONTRAST_PNG_ASSET_PATH); Bitmap expectedBitmap = BitmapTestUtil.readBitmap(MAXIMUM_CONTRAST_PNG_ASSET_PATH);
contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs = */ 0); contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs = */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight()); outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap); BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(testId, "actual", actualBitmap);
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
......
...@@ -25,7 +25,7 @@ import android.graphics.Bitmap; ...@@ -25,7 +25,7 @@ import android.graphics.Bitmap;
import android.opengl.EGLContext; import android.opengl.EGLContext;
import android.opengl.EGLDisplay; import android.opengl.EGLDisplay;
import android.opengl.EGLSurface; import android.opengl.EGLSurface;
import android.util.Size; import android.util.Pair;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import java.io.IOException; import java.io.IOException;
...@@ -90,14 +90,14 @@ public final class CropPixelTest { ...@@ -90,14 +90,14 @@ public final class CropPixelTest {
cropTextureProcessor = cropTextureProcessor =
new Crop(/* left= */ -1, /* right= */ 1, /* bottom= */ -1, /* top= */ 1) new Crop(/* left= */ -1, /* right= */ 1, /* bottom= */ -1, /* top= */ 1)
.toGlTextureProcessor(context, /* useHdr= */ false); .toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = cropTextureProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight()); setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH); Bitmap expectedBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH);
cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0); cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight()); outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap); testId, /* bitmapLabel= */ "actual", actualBitmap);
...@@ -114,14 +114,14 @@ public final class CropPixelTest { ...@@ -114,14 +114,14 @@ public final class CropPixelTest {
cropTextureProcessor = cropTextureProcessor =
new Crop(/* left= */ -.9f, /* right= */ .1f, /* bottom= */ -1f, /* top= */ .5f) new Crop(/* left= */ -.9f, /* right= */ .1f, /* bottom= */ -1f, /* top= */ .5f)
.toGlTextureProcessor(context, /* useHdr= */ false); .toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = cropTextureProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight()); setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(CROP_SMALLER_PNG_ASSET_PATH); Bitmap expectedBitmap = BitmapTestUtil.readBitmap(CROP_SMALLER_PNG_ASSET_PATH);
cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0); cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight()); outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap); testId, /* bitmapLabel= */ "actual", actualBitmap);
...@@ -138,14 +138,14 @@ public final class CropPixelTest { ...@@ -138,14 +138,14 @@ public final class CropPixelTest {
cropTextureProcessor = cropTextureProcessor =
new Crop(/* left= */ -2f, /* right= */ 2f, /* bottom= */ -1f, /* top= */ 2f) new Crop(/* left= */ -2f, /* right= */ 2f, /* bottom= */ -1f, /* top= */ 2f)
.toGlTextureProcessor(context, /* useHdr= */ false); .toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = cropTextureProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight()); setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(CROP_LARGER_PNG_ASSET_PATH); Bitmap expectedBitmap = BitmapTestUtil.readBitmap(CROP_LARGER_PNG_ASSET_PATH);
cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0); cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight()); outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap); testId, /* bitmapLabel= */ "actual", actualBitmap);
......
...@@ -32,7 +32,7 @@ import android.media.ImageReader; ...@@ -32,7 +32,7 @@ import android.media.ImageReader;
import android.media.MediaCodec; import android.media.MediaCodec;
import android.media.MediaExtractor; import android.media.MediaExtractor;
import android.media.MediaFormat; import android.media.MediaFormat;
import android.util.Size; import android.util.Pair;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
...@@ -463,14 +463,14 @@ public final class GlEffectsFrameProcessorPixelTest { ...@@ -463,14 +463,14 @@ public final class GlEffectsFrameProcessorPixelTest {
} }
@Override @Override
public Size configure(int inputWidth, int inputHeight) { public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
adjustedTransformationMatrix = new Matrix(); adjustedTransformationMatrix = new Matrix();
adjustedTransformationMatrix.postRotate(degrees); adjustedTransformationMatrix.postRotate(degrees);
float inputAspectRatio = (float) inputWidth / inputHeight; float inputAspectRatio = (float) inputWidth / inputHeight;
adjustedTransformationMatrix.preScale(/* sx= */ inputAspectRatio, /* sy= */ 1f); adjustedTransformationMatrix.preScale(/* sx= */ inputAspectRatio, /* sy= */ 1f);
adjustedTransformationMatrix.postScale(/* sx= */ 1f / inputAspectRatio, /* sy= */ 1f); adjustedTransformationMatrix.postScale(/* sx= */ 1f / inputAspectRatio, /* sy= */ 1f);
return new Size(inputWidth, inputHeight); return Pair.create(inputWidth, inputHeight);
} }
@Override @Override
......
...@@ -25,7 +25,7 @@ import android.graphics.Bitmap; ...@@ -25,7 +25,7 @@ import android.graphics.Bitmap;
import android.opengl.EGLContext; import android.opengl.EGLContext;
import android.opengl.EGLDisplay; import android.opengl.EGLDisplay;
import android.opengl.EGLSurface; import android.opengl.EGLSurface;
import android.util.Size; import android.util.Pair;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
...@@ -99,14 +99,15 @@ public final class PresentationPixelTest { ...@@ -99,14 +99,15 @@ public final class PresentationPixelTest {
presentationTextureProcessor = presentationTextureProcessor =
Presentation.createForHeight(C.LENGTH_UNSET) Presentation.createForHeight(C.LENGTH_UNSET)
.toGlTextureProcessor(context, /* useHdr= */ false); .toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize =
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight()); presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH); Bitmap expectedBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH);
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0); presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight()); outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap); testId, /* bitmapLabel= */ "actual", actualBitmap);
...@@ -124,15 +125,16 @@ public final class PresentationPixelTest { ...@@ -124,15 +125,16 @@ public final class PresentationPixelTest {
presentationTextureProcessor = presentationTextureProcessor =
Presentation.createForAspectRatio(/* aspectRatio= */ 1f, Presentation.LAYOUT_SCALE_TO_FIT) Presentation.createForAspectRatio(/* aspectRatio= */ 1f, Presentation.LAYOUT_SCALE_TO_FIT)
.toGlTextureProcessor(context, /* useHdr= */ false); .toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize =
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight()); presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = Bitmap expectedBitmap =
BitmapTestUtil.readBitmap(ASPECT_RATIO_SCALE_TO_FIT_NARROW_PNG_ASSET_PATH); BitmapTestUtil.readBitmap(ASPECT_RATIO_SCALE_TO_FIT_NARROW_PNG_ASSET_PATH);
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0); presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight()); outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap); testId, /* bitmapLabel= */ "actual", actualBitmap);
...@@ -150,15 +152,16 @@ public final class PresentationPixelTest { ...@@ -150,15 +152,16 @@ public final class PresentationPixelTest {
presentationTextureProcessor = presentationTextureProcessor =
Presentation.createForAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT) Presentation.createForAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT)
.toGlTextureProcessor(context, /* useHdr= */ false); .toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize =
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight()); presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = Bitmap expectedBitmap =
BitmapTestUtil.readBitmap(ASPECT_RATIO_SCALE_TO_FIT_WIDE_PNG_ASSET_PATH); BitmapTestUtil.readBitmap(ASPECT_RATIO_SCALE_TO_FIT_WIDE_PNG_ASSET_PATH);
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0); presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight()); outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap); testId, /* bitmapLabel= */ "actual", actualBitmap);
...@@ -177,15 +180,16 @@ public final class PresentationPixelTest { ...@@ -177,15 +180,16 @@ public final class PresentationPixelTest {
Presentation.createForAspectRatio( Presentation.createForAspectRatio(
/* aspectRatio= */ 1f, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP) /* aspectRatio= */ 1f, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP)
.toGlTextureProcessor(context, /* useHdr= */ false); .toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize =
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight()); presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = Bitmap expectedBitmap =
BitmapTestUtil.readBitmap(ASPECT_RATIO_SCALE_TO_FIT_WITH_CROP_NARROW_PNG_ASSET_PATH); BitmapTestUtil.readBitmap(ASPECT_RATIO_SCALE_TO_FIT_WITH_CROP_NARROW_PNG_ASSET_PATH);
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0); presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight()); outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap); testId, /* bitmapLabel= */ "actual", actualBitmap);
...@@ -204,15 +208,16 @@ public final class PresentationPixelTest { ...@@ -204,15 +208,16 @@ public final class PresentationPixelTest {
Presentation.createForAspectRatio( Presentation.createForAspectRatio(
/* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP) /* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP)
.toGlTextureProcessor(context, /* useHdr= */ false); .toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize =
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight()); presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = Bitmap expectedBitmap =
BitmapTestUtil.readBitmap(ASPECT_RATIO_SCALE_TO_FIT_WITH_CROP_WIDE_PNG_ASSET_PATH); BitmapTestUtil.readBitmap(ASPECT_RATIO_SCALE_TO_FIT_WITH_CROP_WIDE_PNG_ASSET_PATH);
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0); presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight()); outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap); testId, /* bitmapLabel= */ "actual", actualBitmap);
...@@ -230,15 +235,16 @@ public final class PresentationPixelTest { ...@@ -230,15 +235,16 @@ public final class PresentationPixelTest {
presentationTextureProcessor = presentationTextureProcessor =
Presentation.createForAspectRatio(/* aspectRatio= */ 1f, Presentation.LAYOUT_STRETCH_TO_FIT) Presentation.createForAspectRatio(/* aspectRatio= */ 1f, Presentation.LAYOUT_STRETCH_TO_FIT)
.toGlTextureProcessor(context, /* useHdr= */ false); .toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize =
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight()); presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = Bitmap expectedBitmap =
BitmapTestUtil.readBitmap(ASPECT_RATIO_STRETCH_TO_FIT_NARROW_PNG_ASSET_PATH); BitmapTestUtil.readBitmap(ASPECT_RATIO_STRETCH_TO_FIT_NARROW_PNG_ASSET_PATH);
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0); presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight()); outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap); testId, /* bitmapLabel= */ "actual", actualBitmap);
...@@ -256,15 +262,16 @@ public final class PresentationPixelTest { ...@@ -256,15 +262,16 @@ public final class PresentationPixelTest {
presentationTextureProcessor = presentationTextureProcessor =
Presentation.createForAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_STRETCH_TO_FIT) Presentation.createForAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_STRETCH_TO_FIT)
.toGlTextureProcessor(context, /* useHdr= */ false); .toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = presentationTextureProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize =
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight()); presentationTextureProcessor.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.first, outputSize.second);
Bitmap expectedBitmap = Bitmap expectedBitmap =
BitmapTestUtil.readBitmap(ASPECT_RATIO_STRETCH_TO_FIT_WIDE_PNG_ASSET_PATH); BitmapTestUtil.readBitmap(ASPECT_RATIO_STRETCH_TO_FIT_WIDE_PNG_ASSET_PATH);
presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0); presentationTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer( BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight()); outputSize.first, outputSize.second);
BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory( BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
testId, /* bitmapLabel= */ "actual", actualBitmap); testId, /* bitmapLabel= */ "actual", actualBitmap);
......
...@@ -19,7 +19,7 @@ package com.google.android.exoplayer2.transformer; ...@@ -19,7 +19,7 @@ package com.google.android.exoplayer2.transformer;
import android.content.Context; import android.content.Context;
import android.opengl.GLES20; import android.opengl.GLES20;
import android.opengl.Matrix; 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.GlProgram;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import java.io.IOException; import java.io.IOException;
...@@ -57,8 +57,8 @@ import java.io.IOException; ...@@ -57,8 +57,8 @@ import java.io.IOException;
} }
@Override @Override
public Size configure(int inputWidth, int inputHeight) { public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
return new Size(inputWidth, inputHeight); return Pair.create(inputWidth, inputHeight);
} }
@Override @Override
......
...@@ -19,7 +19,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkArgument; ...@@ -19,7 +19,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull; import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.util.Size; import android.util.Pair;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
...@@ -64,14 +64,14 @@ public final class Crop implements MatrixTransformation { ...@@ -64,14 +64,14 @@ public final class Crop implements MatrixTransformation {
} }
@Override @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(inputWidth > 0, "inputWidth must be positive");
checkArgument(inputHeight > 0, "inputHeight must be positive"); checkArgument(inputHeight > 0, "inputHeight must be positive");
transformationMatrix = new Matrix(); transformationMatrix = new Matrix();
if (left == -1f && right == 1f && bottom == -1f && top == 1f) { if (left == -1f && right == 1f && bottom == -1f && top == 1f) {
// No crop needed. // No crop needed.
return new Size(inputWidth, inputHeight); return Pair.create(inputWidth, inputHeight);
} }
float scaleX = (right - left) / GlUtil.LENGTH_NDC; float scaleX = (right - left) / GlUtil.LENGTH_NDC;
...@@ -84,7 +84,7 @@ public final class Crop implements MatrixTransformation { ...@@ -84,7 +84,7 @@ public final class Crop implements MatrixTransformation {
int outputWidth = Math.round(inputWidth * scaleX); int outputWidth = Math.round(inputWidth * scaleX);
int outputHeight = Math.round(inputHeight * scaleY); int outputHeight = Math.round(inputHeight * scaleY);
return new Size(outputWidth, outputHeight); return Pair.create(outputWidth, outputHeight);
} }
@Override @Override
......
...@@ -25,7 +25,7 @@ import android.opengl.EGLExt; ...@@ -25,7 +25,7 @@ import android.opengl.EGLExt;
import android.opengl.EGLSurface; import android.opengl.EGLSurface;
import android.opengl.GLES20; import android.opengl.GLES20;
import android.opengl.Matrix; import android.opengl.Matrix;
import android.util.Size; import android.util.Pair;
import android.view.Surface; import android.view.Surface;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
...@@ -74,7 +74,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -74,7 +74,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Nullable private MatrixTransformationProcessor matrixTransformationProcessor; @Nullable private MatrixTransformationProcessor matrixTransformationProcessor;
@Nullable private SurfaceViewWrapper debugSurfaceViewWrapper; @Nullable private SurfaceViewWrapper debugSurfaceViewWrapper;
private @MonotonicNonNull Listener listener; private @MonotonicNonNull Listener listener;
private @MonotonicNonNull Size outputSizeBeforeSurfaceTransformation; private @MonotonicNonNull Pair<Integer, Integer> outputSizeBeforeSurfaceTransformation;
private @MonotonicNonNull SurfaceView debugSurfaceView; private @MonotonicNonNull SurfaceView debugSurfaceView;
private volatile boolean outputSizeOrRotationChanged; private volatile boolean outputSizeOrRotationChanged;
...@@ -188,14 +188,14 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -188,14 +188,14 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|| this.outputSizeBeforeSurfaceTransformation == null) { || this.outputSizeBeforeSurfaceTransformation == null) {
this.inputWidth = inputWidth; this.inputWidth = inputWidth;
this.inputHeight = inputHeight; this.inputHeight = inputHeight;
Size outputSizeBeforeSurfaceTransformation = Pair<Integer, Integer> outputSizeBeforeSurfaceTransformation =
MatrixUtils.configureAndGetOutputSize(inputWidth, inputHeight, matrixTransformations); MatrixUtils.configureAndGetOutputSize(inputWidth, inputHeight, matrixTransformations);
if (!Util.areEqual( if (!Util.areEqual(
this.outputSizeBeforeSurfaceTransformation, outputSizeBeforeSurfaceTransformation)) { this.outputSizeBeforeSurfaceTransformation, outputSizeBeforeSurfaceTransformation)) {
this.outputSizeBeforeSurfaceTransformation = outputSizeBeforeSurfaceTransformation; this.outputSizeBeforeSurfaceTransformation = outputSizeBeforeSurfaceTransformation;
frameProcessorListener.onOutputSizeChanged( frameProcessorListener.onOutputSizeChanged(
outputSizeBeforeSurfaceTransformation.getWidth(), outputSizeBeforeSurfaceTransformation.first,
outputSizeBeforeSurfaceTransformation.getHeight()); outputSizeBeforeSurfaceTransformation.second);
} }
} }
...@@ -264,9 +264,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -264,9 +264,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
useHdr, useHdr,
/* outputOpticalColors= */ true); /* outputOpticalColors= */ true);
matrixTransformationProcessor.setTextureTransformMatrix(textureTransformMatrix); matrixTransformationProcessor.setTextureTransformMatrix(textureTransformMatrix);
Size outputSize = matrixTransformationProcessor.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize =
checkState(outputSize.getWidth() == outputSurfaceInfo.width); matrixTransformationProcessor.configure(inputWidth, inputHeight);
checkState(outputSize.getHeight() == outputSurfaceInfo.height); checkState(outputSize.first == outputSurfaceInfo.width);
checkState(outputSize.second == outputSurfaceInfo.height);
return matrixTransformationProcessor; return matrixTransformationProcessor;
} }
......
...@@ -17,7 +17,7 @@ package com.google.android.exoplayer2.transformer; ...@@ -17,7 +17,7 @@ package com.google.android.exoplayer2.transformer;
import android.content.Context; import android.content.Context;
import android.opengl.Matrix; 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. * Specifies a 4x4 transformation {@link Matrix} to apply in the vertex shader for each frame.
...@@ -37,10 +37,10 @@ public interface GlMatrixTransformation extends GlEffect { ...@@ -37,10 +37,10 @@ public interface GlMatrixTransformation extends GlEffect {
* *
* @param inputWidth The input frame width, in pixels. * @param inputWidth The input frame width, in pixels.
* @param inputHeight The input frame height, 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) { default Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
return new Size(inputWidth, inputHeight); return Pair.create(inputWidth, inputHeight);
} }
/** /**
......
...@@ -20,7 +20,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkState; ...@@ -20,7 +20,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkState;
import android.content.Context; import android.content.Context;
import android.opengl.GLES20; import android.opengl.GLES20;
import android.opengl.Matrix; 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.GlProgram;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
...@@ -218,7 +218,7 @@ import java.util.Arrays; ...@@ -218,7 +218,7 @@ import java.util.Arrays;
} }
@Override @Override
public Size configure(int inputWidth, int inputHeight) { public Pair<Integer, Integer> configure(int inputWidth, int inputHeight) {
return MatrixUtils.configureAndGetOutputSize(inputWidth, inputHeight, matrixTransformations); return MatrixUtils.configureAndGetOutputSize(inputWidth, inputHeight, matrixTransformations);
} }
......
...@@ -18,7 +18,7 @@ package com.google.android.exoplayer2.transformer; ...@@ -18,7 +18,7 @@ package com.google.android.exoplayer2.transformer;
import static com.google.android.exoplayer2.util.Assertions.checkArgument; import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import android.opengl.Matrix; import android.opengl.Matrix;
import android.util.Size; import android.util.Pair;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.util.Arrays; import java.util.Arrays;
...@@ -219,20 +219,19 @@ 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 * Returns the output frame size after applying the given list of {@link GlMatrixTransformation
* GlMatrixTransformation GlMatrixTransformations} to an input frame with the given size. * GlMatrixTransformations} to an input frame with the given size.
*/ */
public static Size configureAndGetOutputSize( public static Pair<Integer, Integer> configureAndGetOutputSize(
int inputWidth, int inputWidth,
int inputHeight, int inputHeight,
ImmutableList<GlMatrixTransformation> matrixTransformations) { ImmutableList<GlMatrixTransformation> matrixTransformations) {
checkArgument(inputWidth > 0, "inputWidth must be positive"); checkArgument(inputWidth > 0, "inputWidth must be positive");
checkArgument(inputHeight > 0, "inputHeight 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++) { for (int i = 0; i < matrixTransformations.size(); i++) {
outputSize = outputSize = matrixTransformations.get(i).configure(outputSize.first, outputSize.second);
matrixTransformations.get(i).configure(outputSize.getWidth(), outputSize.getHeight());
} }
return outputSize; return outputSize;
......
...@@ -21,7 +21,7 @@ import static java.lang.annotation.ElementType.TYPE_USE; ...@@ -21,7 +21,7 @@ import static java.lang.annotation.ElementType.TYPE_USE;
import static java.lang.annotation.RetentionPolicy.SOURCE; import static java.lang.annotation.RetentionPolicy.SOURCE;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.util.Size; import android.util.Pair;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
...@@ -179,7 +179,7 @@ public final class Presentation implements MatrixTransformation { ...@@ -179,7 +179,7 @@ public final class Presentation implements MatrixTransformation {
} }
@Override @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(inputWidth > 0, "inputWidth must be positive");
checkArgument(inputHeight > 0, "inputHeight must be positive"); checkArgument(inputHeight > 0, "inputHeight must be positive");
...@@ -204,7 +204,7 @@ public final class Presentation implements MatrixTransformation { ...@@ -204,7 +204,7 @@ public final class Presentation implements MatrixTransformation {
} }
outputHeight = requestedHeightPixels; outputHeight = requestedHeightPixels;
} }
return new Size(Math.round(outputWidth), Math.round(outputHeight)); return Pair.create(Math.round(outputWidth), Math.round(outputHeight));
} }
@Override @Override
......
...@@ -21,7 +21,7 @@ import static java.lang.Math.max; ...@@ -21,7 +21,7 @@ import static java.lang.Math.max;
import static java.lang.Math.min; import static java.lang.Math.min;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.util.Size; import android.util.Pair;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.CanIgnoreReturnValue;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
...@@ -103,14 +103,14 @@ public final class ScaleToFitTransformation implements MatrixTransformation { ...@@ -103,14 +103,14 @@ public final class ScaleToFitTransformation implements MatrixTransformation {
} }
@Override @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(inputWidth > 0, "inputWidth must be positive");
checkArgument(inputHeight > 0, "inputHeight must be positive"); checkArgument(inputHeight > 0, "inputHeight must be positive");
adjustedTransformationMatrix = new Matrix(transformationMatrix); adjustedTransformationMatrix = new Matrix(transformationMatrix);
if (transformationMatrix.isIdentity()) { if (transformationMatrix.isIdentity()) {
return new Size(inputWidth, inputHeight); return Pair.create(inputWidth, inputHeight);
} }
float inputAspectRatio = (float) inputWidth / inputHeight; float inputAspectRatio = (float) inputWidth / inputHeight;
...@@ -139,7 +139,7 @@ public final class ScaleToFitTransformation implements MatrixTransformation { ...@@ -139,7 +139,7 @@ public final class ScaleToFitTransformation implements MatrixTransformation {
float scaleX = (maxX - minX) / GlUtil.LENGTH_NDC; float scaleX = (maxX - minX) / GlUtil.LENGTH_NDC;
float scaleY = (maxY - minY) / GlUtil.LENGTH_NDC; float scaleY = (maxY - minY) / GlUtil.LENGTH_NDC;
adjustedTransformationMatrix.postScale(1f / scaleX, 1f / scaleY); 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 @Override
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
*/ */
package com.google.android.exoplayer2.transformer; package com.google.android.exoplayer2.transformer;
import android.util.Size; import android.util.Pair;
import androidx.annotation.CallSuper; import androidx.annotation.CallSuper;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull; import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
...@@ -58,9 +58,9 @@ public abstract class SingleFrameGlTextureProcessor implements GlTextureProcesso ...@@ -58,9 +58,9 @@ public abstract class SingleFrameGlTextureProcessor implements GlTextureProcesso
* *
* @param inputWidth The input width, in pixels. * @param inputWidth The input width, in pixels.
* @param inputHeight The input height, 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. * Draws one frame.
...@@ -120,17 +120,17 @@ public abstract class SingleFrameGlTextureProcessor implements GlTextureProcesso ...@@ -120,17 +120,17 @@ public abstract class SingleFrameGlTextureProcessor implements GlTextureProcesso
private void configureOutputTexture(int inputWidth, int inputHeight) throws GlUtil.GlException { private void configureOutputTexture(int inputWidth, int inputHeight) throws GlUtil.GlException {
this.inputWidth = inputWidth; this.inputWidth = inputWidth;
this.inputHeight = inputHeight; this.inputHeight = inputHeight;
Size outputSize = configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize = configure(inputWidth, inputHeight);
if (outputTexture == null if (outputTexture == null
|| outputSize.getWidth() != outputTexture.width || outputSize.first != outputTexture.width
|| outputSize.getHeight() != outputTexture.height) { || outputSize.second != outputTexture.height) {
if (outputTexture != null) { if (outputTexture != null) {
GlUtil.deleteTexture(outputTexture.texId); 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); int outputFboId = GlUtil.createFboForTexture(outputTexId);
outputTexture = outputTexture =
new TextureInfo(outputTexId, outputFboId, outputSize.getWidth(), outputSize.getHeight()); new TextureInfo(outputTexId, outputFboId, outputSize.first, outputSize.second);
} }
} }
......
...@@ -17,7 +17,7 @@ package com.google.android.exoplayer2.transformer; ...@@ -17,7 +17,7 @@ package com.google.android.exoplayer2.transformer;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import android.util.Size; import android.util.Pair;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import org.junit.Test; import org.junit.Test;
...@@ -36,10 +36,10 @@ public final class CropTest { ...@@ -36,10 +36,10 @@ public final class CropTest {
int inputHeight = 150; int inputHeight = 150;
Crop crop = new Crop(/* left= */ -1, /* right= */ 1, /* bottom= */ -1, /* top= */ 1); 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.first).isEqualTo(inputWidth);
assertThat(outputSize.getHeight()).isEqualTo(inputHeight); assertThat(outputSize.second).isEqualTo(inputHeight);
} }
@Test @Test
...@@ -52,11 +52,11 @@ public final class CropTest { ...@@ -52,11 +52,11 @@ public final class CropTest {
float top = 1f; float top = 1f;
Crop crop = new Crop(left, right, bottom, top); 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 expectedPostCropWidth = Math.round(inputWidth * (right - left) / GlUtil.LENGTH_NDC);
int expectedPostCropHeight = Math.round(inputHeight * (top - bottom) / GlUtil.LENGTH_NDC); int expectedPostCropHeight = Math.round(inputHeight * (top - bottom) / GlUtil.LENGTH_NDC);
assertThat(outputSize.getWidth()).isEqualTo(expectedPostCropWidth); assertThat(outputSize.first).isEqualTo(expectedPostCropWidth);
assertThat(outputSize.getHeight()).isEqualTo(expectedPostCropHeight); assertThat(outputSize.second).isEqualTo(expectedPostCropHeight);
} }
} }
...@@ -17,7 +17,7 @@ package com.google.android.exoplayer2.transformer; ...@@ -17,7 +17,7 @@ package com.google.android.exoplayer2.transformer;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import android.util.Size; import android.util.Pair;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import org.junit.Test; import org.junit.Test;
...@@ -36,10 +36,10 @@ public final class PresentationTest { ...@@ -36,10 +36,10 @@ public final class PresentationTest {
int inputHeight = 150; int inputHeight = 150;
Presentation presentation = Presentation.createForHeight(C.LENGTH_UNSET); 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.first).isEqualTo(inputWidth);
assertThat(outputSize.getHeight()).isEqualTo(inputHeight); assertThat(outputSize.second).isEqualTo(inputHeight);
} }
@Test @Test
...@@ -49,10 +49,10 @@ public final class PresentationTest { ...@@ -49,10 +49,10 @@ public final class PresentationTest {
int requestedHeight = 300; int requestedHeight = 300;
Presentation presentation = Presentation.createForHeight(requestedHeight); 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.first).isEqualTo(requestedHeight * inputWidth / inputHeight);
assertThat(outputSize.getHeight()).isEqualTo(requestedHeight); assertThat(outputSize.second).isEqualTo(requestedHeight);
} }
@Test @Test
...@@ -63,10 +63,10 @@ public final class PresentationTest { ...@@ -63,10 +63,10 @@ public final class PresentationTest {
Presentation presentation = Presentation presentation =
Presentation.createForAspectRatio(aspectRatio, Presentation.LAYOUT_SCALE_TO_FIT); 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.first).isEqualTo(Math.round(aspectRatio * inputHeight));
assertThat(outputSize.getHeight()).isEqualTo(inputHeight); assertThat(outputSize.second).isEqualTo(inputHeight);
} }
@Test @Test
...@@ -79,9 +79,9 @@ public final class PresentationTest { ...@@ -79,9 +79,9 @@ public final class PresentationTest {
Presentation.createForWidthAndHeight( Presentation.createForWidthAndHeight(
requestedWidth, requestedHeight, Presentation.LAYOUT_SCALE_TO_FIT); 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.first).isEqualTo(requestedWidth);
assertThat(outputSize.getHeight()).isEqualTo(requestedHeight); assertThat(outputSize.second).isEqualTo(requestedHeight);
} }
} }
...@@ -17,7 +17,7 @@ package com.google.android.exoplayer2.transformer; ...@@ -17,7 +17,7 @@ package com.google.android.exoplayer2.transformer;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import android.util.Size; import android.util.Pair;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -38,10 +38,10 @@ public final class ScaleToFitTransformationTest { ...@@ -38,10 +38,10 @@ public final class ScaleToFitTransformationTest {
ScaleToFitTransformation scaleToFitTransformation = ScaleToFitTransformation scaleToFitTransformation =
new ScaleToFitTransformation.Builder().build(); 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.first).isEqualTo(inputWidth);
assertThat(outputSize.getHeight()).isEqualTo(inputHeight); assertThat(outputSize.second).isEqualTo(inputHeight);
} }
@Test @Test
...@@ -53,10 +53,10 @@ public final class ScaleToFitTransformationTest { ...@@ -53,10 +53,10 @@ public final class ScaleToFitTransformationTest {
.setScale(/* scaleX= */ .5f, /* scaleY= */ 1f) .setScale(/* scaleX= */ .5f, /* scaleY= */ 1f)
.build(); .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.first).isEqualTo(Math.round(inputWidth * .5f));
assertThat(outputSize.getHeight()).isEqualTo(inputHeight); assertThat(outputSize.second).isEqualTo(inputHeight);
} }
@Test @Test
...@@ -66,10 +66,10 @@ public final class ScaleToFitTransformationTest { ...@@ -66,10 +66,10 @@ public final class ScaleToFitTransformationTest {
ScaleToFitTransformation scaleToFitTransformation = ScaleToFitTransformation scaleToFitTransformation =
new ScaleToFitTransformation.Builder().setScale(/* scaleX= */ 2f, /* scaleY= */ 1f).build(); 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.first).isEqualTo(inputWidth * 2);
assertThat(outputSize.getHeight()).isEqualTo(inputHeight); assertThat(outputSize.second).isEqualTo(inputHeight);
} }
@Test @Test
...@@ -79,10 +79,10 @@ public final class ScaleToFitTransformationTest { ...@@ -79,10 +79,10 @@ public final class ScaleToFitTransformationTest {
ScaleToFitTransformation scaleToFitTransformation = ScaleToFitTransformation scaleToFitTransformation =
new ScaleToFitTransformation.Builder().setScale(/* scaleX= */ 1f, /* scaleY= */ 2f).build(); 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.first).isEqualTo(inputWidth);
assertThat(outputSize.getHeight()).isEqualTo(inputHeight * 2); assertThat(outputSize.second).isEqualTo(inputHeight * 2);
} }
@Test @Test
...@@ -92,10 +92,10 @@ public final class ScaleToFitTransformationTest { ...@@ -92,10 +92,10 @@ public final class ScaleToFitTransformationTest {
ScaleToFitTransformation scaleToFitTransformation = ScaleToFitTransformation scaleToFitTransformation =
new ScaleToFitTransformation.Builder().setRotationDegrees(90).build(); 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.first).isEqualTo(inputHeight);
assertThat(outputSize.getHeight()).isEqualTo(inputWidth); assertThat(outputSize.second).isEqualTo(inputWidth);
} }
@Test @Test
...@@ -106,9 +106,9 @@ public final class ScaleToFitTransformationTest { ...@@ -106,9 +106,9 @@ public final class ScaleToFitTransformationTest {
new ScaleToFitTransformation.Builder().setRotationDegrees(45).build(); new ScaleToFitTransformation.Builder().setRotationDegrees(45).build();
long expectedOutputWidthHeight = 247; long expectedOutputWidthHeight = 247;
Size outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight); Pair<Integer, Integer> outputSize = scaleToFitTransformation.configure(inputWidth, inputHeight);
assertThat(outputSize.getWidth()).isEqualTo(expectedOutputWidthHeight); assertThat(outputSize.first).isEqualTo(expectedOutputWidthHeight);
assertThat(outputSize.getHeight()).isEqualTo(expectedOutputWidthHeight); assertThat(outputSize.second).isEqualTo(expectedOutputWidthHeight);
} }
} }
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