From 18bf98ce5305439766fce8a3d474be68322655ab Mon Sep 17 00:00:00 2001 From: Karl Schults Date: Wed, 20 Dec 2023 13:56:59 -0500 Subject: [PATCH] [APT-9568] Add model support for DRM info --- .../com/scribd/armadillo/models/Models.kt | 23 +++++++++++++++++-- .../mediasource/DashMediaSourceGenerator.kt | 15 +++++++++--- .../mediasource/HlsMediaSourceGenerator.kt | 6 +++++ .../mediasource/MediaSourceGenerator.kt | 4 ++++ .../ProgressiveMediaSourceGenerator.kt | 7 +++++- RELEASE.md | 3 +++ gradle.properties | 2 +- 7 files changed, 53 insertions(+), 7 deletions(-) diff --git a/Armadillo/src/main/java/com/scribd/armadillo/models/Models.kt b/Armadillo/src/main/java/com/scribd/armadillo/models/Models.kt index 055bee9..430c4b8 100644 --- a/Armadillo/src/main/java/com/scribd/armadillo/models/Models.kt +++ b/Armadillo/src/main/java/com/scribd/armadillo/models/Models.kt @@ -2,10 +2,12 @@ package com.scribd.armadillo.models import android.os.Parcel import android.os.Parcelable +import com.google.android.exoplayer2.C import com.scribd.armadillo.Milliseconds import com.scribd.armadillo.extensions.toPrint import com.scribd.armadillo.time.milliseconds import java.io.Serializable +import java.util.UUID data class AudioPlayable(val id: Int, val title: String, @@ -23,7 +25,11 @@ data class AudioPlayable(val id: Int, /** * Additional provider-specific metadata required to access the URL (e.g. HTTP authentication headers) */ - val headers: Map = emptyMap() + val headers: Map = emptyMap(), + /** + * Additional information required to access a DRM server + */ + val drmInfo: DrmInfo? = null ) : Serializable { companion object { // Just roughing in a factory pattern in case we need to generate more complex accessors in the future. @@ -38,13 +44,14 @@ data class AudioPlayable(val id: Int, if (url != other.url) return false if (headers != other.headers) return false + if (drmInfo != other.drmInfo) return false return true } override fun hashCode(): Int { var result = url.hashCode() - result = 31 * result + headers.hashCode() + result = 31 * result + headers.hashCode() + 3 * drmInfo.hashCode() return result } @@ -131,4 +138,16 @@ data class Chapter( return arrayOfNulls(size) } } +} + +data class DrmInfo(val licenseServer: String, val drmType: DrmType, val drmHeaders: Map = emptyMap()) + +enum class DrmType { + WIDEVINE; + + internal fun toExoplayerConstant(): UUID { + return when (this) { + WIDEVINE -> C.WIDEVINE_UUID + } + } } \ No newline at end of file diff --git a/Armadillo/src/main/java/com/scribd/armadillo/playback/mediasource/DashMediaSourceGenerator.kt b/Armadillo/src/main/java/com/scribd/armadillo/playback/mediasource/DashMediaSourceGenerator.kt index be5b637..2b17704 100644 --- a/Armadillo/src/main/java/com/scribd/armadillo/playback/mediasource/DashMediaSourceGenerator.kt +++ b/Armadillo/src/main/java/com/scribd/armadillo/playback/mediasource/DashMediaSourceGenerator.kt @@ -2,6 +2,7 @@ package com.scribd.armadillo.playback.mediasource import android.content.Context import com.google.android.exoplayer2.MediaItem +import com.google.android.exoplayer2.MediaItem.DrmConfiguration import com.google.android.exoplayer2.offline.Download import com.google.android.exoplayer2.offline.DownloadHelper import com.google.android.exoplayer2.source.MediaSource @@ -24,12 +25,20 @@ internal class DashMediaSourceGenerator @Inject constructor( } } - val mediaItem = MediaItem.Builder() + val mediaItemBuilder = MediaItem.Builder() .setUri(request.url) - .build() + + if (request.drmInfo != null) { + mediaItemBuilder.setDrmConfiguration( + DrmConfiguration.Builder(request.drmInfo.drmType.toExoplayerConstant()) + .setLicenseUri(request.drmInfo.licenseServer) + .setLicenseRequestHeaders(request.drmInfo.drmHeaders) + .build() + ) + } return DashMediaSource.Factory(dataSourceFactory) - .createMediaSource(mediaItem) + .createMediaSource(mediaItemBuilder.build()) } override fun updateMediaSourceHeaders(request: AudioPlayable.MediaRequest) = mediaSourceHelper.updateMediaSourceHeaders(request) diff --git a/Armadillo/src/main/java/com/scribd/armadillo/playback/mediasource/HlsMediaSourceGenerator.kt b/Armadillo/src/main/java/com/scribd/armadillo/playback/mediasource/HlsMediaSourceGenerator.kt index a8b5ece..7d40f47 100644 --- a/Armadillo/src/main/java/com/scribd/armadillo/playback/mediasource/HlsMediaSourceGenerator.kt +++ b/Armadillo/src/main/java/com/scribd/armadillo/playback/mediasource/HlsMediaSourceGenerator.kt @@ -1,6 +1,7 @@ package com.scribd.armadillo.playback.mediasource import android.content.Context +import android.util.Log import com.google.android.exoplayer2.MediaItem import com.google.android.exoplayer2.offline.Download import com.google.android.exoplayer2.offline.DownloadHelper @@ -28,6 +29,11 @@ internal class HlsMediaSourceGenerator @Inject constructor( return DownloadHelper.createMediaSource(it.request, dataSourceFactory) } } + + if (request.drmInfo != null) { + Log.e(MediaSourceGenerator.TAG, "HLS does not currently support DRM") + } + return HlsMediaSource.Factory(dataSourceFactory) .createMediaSource(MediaItem.fromUri(request.url)) } diff --git a/Armadillo/src/main/java/com/scribd/armadillo/playback/mediasource/MediaSourceGenerator.kt b/Armadillo/src/main/java/com/scribd/armadillo/playback/mediasource/MediaSourceGenerator.kt index 6274a80..5cdaef0 100644 --- a/Armadillo/src/main/java/com/scribd/armadillo/playback/mediasource/MediaSourceGenerator.kt +++ b/Armadillo/src/main/java/com/scribd/armadillo/playback/mediasource/MediaSourceGenerator.kt @@ -7,6 +7,10 @@ import com.scribd.armadillo.models.AudioPlayable /** Creates a MediaSource for starting playback in Exoplayer when this * class is initialized. */ internal interface MediaSourceGenerator { + companion object { + const val TAG = "MediaSourceGenerator" + } + fun generateMediaSource(context: Context, request: AudioPlayable.MediaRequest): MediaSource fun updateMediaSourceHeaders(request: AudioPlayable.MediaRequest) diff --git a/Armadillo/src/main/java/com/scribd/armadillo/playback/mediasource/ProgressiveMediaSourceGenerator.kt b/Armadillo/src/main/java/com/scribd/armadillo/playback/mediasource/ProgressiveMediaSourceGenerator.kt index 1cfa594..375ad9a 100644 --- a/Armadillo/src/main/java/com/scribd/armadillo/playback/mediasource/ProgressiveMediaSourceGenerator.kt +++ b/Armadillo/src/main/java/com/scribd/armadillo/playback/mediasource/ProgressiveMediaSourceGenerator.kt @@ -1,6 +1,7 @@ package com.scribd.armadillo.playback.mediasource import android.content.Context +import android.util.Log import com.google.android.exoplayer2.MediaItem import com.google.android.exoplayer2.source.MediaSource import com.google.android.exoplayer2.source.ProgressiveMediaSource @@ -16,7 +17,11 @@ internal class ProgressiveMediaSourceGenerator @Inject constructor( private val cacheManager: CacheManager) : MediaSourceGenerator { override fun generateMediaSource(context: Context, request: AudioPlayable.MediaRequest): MediaSource = - ProgressiveMediaSource.Factory(buildDataSourceFactory(context)).createMediaSource(MediaItem.fromUri(request.url)) + ProgressiveMediaSource.Factory(buildDataSourceFactory(context)).createMediaSource(MediaItem.fromUri(request.url)).also { + if (request.drmInfo != null) { + Log.e(MediaSourceGenerator.TAG, "Progressive media does not currently support DRM") + } + } override fun updateMediaSourceHeaders(request: AudioPlayable.MediaRequest) = Unit // Doesn't use headers diff --git a/RELEASE.md b/RELEASE.md index 20be961..1265649 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,5 +1,8 @@ # Project Armadillo Release Notes +## 1.3.0 +- Adds support for DRM when playing MPEG-DASH audio + ## 1.2.0 - Adds support for MPEG-DASH audio diff --git a/gradle.properties b/gradle.properties index 67a9b1e..021cb71 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ org.gradle.jvmargs=-Xmx1536m # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true PACKAGE_NAME=com.scribd.armadillo -LIBRARY_VERSION=1.2.0 +LIBRARY_VERSION=1.3.0 EXOPLAYER_VERSION=2.17.1 RXJAVA_VERSION=2.2.4 RXANDROID_VERSION=2.0.1