Search in sources :

Example 1 with AesCipherDataSource

use of androidx.media3.datasource.AesCipherDataSource in project media by androidx.

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 : DataSink(androidx.media3.datasource.DataSink) AesCipherDataSink(androidx.media3.datasource.AesCipherDataSink) FileDataSource(androidx.media3.datasource.FileDataSource) DataSource(androidx.media3.datasource.DataSource) FakeDataSource(androidx.media3.test.utils.FakeDataSource) AesCipherDataSource(androidx.media3.datasource.AesCipherDataSource) AesCipherDataSink(androidx.media3.datasource.AesCipherDataSink) FileDataSource(androidx.media3.datasource.FileDataSource) AesCipherDataSource(androidx.media3.datasource.AesCipherDataSource) File(java.io.File)

Aggregations

AesCipherDataSink (androidx.media3.datasource.AesCipherDataSink)1 AesCipherDataSource (androidx.media3.datasource.AesCipherDataSource)1 DataSink (androidx.media3.datasource.DataSink)1 DataSource (androidx.media3.datasource.DataSource)1 FileDataSource (androidx.media3.datasource.FileDataSource)1 FakeDataSource (androidx.media3.test.utils.FakeDataSource)1 File (java.io.File)1