1 /* 2 * Copyright (C) 2024 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.media.decoder.cts; 18 19 import static org.junit.Assume.assumeFalse; 20 21 import android.hardware.display.DisplayManager; 22 import android.media.MediaCodec; 23 import android.media.MediaExtractor; 24 import android.media.cts.MediaTestBase; 25 import android.view.Display; 26 27 import org.junit.After; 28 import org.junit.Before; 29 30 import java.util.Arrays; 31 import java.util.regex.Matcher; 32 import java.util.regex.Pattern; 33 34 public class HDRDecoderTestBase extends MediaTestBase { 35 private static final String TAG = "HDRDecoderTestBase"; 36 protected static final String MEDIA_DIR = WorkDir.getMediaDirString(); 37 38 protected DisplayManager mDisplayManager; 39 protected MediaExtractor mExtractor = null; 40 protected MediaCodec mDecoder = null; 41 42 protected static final String VP9_HDR_RES = "video_1280x720_vp9_hdr_static_3mbps.mkv"; 43 protected static final String VP9_HDR_STATIC_INFO = 44 "00 d0 84 80 3e c2 33 c4 86 4c 1d b8 0b 13 3d 42" + 45 "40 e8 03 64 00 e8 03 2c 01 " ; 46 47 protected static final String AV1_HDR_RES = "video_1280x720_av1_hdr_static_3mbps.webm"; 48 protected static final String AV1_HDR_STATIC_INFO = 49 "00 d0 84 80 3e c2 33 c4 86 4c 1d b8 0b 13 3d 42" + 50 "40 e8 03 64 00 e8 03 2c 01 " ; 51 52 // Expected value of MediaFormat.KEY_HDR_STATIC_INFO key. 53 // The associated value is a ByteBuffer. This buffer contains the raw contents of the 54 // Static Metadata Descriptor (including the descriptor ID) of an HDMI Dynamic Range and 55 // Mastering InfoFrame as defined by CTA-861.3. 56 // Media frameworks puts the display primaries in RGB order, here we verify the three 57 // primaries are indeed in this order and fail otherwise. 58 protected static final String H265_HDR10_RES = "video_1280x720_hevc_hdr10_static_3mbps.mp4"; 59 protected static final String H265_HDR10_STATIC_INFO = 60 "00 d0 84 80 3e c2 33 c4 86 4c 1d b8 0b 13 3d 42" + 61 "40 e8 03 00 00 e8 03 90 01 " ; 62 63 protected static final String VP9_HDR10PLUS_RES = "video_bikes_hdr10plus.webm"; 64 protected static final String VP9_HDR10PLUS_STATIC_INFO = 65 "00 4c 1d b8 0b d0 84 80 3e c0 33 c4 86 12 3d 42" + 66 "40 e8 03 32 00 e8 03 c8 00 " ; 67 // TODO: Use some manually extracted metadata for now. 68 // MediaExtractor currently doesn't have an API for extracting 69 // the dynamic metadata. Get the metadata from extractor when 70 // it's supported. 71 protected static final String[] VP9_HDR10PLUS_DYNAMIC_INFO = new String[]{ 72 "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + 73 "0a 00 00 24 08 00 00 28 00 00 50 00 28 c8 00 c9" + 74 "90 02 aa 58 05 ca d0 0c 0a f8 16 83 18 9c 18 00" + 75 "40 78 13 64 d5 7c 2e 2c c3 59 de 79 6e c3 c2 00" , 76 77 "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + 78 "0a 00 00 24 08 00 00 28 00 00 50 00 28 c8 00 c9" + 79 "90 02 aa 58 05 ca d0 0c 0a f8 16 83 18 9c 18 00" + 80 "40 78 13 64 d5 7c 2e 2c c3 59 de 79 6e c3 c2 00" , 81 82 "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + 83 "0e 80 00 24 08 00 00 28 00 00 50 00 28 c8 00 c9" + 84 "90 02 aa 58 05 ca d0 0c 0a f8 16 83 18 9c 18 00" + 85 "40 78 13 64 d5 7c 2e 2c c3 59 de 79 6e c3 c2 00" , 86 87 "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + 88 "0e 80 00 24 08 00 00 28 00 00 50 00 28 c8 00 c9" + 89 "90 02 aa 58 05 ca d0 0c 0a f8 16 83 18 9c 18 00" + 90 "40 78 13 64 d5 7c 2e 2c c3 59 de 79 6e c3 c2 00" , 91 }; 92 93 protected static final String H265_HDR10PLUS_RES = "video_h265_hdr10plus.mp4"; 94 protected static final String H265_HDR10PLUS_STATIC_INFO = 95 "00 4c 1d b8 0b d0 84 80 3e c2 33 c4 86 13 3d 42" + 96 "40 e8 03 32 00 e8 03 c8 00 " ; 97 protected static final String[] H265_HDR10PLUS_DYNAMIC_INFO = new String[]{ 98 "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + 99 "0f 00 00 24 08 00 00 28 00 00 50 00 28 c8 00 a1" + 100 "90 03 9a 58 0b 6a d0 23 2a f8 40 8b 18 9c 18 00" + 101 "40 78 13 64 cf 78 ed cc bf 5a de f9 8e c7 c3 00" , 102 103 "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + 104 "0a 00 00 24 08 00 00 28 00 00 50 00 28 c8 00 a1" + 105 "90 03 9a 58 0b 6a d0 23 2a f8 40 8b 18 9c 18 00" + 106 "40 78 13 64 cf 78 ed cc bf 5a de f9 8e c7 c3 00" , 107 108 "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + 109 "0f 00 00 24 08 00 00 28 00 00 50 00 28 c8 00 a1" + 110 "90 03 9a 58 0b 6a d0 23 2a f8 40 8b 18 9c 18 00" + 111 "40 78 13 64 cf 78 ed cc bf 5a de f9 8e c7 c3 00" , 112 113 "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + 114 "0a 00 00 24 08 00 00 28 00 00 50 00 28 c8 00 a1" + 115 "90 03 9a 58 0b 6a d0 23 2a f8 40 8b 18 9c 18 00" + 116 "40 78 13 64 cf 78 ed cc bf 5a de f9 8e c7 c3 00" 117 }; 118 119 protected static final String AV1_HLG_RES = "cosmat_520x390_24fps_768kbps_av1_10bit.mkv"; 120 protected static final String H265_HLG_RES = "cosmat_520x390_24fps_crf22_hevc_10bit.mkv"; 121 protected static final String VP9_HLG_RES = "cosmat_520x390_24fps_crf22_vp9_10bit.mkv"; 122 123 @Before 124 @Override setUp()125 public void setUp() throws Throwable { 126 super.setUp(); 127 mDisplayManager = mContext.getSystemService(DisplayManager.class); 128 int numberOfSupportedHdrTypes = 129 mDisplayManager.getDisplay(Display.DEFAULT_DISPLAY).getHdrCapabilities() 130 .getSupportedHdrTypes().length; 131 assumeFalse("Device doesn't support HDR display", numberOfSupportedHdrTypes == 0); 132 133 mExtractor = new MediaExtractor(); 134 } 135 136 @After 137 @Override tearDown()138 public void tearDown() { 139 if (mDecoder != null) { 140 mDecoder.release(); 141 } 142 if (mExtractor != null) { 143 mExtractor.release(); 144 } 145 super.tearDown(); 146 } 147 148 // helper to load byte[] from a String loadByteArrayFromString(final String str)149 public byte[] loadByteArrayFromString(final String str) { 150 Pattern pattern = Pattern.compile("[0-9a-fA-F]{2}"); 151 Matcher matcher = pattern.matcher(str); 152 // allocate a large enough byte array first 153 byte[] tempArray = new byte[str.length() / 2]; 154 int i = 0; 155 while (matcher.find()) { 156 tempArray[i++] = (byte) Integer.parseInt(matcher.group(), 16); 157 } 158 return Arrays.copyOfRange(tempArray, 0, i); 159 } 160 } 161