use of com.google.android.exoplayer2.testutil.MediaPeriodAsserts.FilterableManifestMediaPeriodFactory in project ExoPlayer by google.
the class HlsMediaPeriodTest method getSteamKeys_isCompatibleWithHlsMultivariantPlaylistFilter.
@Test
public void getSteamKeys_isCompatibleWithHlsMultivariantPlaylistFilter() {
HlsMultivariantPlaylist testMultivariantPlaylist = createMultivariantPlaylist(/* variants= */
Arrays.asList(createAudioOnlyVariant(/* peakBitrate= */
10000), createMuxedVideoAudioVariant(/* peakBitrate= */
200000), createAudioOnlyVariant(/* peakBitrate= */
300000), createMuxedVideoAudioVariant(/* peakBitrate= */
400000), createMuxedVideoAudioVariant(/* peakBitrate= */
600000)), /* audios= */
Arrays.asList(createAudioRendition(/* language= */
"spa"), createAudioRendition(/* language= */
"ger"), createAudioRendition(/* language= */
"tur")), /* subtitles= */
Arrays.asList(createSubtitleRendition(/* language= */
"spa"), createSubtitleRendition(/* language= */
"ger"), createSubtitleRendition(/* language= */
"tur")), /* muxedAudioFormat= */
createAudioFormat("eng"), /* muxedCaptionFormats= */
Arrays.asList(createSubtitleFormat("eng"), createSubtitleFormat("gsw")));
FilterableManifestMediaPeriodFactory<HlsPlaylist> mediaPeriodFactory = (playlist, periodIndex) -> {
HlsDataSourceFactory mockDataSourceFactory = mock(HlsDataSourceFactory.class);
when(mockDataSourceFactory.createDataSource(anyInt())).thenReturn(mock(DataSource.class));
HlsPlaylistTracker mockPlaylistTracker = mock(HlsPlaylistTracker.class);
when(mockPlaylistTracker.getMultivariantPlaylist()).thenReturn((HlsMultivariantPlaylist) playlist);
MediaPeriodId mediaPeriodId = new MediaPeriodId(/* periodUid= */
new Object());
return new HlsMediaPeriod(mock(HlsExtractorFactory.class), mockPlaylistTracker, mockDataSourceFactory, mock(TransferListener.class), mock(DrmSessionManager.class), new DrmSessionEventListener.EventDispatcher().withParameters(/* windowIndex= */
0, mediaPeriodId), mock(LoadErrorHandlingPolicy.class), new MediaSourceEventListener.EventDispatcher().withParameters(/* windowIndex= */
0, mediaPeriodId, /* mediaTimeOffsetMs= */
0), mock(Allocator.class), mock(CompositeSequenceableLoaderFactory.class), /* allowChunklessPreparation= */
true, HlsMediaSource.METADATA_TYPE_ID3, /* useSessionKeys= */
false, PlayerId.UNSET);
};
MediaPeriodAsserts.assertGetStreamKeysAndManifestFilterIntegration(mediaPeriodFactory, testMultivariantPlaylist);
}
use of com.google.android.exoplayer2.testutil.MediaPeriodAsserts.FilterableManifestMediaPeriodFactory in project ExoPlayer by google.
the class MediaPeriodAsserts method assertGetStreamKeysAndManifestFilterIntegration.
/**
* Asserts that the values returns by {@link MediaPeriod#getStreamKeys(List)} are compatible with
* a {@link FilterableManifest} using these stream keys.
*
* @param mediaPeriodFactory A factory to create a {@link MediaPeriod} based on a manifest.
* @param manifest The manifest which is to be tested.
* @param periodIndex The index of period in the manifest.
* @param ignoredMimeType Optional mime type whose existence in the filtered track groups is not
* asserted.
*/
public static <T extends FilterableManifest<T>> void assertGetStreamKeysAndManifestFilterIntegration(FilterableManifestMediaPeriodFactory<T> mediaPeriodFactory, T manifest, int periodIndex, @Nullable String ignoredMimeType) {
MediaPeriod mediaPeriod = mediaPeriodFactory.createMediaPeriod(manifest, periodIndex);
TrackGroupArray trackGroupArray = prepareAndGetTrackGroups(mediaPeriod);
// Create test vector of query test selections:
// - One selection with one track per group, two tracks or all tracks.
// - Two selections with tracks from multiple groups, or tracks from a single group.
// - Multiple selections with tracks from all groups.
List<List<ExoTrackSelection>> testSelections = new ArrayList<>();
for (int i = 0; i < trackGroupArray.length; i++) {
TrackGroup trackGroup = trackGroupArray.get(i);
for (int j = 0; j < trackGroup.length; j++) {
testSelections.add(Collections.singletonList(new TestTrackSelection(trackGroup, j)));
}
if (trackGroup.length > 1) {
testSelections.add(Collections.singletonList(new TestTrackSelection(trackGroup, 0, 1)));
testSelections.add(Arrays.asList(new ExoTrackSelection[] { new TestTrackSelection(trackGroup, 0), new TestTrackSelection(trackGroup, 1) }));
}
if (trackGroup.length > 2) {
int[] allTracks = new int[trackGroup.length];
for (int j = 0; j < trackGroup.length; j++) {
allTracks[j] = j;
}
testSelections.add(Collections.singletonList(new TestTrackSelection(trackGroup, allTracks)));
}
}
if (trackGroupArray.length > 1) {
for (int i = 0; i < trackGroupArray.length - 1; i++) {
for (int j = i + 1; j < trackGroupArray.length; j++) {
testSelections.add(Arrays.asList(new ExoTrackSelection[] { new TestTrackSelection(trackGroupArray.get(i), 0), new TestTrackSelection(trackGroupArray.get(j), 0) }));
}
}
}
if (trackGroupArray.length > 2) {
List<ExoTrackSelection> selectionsFromAllGroups = new ArrayList<>();
for (int i = 0; i < trackGroupArray.length; i++) {
selectionsFromAllGroups.add(new TestTrackSelection(trackGroupArray.get(i), 0));
}
testSelections.add(selectionsFromAllGroups);
}
// contain at least all requested formats.
for (List<ExoTrackSelection> testSelection : testSelections) {
List<StreamKey> streamKeys = mediaPeriod.getStreamKeys(testSelection);
if (streamKeys.isEmpty()) {
// Manifests won't be filtered if stream key is empty.
continue;
}
T filteredManifest = manifest.copy(streamKeys);
// The filtered manifest should only have one period left.
MediaPeriod filteredMediaPeriod = mediaPeriodFactory.createMediaPeriod(filteredManifest, /* periodIndex= */
0);
TrackGroupArray filteredTrackGroupArray = prepareAndGetTrackGroups(filteredMediaPeriod);
for (ExoTrackSelection trackSelection : testSelection) {
if (ignoredMimeType != null && ignoredMimeType.equals(trackSelection.getFormat(0).sampleMimeType)) {
continue;
}
Format[] expectedFormats = new Format[trackSelection.length()];
for (int k = 0; k < trackSelection.length(); k++) {
expectedFormats[k] = trackSelection.getFormat(k);
}
assertOneTrackGroupContainsFormats(filteredTrackGroupArray, expectedFormats);
}
}
}
use of com.google.android.exoplayer2.testutil.MediaPeriodAsserts.FilterableManifestMediaPeriodFactory in project ExoPlayer by google.
the class SsMediaPeriodTest method getSteamKeys_isCompatibleWithSsManifestFilter.
@Test
public void getSteamKeys_isCompatibleWithSsManifestFilter() {
SsManifest testManifest = createSsManifest(createStreamElement(/* name= */
"video", C.TRACK_TYPE_VIDEO, createVideoFormat(/* bitrate= */
200000), createVideoFormat(/* bitrate= */
400000), createVideoFormat(/* bitrate= */
800000)), createStreamElement(/* name= */
"audio", C.TRACK_TYPE_AUDIO, createAudioFormat(/* bitrate= */
48000), createAudioFormat(/* bitrate= */
96000)), createStreamElement(/* name= */
"text", C.TRACK_TYPE_TEXT, createTextFormat(/* language= */
"eng")));
FilterableManifestMediaPeriodFactory<SsManifest> mediaPeriodFactory = (manifest, periodIndex) -> {
MediaPeriodId mediaPeriodId = new MediaPeriodId(/* periodUid= */
new Object());
return new SsMediaPeriod(manifest, mock(SsChunkSource.Factory.class), mock(TransferListener.class), mock(CompositeSequenceableLoaderFactory.class), mock(DrmSessionManager.class), new DrmSessionEventListener.EventDispatcher().withParameters(/* windowIndex= */
0, mediaPeriodId), mock(LoadErrorHandlingPolicy.class), new MediaSourceEventListener.EventDispatcher().withParameters(/* windowIndex= */
0, mediaPeriodId, /* mediaTimeOffsetMs= */
0), mock(LoaderErrorThrower.class), mock(Allocator.class));
};
MediaPeriodAsserts.assertGetStreamKeysAndManifestFilterIntegration(mediaPeriodFactory, testManifest);
}
Aggregations