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