Search in sources :

Example 21 with CacheDataSource

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

the class CacheWriterTest method cacheUnknownLength.

@Test
public void cacheUnknownLength() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().newData("test_data").setSimulateUnknownLength(true).appendReadData(TestUtil.buildTestData(100)).endData();
    FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
    DataSpec dataSpec = new DataSpec(Uri.parse("test_data"));
    CachingCounters counters = new CachingCounters();
    CacheWriter cacheWriter = new CacheWriter(new CacheDataSource(cache, dataSource), dataSpec, /* temporaryBuffer= */
    null, counters);
    cacheWriter.cache();
    counters.assertValues(0, 100, 100);
    assertCachedData(cache, fakeDataSet);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) Test(org.junit.Test)

Example 22 with CacheDataSource

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

the class CacheWriterTest method cacheSetOffsetAndLength.

@Test
public void cacheSetOffsetAndLength() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().setRandomData("test_data", 100);
    FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
    Uri testUri = Uri.parse("test_data");
    DataSpec dataSpec = new DataSpec(testUri, /* position= */
    10, /* length= */
    20);
    CachingCounters counters = new CachingCounters();
    CacheWriter cacheWriter = new CacheWriter(new CacheDataSource(cache, dataSource), dataSpec, /* temporaryBuffer= */
    null, counters);
    cacheWriter.cache();
    counters.assertValues(0, 20, 20);
    counters.reset();
    cacheWriter = new CacheWriter(new CacheDataSource(cache, dataSource), new DataSpec(testUri), /* temporaryBuffer= */
    null, counters);
    cacheWriter.cache();
    counters.assertValues(20, 80, 100);
    assertCachedData(cache, fakeDataSet);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) Uri(android.net.Uri) Test(org.junit.Test)

Example 23 with CacheDataSource

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

the class CacheWriterTest method cache.

@Test
public void cache() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().setRandomData("test_data", 100);
    FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
    CachingCounters counters = new CachingCounters();
    CacheWriter cacheWriter = new CacheWriter(new CacheDataSource(cache, dataSource), new DataSpec(Uri.parse("test_data")), /* temporaryBuffer= */
    null, counters);
    cacheWriter.cache();
    counters.assertValues(0, 100, 100);
    assertCachedData(cache, fakeDataSet);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) Test(org.junit.Test)

Example 24 with CacheDataSource

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

the class CacheWriterTest method cachePolling.

@Test
public void cachePolling() throws Exception {
    final CachingCounters counters = new CachingCounters();
    FakeDataSet fakeDataSet = new FakeDataSet().newData("test_data").appendReadData(TestUtil.buildTestData(100)).appendReadAction(() -> counters.assertValues(0, 100, 300)).appendReadData(TestUtil.buildTestData(100)).appendReadAction(() -> counters.assertValues(0, 200, 300)).appendReadData(TestUtil.buildTestData(100)).endData();
    FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
    CacheWriter cacheWriter = new CacheWriter(new CacheDataSource(cache, dataSource), new DataSpec(Uri.parse("test_data")), /* temporaryBuffer= */
    null, counters);
    cacheWriter.cache();
    counters.assertValues(0, 300, 300);
    assertCachedData(cache, fakeDataSet);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) Test(org.junit.Test)

Example 25 with CacheDataSource

use of com.google.android.exoplayer2.upstream.cache.CacheDataSource in project NewPipe by TeamNewPipe.

the class CacheFactory method createDataSource.

@Override
public DataSource createDataSource() {
    Log.d(TAG, "initExoPlayerCache: cacheDir = " + cacheDir.getAbsolutePath());
    final DefaultDataSource dataSource = dataSourceFactory.createDataSource();
    final FileDataSource fileSource = new FileDataSource();
    final CacheDataSink dataSink = new CacheDataSink(cache, maxFileSize);
    return new CacheDataSource(cache, dataSource, fileSource, dataSink, CACHE_FLAGS, null);
}
Also used : CacheDataSink(com.google.android.exoplayer2.upstream.cache.CacheDataSink) DefaultDataSource(com.google.android.exoplayer2.upstream.DefaultDataSource) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) FileDataSource(com.google.android.exoplayer2.upstream.FileDataSource)

Aggregations

FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)17 Test (org.junit.Test)15 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)13 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)7 FileDataSource (com.google.android.exoplayer2.upstream.FileDataSource)7 CacheDataSource (com.google.android.exoplayer2.upstream.cache.CacheDataSource)5 IOException (java.io.IOException)5 Uri (android.net.Uri)3 File (java.io.File)3 FakeData (com.google.android.exoplayer2.testutil.FakeDataSet.FakeData)2 DataSource (com.google.android.exoplayer2.upstream.DataSource)2 CacheDataSink (com.google.android.exoplayer2.upstream.cache.CacheDataSink)2 PriorityTooLowException (com.google.android.exoplayer2.util.PriorityTaskManager.PriorityTooLowException)2 ExecutionException (java.util.concurrent.ExecutionException)2 Nullable (androidx.annotation.Nullable)1 FailOnCloseDataSink (com.google.android.exoplayer2.testutil.FailOnCloseDataSink)1 DataSink (com.google.android.exoplayer2.upstream.DataSink)1 DefaultDataSource (com.google.android.exoplayer2.upstream.DefaultDataSource)1 DummyDataSource (com.google.android.exoplayer2.upstream.DummyDataSource)1 LeastRecentlyUsedCacheEvictor (com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor)1