Commit 4b3cbfd6 by christosts Committed by Oliver Woodman

End to end test for WebVTT sideloaded subtitles

Enable subtitle output in the PlaybackOutput and disable the text
renderer in the MkvPlaybackTest. Add WebvttPlaybackTest to test the
output of side-loaded WebVTT subtitles.

PiperOrigin-RevId: 402526588
parent a56af3d0
......@@ -19,6 +19,7 @@ import android.content.Context;
import android.graphics.SurfaceTexture;
import android.view.Surface;
import androidx.test.core.app.ApplicationProvider;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.Player;
......@@ -29,6 +30,7 @@ import com.google.android.exoplayer2.robolectric.TestPlayerRunHelper;
import com.google.android.exoplayer2.testutil.CapturingRenderersFactory;
import com.google.android.exoplayer2.testutil.DumpFileAsserts;
import com.google.android.exoplayer2.testutil.FakeClock;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.common.collect.ImmutableList;
import org.junit.Rule;
import org.junit.Test;
......@@ -65,6 +67,19 @@ public final class MkvPlaybackTest {
new ExoPlayer.Builder(applicationContext, capturingRenderersFactory)
.setClock(new FakeClock(/* isAutoAdvancing= */ true))
.build();
// TODO(internal b/174661563): Remove the for-loop below to enable the text renderer when
// subtitle output is not flaky.
for (int textRendererIndex = 0;
textRendererIndex < player.getRendererCount();
textRendererIndex++) {
if (player.getRendererType(textRendererIndex) == C.TRACK_TYPE_TEXT) {
player.setTrackSelectionParameters(
new DefaultTrackSelector.ParametersBuilder(applicationContext)
.setRendererDisabled(textRendererIndex, /* disabled= */ true)
.build());
break;
}
}
player.setVideoSurface(new Surface(new SurfaceTexture(/* texName= */ 1)));
PlaybackOutput playbackOutput = PlaybackOutput.register(player, capturingRenderersFactory);
......
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.e2etest;
import android.content.Context;
import android.graphics.SurfaceTexture;
import android.net.Uri;
import android.view.Surface;
import androidx.test.core.app.ApplicationProvider;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.robolectric.PlaybackOutput;
import com.google.android.exoplayer2.robolectric.ShadowMediaCodecConfig;
import com.google.android.exoplayer2.robolectric.TestPlayerRunHelper;
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory;
import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.testutil.CapturingRenderersFactory;
import com.google.android.exoplayer2.testutil.DumpFileAsserts;
import com.google.android.exoplayer2.testutil.FakeClock;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.common.collect.ImmutableList;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.ParameterizedRobolectricTestRunner;
/** End-to-end tests using side-loaded WebVTT subtitles. */
@RunWith(ParameterizedRobolectricTestRunner.class)
public class WebvttPlaybackTest {
@ParameterizedRobolectricTestRunner.Parameters(name = "{0}")
public static ImmutableList<String> mediaSamples() {
return ImmutableList.of("typical");
}
@ParameterizedRobolectricTestRunner.Parameter public String inputFile;
@Rule
public ShadowMediaCodecConfig mediaCodecConfig =
ShadowMediaCodecConfig.forAllSupportedMimeTypes();
@Test
public void test() throws Exception {
Context applicationContext = ApplicationProvider.getApplicationContext();
CapturingRenderersFactory capturingRenderersFactory =
new CapturingRenderersFactory(applicationContext);
MediaSourceFactory mediaSourceFactory =
new DefaultMediaSourceFactory(applicationContext)
.experimentalUseProgressiveMediaSourceForSubtitles(true);
ExoPlayer player =
new ExoPlayer.Builder(applicationContext, capturingRenderersFactory)
.setClock(new FakeClock(/* isAutoAdvancing= */ true))
.setMediaSourceFactory(mediaSourceFactory)
.build();
player.setVideoSurface(new Surface(new SurfaceTexture(/* texName= */ 1)));
PlaybackOutput playbackOutput = PlaybackOutput.register(player, capturingRenderersFactory);
MediaItem mediaItem =
new MediaItem.Builder()
.setUri("asset:///media/mp4/preroll-5s.mp4")
.setSubtitleConfigurations(
ImmutableList.of(
new MediaItem.SubtitleConfiguration.Builder(
Uri.parse("asset:///media/webvtt/" + inputFile))
.setMimeType(MimeTypes.TEXT_VTT)
.setLanguage("en")
.setSelectionFlags(C.SELECTION_FLAG_DEFAULT)
.build()))
.build();
player.setMediaItem(mediaItem);
player.prepare();
player.play();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
player.release();
DumpFileAsserts.assertOutput(
applicationContext, playbackOutput, "playbackdumps/webvtt/" + inputFile + ".dump");
}
}
......@@ -33,6 +33,7 @@ import com.google.android.exoplayer2.testutil.CapturingRenderersFactory;
import com.google.android.exoplayer2.testutil.DumpFileAsserts;
import com.google.android.exoplayer2.testutil.FakeClock;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -47,6 +48,8 @@ public final class DashPlaybackTest {
// https://github.com/google/ExoPlayer/issues/7985
@Test
@Ignore(
"Disabled until subtitles are reliably asserted in robolectric tests [internal b/174661563].")
public void webvttInMp4() throws Exception {
Context applicationContext = ApplicationProvider.getApplicationContext();
CapturingRenderersFactory capturingRenderersFactory =
......
......@@ -17,8 +17,8 @@ package com.google.android.exoplayer2.robolectric;
import android.graphics.Bitmap;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.dvbsi.AppInfoTable;
import com.google.android.exoplayer2.metadata.emsg.EventMessage;
......@@ -55,8 +55,7 @@ public final class PlaybackOutput implements Dumper.Dumpable {
private final List<Metadata> metadatas;
private final List<List<Cue>> subtitles;
private PlaybackOutput(
SimpleExoPlayer player, CapturingRenderersFactory capturingRenderersFactory) {
private PlaybackOutput(ExoPlayer player, CapturingRenderersFactory capturingRenderersFactory) {
this.capturingRenderersFactory = capturingRenderersFactory;
metadatas = Collections.synchronizedList(new ArrayList<>());
......@@ -73,7 +72,7 @@ public final class PlaybackOutput implements Dumper.Dumpable {
@Override
public void onCues(List<Cue> cues) {
// TODO(internal b/174661563): Output subtitle data when it's not flaky.
subtitles.add(cues);
}
});
}
......@@ -85,13 +84,13 @@ public final class PlaybackOutput implements Dumper.Dumpable {
* <p>Must be called <b>before</b> playback to ensure metadata and text output is captured
* correctly.
*
* @param player The {@link SimpleExoPlayer} to capture metadata and text output from.
* @param player The {@link ExoPlayer} to capture metadata and text output from.
* @param capturingRenderersFactory The {@link CapturingRenderersFactory} to capture audio and
* video output from.
* @return A new instance that can be used to dump the playback output.
*/
public static PlaybackOutput register(
SimpleExoPlayer player, CapturingRenderersFactory capturingRenderersFactory) {
ExoPlayer player, CapturingRenderersFactory capturingRenderersFactory) {
return new PlaybackOutput(player, capturingRenderersFactory);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment