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.media.codec.cts;
18 
19 import android.media.MediaCodecInfo;
20 import android.media.MediaCodecList;
21 import android.media.MediaFormat;
22 import android.media.cts.TestArgs;
23 import android.platform.test.annotations.RequiresDevice;
24 import android.util.Log;
25 
26 import androidx.test.filters.SmallTest;
27 import androidx.test.platform.app.InstrumentationRegistry;
28 
29 import com.android.compatibility.common.util.ApiTest;
30 import com.android.compatibility.common.util.FrameworkSpecificTest;
31 import com.android.compatibility.common.util.NonMainlineTest;
32 
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.junit.runners.Parameterized;
36 import org.junit.runners.Parameterized.Parameter;
37 import org.junit.runners.Parameterized.Parameters;
38 
39 import java.util.ArrayList;
40 import java.util.Arrays;
41 import java.util.Collection;
42 import java.util.List;
43 
44 /**
45  * Tests to check if MediaCodec decoding works with rotation.
46  */
47 @SmallTest
48 @RequiresDevice
49 @FrameworkSpecificTest   // fails in windowing on pure older releases
50 @NonMainlineTest   // fails in windowing on pure older releases
51 @RunWith(Parameterized.class)
52 public class VideoDecoderRotationTest {
53     private static final String TAG = "VideoDecoderRotationTest";
54 
55     private final EncodeVirtualDisplayWithCompositionTestImpl mImpl =
56             new EncodeVirtualDisplayWithCompositionTestImpl();
57 
58     @Parameter(0)
59     public String mDecoderName;
60     @Parameter(1)
61     public String mMimeType;
62     @Parameter(2)
63     public Integer mDegrees;
64 
65     private static final List<String> SUPPORTED_TYPES = Arrays.asList(
66             MediaFormat.MIMETYPE_VIDEO_AVC,
67             MediaFormat.MIMETYPE_VIDEO_HEVC,
68             MediaFormat.MIMETYPE_VIDEO_VP8,
69             MediaFormat.MIMETYPE_VIDEO_VP9,
70             MediaFormat.MIMETYPE_VIDEO_AV1);
71 
72     @Parameters(name = "{0}:{1}:{2}")
data()73     public static Collection<Object[]> data() {
74         final List<Object[]> testParams = new ArrayList<>();
75         MediaCodecList mcl = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
76         for (MediaCodecInfo info : mcl.getCodecInfos()) {
77             if (info.isAlias() || info.isEncoder()) {
78                 continue;
79             }
80             String name = info.getName();
81             if (TestArgs.shouldSkipCodec(name)) {
82                 continue;
83             }
84 
85             for (String type : info.getSupportedTypes()) {
86                 if (!SUPPORTED_TYPES.contains(type)) {
87                     continue;
88                 }
89                 if (TestArgs.shouldSkipMediaType(type)) {
90                     continue;
91                 }
92 
93                 testParams.add(new Object[] { name, type, Integer.valueOf(90) });
94                 testParams.add(new Object[] { name, type, Integer.valueOf(180) });
95                 testParams.add(new Object[] { name, type, Integer.valueOf(270) });
96                 testParams.add(new Object[] { name, type, Integer.valueOf(360) });
97             }
98         }
99         return testParams;
100     }
101 
102     @ApiTest(apis = "android.media.MediaFormat#KEY_ROTATION")
103     @Test
testRendering800x480Rotated()104     public void testRendering800x480Rotated() throws Throwable {
105         if (mImpl.isConcurrentEncodingDecodingSupported(
106                 mMimeType, 800, 480, mImpl.BITRATE_800x480, mDecoderName)) {
107             mImpl.runTestRenderingInSeparateThread(
108                     InstrumentationRegistry.getInstrumentation().getContext(),
109                     mMimeType, 800, 480, false, false, mDegrees, mDecoderName);
110         } else {
111             Log.i(TAG, "SKIPPING testRendering800x480Rotated" + mDegrees + ":codec (" +
112                     mDecoderName + ":" + mMimeType + ") not supported");
113         }
114     }
115 }
116