1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.mediav2.cts; 18 19 import android.media.MediaFormat; 20 import android.os.Build; 21 22 import androidx.test.filters.SdkSuppress; 23 import androidx.test.filters.SmallTest; 24 25 import org.junit.Assume; 26 import org.junit.Test; 27 import org.junit.runner.RunWith; 28 import org.junit.runners.Parameterized; 29 30 import java.io.IOException; 31 import java.nio.ByteBuffer; 32 import java.util.ArrayList; 33 import java.util.Arrays; 34 import java.util.Collection; 35 import java.util.List; 36 37 /** 38 * Test to validate hdr static metadata in decoders 39 */ 40 @RunWith(Parameterized.class) 41 // P010 support was added in Android T, hence limit the following tests to Android T and above 42 @SdkSuppress(minSdkVersion = Build.VERSION_CODES.TIRAMISU, codeName = "Tiramisu") 43 public class DecoderHDRInfoTest extends CodecDecoderTestBase { 44 private static final String LOG_TAG = DecoderHDRInfoTest.class.getSimpleName(); 45 private static final String HDR_STATIC_INFO = 46 "00 d0 84 80 3e c2 33 c4 86 4c 1d b8 0b 13 3d 42 40 a0 0f 32 00 10 27 df 0d"; 47 private static final String HDR_STATIC_INCORRECT_INFO = 48 "00 d0 84 80 3e c2 33 c4 86 10 27 d0 07 13 3d 42 40 a0 0f 32 00 10 27 df 0d"; 49 50 private final ByteBuffer mHDRStaticInfoStream; 51 private final ByteBuffer mHDRStaticInfoContainer; 52 DecoderHDRInfoTest(String codecName, String mediaType, String testFile, String hdrStaticInfoStream, String hdrStaticInfoContainer)53 public DecoderHDRInfoTest(String codecName, String mediaType, String testFile, 54 String hdrStaticInfoStream, String hdrStaticInfoContainer) { 55 super(codecName, mediaType, testFile); 56 mHDRStaticInfoStream = hdrStaticInfoStream != null ? 57 ByteBuffer.wrap(loadByteArrayFromString(hdrStaticInfoStream)) : null; 58 mHDRStaticInfoContainer = hdrStaticInfoContainer != null ? 59 ByteBuffer.wrap(loadByteArrayFromString(hdrStaticInfoContainer)) : null; 60 } 61 62 @Parameterized.Parameters(name = "{index}({0}_{1})") input()63 public static Collection<Object[]> input() { 64 final boolean isEncoder = false; 65 final boolean needAudio = false; 66 final boolean needVideo = true; 67 final List<Object[]> exhaustiveArgsList = Arrays.asList(new Object[][]{ 68 // codecMediaType, testFile, hdrInfo in stream, hdrInfo in container 69 {MediaFormat.MIMETYPE_VIDEO_HEVC, 70 "cosmat_352x288_hdr10_stream_and_container_correct_hevc.mkv", 71 HDR_STATIC_INFO, HDR_STATIC_INFO}, 72 {MediaFormat.MIMETYPE_VIDEO_HEVC, 73 "cosmat_352x288_hdr10_stream_correct_container_incorrect_hevc.mkv", 74 HDR_STATIC_INFO, HDR_STATIC_INCORRECT_INFO}, 75 {MediaFormat.MIMETYPE_VIDEO_HEVC, "cosmat_352x288_hdr10_only_stream_hevc.mkv", 76 HDR_STATIC_INFO, null}, 77 {MediaFormat.MIMETYPE_VIDEO_HEVC, "cosmat_352x288_hdr10_only_container_hevc.mkv", 78 null, HDR_STATIC_INFO}, 79 {MediaFormat.MIMETYPE_VIDEO_VP9, "cosmat_352x288_hdr10_only_container_vp9.mkv", 80 null, HDR_STATIC_INFO}, 81 {MediaFormat.MIMETYPE_VIDEO_AV1, 82 "cosmat_352x288_hdr10_stream_and_container_correct_av1.mkv", 83 HDR_STATIC_INFO, HDR_STATIC_INFO}, 84 {MediaFormat.MIMETYPE_VIDEO_AV1, 85 "cosmat_352x288_hdr10_stream_correct_container_incorrect_av1.mkv", 86 HDR_STATIC_INFO, HDR_STATIC_INCORRECT_INFO}, 87 {MediaFormat.MIMETYPE_VIDEO_AV1, "cosmat_352x288_hdr10_only_stream_av1.mkv", 88 HDR_STATIC_INFO, null}, 89 {MediaFormat.MIMETYPE_VIDEO_AV1, "cosmat_352x288_hdr10_only_container_av1.mkv", 90 null, HDR_STATIC_INFO}, 91 }); 92 return prepareParamList(exhaustiveArgsList, isEncoder, needAudio, needVideo, false); 93 } 94 95 @SmallTest 96 @Test(timeout = PER_TEST_TIMEOUT_SMALL_TEST_MS) testHDRMetadata()97 public void testHDRMetadata() throws IOException, InterruptedException { 98 int[] Hdr10Profiles = mProfileHdr10Map.get(mMime); 99 Assume.assumeNotNull("Test is only applicable to codecs that have HDR10 profiles", 100 Hdr10Profiles); 101 MediaFormat format = setUpSource(mTestFile); 102 mExtractor.release(); 103 ArrayList<MediaFormat> formats = new ArrayList<>(); 104 formats.add(format); 105 106 // When HDR metadata isn't present in the container, but included in the bitstream, 107 // extractors may not be able to populate HDR10/HDR10+ profiles correctly. 108 // In such cases, override the profile 109 if (mHDRStaticInfoContainer == null && mHDRStaticInfoStream != null) { 110 int profile = Hdr10Profiles[0]; 111 format.setInteger(MediaFormat.KEY_PROFILE, profile); 112 } 113 Assume.assumeTrue(areFormatsSupported(mCodecName, mMime, formats)); 114 115 if (mHDRStaticInfoContainer != null) { 116 validateHDRStaticMetaData(format, mHDRStaticInfoContainer); 117 } 118 119 validateHDRStaticMetaData(mInpPrefix, mTestFile, 120 mHDRStaticInfoStream == null ? mHDRStaticInfoContainer : mHDRStaticInfoStream, 121 false); 122 if (mHDRStaticInfoStream != null) { 123 if (EncoderHDRInfoTest.mCheckESList.contains(mMime)) { 124 validateHDRStaticMetaData(mInpPrefix, mTestFile, mHDRStaticInfoStream, true); 125 } 126 } 127 } 128 } 129