use of com.google.android.exoplayer2.upstream.cache.Cache in project ExoPlayer by google.
the class CacheDataSourceTest method testUnsatisfiableRange.
public void testUnsatisfiableRange() throws Exception {
// Bounded request but the content length is unknown. This forces all data to be cached but not
// the length
assertCacheAndRead(false, true);
// Now do an unbounded request. This will read all of the data from cache and then try to read
// more from upstream which will cause to a 416 so CDS will store the length.
CacheDataSource cacheDataSource = createCacheDataSource(true, true);
assertReadDataContentLength(cacheDataSource, true, true);
// If the user try to access off range then it should throw an IOException
try {
cacheDataSource = createCacheDataSource(false, false);
cacheDataSource.open(new DataSpec(Uri.EMPTY, TEST_DATA.length, 5, KEY_1));
fail();
} catch (IOException e) {
// success
}
}
use of com.google.android.exoplayer2.upstream.cache.Cache in project ExoPlayer by google.
the class DemoUtil method getDownloadCache.
private static synchronized Cache getDownloadCache(Context context) {
if (downloadCache == null) {
File downloadContentDirectory = new File(getDownloadDirectory(context), DOWNLOAD_CONTENT_DIRECTORY);
downloadCache = new SimpleCache(downloadContentDirectory, new NoOpCacheEvictor(), getDatabaseProvider(context));
}
return downloadCache;
}
use of com.google.android.exoplayer2.upstream.cache.Cache in project ExoPlayer by google.
the class DefaultDrmSessionManagerProviderTest method create_reusesCachedInstanceWherePossible.
@Test
public void create_reusesCachedInstanceWherePossible() {
MediaItem mediaItem1 = new MediaItem.Builder().setUri("https://example.test/content-1").setDrmConfiguration(new MediaItem.DrmConfiguration.Builder(C.WIDEVINE_UUID).build()).build();
// Same DRM info as item1, but different URL to check it doesn't prevent re-using a manager.
MediaItem mediaItem2 = new MediaItem.Builder().setUri("https://example.test/content-2").setDrmConfiguration(new MediaItem.DrmConfiguration.Builder(C.WIDEVINE_UUID).build()).build();
// Different DRM info to 1 and 2, needs a different manager instance.
MediaItem mediaItem3 = new MediaItem.Builder().setUri("https://example.test/content-3").setDrmConfiguration(new MediaItem.DrmConfiguration.Builder(C.WIDEVINE_UUID).setLicenseUri("https://example.test/license").build()).build();
DefaultDrmSessionManagerProvider provider = new DefaultDrmSessionManagerProvider();
DrmSessionManager drmSessionManager1 = provider.get(mediaItem1);
DrmSessionManager drmSessionManager2 = provider.get(mediaItem2);
DrmSessionManager drmSessionManager3 = provider.get(mediaItem3);
// Get a manager for the first item again - expect it to be a different instance to last time
// since we only cache one.
DrmSessionManager drmSessionManager4 = provider.get(mediaItem1);
assertThat(drmSessionManager1).isSameInstanceAs(drmSessionManager2);
assertThat(drmSessionManager1).isNotSameInstanceAs(drmSessionManager3);
assertThat(drmSessionManager1).isNotSameInstanceAs(drmSessionManager4);
}
use of com.google.android.exoplayer2.upstream.cache.Cache 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);
}
use of com.google.android.exoplayer2.upstream.cache.Cache 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();
}
Aggregations