Search in sources :

Example 6 with SimpleCache

use of com.google.android.exoplayer2.upstream.cache.SimpleCache in project ExoPlayer by google.

the class CacheDataSourceTest2 method buildCacheDataSource.

private static CacheDataSource buildCacheDataSource(Context context, DataSource upstreamSource, boolean useAesEncryption) throws CacheException {
    File cacheDir = context.getExternalCacheDir();
    Cache cache = new SimpleCache(new File(cacheDir, EXO_CACHE_DIR), new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    emptyCache(cache);
    // Source and cipher
    final String secretKey = "testKey:12345678";
    DataSource file = new FileDataSource();
    DataSource cacheReadDataSource = useAesEncryption ? new AesCipherDataSource(Util.getUtf8Bytes(secretKey), file) : file;
    // Sink and cipher
    CacheDataSink cacheSink = new CacheDataSink(cache, EXO_CACHE_MAX_FILESIZE);
    byte[] scratch = new byte[3897];
    DataSink cacheWriteDataSink = useAesEncryption ? new AesCipherDataSink(Util.getUtf8Bytes(secretKey), cacheSink, scratch) : cacheSink;
    return new CacheDataSource(cache, upstreamSource, cacheReadDataSource, cacheWriteDataSink, CacheDataSource.FLAG_BLOCK_ON_CACHE, // eventListener
    null);
}
Also used : AesCipherDataSink(com.google.android.exoplayer2.upstream.crypto.AesCipherDataSink) DataSink(com.google.android.exoplayer2.upstream.DataSink) FileDataSource(com.google.android.exoplayer2.upstream.FileDataSource) AesCipherDataSource(com.google.android.exoplayer2.upstream.crypto.AesCipherDataSource) DataSource(com.google.android.exoplayer2.upstream.DataSource) FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) AesCipherDataSink(com.google.android.exoplayer2.upstream.crypto.AesCipherDataSink) FileDataSource(com.google.android.exoplayer2.upstream.FileDataSource) AesCipherDataSource(com.google.android.exoplayer2.upstream.crypto.AesCipherDataSource) File(java.io.File)

Example 7 with SimpleCache

use of com.google.android.exoplayer2.upstream.cache.SimpleCache in project ExoPlayer by google.

the class CacheDataSourceTest method setUp.

@Before
public void setUp() throws Exception {
    testDataUri = Uri.parse("https://www.test.com/data");
    httpRequestHeaders = new HashMap<>();
    httpRequestHeaders.put("Test-key", "Test-val");
    unboundedDataSpec = buildDataSpec(/* unbounded= */
    true, /* key= */
    null);
    boundedDataSpec = buildDataSpec(/* unbounded= */
    false, /* key= */
    null);
    unboundedDataSpecWithKey = buildDataSpec(/* unbounded= */
    true, DATASPEC_KEY);
    boundedDataSpecWithKey = buildDataSpec(/* unbounded= */
    false, DATASPEC_KEY);
    defaultCacheKey = CacheKeyFactory.DEFAULT.buildCacheKey(unboundedDataSpec);
    customCacheKey = "customKey." + defaultCacheKey;
    cacheKeyFactory = dataSpec -> customCacheKey;
    tempFolder = Util.createTempDirectory(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
    cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    upstreamDataSource = new FakeDataSource();
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) Before(org.junit.Before)

Example 8 with SimpleCache

use of com.google.android.exoplayer2.upstream.cache.SimpleCache in project ExoPlayer by google.

the class DownloadServiceDashTest method setUp.

@Before
public void setUp() throws IOException {
    testThread = new DummyMainThread();
    context = ApplicationProvider.getApplicationContext();
    tempFolder = Util.createTempDirectory(context, "ExoPlayerTest");
    cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    Runnable pauseAction = () -> {
        if (pauseDownloadCondition != null) {
            try {
                pauseDownloadCondition.block();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    };
    fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).newData("audio_init_data").appendReadAction(pauseAction).appendReadData(TestUtil.buildTestData(10)).endData().setRandomData("audio_segment_1", 4).setRandomData("audio_segment_2", 5).setRandomData("audio_segment_3", 6).setRandomData("text_segment_1", 1).setRandomData("text_segment_2", 2).setRandomData("text_segment_3", 3);
    final DataSource.Factory fakeDataSourceFactory = new FakeDataSource.Factory().setFakeDataSet(fakeDataSet);
    fakeStreamKey1 = new StreamKey(0, 0, 0);
    fakeStreamKey2 = new StreamKey(0, 1, 0);
    testThread.runTestOnMainThread(() -> {
        DefaultDownloadIndex downloadIndex = new DefaultDownloadIndex(TestUtil.getInMemoryDatabaseProvider());
        DefaultDownloaderFactory downloaderFactory = new DefaultDownloaderFactory(new CacheDataSource.Factory().setCache(cache).setUpstreamDataSourceFactory(fakeDataSourceFactory), /* executor= */
        Runnable::run);
        final DownloadManager dashDownloadManager = new DownloadManager(ApplicationProvider.getApplicationContext(), downloadIndex, downloaderFactory);
        downloadManagerListener = new TestDownloadManagerListener(dashDownloadManager);
        dashDownloadManager.resumeDownloads();
        dashDownloadService = new DownloadService(DownloadService.FOREGROUND_NOTIFICATION_ID_NONE) {

            @Override
            protected DownloadManager getDownloadManager() {
                return dashDownloadManager;
            }

            @Override
            @Nullable
            protected Scheduler getScheduler() {
                return null;
            }

            @Override
            protected Notification getForegroundNotification(List<Download> downloads, @Requirements.RequirementFlags int notMetRequirements) {
                throw new UnsupportedOperationException();
            }
        };
        dashDownloadService.onCreate();
    });
}
Also used : Scheduler(com.google.android.exoplayer2.scheduler.Scheduler) DownloadManager(com.google.android.exoplayer2.offline.DownloadManager) DownloadService(com.google.android.exoplayer2.offline.DownloadService) Notification(android.app.Notification) SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache) FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) DefaultDownloaderFactory(com.google.android.exoplayer2.offline.DefaultDownloaderFactory) Download(com.google.android.exoplayer2.offline.Download) NoOpCacheEvictor(com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) DataSource(com.google.android.exoplayer2.upstream.DataSource) FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) DefaultDownloadIndex(com.google.android.exoplayer2.offline.DefaultDownloadIndex) DummyMainThread(com.google.android.exoplayer2.testutil.DummyMainThread) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Nullable(androidx.annotation.Nullable) TestDownloadManagerListener(com.google.android.exoplayer2.robolectric.TestDownloadManagerListener) Before(org.junit.Before)

Example 9 with SimpleCache

use of com.google.android.exoplayer2.upstream.cache.SimpleCache in project ExoPlayer by google.

the class DashDownloaderTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    tempFolder = Util.createTempDirectory(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
    cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    progressListener = new ProgressListener();
}
Also used : SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache) NoOpCacheEvictor(com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor) Before(org.junit.Before)

Example 10 with SimpleCache

use of com.google.android.exoplayer2.upstream.cache.SimpleCache in project ExoPlayer by google.

the class HlsDownloaderTest method setUp.

@Before
public void setUp() throws Exception {
    tempFolder = Util.createTempDirectory(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
    cache = new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());
    progressListener = new ProgressListener();
    fakeDataSet = new FakeDataSet().setData(MULTIVARIANT_PLAYLIST_URI, MULTIVARIANT_PLAYLIST_DATA).setData(MEDIA_PLAYLIST_1_URI, MEDIA_PLAYLIST_DATA).setRandomData(MEDIA_PLAYLIST_1_DIR + "fileSequence0.ts", 10).setRandomData(MEDIA_PLAYLIST_1_DIR + "fileSequence1.ts", 11).setRandomData(MEDIA_PLAYLIST_1_DIR + "fileSequence2.ts", 12).setData(MEDIA_PLAYLIST_2_URI, MEDIA_PLAYLIST_DATA).setRandomData(MEDIA_PLAYLIST_2_DIR + "fileSequence0.ts", 13).setRandomData(MEDIA_PLAYLIST_2_DIR + "fileSequence1.ts", 14).setRandomData(MEDIA_PLAYLIST_2_DIR + "fileSequence2.ts", 15);
}
Also used : SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache) NoOpCacheEvictor(com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) Before(org.junit.Before)

Aggregations

SimpleCache (com.google.android.exoplayer2.upstream.cache.SimpleCache)11 File (java.io.File)8 NoOpCacheEvictor (com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor)7 Before (org.junit.Before)7 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)5 DataSource (com.google.android.exoplayer2.upstream.DataSource)4 LeastRecentlyUsedCacheEvictor (com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor)4 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)3 FileDataSource (com.google.android.exoplayer2.upstream.FileDataSource)3 CacheDataSource (com.google.android.exoplayer2.upstream.cache.CacheDataSource)3 Context (android.content.Context)2 DatabaseProvider (com.google.android.exoplayer2.database.DatabaseProvider)2 DefaultExtractorsFactory (com.google.android.exoplayer2.extractor.DefaultExtractorsFactory)2 DefaultDownloadIndex (com.google.android.exoplayer2.offline.DefaultDownloadIndex)2 StreamKey (com.google.android.exoplayer2.offline.StreamKey)2 DummyMainThread (com.google.android.exoplayer2.testutil.DummyMainThread)2 DefaultHttpDataSource (com.google.android.exoplayer2.upstream.DefaultHttpDataSource)2 Cache (com.google.android.exoplayer2.upstream.cache.Cache)2 CacheDataSourceFactory (com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory)2 Notification (android.app.Notification)1