created DefaultHttpDataSourceFactory
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=131931668
This commit is contained in:
parent
ceebb4c561
commit
860c6588c0
@ -74,7 +74,7 @@ import com.google.android.exoplayer2.ui.SubtitleView;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
|
||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
|
||||
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import java.net.CookieHandler;
|
||||
@ -363,12 +363,7 @@ public class PlayerActivity extends Activity implements OnKeyListener, OnTouchLi
|
||||
return null;
|
||||
}
|
||||
HttpMediaDrmCallback drmCallback = new HttpMediaDrmCallback(licenseUrl,
|
||||
new HttpDataSource.Factory() {
|
||||
@Override
|
||||
public HttpDataSource createDataSource() {
|
||||
return new DefaultHttpDataSource(userAgent, null);
|
||||
}
|
||||
});
|
||||
buildHttpDataSourceFactory(false));
|
||||
return new StreamingDrmSessionManager<FrameworkMediaCrypto>(uuid,
|
||||
FrameworkMediaDrm.newInstance(uuid), drmCallback, null, mainHandler, eventLogger);
|
||||
}
|
||||
@ -403,8 +398,16 @@ public class PlayerActivity extends Activity implements OnKeyListener, OnTouchLi
|
||||
* DataSource factory.
|
||||
*/
|
||||
private DataSource.Factory buildDataSourceFactory(boolean useBandwidthMeter) {
|
||||
return new DefaultDataSourceFactory(this, userAgent,
|
||||
useBandwidthMeter ? BANDWIDTH_METER : null);
|
||||
return new DefaultDataSourceFactory(this, useBandwidthMeter ? BANDWIDTH_METER : null,
|
||||
buildHttpDataSourceFactory(useBandwidthMeter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a HttpDataSource factory.
|
||||
* @param useBandwidthMeter
|
||||
*/
|
||||
private HttpDataSource.Factory buildHttpDataSourceFactory(boolean useBandwidthMeter) {
|
||||
return new DefaultHttpDataSourceFactory(userAgent, useBandwidthMeter ? BANDWIDTH_METER : null);
|
||||
}
|
||||
|
||||
// ExoPlayer.EventListener implementation
|
||||
|
@ -15,20 +15,17 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2.ext.cronet;
|
||||
|
||||
import android.content.Context;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DataSource.Factory;
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSource;
|
||||
import com.google.android.exoplayer2.upstream.HttpDataSource.Factory;
|
||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
||||
import com.google.android.exoplayer2.util.Predicate;
|
||||
import java.util.concurrent.Executor;
|
||||
import org.chromium.net.CronetEngine;
|
||||
|
||||
/**
|
||||
* A {@link Factory} that produces {@link DefaultDataSource} instances that delegate to
|
||||
* {@link CronetDataSource}s for non-file/asset/content URIs.
|
||||
* A {@link Factory} that produces {@link CronetDataSource}.
|
||||
*/
|
||||
public final class DefaultCronetDataSourceFactory implements Factory {
|
||||
public final class CronetDataSourceFactory implements Factory {
|
||||
|
||||
/**
|
||||
* The default connection timeout, in milliseconds.
|
||||
@ -41,7 +38,6 @@ public final class DefaultCronetDataSourceFactory implements Factory {
|
||||
public static final int DEFAULT_READ_TIMEOUT_MILLIS =
|
||||
CronetDataSource.DEFAULT_READ_TIMEOUT_MILLIS;
|
||||
|
||||
private final Context context;
|
||||
private final CronetEngine cronetEngine;
|
||||
private final Executor executor;
|
||||
private final Predicate<String> contentTypePredicate;
|
||||
@ -50,18 +46,17 @@ public final class DefaultCronetDataSourceFactory implements Factory {
|
||||
private final int readTimeoutMs;
|
||||
private final boolean resetTimeoutOnRedirects;
|
||||
|
||||
public DefaultCronetDataSourceFactory(Context context, CronetEngine cronetEngine,
|
||||
public CronetDataSourceFactory(CronetEngine cronetEngine,
|
||||
Executor executor, Predicate<String> contentTypePredicate,
|
||||
TransferListener<? super DataSource> transferListener) {
|
||||
this(context, cronetEngine, executor, contentTypePredicate, transferListener,
|
||||
this(cronetEngine, executor, contentTypePredicate, transferListener,
|
||||
DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, false);
|
||||
}
|
||||
|
||||
public DefaultCronetDataSourceFactory(Context context, CronetEngine cronetEngine,
|
||||
public CronetDataSourceFactory(CronetEngine cronetEngine,
|
||||
Executor executor, Predicate<String> contentTypePredicate,
|
||||
TransferListener<? super DataSource> transferListener, int connectTimeoutMs,
|
||||
int readTimeoutMs, boolean resetTimeoutOnRedirects) {
|
||||
this.context = context;
|
||||
this.cronetEngine = cronetEngine;
|
||||
this.executor = executor;
|
||||
this.contentTypePredicate = contentTypePredicate;
|
||||
@ -72,10 +67,9 @@ public final class DefaultCronetDataSourceFactory implements Factory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultDataSource createDataSource() {
|
||||
DataSource cronetDataSource = new CronetDataSource(cronetEngine, executor, contentTypePredicate,
|
||||
transferListener, connectTimeoutMs, readTimeoutMs, resetTimeoutOnRedirects);
|
||||
return new DefaultDataSource(context, transferListener, cronetDataSource);
|
||||
public CronetDataSource createDataSource() {
|
||||
return new CronetDataSource(cronetEngine, executor, contentTypePredicate, transferListener,
|
||||
connectTimeoutMs, readTimeoutMs, resetTimeoutOnRedirects);
|
||||
}
|
||||
|
||||
}
|
@ -15,34 +15,29 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2.ext.okhttp;
|
||||
|
||||
import android.content.Context;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DataSource.Factory;
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSource;
|
||||
import com.google.android.exoplayer2.upstream.HttpDataSource.Factory;
|
||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
||||
import okhttp3.CacheControl;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
/**
|
||||
* A {@link Factory} that produces {@link DefaultDataSource} instances that delegate to
|
||||
* {@link OkHttpDataSource}s for non-file/asset/content URIs.
|
||||
* A {@link Factory} that produces {@link OkHttpDataSource}.
|
||||
*/
|
||||
public final class DefaultOkHttpDataSourceFactory implements Factory {
|
||||
public final class OkHttpDataSourceFactory implements Factory {
|
||||
|
||||
private final Context context;
|
||||
private final OkHttpClient client;
|
||||
private final String userAgent;
|
||||
private final TransferListener<? super DataSource> transferListener;
|
||||
private final CacheControl cacheControl;
|
||||
|
||||
public DefaultOkHttpDataSourceFactory(Context context, OkHttpClient client, String userAgent,
|
||||
public OkHttpDataSourceFactory(OkHttpClient client, String userAgent,
|
||||
TransferListener<? super DataSource> transferListener) {
|
||||
this(context, client, userAgent, transferListener, null);
|
||||
this(client, userAgent, transferListener, null);
|
||||
}
|
||||
|
||||
public DefaultOkHttpDataSourceFactory(Context context, OkHttpClient client, String userAgent,
|
||||
public OkHttpDataSourceFactory(OkHttpClient client, String userAgent,
|
||||
TransferListener<? super DataSource> transferListener, CacheControl cacheControl) {
|
||||
this.context = context.getApplicationContext();
|
||||
this.client = client;
|
||||
this.userAgent = userAgent;
|
||||
this.transferListener = transferListener;
|
||||
@ -50,10 +45,8 @@ public final class DefaultOkHttpDataSourceFactory implements Factory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultDataSource createDataSource() {
|
||||
DataSource httpDataSource = new OkHttpDataSource(client, userAgent, null, transferListener,
|
||||
cacheControl);
|
||||
return new DefaultDataSource(context, transferListener, httpDataSource);
|
||||
public OkHttpDataSource createDataSource() {
|
||||
return new OkHttpDataSource(client, userAgent, null, transferListener, cacheControl);
|
||||
}
|
||||
|
||||
}
|
@ -24,23 +24,9 @@ import com.google.android.exoplayer2.upstream.DataSource.Factory;
|
||||
*/
|
||||
public final class DefaultDataSourceFactory implements Factory {
|
||||
|
||||
/**
|
||||
* The default connection timeout, in milliseconds.
|
||||
*/
|
||||
public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS =
|
||||
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS;
|
||||
/**
|
||||
* The default read timeout, in milliseconds.
|
||||
*/
|
||||
public static final int DEFAULT_READ_TIMEOUT_MILLIS =
|
||||
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS;
|
||||
|
||||
private final Context context;
|
||||
private final String userAgent;
|
||||
private final TransferListener<? super DataSource> listener;
|
||||
private final int connectTimeoutMillis;
|
||||
private final int readTimeoutMillis;
|
||||
private final boolean allowCrossProtocolRedirects;
|
||||
private final DataSource.Factory baseDataSourceFactory;
|
||||
|
||||
/**
|
||||
* @param context A context.
|
||||
@ -57,48 +43,26 @@ public final class DefaultDataSourceFactory implements Factory {
|
||||
*/
|
||||
public DefaultDataSourceFactory(Context context, String userAgent,
|
||||
TransferListener<? super DataSource> listener) {
|
||||
this(context, userAgent, listener, false);
|
||||
this(context, listener, new DefaultHttpDataSourceFactory(userAgent, listener));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context A context.
|
||||
* @param userAgent The User-Agent string that should be used.
|
||||
* @param listener An optional listener.
|
||||
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP
|
||||
* to HTTPS and vice versa) are enabled.
|
||||
* @param baseDataSourceFactory A {@link Factory} to be used to create a base {@link DataSource}
|
||||
* for {@link DefaultDataSource}.
|
||||
* @see DefaultDataSource#DefaultDataSource(Context, TransferListener, DataSource)
|
||||
*/
|
||||
public DefaultDataSourceFactory(Context context, String userAgent,
|
||||
TransferListener<? super DataSource> listener, boolean allowCrossProtocolRedirects) {
|
||||
this(context, userAgent, listener, DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS,
|
||||
allowCrossProtocolRedirects);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context A context.
|
||||
* @param userAgent The User-Agent string that should be used.
|
||||
* @param listener An optional listener.
|
||||
* @param connectTimeoutMillis The connection timeout that should be used when requesting remote
|
||||
* data, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
|
||||
* @param readTimeoutMillis The read timeout that should be used when requesting remote data,
|
||||
* in milliseconds. A timeout of zero is interpreted as an infinite timeout.
|
||||
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP
|
||||
* to HTTPS and vice versa) are enabled.
|
||||
*/
|
||||
public DefaultDataSourceFactory(Context context, String userAgent,
|
||||
TransferListener<? super DataSource> listener, int connectTimeoutMillis,
|
||||
int readTimeoutMillis, boolean allowCrossProtocolRedirects) {
|
||||
public DefaultDataSourceFactory(Context context, TransferListener<? super DataSource> listener,
|
||||
DataSource.Factory baseDataSourceFactory) {
|
||||
this.context = context.getApplicationContext();
|
||||
this.userAgent = userAgent;
|
||||
this.listener = listener;
|
||||
this.connectTimeoutMillis = connectTimeoutMillis;
|
||||
this.readTimeoutMillis = readTimeoutMillis;
|
||||
this.allowCrossProtocolRedirects = allowCrossProtocolRedirects;
|
||||
this.baseDataSourceFactory = baseDataSourceFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultDataSource createDataSource() {
|
||||
return new DefaultDataSource(context, listener, userAgent, connectTimeoutMillis,
|
||||
readTimeoutMillis, allowCrossProtocolRedirects);
|
||||
return new DefaultDataSource(context, listener, baseDataSourceFactory.createDataSource());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer2.upstream;
|
||||
|
||||
import com.google.android.exoplayer2.upstream.HttpDataSource.Factory;
|
||||
|
||||
/** A {@link Factory} that produces {@link DefaultHttpDataSource} instances. */
|
||||
public final class DefaultHttpDataSourceFactory implements Factory {
|
||||
|
||||
private final String userAgent;
|
||||
private final TransferListener<? super DataSource> listener;
|
||||
private final int connectTimeoutMillis;
|
||||
private final int readTimeoutMillis;
|
||||
private final boolean allowCrossProtocolRedirects;
|
||||
|
||||
/**
|
||||
* Constructs a DefaultHttpDataSourceFactory. Sets {@link
|
||||
* DefaultHttpDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout, {@link
|
||||
* DefaultHttpDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables
|
||||
* cross-protocol redirects.
|
||||
*
|
||||
* @param userAgent The User-Agent string that should be used.
|
||||
*/
|
||||
public DefaultHttpDataSourceFactory(String userAgent) {
|
||||
this(userAgent, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a DefaultHttpDataSourceFactory. Sets {@link
|
||||
* DefaultHttpDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout, {@link
|
||||
* DefaultHttpDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables
|
||||
* cross-protocol redirects.
|
||||
*
|
||||
* @param userAgent The User-Agent string that should be used.
|
||||
* @param listener An optional listener.
|
||||
* @see #DefaultHttpDataSourceFactory(String, TransferListener, int, int, boolean)
|
||||
*/
|
||||
public DefaultHttpDataSourceFactory(
|
||||
String userAgent, TransferListener<? super DataSource> listener) {
|
||||
this(userAgent, listener, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
|
||||
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userAgent The User-Agent string that should be used.
|
||||
* @param listener An optional listener.
|
||||
* @param connectTimeoutMillis The connection timeout that should be used when requesting remote
|
||||
* data, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
|
||||
* @param readTimeoutMillis The read timeout that should be used when requesting remote data, in
|
||||
* milliseconds. A timeout of zero is interpreted as an infinite timeout.
|
||||
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP
|
||||
* to HTTPS and vice versa) are enabled.
|
||||
*/
|
||||
public DefaultHttpDataSourceFactory(String userAgent,
|
||||
TransferListener<? super DataSource> listener, int connectTimeoutMillis,
|
||||
int readTimeoutMillis, boolean allowCrossProtocolRedirects) {
|
||||
this.userAgent = userAgent;
|
||||
this.listener = listener;
|
||||
this.connectTimeoutMillis = connectTimeoutMillis;
|
||||
this.readTimeoutMillis = readTimeoutMillis;
|
||||
this.allowCrossProtocolRedirects = allowCrossProtocolRedirects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultHttpDataSource createDataSource() {
|
||||
return new DefaultHttpDataSource(userAgent, null, listener, connectTimeoutMillis,
|
||||
readTimeoutMillis, allowCrossProtocolRedirects);
|
||||
}
|
||||
}
|
@ -49,8 +49,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelection;
|
||||
import com.google.android.exoplayer2.upstream.BandwidthMeter;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
|
||||
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
|
||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
@ -708,12 +707,7 @@ public final class DashTest extends ActivityInstrumentationTestCase2<HostActivit
|
||||
? WIDEVINE_HW_SECURE_DECODE_CONTENT_ID : WIDEVINE_SW_CRYPTO_CONTENT_ID;
|
||||
HttpMediaDrmCallback drmCallback = new HttpMediaDrmCallback(
|
||||
WIDEVINE_LICENSE_URL + widevineContentId,
|
||||
new HttpDataSource.Factory() {
|
||||
@Override
|
||||
public HttpDataSource createDataSource() {
|
||||
return new DefaultHttpDataSource(userAgent, null);
|
||||
}
|
||||
});
|
||||
new DefaultHttpDataSourceFactory(userAgent));
|
||||
drmSessionManager = StreamingDrmSessionManager.newWidevineInstance(drmCallback, null,
|
||||
null, null);
|
||||
if (forceL3Widevine && !WIDEVINE_SECURITY_LEVEL_3.equals(securityProperty)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user