Test: Move OpenGL tone mapping capabilities check to utility method.

PiperOrigin-RevId: 570316091
This commit is contained in:
huangdarwin 2023-10-03 01:58:25 -07:00 committed by Copybara-Service
parent 9ca5d50b2d
commit 8953f26a5c
3 changed files with 78 additions and 69 deletions

View file

@ -0,0 +1,69 @@
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package androidx.media3.transformer.mh;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT;
import static androidx.media3.transformer.AndroidTestUtil.recordTestSkipped;
import static androidx.media3.transformer.AndroidTestUtil.skipAndLogIfFormatsUnsupported;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import android.content.Context;
import androidx.media3.common.ColorInfo;
import androidx.media3.common.Format;
import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.Util;
import androidx.media3.exoplayer.mediacodec.MediaCodecUtil;
import java.io.IOException;
import org.json.JSONException;
/** Utility class for checking HDR capabilities. */
public final class HdrCapabilitiesUtil {
private static final String SKIP_REASON_NO_OPENGL_UNDER_API_29 =
"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.";
/**
* Returns whether the test should be skipped because the device is incapable of tone-mapping the
* {@code inputFormat} using OpenGL.
*
* <p>If the test should be skipped, logs the reason for skipping.
*/
public static boolean skipAndLogIfOpenGlToneMappingUnsupported(String testId, Format inputFormat)
throws JSONException, IOException, MediaCodecUtil.DecoderQueryException {
Context context = getApplicationContext();
if (Util.SDK_INT < 29) {
recordTestSkipped(context, testId, SKIP_REASON_NO_OPENGL_UNDER_API_29);
return true;
}
if (!GlUtil.isYuvTargetExtensionSupported()) {
recordTestSkipped(context, testId, SKIP_REASON_NO_YUV);
return true;
}
if (skipAndLogIfFormatsUnsupported(
context,
testId,
inputFormat,
/* outputFormat= */ MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT
.buildUpon()
.setColorInfo(ColorInfo.SDR_BT709_LIMITED)
.build())) {
return true;
}
return false;
}
private HdrCapabilitiesUtil() {}
}

View file

@ -21,19 +21,15 @@ import static androidx.media3.test.utils.BitmapPixelTestUtil.readBitmap;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_720P_4_SECOND_HDR10_FORMAT;
import static androidx.media3.transformer.AndroidTestUtil.recordTestSkipped;
import static androidx.media3.transformer.AndroidTestUtil.skipAndLogIfFormatsUnsupported;
import static androidx.media3.transformer.mh.HdrCapabilitiesUtil.skipAndLogIfOpenGlToneMappingUnsupported;
import static androidx.media3.transformer.mh.UnoptimizedGlEffect.NO_OP_EFFECT;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import androidx.media3.common.C;
import androidx.media3.common.ColorInfo;
import androidx.media3.common.Format;
import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.Util;
import androidx.media3.effect.DefaultVideoFrameProcessor;
import androidx.media3.test.utils.DecodeOneFrameUtil;
import androidx.media3.test.utils.VideoFrameProcessorTestRunner;
@ -78,10 +74,6 @@ public final class ToneMapHdrToSdrUsingOpenGlPixelTest {
/** Input PQ video of which we only use the first frame. */
private static final String INPUT_PQ_MP4_ASSET_STRING = "media/mp4/hdr10-720p.mp4";
private static final String SKIP_REASON_NO_OPENGL_UNDER_API_29 =
"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)
@ -101,7 +93,7 @@ public final class ToneMapHdrToSdrUsingOpenGlPixelTest {
@Test
public void toneMap_hlgFrame_matchesGoldenFile() throws Exception {
String testId = "toneMap_hlgFrame_matchesGoldenFile";
if (!deviceSupportsOpenGlToneMapping(testId, MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT)) {
if (skipAndLogIfOpenGlToneMappingUnsupported(testId, MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT)) {
return;
}
videoFrameProcessorTestRunner =
@ -140,7 +132,7 @@ public final class ToneMapHdrToSdrUsingOpenGlPixelTest {
@Test
public void toneMapWithNoOpEffect_hlgFrame_matchesGoldenFile() throws Exception {
String testId = "toneMapWithNoOpEffect_hlgFrame_matchesGoldenFile";
if (!deviceSupportsOpenGlToneMapping(testId, MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT)) {
if (skipAndLogIfOpenGlToneMappingUnsupported(testId, MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT)) {
return;
}
videoFrameProcessorTestRunner =
@ -180,7 +172,7 @@ public final class ToneMapHdrToSdrUsingOpenGlPixelTest {
@Test
public void toneMap_pqFrame_matchesGoldenFile() throws Exception {
String testId = "toneMap_pqFrame_matchesGoldenFile";
if (!deviceSupportsOpenGlToneMapping(testId, MP4_ASSET_720P_4_SECOND_HDR10_FORMAT)) {
if (skipAndLogIfOpenGlToneMappingUnsupported(testId, MP4_ASSET_720P_4_SECOND_HDR10_FORMAT)) {
return;
}
@ -220,7 +212,7 @@ public final class ToneMapHdrToSdrUsingOpenGlPixelTest {
@Test
public void toneMapWithNoOpEffect_pqFrame_matchesGoldenFile() throws Exception {
String testId = "toneMapWithNoOpEffect_pqFrame_matchesGoldenFile";
if (!deviceSupportsOpenGlToneMapping(testId, MP4_ASSET_720P_4_SECOND_HDR10_FORMAT)) {
if (skipAndLogIfOpenGlToneMappingUnsupported(testId, MP4_ASSET_720P_4_SECOND_HDR10_FORMAT)) {
return;
}
@ -258,23 +250,6 @@ public final class ToneMapHdrToSdrUsingOpenGlPixelTest {
.isAtMost(MAXIMUM_DEVICE_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE);
}
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()

View file

@ -21,19 +21,12 @@ import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_720P_4_SECON
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_720P_4_SECOND_HDR10_FORMAT;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_DOLBY_VISION_HDR;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_DOLBY_VISION_HDR_FORMAT;
import static androidx.media3.transformer.AndroidTestUtil.recordTestSkipped;
import static androidx.media3.transformer.mh.FileUtil.assertFileHasColorTransfer;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static androidx.media3.transformer.mh.HdrCapabilitiesUtil.skipAndLogIfOpenGlToneMappingUnsupported;
import android.content.Context;
import androidx.media3.common.C;
import androidx.media3.common.ColorInfo;
import androidx.media3.common.Format;
import androidx.media3.common.MediaItem;
import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.Util;
import androidx.media3.exoplayer.mediacodec.MediaCodecUtil;
import androidx.media3.transformer.AndroidTestUtil;
import androidx.media3.transformer.Composition;
import androidx.media3.transformer.EditedMediaItem;
import androidx.media3.transformer.EditedMediaItemSequence;
@ -42,8 +35,6 @@ import androidx.media3.transformer.Transformer;
import androidx.media3.transformer.TransformerAndroidTestRunner;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import java.io.IOException;
import org.json.JSONException;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -59,7 +50,7 @@ public class ToneMapHdrToSdrUsingOpenGlTest {
@Test
public void export_toneMap_hlg10File_toneMaps() throws Exception {
String testId = "export_glToneMap_hlg10File_toneMaps";
if (!deviceSupportsOpenGlToneMapping(
if (skipAndLogIfOpenGlToneMappingUnsupported(
testId, /* inputFormat= */ MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT)) {
return;
}
@ -70,7 +61,7 @@ public class ToneMapHdrToSdrUsingOpenGlTest {
@Test
public void export_toneMap_hdr10File_toneMaps() throws Exception {
String testId = "export_glToneMap_hdr10File_toneMaps";
if (!deviceSupportsOpenGlToneMapping(
if (skipAndLogIfOpenGlToneMappingUnsupported(
testId, /* inputFormat= */ MP4_ASSET_720P_4_SECOND_HDR10_FORMAT)) {
return;
}
@ -81,7 +72,7 @@ public class ToneMapHdrToSdrUsingOpenGlTest {
@Test
public void export_toneMap_dolbyVisionFile_toneMaps() throws Exception {
String testId = "export_toneMap_dolbyVisionFile_toneMaps";
if (!deviceSupportsOpenGlToneMapping(
if (skipAndLogIfOpenGlToneMappingUnsupported(
testId, /* inputFormat= */ MP4_ASSET_DOLBY_VISION_HDR_FORMAT)) {
return;
}
@ -103,30 +94,4 @@ public class ToneMapHdrToSdrUsingOpenGlTest {
.run(testId, composition);
assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
}
private static boolean deviceSupportsOpenGlToneMapping(String testId, Format inputFormat)
throws JSONException, IOException, MediaCodecUtil.DecoderQueryException {
Context context = getApplicationContext();
if (Util.SDK_INT < 29) {
recordTestSkipped(
context,
testId,
/* reason= */ "OpenGL-based HDR to SDR tone mapping is only supported on API 29+.");
return false;
}
if (!GlUtil.isYuvTargetExtensionSupported()) {
recordTestSkipped(context, testId, /* reason= */ "Device lacks YUV extension support.");
return false;
}
return !AndroidTestUtil.skipAndLogIfFormatsUnsupported(
context,
testId,
inputFormat,
/* outputFormat= */ inputFormat
.buildUpon()
.setColorInfo(ColorInfo.SDR_BT709_LIMITED)
.build());
}
}