|
| 1 | +/* |
| 2 | + * Copyright 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 | +package androidx.media3.exoplayer.e2etest; |
| 17 | + |
| 18 | +import static androidx.media3.test.utils.robolectric.TestPlayerRunHelper.play; |
| 19 | +import static androidx.media3.test.utils.robolectric.TestPlayerRunHelper.run; |
| 20 | +import static com.google.common.truth.Truth.assertThat; |
| 21 | + |
| 22 | +import android.content.Context; |
| 23 | +import android.graphics.SurfaceTexture; |
| 24 | +import android.net.Uri; |
| 25 | +import android.view.Surface; |
| 26 | +import androidx.media3.common.C; |
| 27 | +import androidx.media3.common.MediaItem; |
| 28 | +import androidx.media3.common.MimeTypes; |
| 29 | +import androidx.media3.common.Player; |
| 30 | +import androidx.media3.common.text.CueGroup; |
| 31 | +import androidx.media3.common.util.Clock; |
| 32 | +import androidx.media3.common.util.Util; |
| 33 | +import androidx.media3.exoplayer.DefaultLoadControl; |
| 34 | +import androidx.media3.exoplayer.DefaultRenderersFactory; |
| 35 | +import androidx.media3.exoplayer.ExoPlaybackException; |
| 36 | +import androidx.media3.exoplayer.ExoPlayer; |
| 37 | +import androidx.media3.exoplayer.RenderersFactory; |
| 38 | +import androidx.media3.exoplayer.source.DefaultMediaSourceFactory; |
| 39 | +import androidx.media3.exoplayer.source.MediaSource; |
| 40 | +import androidx.media3.exoplayer.text.TextRenderer; |
| 41 | +import androidx.media3.test.utils.CapturingRenderersFactory; |
| 42 | +import androidx.media3.test.utils.DumpFileAsserts; |
| 43 | +import androidx.media3.test.utils.FakeClock; |
| 44 | +import androidx.media3.test.utils.robolectric.PlaybackOutput; |
| 45 | +import androidx.media3.test.utils.robolectric.RobolectricUtil; |
| 46 | +import androidx.media3.test.utils.robolectric.ShadowMediaCodecConfig; |
| 47 | +import androidx.media3.test.utils.robolectric.TestPlayerRunHelper; |
| 48 | +import androidx.test.core.app.ApplicationProvider; |
| 49 | +import com.google.common.collect.ImmutableList; |
| 50 | +import java.util.concurrent.TimeoutException; |
| 51 | +import java.util.concurrent.atomic.AtomicBoolean; |
| 52 | +import org.junit.Rule; |
| 53 | +import org.junit.Test; |
| 54 | +import org.junit.runner.RunWith; |
| 55 | +import org.robolectric.ParameterizedRobolectricTestRunner; |
| 56 | +import org.robolectric.annotation.Config; |
| 57 | + |
| 58 | +/** End-to-end tests using side-loaded SSA subtitles. */ |
| 59 | +@Config(sdk = 30) // TODO: b/382017156 - Remove this when the tests pass on API 31+. |
| 60 | +@RunWith(ParameterizedRobolectricTestRunner.class) |
| 61 | +public class SsaPlaybackTest { |
| 62 | + @ParameterizedRobolectricTestRunner.Parameters(name = "{0}") |
| 63 | + public static ImmutableList<String> mediaSamples() { |
| 64 | + return ImmutableList.of("overlapping_cues_different_layers"); |
| 65 | + } |
| 66 | + |
| 67 | + @ParameterizedRobolectricTestRunner.Parameter public String inputFile; |
| 68 | + |
| 69 | + @Rule |
| 70 | + public ShadowMediaCodecConfig mediaCodecConfig = |
| 71 | + ShadowMediaCodecConfig.forAllSupportedMimeTypes(); |
| 72 | + |
| 73 | + @Test |
| 74 | + public void test() throws Exception { |
| 75 | + Context applicationContext = ApplicationProvider.getApplicationContext(); |
| 76 | + CapturingRenderersFactory capturingRenderersFactory = |
| 77 | + new CapturingRenderersFactory(applicationContext); |
| 78 | + ExoPlayer player = |
| 79 | + new ExoPlayer.Builder(applicationContext, capturingRenderersFactory) |
| 80 | + .setClock(new FakeClock(/* isAutoAdvancing= */ true)) |
| 81 | + .build(); |
| 82 | + Surface surface = new Surface(new SurfaceTexture(/* texName= */ 1)); |
| 83 | + player.setVideoSurface(surface); |
| 84 | + PlaybackOutput playbackOutput = PlaybackOutput.register(player, capturingRenderersFactory); |
| 85 | + MediaItem mediaItem = |
| 86 | + new MediaItem.Builder() |
| 87 | + .setUri("asset:///media/mp4/preroll-5s.mp4") |
| 88 | + .setSubtitleConfigurations( |
| 89 | + ImmutableList.of( |
| 90 | + new MediaItem.SubtitleConfiguration.Builder( |
| 91 | + Uri.parse("asset:///media/ssa/" + inputFile)) |
| 92 | + .setMimeType(MimeTypes.TEXT_SSA) |
| 93 | + .setLanguage("en") |
| 94 | + .setSelectionFlags(C.SELECTION_FLAG_DEFAULT) |
| 95 | + .build())) |
| 96 | + .build(); |
| 97 | + |
| 98 | + player.setMediaItem(mediaItem); |
| 99 | + player.prepare(); |
| 100 | + run(player).untilState(Player.STATE_READY); |
| 101 | + run(player).untilFullyBuffered(); |
| 102 | + player.play(); |
| 103 | + run(player).untilState(Player.STATE_ENDED); |
| 104 | + player.release(); |
| 105 | + surface.release(); |
| 106 | + |
| 107 | + DumpFileAsserts.assertOutput( |
| 108 | + applicationContext, playbackOutput, "playbackdumps/ssa/" + inputFile + ".dump"); |
| 109 | + } |
| 110 | +} |
0 commit comments