1 /* 2 * Copyright (C) 2020 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 static android.media.MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Flexible; 20 import static android.media.MediaCodecInfo.CodecCapabilities.COLOR_FormatYUVP010; 21 import static android.media.MediaCodecInfo.CodecProfileLevel.*; 22 23 import static org.junit.Assert.assertEquals; 24 import static org.junit.Assert.assertFalse; 25 import static org.junit.Assert.assertNotNull; 26 import static org.junit.Assert.assertTrue; 27 28 import android.media.MediaCodec; 29 import android.media.MediaCodecInfo; 30 import android.media.MediaFormat; 31 import android.mediav2.common.cts.EncoderConfigParams; 32 import android.mediav2.common.cts.EncoderProfileLevelTestBase; 33 import android.mediav2.common.cts.OutputManager; 34 import android.util.Log; 35 36 import com.android.compatibility.common.util.ApiTest; 37 import com.android.compatibility.common.util.CddTest; 38 39 import org.junit.Assume; 40 import org.junit.Test; 41 import org.junit.runner.RunWith; 42 import org.junit.runners.Parameterized; 43 44 import java.io.IOException; 45 import java.util.ArrayList; 46 import java.util.Collection; 47 import java.util.HashMap; 48 import java.util.List; 49 import java.util.Objects; 50 51 /** 52 * EncoderProfileLevelTest validates the profile, level information advertised by the component 53 * in its codec capabilities. The test sets profile and level keys in media format and uses it 54 * during encoder configuration. Upon successful configuration, frames are queued for encoding 55 * (byte buffer mode) and the encoded output (bitstream) is expected to contain the same profile 56 * that was used during configure. The level shall be at least the input configured level. 57 * <p> 58 * NOTE: The test configures level information basing on standard guidelines, not arbitrarily so 59 * encoders are expected to maintain at least the input configured level 60 * <p> 61 * The test parses the bitstream (csd or frame header) and determines profile and level 62 * information. This serves as reference for further validation. The test checks if the output 63 * format returned by component contains same profile and level information as the bitstream. The 64 * output of encoder is muxed and is extracted. The extracted format is expected to contain same 65 * profile and level information as the bitstream. 66 * <p> 67 * As per cdd, if a device contains an encoder capable of encoding a profile/level combination 68 * then it should contain a decoder capable of decoding the same profile/level combination. This 69 * is verified. 70 * <p> 71 * If device implementations support encoding in a media type, then as per cdd they are expected to 72 * handle certain profile and level configurations. This is verified. 73 */ 74 @RunWith(Parameterized.class) 75 public class EncoderProfileLevelTest extends EncoderProfileLevelTestBase { 76 private static final String LOG_TAG = EncoderProfileLevelTest.class.getSimpleName(); 77 private static final HashMap<String, CddRequirements> CDD_REQUIREMENTS_MAP = new HashMap<>(); 78 79 private static class CddRequirements { 80 private int[] mProfiles; 81 private int mLevel; 82 private int mHeight; 83 private int mWidth; 84 CddRequirements(int[] profiles, int level, int width, int height)85 CddRequirements(int[] profiles, int level, int width, int height) { 86 mProfiles = profiles; 87 mLevel = level; 88 mWidth = width; 89 mHeight = height; 90 } 91 CddRequirements(int[] profiles)92 CddRequirements(int[] profiles) { 93 this(profiles, -1 /* level */, -1 /* width */, -1 /* height */); 94 } 95 CddRequirements(int[] profiles, int level)96 CddRequirements(int[] profiles, int level) { 97 this(profiles, level, -1 /* width */, -1 /* height */); 98 } 99 getProfiles()100 public int[] getProfiles() { 101 return mProfiles; 102 } 103 getLevel()104 public int getLevel() { 105 return mLevel; 106 } 107 getWidth()108 public int getWidth() { 109 return mWidth; 110 } 111 getHeight()112 public int getHeight() { 113 return mHeight; 114 } 115 } EncoderProfileLevelTest(String encoder, String mediaType, EncoderConfigParams[] encCfgParams, @SuppressWarnings("unused") String testLabel, String allTestParams)116 public EncoderProfileLevelTest(String encoder, String mediaType, 117 EncoderConfigParams[] encCfgParams, @SuppressWarnings("unused") String testLabel, 118 String allTestParams) { 119 super(encoder, mediaType, encCfgParams, allTestParams); 120 } 121 prepareTestArgs(Object[] arg, int[] profiles, int colorFormat)122 private static List<Object[]> prepareTestArgs(Object[] arg, int[] profiles, int colorFormat) { 123 List<Object[]> argsList = new ArrayList<>(); 124 final int[] maxBFrames = {0, 2}; 125 final String mediaType = (String) arg[0]; 126 boolean isVideo = mediaType.startsWith("video/"); 127 final int br = (int) arg[1]; 128 final int param1 = (int) arg[2]; 129 final int param2 = (int) arg[3]; 130 final int fps = (int) arg[4]; 131 final int level = (int) arg[5]; 132 boolean[] boolStates = {false, true}; 133 if (isVideo) { 134 for (int maxBframe : maxBFrames) { 135 if (maxBframe != 0) { 136 if (!mediaType.equals(MediaFormat.MIMETYPE_VIDEO_AVC) 137 && !mediaType.equals(MediaFormat.MIMETYPE_VIDEO_HEVC)) { 138 continue; 139 } 140 } 141 // test each resolution in both landscape and portrait orientation 142 for (boolean rotate : boolStates) { 143 int width, height; 144 if (rotate) { 145 width = param2; 146 height = param1; 147 } else { 148 width = param1; 149 height = param2; 150 } 151 152 // H.263 doesn't support portait mode, so skip cases where width is smaller 153 // than height. 154 if (mediaType.equals(MediaFormat.MIMETYPE_VIDEO_H263) && width <= height) { 155 continue; 156 } 157 158 Object[] testArgs = new Object[3]; 159 testArgs[0] = arg[0]; 160 testArgs[1] = getVideoEncoderCfgParams(mediaType, br, width, height, fps, 161 colorFormat, maxBframe, profiles, level); 162 testArgs[2] = String.format("%dkbps_%dx%d_%dfps_%s_%d_%d-bframes", br / 1000, 163 width, height, fps, colorFormatToString(colorFormat, -1), 164 level, maxBframe); 165 argsList.add(testArgs); 166 } 167 } 168 } else { 169 Object[] testArgs = new Object[3]; 170 testArgs[0] = arg[0]; 171 testArgs[1] = getAudioEncoderCfgParams(mediaType, br, param1, param2, profiles); 172 testArgs[2] = String.format("%dkbps_%dkHz_%dch", br / 1000, param1 / 1000, param2); 173 argsList.add(testArgs); 174 } 175 return argsList; 176 } 177 getVideoEncoderCfgParams(String mediaType, int bitRate, int width, int height, int frameRate, int colorFormat, int maxBframe, int[] profiles, int level)178 private static EncoderConfigParams[] getVideoEncoderCfgParams(String mediaType, int bitRate, 179 int width, int height, int frameRate, int colorFormat, int maxBframe, int[] profiles, 180 int level) { 181 ArrayList<EncoderConfigParams> cfgParams = new ArrayList<>(); 182 for (int profile : profiles) { 183 if (maxBframe != 0) { 184 if (mediaType.equals(MediaFormat.MIMETYPE_VIDEO_AVC) && ( 185 profile == AVCProfileBaseline 186 || profile == AVCProfileConstrainedBaseline)) { 187 continue; 188 } 189 } 190 cfgParams.add(new EncoderConfigParams.Builder(mediaType) 191 .setBitRate(bitRate) 192 .setWidth(width) 193 .setHeight(height) 194 .setFrameRate(frameRate) 195 .setMaxBFrames(maxBframe) 196 .setProfile(profile) 197 .setLevel(level) 198 .setColorFormat(colorFormat) 199 .build()); 200 } 201 return cfgParams.toArray(new EncoderConfigParams[0]); 202 } 203 getAudioEncoderCfgParams(String mediaType, int bitRate, int sampleRate, int channelCount, int[] profiles)204 private static EncoderConfigParams[] getAudioEncoderCfgParams(String mediaType, int bitRate, 205 int sampleRate, int channelCount, int[] profiles) { 206 EncoderConfigParams[] cfgParams = new EncoderConfigParams[profiles.length]; 207 for (int i = 0; i < profiles.length; i++) { 208 cfgParams[i] = new EncoderConfigParams.Builder(mediaType) 209 .setBitRate(bitRate) 210 .setSampleRate(sampleRate) 211 .setChannelCount(channelCount) 212 .setProfile(profiles[i]) 213 .build(); 214 } 215 return cfgParams; 216 } 217 218 @Parameterized.Parameters(name = "{index}_{0}_{1}_{3}") input()219 public static Collection<Object[]> input() { 220 final boolean isEncoder = true; 221 final boolean needAudio = true; 222 final boolean needVideo = true; 223 final Object[][] exhaustiveArgsList = new Object[][]{ 224 // Audio - CodecMediaType, bit-rate, sample rate, channel count, level 225 {MediaFormat.MIMETYPE_AUDIO_AAC, 64000, 48000, 1, -1, -1}, 226 {MediaFormat.MIMETYPE_AUDIO_AAC, 128000, 48000, 2, -1, -1}, 227 // Video - CodecMediaType, bit-rate, width, height, frame-rate, level 228 229 // ITU-T H.264 230 // Table A-6 – Maximum frame rates (frames per second) for some example frame sizes 231 {MediaFormat.MIMETYPE_VIDEO_AVC, 64000, 176, 144, 15, AVCLevel1}, 232 {MediaFormat.MIMETYPE_VIDEO_AVC, 128000, 176, 144, 15, AVCLevel1b}, 233 {MediaFormat.MIMETYPE_VIDEO_AVC, 192000, 352, 288, 7, AVCLevel11}, 234 {MediaFormat.MIMETYPE_VIDEO_AVC, 384000, 352, 288, 15, AVCLevel12}, 235 {MediaFormat.MIMETYPE_VIDEO_AVC, 512000, 352, 288, 30, AVCLevel13}, 236 {MediaFormat.MIMETYPE_VIDEO_AVC, 832000, 352, 288, 30, AVCLevel2}, 237 {MediaFormat.MIMETYPE_VIDEO_AVC, 1000000, 352, 576, 25, AVCLevel21}, 238 {MediaFormat.MIMETYPE_VIDEO_AVC, 1500000, 720, 576, 12, AVCLevel22}, 239 {MediaFormat.MIMETYPE_VIDEO_AVC, 2000000, 720, 576, 25, AVCLevel3}, 240 {MediaFormat.MIMETYPE_VIDEO_AVC, 3000000, 1280, 720, 30, AVCLevel31}, 241 {MediaFormat.MIMETYPE_VIDEO_AVC, 6000000, 1280, 1024, 42, AVCLevel32}, 242 {MediaFormat.MIMETYPE_VIDEO_AVC, 10000000, 2048, 1024, 30, AVCLevel4}, 243 {MediaFormat.MIMETYPE_VIDEO_AVC, 25000000, 2048, 1024, 30, AVCLevel41}, 244 {MediaFormat.MIMETYPE_VIDEO_AVC, 50000000, 2048, 1088, 60, AVCLevel42}, 245 {MediaFormat.MIMETYPE_VIDEO_AVC, 60000000, 3680, 1526, 26, AVCLevel5}, 246 {MediaFormat.MIMETYPE_VIDEO_AVC, 80000000, 4096, 2304, 26, AVCLevel51}, 247 {MediaFormat.MIMETYPE_VIDEO_AVC, 120000000, 4096, 2304, 56, AVCLevel52}, 248 {MediaFormat.MIMETYPE_VIDEO_AVC, 240000000, 8192, 4320, 30, AVCLevel6}, 249 {MediaFormat.MIMETYPE_VIDEO_AVC, 480000000, 8192, 4320, 60, AVCLevel61}, 250 {MediaFormat.MIMETYPE_VIDEO_AVC, 800000000, 8192, 4320, 120, AVCLevel62}, 251 252 // The entries below have width being twice that of the widths and height being 253 // half of the heights in Table A-6 254 // Since AVC specification has level limits in terms MacroBlocks and not in terms 255 // of pixels, the height is floored to multiple of 16 to fit within the level being 256 // tested 257 {MediaFormat.MIMETYPE_VIDEO_AVC, 64000, 352, 64, 15, AVCLevel1}, 258 {MediaFormat.MIMETYPE_VIDEO_AVC, 128000, 352, 64, 15, AVCLevel1b}, 259 {MediaFormat.MIMETYPE_VIDEO_AVC, 192000, 704, 144, 7, AVCLevel11}, 260 {MediaFormat.MIMETYPE_VIDEO_AVC, 384000, 704, 144, 15, AVCLevel12}, 261 {MediaFormat.MIMETYPE_VIDEO_AVC, 512000, 704, 144, 30, AVCLevel13}, 262 {MediaFormat.MIMETYPE_VIDEO_AVC, 832000, 704, 144, 30, AVCLevel2}, 263 {MediaFormat.MIMETYPE_VIDEO_AVC, 1000000, 704, 288, 25, AVCLevel21}, 264 {MediaFormat.MIMETYPE_VIDEO_AVC, 1500000, 1440, 288, 12, AVCLevel22}, 265 {MediaFormat.MIMETYPE_VIDEO_AVC, 2000000, 1440, 288, 25, AVCLevel3}, 266 {MediaFormat.MIMETYPE_VIDEO_AVC, 3000000, 2560, 352, 30, AVCLevel31}, 267 {MediaFormat.MIMETYPE_VIDEO_AVC, 6000000, 2560, 512, 42, AVCLevel32}, 268 {MediaFormat.MIMETYPE_VIDEO_AVC, 10000000, 4096, 512, 30, AVCLevel4}, 269 {MediaFormat.MIMETYPE_VIDEO_AVC, 25000000, 4096, 512, 30, AVCLevel41}, 270 {MediaFormat.MIMETYPE_VIDEO_AVC, 50000000, 4096, 544, 60, AVCLevel42}, 271 {MediaFormat.MIMETYPE_VIDEO_AVC, 60000000, 7360, 752, 26, AVCLevel5}, 272 {MediaFormat.MIMETYPE_VIDEO_AVC, 80000000, 8192, 1152, 26, AVCLevel51}, 273 {MediaFormat.MIMETYPE_VIDEO_AVC, 120000000, 8192, 1152, 56, AVCLevel52}, 274 {MediaFormat.MIMETYPE_VIDEO_AVC, 240000000, 16384, 2160, 30, AVCLevel6}, 275 {MediaFormat.MIMETYPE_VIDEO_AVC, 480000000, 16384, 2160, 60, AVCLevel61}, 276 {MediaFormat.MIMETYPE_VIDEO_AVC, 800000000, 16384, 2160, 120, AVCLevel62}, 277 278 // Resolutions listed in CDD Section 5.2 279 {MediaFormat.MIMETYPE_VIDEO_AVC, 384000, 320, 240, 20, AVCLevel12}, 280 {MediaFormat.MIMETYPE_VIDEO_AVC, 2000000, 720, 480, 30, AVCLevel3}, 281 {MediaFormat.MIMETYPE_VIDEO_AVC, 4000000, 1280, 720, 30, AVCLevel31}, 282 {MediaFormat.MIMETYPE_VIDEO_AVC, 10000000, 1920, 1088, 30, AVCLevel4}, 283 284 // Clips at Maximum frame rates and bitrates 285 {MediaFormat.MIMETYPE_VIDEO_AVC, 64000, 128, 96, 30, AVCLevel1}, 286 {MediaFormat.MIMETYPE_VIDEO_AVC, 128000, 128, 96, 30, AVCLevel1b}, 287 {MediaFormat.MIMETYPE_VIDEO_AVC, 192000, 128, 96, 62, AVCLevel11}, 288 {MediaFormat.MIMETYPE_VIDEO_AVC, 384000, 128, 96, 125, AVCLevel12}, 289 {MediaFormat.MIMETYPE_VIDEO_AVC, 768000, 128, 96, 172, AVCLevel13}, 290 {MediaFormat.MIMETYPE_VIDEO_AVC, 2000000, 128, 96, 172, AVCLevel2}, 291 // Following entry covers level 2.1 and 2.2 292 {MediaFormat.MIMETYPE_VIDEO_AVC, 4000000, 176, 144, 172, AVCLevel21}, 293 {MediaFormat.MIMETYPE_VIDEO_AVC, 10000000, 176, 144, 172, AVCLevel3}, 294 {MediaFormat.MIMETYPE_VIDEO_AVC, 14000000, 352, 288, 172, AVCLevel31}, 295 {MediaFormat.MIMETYPE_VIDEO_AVC, 20000000, 640, 480, 172, AVCLevel32}, 296 {MediaFormat.MIMETYPE_VIDEO_AVC, 20000000, 720, 480, 172, AVCLevel4}, 297 {MediaFormat.MIMETYPE_VIDEO_AVC, 50000000, 720, 480, 172, AVCLevel41}, 298 {MediaFormat.MIMETYPE_VIDEO_AVC, 50000000, 800, 600, 172, AVCLevel42}, 299 {MediaFormat.MIMETYPE_VIDEO_AVC, 135000000, 1024, 768, 172, AVCLevel5}, 300 {MediaFormat.MIMETYPE_VIDEO_AVC, 240000000, 1408, 960, 172, AVCLevel51}, 301 {MediaFormat.MIMETYPE_VIDEO_AVC, 240000000, 2048, 1088, 172, AVCLevel52}, 302 {MediaFormat.MIMETYPE_VIDEO_AVC, 240000000, 2048, 1526, 300, AVCLevel6}, 303 {MediaFormat.MIMETYPE_VIDEO_AVC, 480000000, 3680, 1536, 300, AVCLevel61}, 304 {MediaFormat.MIMETYPE_VIDEO_AVC, 800000000, 4096, 2304, 300, AVCLevel62}, 305 306 {MediaFormat.MIMETYPE_VIDEO_MPEG2, 4000000, 352, 288, 30, MPEG2LevelLL}, 307 {MediaFormat.MIMETYPE_VIDEO_MPEG2, 15000000, 720, 480, 30, MPEG2LevelML}, 308 {MediaFormat.MIMETYPE_VIDEO_MPEG2, 60000000, 1440, 1088, 30, MPEG2LevelH14}, 309 {MediaFormat.MIMETYPE_VIDEO_MPEG2, 80000000, 1920, 1088, 30, MPEG2LevelHL}, 310 {MediaFormat.MIMETYPE_VIDEO_MPEG2, 80000000, 1920, 1088, 60, MPEG2LevelHP}, 311 312 // Resolutions listed in https://www.webmproject.org/vp9/levels/ 313 {MediaFormat.MIMETYPE_VIDEO_VP9, 200000, 256, 144, 15, VP9Level1}, 314 {MediaFormat.MIMETYPE_VIDEO_VP9, 512000, 384, 192, 30, VP9Level11}, 315 {MediaFormat.MIMETYPE_VIDEO_VP9, 1000000, 480, 256, 30, VP9Level2}, 316 {MediaFormat.MIMETYPE_VIDEO_VP9, 1500000, 640, 384, 30, VP9Level21}, 317 {MediaFormat.MIMETYPE_VIDEO_VP9, 1600000, 1080, 512, 30, VP9Level3}, 318 {MediaFormat.MIMETYPE_VIDEO_VP9, 4000000, 1280, 768, 30, VP9Level31}, 319 {MediaFormat.MIMETYPE_VIDEO_VP9, 5000000, 2048, 1088, 30, VP9Level4}, 320 {MediaFormat.MIMETYPE_VIDEO_VP9, 16000000, 2048, 1088, 60, VP9Level41}, 321 {MediaFormat.MIMETYPE_VIDEO_VP9, 20000000, 4096, 2176, 30, VP9Level5}, 322 {MediaFormat.MIMETYPE_VIDEO_VP9, 80000000, 4096, 2176, 60, VP9Level51}, 323 {MediaFormat.MIMETYPE_VIDEO_VP9, 160000000, 4096, 2176, 120, VP9Level52}, 324 {MediaFormat.MIMETYPE_VIDEO_VP9, 180000000, 8192, 4352, 30, VP9Level6}, 325 {MediaFormat.MIMETYPE_VIDEO_VP9, 240000000, 8192, 4352, 60, VP9Level61}, 326 {MediaFormat.MIMETYPE_VIDEO_VP9, 480000000, 8192, 4352, 120, VP9Level62}, 327 328 // The entries below have width being twice that of the widths and height being 329 // half of the heights in https://www.webmproject.org/vp9/levels/ 330 // Some of the cases where max dimension is limited by specification, width is 331 // clipped. 332 {MediaFormat.MIMETYPE_VIDEO_VP9, 200000, 512, 72, 15, VP9Level1}, 333 {MediaFormat.MIMETYPE_VIDEO_VP9, 512000, 768, 96, 30, VP9Level11}, 334 {MediaFormat.MIMETYPE_VIDEO_VP9, 1000000, 960, 128, 30, VP9Level2}, 335 {MediaFormat.MIMETYPE_VIDEO_VP9, 1500000, 1280, 192, 30, VP9Level21}, 336 {MediaFormat.MIMETYPE_VIDEO_VP9, 1600000, 2048, 256, 30, VP9Level3}, 337 {MediaFormat.MIMETYPE_VIDEO_VP9, 4000000, 2560, 384, 30, VP9Level31}, 338 {MediaFormat.MIMETYPE_VIDEO_VP9, 5000000, 4096, 544, 30, VP9Level4}, 339 {MediaFormat.MIMETYPE_VIDEO_VP9, 16000000, 4096, 544, 60, VP9Level41}, 340 {MediaFormat.MIMETYPE_VIDEO_VP9, 20000000, 8192, 1088, 30, VP9Level5}, 341 {MediaFormat.MIMETYPE_VIDEO_VP9, 80000000, 8192, 1088, 60, VP9Level51}, 342 {MediaFormat.MIMETYPE_VIDEO_VP9, 160000000, 8192, 1088, 120, VP9Level52}, 343 {MediaFormat.MIMETYPE_VIDEO_VP9, 180000000, 16384, 2176, 30, VP9Level6}, 344 {MediaFormat.MIMETYPE_VIDEO_VP9, 240000000, 16384, 2176, 60, VP9Level61}, 345 {MediaFormat.MIMETYPE_VIDEO_VP9, 480000000, 16384, 2176, 120, VP9Level62}, 346 347 // Resolutions listed in CDD Section 5.2 348 {MediaFormat.MIMETYPE_VIDEO_VP9, 1600000, 720, 480, 30, VP9Level3}, 349 {MediaFormat.MIMETYPE_VIDEO_VP9, 4000000, 1280, 720, 30, VP9Level31}, 350 {MediaFormat.MIMETYPE_VIDEO_VP9, 5000000, 1920, 1080, 30, VP9Level4}, 351 {MediaFormat.MIMETYPE_VIDEO_VP9, 20000000, 3840, 2160, 30, VP9Level5}, 352 353 // ITU-T H.263 354 // Table X.2/H.263 − Levels of operation 355 // This also includes 176x144 which is the CDD 356 {MediaFormat.MIMETYPE_VIDEO_H263, 64000, 176, 144, 15, H263Level10}, 357 {MediaFormat.MIMETYPE_VIDEO_H263, 128000, 176, 144, 15, H263Level45}, 358 {MediaFormat.MIMETYPE_VIDEO_H263, 128000, 352, 288, 15, H263Level20}, 359 {MediaFormat.MIMETYPE_VIDEO_H263, 384000, 352, 288, 30, H263Level30}, 360 {MediaFormat.MIMETYPE_VIDEO_H263, 2048000, 352, 288, 30, H263Level40}, 361 {MediaFormat.MIMETYPE_VIDEO_H263, 4096000, 352, 240, 60, H263Level50}, 362 {MediaFormat.MIMETYPE_VIDEO_H263, 8192000, 720, 240, 60, H263Level60}, 363 {MediaFormat.MIMETYPE_VIDEO_H263, 16384000, 720, 576, 50, H263Level70}, 364 365 // From ITU-T H.265 366 // Table A.11 – Maximum picture rates (pictures per second) at level 1 to 4.1 for 367 // some example picture sizes when MinCbSizeY is equal to 64 368 {MediaFormat.MIMETYPE_VIDEO_HEVC, 128000, 176, 144, 15, HEVCMainTierLevel1}, 369 {MediaFormat.MIMETYPE_VIDEO_HEVC, 512000, 352, 288, 30, HEVCMainTierLevel2}, 370 {MediaFormat.MIMETYPE_VIDEO_HEVC, 1000000, 640, 360, 30, HEVCMainTierLevel21}, 371 {MediaFormat.MIMETYPE_VIDEO_HEVC, 1600000, 960, 540, 30, HEVCMainTierLevel3}, 372 {MediaFormat.MIMETYPE_VIDEO_HEVC, 4000000, 1280, 720, 33, HEVCMainTierLevel31}, 373 {MediaFormat.MIMETYPE_VIDEO_HEVC, 6000000, 2048, 1080, 30, HEVCMainTierLevel4}, 374 {MediaFormat.MIMETYPE_VIDEO_HEVC, 16000000, 2048, 1080, 30, HEVCHighTierLevel4}, 375 {MediaFormat.MIMETYPE_VIDEO_HEVC, 20000000, 2048, 1080, 60, HEVCMainTierLevel41}, 376 {MediaFormat.MIMETYPE_VIDEO_HEVC, 30000000, 2048, 1080, 60, HEVCHighTierLevel41}, 377 378 // From ITU-T H.265 379 // Table A.12 – Maximum picture rates (pictures per second) at level 5 to 6.2 for 380 // some example picture sizes when MinCbSizeY is equal to 64 381 {MediaFormat.MIMETYPE_VIDEO_HEVC, 20000000, 4096, 2160, 30, HEVCMainTierLevel5}, 382 {MediaFormat.MIMETYPE_VIDEO_HEVC, 50000000, 4096, 2160, 30, HEVCHighTierLevel5}, 383 {MediaFormat.MIMETYPE_VIDEO_HEVC, 40000000, 4096, 2160, 60, HEVCMainTierLevel51}, 384 {MediaFormat.MIMETYPE_VIDEO_HEVC, 80000000, 4096, 2160, 60, HEVCHighTierLevel51}, 385 {MediaFormat.MIMETYPE_VIDEO_HEVC, 50000000, 4096, 2160, 120, HEVCMainTierLevel52}, 386 {MediaFormat.MIMETYPE_VIDEO_HEVC, 100000000, 4096, 2160, 120, HEVCHighTierLevel52}, 387 {MediaFormat.MIMETYPE_VIDEO_HEVC, 50000000, 8192, 4320, 30, HEVCMainTierLevel6}, 388 {MediaFormat.MIMETYPE_VIDEO_HEVC, 80000000, 8192, 4320, 30, HEVCHighTierLevel6}, 389 {MediaFormat.MIMETYPE_VIDEO_HEVC, 100000000, 8192, 4320, 60, HEVCMainTierLevel61}, 390 {MediaFormat.MIMETYPE_VIDEO_HEVC, 240000000, 8192, 4320, 60, HEVCHighTierLevel61}, 391 {MediaFormat.MIMETYPE_VIDEO_HEVC, 200000000, 8192, 4320, 120, HEVCMainTierLevel62}, 392 {MediaFormat.MIMETYPE_VIDEO_HEVC, 360000000, 8192, 4320, 120, HEVCHighTierLevel62}, 393 394 // The entries below have width being twice that of the widths and height being 395 // half of the heights in Table A.11 and A.12 396 {MediaFormat.MIMETYPE_VIDEO_HEVC, 128000, 352, 72, 15, HEVCMainTierLevel1}, 397 {MediaFormat.MIMETYPE_VIDEO_HEVC, 512000, 704, 144, 30, HEVCMainTierLevel2}, 398 {MediaFormat.MIMETYPE_VIDEO_HEVC, 1000000, 1280, 180, 30, HEVCMainTierLevel21}, 399 {MediaFormat.MIMETYPE_VIDEO_HEVC, 1600000, 1920, 270, 30, HEVCMainTierLevel3}, 400 {MediaFormat.MIMETYPE_VIDEO_HEVC, 4000000, 2560, 360, 33, HEVCMainTierLevel31}, 401 {MediaFormat.MIMETYPE_VIDEO_HEVC, 6000000, 4096, 540, 30, HEVCMainTierLevel4}, 402 {MediaFormat.MIMETYPE_VIDEO_HEVC, 16000000, 4096, 540, 30, HEVCHighTierLevel4}, 403 {MediaFormat.MIMETYPE_VIDEO_HEVC, 20000000, 4096, 540, 60, HEVCMainTierLevel41}, 404 {MediaFormat.MIMETYPE_VIDEO_HEVC, 30000000, 4096, 540, 60, HEVCHighTierLevel41}, 405 {MediaFormat.MIMETYPE_VIDEO_HEVC, 20000000, 8192, 1080, 30, HEVCMainTierLevel5}, 406 {MediaFormat.MIMETYPE_VIDEO_HEVC, 50000000, 8192, 1080, 30, HEVCHighTierLevel5}, 407 {MediaFormat.MIMETYPE_VIDEO_HEVC, 40000000, 8192, 1080, 60, HEVCMainTierLevel51}, 408 {MediaFormat.MIMETYPE_VIDEO_HEVC, 80000000, 8192, 1080, 60, HEVCHighTierLevel51}, 409 {MediaFormat.MIMETYPE_VIDEO_HEVC, 50000000, 8192, 1080, 120, HEVCMainTierLevel52}, 410 {MediaFormat.MIMETYPE_VIDEO_HEVC, 100000000, 8192, 1080, 120, HEVCHighTierLevel52}, 411 {MediaFormat.MIMETYPE_VIDEO_HEVC, 50000000, 16384, 2160, 30, HEVCMainTierLevel6}, 412 {MediaFormat.MIMETYPE_VIDEO_HEVC, 80000000, 16384, 2160, 30, HEVCHighTierLevel6}, 413 {MediaFormat.MIMETYPE_VIDEO_HEVC, 100000000, 16384, 2160, 60, HEVCMainTierLevel61}, 414 {MediaFormat.MIMETYPE_VIDEO_HEVC, 240000000, 16384, 2160, 60, HEVCHighTierLevel61}, 415 {MediaFormat.MIMETYPE_VIDEO_HEVC, 200000000, 16384, 2160, 120, HEVCMainTierLevel62}, 416 {MediaFormat.MIMETYPE_VIDEO_HEVC, 360000000, 16384, 2160, 120, HEVCHighTierLevel62}, 417 418 // Resolutions listed in CDD Section 5.2 419 {MediaFormat.MIMETYPE_VIDEO_HEVC, 1000000, 512, 512, 30, HEVCMainTierLevel3}, 420 {MediaFormat.MIMETYPE_VIDEO_HEVC, 1600000, 720, 480, 30, HEVCMainTierLevel3}, 421 {MediaFormat.MIMETYPE_VIDEO_HEVC, 4000000, 1280, 720, 30, HEVCMainTierLevel31}, 422 {MediaFormat.MIMETYPE_VIDEO_HEVC, 5000000, 1920, 1080, 30, HEVCMainTierLevel4}, 423 {MediaFormat.MIMETYPE_VIDEO_HEVC, 20000000, 3840, 2160, 30, HEVCMainTierLevel5}, 424 425 // Clips at Maximum frame rates and bitrates 426 {MediaFormat.MIMETYPE_VIDEO_HEVC, 128000, 128, 96, 33, HEVCMainTierLevel1}, 427 {MediaFormat.MIMETYPE_VIDEO_HEVC, 1500000, 128, 96, 225, HEVCMainTierLevel2}, 428 {MediaFormat.MIMETYPE_VIDEO_HEVC, 3000000, 128, 96, 300, HEVCMainTierLevel21}, 429 {MediaFormat.MIMETYPE_VIDEO_HEVC, 6000000, 176, 144, 300, HEVCMainTierLevel3}, 430 {MediaFormat.MIMETYPE_VIDEO_HEVC, 10000000, 352, 240, 300, HEVCMainTierLevel31}, 431 {MediaFormat.MIMETYPE_VIDEO_HEVC, 12000000, 352, 576, 300, HEVCMainTierLevel4}, 432 {MediaFormat.MIMETYPE_VIDEO_HEVC, 30000000, 352, 576, 300, HEVCHighTierLevel4}, 433 {MediaFormat.MIMETYPE_VIDEO_HEVC, 20000000, 720, 576, 300, HEVCMainTierLevel41}, 434 {MediaFormat.MIMETYPE_VIDEO_HEVC, 50000000, 720, 576, 300, HEVCHighTierLevel41}, 435 {MediaFormat.MIMETYPE_VIDEO_HEVC, 25000000, 1024, 768, 300, HEVCMainTierLevel5}, 436 {MediaFormat.MIMETYPE_VIDEO_HEVC, 100000000, 1024, 768, 300, HEVCHighTierLevel5}, 437 {MediaFormat.MIMETYPE_VIDEO_HEVC, 40000000, 1408, 1152, 300, HEVCMainTierLevel51}, 438 {MediaFormat.MIMETYPE_VIDEO_HEVC, 160000000, 1408, 1152, 300, HEVCHighTierLevel51}, 439 // Following two entries cover Level 5.2 and Level 6.0 440 {MediaFormat.MIMETYPE_VIDEO_HEVC, 60000000, 2048, 1526, 300, HEVCMainTierLevel52}, 441 {MediaFormat.MIMETYPE_VIDEO_HEVC, 240000000, 2048, 1526, 300, HEVCHighTierLevel52}, 442 {MediaFormat.MIMETYPE_VIDEO_HEVC, 120000000, 3672, 1536, 300, HEVCMainTierLevel61}, 443 {MediaFormat.MIMETYPE_VIDEO_HEVC, 480000000, 3672, 1536, 300, HEVCHighTierLevel61}, 444 {MediaFormat.MIMETYPE_VIDEO_HEVC, 240000000, 4096, 3072, 300, HEVCMainTierLevel62}, 445 {MediaFormat.MIMETYPE_VIDEO_HEVC, 800000000, 4096, 3072, 300, HEVCHighTierLevel62}, 446 447 // Resolutions listed in https://aomedia.org/av1/specification/annex-a/#levels 448 {MediaFormat.MIMETYPE_VIDEO_AV1, 1500000, 426, 240, 30, AV1Level2}, 449 {MediaFormat.MIMETYPE_VIDEO_AV1, 3000000, 640, 360, 30, AV1Level21}, 450 {MediaFormat.MIMETYPE_VIDEO_AV1, 6000000, 854, 480, 30, AV1Level3}, 451 {MediaFormat.MIMETYPE_VIDEO_AV1, 10000000, 1280, 720, 30, AV1Level31}, 452 {MediaFormat.MIMETYPE_VIDEO_AV1, 12000000, 1920, 1080, 30, AV1Level4}, 453 {MediaFormat.MIMETYPE_VIDEO_AV1, 20000000, 1920, 1080, 60, AV1Level41}, 454 {MediaFormat.MIMETYPE_VIDEO_AV1, 30000000, 3840, 2160, 30, AV1Level5}, 455 {MediaFormat.MIMETYPE_VIDEO_AV1, 40000000, 3840, 2160, 60, AV1Level51}, 456 {MediaFormat.MIMETYPE_VIDEO_AV1, 60000000, 3840, 2160, 120, AV1Level52}, 457 {MediaFormat.MIMETYPE_VIDEO_AV1, 60000000, 7680, 4320, 30, AV1Level6}, 458 {MediaFormat.MIMETYPE_VIDEO_AV1, 100000000, 7680, 4320, 60, AV1Level61}, 459 {MediaFormat.MIMETYPE_VIDEO_AV1, 160000000, 7680, 4320, 120, AV1Level62}, 460 461 // The entries below have width being twice that of the widths and height being 462 // half of the heights in https://aomedia.org/av1/specification/annex-a/#levels 463 {MediaFormat.MIMETYPE_VIDEO_AV1, 1500000, 852, 120, 30, AV1Level2}, 464 {MediaFormat.MIMETYPE_VIDEO_AV1, 3000000, 1280, 180, 30, AV1Level21}, 465 {MediaFormat.MIMETYPE_VIDEO_AV1, 6000000, 1708, 240, 30, AV1Level3}, 466 {MediaFormat.MIMETYPE_VIDEO_AV1, 10000000, 2560, 360, 30, AV1Level31}, 467 {MediaFormat.MIMETYPE_VIDEO_AV1, 12000000, 3840, 540, 30, AV1Level4}, 468 {MediaFormat.MIMETYPE_VIDEO_AV1, 20000000, 3840, 540, 60, AV1Level41}, 469 {MediaFormat.MIMETYPE_VIDEO_AV1, 30000000, 7680, 1080, 30, AV1Level5}, 470 {MediaFormat.MIMETYPE_VIDEO_AV1, 40000000, 7680, 1080, 60, AV1Level51}, 471 {MediaFormat.MIMETYPE_VIDEO_AV1, 60000000, 7680, 1080, 120, AV1Level52}, 472 {MediaFormat.MIMETYPE_VIDEO_AV1, 60000000, 15360, 2160, 30, AV1Level6}, 473 {MediaFormat.MIMETYPE_VIDEO_AV1, 100000000, 15360, 2160, 60, AV1Level61}, 474 {MediaFormat.MIMETYPE_VIDEO_AV1, 160000000, 15360, 2160, 120, AV1Level62}, 475 476 // Resolutions listed in CDD Section 5.2 477 {MediaFormat.MIMETYPE_VIDEO_AV1, 5000000, 720, 480, 30, AV1Level3}, 478 {MediaFormat.MIMETYPE_VIDEO_AV1, 8000000, 1280, 720, 30, AV1Level31}, 479 {MediaFormat.MIMETYPE_VIDEO_AV1, 16000000, 1920, 1080, 30, AV1Level4}, 480 {MediaFormat.MIMETYPE_VIDEO_AV1, 50000000, 3840, 2160, 30, AV1Level5}, 481 }; 482 final List<Object[]> argsList = new ArrayList<>(); 483 for (Object[] arg : exhaustiveArgsList) { 484 final String mediaType = (String) arg[0]; 485 argsList.addAll(prepareTestArgs(arg, 486 Objects.requireNonNull(PROFILE_SDR_MAP.get(mediaType)), 487 COLOR_FormatYUV420Flexible)); 488 // P010 support was added in Android T, hence limit the following tests to Android 489 // T and above 490 if (IS_AT_LEAST_T && PROFILE_HLG_MAP.get(mediaType) != null) { 491 argsList.addAll(prepareTestArgs(arg, 492 Objects.requireNonNull(PROFILE_HLG_MAP.get(mediaType)), 493 COLOR_FormatYUVP010)); 494 } 495 } 496 final Object[][] mpeg4SimpleProfileArgsList = new Object[][]{ 497 {MediaFormat.MIMETYPE_VIDEO_MPEG4, 64000, 176, 144, 15, MPEG4Level0}, 498 {MediaFormat.MIMETYPE_VIDEO_MPEG4, 128000, 176, 144, 15, MPEG4Level0b}, 499 {MediaFormat.MIMETYPE_VIDEO_MPEG4, 64000, 128, 96, 30, MPEG4Level1}, 500 {MediaFormat.MIMETYPE_VIDEO_MPEG4, 128000, 352, 288, 15, MPEG4Level2}, 501 {MediaFormat.MIMETYPE_VIDEO_MPEG4, 384000, 352, 288, 30, MPEG4Level3}, 502 {MediaFormat.MIMETYPE_VIDEO_MPEG4, 4000000, 640, 480, 30, MPEG4Level4a}, 503 {MediaFormat.MIMETYPE_VIDEO_MPEG4, 8000000, 720, 576, 24, MPEG4Level5}, 504 {MediaFormat.MIMETYPE_VIDEO_MPEG4, 12000000, 1280, 720, 30, MPEG4Level6}, 505 }; 506 for (Object[] arg : mpeg4SimpleProfileArgsList) { 507 argsList.addAll(prepareTestArgs(arg, new int[]{MPEG4ProfileSimple}, 508 COLOR_FormatYUV420Flexible)); 509 } 510 final Object[][] mpeg4AdvSimpleProfileArgsList = new Object[][]{ 511 {MediaFormat.MIMETYPE_VIDEO_MPEG4, 128000, 176, 144, 30, MPEG4Level1}, 512 {MediaFormat.MIMETYPE_VIDEO_MPEG4, 384000, 352, 288, 15, MPEG4Level2}, 513 {MediaFormat.MIMETYPE_VIDEO_MPEG4, 768000, 352, 288, 30, MPEG4Level3}, 514 {MediaFormat.MIMETYPE_VIDEO_MPEG4, 1500000, 352, 288, 30, MPEG4Level3b}, 515 {MediaFormat.MIMETYPE_VIDEO_MPEG4, 3000000, 704, 576, 15, MPEG4Level4}, 516 {MediaFormat.MIMETYPE_VIDEO_MPEG4, 8000000, 720, 576, 30, MPEG4Level5}, 517 }; 518 for (Object[] arg : mpeg4AdvSimpleProfileArgsList) { 519 argsList.addAll(prepareTestArgs(arg, new int[]{MPEG4ProfileAdvancedSimple}, 520 COLOR_FormatYUV420Flexible)); 521 } 522 return prepareParamList(argsList, isEncoder, needAudio, needVideo, false); 523 } 524 525 static { 526 // Following lists profiles, level, maxWidth and maxHeight mandated by the CDD. 527 // CodecMediaType, profiles, level, maxWidth, maxHeight CDD_REQUIREMENTS_MAP.put(MediaFormat.MIMETYPE_AUDIO_AAC, new CddRequirements(new int[]{AACObjectLC, AACObjectHE, AACObjectELD}))528 CDD_REQUIREMENTS_MAP.put(MediaFormat.MIMETYPE_AUDIO_AAC, 529 new CddRequirements(new int[]{AACObjectLC, AACObjectHE, AACObjectELD})); CDD_REQUIREMENTS_MAP.put(MediaFormat.MIMETYPE_VIDEO_H263, new CddRequirements(new int[]{H263ProfileBaseline}, H263Level45))530 CDD_REQUIREMENTS_MAP.put(MediaFormat.MIMETYPE_VIDEO_H263, 531 new CddRequirements(new int[]{H263ProfileBaseline}, H263Level45)); CDD_REQUIREMENTS_MAP.put(MediaFormat.MIMETYPE_VIDEO_AVC, new CddRequirements(new int[]{AVCProfileBaseline}, AVCLevel3))532 CDD_REQUIREMENTS_MAP.put(MediaFormat.MIMETYPE_VIDEO_AVC, 533 new CddRequirements(new int[]{AVCProfileBaseline}, AVCLevel3)); CDD_REQUIREMENTS_MAP.put(MediaFormat.MIMETYPE_VIDEO_HEVC, new CddRequirements(new int[]{HEVCProfileMain}, HEVCMainTierLevel3, 512, 512))534 CDD_REQUIREMENTS_MAP.put(MediaFormat.MIMETYPE_VIDEO_HEVC, 535 new CddRequirements(new int[]{HEVCProfileMain}, HEVCMainTierLevel3, 512, 512)); CDD_REQUIREMENTS_MAP.put(MediaFormat.MIMETYPE_VIDEO_VP9, new CddRequirements(new int[]{VP9Profile0}, VP9Level3))536 CDD_REQUIREMENTS_MAP.put(MediaFormat.MIMETYPE_VIDEO_VP9, 537 new CddRequirements(new int[]{VP9Profile0}, VP9Level3)); 538 if (IS_AT_LEAST_U) { CDD_REQUIREMENTS_MAP.put(MediaFormat.MIMETYPE_VIDEO_AV1, new CddRequirements(new int[]{AV1ProfileMain8, AV1ProfileMain10}))539 CDD_REQUIREMENTS_MAP.put(MediaFormat.MIMETYPE_VIDEO_AV1, 540 new CddRequirements(new int[]{AV1ProfileMain8, AV1ProfileMain10})); 541 } 542 } 543 checkIfTrackFormatIsOk(MediaFormat trackFormat)544 void checkIfTrackFormatIsOk(MediaFormat trackFormat) { 545 assertEquals("Input media type and extracted media type are not identical " + mTestEnv 546 + mTestConfig, mActiveEncCfg.mMediaType, 547 trackFormat.getString(MediaFormat.KEY_MIME)); 548 if (mIsVideo) { 549 assertEquals("Input width and extracted width are not same " + mTestEnv + mTestConfig, 550 mActiveEncCfg.mWidth, getWidth(trackFormat)); 551 assertEquals("Input height and extracted height are not same " + mTestEnv + mTestConfig, 552 mActiveEncCfg.mHeight, getHeight(trackFormat)); 553 } else { 554 int expSampleRate = mActiveEncCfg.mProfile != AACObjectHE ? mActiveEncCfg.mSampleRate 555 : mActiveEncCfg.mSampleRate / 2; 556 int expChCount = mActiveEncCfg.mProfile != AACObjectHE_PS ? mActiveEncCfg.mChannelCount 557 : mActiveEncCfg.mChannelCount / 2; 558 assertEquals("Input sample rate and extracted sample rate are not same " + mTestEnv 559 + mTestConfig, expSampleRate, 560 trackFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE)); 561 assertEquals("Input channe count and extracted channel count are not same " + mTestEnv 562 + mTestConfig, expChCount, 563 trackFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT)); 564 } 565 } 566 shallSupportProfileAndLevel(EncoderConfigParams cfg)567 private boolean shallSupportProfileAndLevel(EncoderConfigParams cfg) { 568 CddRequirements requirement = 569 Objects.requireNonNull(CDD_REQUIREMENTS_MAP.get(cfg.mMediaType)); 570 int[] profileCdd = requirement.getProfiles(); 571 int levelCdd = requirement.getLevel(); 572 int widthCdd = requirement.getWidth(); 573 int heightCdd = requirement.getHeight(); 574 575 // Check if CDD doesn't require support beyond certain resolutions. 576 if (widthCdd != -1 && mActiveEncCfg.mWidth > widthCdd) { 577 return false; 578 } 579 if (heightCdd != -1 && mActiveEncCfg.mHeight > heightCdd) { 580 return false; 581 } 582 583 for (int cddProfile : profileCdd) { 584 if (cfg.mProfile == cddProfile) { 585 if (!cfg.mIsAudio) { 586 if (cfg.mLevel <= levelCdd) { 587 if (cfg.mMediaType.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_H263) 588 && cfg.mLevel != MediaCodecInfo.CodecProfileLevel.H263Level45 589 && cfg.mLevel > MediaCodecInfo.CodecProfileLevel.H263Level10) { 590 continue; 591 } 592 } else { 593 continue; 594 } 595 } 596 return true; 597 } 598 } 599 return false; 600 } 601 602 /** 603 * Check description of class {@link EncoderProfileLevelTest} 604 */ 605 @CddTest(requirements = {"2.2.2/5.1/H-0-3", "2.2.2/5.1/H-0-4", "2.2.2/5.1/H-0-5", "5/C-0-3", 606 "5.2.1/C-1-1", "5.2.2/C-1-1", "5.2.4/C-1-2", "5.2.5/C-1-1", "5.2.6/C-1-1"}) 607 @ApiTest(apis = {"android.media.MediaFormat#KEY_PROFILE", 608 "android.media.MediaFormat#KEY_AAC_PROFILE", 609 "android.media.MediaFormat#KEY_LEVEL"}) 610 @Test(timeout = PER_TEST_TIMEOUT_LARGE_TEST_MS) testValidateProfileLevel()611 public void testValidateProfileLevel() throws IOException, InterruptedException { 612 int minLevel = getMinLevel(mMediaType, mEncCfgParams[0].mWidth, mEncCfgParams[0].mHeight, 613 mEncCfgParams[0].mFrameRate, mEncCfgParams[0].mBitRate, mEncCfgParams[0].mProfile); 614 boolean validateMinLevel = true; 615 // MPEG4 and AV1 have independent checks on width and height and because of that, 616 // level limits that are passed to landscape resolution in the test table, do not 617 // match the minimum level computed later. For such cases, disable the minLevel check. 618 if ((mMediaType.equals(MediaFormat.MIMETYPE_VIDEO_MPEG4) 619 || mMediaType.equals(MediaFormat.MIMETYPE_VIDEO_AV1)) 620 && (mEncCfgParams[0].mWidth < mEncCfgParams[0].mHeight)) { 621 validateMinLevel = false; 622 } 623 if (validateMinLevel) { 624 assertEquals("Calculated minimum acceptable level does not match the entry in test " 625 + "table " + mTestConfig, mEncCfgParams[0].mLevel, minLevel); 626 } 627 628 if (mIsVideo && mEncCfgParams[0].mInputBitDepth != 8) { 629 Assume.assumeTrue(mCodecName + " doesn't support " + colorFormatToString( 630 mEncCfgParams[0].mColorFormat, mEncCfgParams[0].mInputBitDepth), 631 hasSupportForColorFormat(mCodecName, mMediaType, 632 mEncCfgParams[0].mColorFormat)); 633 } 634 635 boolean cddSupportedMediaType = CDD_REQUIREMENTS_MAP.get(mMediaType) != null; 636 { 637 mActiveRawRes = EncoderInput.getRawResource(mEncCfgParams[0]); 638 assertNotNull("no raw resource found for testing config : " 639 + mEncCfgParams[0] + mTestConfig + mTestEnv, mActiveRawRes); 640 setUpSource(mActiveRawRes.mFileName); 641 mSaveToMem = true; 642 mMuxOutput = true; 643 mOutputBuff = new OutputManager(); 644 mCodec = MediaCodec.createByCodecName(mCodecName); 645 MediaCodecInfo.CodecCapabilities codecCapabilities = 646 mCodec.getCodecInfo().getCapabilitiesForType(mMediaType); 647 int configsTested = 0; 648 for (EncoderConfigParams cfg : mEncCfgParams) { 649 mActiveEncCfg = cfg; 650 MediaFormat format = cfg.getFormat(); 651 if (!codecCapabilities.isFormatSupported(format)) { 652 if (cddSupportedMediaType) { 653 if (shallSupportProfileAndLevel(cfg)) { 654 ArrayList<MediaFormat> formats = new ArrayList<>(); 655 formats.add(format); 656 assertFalse("No components present on the device supports cdd " 657 + "required encode format:- " + format + mTestConfig + mTestEnv, 658 selectCodecs(mMediaType, formats, null, true).isEmpty()); 659 } 660 Log.d(LOG_TAG, mCodecName + " doesn't support format: " + format); 661 } 662 continue; 663 } 664 665 mOutputBuff.reset(); 666 configureCodec(format, false, true, true); 667 mCodec.start(); 668 doWork(5); 669 queueEOS(); 670 waitForAllOutputs(); 671 mCodec.reset(); 672 673 MediaFormat trackFormat = validateProfileAndLevel(); 674 675 deleteMuxedFile(); 676 677 // validate extracted format for mandatory keys 678 if (trackFormat != null) checkIfTrackFormatIsOk(trackFormat); 679 680 // Verify if device has an equivalent decoder for the current format 681 ArrayList<MediaFormat> formatList = new ArrayList<>(); 682 if (mProfileLevel != null && mProfileLevel.second != -1 683 && cfg.mLevel != mProfileLevel.second) { 684 format.setInteger(MediaFormat.KEY_LEVEL, mProfileLevel.second); 685 } 686 formatList.add(format); 687 assertTrue("Device advertises support for encoding " + format + " but cannot" 688 + " decode it. \n" + mTestConfig + mTestEnv, 689 selectCodecs(mMediaType, formatList, null, false).size() > 0); 690 configsTested++; 691 } 692 mCodec.release(); 693 Assume.assumeTrue("skipping test, formats not supported by component", 694 configsTested > 0); 695 } 696 } 697 } 698