1 /* 2 * Copyright (C) 2021 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.video.cts; 18 19 import static org.junit.Assert.assertTrue; 20 21 import android.media.MediaFormat; 22 import android.util.Log; 23 24 import androidx.test.filters.LargeTest; 25 26 import com.android.compatibility.common.util.ApiTest; 27 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 import org.junit.runners.Parameterized; 31 32 import java.io.IOException; 33 import java.util.ArrayList; 34 import java.util.Collection; 35 import java.util.List; 36 37 @RunWith(Parameterized.class) 38 public class CodecDecoderPerformanceTest extends CodecDecoderPerformanceTestBase { 39 private static final String LOG_TAG = CodecDecoderPerformanceTest.class.getSimpleName(); 40 CodecDecoderPerformanceTest(String decoderName, String testFile, int keyPriority, float scalingFactor)41 public CodecDecoderPerformanceTest(String decoderName, String testFile, int keyPriority, 42 float scalingFactor) { 43 super(decoderName, testFile, keyPriority, scalingFactor); 44 } 45 46 @Parameterized.Parameters(name = "{index}_{0}_{2}_{3}") input()47 public static Collection<Object[]> input() throws IOException { 48 final String[] fileList = new String[]{ 49 // Video - Filename 50 // AVC 51 "crowd_run_720x480_30fps_avc.mp4", 52 "crowd_run_1280x720_30fps_avc.mp4", 53 "crowd_run_1920x1080_30fps_avc.mp4", 54 "crowd_run_3840x2160_30fps_avc.mp4", 55 // HEVC 56 "crowd_run_720x480_30fps_hevc.mp4", 57 "crowd_run_1280x720_30fps_hevc.mp4", 58 "crowd_run_1920x1080_30fps_hevc.mp4", 59 "crowd_run_3840x2160_30fps_hevc.mp4", 60 // TODO (b/194721211) Enable 8k tests 61 //"crowd_run_7680x4320_30fps_hevc.mp4", 62 // VP8 63 "crowd_run_720x480_30fps_vp8.webm", 64 "crowd_run_1280x720_30fps_vp8.webm", 65 "crowd_run_1920x1080_30fps_vp8.webm", 66 "crowd_run_3840x2160_30fps_vp8.webm", 67 // VP9 68 "crowd_run_720x480_30fps_vp9.webm", 69 "crowd_run_1280x720_30fps_vp9.webm", 70 "crowd_run_1920x1080_30fps_vp9.webm", 71 "crowd_run_3840x2160_30fps_vp9.webm", 72 // TODO (b/194721211) Enable 8k tests 73 //"crowd_run_7680x4320_30fps_vp9.webm", 74 // AV1 75 "crowd_run_720x480_30fps_av1.mp4", 76 "crowd_run_1280x720_30fps_av1.mp4", 77 "crowd_run_1920x1080_30fps_av1.mp4", 78 "crowd_run_3840x2160_30fps_av1.mp4", 79 // TODO (b/194721211) Enable 8k tests 80 //"crowd_run_7680x4320_30fps_av1.mp4", 81 // MPEG-2 82 "crowd_run_720x480_30fps_mpeg2.mp4", 83 "crowd_run_1280x720_30fps_mpeg2.mp4", 84 "crowd_run_1920x1080_30fps_mpeg2.mp4", 85 "crowd_run_3840x2160_30fps_mpeg2.mp4", 86 // TODO (b/194721211) Enable 8k tests 87 //"crowd_run_7680x4320_30fps_mpeg2.mp4", 88 }; 89 // Prepares the params list combining with supported Hardware decoders, key priority 90 // and scaling factor. 91 final List<Object[]> argsList = new ArrayList<>(); 92 for (String fileName : fileList) { 93 // Gets the format for the first video track found 94 MediaFormat format = getVideoFormat(fileName); 95 if (format == null) { 96 Log.e(LOG_TAG, "Test vector is ignored as it has no video tracks present " + 97 "in the file: " + fileName); 98 continue; 99 } 100 String mime = format.getString(MediaFormat.KEY_MIME); 101 ArrayList<MediaFormat> formatsList = new ArrayList<>(); 102 formatsList.add(format); 103 ArrayList<String> listOfDecoders = selectHardwareCodecs(mime, formatsList, null, 104 false); 105 for (String decoder : listOfDecoders) { 106 for (int keyPriority : KEY_PRIORITIES_LIST) { 107 for (float scalingFactor : SCALING_FACTORS_LIST) { 108 if (keyPriority == 1 || (scalingFactor > 0.0 && scalingFactor <= 1.0)) { 109 argsList.add(new Object[]{decoder, fileName, keyPriority, 110 scalingFactor}); 111 } 112 } 113 } 114 } 115 } 116 return argsList; 117 } 118 119 /** 120 * Validates performance of hardware accelerated video decoders 121 */ 122 @ApiTest(apis = {"android.media.MediaFormat#KEY_PRIORITY", 123 "android.media.MediaFormat#KEY_OPERATING_RATE"}) 124 @LargeTest 125 @Test(timeout = PER_TEST_TIMEOUT_LARGE_TEST_MS) testPerformanceOfHardwareVideoDecoders()126 public void testPerformanceOfHardwareVideoDecoders() throws IOException, InterruptedException { 127 decode(); 128 String log = String.format("DecodeMime: %s, Decoder: %s, resolution: %dp, Key-priority: " + 129 "%d :: ", mDecoderMime, mDecoderName, mHeight, mKeyPriority); 130 int maxExpectedFps = getMaxExpectedFps(mWidth, mHeight); 131 double expectedFps = 132 Math.min(mOperatingRateExpected * FPS_TOLERANCE_FACTOR, maxExpectedFps); 133 Log.d(LOG_TAG, log + "act/exp fps: " + mAchievedFps + "/" + expectedFps); 134 assertTrue("Unable to achieve the expected rate. " + log + "act/exp fps: " + mAchievedFps 135 + "/" + expectedFps, mAchievedFps >= expectedFps); 136 } 137 } 138