Add simpler HttpDataSource constructors
PiperOrigin-RevId: 248350557
This commit is contained in:
parent
cf389268b0
commit
8edce41ff3
@ -113,7 +113,7 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||
|
||||
private final CronetEngine cronetEngine;
|
||||
private final Executor executor;
|
||||
private final Predicate<String> contentTypePredicate;
|
||||
@Nullable private final Predicate<String> contentTypePredicate;
|
||||
private final int connectTimeoutMs;
|
||||
private final int readTimeoutMs;
|
||||
private final boolean resetTimeoutOnRedirects;
|
||||
@ -146,6 +146,18 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||
|
||||
private volatile long currentConnectTimeoutMs;
|
||||
|
||||
/**
|
||||
* @param cronetEngine A CronetEngine.
|
||||
* @param executor The {@link java.util.concurrent.Executor} that will handle responses. This may
|
||||
* be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread
|
||||
* hop from Cronet's internal network thread to the response handling thread. However, to
|
||||
* avoid slowing down overall network performance, care must be taken to make sure response
|
||||
* handling is a fast operation when using a direct executor.
|
||||
*/
|
||||
public CronetDataSource(CronetEngine cronetEngine, Executor executor) {
|
||||
this(cronetEngine, executor, /* contentTypePredicate= */ null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cronetEngine A CronetEngine.
|
||||
* @param executor The {@link java.util.concurrent.Executor} that will handle responses. This may
|
||||
@ -158,7 +170,9 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||
* #open(DataSpec)}.
|
||||
*/
|
||||
public CronetDataSource(
|
||||
CronetEngine cronetEngine, Executor executor, Predicate<String> contentTypePredicate) {
|
||||
CronetEngine cronetEngine,
|
||||
Executor executor,
|
||||
@Nullable Predicate<String> contentTypePredicate) {
|
||||
this(
|
||||
cronetEngine,
|
||||
executor,
|
||||
@ -188,7 +202,7 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||
public CronetDataSource(
|
||||
CronetEngine cronetEngine,
|
||||
Executor executor,
|
||||
Predicate<String> contentTypePredicate,
|
||||
@Nullable Predicate<String> contentTypePredicate,
|
||||
int connectTimeoutMs,
|
||||
int readTimeoutMs,
|
||||
boolean resetTimeoutOnRedirects,
|
||||
@ -225,7 +239,7 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||
public CronetDataSource(
|
||||
CronetEngine cronetEngine,
|
||||
Executor executor,
|
||||
Predicate<String> contentTypePredicate,
|
||||
@Nullable Predicate<String> contentTypePredicate,
|
||||
int connectTimeoutMs,
|
||||
int readTimeoutMs,
|
||||
boolean resetTimeoutOnRedirects,
|
||||
@ -246,7 +260,7 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||
/* package */ CronetDataSource(
|
||||
CronetEngine cronetEngine,
|
||||
Executor executor,
|
||||
Predicate<String> contentTypePredicate,
|
||||
@Nullable Predicate<String> contentTypePredicate,
|
||||
int connectTimeoutMs,
|
||||
int readTimeoutMs,
|
||||
boolean resetTimeoutOnRedirects,
|
||||
|
@ -73,6 +73,15 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource {
|
||||
private long bytesSkipped;
|
||||
private long bytesRead;
|
||||
|
||||
/**
|
||||
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
||||
* by the source.
|
||||
* @param userAgent An optional User-Agent string.
|
||||
*/
|
||||
public OkHttpDataSource(Call.Factory callFactory, @Nullable String userAgent) {
|
||||
this(callFactory, userAgent, /* contentTypePredicate= */ null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
|
||||
* by the source.
|
||||
|
@ -89,6 +89,11 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
||||
private long bytesSkipped;
|
||||
private long bytesRead;
|
||||
|
||||
/** @param userAgent The User-Agent string that should be used. */
|
||||
public DefaultHttpDataSource(String userAgent) {
|
||||
this(userAgent, /* contentTypePredicate= */ null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userAgent The User-Agent string that should be used.
|
||||
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
|
||||
|
@ -27,7 +27,7 @@ import java.io.IOException;
|
||||
/** Fake {@link MediaChunk}. */
|
||||
public final class FakeMediaChunk extends MediaChunk {
|
||||
|
||||
private static final DataSource DATA_SOURCE = new DefaultHttpDataSource("TEST_AGENT", null);
|
||||
private static final DataSource DATA_SOURCE = new DefaultHttpDataSource("TEST_AGENT");
|
||||
|
||||
public FakeMediaChunk(Format trackFormat, long startTimeUs, long endTimeUs) {
|
||||
this(new DataSpec(Uri.EMPTY), trackFormat, startTimeUs, endTimeUs);
|
||||
|
Loading…
x
Reference in New Issue
Block a user