Commit a076924c by tonihei Committed by Oliver Woodman

Simplify using DataSource factories without a TransferListener.

Setting the transfer listener on the data source factories is only needed for debug
purposes, logging and for custom bandwidth metering which doesn't use the
player-provided bandwidth meter. As such, it is not compulsary and it should be easy
to set up the data source factory without a transfer listener.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=204926083
parent 59b18a52
......@@ -39,11 +39,33 @@ public final class OkHttpDataSourceFactory extends BaseFactory {
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
* by the sources created by the factory.
* @param userAgent An optional User-Agent string.
*/
public OkHttpDataSourceFactory(@NonNull Call.Factory callFactory, @Nullable String userAgent) {
this(callFactory, userAgent, /* listener= */ null, /* cacheControl= */ null);
}
/**
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
* by the sources created by the factory.
* @param userAgent An optional User-Agent string.
* @param cacheControl An optional {@link CacheControl} for setting the Cache-Control header.
*/
public OkHttpDataSourceFactory(
@NonNull Call.Factory callFactory,
@Nullable String userAgent,
@Nullable CacheControl cacheControl) {
this(callFactory, userAgent, /* listener= */ null, cacheControl);
}
/**
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
* by the sources created by the factory.
* @param userAgent An optional User-Agent string.
* @param listener An optional listener.
*/
public OkHttpDataSourceFactory(@NonNull Call.Factory callFactory, @Nullable String userAgent,
@Nullable TransferListener<? super DataSource> listener) {
this(callFactory, userAgent, listener, null);
this(callFactory, userAgent, listener, /* cacheControl= */ null);
}
/**
......@@ -68,5 +90,4 @@ public final class OkHttpDataSourceFactory extends BaseFactory {
return new OkHttpDataSource(callFactory, userAgent, null, listener, cacheControl,
defaultRequestProperties);
}
}
......@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.upstream;
import android.content.Context;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.upstream.DataSource.Factory;
/**
......@@ -25,7 +26,7 @@ import com.google.android.exoplayer2.upstream.DataSource.Factory;
public final class DefaultDataSourceFactory implements Factory {
private final Context context;
private final TransferListener<? super DataSource> listener;
private final @Nullable TransferListener<? super DataSource> listener;
private final DataSource.Factory baseDataSourceFactory;
/**
......@@ -33,7 +34,7 @@ public final class DefaultDataSourceFactory implements Factory {
* @param userAgent The User-Agent string that should be used.
*/
public DefaultDataSourceFactory(Context context, String userAgent) {
this(context, userAgent, null);
this(context, userAgent, /* listener= */ null);
}
/**
......@@ -41,19 +42,31 @@ public final class DefaultDataSourceFactory implements Factory {
* @param userAgent The User-Agent string that should be used.
* @param listener An optional listener.
*/
public DefaultDataSourceFactory(Context context, String userAgent,
TransferListener<? super DataSource> listener) {
public DefaultDataSourceFactory(
Context context, String userAgent, @Nullable TransferListener<? super DataSource> listener) {
this(context, listener, new DefaultHttpDataSourceFactory(userAgent, listener));
}
/**
* @param context A context.
* @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, DataSource.Factory baseDataSourceFactory) {
this(context, /* listener= */ null, baseDataSourceFactory);
}
/**
* @param context A context.
* @param listener An optional listener.
* @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, TransferListener<? super DataSource> listener,
public DefaultDataSourceFactory(
Context context,
@Nullable TransferListener<? super DataSource> listener,
DataSource.Factory baseDataSourceFactory) {
this.context = context.getApplicationContext();
this.listener = listener;
......@@ -64,5 +77,4 @@ public final class DefaultDataSourceFactory implements Factory {
public DefaultDataSource createDataSource() {
return new DefaultDataSource(context, listener, baseDataSourceFactory.createDataSource());
}
}
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.upstream;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.upstream.HttpDataSource.BaseFactory;
import com.google.android.exoplayer2.upstream.HttpDataSource.Factory;
......@@ -22,7 +23,7 @@ import com.google.android.exoplayer2.upstream.HttpDataSource.Factory;
public final class DefaultHttpDataSourceFactory extends BaseFactory {
private final String userAgent;
private final TransferListener<? super DataSource> listener;
private final @Nullable TransferListener<? super DataSource> listener;
private final int connectTimeoutMillis;
private final int readTimeoutMillis;
private final boolean allowCrossProtocolRedirects;
......@@ -50,13 +51,35 @@ public final class DefaultHttpDataSourceFactory extends BaseFactory {
* @see #DefaultHttpDataSourceFactory(String, TransferListener, int, int, boolean)
*/
public DefaultHttpDataSourceFactory(
String userAgent, TransferListener<? super DataSource> listener) {
String userAgent, @Nullable 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 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,
int connectTimeoutMillis,
int readTimeoutMillis,
boolean allowCrossProtocolRedirects) {
this(
userAgent,
/* listener= */ null,
connectTimeoutMillis,
readTimeoutMillis,
allowCrossProtocolRedirects);
}
/**
* @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.
......@@ -65,9 +88,12 @@ public final class DefaultHttpDataSourceFactory extends BaseFactory {
* @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) {
public DefaultHttpDataSourceFactory(
String userAgent,
@Nullable TransferListener<? super DataSource> listener,
int connectTimeoutMillis,
int readTimeoutMillis,
boolean allowCrossProtocolRedirects) {
this.userAgent = userAgent;
this.listener = listener;
this.connectTimeoutMillis = connectTimeoutMillis;
......@@ -81,5 +107,4 @@ public final class DefaultHttpDataSourceFactory extends BaseFactory {
return new DefaultHttpDataSource(userAgent, null, listener, connectTimeoutMillis,
readTimeoutMillis, allowCrossProtocolRedirects, defaultRequestProperties);
}
}
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