1 /*
2  * Copyright (C) 2015 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.cts;
18 
19 import android.media.cts.R;
20 
21 import android.content.Context;
22 import android.content.res.AssetFileDescriptor;
23 import android.content.res.Resources;
24 import android.cts.util.MediaPerfUtils;
25 import android.cts.util.MediaUtils;
26 import android.media.MediaCodec;
27 import android.media.MediaCodecInfo.VideoCapabilities;
28 import android.media.MediaExtractor;
29 import android.media.MediaFormat;
30 import android.util.Log;
31 import android.view.Surface;
32 
33 import com.android.compatibility.common.util.DeviceReportLog;
34 import com.android.compatibility.common.util.ResultType;
35 import com.android.compatibility.common.util.ResultUnit;
36 
37 import java.nio.ByteBuffer;
38 import java.util.Arrays;
39 import java.util.LinkedList;
40 
41 public class VideoDecoderPerfTest extends MediaPlayerTestBase {
42     private static final String TAG = "VideoDecoderPerfTest";
43     private static final String REPORT_LOG_NAME = "CtsMediaTestCases";
44     private static final int TOTAL_FRAMES = 30000;
45     private static final int MIN_FRAMES = 3000;
46     private static final int MAX_TIME_MS = 120000;  // 2 minutes
47     private static final int MAX_TEST_TIMEOUT_MS = 300000;  // 5 minutes
48     private static final int MIN_TEST_MS = 10000;  // 10 seconds
49     private static final int NUMBER_OF_REPEATS = 2;
50 
51     private static final String AVC = MediaFormat.MIMETYPE_VIDEO_AVC;
52     private static final String H263 = MediaFormat.MIMETYPE_VIDEO_H263;
53     private static final String HEVC = MediaFormat.MIMETYPE_VIDEO_HEVC;
54     private static final String MPEG2 = MediaFormat.MIMETYPE_VIDEO_MPEG2;
55     private static final String MPEG4 = MediaFormat.MIMETYPE_VIDEO_MPEG4;
56     private static final String VP8 = MediaFormat.MIMETYPE_VIDEO_VP8;
57     private static final String VP9 = MediaFormat.MIMETYPE_VIDEO_VP9;
58 
59     private static final boolean GOOG = true;
60     private static final boolean OTHER = false;
61 
62     private static final int MAX_SIZE_SAMPLES_IN_MEMORY_BYTES = 12 << 20;  // 12MB
63     LinkedList<ByteBuffer> mSamplesInMemory = new LinkedList<ByteBuffer>();
64     private MediaFormat mDecInputFormat;
65     private MediaFormat mDecOutputFormat;
66     private int mBitrate;
67 
68     private Resources mResources;
69 
70     @Override
setUp()71     protected void setUp() throws Exception {
72         super.setUp();
73         mResources = mContext.getResources();
74     }
75 
76     @Override
tearDown()77     protected void tearDown() throws Exception {
78         super.tearDown();
79     }
80 
decode(String name, int resourceId, MediaFormat format)81     private void decode(String name, int resourceId, MediaFormat format) throws Exception {
82         int width = format.getInteger(MediaFormat.KEY_WIDTH);
83         int height = format.getInteger(MediaFormat.KEY_HEIGHT);
84         String mime = format.getString(MediaFormat.KEY_MIME);
85 
86         // Ensure we can finish this test within the test timeout. Allow 25% slack (4/5).
87         long maxTimeMs = Math.min(
88                 MAX_TEST_TIMEOUT_MS * 4 / 5 / NUMBER_OF_REPEATS, MAX_TIME_MS);
89         double measuredFps[] = new double[NUMBER_OF_REPEATS];
90 
91         for (int i = 0; i < NUMBER_OF_REPEATS; ++i) {
92             // Decode to Surface.
93             Log.d(TAG, "round #" + i + ": " + name + " for " + maxTimeMs + " msecs to surface");
94             Surface s = getActivity().getSurfaceHolder().getSurface();
95             // only verify the result for decode to surface case.
96             measuredFps[i] = doDecode(name, resourceId, width, height, s, i, maxTimeMs);
97 
98             // We don't test decoding to buffer.
99             // Log.d(TAG, "round #" + i + " decode to buffer");
100             // doDecode(name, video, width, height, null, i, maxTimeMs);
101         }
102 
103         String error =
104             MediaPerfUtils.verifyAchievableFrameRates(name, mime, width, height, measuredFps);
105         assertNull(error, error);
106         mSamplesInMemory.clear();
107     }
108 
doDecode( String name, int video, int w, int h, Surface surface, int round, long maxTimeMs)109     private double doDecode(
110             String name, int video, int w, int h, Surface surface, int round, long maxTimeMs)
111             throws Exception {
112         AssetFileDescriptor testFd = mResources.openRawResourceFd(video);
113         MediaExtractor extractor = new MediaExtractor();
114         extractor.setDataSource(testFd.getFileDescriptor(), testFd.getStartOffset(),
115                 testFd.getLength());
116         extractor.selectTrack(0);
117         int trackIndex = extractor.getSampleTrackIndex();
118         MediaFormat format = extractor.getTrackFormat(trackIndex);
119         String mime = format.getString(MediaFormat.KEY_MIME);
120         ByteBuffer[] codecInputBuffers;
121         ByteBuffer[] codecOutputBuffers;
122 
123         if (mSamplesInMemory.size() == 0) {
124             int totalMemory = 0;
125             ByteBuffer tmpBuf = ByteBuffer.allocate(w * h * 3 / 2);
126             int sampleSize = 0;
127             int index = 0;
128             while ((sampleSize = extractor.readSampleData(tmpBuf, 0 /* offset */)) > 0) {
129                 if (totalMemory + sampleSize > MAX_SIZE_SAMPLES_IN_MEMORY_BYTES) {
130                     break;
131                 }
132                 ByteBuffer copied = ByteBuffer.allocate(sampleSize);
133                 copied.put(tmpBuf);
134                 mSamplesInMemory.addLast(copied);
135                 totalMemory += sampleSize;
136                 extractor.advance();
137             }
138             Log.d(TAG, mSamplesInMemory.size() + " samples in memory for " +
139                     (totalMemory / 1024) + " KB.");
140             // bitrate normalized to 30fps
141             mBitrate = (int)Math.round(totalMemory * 30. * 8. / mSamplesInMemory.size());
142         }
143         format.setInteger(MediaFormat.KEY_BIT_RATE, mBitrate);
144 
145         int sampleIndex = 0;
146 
147         extractor.release();
148         testFd.close();
149 
150         MediaCodec codec = MediaCodec.createByCodecName(name);
151         VideoCapabilities cap = codec.getCodecInfo().getCapabilitiesForType(mime).getVideoCapabilities();
152         int frameRate = cap.getSupportedFrameRatesFor(w, h).getUpper().intValue();
153         codec.configure(format, surface, null /* crypto */, 0 /* flags */);
154         codec.start();
155         codecInputBuffers = codec.getInputBuffers();
156         codecOutputBuffers = codec.getOutputBuffers();
157         mDecInputFormat = codec.getInputFormat();
158 
159         // start decode loop
160         MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
161 
162         final long kTimeOutUs = 1000; // 1ms timeout
163         double[] frameTimeUsDiff = new double[TOTAL_FRAMES - 1];
164         long lastOutputTimeUs = 0;
165         boolean sawInputEOS = false;
166         boolean sawOutputEOS = false;
167         int inputNum = 0;
168         int outputNum = 0;
169         long start = System.currentTimeMillis();
170         while (!sawOutputEOS) {
171             // handle input
172             if (!sawInputEOS) {
173                 int inputBufIndex = codec.dequeueInputBuffer(kTimeOutUs);
174 
175                 if (inputBufIndex >= 0) {
176                     ByteBuffer dstBuf = codecInputBuffers[inputBufIndex];
177                     ByteBuffer sample =
178                             mSamplesInMemory.get(sampleIndex++ % mSamplesInMemory.size());
179                     sample.rewind();
180                     int sampleSize = sample.remaining();
181                     dstBuf.put(sample);
182                     // use 120fps to compute pts
183                     long presentationTimeUs = inputNum * 1000000L / frameRate;
184 
185                     long elapsed = System.currentTimeMillis() - start;
186                     sawInputEOS = ((++inputNum == TOTAL_FRAMES)
187                                    || (elapsed > maxTimeMs)
188                                    || (elapsed > MIN_TEST_MS && outputNum > MIN_FRAMES));
189                     if (sawInputEOS) {
190                         Log.d(TAG, "saw input EOS (stop at sample).");
191                     }
192                     codec.queueInputBuffer(
193                             inputBufIndex,
194                             0 /* offset */,
195                             sampleSize,
196                             presentationTimeUs,
197                             sawInputEOS ? MediaCodec.BUFFER_FLAG_END_OF_STREAM : 0);
198                 } else {
199                     assertEquals(
200                             "codec.dequeueInputBuffer() unrecognized return value: " + inputBufIndex,
201                             MediaCodec.INFO_TRY_AGAIN_LATER, inputBufIndex);
202                 }
203             }
204 
205             // handle output
206             int outputBufIndex = codec.dequeueOutputBuffer(info, kTimeOutUs);
207 
208             if (outputBufIndex >= 0) {
209                 if (info.size > 0) { // Disregard 0-sized buffers at the end.
210                     long nowUs = (System.nanoTime() + 500) / 1000;
211                     if (outputNum > 1) {
212                         frameTimeUsDiff[outputNum - 1] = nowUs - lastOutputTimeUs;
213                     }
214                     lastOutputTimeUs = nowUs;
215                     outputNum++;
216                 }
217                 codec.releaseOutputBuffer(outputBufIndex, false /* render */);
218                 if ((info.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) {
219                     Log.d(TAG, "saw output EOS.");
220                     sawOutputEOS = true;
221                 }
222             } else if (outputBufIndex == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
223                 codecOutputBuffers = codec.getOutputBuffers();
224                 Log.d(TAG, "output buffers have changed.");
225             } else if (outputBufIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
226                 mDecOutputFormat = codec.getOutputFormat();
227                 int width = mDecOutputFormat.getInteger(MediaFormat.KEY_WIDTH);
228                 int height = mDecOutputFormat.getInteger(MediaFormat.KEY_HEIGHT);
229                 Log.d(TAG, "output resolution " + width + "x" + height);
230             } else {
231                 assertEquals(
232                         "codec.dequeueOutputBuffer() unrecognized return index: "
233                                 + outputBufIndex,
234                         MediaCodec.INFO_TRY_AGAIN_LATER, outputBufIndex);
235             }
236         }
237         long finish = System.currentTimeMillis();
238         int validDataNum = outputNum - 1;
239         frameTimeUsDiff = Arrays.copyOf(frameTimeUsDiff, validDataNum);
240         codec.stop();
241         codec.release();
242 
243         Log.d(TAG, "input num " + inputNum + " vs output num " + outputNum);
244 
245         DeviceReportLog log = new DeviceReportLog(REPORT_LOG_NAME, "video_decoder_performance");
246         String message = MediaPerfUtils.addPerformanceHeadersToLog(
247                 log, "decoder stats: decodeTo=" + ((surface == null) ? "buffer" : "surface"),
248                 round, name, format, mDecInputFormat, mDecOutputFormat);
249         log.addValue("video_res", video, ResultType.NEUTRAL, ResultUnit.NONE);
250         log.addValue("decode_to", surface == null ? "buffer" : "surface",
251                 ResultType.NEUTRAL, ResultUnit.NONE);
252 
253         double fps = outputNum / ((finish - start) / 1000.0);
254         log.addValue("average_fps", fps, ResultType.HIGHER_BETTER, ResultUnit.FPS);
255 
256         MediaUtils.Stats stats = new MediaUtils.Stats(frameTimeUsDiff);
257         fps = MediaPerfUtils.addPerformanceStatsToLog(log, stats, message);
258         log.submit(getInstrumentation());
259         return fps;
260     }
261 
getVideoTrackFormats(int... resources)262     private MediaFormat[] getVideoTrackFormats(int... resources) throws Exception {
263         MediaFormat[] formats = new MediaFormat[resources.length];
264         for (int i = 0; i < resources.length; ++i) {
265             formats[i] = MediaUtils.getTrackFormatForResource(mContext, resources[i], "video/");
266         }
267         return formats;
268     }
269 
count(int[] resources, int numGoog, int numOther)270     private void count(int[] resources, int numGoog, int numOther) throws Exception {
271         MediaFormat[] formats = getVideoTrackFormats(resources);
272         MediaUtils.verifyNumCodecs(numGoog,  false /* isEncoder */, true /* isGoog */,  formats);
273         MediaUtils.verifyNumCodecs(numOther, false /* isEncoder */, false /* isGoog */, formats);
274     }
275 
perf(int[] resources, boolean isGoog, int ix)276     private void perf(int[] resources, boolean isGoog, int ix)  throws Exception {
277         MediaFormat[] formats = getVideoTrackFormats(resources);
278         String[] decoders = MediaUtils.getDecoderNames(isGoog, formats);
279         String kind = isGoog ? "Google" : "non-Google";
280         if (decoders.length == 0) {
281             MediaUtils.skipTest("No " + kind + " decoders for " + Arrays.toString(formats));
282             return;
283         } else if (ix >= decoders.length) {
284             Log.i(TAG, "No more " + kind + " decoders for " + Arrays.toString(formats));
285             return;
286         }
287 
288         String decoderName = decoders[ix];
289 
290         // Decode/measure the first supported video resource
291         for (int i = 0; i < resources.length; ++i) {
292             if (MediaUtils.supports(decoderName, formats[i])) {
293                 decode(decoderName, resources[i], formats[i]);
294                 break;
295             }
296         }
297     }
298 
299     // Poor man's Parametrized test as this test must still run on CTSv1 runner.
300 
301     // The count tests are to ensure this Cts test covers all decoders. Add further
302     // tests and change the count if there can be more decoders.
303 
304     // AVC tests
305 
306     private static final int[] sAvcMedia0320x0240 = {
307         R.raw.bbb_s1_320x240_mp4_h264_mp2_800kbps_30fps_aac_lc_5ch_240kbps_44100hz,
308     };
309 
testAvcCount0320x0240()310     public void testAvcCount0320x0240() throws Exception { count(sAvcMedia0320x0240, 1, 4); }
testAvcGoog0Perf0320x0240()311     public void testAvcGoog0Perf0320x0240() throws Exception { perf(sAvcMedia0320x0240, GOOG, 0); }
testAvcOther0Perf0320x0240()312     public void testAvcOther0Perf0320x0240() throws Exception { perf(sAvcMedia0320x0240, OTHER, 0); }
testAvcOther1Perf0320x0240()313     public void testAvcOther1Perf0320x0240() throws Exception { perf(sAvcMedia0320x0240, OTHER, 1); }
testAvcOther2Perf0320x0240()314     public void testAvcOther2Perf0320x0240() throws Exception { perf(sAvcMedia0320x0240, OTHER, 2); }
testAvcOther3Perf0320x0240()315     public void testAvcOther3Perf0320x0240() throws Exception { perf(sAvcMedia0320x0240, OTHER, 3); }
316 
317     private static final int[] sAvcMedia0720x0480 = {
318         R.raw.bbb_s1_720x480_mp4_h264_mp3_2mbps_30fps_aac_lc_5ch_320kbps_48000hz,
319     };
320 
testAvcCount0720x0480()321     public void testAvcCount0720x0480() throws Exception { count(sAvcMedia0720x0480, 1, 4); }
testAvcGoog0Perf0720x0480()322     public void testAvcGoog0Perf0720x0480() throws Exception { perf(sAvcMedia0720x0480, GOOG, 0); }
testAvcOther0Perf0720x0480()323     public void testAvcOther0Perf0720x0480() throws Exception { perf(sAvcMedia0720x0480, OTHER, 0); }
testAvcOther1Perf0720x0480()324     public void testAvcOther1Perf0720x0480() throws Exception { perf(sAvcMedia0720x0480, OTHER, 1); }
testAvcOther2Perf0720x0480()325     public void testAvcOther2Perf0720x0480() throws Exception { perf(sAvcMedia0720x0480, OTHER, 2); }
testAvcOther3Perf0720x0480()326     public void testAvcOther3Perf0720x0480() throws Exception { perf(sAvcMedia0720x0480, OTHER, 3); }
327 
328     // prefer highest effective bitrate, then high profile
329     private static final int[] sAvcMedia1280x0720 = {
330         R.raw.bbb_s4_1280x720_mp4_h264_mp31_8mbps_30fps_aac_he_mono_40kbps_44100hz,
331         R.raw.bbb_s3_1280x720_mp4_h264_hp32_8mbps_60fps_aac_he_v2_stereo_48kbps_48000hz,
332         R.raw.bbb_s3_1280x720_mp4_h264_mp32_8mbps_60fps_aac_he_v2_6ch_144kbps_44100hz,
333     };
334 
testAvcCount1280x0720()335     public void testAvcCount1280x0720() throws Exception { count(sAvcMedia1280x0720, 1, 4); }
testAvcGoog0Perf1280x0720()336     public void testAvcGoog0Perf1280x0720() throws Exception { perf(sAvcMedia1280x0720, GOOG, 0); }
testAvcOther0Perf1280x0720()337     public void testAvcOther0Perf1280x0720() throws Exception { perf(sAvcMedia1280x0720, OTHER, 0); }
testAvcOther1Perf1280x0720()338     public void testAvcOther1Perf1280x0720() throws Exception { perf(sAvcMedia1280x0720, OTHER, 1); }
testAvcOther2Perf1280x0720()339     public void testAvcOther2Perf1280x0720() throws Exception { perf(sAvcMedia1280x0720, OTHER, 2); }
testAvcOther3Perf1280x0720()340     public void testAvcOther3Perf1280x0720() throws Exception { perf(sAvcMedia1280x0720, OTHER, 3); }
341 
342     // prefer highest effective bitrate, then high profile
343     private static final int[] sAvcMedia1920x1080 = {
344         R.raw.bbb_s4_1920x1080_wide_mp4_h264_hp4_20mbps_30fps_aac_lc_6ch_384kbps_44100hz,
345         R.raw.bbb_s4_1920x1080_wide_mp4_h264_mp4_20mbps_30fps_aac_he_5ch_200kbps_44100hz,
346         R.raw.bbb_s2_1920x1080_mp4_h264_hp42_20mbps_60fps_aac_lc_6ch_384kbps_48000hz,
347         R.raw.bbb_s2_1920x1080_mp4_h264_mp42_20mbps_60fps_aac_he_v2_5ch_160kbps_48000hz,
348     };
349 
testAvcCount1920x1080()350     public void testAvcCount1920x1080() throws Exception { count(sAvcMedia1920x1080, 1, 4); }
testAvcGoog0Perf1920x1080()351     public void testAvcGoog0Perf1920x1080() throws Exception { perf(sAvcMedia1920x1080, GOOG, 0); }
testAvcOther0Perf1920x1080()352     public void testAvcOther0Perf1920x1080() throws Exception { perf(sAvcMedia1920x1080, OTHER, 0); }
testAvcOther1Perf1920x1080()353     public void testAvcOther1Perf1920x1080() throws Exception { perf(sAvcMedia1920x1080, OTHER, 1); }
testAvcOther2Perf1920x1080()354     public void testAvcOther2Perf1920x1080() throws Exception { perf(sAvcMedia1920x1080, OTHER, 2); }
testAvcOther3Perf1920x1080()355     public void testAvcOther3Perf1920x1080() throws Exception { perf(sAvcMedia1920x1080, OTHER, 3); }
356 
357     // H263 tests
358 
359     private static final int[] sH263Media0176x0144 = {
360         R.raw.video_176x144_3gp_h263_300kbps_12fps_aac_stereo_128kbps_22050hz,
361     };
362 
testH263Count0176x0144()363     public void testH263Count0176x0144() throws Exception { count(sH263Media0176x0144, 1, 2); }
testH263Goog0Perf0176x0144()364     public void testH263Goog0Perf0176x0144() throws Exception { perf(sH263Media0176x0144, GOOG, 0); }
testH263Other0Perf0176x0144()365     public void testH263Other0Perf0176x0144() throws Exception { perf(sH263Media0176x0144, OTHER, 0); }
testH263Other1Perf0176x0144()366     public void testH263Other1Perf0176x0144() throws Exception { perf(sH263Media0176x0144, OTHER, 1); }
367 
368     private static final int[] sH263Media0352x0288 = {
369         R.raw.video_352x288_3gp_h263_300kbps_12fps_aac_stereo_128kbps_22050hz,
370     };
371 
testH263Count0352x0288()372     public void testH263Count0352x0288() throws Exception { count(sH263Media0352x0288, 1, 2); }
testH263Goog0Perf0352x0288()373     public void testH263Goog0Perf0352x0288() throws Exception { perf(sH263Media0352x0288, GOOG, 0); }
testH263Other0Perf0352x0288()374     public void testH263Other0Perf0352x0288() throws Exception { perf(sH263Media0352x0288, OTHER, 0); }
testH263Other1Perf0352x0288()375     public void testH263Other1Perf0352x0288() throws Exception { perf(sH263Media0352x0288, OTHER, 1); }
376 
377     // No media for H263 704x576
378 
379     // No media for H263 1408x1152
380 
381     // HEVC tests
382 
383     private static final int[] sHevcMedia0352x0288 = {
384         R.raw.bbb_s1_352x288_mp4_hevc_mp2_600kbps_30fps_aac_he_stereo_96kbps_48000hz,
385     };
386 
testHevcCount0352x0288()387     public void testHevcCount0352x0288() throws Exception { count(sHevcMedia0352x0288, 1, 4); }
testHevcGoog0Perf0352x0288()388     public void testHevcGoog0Perf0352x0288() throws Exception { perf(sHevcMedia0352x0288, GOOG, 0); }
testHevcOther0Perf0352x0288()389     public void testHevcOther0Perf0352x0288() throws Exception { perf(sHevcMedia0352x0288, OTHER, 0); }
testHevcOther1Perf0352x0288()390     public void testHevcOther1Perf0352x0288() throws Exception { perf(sHevcMedia0352x0288, OTHER, 1); }
testHevcOther2Perf0352x0288()391     public void testHevcOther2Perf0352x0288() throws Exception { perf(sHevcMedia0352x0288, OTHER, 2); }
testHevcOther3Perf0352x0288()392     public void testHevcOther3Perf0352x0288() throws Exception { perf(sHevcMedia0352x0288, OTHER, 3); }
393 
394     private static final int[] sHevcMedia0640x0360 = {
395         R.raw.bbb_s1_640x360_mp4_hevc_mp21_1600kbps_30fps_aac_he_6ch_288kbps_44100hz,
396     };
397 
testHevcCount0640x0360()398     public void testHevcCount0640x0360() throws Exception { count(sHevcMedia0640x0360, 1, 4); }
testHevcGoog0Perf0640x0360()399     public void testHevcGoog0Perf0640x0360() throws Exception { perf(sHevcMedia0640x0360, GOOG, 0); }
testHevcOther0Perf0640x0360()400     public void testHevcOther0Perf0640x0360() throws Exception { perf(sHevcMedia0640x0360, OTHER, 0); }
testHevcOther1Perf0640x0360()401     public void testHevcOther1Perf0640x0360() throws Exception { perf(sHevcMedia0640x0360, OTHER, 1); }
testHevcOther2Perf0640x0360()402     public void testHevcOther2Perf0640x0360() throws Exception { perf(sHevcMedia0640x0360, OTHER, 2); }
testHevcOther3Perf0640x0360()403     public void testHevcOther3Perf0640x0360() throws Exception { perf(sHevcMedia0640x0360, OTHER, 3); }
404 
405     private static final int[] sHevcMedia0720x0480 = {
406         R.raw.bbb_s1_720x480_mp4_hevc_mp3_1600kbps_30fps_aac_he_6ch_240kbps_48000hz,
407     };
408 
testHevcCount0720x0480()409     public void testHevcCount0720x0480() throws Exception { count(sHevcMedia0720x0480, 1, 4); }
testHevcGoog0Perf0720x0480()410     public void testHevcGoog0Perf0720x0480() throws Exception { perf(sHevcMedia0720x0480, GOOG, 0); }
testHevcOther0Perf0720x0480()411     public void testHevcOther0Perf0720x0480() throws Exception { perf(sHevcMedia0720x0480, OTHER, 0); }
testHevcOther1Perf0720x0480()412     public void testHevcOther1Perf0720x0480() throws Exception { perf(sHevcMedia0720x0480, OTHER, 1); }
testHevcOther2Perf0720x0480()413     public void testHevcOther2Perf0720x0480() throws Exception { perf(sHevcMedia0720x0480, OTHER, 2); }
testHevcOther3Perf0720x0480()414     public void testHevcOther3Perf0720x0480() throws Exception { perf(sHevcMedia0720x0480, OTHER, 3); }
415 
416     private static final int[] sHevcMedia1280x0720 = {
417         R.raw.bbb_s4_1280x720_mp4_hevc_mp31_4mbps_30fps_aac_he_stereo_80kbps_32000hz,
418     };
419 
testHevcCount1280x0720()420     public void testHevcCount1280x0720() throws Exception { count(sHevcMedia1280x0720, 1, 4); }
testHevcGoog0Perf1280x0720()421     public void testHevcGoog0Perf1280x0720() throws Exception { perf(sHevcMedia1280x0720, GOOG, 0); }
testHevcOther0Perf1280x0720()422     public void testHevcOther0Perf1280x0720() throws Exception { perf(sHevcMedia1280x0720, OTHER, 0); }
testHevcOther1Perf1280x0720()423     public void testHevcOther1Perf1280x0720() throws Exception { perf(sHevcMedia1280x0720, OTHER, 1); }
testHevcOther2Perf1280x0720()424     public void testHevcOther2Perf1280x0720() throws Exception { perf(sHevcMedia1280x0720, OTHER, 2); }
testHevcOther3Perf1280x0720()425     public void testHevcOther3Perf1280x0720() throws Exception { perf(sHevcMedia1280x0720, OTHER, 3); }
426 
427     private static final int[] sHevcMedia1920x1080 = {
428         R.raw.bbb_s2_1920x1080_mp4_hevc_mp41_10mbps_60fps_aac_lc_6ch_384kbps_22050hz,
429     };
430 
testHevcCount1920x1080()431     public void testHevcCount1920x1080() throws Exception { count(sHevcMedia1920x1080, 1, 4); }
testHevcGoog0Perf1920x1080()432     public void testHevcGoog0Perf1920x1080() throws Exception { perf(sHevcMedia1920x1080, GOOG, 0); }
testHevcOther0Perf1920x1080()433     public void testHevcOther0Perf1920x1080() throws Exception { perf(sHevcMedia1920x1080, OTHER, 0); }
testHevcOther1Perf1920x1080()434     public void testHevcOther1Perf1920x1080() throws Exception { perf(sHevcMedia1920x1080, OTHER, 1); }
testHevcOther2Perf1920x1080()435     public void testHevcOther2Perf1920x1080() throws Exception { perf(sHevcMedia1920x1080, OTHER, 2); }
testHevcOther3Perf1920x1080()436     public void testHevcOther3Perf1920x1080() throws Exception { perf(sHevcMedia1920x1080, OTHER, 3); }
437 
438     // prefer highest effective bitrate
439     private static final int[] sHevcMedia3840x2160 = {
440         R.raw.bbb_s4_3840x2160_mp4_hevc_mp5_20mbps_30fps_aac_lc_6ch_384kbps_24000hz,
441         R.raw.bbb_s2_3840x2160_mp4_hevc_mp51_20mbps_60fps_aac_lc_6ch_384kbps_32000hz,
442     };
443 
testHevcCount3840x2160()444     public void testHevcCount3840x2160() throws Exception { count(sHevcMedia3840x2160, 1, 4); }
testHevcGoog0Perf3840x2160()445     public void testHevcGoog0Perf3840x2160() throws Exception { perf(sHevcMedia3840x2160, GOOG, 0); }
testHevcOther0Perf3840x2160()446     public void testHevcOther0Perf3840x2160() throws Exception { perf(sHevcMedia3840x2160, OTHER, 0); }
testHevcOther1Perf3840x2160()447     public void testHevcOther1Perf3840x2160() throws Exception { perf(sHevcMedia3840x2160, OTHER, 1); }
testHevcOther2Perf3840x2160()448     public void testHevcOther2Perf3840x2160() throws Exception { perf(sHevcMedia3840x2160, OTHER, 2); }
testHevcOther3Perf3840x2160()449     public void testHevcOther3Perf3840x2160() throws Exception { perf(sHevcMedia3840x2160, OTHER, 3); }
450 
451     // MPEG2 tests
452 
453     // No media for MPEG2 176x144
454 
455     // No media for MPEG2 352x288
456 
457     // No media for MPEG2 640x480
458 
459     // No media for MPEG2 1280x720
460 
461     // No media for MPEG2 1920x1080
462 
463     // MPEG4 tests
464 
465     private static final int[] sMpeg4Media0176x0144 = {
466         R.raw.video_176x144_mp4_mpeg4_300kbps_25fps_aac_stereo_128kbps_44100hz,
467     };
468 
testMpeg4Count0176x0144()469     public void testMpeg4Count0176x0144() throws Exception { count(sMpeg4Media0176x0144, 1, 4); }
testMpeg4Goog0Perf0176x0144()470     public void testMpeg4Goog0Perf0176x0144() throws Exception { perf(sMpeg4Media0176x0144, GOOG, 0); }
testMpeg4Other0Perf0176x0144()471     public void testMpeg4Other0Perf0176x0144() throws Exception { perf(sMpeg4Media0176x0144, OTHER, 0); }
testMpeg4Other1Perf0176x0144()472     public void testMpeg4Other1Perf0176x0144() throws Exception { perf(sMpeg4Media0176x0144, OTHER, 1); }
testMpeg4Other2Perf0176x0144()473     public void testMpeg4Other2Perf0176x0144() throws Exception { perf(sMpeg4Media0176x0144, OTHER, 2); }
testMpeg4Other3Perf0176x0144()474     public void testMpeg4Other3Perf0176x0144() throws Exception { perf(sMpeg4Media0176x0144, OTHER, 3); }
475 
476     private static final int[] sMpeg4Media0480x0360 = {
477         R.raw.video_480x360_mp4_mpeg4_860kbps_25fps_aac_stereo_128kbps_44100hz,
478     };
479 
testMpeg4Count0480x0360()480     public void testMpeg4Count0480x0360() throws Exception { count(sMpeg4Media0480x0360, 1, 4); }
testMpeg4Goog0Perf0480x0360()481     public void testMpeg4Goog0Perf0480x0360() throws Exception { perf(sMpeg4Media0480x0360, GOOG, 0); }
testMpeg4Other0Perf0480x0360()482     public void testMpeg4Other0Perf0480x0360() throws Exception { perf(sMpeg4Media0480x0360, OTHER, 0); }
testMpeg4Other1Perf0480x0360()483     public void testMpeg4Other1Perf0480x0360() throws Exception { perf(sMpeg4Media0480x0360, OTHER, 1); }
testMpeg4Other2Perf0480x0360()484     public void testMpeg4Other2Perf0480x0360() throws Exception { perf(sMpeg4Media0480x0360, OTHER, 2); }
testMpeg4Other3Perf0480x0360()485     public void testMpeg4Other3Perf0480x0360() throws Exception { perf(sMpeg4Media0480x0360, OTHER, 3); }
486 
487    // No media for MPEG4 640x480
488 
489     private static final int[] sMpeg4Media1280x0720 = {
490         R.raw.video_1280x720_mp4_mpeg4_1000kbps_25fps_aac_stereo_128kbps_44100hz,
491     };
492 
testMpeg4Count1280x0720()493     public void testMpeg4Count1280x0720() throws Exception { count(sMpeg4Media1280x0720, 1, 4); }
testMpeg4Goog0Perf1280x0720()494     public void testMpeg4Goog0Perf1280x0720() throws Exception { perf(sMpeg4Media1280x0720, GOOG, 0); }
testMpeg4Other0Perf1280x0720()495     public void testMpeg4Other0Perf1280x0720() throws Exception { perf(sMpeg4Media1280x0720, OTHER, 0); }
testMpeg4Other1Perf1280x0720()496     public void testMpeg4Other1Perf1280x0720() throws Exception { perf(sMpeg4Media1280x0720, OTHER, 1); }
testMpeg4Other2Perf1280x0720()497     public void testMpeg4Other2Perf1280x0720() throws Exception { perf(sMpeg4Media1280x0720, OTHER, 2); }
testMpeg4Other3Perf1280x0720()498     public void testMpeg4Other3Perf1280x0720() throws Exception { perf(sMpeg4Media1280x0720, OTHER, 3); }
499 
500     // VP8 tests
501 
502     private static final int[] sVp8Media0320x0180 = {
503         R.raw.bbb_s1_320x180_webm_vp8_800kbps_30fps_opus_5ch_320kbps_48000hz,
504     };
505 
testVp8Count0320x0180()506     public void testVp8Count0320x0180() throws Exception { count(sVp8Media0320x0180, 1, 2); }
testVp8Goog0Perf0320x0180()507     public void testVp8Goog0Perf0320x0180() throws Exception { perf(sVp8Media0320x0180, GOOG, 0); }
testVp8Other0Perf0320x0180()508     public void testVp8Other0Perf0320x0180() throws Exception { perf(sVp8Media0320x0180, OTHER, 0); }
testVp8Other1Perf0320x0180()509     public void testVp8Other1Perf0320x0180() throws Exception { perf(sVp8Media0320x0180, OTHER, 1); }
510 
511     private static final int[] sVp8Media0640x0360 = {
512         R.raw.bbb_s1_640x360_webm_vp8_2mbps_30fps_vorbis_5ch_320kbps_48000hz,
513     };
514 
testVp8Count0640x0360()515     public void testVp8Count0640x0360() throws Exception { count(sVp8Media0640x0360, 1, 2); }
testVp8Goog0Perf0640x0360()516     public void testVp8Goog0Perf0640x0360() throws Exception { perf(sVp8Media0640x0360, GOOG, 0); }
testVp8Other0Perf0640x0360()517     public void testVp8Other0Perf0640x0360() throws Exception { perf(sVp8Media0640x0360, OTHER, 0); }
testVp8Other1Perf0640x0360()518     public void testVp8Other1Perf0640x0360() throws Exception { perf(sVp8Media0640x0360, OTHER, 1); }
519 
520     // prefer highest effective bitrate
521     private static final int[] sVp8Media1280x0720 = {
522         R.raw.bbb_s4_1280x720_webm_vp8_8mbps_30fps_opus_mono_64kbps_48000hz,
523         R.raw.bbb_s3_1280x720_webm_vp8_8mbps_60fps_opus_6ch_384kbps_48000hz,
524     };
525 
testVp8Count1280x0720()526     public void testVp8Count1280x0720() throws Exception { count(sVp8Media1280x0720, 1, 2); }
testVp8Goog0Perf1280x0720()527     public void testVp8Goog0Perf1280x0720() throws Exception { perf(sVp8Media1280x0720, GOOG, 0); }
testVp8Other0Perf1280x0720()528     public void testVp8Other0Perf1280x0720() throws Exception { perf(sVp8Media1280x0720, OTHER, 0); }
testVp8Other1Perf1280x0720()529     public void testVp8Other1Perf1280x0720() throws Exception { perf(sVp8Media1280x0720, OTHER, 1); }
530 
531     // prefer highest effective bitrate
532     private static final int[] sVp8Media1920x1080 = {
533         R.raw.bbb_s4_1920x1080_wide_webm_vp8_20mbps_30fps_vorbis_6ch_384kbps_44100hz,
534         R.raw.bbb_s2_1920x1080_webm_vp8_20mbps_60fps_vorbis_6ch_384kbps_48000hz,
535     };
536 
testVp8Count1920x1080()537     public void testVp8Count1920x1080() throws Exception { count(sVp8Media1920x1080, 1, 2); }
testVp8Goog0Perf1920x1080()538     public void testVp8Goog0Perf1920x1080() throws Exception { perf(sVp8Media1920x1080, GOOG, 0); }
testVp8Other0Perf1920x1080()539     public void testVp8Other0Perf1920x1080() throws Exception { perf(sVp8Media1920x1080, OTHER, 0); }
testVp8Other1Perf1920x1080()540     public void testVp8Other1Perf1920x1080() throws Exception { perf(sVp8Media1920x1080, OTHER, 1); }
541 
542     // VP9 tests
543 
544     private static final int[] sVp9Media0320x0180 = {
545         R.raw.bbb_s1_320x180_webm_vp9_0p11_600kbps_30fps_vorbis_mono_64kbps_48000hz,
546     };
547 
testVp9Count0320x0180()548     public void testVp9Count0320x0180() throws Exception { count(sVp9Media0320x0180, 1, 4); }
testVp9Goog0Perf0320x0180()549     public void testVp9Goog0Perf0320x0180() throws Exception { perf(sVp9Media0320x0180, GOOG, 0); }
testVp9Other0Perf0320x0180()550     public void testVp9Other0Perf0320x0180() throws Exception { perf(sVp9Media0320x0180, OTHER, 0); }
testVp9Other1Perf0320x0180()551     public void testVp9Other1Perf0320x0180() throws Exception { perf(sVp9Media0320x0180, OTHER, 1); }
testVp9Other2Perf0320x0180()552     public void testVp9Other2Perf0320x0180() throws Exception { perf(sVp9Media0320x0180, OTHER, 2); }
testVp9Other3Perf0320x0180()553     public void testVp9Other3Perf0320x0180() throws Exception { perf(sVp9Media0320x0180, OTHER, 3); }
554 
555     private static final int[] sVp9Media0640x0360 = {
556         R.raw.bbb_s1_640x360_webm_vp9_0p21_1600kbps_30fps_vorbis_stereo_128kbps_48000hz,
557     };
558 
testVp9Count0640x0360()559     public void testVp9Count0640x0360() throws Exception { count(sVp9Media0640x0360, 1, 4); }
testVp9Goog0Perf0640x0360()560     public void testVp9Goog0Perf0640x0360() throws Exception { perf(sVp9Media0640x0360, GOOG, 0); }
testVp9Other0Perf0640x0360()561     public void testVp9Other0Perf0640x0360() throws Exception { perf(sVp9Media0640x0360, OTHER, 0); }
testVp9Other1Perf0640x0360()562     public void testVp9Other1Perf0640x0360() throws Exception { perf(sVp9Media0640x0360, OTHER, 1); }
testVp9Other2Perf0640x0360()563     public void testVp9Other2Perf0640x0360() throws Exception { perf(sVp9Media0640x0360, OTHER, 2); }
testVp9Other3Perf0640x0360()564     public void testVp9Other3Perf0640x0360() throws Exception { perf(sVp9Media0640x0360, OTHER, 3); }
565 
566     private static final int[] sVp9Media1280x0720 = {
567         R.raw.bbb_s4_1280x720_webm_vp9_0p31_4mbps_30fps_opus_stereo_128kbps_48000hz,
568     };
569 
testVp9Count1280x0720()570     public void testVp9Count1280x0720() throws Exception { count(sVp9Media1280x0720, 1, 4); }
testVp9Goog0Perf1280x0720()571     public void testVp9Goog0Perf1280x0720() throws Exception { perf(sVp9Media1280x0720, GOOG, 0); }
testVp9Other0Perf1280x0720()572     public void testVp9Other0Perf1280x0720() throws Exception { perf(sVp9Media1280x0720, OTHER, 0); }
testVp9Other1Perf1280x0720()573     public void testVp9Other1Perf1280x0720() throws Exception { perf(sVp9Media1280x0720, OTHER, 1); }
testVp9Other2Perf1280x0720()574     public void testVp9Other2Perf1280x0720() throws Exception { perf(sVp9Media1280x0720, OTHER, 2); }
testVp9Other3Perf1280x0720()575     public void testVp9Other3Perf1280x0720() throws Exception { perf(sVp9Media1280x0720, OTHER, 3); }
576 
577     private static final int[] sVp9Media1920x1080 = {
578         R.raw.bbb_s2_1920x1080_webm_vp9_0p41_10mbps_60fps_vorbis_6ch_384kbps_22050hz,
579     };
580 
testVp9Count1920x1080()581     public void testVp9Count1920x1080() throws Exception { count(sVp9Media1920x1080, 1, 4); }
testVp9Goog0Perf1920x1080()582     public void testVp9Goog0Perf1920x1080() throws Exception { perf(sVp9Media1920x1080, GOOG, 0); }
testVp9Other0Perf1920x1080()583     public void testVp9Other0Perf1920x1080() throws Exception { perf(sVp9Media1920x1080, OTHER, 0); }
testVp9Other1Perf1920x1080()584     public void testVp9Other1Perf1920x1080() throws Exception { perf(sVp9Media1920x1080, OTHER, 1); }
testVp9Other2Perf1920x1080()585     public void testVp9Other2Perf1920x1080() throws Exception { perf(sVp9Media1920x1080, OTHER, 2); }
testVp9Other3Perf1920x1080()586     public void testVp9Other3Perf1920x1080() throws Exception { perf(sVp9Media1920x1080, OTHER, 3); }
587 
588     // prefer highest effective bitrate
589     private static final int[] sVp9Media3840x2160 = {
590         R.raw.bbb_s4_3840x2160_webm_vp9_0p5_20mbps_30fps_vorbis_6ch_384kbps_24000hz,
591         R.raw.bbb_s2_3840x2160_webm_vp9_0p51_20mbps_60fps_vorbis_6ch_384kbps_32000hz,
592     };
593 
testVp9Count3840x2160()594     public void testVp9Count3840x2160() throws Exception { count(sVp9Media3840x2160, 1, 4); }
testVp9Goog0Perf3840x2160()595     public void testVp9Goog0Perf3840x2160() throws Exception { perf(sVp9Media3840x2160, GOOG, 0); }
testVp9Other0Perf3840x2160()596     public void testVp9Other0Perf3840x2160() throws Exception { perf(sVp9Media3840x2160, OTHER, 0); }
testVp9Other1Perf3840x2160()597     public void testVp9Other1Perf3840x2160() throws Exception { perf(sVp9Media3840x2160, OTHER, 1); }
testVp9Other2Perf3840x2160()598     public void testVp9Other2Perf3840x2160() throws Exception { perf(sVp9Media3840x2160, OTHER, 2); }
testVp9Other3Perf3840x2160()599     public void testVp9Other3Perf3840x2160() throws Exception { perf(sVp9Media3840x2160, OTHER, 3); }
600 }
601 
602