-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APT-9577] Add DRM for downloads for offline usage : add DRM support …
…for MPEG-Dash audio playback in both online and offline mode Create new helper DrmMediaSourceHelper to generate the correct media item with DRM info depending on if the content is downloaded/being downloaded. If the content is streaming, we only need to include the general DRM info so the DRM license can be fetched from the server to decrypt the encrypted content. If the content is a download, we need to include all DRM info as well as the DRM key ID so the local DRM license can be used for decryption instead.
- Loading branch information
Showing
4 changed files
with
70 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
Armadillo/src/main/java/com/scribd/armadillo/playback/mediasource/DrmMediaSourceHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.scribd.armadillo.playback.mediasource | ||
|
||
import android.content.Context | ||
import com.google.android.exoplayer2.MediaItem | ||
import com.scribd.armadillo.encryption.SecureStorage | ||
import com.scribd.armadillo.error.DrmPlaybackException | ||
import com.scribd.armadillo.models.AudioPlayable | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
/** | ||
* This is a helper responsible for generating the correct media source for an audio request. | ||
* | ||
* This will apply the correct DRM-related information needed for content decryption (if the content is DRM-protected). | ||
* In case of a download media (the content is either downloaded or being downloaded), this includes the DRM key ID used for retrieving | ||
* the local DRM license (instead of fetching DRM license from the server). | ||
*/ | ||
internal interface DrmMediaSourceHelper { | ||
fun createMediaItem( | ||
context: Context, | ||
request: AudioPlayable.MediaRequest, | ||
isDownload: Boolean, | ||
): MediaItem | ||
} | ||
|
||
@Singleton | ||
internal class DrmMediaSourceHelperImpl @Inject constructor(private val secureStorage: SecureStorage) : DrmMediaSourceHelper { | ||
|
||
override fun createMediaItem(context: Context, request: AudioPlayable.MediaRequest, isDownload: Boolean): MediaItem = | ||
MediaItem.Builder() | ||
.setUri(request.url) | ||
.apply { | ||
// Apply DRM config if content is DRM-protected | ||
val drmConfig = request.drmInfo?.let { drmInfo -> | ||
MediaItem.DrmConfiguration.Builder(drmInfo.drmType.toExoplayerConstant()) | ||
.setLicenseUri(drmInfo.licenseServer) | ||
.setLicenseRequestHeaders(drmInfo.drmHeaders) | ||
.apply { | ||
// If the content is a download content, use the saved offline DRM key id. | ||
// This ID is needed to retrieve the local DRM license for content decryption. | ||
if (isDownload) { | ||
secureStorage.getDrmKeyId(context, request.url, drmInfo.drmType.name)?.let { drmKeyId -> | ||
setKeySetId(drmKeyId) | ||
} ?: throw DrmPlaybackException(IllegalStateException("No DRM key id saved for download content")) | ||
} | ||
} | ||
.build() | ||
} | ||
setDrmConfiguration(drmConfig) | ||
} | ||
.build() | ||
} |