diff --git a/demos/main/src/main/java/com/google/android/exoplayer2/demo/DownloadTracker.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/DownloadTracker.java index 584dad509f..5dbea51a6e 100644 --- a/demos/main/src/main/java/com/google/android/exoplayer2/demo/DownloadTracker.java +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/DownloadTracker.java @@ -46,7 +46,7 @@ import com.google.android.exoplayer2.source.TrackGroup; import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo; import com.google.android.exoplayer2.trackselection.TrackSelectionParameters; -import com.google.android.exoplayer2.upstream.HttpDataSource; +import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.util.Util; import java.io.IOException; @@ -66,7 +66,7 @@ public class DownloadTracker { private static final String TAG = "DownloadTracker"; private final Context context; - private final HttpDataSource.Factory httpDataSourceFactory; + private final DataSource.Factory dataSourceFactory; private final CopyOnWriteArraySet listeners; private final HashMap downloads; private final DownloadIndex downloadIndex; @@ -74,11 +74,9 @@ public class DownloadTracker { @Nullable private StartDownloadDialogHelper startDownloadDialogHelper; public DownloadTracker( - Context context, - HttpDataSource.Factory httpDataSourceFactory, - DownloadManager downloadManager) { + Context context, DataSource.Factory dataSourceFactory, DownloadManager downloadManager) { this.context = context.getApplicationContext(); - this.httpDataSourceFactory = httpDataSourceFactory; + this.dataSourceFactory = dataSourceFactory; listeners = new CopyOnWriteArraySet<>(); downloads = new HashMap<>(); downloadIndex = downloadManager.getDownloadIndex(); @@ -119,8 +117,7 @@ public class DownloadTracker { startDownloadDialogHelper = new StartDownloadDialogHelper( fragmentManager, - DownloadHelper.forMediaItem( - context, mediaItem, renderersFactory, httpDataSourceFactory), + DownloadHelper.forMediaItem(context, mediaItem, renderersFactory, dataSourceFactory), mediaItem); } } @@ -218,7 +215,7 @@ public class DownloadTracker { new WidevineOfflineLicenseFetchTask( format, mediaItem.localConfiguration.drmConfiguration, - httpDataSourceFactory, + dataSourceFactory, /* dialogHelper= */ this, helper); widevineOfflineLicenseFetchTask.execute(); @@ -361,7 +358,7 @@ public class DownloadTracker { private final Format format; private final MediaItem.DrmConfiguration drmConfiguration; - private final HttpDataSource.Factory httpDataSourceFactory; + private final DataSource.Factory dataSourceFactory; private final StartDownloadDialogHelper dialogHelper; private final DownloadHelper downloadHelper; @@ -371,12 +368,12 @@ public class DownloadTracker { public WidevineOfflineLicenseFetchTask( Format format, MediaItem.DrmConfiguration drmConfiguration, - HttpDataSource.Factory httpDataSourceFactory, + DataSource.Factory dataSourceFactory, StartDownloadDialogHelper dialogHelper, DownloadHelper downloadHelper) { this.format = format; this.drmConfiguration = drmConfiguration; - this.httpDataSourceFactory = httpDataSourceFactory; + this.dataSourceFactory = dataSourceFactory; this.dialogHelper = dialogHelper; this.downloadHelper = downloadHelper; } @@ -387,7 +384,7 @@ public class DownloadTracker { OfflineLicenseHelper.newWidevineInstance( drmConfiguration.licenseUri.toString(), drmConfiguration.forceDefaultLicenseUri, - httpDataSourceFactory, + dataSourceFactory, drmConfiguration.licenseRequestHeaders, new DrmSessionEventListener.EventDispatcher()); try { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSessionManagerProvider.java b/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSessionManagerProvider.java index c56817430f..0a37d3bcb1 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSessionManagerProvider.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSessionManagerProvider.java @@ -22,8 +22,8 @@ import androidx.annotation.GuardedBy; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import com.google.android.exoplayer2.MediaItem; +import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DefaultHttpDataSource; -import com.google.android.exoplayer2.upstream.HttpDataSource; import com.google.android.exoplayer2.util.Util; import com.google.common.primitives.Ints; import java.util.Map; @@ -40,7 +40,7 @@ public final class DefaultDrmSessionManagerProvider implements DrmSessionManager @GuardedBy("lock") private @MonotonicNonNull DrmSessionManager manager; - @Nullable private HttpDataSource.Factory drmHttpDataSourceFactory; + @Nullable private DataSource.Factory drmHttpDataSourceFactory; @Nullable private String userAgent; public DefaultDrmSessionManagerProvider() { @@ -48,23 +48,21 @@ public final class DefaultDrmSessionManagerProvider implements DrmSessionManager } /** - * Sets the {@link HttpDataSource.Factory} to be used for creating {@link HttpMediaDrmCallback - * HttpMediaDrmCallbacks} which executes key and provisioning requests over HTTP. If {@code null} - * is passed the {@link DefaultHttpDataSource.Factory} is used. + * Sets the {@link DataSource.Factory} which is used to create {@link HttpMediaDrmCallback} + * instances. If {@code null} is passed a {@link DefaultHttpDataSource.Factory} is used. * - * @param drmHttpDataSourceFactory The HTTP data source factory or {@code null} to use {@link + * @param drmDataSourceFactory The data source factory or {@code null} to use {@link * DefaultHttpDataSource.Factory}. */ - public void setDrmHttpDataSourceFactory( - @Nullable HttpDataSource.Factory drmHttpDataSourceFactory) { - this.drmHttpDataSourceFactory = drmHttpDataSourceFactory; + public void setDrmHttpDataSourceFactory(@Nullable DataSource.Factory drmDataSourceFactory) { + this.drmHttpDataSourceFactory = drmDataSourceFactory; } /** * Sets the optional user agent to be used for DRM requests. * - *

In case a factory has been set by {@link - * #setDrmHttpDataSourceFactory(HttpDataSource.Factory)}, this user agent is ignored. + *

In case a factory has been set by {@link #setDrmHttpDataSourceFactory(DataSource.Factory)}, + * this user agent is ignored. * * @param userAgent The user agent to be used for DRM requests. */ @@ -92,7 +90,7 @@ public final class DefaultDrmSessionManagerProvider implements DrmSessionManager @RequiresApi(18) private DrmSessionManager createManager(MediaItem.DrmConfiguration drmConfiguration) { - HttpDataSource.Factory dataSourceFactory = + DataSource.Factory dataSourceFactory = drmHttpDataSourceFactory != null ? drmHttpDataSourceFactory : new DefaultHttpDataSource.Factory().setUserAgent(userAgent); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/drm/HttpMediaDrmCallback.java b/library/core/src/main/java/com/google/android/exoplayer2/drm/HttpMediaDrmCallback.java index d5288a1b35..4af1e6bd14 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/drm/HttpMediaDrmCallback.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/drm/HttpMediaDrmCallback.java @@ -21,9 +21,9 @@ import androidx.annotation.Nullable; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.drm.ExoMediaDrm.KeyRequest; import com.google.android.exoplayer2.drm.ExoMediaDrm.ProvisionRequest; +import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSourceInputStream; import com.google.android.exoplayer2.upstream.DataSpec; -import com.google.android.exoplayer2.upstream.HttpDataSource; import com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException; import com.google.android.exoplayer2.upstream.StatsDataSource; import com.google.android.exoplayer2.util.Assertions; @@ -35,40 +35,46 @@ import java.util.List; import java.util.Map; import java.util.UUID; -/** A {@link MediaDrmCallback} that makes requests using {@link HttpDataSource} instances. */ +/** A {@link MediaDrmCallback} that makes requests using {@link DataSource} instances. */ public final class HttpMediaDrmCallback implements MediaDrmCallback { private static final int MAX_MANUAL_REDIRECTS = 5; - private final HttpDataSource.Factory dataSourceFactory; + private final DataSource.Factory dataSourceFactory; @Nullable private final String defaultLicenseUrl; private final boolean forceDefaultLicenseUrl; private final Map keyRequestProperties; /** + * Constructs an instance. + * * @param defaultLicenseUrl The default license URL. Used for key requests that do not specify * their own license URL. May be {@code null} if it's known that all key requests will specify * their own URLs. - * @param dataSourceFactory A factory from which to obtain {@link HttpDataSource} instances. + * @param dataSourceFactory A factory from which to obtain {@link DataSource} instances. This will + * usually be an HTTP-based {@link DataSource}. */ public HttpMediaDrmCallback( - @Nullable String defaultLicenseUrl, HttpDataSource.Factory dataSourceFactory) { + @Nullable String defaultLicenseUrl, DataSource.Factory dataSourceFactory) { this(defaultLicenseUrl, /* forceDefaultLicenseUrl= */ false, dataSourceFactory); } /** + * Constructs an instance. + * * @param defaultLicenseUrl The default license URL. Used for key requests that do not specify * their own license URL, or for all key requests if {@code forceDefaultLicenseUrl} is set to * true. May be {@code null} if {@code forceDefaultLicenseUrl} is {@code false} and if it's * known that all key requests will specify their own URLs. * @param forceDefaultLicenseUrl Whether to force use of {@code defaultLicenseUrl} for key * requests that include their own license URL. - * @param dataSourceFactory A factory from which to obtain {@link HttpDataSource} instances. + * @param dataSourceFactory A factory from which to obtain {@link DataSource} instances. This will + * * usually be an HTTP-based {@link DataSource}. */ public HttpMediaDrmCallback( @Nullable String defaultLicenseUrl, boolean forceDefaultLicenseUrl, - HttpDataSource.Factory dataSourceFactory) { + DataSource.Factory dataSourceFactory) { Assertions.checkArgument(!(forceDefaultLicenseUrl && TextUtils.isEmpty(defaultLicenseUrl))); this.dataSourceFactory = dataSourceFactory; this.defaultLicenseUrl = defaultLicenseUrl; @@ -154,7 +160,7 @@ public final class HttpMediaDrmCallback implements MediaDrmCallback { } private static byte[] executePost( - HttpDataSource.Factory dataSourceFactory, + DataSource.Factory dataSourceFactory, String url, @Nullable byte[] httpBody, Map requestProperties) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/drm/OfflineLicenseHelper.java b/library/core/src/main/java/com/google/android/exoplayer2/drm/OfflineLicenseHelper.java index 200e051721..7bc885a383 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/drm/OfflineLicenseHelper.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/drm/OfflineLicenseHelper.java @@ -27,7 +27,7 @@ import com.google.android.exoplayer2.analytics.PlayerId; import com.google.android.exoplayer2.drm.DefaultDrmSessionManager.Mode; import com.google.android.exoplayer2.drm.DrmSession.DrmSessionException; import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId; -import com.google.android.exoplayer2.upstream.HttpDataSource; +import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.util.Assertions; import java.util.Map; import java.util.UUID; @@ -50,20 +50,17 @@ public final class OfflineLicenseHelper { * * @param defaultLicenseUrl The default license URL. Used for key requests that do not specify * their own license URL. - * @param httpDataSourceFactory A factory from which to obtain {@link HttpDataSource} instances. + * @param dataSourceFactory A factory from which to obtain {@link DataSource} instances. * @param eventDispatcher A {@link DrmSessionEventListener.EventDispatcher} used to distribute * DRM-related events. * @return A new instance which uses Widevine CDM. */ public static OfflineLicenseHelper newWidevineInstance( String defaultLicenseUrl, - HttpDataSource.Factory httpDataSourceFactory, + DataSource.Factory dataSourceFactory, DrmSessionEventListener.EventDispatcher eventDispatcher) { return newWidevineInstance( - defaultLicenseUrl, - /* forceDefaultLicenseUrl= */ false, - httpDataSourceFactory, - eventDispatcher); + defaultLicenseUrl, /* forceDefaultLicenseUrl= */ false, dataSourceFactory, eventDispatcher); } /** @@ -74,7 +71,7 @@ public final class OfflineLicenseHelper { * their own license URL. * @param forceDefaultLicenseUrl Whether to use {@code defaultLicenseUrl} for key requests that * include their own license URL. - * @param httpDataSourceFactory A factory from which to obtain {@link HttpDataSource} instances. + * @param dataSourceFactory A factory from which to obtain {@link DataSource} instances. * @param eventDispatcher A {@link DrmSessionEventListener.EventDispatcher} used to distribute * DRM-related events. * @return A new instance which uses Widevine CDM. @@ -82,12 +79,12 @@ public final class OfflineLicenseHelper { public static OfflineLicenseHelper newWidevineInstance( String defaultLicenseUrl, boolean forceDefaultLicenseUrl, - HttpDataSource.Factory httpDataSourceFactory, + DataSource.Factory dataSourceFactory, DrmSessionEventListener.EventDispatcher eventDispatcher) { return newWidevineInstance( defaultLicenseUrl, forceDefaultLicenseUrl, - httpDataSourceFactory, + dataSourceFactory, /* optionalKeyRequestParameters= */ null, eventDispatcher); } @@ -110,7 +107,7 @@ public final class OfflineLicenseHelper { public static OfflineLicenseHelper newWidevineInstance( String defaultLicenseUrl, boolean forceDefaultLicenseUrl, - HttpDataSource.Factory httpDataSourceFactory, + DataSource.Factory dataSourceFactory, @Nullable Map optionalKeyRequestParameters, DrmSessionEventListener.EventDispatcher eventDispatcher) { return new OfflineLicenseHelper( @@ -118,7 +115,7 @@ public final class OfflineLicenseHelper { .setKeyRequestParameters(optionalKeyRequestParameters) .build( new HttpMediaDrmCallback( - defaultLicenseUrl, forceDefaultLicenseUrl, httpDataSourceFactory)), + defaultLicenseUrl, forceDefaultLicenseUrl, dataSourceFactory)), eventDispatcher); }