Skip to content

Commit

Permalink
Drop support for playback of partially encrypted content
Browse files Browse the repository at this point in the history
  • Loading branch information
stoyicker committed Aug 21, 2024
1 parent bcdf084 commit 90620b7
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal class ExoPlayerPlaybackEngineLooperTest {
TrueTimeWrapper(),
mock(),
mock(),
mock(),
null,
Base64Codec(),
Dispatchers.IO,
CoroutineScope(Dispatchers.IO),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class PlaybackEngineModuleRoot(
trueTimeWrapper: TrueTimeWrapper,
playbackPrivilegeProvider: PlaybackPrivilegeProvider,
offlineCacheProvider: OfflineCacheProvider?,
encryption: Encryption?,
offlineSecretKey: ByteArray?,
base64Codec: Base64Codec,
coroutineDispatcher: CoroutineDispatcher,
coroutineScope: CoroutineScope,
Expand All @@ -72,7 +72,7 @@ class PlaybackEngineModuleRoot(
trueTimeWrapper,
playbackPrivilegeProvider,
offlineCacheProvider,
encryption,
offlineSecretKey,
base64Codec,
coroutineDispatcher,
coroutineScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ package com.tidal.sdk.player.playbackengine.datasource
import androidx.media3.datasource.cache.Cache
import androidx.media3.datasource.cache.CacheDataSource
import androidx.media3.datasource.cache.CacheKeyFactory
import com.tidal.sdk.player.playbackengine.Encryption
import com.tidal.sdk.player.playbackengine.offline.crypto.CacheKeyAesCipherDataSourceFactory

internal class CacheKeyAesCipherDataSourceFactoryFactory(
private val cacheDataSourceFactory: CacheDataSource.Factory,
private val cacheKeyFactory: CacheKeyFactory,
private val encryption: Encryption?,
private val offlineSecretKey: ByteArray?,
) {

fun create(cache: Cache) = CacheKeyAesCipherDataSourceFactory(
cacheKeyFactory,
encryption!!.secretKey,
offlineSecretKey,
cacheDataSourceFactory.setCache(cache)
.setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.tidal.sdk.player.common.UUIDWrapper
import com.tidal.sdk.player.commonandroid.Base64Codec
import com.tidal.sdk.player.commonandroid.TrueTimeWrapper
import com.tidal.sdk.player.events.EventReporter
import com.tidal.sdk.player.playbackengine.Encryption
import com.tidal.sdk.player.playbackengine.PlaybackEngine
import com.tidal.sdk.player.playbackengine.model.AssetTimeoutConfig
import com.tidal.sdk.player.playbackengine.model.BufferConfiguration
Expand Down Expand Up @@ -58,7 +57,7 @@ interface ExoPlayerPlaybackEngineComponent {
@BindsInstance trueTimeWrapper: TrueTimeWrapper,
@BindsInstance playbackPrivilegeProvider: PlaybackPrivilegeProvider,
@BindsInstance offlineCacheProvider: OfflineCacheProvider?,
@BindsInstance encryption: Encryption?,
@BindsInstance offlineSecretKey: ByteArray?,
@BindsInstance base64Codec: Base64Codec,
@BindsInstance coroutineDispatcher: CoroutineDispatcher,
@BindsInstance coroutineScope: CoroutineScope,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ internal class TidalMediaSourceCreator(
private val playerProgressiveMediaSourceFactory: PlayerProgressiveMediaSourceFactory,
private val playerDashMediaSourceFactory: PlayerDashMediaSourceFactory,
private val playerHlsMediaSourceFactory: PlayerHlsMediaSourceFactory,
@Suppress("MaxLineLength") private val playerDecryptedHeaderProgressiveOfflineMediaSourceFactory: PlayerDecryptedHeaderProgressiveOfflineMediaSourceFactory, // ktlint-disable max-line-length parameter-wrapping
@Suppress("MaxLineLength") private val playerProgressiveOfflineMediaSourceFactory: PlayerProgressiveOfflineMediaSourceFactory, // ktlint-disable max-line-length parameter-wrapping
private val playerDashOfflineMediaSourceFactory: PlayerDashOfflineMediaSourceFactory,
private val drmSessionManagerFactory: DrmSessionManagerFactory,
Expand All @@ -26,35 +25,23 @@ internal class TidalMediaSourceCreator(
override fun invoke(mediaItem: MediaItem, playbackInfo: PlaybackInfo): MediaSource {
return if (playbackInfo is PlaybackInfo.Offline) {
when (playbackInfo.manifestMimeType) {
ManifestMimeType.BTS -> {
if (playbackInfo.partiallyEncrypted) {
playerDecryptedHeaderProgressiveOfflineMediaSourceFactory.create(
mediaItem,
playbackInfo.manifest,
playbackInfo.productId,
)
} else {
playerProgressiveOfflineMediaSourceFactory.create(
mediaItem,
playbackInfo.manifest,
playbackInfo.storage!!,
)
}
}
ManifestMimeType.BTS -> playerProgressiveOfflineMediaSourceFactory.create(
mediaItem,
playbackInfo.manifest,
playbackInfo.storage!!,
)

ManifestMimeType.DASH -> {
playerDashOfflineMediaSourceFactory.create(
mediaItem,
playbackInfo.manifest,
playbackInfo.offlineLicense!!,
playbackInfo.storage!!,
drmSessionManagerProviderFactory.create(
drmSessionManagerFactory.createDrmSessionManagerForOfflinePlay(
playbackInfo,
),
ManifestMimeType.DASH -> playerDashOfflineMediaSourceFactory.create(
mediaItem,
playbackInfo.manifest,
playbackInfo.offlineLicense!!,
playbackInfo.storage!!,
drmSessionManagerProviderFactory.create(
drmSessionManagerFactory.createDrmSessionManagerForOfflinePlay(
playbackInfo,
),
)
}
),
)

else -> throw IllegalArgumentException(
"No valid manifestMimeType for offline playback: " +
Expand Down Expand Up @@ -99,11 +86,4 @@ internal class TidalMediaSourceCreator(
}
}
}

private val PlaybackInfo.Offline.productId: String
get() = when (this) {
is PlaybackInfo.Offline.Track -> track.trackId.toString()
is PlaybackInfo.Offline.Video -> video.videoId.toString()
else -> throw IllegalArgumentException("Not a valid delegate for PlaybackInfo.Offline")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import androidx.media3.datasource.cache.CacheKeyFactory
*/
class CacheKeyAesCipherDataSourceFactory(
private val cacheKeyFactory: CacheKeyFactory,
private val secretKey: ByteArray,
private val secretKey: ByteArray?,
private val upstream: DataSource.Factory,
) : DataSource.Factory {

override fun createDataSource(): DataSource {
val aesCipherDataSource = AesCipherDataSource(secretKey, upstream.createDataSource())
val aesCipherDataSource = AesCipherDataSource(secretKey!!, upstream.createDataSource())
return CacheKeyAesCipherDataSource(cacheKeyFactory, aesCipherDataSource)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import com.tidal.sdk.player.common.UUIDWrapper
import com.tidal.sdk.player.commonandroid.Base64Codec
import com.tidal.sdk.player.commonandroid.TrueTimeWrapper
import com.tidal.sdk.player.events.EventReporter
import com.tidal.sdk.player.playbackengine.Encryption
import com.tidal.sdk.player.playbackengine.PlayerLoadErrorHandlingPolicy
import com.tidal.sdk.player.playbackengine.StreamingApiRepository
import com.tidal.sdk.player.playbackengine.TidalExtractorsFactory
Expand All @@ -49,7 +48,6 @@ import com.tidal.sdk.player.playbackengine.mediasource.MediaSourcerer
import com.tidal.sdk.player.playbackengine.mediasource.PlaybackInfoMediaSourceFactory
import com.tidal.sdk.player.playbackengine.mediasource.PlayerDashMediaSourceFactory
import com.tidal.sdk.player.playbackengine.mediasource.PlayerDashOfflineMediaSourceFactory
import com.tidal.sdk.player.playbackengine.mediasource.PlayerDecryptedHeaderProgressiveOfflineMediaSourceFactory
import com.tidal.sdk.player.playbackengine.mediasource.PlayerHlsMediaSourceFactory
import com.tidal.sdk.player.playbackengine.mediasource.PlayerProgressiveMediaSourceFactory
import com.tidal.sdk.player.playbackengine.mediasource.PlayerProgressiveOfflineMediaSourceFactory
Expand Down Expand Up @@ -239,11 +237,11 @@ internal object MediaSourcererModule {
@Named("cacheDataSourceFactoryForOfflinePlay")
cacheDataSourceFactory: CacheDataSource.Factory,
cacheKeyFactory: CacheKeyFactory,
encryption: Encryption?,
offlineSecretKey: ByteArray?,
) = CacheKeyAesCipherDataSourceFactoryFactory(
cacheDataSourceFactory,
cacheKeyFactory,
encryption,
offlineSecretKey,
)

@Provides
Expand Down Expand Up @@ -295,20 +293,6 @@ internal object MediaSourcererModule {
upstream: FileDataSource.Factory,
) = DecryptedHeaderFileDataSourceFactoryFactory(upstream)

@Provides
@Reusable
fun playerDecryptedHeaderProgressiveOfflineMediaSourceFactory(
progressiveMediaSourceFactoryFactory: ProgressiveMediaSourceFactoryFactory,
decryptedHeaderFileDataSourceFactoryFactory: DecryptedHeaderFileDataSourceFactoryFactory,
encryption: Encryption?,
btsManifestFactory: DefaultBtsManifestFactory,
) = PlayerDecryptedHeaderProgressiveOfflineMediaSourceFactory(
progressiveMediaSourceFactoryFactory,
decryptedHeaderFileDataSourceFactoryFactory,
encryption,
btsManifestFactory,
)

@Provides
@Reusable
fun dashManifestParser(): ParsingLoadable.Parser<DashManifest> = DashManifestParser()
Expand Down Expand Up @@ -440,7 +424,6 @@ internal object MediaSourcererModule {
playerProgressiveMediaSourceFactory: PlayerProgressiveMediaSourceFactory,
playerDashMediaSourceFactory: PlayerDashMediaSourceFactory,
playerHlsMediaSourceFactory: PlayerHlsMediaSourceFactory,
@Suppress("MaxLineLength") playerDecryptedHeaderProgressiveOfflineMediaSourceFactory: PlayerDecryptedHeaderProgressiveOfflineMediaSourceFactory, // ktlint-disable max-line-length parameter-wrapping
playerProgressiveOfflineMediaSourceFactory: PlayerProgressiveOfflineMediaSourceFactory,
playerDashOfflineMediaSourceFactory: PlayerDashOfflineMediaSourceFactory,
drmSessionManagerFactory: DrmSessionManagerFactory,
Expand All @@ -449,7 +432,6 @@ internal object MediaSourcererModule {
playerProgressiveMediaSourceFactory,
playerDashMediaSourceFactory,
playerHlsMediaSourceFactory,
playerDecryptedHeaderProgressiveOfflineMediaSourceFactory,
playerProgressiveOfflineMediaSourceFactory,
playerDashOfflineMediaSourceFactory,
drmSessionManagerFactory,
Expand Down

This file was deleted.

Loading

0 comments on commit 90620b7

Please sign in to comment.