Test: Use TestName in media3.effects tests.

Instead of duplicating strings

PiperOrigin-RevId: 552865414
This commit is contained in:
huangdarwin 2023-08-01 18:28:20 +00:00 committed by Tianyi Feng
parent 69656774f9
commit 4302102cf0
13 changed files with 231 additions and 98 deletions

View File

@ -38,10 +38,14 @@ import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.Size; import androidx.media3.common.util.Size;
import androidx.media3.test.utils.BitmapPixelTestUtil; import androidx.media3.test.utils.BitmapPixelTestUtil;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** /**
@ -54,6 +58,8 @@ import org.junit.runner.RunWith;
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class ContrastPixelTest { public class ContrastPixelTest {
@Rule public final TestName testName = new TestName();
private static final String ORIGINAL_PNG_ASSET_PATH = private static final String ORIGINAL_PNG_ASSET_PATH =
"media/bitmap/sample_mp4_first_frame/linear_colors/original.png"; "media/bitmap/sample_mp4_first_frame/linear_colors/original.png";
private static final String INCREASE_CONTRAST_PNG_ASSET_PATH = private static final String INCREASE_CONTRAST_PNG_ASSET_PATH =
@ -68,6 +74,7 @@ public class ContrastPixelTest {
private final Context context = getApplicationContext(); private final Context context = getApplicationContext();
private @MonotonicNonNull String testId;
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull EGLSurface placeholderEglSurface; private @MonotonicNonNull EGLSurface placeholderEglSurface;
@ -88,6 +95,12 @@ public class ContrastPixelTest {
inputTexId = createGlTextureFromBitmap(inputBitmap); inputTexId = createGlTextureFromBitmap(inputBitmap);
} }
@Before
@EnsuresNonNull("testId")
public void setUpTestId() {
testId = testName.getMethodName();
}
@After @After
public void release() throws GlUtil.GlException, VideoFrameProcessingException { public void release() throws GlUtil.GlException, VideoFrameProcessingException {
if (contrastShaderProgram != null) { if (contrastShaderProgram != null) {
@ -97,8 +110,8 @@ public class ContrastPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_noContrastChange_leavesFrameUnchanged() throws Exception { public void drawFrame_noContrastChange_leavesFrameUnchanged() throws Exception {
String testId = "drawFrame_noContrastChange";
contrastShaderProgram = contrastShaderProgram =
new Contrast(/* contrast= */ 0.0f).toGlShaderProgram(context, /* useHdr= */ false); new Contrast(/* contrast= */ 0.0f).toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight); Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight);
@ -116,8 +129,8 @@ public class ContrastPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_minimumContrast_producesAllGrayFrame() throws Exception { public void drawFrame_minimumContrast_producesAllGrayFrame() throws Exception {
String testId = "drawFrame_minimumContrast";
contrastShaderProgram = contrastShaderProgram =
new Contrast(/* contrast= */ -1.0f).toGlShaderProgram(context, /* useHdr= */ false); new Contrast(/* contrast= */ -1.0f).toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight); Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight);
@ -140,9 +153,9 @@ public class ContrastPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_decreaseContrast_decreasesPixelsGreaterEqual128IncreasesBelow() public void drawFrame_decreaseContrast_decreasesPixelsGreaterEqual128IncreasesBelow()
throws Exception { throws Exception {
String testId = "drawFrame_decreaseContrast";
contrastShaderProgram = contrastShaderProgram =
new Contrast(/* contrast= */ -0.75f).toGlShaderProgram(context, /* useHdr= */ false); new Contrast(/* contrast= */ -0.75f).toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight); Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight);
@ -160,9 +173,9 @@ public class ContrastPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_increaseContrast_increasesPixelsGreaterEqual128DecreasesBelow() public void drawFrame_increaseContrast_increasesPixelsGreaterEqual128DecreasesBelow()
throws Exception { throws Exception {
String testId = "drawFrame_increaseContrast";
contrastShaderProgram = contrastShaderProgram =
new Contrast(/* contrast= */ 0.75f).toGlShaderProgram(context, /* useHdr= */ false); new Contrast(/* contrast= */ 0.75f).toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight); Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight);
@ -180,8 +193,8 @@ public class ContrastPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_maximumContrast_pixelEither0or255() throws Exception { public void drawFrame_maximumContrast_pixelEither0or255() throws Exception {
String testId = "drawFrame_maximumContrast";
contrastShaderProgram = contrastShaderProgram =
new Contrast(/* contrast= */ 1.0f).toGlShaderProgram(context, /* useHdr= */ false); new Contrast(/* contrast= */ 1.0f).toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight); Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight);

View File

@ -36,10 +36,14 @@ import androidx.media3.common.util.Size;
import androidx.media3.test.utils.BitmapPixelTestUtil; import androidx.media3.test.utils.BitmapPixelTestUtil;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import java.io.IOException; import java.io.IOException;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** /**
@ -52,6 +56,8 @@ import org.junit.runner.RunWith;
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public final class CropPixelTest { public final class CropPixelTest {
@Rule public final TestName testName = new TestName();
private static final String ORIGINAL_PNG_ASSET_PATH = private static final String ORIGINAL_PNG_ASSET_PATH =
"media/bitmap/sample_mp4_first_frame/electrical_colors/original.png"; "media/bitmap/sample_mp4_first_frame/electrical_colors/original.png";
private static final String CROP_SMALLER_PNG_ASSET_PATH = private static final String CROP_SMALLER_PNG_ASSET_PATH =
@ -61,6 +67,7 @@ public final class CropPixelTest {
private final Context context = getApplicationContext(); private final Context context = getApplicationContext();
private @MonotonicNonNull String testId;
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlShaderProgram cropShaderProgram; private @MonotonicNonNull SingleFrameGlShaderProgram cropShaderProgram;
@ -81,6 +88,12 @@ public final class CropPixelTest {
inputTexId = createGlTextureFromBitmap(inputBitmap); inputTexId = createGlTextureFromBitmap(inputBitmap);
} }
@Before
@EnsuresNonNull("testId")
public void setUpTestId() {
testId = testName.getMethodName();
}
@After @After
public void release() throws GlUtil.GlException, VideoFrameProcessingException { public void release() throws GlUtil.GlException, VideoFrameProcessingException {
if (cropShaderProgram != null) { if (cropShaderProgram != null) {
@ -92,8 +105,8 @@ public final class CropPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_noEdits_matchesGoldenFile() throws Exception { public void drawFrame_noEdits_matchesGoldenFile() throws Exception {
String testId = "drawFrame_noEdits";
cropShaderProgram = cropShaderProgram =
new Crop(/* left= */ -1, /* right= */ 1, /* bottom= */ -1, /* top= */ 1) new Crop(/* left= */ -1, /* right= */ 1, /* bottom= */ -1, /* top= */ 1)
.toGlShaderProgram(context, /* useHdr= */ false); .toGlShaderProgram(context, /* useHdr= */ false);
@ -113,8 +126,8 @@ public final class CropPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_cropSmaller_matchesGoldenFile() throws Exception { public void drawFrame_cropSmaller_matchesGoldenFile() throws Exception {
String testId = "drawFrame_cropSmaller";
cropShaderProgram = cropShaderProgram =
new Crop(/* left= */ -0.9f, /* right= */ 0.1f, /* bottom= */ -1f, /* top= */ 0.5f) new Crop(/* left= */ -0.9f, /* right= */ 0.1f, /* bottom= */ -1f, /* top= */ 0.5f)
.toGlShaderProgram(context, /* useHdr= */ false); .toGlShaderProgram(context, /* useHdr= */ false);
@ -134,8 +147,8 @@ public final class CropPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_cropLarger_matchesGoldenFile() throws Exception { public void drawFrame_cropLarger_matchesGoldenFile() throws Exception {
String testId = "drawFrame_cropLarger";
cropShaderProgram = cropShaderProgram =
new Crop(/* left= */ -2f, /* right= */ 2f, /* bottom= */ -1f, /* top= */ 2f) new Crop(/* left= */ -2f, /* right= */ 2f, /* bottom= */ -1f, /* top= */ 2f)
.toGlShaderProgram(context, /* useHdr= */ false); .toGlShaderProgram(context, /* useHdr= */ false);

View File

@ -35,10 +35,14 @@ import androidx.media3.common.util.GlUtil;
import androidx.media3.test.utils.BitmapPixelTestUtil; import androidx.media3.test.utils.BitmapPixelTestUtil;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import java.io.IOException; import java.io.IOException;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** /**
@ -51,6 +55,8 @@ import org.junit.runner.RunWith;
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public final class DefaultShaderProgramPixelTest { public final class DefaultShaderProgramPixelTest {
@Rule public final TestName testName = new TestName();
private static final String ORIGINAL_PNG_ASSET_PATH = private static final String ORIGINAL_PNG_ASSET_PATH =
"media/bitmap/sample_mp4_first_frame/electrical_colors/original.png"; "media/bitmap/sample_mp4_first_frame/electrical_colors/original.png";
private static final String TRANSLATE_RIGHT_PNG_ASSET_PATH = private static final String TRANSLATE_RIGHT_PNG_ASSET_PATH =
@ -62,6 +68,7 @@ public final class DefaultShaderProgramPixelTest {
private final Context context = getApplicationContext(); private final Context context = getApplicationContext();
private @MonotonicNonNull String testId;
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram; private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram;
@ -87,6 +94,12 @@ public final class DefaultShaderProgramPixelTest {
eglDisplay, eglContext, placeholderEglSurface, frameBuffer, inputWidth, inputHeight); eglDisplay, eglContext, placeholderEglSurface, frameBuffer, inputWidth, inputHeight);
} }
@Before
@EnsuresNonNull("testId")
public void setUpTestId() {
testId = testName.getMethodName();
}
@After @After
public void release() throws GlUtil.GlException, VideoFrameProcessingException { public void release() throws GlUtil.GlException, VideoFrameProcessingException {
if (defaultShaderProgram != null) { if (defaultShaderProgram != null) {
@ -98,8 +111,8 @@ public final class DefaultShaderProgramPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_noEdits_matchesGoldenFile() throws Exception { public void drawFrame_noEdits_matchesGoldenFile() throws Exception {
String testId = "drawFrame_noEdits";
Matrix identityMatrix = new Matrix(); Matrix identityMatrix = new Matrix();
MatrixTransformation noEditsTransformation = (long presentationTimeUs) -> identityMatrix; MatrixTransformation noEditsTransformation = (long presentationTimeUs) -> identityMatrix;
defaultShaderProgram = noEditsTransformation.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram = noEditsTransformation.toGlShaderProgram(context, /* useHdr= */ false);
@ -117,8 +130,8 @@ public final class DefaultShaderProgramPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_translateRight_matchesGoldenFile() throws Exception { public void drawFrame_translateRight_matchesGoldenFile() throws Exception {
String testId = "drawFrame_translateRight";
Matrix translateRightMatrix = new Matrix(); Matrix translateRightMatrix = new Matrix();
translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0); translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0);
MatrixTransformation translateRightTransformation = MatrixTransformation translateRightTransformation =
@ -139,8 +152,8 @@ public final class DefaultShaderProgramPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_scaleNarrow_matchesGoldenFile() throws Exception { public void drawFrame_scaleNarrow_matchesGoldenFile() throws Exception {
String testId = "drawFrame_scaleNarrow";
Matrix scaleNarrowMatrix = new Matrix(); Matrix scaleNarrowMatrix = new Matrix();
scaleNarrowMatrix.postScale(.5f, 1.2f); scaleNarrowMatrix.postScale(.5f, 1.2f);
MatrixTransformation scaleNarrowTransformation = (long presentationTimeUs) -> scaleNarrowMatrix; MatrixTransformation scaleNarrowTransformation = (long presentationTimeUs) -> scaleNarrowMatrix;
@ -160,8 +173,8 @@ public final class DefaultShaderProgramPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_rotate90_matchesGoldenFile() throws Exception { public void drawFrame_rotate90_matchesGoldenFile() throws Exception {
String testId = "drawFrame_rotate90";
Matrix rotate90Matrix = new Matrix(); Matrix rotate90Matrix = new Matrix();
rotate90Matrix.postRotate(/* degrees= */ 90); rotate90Matrix.postRotate(/* degrees= */ 90);
MatrixTransformation rotate90Transformation = (long presentationTimeUs) -> rotate90Matrix; MatrixTransformation rotate90Transformation = (long presentationTimeUs) -> rotate90Matrix;

View File

@ -31,12 +31,16 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.checkerframework.checker.nullness.qual.RequiresNonNull;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** Tests for frame queuing and output in {@link DefaultVideoFrameProcessor} given image input. */ /** Tests for frame queuing and output in {@link DefaultVideoFrameProcessor} given image input. */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class DefaultVideoFrameProcessorImageFrameOutputTest { public class DefaultVideoFrameProcessorImageFrameOutputTest {
@Rule public final TestName testName = new TestName();
private static final String ORIGINAL_PNG_ASSET_PATH = private static final String ORIGINAL_PNG_ASSET_PATH =
"media/bitmap/sample_mp4_first_frame/electrical_colors/original.png"; "media/bitmap/sample_mp4_first_frame/electrical_colors/original.png";
private static final String SCALE_WIDE_PNG_ASSET_PATH = private static final String SCALE_WIDE_PNG_ASSET_PATH =
@ -44,13 +48,15 @@ public class DefaultVideoFrameProcessorImageFrameOutputTest {
private static final String BITMAP_OVERLAY_PNG_ASSET_PATH = private static final String BITMAP_OVERLAY_PNG_ASSET_PATH =
"media/bitmap/sample_mp4_first_frame/electrical_colors/overlay_bitmap_FrameProcessor.png"; "media/bitmap/sample_mp4_first_frame/electrical_colors/overlay_bitmap_FrameProcessor.png";
private @MonotonicNonNull String testId;
private @MonotonicNonNull VideoFrameProcessorTestRunner videoFrameProcessorTestRunner; private @MonotonicNonNull VideoFrameProcessorTestRunner videoFrameProcessorTestRunner;
private @MonotonicNonNull AtomicInteger framesProduced; private @MonotonicNonNull AtomicInteger framesProduced;
@EnsuresNonNull("framesProduced")
@Before @Before
@EnsuresNonNull({"framesProduced", "testId"})
public void setUp() { public void setUp() {
framesProduced = new AtomicInteger(); framesProduced = new AtomicInteger();
testId = testName.getMethodName();
} }
@After @After
@ -58,10 +64,9 @@ public class DefaultVideoFrameProcessorImageFrameOutputTest {
checkNotNull(videoFrameProcessorTestRunner).release(); checkNotNull(videoFrameProcessorTestRunner).release();
} }
@RequiresNonNull("framesProduced")
@Test @Test
@RequiresNonNull({"framesProduced", "testId"})
public void imageInput_queueThreeBitmaps_outputsCorrectNumberOfFrames() throws Exception { public void imageInput_queueThreeBitmaps_outputsCorrectNumberOfFrames() throws Exception {
String testId = "imageInput_queueThreeBitmaps_outputsCorrectNumberOfFrames";
videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId).build(); videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId).build();
videoFrameProcessorTestRunner.queueInputBitmap( videoFrameProcessorTestRunner.queueInputBitmap(
@ -85,10 +90,9 @@ public class DefaultVideoFrameProcessorImageFrameOutputTest {
assertThat(actualFrameCount).isEqualTo(/* expected= */ 20); assertThat(actualFrameCount).isEqualTo(/* expected= */ 20);
} }
@RequiresNonNull("framesProduced")
@Test @Test
@RequiresNonNull({"framesProduced", "testId"})
public void imageInput_queueTwentyBitmaps_outputsCorrectNumberOfFrames() throws Exception { public void imageInput_queueTwentyBitmaps_outputsCorrectNumberOfFrames() throws Exception {
String testId = "imageInput_queueTwentyBitmaps_outputsCorrectNumberOfFrames";
videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId).build(); videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId).build();
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
@ -104,8 +108,8 @@ public class DefaultVideoFrameProcessorImageFrameOutputTest {
assertThat(actualFrameCount).isEqualTo(/* expected= */ 20); assertThat(actualFrameCount).isEqualTo(/* expected= */ 20);
} }
@RequiresNonNull("framesProduced")
@Test @Test
@RequiresNonNull({"framesProduced", "testId"})
public void imageInput_queueOneWithStartOffset_outputsFramesAtTheCorrectPresentationTimesUs() public void imageInput_queueOneWithStartOffset_outputsFramesAtTheCorrectPresentationTimesUs()
throws Exception { throws Exception {
String testId = String testId =
@ -128,11 +132,10 @@ public class DefaultVideoFrameProcessorImageFrameOutputTest {
.inOrder(); .inOrder();
} }
@RequiresNonNull("framesProduced")
@Test @Test
@RequiresNonNull({"framesProduced", "testId"})
public void imageInput_queueWithStartOffsets_outputsFramesAtTheCorrectPresentationTimesUs() public void imageInput_queueWithStartOffsets_outputsFramesAtTheCorrectPresentationTimesUs()
throws Exception { throws Exception {
String testId = "imageInput_queueWithStartOffsets_outputsFramesAtTheCorrectPresentationTimesUs";
Queue<Long> actualPresentationTimesUs = new ConcurrentLinkedQueue<>(); Queue<Long> actualPresentationTimesUs = new ConcurrentLinkedQueue<>();
videoFrameProcessorTestRunner = videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId) getDefaultFrameProcessorTestRunnerBuilder(testId)
@ -161,8 +164,8 @@ public class DefaultVideoFrameProcessorImageFrameOutputTest {
.inOrder(); .inOrder();
} }
@RequiresNonNull("framesProduced")
@Test @Test
@RequiresNonNull({"framesProduced", "testId"})
public void public void
imageInput_queueEndAndQueueAgain_outputsFirstSetOfFramesOnlyAtTheCorrectPresentationTimesUs() imageInput_queueEndAndQueueAgain_outputsFirstSetOfFramesOnlyAtTheCorrectPresentationTimesUs()
throws Exception { throws Exception {

View File

@ -34,9 +34,14 @@ import androidx.media3.test.utils.BitmapPixelTestUtil;
import androidx.media3.test.utils.VideoFrameProcessorTestRunner; import androidx.media3.test.utils.VideoFrameProcessorTestRunner;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
import org.junit.After; import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** /**
@ -52,6 +57,8 @@ import org.junit.runner.RunWith;
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public final class DefaultVideoFrameProcessorPixelTest { public final class DefaultVideoFrameProcessorPixelTest {
@Rule public final TestName testName = new TestName();
private static final String ORIGINAL_PNG_ASSET_PATH = private static final String ORIGINAL_PNG_ASSET_PATH =
"media/bitmap/sample_mp4_first_frame/electrical_colors/original.png"; "media/bitmap/sample_mp4_first_frame/electrical_colors/original.png";
private static final String OVERLAY_PNG_ASSET_PATH = "media/bitmap/input_images/media3test.png"; private static final String OVERLAY_PNG_ASSET_PATH = "media/bitmap/input_images/media3test.png";
@ -91,16 +98,23 @@ public final class DefaultVideoFrameProcessorPixelTest {
private static final GlEffect NO_OP_EFFECT = private static final GlEffect NO_OP_EFFECT =
new GlEffectWrapper(new ScaleAndRotateTransformation.Builder().build()); new GlEffectWrapper(new ScaleAndRotateTransformation.Builder().build());
private @MonotonicNonNull String testId;
private @MonotonicNonNull VideoFrameProcessorTestRunner videoFrameProcessorTestRunner; private @MonotonicNonNull VideoFrameProcessorTestRunner videoFrameProcessorTestRunner;
@Before
@EnsuresNonNull("testId")
public void setUpTestId() {
testId = testName.getMethodName();
}
@After @After
public void release() { public void release() {
checkNotNull(videoFrameProcessorTestRunner).release(); checkNotNull(videoFrameProcessorTestRunner).release();
} }
@Test @Test
@RequiresNonNull("testId")
public void noEffects_matchesGoldenFile() throws Exception { public void noEffects_matchesGoldenFile() throws Exception {
String testId = "noEffects_matchesGoldenFile";
videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId).build(); videoFrameProcessorTestRunner = getDefaultFrameProcessorTestRunnerBuilder(testId).build();
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
@ -114,8 +128,8 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void noEffects_withFrameCache_matchesGoldenFile() throws Exception { public void noEffects_withFrameCache_matchesGoldenFile() throws Exception {
String testId = "noEffects_withFrameCache_matchesGoldenFile";
videoFrameProcessorTestRunner = videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId) getDefaultFrameProcessorTestRunnerBuilder(testId)
.setEffects(new FrameCache(/* capacity= */ 5)) .setEffects(new FrameCache(/* capacity= */ 5))
@ -132,8 +146,8 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void noEffects_withDisabledColorTransfers_matchesGoldenFile() throws Exception { public void noEffects_withDisabledColorTransfers_matchesGoldenFile() throws Exception {
String testId = "noEffects_withDisabledColorTransfers_matchesGoldenFile";
videoFrameProcessorTestRunner = videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId) getDefaultFrameProcessorTestRunnerBuilder(testId)
.setVideoFrameProcessorFactory( .setVideoFrameProcessorFactory(
@ -153,8 +167,8 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void noEffects_withImageInput_matchesGoldenFile() throws Exception { public void noEffects_withImageInput_matchesGoldenFile() throws Exception {
String testId = "noEffects_withImageInput_matchesGoldenFile";
videoFrameProcessorTestRunner = videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId) getDefaultFrameProcessorTestRunnerBuilder(testId)
.setInputColorInfo(ColorInfo.SRGB_BT709_FULL) .setInputColorInfo(ColorInfo.SRGB_BT709_FULL)
@ -174,8 +188,8 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void wrappedCrop_withImageInput_matchesGoldenFile() throws Exception { public void wrappedCrop_withImageInput_matchesGoldenFile() throws Exception {
String testId = "wrappedCrop_withImageInput_matchesGoldenFile";
videoFrameProcessorTestRunner = videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId) getDefaultFrameProcessorTestRunnerBuilder(testId)
.setInputColorInfo(ColorInfo.SRGB_BT709_FULL) .setInputColorInfo(ColorInfo.SRGB_BT709_FULL)
@ -202,9 +216,9 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void noOpEffect_withImageInputAndDisabledColorTransfers_matchesGoldenFile() public void noOpEffect_withImageInputAndDisabledColorTransfers_matchesGoldenFile()
throws Exception { throws Exception {
String testId = "noOpEffect_withImageInputAndDisabledColorTransfers_matchesGoldenFile";
videoFrameProcessorTestRunner = videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId) getDefaultFrameProcessorTestRunnerBuilder(testId)
.setVideoFrameProcessorFactory( .setVideoFrameProcessorFactory(
@ -228,8 +242,8 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void setPixelWidthHeightRatio_matchesGoldenFile() throws Exception { public void setPixelWidthHeightRatio_matchesGoldenFile() throws Exception {
String testId = "setPixelWidthHeightRatio_matchesGoldenFile";
videoFrameProcessorTestRunner = videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId).setPixelWidthHeightRatio(2f).build(); getDefaultFrameProcessorTestRunnerBuilder(testId).setPixelWidthHeightRatio(2f).build();
Bitmap expectedBitmap = readBitmap(SCALE_WIDE_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(SCALE_WIDE_PNG_ASSET_PATH);
@ -244,8 +258,8 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void matrixTransformation_matchesGoldenFile() throws Exception { public void matrixTransformation_matchesGoldenFile() throws Exception {
String testId = "matrixTransformation_matchesGoldenFile";
Matrix translateRightMatrix = new Matrix(); Matrix translateRightMatrix = new Matrix();
translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0); translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0);
videoFrameProcessorTestRunner = videoFrameProcessorTestRunner =
@ -264,8 +278,8 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void matrixAndScaleAndRotateTransformation_matchesGoldenFile() throws Exception { public void matrixAndScaleAndRotateTransformation_matchesGoldenFile() throws Exception {
String testId = "matrixAndScaleAndRotateTransformation_matchesGoldenFile";
Matrix translateRightMatrix = new Matrix(); Matrix translateRightMatrix = new Matrix();
translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0); translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0);
videoFrameProcessorTestRunner = videoFrameProcessorTestRunner =
@ -286,8 +300,8 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void bitmapOverlay_matchesGoldenFile() throws Exception { public void bitmapOverlay_matchesGoldenFile() throws Exception {
String testId = "bitmapOverlay_matchesGoldenFile";
Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH); Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH);
BitmapOverlay bitmapOverlay = BitmapOverlay.createStaticBitmapOverlay(overlayBitmap); BitmapOverlay bitmapOverlay = BitmapOverlay.createStaticBitmapOverlay(overlayBitmap);
videoFrameProcessorTestRunner = videoFrameProcessorTestRunner =
@ -306,8 +320,8 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void scaleAndRotateAndMatrixTransformation_matchesGoldenFile() throws Exception { public void scaleAndRotateAndMatrixTransformation_matchesGoldenFile() throws Exception {
String testId = "scaleAndRotateAndMatrixTransformation_matchesGoldenFile";
Matrix translateRightMatrix = new Matrix(); Matrix translateRightMatrix = new Matrix();
translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0); translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0);
videoFrameProcessorTestRunner = videoFrameProcessorTestRunner =
@ -328,8 +342,8 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void presentation_createForHeight_matchesGoldenFile() throws Exception { public void presentation_createForHeight_matchesGoldenFile() throws Exception {
String testId = "presentation_createForHeight_matchesGoldenFile";
videoFrameProcessorTestRunner = videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId) getDefaultFrameProcessorTestRunnerBuilder(testId)
.setEffects(Presentation.createForHeight(480)) .setEffects(Presentation.createForHeight(480))
@ -346,8 +360,8 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void cropThenPresentation_matchesGoldenFile() throws Exception { public void cropThenPresentation_matchesGoldenFile() throws Exception {
String testId = "cropThenPresentation_matchesGoldenFile";
videoFrameProcessorTestRunner = videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId) getDefaultFrameProcessorTestRunnerBuilder(testId)
.setEffects( .setEffects(
@ -368,8 +382,8 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void scaleAndRotateTransformation_rotate45_matchesGoldenFile() throws Exception { public void scaleAndRotateTransformation_rotate45_matchesGoldenFile() throws Exception {
String testId = "scaleAndRotateTransformation_rotate45_matchesGoldenFile";
videoFrameProcessorTestRunner = videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId) getDefaultFrameProcessorTestRunnerBuilder(testId)
.setEffects(new ScaleAndRotateTransformation.Builder().setRotationDegrees(45).build()) .setEffects(new ScaleAndRotateTransformation.Builder().setRotationDegrees(45).build())
@ -386,8 +400,8 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void twoWrappedScaleAndRotateTransformations_matchesGoldenFile() throws Exception { public void twoWrappedScaleAndRotateTransformations_matchesGoldenFile() throws Exception {
String testId = "twoWrappedScaleAndRotateTransformations_matchesGoldenFile";
videoFrameProcessorTestRunner = videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId) getDefaultFrameProcessorTestRunnerBuilder(testId)
.setEffects( .setEffects(
@ -410,8 +424,8 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void manyComposedMatrixEffects_matchesSingleEffect() throws Exception { public void manyComposedMatrixEffects_matchesSingleEffect() throws Exception {
String testId = "manyComposedMatrixEffects_matchesSingleEffect";
Crop centerCrop = Crop centerCrop =
new Crop(/* left= */ -0.5f, /* right= */ 0.5f, /* bottom= */ -0.5f, /* top= */ 0.5f); new Crop(/* left= */ -0.5f, /* right= */ 0.5f, /* bottom= */ -0.5f, /* top= */ 0.5f);
ImmutableList.Builder<Effect> full10StepRotationAndCenterCrop = new ImmutableList.Builder<>(); ImmutableList.Builder<Effect> full10StepRotationAndCenterCrop = new ImmutableList.Builder<>();
@ -444,8 +458,8 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void increaseBrightness_matchesGoldenFile() throws Exception { public void increaseBrightness_matchesGoldenFile() throws Exception {
String testId = "increaseBrightness_matchesGoldenFile";
videoFrameProcessorTestRunner = videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId).setEffects(new Brightness(0.5f)).build(); getDefaultFrameProcessorTestRunnerBuilder(testId).setEffects(new Brightness(0.5f)).build();
Bitmap expectedBitmap = readBitmap(INCREASE_BRIGHTNESS_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(INCREASE_BRIGHTNESS_PNG_ASSET_PATH);
@ -460,9 +474,9 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void manyComposedMatrixAndRgbEffects_producesSameOutputAsCombinedEffects() public void manyComposedMatrixAndRgbEffects_producesSameOutputAsCombinedEffects()
throws Exception { throws Exception {
String testId = "manyComposedMatrixAndRgbEffects_producesSameOutputAsCombinedEffects";
Crop centerCrop = Crop centerCrop =
new Crop(/* left= */ -0.5f, /* right= */ 0.5f, /* bottom= */ -0.5f, /* top= */ 0.5f); new Crop(/* left= */ -0.5f, /* right= */ 0.5f, /* bottom= */ -0.5f, /* top= */ 0.5f);
ImmutableList<Effect> increaseBrightnessFullRotationCenterCrop = ImmutableList<Effect> increaseBrightnessFullRotationCenterCrop =
@ -506,10 +520,9 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void manyComposedMatrixAndRgbEffects_withFrameCache_producesSameOutputAsCombinedEffects() public void manyComposedMatrixAndRgbEffects_withFrameCache_producesSameOutputAsCombinedEffects()
throws Exception { throws Exception {
String testId =
"manyComposedMatrixAndRgbEffects_withFrameCache_producesSameOutputAsCombinedEffects";
Crop centerCrop = Crop centerCrop =
new Crop(/* left= */ -0.5f, /* right= */ 0.5f, /* bottom= */ -0.5f, /* top= */ 0.5f); new Crop(/* left= */ -0.5f, /* right= */ 0.5f, /* bottom= */ -0.5f, /* top= */ 0.5f);
ImmutableList<Effect> increaseBrightnessFullRotationCenterCrop = ImmutableList<Effect> increaseBrightnessFullRotationCenterCrop =
@ -554,8 +567,8 @@ public final class DefaultVideoFrameProcessorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void grayscaleThenIncreaseRedChannel_matchesGoldenFile() throws Exception { public void grayscaleThenIncreaseRedChannel_matchesGoldenFile() throws Exception {
String testId = "grayscaleThenIncreaseRedChannel_matchesGoldenFile";
videoFrameProcessorTestRunner = videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId) getDefaultFrameProcessorTestRunnerBuilder(testId)
.setEffects( .setEffects(

View File

@ -52,23 +52,29 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.checkerframework.checker.nullness.qual.RequiresNonNull;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** Tests for {@link FrameDropEffect}. */ /** Tests for {@link FrameDropEffect}. */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class FrameDropTest { public class FrameDropTest {
@Rule public final TestName testName = new TestName();
private static final String ASSET_PATH = "media/bitmap/FrameDropTest"; private static final String ASSET_PATH = "media/bitmap/FrameDropTest";
private static final int BLANK_FRAME_WIDTH = 100; private static final int BLANK_FRAME_WIDTH = 100;
private static final int BLANK_FRAME_HEIGHT = 50; private static final int BLANK_FRAME_HEIGHT = 50;
private @MonotonicNonNull String testId;
private @MonotonicNonNull TextureBitmapReader textureBitmapReader; private @MonotonicNonNull TextureBitmapReader textureBitmapReader;
private @MonotonicNonNull DefaultVideoFrameProcessor defaultVideoFrameProcessor; private @MonotonicNonNull DefaultVideoFrameProcessor defaultVideoFrameProcessor;
@EnsuresNonNull("textureBitmapReader") @EnsuresNonNull({"textureBitmapReader", "testId"})
@Before @Before
public void setUp() { public void setUp() {
textureBitmapReader = new TextureBitmapReader(); textureBitmapReader = new TextureBitmapReader();
testId = testName.getMethodName();
} }
@After @After
@ -76,11 +82,10 @@ public class FrameDropTest {
checkNotNull(defaultVideoFrameProcessor).release(); checkNotNull(defaultVideoFrameProcessor).release();
} }
@RequiresNonNull("textureBitmapReader")
@Test @Test
@RequiresNonNull({"textureBitmapReader", "testId"})
public void frameDrop_withDefaultStrategy_outputsFramesAtTheCorrectPresentationTimesUs() public void frameDrop_withDefaultStrategy_outputsFramesAtTheCorrectPresentationTimesUs()
throws Exception { throws Exception {
String testId = "frameDrop_withDefaultStrategy_outputsFramesAtTheCorrectPresentationTimesUs";
ImmutableList<Long> frameTimesUs = ImmutableList<Long> frameTimesUs =
ImmutableList.of(0L, 16_000L, 32_000L, 48_000L, 58_000L, 71_000L, 86_000L); ImmutableList.of(0L, 16_000L, 32_000L, 48_000L, 58_000L, 71_000L, 86_000L);
@ -92,11 +97,10 @@ public class FrameDropTest {
getAndAssertOutputBitmaps(textureBitmapReader, actualPresentationTimesUs, testId); getAndAssertOutputBitmaps(textureBitmapReader, actualPresentationTimesUs, testId);
} }
@RequiresNonNull("textureBitmapReader")
@Test @Test
@RequiresNonNull({"textureBitmapReader", "testId"})
public void frameDrop_withSimpleStrategy_outputsFramesAtTheCorrectPresentationTimesUs() public void frameDrop_withSimpleStrategy_outputsFramesAtTheCorrectPresentationTimesUs()
throws Exception { throws Exception {
String testId = "frameDrop_withSimpleStrategy_outputsFramesAtTheCorrectPresentationTimesUs";
ImmutableList<Long> frameTimesUs = ImmutableList<Long> frameTimesUs =
ImmutableList.of(0L, 250_000L, 500_000L, 750_000L, 1_000_000L, 1_500_000L); ImmutableList.of(0L, 250_000L, 500_000L, 750_000L, 1_000_000L, 1_500_000L);
@ -110,10 +114,9 @@ public class FrameDropTest {
getAndAssertOutputBitmaps(textureBitmapReader, actualPresentationTimesUs, testId); getAndAssertOutputBitmaps(textureBitmapReader, actualPresentationTimesUs, testId);
} }
@RequiresNonNull("textureBitmapReader")
@Test @Test
@RequiresNonNull({"textureBitmapReader", "testId"})
public void frameDrop_withSimpleStrategy_outputsAllFrames() throws Exception { public void frameDrop_withSimpleStrategy_outputsAllFrames() throws Exception {
String testId = "frameDrop_withSimpleStrategy_outputsAllFrames";
ImmutableList<Long> frameTimesUs = ImmutableList.of(0L, 333_333L, 666_667L); ImmutableList<Long> frameTimesUs = ImmutableList.of(0L, 333_333L, 666_667L);
ImmutableList<Long> actualPresentationTimesUs = ImmutableList<Long> actualPresentationTimesUs =

View File

@ -42,10 +42,14 @@ import androidx.media3.test.utils.BitmapPixelTestUtil;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.io.IOException; import java.io.IOException;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** /**
@ -58,6 +62,8 @@ import org.junit.runner.RunWith;
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class OverlayShaderProgramPixelTest { public class OverlayShaderProgramPixelTest {
@Rule public final TestName testName = new TestName();
private static final String OVERLAY_PNG_ASSET_PATH = "media/bitmap/input_images/media3test.png"; private static final String OVERLAY_PNG_ASSET_PATH = "media/bitmap/input_images/media3test.png";
private static final String ORIGINAL_PNG_ASSET_PATH = private static final String ORIGINAL_PNG_ASSET_PATH =
"media/bitmap/sample_mp4_first_frame/electrical_colors/original.png"; "media/bitmap/sample_mp4_first_frame/electrical_colors/original.png";
@ -87,6 +93,7 @@ public class OverlayShaderProgramPixelTest {
private final Context context = getApplicationContext(); private final Context context = getApplicationContext();
private @MonotonicNonNull String testId;
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlShaderProgram overlayShaderProgram; private @MonotonicNonNull SingleFrameGlShaderProgram overlayShaderProgram;
@ -107,6 +114,12 @@ public class OverlayShaderProgramPixelTest {
inputTexId = createGlTextureFromBitmap(inputBitmap); inputTexId = createGlTextureFromBitmap(inputBitmap);
} }
@Before
@EnsuresNonNull("testId")
public void setUpTestId() {
testId = testName.getMethodName();
}
@After @After
public void release() throws GlUtil.GlException, VideoFrameProcessingException { public void release() throws GlUtil.GlException, VideoFrameProcessingException {
if (overlayShaderProgram != null) { if (overlayShaderProgram != null) {
@ -116,8 +129,8 @@ public class OverlayShaderProgramPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_noOverlay_leavesFrameUnchanged() throws Exception { public void drawFrame_noOverlay_leavesFrameUnchanged() throws Exception {
String testId = "drawFrame_noOverlay";
overlayShaderProgram = overlayShaderProgram =
new OverlayEffect(/* textureOverlays= */ ImmutableList.of()) new OverlayEffect(/* textureOverlays= */ ImmutableList.of())
.toGlShaderProgram(context, /* useHdr= */ false); .toGlShaderProgram(context, /* useHdr= */ false);
@ -136,8 +149,8 @@ public class OverlayShaderProgramPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_bitmapOverlay_blendsBitmapIntoFrame() throws Exception { public void drawFrame_bitmapOverlay_blendsBitmapIntoFrame() throws Exception {
String testId = "drawFrame_bitmapOverlay";
Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH); Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH);
BitmapOverlay bitmapOverlay = BitmapOverlay.createStaticBitmapOverlay(overlayBitmap); BitmapOverlay bitmapOverlay = BitmapOverlay.createStaticBitmapOverlay(overlayBitmap);
overlayShaderProgram = overlayShaderProgram =
@ -158,9 +171,9 @@ public class OverlayShaderProgramPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_anchoredAndTranslatedBitmapOverlay_blendsBitmapIntoTopLeftOfFrame() public void drawFrame_anchoredAndTranslatedBitmapOverlay_blendsBitmapIntoTopLeftOfFrame()
throws Exception { throws Exception {
String testId = "drawFrame_anchoredAndTranslatedBitmapOverlay";
Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH); Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH);
OverlaySettings overlaySettings = OverlaySettings overlaySettings =
new OverlaySettings.Builder() new OverlaySettings.Builder()
@ -187,9 +200,9 @@ public class OverlayShaderProgramPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_overlayAnchoredOnlyBitmapOverlay_anchorsOverlayFromTopLeftCornerOfFrame() public void drawFrame_overlayAnchoredOnlyBitmapOverlay_anchorsOverlayFromTopLeftCornerOfFrame()
throws Exception { throws Exception {
String testId = "drawFrame_anchoredAndTranslatedBitmapOverlay";
Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH); Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH);
OverlaySettings overlaySettings = OverlaySettings overlaySettings =
new OverlaySettings.Builder().setOverlayAnchor(/* x= */ 1f, /* y= */ -1f).build(); new OverlaySettings.Builder().setOverlayAnchor(/* x= */ 1f, /* y= */ -1f).build();
@ -213,8 +226,8 @@ public class OverlayShaderProgramPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_rotatedBitmapOverlay_blendsBitmapRotated90degrees() throws Exception { public void drawFrame_rotatedBitmapOverlay_blendsBitmapRotated90degrees() throws Exception {
String testId = "drawFrame_rotatedBitmapOverlay";
Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH); Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH);
OverlaySettings overlaySettings = new OverlaySettings.Builder().setRotationDegrees(90f).build(); OverlaySettings overlaySettings = new OverlaySettings.Builder().setRotationDegrees(90f).build();
BitmapOverlay staticBitmapOverlay = BitmapOverlay staticBitmapOverlay =
@ -237,8 +250,8 @@ public class OverlayShaderProgramPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_translucentBitmapOverlay_blendsBitmapIntoFrame() throws Exception { public void drawFrame_translucentBitmapOverlay_blendsBitmapIntoFrame() throws Exception {
String testId = "drawFrame_translucentBitmapOverlay";
Bitmap bitmap = readBitmap(OVERLAY_PNG_ASSET_PATH); Bitmap bitmap = readBitmap(OVERLAY_PNG_ASSET_PATH);
OverlaySettings overlaySettings = new OverlaySettings.Builder().setAlpha(0.5f).build(); OverlaySettings overlaySettings = new OverlaySettings.Builder().setAlpha(0.5f).build();
BitmapOverlay translucentBitmapOverlay = BitmapOverlay translucentBitmapOverlay =
@ -261,8 +274,8 @@ public class OverlayShaderProgramPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_transparentTextOverlay_blendsBitmapIntoFrame() throws Exception { public void drawFrame_transparentTextOverlay_blendsBitmapIntoFrame() throws Exception {
String testId = "drawFrame_transparentTextOverlay";
SpannableString overlayText = new SpannableString(/* source= */ "Text styling"); SpannableString overlayText = new SpannableString(/* source= */ "Text styling");
OverlaySettings overlaySettings = new OverlaySettings.Builder().setAlpha(0f).build(); OverlaySettings overlaySettings = new OverlaySettings.Builder().setAlpha(0f).build();
overlayText.setSpan( overlayText.setSpan(
@ -290,8 +303,8 @@ public class OverlayShaderProgramPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_textOverlay_blendsTextIntoFrame() throws Exception { public void drawFrame_textOverlay_blendsTextIntoFrame() throws Exception {
String testId = "drawFrame_textOverlay";
SpannableString overlayText = new SpannableString(/* source= */ "Text styling"); SpannableString overlayText = new SpannableString(/* source= */ "Text styling");
overlayText.setSpan( overlayText.setSpan(
new ForegroundColorSpan(Color.GRAY), new ForegroundColorSpan(Color.GRAY),
@ -317,8 +330,8 @@ public class OverlayShaderProgramPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_textOverlayWithRelativeScaleSpan_blendsTextIntoFrame() throws Exception { public void drawFrame_textOverlayWithRelativeScaleSpan_blendsTextIntoFrame() throws Exception {
String testId = "drawFrame_textOverlayWithRelativeScaleSpan";
SpannableString overlayText = new SpannableString(/* source= */ "helllllloooo!!!"); SpannableString overlayText = new SpannableString(/* source= */ "helllllloooo!!!");
overlayText.setSpan( overlayText.setSpan(
new RelativeSizeSpan(2f), new RelativeSizeSpan(2f),
@ -344,9 +357,9 @@ public class OverlayShaderProgramPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_anchoredTextOverlay_blendsTextIntoTheTopRightQuadrantOfFrame() public void drawFrame_anchoredTextOverlay_blendsTextIntoTheTopRightQuadrantOfFrame()
throws Exception { throws Exception {
String testId = "drawFrame_anchoredTextOverlay";
SpannableString overlayText = new SpannableString(/* source= */ "Text styling"); SpannableString overlayText = new SpannableString(/* source= */ "Text styling");
overlayText.setSpan( overlayText.setSpan(
new ForegroundColorSpan(Color.GRAY), new ForegroundColorSpan(Color.GRAY),
@ -375,8 +388,8 @@ public class OverlayShaderProgramPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_multipleOverlays_blendsBothIntoFrame() throws Exception { public void drawFrame_multipleOverlays_blendsBothIntoFrame() throws Exception {
String testId = "drawFrame_multipleOverlays";
SpannableString overlayText = new SpannableString(/* source= */ "Overlay 1"); SpannableString overlayText = new SpannableString(/* source= */ "Overlay 1");
overlayText.setSpan( overlayText.setSpan(
new ForegroundColorSpan(Color.GRAY), new ForegroundColorSpan(Color.GRAY),
@ -407,8 +420,8 @@ public class OverlayShaderProgramPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_overlappingOverlays_blendsOnFifoOrder() throws Exception { public void drawFrame_overlappingOverlays_blendsOnFifoOrder() throws Exception {
String testId = "drawFrame_overlappingOverlays";
SpannableString overlayText = new SpannableString(/* source= */ "Overlapping text"); SpannableString overlayText = new SpannableString(/* source= */ "Overlapping text");
overlayText.setSpan( overlayText.setSpan(
new ForegroundColorSpan(Color.WHITE), new ForegroundColorSpan(Color.WHITE),
@ -441,8 +454,8 @@ public class OverlayShaderProgramPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_scaledBitmapOverlay_letterboxStretchesOverlay() throws Exception { public void drawFrame_scaledBitmapOverlay_letterboxStretchesOverlay() throws Exception {
String testId = "drawFrame_scaledBitmapOverlay";
Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH); Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH);
overlayShaderProgram = overlayShaderProgram =
new OverlayEffect(ImmutableList.of(new LetterBoxStretchedBitmapOverlay(overlayBitmap))) new OverlayEffect(ImmutableList.of(new LetterBoxStretchedBitmapOverlay(overlayBitmap)))

View File

@ -37,10 +37,14 @@ import androidx.media3.common.util.Size;
import androidx.media3.test.utils.BitmapPixelTestUtil; import androidx.media3.test.utils.BitmapPixelTestUtil;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import java.io.IOException; import java.io.IOException;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** /**
@ -53,6 +57,8 @@ import org.junit.runner.RunWith;
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public final class PresentationPixelTest { public final class PresentationPixelTest {
@Rule public final TestName testName = new TestName();
private static final String ORIGINAL_PNG_ASSET_PATH = private static final String ORIGINAL_PNG_ASSET_PATH =
"media/bitmap/sample_mp4_first_frame/electrical_colors/original.png"; "media/bitmap/sample_mp4_first_frame/electrical_colors/original.png";
private static final String ASPECT_RATIO_SCALE_TO_FIT_NARROW_PNG_ASSET_PATH = private static final String ASPECT_RATIO_SCALE_TO_FIT_NARROW_PNG_ASSET_PATH =
@ -70,6 +76,7 @@ public final class PresentationPixelTest {
private final Context context = getApplicationContext(); private final Context context = getApplicationContext();
private @MonotonicNonNull String testId;
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlShaderProgram presentationShaderProgram; private @MonotonicNonNull SingleFrameGlShaderProgram presentationShaderProgram;
@ -90,6 +97,12 @@ public final class PresentationPixelTest {
inputTexId = createGlTextureFromBitmap(inputBitmap); inputTexId = createGlTextureFromBitmap(inputBitmap);
} }
@Before
@EnsuresNonNull("testId")
public void setUpTestId() {
testId = testName.getMethodName();
}
@After @After
public void release() throws GlUtil.GlException, VideoFrameProcessingException { public void release() throws GlUtil.GlException, VideoFrameProcessingException {
if (presentationShaderProgram != null) { if (presentationShaderProgram != null) {
@ -101,8 +114,8 @@ public final class PresentationPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_noEdits_matchesGoldenFile() throws Exception { public void drawFrame_noEdits_matchesGoldenFile() throws Exception {
String testId = "drawFrame_noEdits";
presentationShaderProgram = presentationShaderProgram =
Presentation.createForHeight(C.LENGTH_UNSET) Presentation.createForHeight(C.LENGTH_UNSET)
.toGlShaderProgram(context, /* useHdr= */ false); .toGlShaderProgram(context, /* useHdr= */ false);
@ -122,8 +135,8 @@ public final class PresentationPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_changeAspectRatio_scaleToFit_narrow_matchesGoldenFile() throws Exception { public void drawFrame_changeAspectRatio_scaleToFit_narrow_matchesGoldenFile() throws Exception {
String testId = "drawFrame_changeAspectRatio_scaleToFit_narrow";
presentationShaderProgram = presentationShaderProgram =
Presentation.createForAspectRatio(/* aspectRatio= */ 1f, Presentation.LAYOUT_SCALE_TO_FIT) Presentation.createForAspectRatio(/* aspectRatio= */ 1f, Presentation.LAYOUT_SCALE_TO_FIT)
.toGlShaderProgram(context, /* useHdr= */ false); .toGlShaderProgram(context, /* useHdr= */ false);
@ -143,8 +156,8 @@ public final class PresentationPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_changeAspectRatio_scaleToFit_wide_matchesGoldenFile() throws Exception { public void drawFrame_changeAspectRatio_scaleToFit_wide_matchesGoldenFile() throws Exception {
String testId = "drawFrame_changeAspectRatio_scaleToFit_wide";
presentationShaderProgram = presentationShaderProgram =
Presentation.createForAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT) Presentation.createForAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT)
.toGlShaderProgram(context, /* useHdr= */ false); .toGlShaderProgram(context, /* useHdr= */ false);
@ -164,9 +177,9 @@ public final class PresentationPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_changeAspectRatio_scaleToFitWithCrop_narrow_matchesGoldenFile() public void drawFrame_changeAspectRatio_scaleToFitWithCrop_narrow_matchesGoldenFile()
throws Exception { throws Exception {
String testId = "drawFrame_changeAspectRatio_scaleToFitWithCrop_narrow";
presentationShaderProgram = presentationShaderProgram =
Presentation.createForAspectRatio( Presentation.createForAspectRatio(
/* aspectRatio= */ 1f, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP) /* aspectRatio= */ 1f, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP)
@ -187,9 +200,9 @@ public final class PresentationPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_changeAspectRatio_scaleToFitWithCrop_wide_matchesGoldenFile() public void drawFrame_changeAspectRatio_scaleToFitWithCrop_wide_matchesGoldenFile()
throws Exception { throws Exception {
String testId = "drawFrame_changeAspectRatio_scaleToFitWithCrop_wide";
presentationShaderProgram = presentationShaderProgram =
Presentation.createForAspectRatio( Presentation.createForAspectRatio(
/* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP) /* aspectRatio= */ 2f, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP)
@ -210,8 +223,8 @@ public final class PresentationPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_changeAspectRatio_stretchToFit_narrow_matchesGoldenFile() throws Exception { public void drawFrame_changeAspectRatio_stretchToFit_narrow_matchesGoldenFile() throws Exception {
String testId = "drawFrame_changeAspectRatio_stretchToFit_narrow";
presentationShaderProgram = presentationShaderProgram =
Presentation.createForAspectRatio(/* aspectRatio= */ 1f, Presentation.LAYOUT_STRETCH_TO_FIT) Presentation.createForAspectRatio(/* aspectRatio= */ 1f, Presentation.LAYOUT_STRETCH_TO_FIT)
.toGlShaderProgram(context, /* useHdr= */ false); .toGlShaderProgram(context, /* useHdr= */ false);
@ -231,8 +244,8 @@ public final class PresentationPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_changeAspectRatio_stretchToFit_wide_matchesGoldenFile() throws Exception { public void drawFrame_changeAspectRatio_stretchToFit_wide_matchesGoldenFile() throws Exception {
String testId = "drawFrame_changeAspectRatio_stretchToFit_wide";
presentationShaderProgram = presentationShaderProgram =
Presentation.createForAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_STRETCH_TO_FIT) Presentation.createForAspectRatio(/* aspectRatio= */ 2f, Presentation.LAYOUT_STRETCH_TO_FIT)
.toGlShaderProgram(context, /* useHdr= */ false); .toGlShaderProgram(context, /* useHdr= */ false);

View File

@ -40,10 +40,14 @@ import androidx.media3.test.utils.BitmapPixelTestUtil;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.io.IOException; import java.io.IOException;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** /**
@ -56,6 +60,8 @@ import org.junit.runner.RunWith;
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public final class RgbAdjustmentPixelTest { public final class RgbAdjustmentPixelTest {
@Rule public final TestName testName = new TestName();
private static final String ORIGINAL_PNG_ASSET_PATH = private static final String ORIGINAL_PNG_ASSET_PATH =
"media/bitmap/sample_mp4_first_frame/linear_colors/original.png"; "media/bitmap/sample_mp4_first_frame/linear_colors/original.png";
private static final String ONLY_RED_CHANNEL_PNG_ASSET_PATH = private static final String ONLY_RED_CHANNEL_PNG_ASSET_PATH =
@ -67,6 +73,7 @@ public final class RgbAdjustmentPixelTest {
private final Context context = getApplicationContext(); private final Context context = getApplicationContext();
private @MonotonicNonNull String testId;
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram; private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram;
@ -98,6 +105,12 @@ public final class RgbAdjustmentPixelTest {
inputHeight); inputHeight);
} }
@Before
@EnsuresNonNull("testId")
public void setUpTestId() {
testId = testName.getMethodName();
}
@After @After
public void release() throws GlUtil.GlException, VideoFrameProcessingException { public void release() throws GlUtil.GlException, VideoFrameProcessingException {
if (defaultShaderProgram != null) { if (defaultShaderProgram != null) {
@ -107,8 +120,8 @@ public final class RgbAdjustmentPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_identityMatrix_leavesFrameUnchanged() throws Exception { public void drawFrame_identityMatrix_leavesFrameUnchanged() throws Exception {
String testId = "drawFrame_identityMatrix";
RgbMatrix identityMatrix = new RgbAdjustment.Builder().build(); RgbMatrix identityMatrix = new RgbAdjustment.Builder().build();
defaultShaderProgram = identityMatrix.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram = identityMatrix.toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight);
@ -125,8 +138,8 @@ public final class RgbAdjustmentPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_removeColors_producesBlackFrame() throws Exception { public void drawFrame_removeColors_producesBlackFrame() throws Exception {
String testId = "drawFrame_removeColors";
RgbMatrix removeColorMatrix = RgbMatrix removeColorMatrix =
new RgbAdjustment.Builder().setRedScale(0).setGreenScale(0).setBlueScale(0).build(); new RgbAdjustment.Builder().setRedScale(0).setGreenScale(0).setBlueScale(0).build();
defaultShaderProgram = removeColorMatrix.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram = removeColorMatrix.toGlShaderProgram(context, /* useHdr= */ false);
@ -146,8 +159,8 @@ public final class RgbAdjustmentPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_redOnlyFilter_removeBlueAndGreenValues() throws Exception { public void drawFrame_redOnlyFilter_removeBlueAndGreenValues() throws Exception {
String testId = "drawFrame_redOnlyFilter";
RgbMatrix redOnlyMatrix = new RgbAdjustment.Builder().setBlueScale(0).setGreenScale(0).build(); RgbMatrix redOnlyMatrix = new RgbAdjustment.Builder().setBlueScale(0).setGreenScale(0).build();
defaultShaderProgram = redOnlyMatrix.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram = redOnlyMatrix.toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight);
@ -164,8 +177,8 @@ public final class RgbAdjustmentPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_increaseRedChannel_producesBrighterAndRedderFrame() throws Exception { public void drawFrame_increaseRedChannel_producesBrighterAndRedderFrame() throws Exception {
String testId = "drawFrame_increaseRedChannel";
RgbMatrix increaseRedMatrix = new RgbAdjustment.Builder().setRedScale(5).build(); RgbMatrix increaseRedMatrix = new RgbAdjustment.Builder().setRedScale(5).build();
defaultShaderProgram = increaseRedMatrix.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram = increaseRedMatrix.toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight);
@ -182,8 +195,8 @@ public final class RgbAdjustmentPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_increaseBrightness_increasesAllValues() throws Exception { public void drawFrame_increaseBrightness_increasesAllValues() throws Exception {
String testId = "drawFrame_increaseBrightness";
RgbMatrix increaseBrightnessMatrix = RgbMatrix increaseBrightnessMatrix =
new RgbAdjustment.Builder().setRedScale(5).setGreenScale(5).setBlueScale(5).build(); new RgbAdjustment.Builder().setRedScale(5).setGreenScale(5).setBlueScale(5).build();
defaultShaderProgram = increaseBrightnessMatrix.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram = increaseBrightnessMatrix.toGlShaderProgram(context, /* useHdr= */ false);
@ -201,8 +214,8 @@ public final class RgbAdjustmentPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_removeRedGreenAndBlueValuesInAChain_producesBlackImage() throws Exception { public void drawFrame_removeRedGreenAndBlueValuesInAChain_producesBlackImage() throws Exception {
String testId = "drawFrame_removeRedGreenBlueValuesInAChain";
RgbMatrix noRed = new RgbAdjustment.Builder().setRedScale(0).build(); RgbMatrix noRed = new RgbAdjustment.Builder().setRedScale(0).build();
RgbMatrix noGreen = new RgbAdjustment.Builder().setGreenScale(0).build(); RgbMatrix noGreen = new RgbAdjustment.Builder().setGreenScale(0).build();
RgbMatrix noBlue = new RgbAdjustment.Builder().setBlueScale(0).build(); RgbMatrix noBlue = new RgbAdjustment.Builder().setBlueScale(0).build();
@ -228,8 +241,8 @@ public final class RgbAdjustmentPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_removeBlueAndGreenValuesInAChain_producesOnlyRedImage() throws Exception { public void drawFrame_removeBlueAndGreenValuesInAChain_producesOnlyRedImage() throws Exception {
String testId = "drawFrame_removeBlueAndGreenValuesInAChain";
RgbMatrix noGreen = new RgbAdjustment.Builder().setGreenScale(0).build(); RgbMatrix noGreen = new RgbAdjustment.Builder().setGreenScale(0).build();
RgbMatrix noBlue = new RgbAdjustment.Builder().setBlueScale(0).build(); RgbMatrix noBlue = new RgbAdjustment.Builder().setBlueScale(0).build();
defaultShaderProgram = defaultShaderProgram =
@ -252,8 +265,8 @@ public final class RgbAdjustmentPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_increasesAndDecreasesRed_producesNoChange() throws Exception { public void drawFrame_increasesAndDecreasesRed_producesNoChange() throws Exception {
String testId = "drawFrame_increaseAndDecreaseRed";
float redScale = 4; float redScale = 4;
RgbMatrix scaleRedMatrix = new RgbAdjustment.Builder().setRedScale(redScale).build(); RgbMatrix scaleRedMatrix = new RgbAdjustment.Builder().setRedScale(redScale).build();
RgbMatrix scaleRedByInverseMatrix = RgbMatrix scaleRedByInverseMatrix =

View File

@ -37,10 +37,14 @@ import androidx.media3.common.util.Size;
import androidx.media3.test.utils.BitmapPixelTestUtil; import androidx.media3.test.utils.BitmapPixelTestUtil;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import java.io.IOException; import java.io.IOException;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** /**
@ -53,6 +57,8 @@ import org.junit.runner.RunWith;
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public final class RgbFilterPixelTest { public final class RgbFilterPixelTest {
@Rule public final TestName testName = new TestName();
private static final String ORIGINAL_PNG_ASSET_PATH = private static final String ORIGINAL_PNG_ASSET_PATH =
"media/bitmap/sample_mp4_first_frame/linear_colors/original.png"; "media/bitmap/sample_mp4_first_frame/linear_colors/original.png";
private static final String GRAYSCALE_PNG_ASSET_PATH = private static final String GRAYSCALE_PNG_ASSET_PATH =
@ -62,6 +68,7 @@ public final class RgbFilterPixelTest {
private final Context context = getApplicationContext(); private final Context context = getApplicationContext();
private @MonotonicNonNull String testId;
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram; private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram;
@ -93,6 +100,12 @@ public final class RgbFilterPixelTest {
inputHeight); inputHeight);
} }
@Before
@EnsuresNonNull("testId")
public void setUpTestId() {
testId = testName.getMethodName();
}
@After @After
public void release() throws GlUtil.GlException, VideoFrameProcessingException { public void release() throws GlUtil.GlException, VideoFrameProcessingException {
if (defaultShaderProgram != null) { if (defaultShaderProgram != null) {
@ -102,8 +115,8 @@ public final class RgbFilterPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_grayscale_producesGrayscaleImage() throws Exception { public void drawFrame_grayscale_producesGrayscaleImage() throws Exception {
String testId = "drawFrame_grayscale";
RgbMatrix grayscaleMatrix = RgbFilter.createGrayscaleFilter(); RgbMatrix grayscaleMatrix = RgbFilter.createGrayscaleFilter();
defaultShaderProgram = grayscaleMatrix.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram = grayscaleMatrix.toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight);
@ -120,8 +133,8 @@ public final class RgbFilterPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_inverted_producesInvertedFrame() throws Exception { public void drawFrame_inverted_producesInvertedFrame() throws Exception {
String testId = "drawFrame_inverted";
RgbMatrix invertedMatrix = RgbFilter.createInvertedFilter(); RgbMatrix invertedMatrix = RgbFilter.createInvertedFilter();
defaultShaderProgram = invertedMatrix.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram = invertedMatrix.toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight);

View File

@ -37,10 +37,14 @@ import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.Size; import androidx.media3.common.util.Size;
import androidx.media3.test.utils.BitmapPixelTestUtil; import androidx.media3.test.utils.BitmapPixelTestUtil;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** /**
@ -53,6 +57,8 @@ import org.junit.runner.RunWith;
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class SingleColorLutPixelTest { public class SingleColorLutPixelTest {
@Rule public final TestName testName = new TestName();
private static final String ORIGINAL_PNG_ASSET_PATH = private static final String ORIGINAL_PNG_ASSET_PATH =
"media/bitmap/sample_mp4_first_frame/linear_colors/original.png"; "media/bitmap/sample_mp4_first_frame/linear_colors/original.png";
private static final String LUT_MAP_WHITE_TO_GREEN_ASSET_PATH = private static final String LUT_MAP_WHITE_TO_GREEN_ASSET_PATH =
@ -67,6 +73,7 @@ public class SingleColorLutPixelTest {
private final Context context = getApplicationContext(); private final Context context = getApplicationContext();
private @MonotonicNonNull String testId;
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull EGLSurface placeholderEglSurface; private @MonotonicNonNull EGLSurface placeholderEglSurface;
@ -87,6 +94,12 @@ public class SingleColorLutPixelTest {
inputTexId = createGlTextureFromBitmap(inputBitmap); inputTexId = createGlTextureFromBitmap(inputBitmap);
} }
@Before
@EnsuresNonNull("testId")
public void setUpTestId() {
testId = testName.getMethodName();
}
@After @After
public void release() throws GlUtil.GlException, VideoFrameProcessingException { public void release() throws GlUtil.GlException, VideoFrameProcessingException {
if (colorLutShaderProgram != null) { if (colorLutShaderProgram != null) {
@ -96,8 +109,8 @@ public class SingleColorLutPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_identityCubeLutSize2_leavesFrameUnchanged() throws Exception { public void drawFrame_identityCubeLutSize2_leavesFrameUnchanged() throws Exception {
String testId = "drawFrame_identityLutCubeSize2";
int[][][] cubeIdentityLut = createIdentityLutCube(/* length= */ 2); int[][][] cubeIdentityLut = createIdentityLutCube(/* length= */ 2);
colorLutShaderProgram = colorLutShaderProgram =
SingleColorLut.createFromCube(cubeIdentityLut) SingleColorLut.createFromCube(cubeIdentityLut)
@ -117,8 +130,8 @@ public class SingleColorLutPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_identityCubeLutSize64_leavesFrameUnchanged() throws Exception { public void drawFrame_identityCubeLutSize64_leavesFrameUnchanged() throws Exception {
String testId = "drawFrame_identityLutCubeSize64";
int[][][] cubeIdentityLut = createIdentityLutCube(/* length= */ 64); int[][][] cubeIdentityLut = createIdentityLutCube(/* length= */ 64);
colorLutShaderProgram = colorLutShaderProgram =
SingleColorLut.createFromCube(cubeIdentityLut) SingleColorLut.createFromCube(cubeIdentityLut)
@ -138,8 +151,8 @@ public class SingleColorLutPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_identityBitmapLutSize2_leavesFrameUnchanged() throws Exception { public void drawFrame_identityBitmapLutSize2_leavesFrameUnchanged() throws Exception {
String testId = "drawFrame_identityBitmapLutSize2";
Bitmap bitmapLut = createIdentityLutBitmap(/* length= */ 2); Bitmap bitmapLut = createIdentityLutBitmap(/* length= */ 2);
colorLutShaderProgram = colorLutShaderProgram =
SingleColorLut.createFromBitmap(bitmapLut).toGlShaderProgram(context, /* useHdr= */ false); SingleColorLut.createFromBitmap(bitmapLut).toGlShaderProgram(context, /* useHdr= */ false);
@ -158,8 +171,8 @@ public class SingleColorLutPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_identityBitmapLutSize64_leavesFrameUnchanged() throws Exception { public void drawFrame_identityBitmapLutSize64_leavesFrameUnchanged() throws Exception {
String testId = "drawFrame_identityBitmapLutSize64";
Bitmap bitmapLut = createIdentityLutBitmap(/* length= */ 64); Bitmap bitmapLut = createIdentityLutBitmap(/* length= */ 64);
colorLutShaderProgram = colorLutShaderProgram =
SingleColorLut.createFromBitmap(bitmapLut).toGlShaderProgram(context, /* useHdr= */ false); SingleColorLut.createFromBitmap(bitmapLut).toGlShaderProgram(context, /* useHdr= */ false);
@ -178,8 +191,8 @@ public class SingleColorLutPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_identityLutFromHaldImage_leavesFrameUnchanged() throws Exception { public void drawFrame_identityLutFromHaldImage_leavesFrameUnchanged() throws Exception {
String testId = "drawFrame_identityLutFromHaldImage";
Bitmap bitmapLut = readBitmap(VERTICAL_HALD_IDENTITY_LUT); Bitmap bitmapLut = readBitmap(VERTICAL_HALD_IDENTITY_LUT);
colorLutShaderProgram = colorLutShaderProgram =
SingleColorLut.createFromBitmap(bitmapLut).toGlShaderProgram(context, /* useHdr= */ false); SingleColorLut.createFromBitmap(bitmapLut).toGlShaderProgram(context, /* useHdr= */ false);
@ -198,8 +211,8 @@ public class SingleColorLutPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_mapWhiteToGreen_producesGreenHighlights() throws Exception { public void drawFrame_mapWhiteToGreen_producesGreenHighlights() throws Exception {
String testId = "drawFrame_mapWhiteToGreen";
int length = 3; int length = 3;
int[][][] mapWhiteToGreen = createIdentityLutCube(length); int[][][] mapWhiteToGreen = createIdentityLutCube(length);
mapWhiteToGreen[length - 1][length - 1][length - 1] = Color.GREEN; mapWhiteToGreen[length - 1][length - 1][length - 1] = Color.GREEN;
@ -221,8 +234,8 @@ public class SingleColorLutPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_applyInvertedLut_producesInvertedFrame() throws Exception { public void drawFrame_applyInvertedLut_producesInvertedFrame() throws Exception {
String testId = "drawFrame_applyInvertedLut";
Bitmap invertedLutBitmap = readBitmap(VERTICAL_HALD_INVERTED_LUT); Bitmap invertedLutBitmap = readBitmap(VERTICAL_HALD_INVERTED_LUT);
colorLutShaderProgram = colorLutShaderProgram =
SingleColorLut.createFromBitmap(invertedLutBitmap) SingleColorLut.createFromBitmap(invertedLutBitmap)
@ -242,8 +255,8 @@ public class SingleColorLutPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void drawFrame_applyGrayscaleLut_producesGrayscaleFrame() throws Exception { public void drawFrame_applyGrayscaleLut_producesGrayscaleFrame() throws Exception {
String testId = "drawFrame_applyGrayscaleLut";
Bitmap grayscaleLutBitmap = readBitmap(VERTICAL_HALD_GRAYSCALE_LUT); Bitmap grayscaleLutBitmap = readBitmap(VERTICAL_HALD_GRAYSCALE_LUT);
colorLutShaderProgram = colorLutShaderProgram =
SingleColorLut.createFromBitmap(grayscaleLutBitmap) SingleColorLut.createFromBitmap(grayscaleLutBitmap)

View File

@ -308,6 +308,7 @@ public class BitmapPixelTestUtil {
*/ */
public static float getBitmapAveragePixelAbsoluteDifferenceArgb8888( public static float getBitmapAveragePixelAbsoluteDifferenceArgb8888(
Bitmap expected, Bitmap actual, @Nullable String testId) { Bitmap expected, Bitmap actual, @Nullable String testId) {
Log.e("TEST", "testId = " + testId);
return getBitmapAveragePixelAbsoluteDifferenceArgb8888( return getBitmapAveragePixelAbsoluteDifferenceArgb8888(
expected, actual, testId, /* differencesBitmapPath= */ null); expected, actual, testId, /* differencesBitmapPath= */ null);
} }

View File

@ -48,9 +48,12 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
import org.junit.After; import org.junit.After;
import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestName; import org.junit.rules.TestName;
@ -60,6 +63,13 @@ import org.junit.runners.Parameterized;
/** Pixel test for {@link DefaultVideoCompositor} compositing 2 input frames into 1 output frame. */ /** Pixel test for {@link DefaultVideoCompositor} compositing 2 input frames into 1 output frame. */
@RunWith(Parameterized.class) @RunWith(Parameterized.class)
public final class DefaultVideoCompositorPixelTest { public final class DefaultVideoCompositorPixelTest {
@Parameterized.Parameters(name = "useSharedExecutor={0}")
public static ImmutableList<Boolean> useSharedExecutor() {
return ImmutableList.of(true, false);
}
@Parameterized.Parameter public boolean useSharedExecutor;
@Rule public final TestName testName = new TestName();
private static final String ORIGINAL_PNG_ASSET_PATH = "media/bitmap/input_images/media3test.png"; private static final String ORIGINAL_PNG_ASSET_PATH = "media/bitmap/input_images/media3test.png";
private static final String GRAYSCALE_PNG_ASSET_PATH = private static final String GRAYSCALE_PNG_ASSET_PATH =
@ -69,16 +79,15 @@ public final class DefaultVideoCompositorPixelTest {
private static final String GRAYSCALE_AND_ROTATE180_COMPOSITE_PNG_ASSET_PATH = private static final String GRAYSCALE_AND_ROTATE180_COMPOSITE_PNG_ASSET_PATH =
"media/bitmap/sample_mp4_first_frame/electrical_colors/grayscaleAndRotate180Composite.png"; "media/bitmap/sample_mp4_first_frame/electrical_colors/grayscaleAndRotate180Composite.png";
@Parameterized.Parameters(name = "useSharedExecutor={0}") private @MonotonicNonNull String testId;
public static ImmutableList<Boolean> useSharedExecutor() {
return ImmutableList.of(true, false);
}
@Parameterized.Parameter public boolean useSharedExecutor;
@Rule public TestName testName = new TestName();
private @MonotonicNonNull VideoCompositorTestRunner compositorTestRunner; private @MonotonicNonNull VideoCompositorTestRunner compositorTestRunner;
@Before
@EnsuresNonNull("testId")
public void setUpTestId() {
testId = testName.getMethodName();
}
@After @After
public void tearDown() { public void tearDown() {
if (compositorTestRunner != null) { if (compositorTestRunner != null) {
@ -87,8 +96,8 @@ public final class DefaultVideoCompositorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void compositeTwoInputs_withOneFrameFromEach_matchesExpectedBitmap() throws Exception { public void compositeTwoInputs_withOneFrameFromEach_matchesExpectedBitmap() throws Exception {
String testId = testName.getMethodName();
compositorTestRunner = new VideoCompositorTestRunner(testId, useSharedExecutor); compositorTestRunner = new VideoCompositorTestRunner(testId, useSharedExecutor);
compositorTestRunner.queueBitmapsToBothInputs(/* count= */ 1); compositorTestRunner.queueBitmapsToBothInputs(/* count= */ 1);
@ -108,9 +117,9 @@ public final class DefaultVideoCompositorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void compositeTwoInputs_withFiveFramesFromEach_matchesExpectedTimestamps() public void compositeTwoInputs_withFiveFramesFromEach_matchesExpectedTimestamps()
throws Exception { throws Exception {
String testId = testName.getMethodName();
compositorTestRunner = new VideoCompositorTestRunner(testId, useSharedExecutor); compositorTestRunner = new VideoCompositorTestRunner(testId, useSharedExecutor);
compositorTestRunner.queueBitmapsToBothInputs(/* count= */ 5); compositorTestRunner.queueBitmapsToBothInputs(/* count= */ 5);
@ -136,9 +145,9 @@ public final class DefaultVideoCompositorPixelTest {
} }
@Test @Test
@RequiresNonNull("testId")
public void compositeTwoInputs_withTenFramesFromEach_matchesExpectedFrameCount() public void compositeTwoInputs_withTenFramesFromEach_matchesExpectedFrameCount()
throws Exception { throws Exception {
String testId = testName.getMethodName();
compositorTestRunner = new VideoCompositorTestRunner(testId, useSharedExecutor); compositorTestRunner = new VideoCompositorTestRunner(testId, useSharedExecutor);
int numberOfFramesToQueue = 10; int numberOfFramesToQueue = 10;