Search in sources :

Example 11 with StreamKey

use of com.google.android.exoplayer2.offline.StreamKey in project ExoPlayer by google.

the class DashDownloaderTest method representationWithoutIndex.

@Test
public void representationWithoutIndex() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD_NO_INDEX).setRandomData("test_segment_1", 4);
    DashDownloader dashDownloader = getDashDownloader(fakeDataSet, new StreamKey(0, 0, 0));
    try {
        dashDownloader.download(progressListener);
        fail();
    } catch (DownloadException e) {
    // Expected.
    }
    dashDownloader.remove();
    assertCacheEmpty(cache);
}
Also used : DownloadException(com.google.android.exoplayer2.offline.DownloadException) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 12 with StreamKey

use of com.google.android.exoplayer2.offline.StreamKey in project ExoPlayer by google.

the class HlsDownloaderTest method createWithDefaultDownloaderFactory.

@Test
public void createWithDefaultDownloaderFactory() {
    CacheDataSource.Factory cacheDataSourceFactory = new CacheDataSource.Factory().setCache(Mockito.mock(Cache.class)).setUpstreamDataSourceFactory(DummyDataSource.FACTORY);
    DownloaderFactory factory = new DefaultDownloaderFactory(cacheDataSourceFactory, /* executor= */
    Runnable::run);
    Downloader downloader = factory.createDownloader(new DownloadRequest.Builder(/* id= */
    "id", Uri.parse("https://www.test.com/download")).setMimeType(MimeTypes.APPLICATION_M3U8).setStreamKeys(Collections.singletonList(new StreamKey(/* groupIndex= */
    0, /* trackIndex= */
    0))).build());
    assertThat(downloader).isInstanceOf(HlsDownloader.class);
}
Also used : CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) DefaultDownloaderFactory(com.google.android.exoplayer2.offline.DefaultDownloaderFactory) DefaultDownloaderFactory(com.google.android.exoplayer2.offline.DefaultDownloaderFactory) DownloaderFactory(com.google.android.exoplayer2.offline.DownloaderFactory) Downloader(com.google.android.exoplayer2.offline.Downloader) DefaultDownloaderFactory(com.google.android.exoplayer2.offline.DefaultDownloaderFactory) DownloaderFactory(com.google.android.exoplayer2.offline.DownloaderFactory) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 13 with StreamKey

use of com.google.android.exoplayer2.offline.StreamKey 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);
        }
    }
}
Also used : TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) ArrayList(java.util.ArrayList) Format(com.google.android.exoplayer2.Format) ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) ArrayList(java.util.ArrayList) List(java.util.List) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) StreamKey(com.google.android.exoplayer2.offline.StreamKey)

Example 14 with StreamKey

use of com.google.android.exoplayer2.offline.StreamKey in project ExoPlayer by google.

the class DefaultDownloadIndexTest method downloadIndex_upgradesFromVersion2.

@Test
public void downloadIndex_upgradesFromVersion2() throws IOException {
    Context context = ApplicationProvider.getApplicationContext();
    File databaseFile = context.getDatabasePath(StandaloneDatabaseProvider.DATABASE_NAME);
    try (FileOutputStream output = new FileOutputStream(databaseFile)) {
        output.write(TestUtil.getByteArray(context, "media/offline/exoplayer_internal_v2.db"));
    }
    Download dashDownload = createDownload(/* uri= */
    "http://www.test.com/manifest.mpd", /* mimeType= */
    MimeTypes.APPLICATION_MPD, ImmutableList.of(), /* customCacheKey= */
    null);
    Download hlsDownload = createDownload(/* uri= */
    "http://www.test.com/manifest.m3u8", /* mimeType= */
    MimeTypes.APPLICATION_M3U8, ImmutableList.of(), /* customCacheKey= */
    null);
    Download ssDownload = createDownload(/* uri= */
    "http://www.test.com/video.ism/manifest", /* mimeType= */
    MimeTypes.APPLICATION_SS, Arrays.asList(new StreamKey(0, 0), new StreamKey(1, 1)), /* customCacheKey= */
    null);
    Download progressiveDownload = createDownload(/* uri= */
    "http://www.test.com/video.mp4", /* mimeType= */
    MimeTypes.VIDEO_UNKNOWN, ImmutableList.of(), /* customCacheKey= */
    "customCacheKey");
    databaseProvider = new StandaloneDatabaseProvider(context);
    downloadIndex = new DefaultDownloadIndex(databaseProvider);
    assertEqual(downloadIndex.getDownload("http://www.test.com/manifest.mpd"), dashDownload);
    assertEqual(downloadIndex.getDownload("http://www.test.com/manifest.m3u8"), hlsDownload);
    assertEqual(downloadIndex.getDownload("http://www.test.com/video.ism/manifest"), ssDownload);
    assertEqual(downloadIndex.getDownload("http://www.test.com/video.mp4"), progressiveDownload);
}
Also used : Context(android.content.Context) FileOutputStream(java.io.FileOutputStream) StandaloneDatabaseProvider(com.google.android.exoplayer2.database.StandaloneDatabaseProvider) File(java.io.File) Test(org.junit.Test)

Example 15 with StreamKey

use of com.google.android.exoplayer2.offline.StreamKey in project ExoPlayer by google.

the class DefaultDownloadIndexTest method addAndGetDownload_existingId_returnsUpdatedDownload.

@Test
public void addAndGetDownload_existingId_returnsUpdatedDownload() throws DatabaseIOException {
    String id = "id";
    DownloadBuilder downloadBuilder = new DownloadBuilder(id);
    downloadIndex.putDownload(downloadBuilder.build());
    Download download = downloadBuilder.setUri("different uri").setMimeType(MimeTypes.APPLICATION_MP4).setCacheKey("different cacheKey").setState(Download.STATE_FAILED).setPercentDownloaded(50).setBytesDownloaded(200).setContentLength(400).setFailureReason(FAILURE_REASON_UNKNOWN).setStopReason(0x12345678).setStartTimeMs(10).setUpdateTimeMs(20).setStreamKeys(new StreamKey(/* periodIndex= */
    0, /* groupIndex= */
    1, /* trackIndex= */
    2), new StreamKey(/* periodIndex= */
    3, /* groupIndex= */
    4, /* trackIndex= */
    5)).setCustomMetadata(new byte[] { 0, 1, 2, 3, 7, 8, 9, 10 }).setKeySetId(new byte[] { 0, 1, 2, 3 }).build();
    downloadIndex.putDownload(download);
    Download readDownload = downloadIndex.getDownload(id);
    assertThat(readDownload).isNotNull();
    assertEqual(readDownload, download);
}
Also used : DownloadBuilder(com.google.android.exoplayer2.testutil.DownloadBuilder) Test(org.junit.Test)

Aggregations

StreamKey (com.google.android.exoplayer2.offline.StreamKey)27 Test (org.junit.Test)18 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)11 ArrayList (java.util.ArrayList)10 CacheDataSource (com.google.android.exoplayer2.upstream.cache.CacheDataSource)5 DefaultDownloaderFactory (com.google.android.exoplayer2.offline.DefaultDownloaderFactory)4 RequestSet (com.google.android.exoplayer2.testutil.CacheAsserts.RequestSet)4 ExoTrackSelection (com.google.android.exoplayer2.trackselection.ExoTrackSelection)4 Downloader (com.google.android.exoplayer2.offline.Downloader)3 DownloaderFactory (com.google.android.exoplayer2.offline.DownloaderFactory)3 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)3 Context (android.content.Context)2 Format (com.google.android.exoplayer2.Format)2 DefaultDownloadIndex (com.google.android.exoplayer2.offline.DefaultDownloadIndex)2 DownloadRequest (com.google.android.exoplayer2.offline.DownloadRequest)2 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)2 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)2 AdaptationSet (com.google.android.exoplayer2.source.dash.manifest.AdaptationSet)2 SsTestUtils.createSsManifest (com.google.android.exoplayer2.source.smoothstreaming.SsTestUtils.createSsManifest)2 DummyMainThread (com.google.android.exoplayer2.testutil.DummyMainThread)2