4242import androidx .test .ext .junit .rules .ActivityScenarioRule ;
4343import com .google .common .collect .ImmutableList ;
4444import com .google .common .collect .Iterables ;
45+ import com .google .testing .junit .testparameterinjector .TestParameter ;
46+ import com .google .testing .junit .testparameterinjector .TestParameterInjector ;
47+ import com .google .testing .junit .testparameterinjector .TestParameterValuesProvider ;
48+ import java .util .List ;
4549import java .util .concurrent .TimeoutException ;
4650import org .checkerframework .checker .nullness .qual .MonotonicNonNull ;
4751import org .junit .After ;
4852import org .junit .Before ;
4953import org .junit .Rule ;
5054import org .junit .Test ;
5155import org .junit .runner .RunWith ;
52- import org .junit .runners .Parameterized ;
53- import org .junit .runners .Parameterized .Parameter ;
54- import org .junit .runners .Parameterized .Parameters ;
5556
5657/** Parameterized playback tests for {@link CompositionPlayer}. */
57- @ RunWith (Parameterized .class )
58+ @ RunWith (TestParameterInjector .class )
5859public class CompositionPlayerParameterizedPlaybackTest {
5960
6061 private static final long TEST_TIMEOUT_MS = isRunningOnEmulator () ? 30_000 : 20_000 ;
@@ -203,89 +204,91 @@ public long getNextSpeedChangeTimeUs(long timeUs) {
203204 private @ MonotonicNonNull CompositionPlayer player ;
204205 private @ MonotonicNonNull PlayerTestListener playerTestListener ;
205206 private @ MonotonicNonNull SurfaceView surfaceView ;
206- @ Parameter public @ MonotonicNonNull TestConfig testConfig ;
207-
208- @ Parameters (name = "{0}" )
209- public static ImmutableList <TestConfig > params () {
210- ImmutableList .Builder <TestConfig > configs = new ImmutableList .Builder <>();
211- // Single asset.
212- configs .add (new TestConfig (new InputSequence (VIDEO_INPUT )));
213- configs .add (new TestConfig (new InputSequence (VIDEO_INPUT_SRGB )));
214- configs .add (new TestConfig (new InputSequence (IMAGE_INPUT )));
215- configs .add (new TestConfig (new InputSequence (AUDIO_INPUT )));
216-
217- // Single sequence.
218- configs .add (
219- new TestConfig (
220- new InputSequence (
221- VIDEO_INPUT , VIDEO_INPUT , VIDEO_INPUT , IMAGE_INPUT , IMAGE_INPUT , IMAGE_INPUT )));
222- configs .add (
223- new TestConfig (
224- new InputSequence (
225- IMAGE_INPUT , VIDEO_INPUT , IMAGE_INPUT , VIDEO_INPUT , IMAGE_INPUT , VIDEO_INPUT )));
226- configs .add (
227- new TestConfig (
228- new InputSequence (VIDEO_INPUT , AUDIO_INPUT , IMAGE_INPUT , AUDIO_INPUT , VIDEO_INPUT )));
229- configs .add (
230- new TestConfig (
231- new InputSequence (VIDEO_INPUT_WITHOUT_AUDIO , VIDEO_INPUT , VIDEO_INPUT_WITHOUT_AUDIO )));
232- configs .add (
233- new TestConfig (new InputSequence (VIDEO_INPUT , VIDEO_INPUT_WITHOUT_AUDIO , VIDEO_INPUT )));
234- configs .add (new TestConfig (new InputSequence (VIDEO_INPUT , AUDIO_INPUT )));
235- // TODO: b/412585977 - Enable once implicit gaps are implemented.
236- // configs.add(new TestConfig(new InputSequence(AUDIO_INPUT,
237- // VIDEO_INPUT).withForceVideoTrack()));
238- configs .add (new TestConfig (new InputSequence (VIDEO_ONLY_CLIPPED_HALF_SPEED )));
239- configs .add (new TestConfig (new InputSequence (VIDEO_ONLY_CLIPPED_TWICE_SPEED )));
240- configs .add (
241- new TestConfig (
242- new InputSequence (VIDEO_ONLY_CLIPPED_TWICE_SPEED , VIDEO_ONLY_CLIPPED_TWICE_SPEED )));
243- configs .add (
244- new TestConfig (
245- new InputSequence (VIDEO_ONLY_CLIPPED_TWICE_SPEED , VIDEO_ONLY_CLIPPED_HALF_SPEED )));
246- configs .add (
247- new TestConfig (
248- new InputSequence (VIDEO_ONLY_CLIPPED_HALF_SPEED , VIDEO_ONLY_CLIPPED_TWICE_SPEED )));
249- configs .add (
250- new TestConfig (
251- new InputSequence (VIDEO_ONLY_CLIPPED_HALF_SPEED , VIDEO_ONLY_CLIPPED_HALF_SPEED )));
252- configs .add (
253- new TestConfig (
254- new InputSequence (
255- VIDEO_INPUT , VIDEO_INPUT_SRGB , VIDEO_INPUT , IMAGE_INPUT , VIDEO_INPUT_SRGB )));
256-
257- // Multiple sequence.
258- configs .add (
259- new TestConfig (
260- new InputSequence (IMAGE_INPUT , IMAGE_INPUT , IMAGE_INPUT ),
261- new InputSequence (IMAGE_INPUT , IMAGE_INPUT , IMAGE_INPUT )));
262- // TODO: b/405966202 - Enable after propagating an EOS signal after each MediaItem.
263- // configs.add(
264- // new TestConfig(
265- // new InputSequence(VIDEO_INPUT, VIDEO_INPUT, VIDEO_INPUT),
266- // new InputSequence(VIDEO_INPUT, VIDEO_INPUT, VIDEO_INPUT)));
267- configs .add (
268- new TestConfig (
269- new InputSequence (VIDEO_INPUT , AUDIO_INPUT , VIDEO_INPUT ),
270- new InputSequence (IMAGE_INPUT )));
271- // TODO: b/418785194 - Enable once fixed.
272- // configs.add(
273- // new TestConfig(
274- // new InputSequence(AUDIO_INPUT), new InputSequence(VIDEO_INPUT)));
275- // TODO: b/421358098 - Enable once fixed.
276- // configs.add(
277- // new TestConfig(
278- // new InputSequence(VIDEO_INPUT), new InputSequence(VIDEO_INPUT, VIDEO_INPUT)));
279- configs .add (
280- new TestConfig (
281- new InputSequence (VIDEO_INPUT , VIDEO_INPUT ),
282- new InputSequence (/* isLooping= */ false , AUDIO_INPUT )));
283- // TODO: b/419479048 - Enable once looping videos are supported.
284- // configs.add(
285- // new TestConfig(
286- // new InputSequence(VIDEO_INPUT, VIDEO_INPUT),
287- // new InputSequence(VIDEO_INPUT).withIsLooping()));
288- return configs .build ();
207+
208+ private static final ImmutableList <TestConfig > singleSequenceConfigs =
209+ ImmutableList .of (
210+ new TestConfig (new InputSequence (VIDEO_INPUT )),
211+ new TestConfig (new InputSequence (VIDEO_INPUT_SRGB )),
212+ new TestConfig (new InputSequence (IMAGE_INPUT )),
213+ new TestConfig (new InputSequence (AUDIO_INPUT )),
214+ new TestConfig (
215+ new InputSequence (
216+ VIDEO_INPUT , VIDEO_INPUT , VIDEO_INPUT , IMAGE_INPUT , IMAGE_INPUT , IMAGE_INPUT )),
217+ new TestConfig (
218+ new InputSequence (
219+ IMAGE_INPUT , VIDEO_INPUT , IMAGE_INPUT , VIDEO_INPUT , IMAGE_INPUT , VIDEO_INPUT )),
220+ new TestConfig (
221+ new InputSequence (VIDEO_INPUT , AUDIO_INPUT , IMAGE_INPUT , AUDIO_INPUT , VIDEO_INPUT )),
222+ new TestConfig (
223+ new InputSequence (VIDEO_INPUT_WITHOUT_AUDIO , VIDEO_INPUT , VIDEO_INPUT_WITHOUT_AUDIO )),
224+ new TestConfig (new InputSequence (VIDEO_INPUT , VIDEO_INPUT_WITHOUT_AUDIO , VIDEO_INPUT )),
225+ new TestConfig (new InputSequence (VIDEO_INPUT , AUDIO_INPUT )),
226+ // TODO: b/412585977 - Enable once implicit gaps are implemented.
227+ // configs.add(new TestConfig(new InputSequence(AUDIO_INPUT,
228+ // VIDEO_INPUT).withForceVideoTrack()));
229+ new TestConfig (new InputSequence (VIDEO_ONLY_CLIPPED_HALF_SPEED )),
230+ new TestConfig (new InputSequence (VIDEO_ONLY_CLIPPED_TWICE_SPEED )),
231+ new TestConfig (
232+ new InputSequence (VIDEO_ONLY_CLIPPED_TWICE_SPEED , VIDEO_ONLY_CLIPPED_TWICE_SPEED )),
233+ new TestConfig (
234+ new InputSequence (VIDEO_ONLY_CLIPPED_TWICE_SPEED , VIDEO_ONLY_CLIPPED_HALF_SPEED )),
235+ new TestConfig (
236+ new InputSequence (VIDEO_ONLY_CLIPPED_HALF_SPEED , VIDEO_ONLY_CLIPPED_TWICE_SPEED )),
237+ new TestConfig (
238+ new InputSequence (VIDEO_ONLY_CLIPPED_HALF_SPEED , VIDEO_ONLY_CLIPPED_HALF_SPEED )),
239+ new TestConfig (
240+ new InputSequence (
241+ VIDEO_INPUT , VIDEO_INPUT_SRGB , VIDEO_INPUT , IMAGE_INPUT , VIDEO_INPUT_SRGB )));
242+
243+ private static final ImmutableList <TestConfig > multiSequenceImageConfigs =
244+ ImmutableList .of (
245+ new TestConfig (
246+ new InputSequence (IMAGE_INPUT , IMAGE_INPUT , IMAGE_INPUT ),
247+ new InputSequence (IMAGE_INPUT , IMAGE_INPUT , IMAGE_INPUT )));
248+
249+ // TODO: b/449957503 - Enable in FrameConsumer test.
250+ // private static final ImmutableList<TestConfig> multiSequenceVideoConfigs =
251+ // ImmutableList.of(
252+ // new TestConfig(
253+ // new InputSequence(VIDEO_INPUT, VIDEO_INPUT, VIDEO_INPUT),
254+ // new InputSequence(VIDEO_INPUT, VIDEO_INPUT, VIDEO_INPUT)));
255+
256+ private static final ImmutableList <TestConfig > multiSequenceMismatchedSequenceDurationConfigs =
257+ ImmutableList .of (
258+ new TestConfig (
259+ new InputSequence (VIDEO_INPUT , AUDIO_INPUT , VIDEO_INPUT ),
260+ new InputSequence (IMAGE_INPUT )),
261+ // TODO: b/418785194 - Enable once fixed.
262+ // new TestConfig(
263+ // new InputSequence(AUDIO_INPUT), new InputSequence(VIDEO_INPUT)),
264+ // TODO: b/421358098 - Enable once fixed.
265+ // new TestConfig(
266+ // new InputSequence(VIDEO_INPUT), new InputSequence(VIDEO_INPUT, VIDEO_INPUT)),
267+ new TestConfig (
268+ new InputSequence (VIDEO_INPUT , VIDEO_INPUT ),
269+ new InputSequence (/* isLooping= */ false , AUDIO_INPUT ))
270+ // TODO: b/419479048 - Enable once looping videos are supported.
271+ // new TestConfig(
272+ // new InputSequence(VIDEO_INPUT, VIDEO_INPUT),
273+ // new InputSequence(VIDEO_INPUT).withIsLooping()),
274+ );
275+
276+ private static class SingleInputVideoGraphConfigsProvider extends TestParameterValuesProvider {
277+ @ Override
278+ protected List <TestConfig > provideValues (TestParameterValuesProvider .Context context ) {
279+ return singleSequenceConfigs ;
280+ }
281+ }
282+
283+ private static class MultipleInputVideoGraphConfigsProvider extends TestParameterValuesProvider {
284+ @ Override
285+ protected List <TestConfig > provideValues (TestParameterValuesProvider .Context context ) {
286+ return new ImmutableList .Builder <TestConfig >()
287+ .addAll (singleSequenceConfigs )
288+ .addAll (multiSequenceImageConfigs )
289+ .addAll (multiSequenceMismatchedSequenceDurationConfigs )
290+ .build ();
291+ }
289292 }
290293
291294 @ Before
@@ -307,17 +310,16 @@ public void tearDown() {
307310 }
308311
309312 @ Test
310- public void playback_singleInputVideoGraph () throws Exception {
313+ public void playback_singleInputVideoGraph (
314+ @ TestParameter (valuesProvider = SingleInputVideoGraphConfigsProvider .class )
315+ TestConfig testConfig )
316+ throws Exception {
311317 // The MediaCodec decoder's output surface is sometimes dropping frames on emulator despite
312318 // using MediaFormat.KEY_ALLOW_FRAME_DROP.
313319 assume ()
314320 .withMessage ("Skipped on emulator due to surface dropping frames" )
315321 .that (isRunningOnEmulator ())
316322 .isFalse ();
317- assume ()
318- .withMessage ("Skipped due to input containing multiple sequences" )
319- .that (testConfig .inputSequences .size ())
320- .isEqualTo (1 );
321323 InputTimestampRecordingShaderProgram inputTimestampRecordingShaderProgram =
322324 new InputTimestampRecordingShaderProgram ();
323325 Composition composition =
@@ -338,7 +340,10 @@ public void playback_singleInputVideoGraph() throws Exception {
338340 }
339341
340342 @ Test
341- public void playback_multipleInputVideoGraph () throws Exception {
343+ public void playback_multipleInputVideoGraph (
344+ @ TestParameter (valuesProvider = MultipleInputVideoGraphConfigsProvider .class )
345+ TestConfig testConfig )
346+ throws Exception {
342347 // The MediaCodec decoder's output surface is sometimes dropping frames on emulator despite
343348 // using MediaFormat.KEY_ALLOW_FRAME_DROP.
344349 assume ()
0 commit comments