Commit a2467d4d by huangdarwin Committed by Tofunmi Adigun-Hameed

Test: Move duplicated GL tone mapping logic into helper methods.

PiperOrigin-RevId: 538491957
(cherry picked from commit 466308c736a2757edbddb0384f25f21dbca9e661)
parent e7673d46
......@@ -22,12 +22,15 @@ import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSE
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_720P_4_SECOND_HDR10_FORMAT;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.recordTestSkipped;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.skipAndLogIfFormatsUnsupported;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.effect.DefaultVideoFrameProcessor;
import com.google.android.exoplayer2.testutil.DecodeOneFrameUtil;
import com.google.android.exoplayer2.testutil.VideoFrameProcessorTestRunner;
......@@ -75,6 +78,13 @@ public final class ToneMapHdrToSdrUsingOpenGlPixelTest {
"OpenGL-based HDR to SDR tone mapping is unsupported below API 29.";
private static final String SKIP_REASON_NO_YUV = "Device lacks YUV extension support.";
private static final ColorInfo TONE_MAP_SDR_COLOR =
new ColorInfo.Builder()
.setColorSpace(C.COLOR_SPACE_BT709)
.setColorRange(C.COLOR_RANGE_LIMITED)
.setColorTransfer(C.COLOR_TRANSFER_GAMMA_2_2)
.build();
private @MonotonicNonNull VideoFrameProcessorTestRunner videoFrameProcessorTestRunner;
@After
......@@ -87,38 +97,14 @@ public final class ToneMapHdrToSdrUsingOpenGlPixelTest {
@Test
public void toneMap_hlgFrame_matchesGoldenFile() throws Exception {
String testId = "toneMap_hlgFrame_matchesGoldenFile";
if (Util.SDK_INT < 29) {
recordTestSkipped(getApplicationContext(), testId, SKIP_REASON_NO_OPENGL_UNDER_API_29);
return;
}
if (!GlUtil.isYuvTargetExtensionSupported()) {
recordTestSkipped(getApplicationContext(), testId, SKIP_REASON_NO_YUV);
return;
}
if (skipAndLogIfFormatsUnsupported(
getApplicationContext(),
testId,
/* inputFormat= */ MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT,
/* outputFormat= */ null)) {
if (!deviceSupportsOpenGlToneMapping(testId, MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT)) {
return;
}
ColorInfo hlgColor =
new ColorInfo.Builder()
.setColorSpace(C.COLOR_SPACE_BT2020)
.setColorRange(C.COLOR_RANGE_LIMITED)
.setColorTransfer(C.COLOR_TRANSFER_HLG)
.build();
ColorInfo toneMapSdrColor =
new ColorInfo.Builder()
.setColorSpace(C.COLOR_SPACE_BT709)
.setColorRange(C.COLOR_RANGE_LIMITED)
.setColorTransfer(C.COLOR_TRANSFER_GAMMA_2_2)
.build();
videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId)
.setVideoAssetPath(INPUT_HLG_MP4_ASSET_STRING)
.setInputColorInfo(hlgColor)
.setOutputColorInfo(toneMapSdrColor)
.setInputColorInfo(checkNotNull(MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT.colorInfo))
.setOutputColorInfo(TONE_MAP_SDR_COLOR)
.build();
Bitmap expectedBitmap = readBitmap(TONE_MAP_HLG_TO_SDR_PNG_ASSET_PATH);
......@@ -151,38 +137,15 @@ public final class ToneMapHdrToSdrUsingOpenGlPixelTest {
public void toneMap_pqFrame_matchesGoldenFile() throws Exception {
// TODO(b/239735341): Move this test to mobileharness testing.
String testId = "toneMap_pqFrame_matchesGoldenFile";
if (Util.SDK_INT < 29) {
recordTestSkipped(getApplicationContext(), testId, SKIP_REASON_NO_OPENGL_UNDER_API_29);
return;
}
if (!GlUtil.isYuvTargetExtensionSupported()) {
recordTestSkipped(getApplicationContext(), testId, SKIP_REASON_NO_YUV);
if (!deviceSupportsOpenGlToneMapping(testId, MP4_ASSET_720P_4_SECOND_HDR10_FORMAT)) {
return;
}
if (skipAndLogIfFormatsUnsupported(
getApplicationContext(),
testId,
/* inputFormat= */ MP4_ASSET_720P_4_SECOND_HDR10_FORMAT,
/* outputFormat= */ null)) {
return;
}
ColorInfo pqColor =
new ColorInfo.Builder()
.setColorSpace(C.COLOR_SPACE_BT2020)
.setColorRange(C.COLOR_RANGE_LIMITED)
.setColorTransfer(C.COLOR_TRANSFER_ST2084)
.build();
ColorInfo toneMapSdrColor =
new ColorInfo.Builder()
.setColorSpace(C.COLOR_SPACE_BT709)
.setColorRange(C.COLOR_RANGE_LIMITED)
.setColorTransfer(C.COLOR_TRANSFER_GAMMA_2_2)
.build();
videoFrameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId)
.setVideoAssetPath(INPUT_PQ_MP4_ASSET_STRING)
.setInputColorInfo(pqColor)
.setOutputColorInfo(toneMapSdrColor)
.setInputColorInfo(checkNotNull(MP4_ASSET_720P_4_SECOND_HDR10_FORMAT.colorInfo))
.setOutputColorInfo(TONE_MAP_SDR_COLOR)
.build();
Bitmap expectedBitmap = readBitmap(TONE_MAP_PQ_TO_SDR_PNG_ASSET_PATH);
......@@ -211,7 +174,24 @@ public final class ToneMapHdrToSdrUsingOpenGlPixelTest {
.isAtMost(MAXIMUM_DEVICE_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE);
}
private VideoFrameProcessorTestRunner.Builder getDefaultFrameProcessorTestRunnerBuilder(
private static boolean deviceSupportsOpenGlToneMapping(String testId, Format inputFormat)
throws Exception {
Context context = getApplicationContext();
if (Util.SDK_INT < 29) {
recordTestSkipped(context, testId, SKIP_REASON_NO_OPENGL_UNDER_API_29);
return false;
}
if (!GlUtil.isYuvTargetExtensionSupported()) {
recordTestSkipped(context, testId, SKIP_REASON_NO_YUV);
return false;
}
if (skipAndLogIfFormatsUnsupported(context, testId, inputFormat, /* outputFormat= */ null)) {
return false;
}
return true;
}
private static VideoFrameProcessorTestRunner.Builder getDefaultFrameProcessorTestRunnerBuilder(
String testId) {
return new VideoFrameProcessorTestRunner.Builder()
.setTestId(testId)
......
......@@ -104,22 +104,22 @@ public class ToneMapHdrToSdrUsingOpenGlTest {
private static boolean deviceSupportsOpenGlToneMapping(String testId, Format inputFormat)
throws JSONException, IOException, MediaCodecUtil.DecoderQueryException {
Context context = getApplicationContext();
if (Util.SDK_INT < 29) {
recordTestSkipped(
ApplicationProvider.getApplicationContext(),
context,
testId,
/* reason= */ "OpenGL-based HDR to SDR tone mapping is only supported on API 29+.");
return false;
}
if (!GlUtil.isYuvTargetExtensionSupported()) {
recordTestSkipped(
getApplicationContext(), testId, /* reason= */ "Device lacks YUV extension support.");
recordTestSkipped(context, testId, /* reason= */ "Device lacks YUV extension support.");
return false;
}
return !AndroidTestUtil.skipAndLogIfFormatsUnsupported(
getApplicationContext(),
context,
testId,
inputFormat,
/* outputFormat= */ inputFormat
......
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