Commit 103c3b63 by eguven Committed by Oliver Woodman

Add DashDownloader helper class to download dash streams

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=151456161
parent 2f9e082f
...@@ -541,10 +541,19 @@ public final class C { ...@@ -541,10 +541,19 @@ public final class C {
/** /**
* Priority for media playback. * Priority for media playback.
*
* <p>Larger values indicate higher priorities.
*/ */
public static final int PRIORITY_PLAYBACK = 0; public static final int PRIORITY_PLAYBACK = 0;
/** /**
* Priority for media downloading.
*
* <p>Larger values indicate higher priorities.
*/
public static final int PRIORITY_DOWNLOAD = PRIORITY_PLAYBACK - 1000;
/**
* Converts a time in microseconds to the corresponding time in milliseconds, preserving * Converts a time in microseconds to the corresponding time in milliseconds, preserving
* {@link #TIME_UNSET} values. * {@link #TIME_UNSET} values.
* *
......
...@@ -109,6 +109,15 @@ public final class CacheDataSource implements DataSource { ...@@ -109,6 +109,15 @@ public final class CacheDataSource implements DataSource {
private long totalCachedBytesRead; private long totalCachedBytesRead;
/** /**
* Generates a cache key out of the given {@link Uri}.
*
* @param uri Uri of a content which the requested key is for.
*/
public static String generateKey(Uri uri) {
return uri.toString();
}
/**
* Constructs an instance with default {@link DataSource} and {@link DataSink} instances for * Constructs an instance with default {@link DataSource} and {@link DataSink} instances for
* reading and writing the cache and with {@link #DEFAULT_MAX_CACHE_FILE_SIZE}. * reading and writing the cache and with {@link #DEFAULT_MAX_CACHE_FILE_SIZE}.
*/ */
...@@ -171,7 +180,7 @@ public final class CacheDataSource implements DataSource { ...@@ -171,7 +180,7 @@ public final class CacheDataSource implements DataSource {
try { try {
uri = dataSpec.uri; uri = dataSpec.uri;
flags = dataSpec.flags; flags = dataSpec.flags;
key = dataSpec.key != null ? dataSpec.key : uri.toString(); key = dataSpec.key != null ? dataSpec.key : generateKey(dataSpec.uri);
readPosition = dataSpec.position; readPosition = dataSpec.position;
currentRequestIgnoresCache = (ignoreCacheOnError && seenCacheError) currentRequestIgnoresCache = (ignoreCacheOnError && seenCacheError)
|| (dataSpec.length == C.LENGTH_UNSET && ignoreCacheForUnsetLengthRequests); || (dataSpec.length == C.LENGTH_UNSET && ignoreCacheForUnsetLengthRequests);
......
...@@ -54,7 +54,7 @@ public final class PriorityTaskManager { ...@@ -54,7 +54,7 @@ public final class PriorityTaskManager {
/** /**
* Register a new task. The task must call {@link #remove(int)} when done. * Register a new task. The task must call {@link #remove(int)} when done.
* *
* @param priority The priority of the task. * @param priority The priority of the task. Larger values indicate higher priorities.
*/ */
public void add(int priority) { public void add(int priority) {
synchronized (lock) { synchronized (lock) {
......
...@@ -48,14 +48,14 @@ public final class DashUtil { ...@@ -48,14 +48,14 @@ public final class DashUtil {
* Loads a DASH manifest. * Loads a DASH manifest.
* *
* @param dataSource The {@link HttpDataSource} from which the manifest should be read. * @param dataSource The {@link HttpDataSource} from which the manifest should be read.
* @param manifestUriString The URI of the manifest to be read. * @param manifestUri The URI of the manifest to be read.
* @return An instance of {@link DashManifest}. * @return An instance of {@link DashManifest}.
* @throws IOException Thrown when there is an error while loading. * @throws IOException Thrown when there is an error while loading.
*/ */
public static DashManifest loadManifest(DataSource dataSource, String manifestUriString) public static DashManifest loadManifest(DataSource dataSource, String manifestUri)
throws IOException { throws IOException {
DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, DataSourceInputStream inputStream = new DataSourceInputStream(dataSource,
new DataSpec(Uri.parse(manifestUriString), DataSpec.FLAG_ALLOW_CACHING_UNKNOWN_LENGTH)); new DataSpec(Uri.parse(manifestUri), DataSpec.FLAG_ALLOW_CACHING_UNKNOWN_LENGTH));
try { try {
inputStream.open(); inputStream.open();
DashManifestParser parser = new DashManifestParser(); DashManifestParser parser = new DashManifestParser();
......
...@@ -22,7 +22,7 @@ import com.google.android.exoplayer2.source.dash.manifest.RangedUri; ...@@ -22,7 +22,7 @@ import com.google.android.exoplayer2.source.dash.manifest.RangedUri;
* An implementation of {@link DashSegmentIndex} that wraps a {@link ChunkIndex} parsed from a * An implementation of {@link DashSegmentIndex} that wraps a {@link ChunkIndex} parsed from a
* media stream. * media stream.
*/ */
/* package */ final class DashWrappingSegmentIndex implements DashSegmentIndex { public final class DashWrappingSegmentIndex implements DashSegmentIndex {
private final ChunkIndex chunkIndex; private final ChunkIndex chunkIndex;
......
...@@ -28,9 +28,9 @@ import com.google.android.exoplayer2.util.Util; ...@@ -28,9 +28,9 @@ import com.google.android.exoplayer2.util.Util;
/** /**
* Tests DASH playbacks using {@link ExoPlayer}. * Tests DASH playbacks using {@link ExoPlayer}.
*/ */
public final class DashTest extends ActivityInstrumentationTestCase2<HostActivity> { public final class DashStreamingTest extends ActivityInstrumentationTestCase2<HostActivity> {
private static final String TAG = "DashTest"; private static final String TAG = "DashStreamingTest";
private static final ActionSchedule SEEKING_SCHEDULE = new ActionSchedule.Builder(TAG) private static final ActionSchedule SEEKING_SCHEDULE = new ActionSchedule.Builder(TAG)
.delay(10000).seek(15000) .delay(10000).seek(15000)
...@@ -72,7 +72,7 @@ public final class DashTest extends ActivityInstrumentationTestCase2<HostActivit ...@@ -72,7 +72,7 @@ public final class DashTest extends ActivityInstrumentationTestCase2<HostActivit
private DashTestRunner testRunner; private DashTestRunner testRunner;
public DashTest() { public DashStreamingTest() {
super(HostActivity.class); super(HostActivity.class);
} }
......
...@@ -18,7 +18,7 @@ package com.google.android.exoplayer2.playbacktests.gts; ...@@ -18,7 +18,7 @@ package com.google.android.exoplayer2.playbacktests.gts;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
/** /**
* Test data for {@link DashTest} and {@link DashWidevineOfflineTest). * Test data for DASH tests.
*/ */
public final class DashTestData { public final class DashTestData {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment