From f8311a48ede0f9b5e0bdb416b19a839454205c5a Mon Sep 17 00:00:00 2001 From: olly Date: Fri, 26 Aug 2016 08:32:51 -0700 Subject: [PATCH] Add some convenience constructors for Cronet in V2 - The need to pass a Clock is pretty much only for testing, so make the constructor that takes one package private + use the system clock for public constructors. - Add default timeout values. - Also make sure we set Content-Type in all license requests, since when using Cronet the stack requires it to be set. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=131404298 --- .../exoplayer2/drm/HttpMediaDrmCallback.java | 2 ++ .../upstream/DefaultDataSourceFactory.java | 4 ++-- .../upstream/DefaultHttpDataSource.java | 24 +++++++++---------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/drm/HttpMediaDrmCallback.java b/library/src/main/java/com/google/android/exoplayer2/drm/HttpMediaDrmCallback.java index ef8a808fbd3..6f5b1373ee3 100644 --- a/library/src/main/java/com/google/android/exoplayer2/drm/HttpMediaDrmCallback.java +++ b/library/src/main/java/com/google/android/exoplayer2/drm/HttpMediaDrmCallback.java @@ -77,6 +77,8 @@ public byte[] executeKeyRequest(UUID uuid, KeyRequest request) throws Exception private byte[] executePost(String url, byte[] data, Map requestProperties) throws IOException { HttpDataSource dataSource = dataSourceFactory.createDataSource(); + // Note: This will be overridden by a Content-Type in requestProperties, if one is set. + dataSource.setRequestProperty("Content-Type", "application/octet-stream"); if (requestProperties != null) { for (Map.Entry requestProperty : requestProperties.entrySet()) { dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue()); diff --git a/library/src/main/java/com/google/android/exoplayer2/upstream/DefaultDataSourceFactory.java b/library/src/main/java/com/google/android/exoplayer2/upstream/DefaultDataSourceFactory.java index 5e9a8e73559..2c81ea30f75 100644 --- a/library/src/main/java/com/google/android/exoplayer2/upstream/DefaultDataSourceFactory.java +++ b/library/src/main/java/com/google/android/exoplayer2/upstream/DefaultDataSourceFactory.java @@ -69,8 +69,8 @@ public DefaultDataSourceFactory(Context context, String userAgent, */ public DefaultDataSourceFactory(Context context, String userAgent, TransferListener listener, boolean allowCrossProtocolRedirects) { - this(context, userAgent, listener, DEFAULT_CONNECT_TIMEOUT_MILLIS, - DEFAULT_CONNECT_TIMEOUT_MILLIS, allowCrossProtocolRedirects); + this(context, userAgent, listener, DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, + allowCrossProtocolRedirects); } /** diff --git a/library/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java b/library/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java index efff4314007..1365311a75e 100644 --- a/library/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java +++ b/library/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java @@ -86,9 +86,9 @@ public class DefaultHttpDataSource implements HttpDataSource { /** * @param userAgent The User-Agent string that should be used. - * @param contentTypePredicate An optional {@link Predicate}. If a content type is - * rejected by the predicate then a {@link HttpDataSource.InvalidContentTypeException} is - * thrown from {@link #open(DataSpec)}. + * @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the + * predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from + * {@link #open(DataSpec)}. */ public DefaultHttpDataSource(String userAgent, Predicate contentTypePredicate) { this(userAgent, contentTypePredicate, null); @@ -96,9 +96,9 @@ public DefaultHttpDataSource(String userAgent, Predicate contentTypePred /** * @param userAgent The User-Agent string that should be used. - * @param contentTypePredicate An optional {@link Predicate}. If a content type is - * rejected by the predicate then a {@link HttpDataSource.InvalidContentTypeException} is - * thrown from {@link #open(DataSpec)}. + * @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the + * predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from + * {@link #open(DataSpec)}. * @param listener An optional listener. */ public DefaultHttpDataSource(String userAgent, Predicate contentTypePredicate, @@ -109,9 +109,9 @@ public DefaultHttpDataSource(String userAgent, Predicate contentTypePred /** * @param userAgent The User-Agent string that should be used. - * @param contentTypePredicate An optional {@link Predicate}. If a content type is - * rejected by the predicate then a {@link HttpDataSource.InvalidContentTypeException} is - * thrown from {@link #open(DataSpec)}. + * @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the + * predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from + * {@link #open(DataSpec)}. * @param listener An optional listener. * @param connectTimeoutMillis The connection timeout, in milliseconds. A timeout of zero is * interpreted as an infinite timeout. @@ -126,9 +126,9 @@ public DefaultHttpDataSource(String userAgent, Predicate contentTypePred /** * @param userAgent The User-Agent string that should be used. - * @param contentTypePredicate An optional {@link Predicate}. If a content type is - * rejected by the predicate then a {@link HttpDataSource.InvalidContentTypeException} is - * thrown from {@link #open(DataSpec)}. + * @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the + * predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from + * {@link #open(DataSpec)}. * @param listener An optional listener. * @param connectTimeoutMillis The connection timeout, in milliseconds. A timeout of zero is * interpreted as an infinite timeout. Pass {@link #DEFAULT_CONNECT_TIMEOUT_MILLIS} to use