1616
1717package android .media .encoder .cts ;
1818
19+ import static android .media .MediaCodecInfo .CodecProfileLevel .AACObjectELD ;
20+ import static android .media .MediaCodecInfo .CodecProfileLevel .AACObjectHE ;
21+ import static android .media .MediaCodecInfo .CodecProfileLevel .AACObjectLC ;
22+
23+ import static org .junit .Assert .assertEquals ;
24+ import static org .junit .Assert .assertFalse ;
25+ import static org .junit .Assert .assertTrue ;
26+ import static org .junit .Assert .fail ;
27+
1928import android .media .MediaCodec ;
2029import android .media .MediaCodecInfo ;
2130import android .media .MediaFormat ;
5362import org .junit .runner .RunWith ;
5463import org .junit .runners .Parameterized ;
5564
56- import static org .junit .Assert .assertEquals ;
57- import static org .junit .Assert .assertFalse ;
58- import static org .junit .Assert .assertTrue ;
59- import static org .junit .Assert .fail ;
60-
6165@ SmallTest
6266@ RequiresDevice
6367@ AppModeFull (reason = "Instant apps cannot access the SD card" )
@@ -87,10 +91,10 @@ public class EncoderTest {
8791
8892 private final String mEncoderName ;
8993 private final String mMime ;
90- private final int [] mProfiles ;
91- private final int [] mBitrates ;
92- private final int [] mSampleRates ;
93- private final int [] mChannelCounts ;
94+ private final int mProfile ;
95+ private final int mBitrate ;
96+ private final int mSampleRate ;
97+ private final int mChannelCount ;
9498 private ArrayList <MediaFormat > mFormats ;
9599
96100 static boolean isDefaultCodec (String codecName , String mime )
@@ -105,6 +109,34 @@ static boolean isDefaultCodec(String codecName, String mime)
105109 return isDefault ;
106110 }
107111
112+ private static List <Object []> flattenParams (List <Object []> params ) {
113+ List <Object []> argsList = new ArrayList <>();
114+ for (Object [] param : params ) {
115+ String mediaType = (String ) param [0 ];
116+ int [] profiles = (int []) param [1 ];
117+ int [] bitRates = (int []) param [2 ];
118+ int [] sampleRates = (int []) param [3 ];
119+ int [] channelCounts = (int []) param [4 ];
120+ for (int profile : profiles ) {
121+ for (int bitrate : bitRates ) {
122+ for (int channelCount : channelCounts ) {
123+ for (int sampleRate : sampleRates ) {
124+ if (mediaType .equals (MediaFormat .MIMETYPE_AUDIO_AAC )
125+ && profile == AACObjectHE && sampleRate < 22050 ) {
126+ // Is this right? HE does not support sample rates < 22050Hz?
127+ continue ;
128+ }
129+ argsList .add (
130+ new Object []{mediaType , profile , bitrate , sampleRate ,
131+ channelCount });
132+ }
133+ }
134+ }
135+ }
136+ }
137+ return argsList ;
138+ }
139+
108140 static private List <Object []> prepareParamList (List <Object []> exhaustiveArgsList ) {
109141 final List <Object []> argsList = new ArrayList <>();
110142 int argLength = exhaustiveArgsList .get (0 ).length ;
@@ -127,54 +159,48 @@ static private List<Object[]> prepareParamList(List<Object[]> exhaustiveArgsList
127159 return argsList ;
128160 }
129161
130- @ Parameterized .Parameters (name = "{index}({0}_{1})" )
162+ @ Parameterized .Parameters (name = "{index}({0}_{1}_{2}_{3}_{4}_{5} )" )
131163 public static Collection <Object []> input () {
132164 final List <Object []> exhaustiveArgsList = Arrays .asList (new Object [][]{
133165 // Audio - CodecMime, arrays of profiles, bit-rates, sample rates, channel counts
134- {MediaFormat .MIMETYPE_AUDIO_AAC , new int []{2 , 5 , 39 }, new int []{64000 , 128000 },
135- new int []{8000 , 11025 , 22050 , 44100 , 48000 }, new int []{1 , 2 }},
166+ {MediaFormat .MIMETYPE_AUDIO_AAC , new int []{AACObjectLC , AACObjectHE ,
167+ AACObjectELD }, new int []{64000 , 128000 }, new int []{8000 , 11025 , 22050 ,
168+ 44100 , 48000 }, new int []{1 , 2 }},
136169 {MediaFormat .MIMETYPE_AUDIO_OPUS , new int []{-1 }, new int []{8000 , 12000 , 16000 ,
137170 24000 , 48000 }, new int []{16000 }, new int []{1 , 2 }},
138171 {MediaFormat .MIMETYPE_AUDIO_AMR_NB , new int []{-1 }, new int []{4750 , 5150 , 5900 , 6700
139172 , 7400 , 7950 , 10200 , 12200 }, new int []{8000 }, new int []{1 }},
140173 {MediaFormat .MIMETYPE_AUDIO_AMR_WB , new int []{-1 }, new int []{6600 , 8850 , 12650 ,
141174 14250 , 15850 , 18250 , 19850 , 23050 , 23850 }, new int []{16000 }, new int []{1 }},
142175 });
143- return prepareParamList (exhaustiveArgsList );
176+ List <Object []> argsList = flattenParams (exhaustiveArgsList );
177+ return prepareParamList (argsList );
144178 }
145179
146- public EncoderTest (String encodername , String mime , int [] profiles , int [] bitrates ,
147- int samplerates [] , int channelcounts [] ) {
180+ public EncoderTest (String encodername , String mime , int profile , int bitrate ,
181+ int samplerate , int channelcount ) {
148182 mEncoderName = encodername ;
149183 mMime = mime ;
150- mProfiles = profiles ;
151- mBitrates = bitrates ;
152- mSampleRates = samplerates ;
153- mChannelCounts = channelcounts ;
184+ mProfile = profile ;
185+ mBitrate = bitrate ;
186+ mSampleRate = samplerate ;
187+ mChannelCount = channelcount ;
154188 }
155189
156190 private void setUpFormats () {
157191 mFormats = new ArrayList <MediaFormat >();
158- // TODO(b/218887182) Explore parameterizing based on the following loop params as well
159- for (int profile : mProfiles ) {
160- for (int rate : mSampleRates ) {
161- if (mMime .equals (MediaFormat .MIMETYPE_AUDIO_AAC ) && profile == 5 && rate < 22050 ) {
162- // Is this right? HE does not support sample rates < 22050Hz?
163- continue ;
164- }
165- for (int bitrate : mBitrates ) {
166- for (int channels : mChannelCounts ) {
167- MediaFormat format = new MediaFormat ();
168- format .setString (MediaFormat .KEY_MIME , mMime );
169- format .setInteger (MediaFormat .KEY_SAMPLE_RATE , rate );
170- format .setInteger (MediaFormat .KEY_CHANNEL_COUNT , channels );
171- format .setInteger (MediaFormat .KEY_AAC_PROFILE , profile );
172- format .setInteger (MediaFormat .KEY_BIT_RATE , bitrate );
173- mFormats .add (format );
174- }
175- }
192+ MediaFormat format = new MediaFormat ();
193+ format .setString (MediaFormat .KEY_MIME , mMime );
194+ format .setInteger (MediaFormat .KEY_SAMPLE_RATE , mSampleRate );
195+ format .setInteger (MediaFormat .KEY_CHANNEL_COUNT , mChannelCount );
196+ if (mProfile >= 0 ) {
197+ format .setInteger (MediaFormat .KEY_PROFILE , mProfile );
198+ if (mMime .equals (MediaFormat .MIMETYPE_AUDIO_AAC )) {
199+ format .setInteger (MediaFormat .KEY_AAC_PROFILE , mProfile );
176200 }
177201 }
202+ format .setInteger (MediaFormat .KEY_BIT_RATE , mBitrate );
203+ mFormats .add (format );
178204 }
179205
180206 @ Test
@@ -218,7 +244,7 @@ private void testEncoderWithFormats() {
218244 return ;
219245 }
220246 }
221- final int ThreadPoolCount = 3 ;
247+ final int ThreadPoolCount = 1 ;
222248 int instances = ThreadPoolCount ;
223249 MediaCodec codec = null ;
224250 try {
0 commit comments