Skip to content

Commit

Permalink
Adding immersiveaudio param to playbackinfo endpoint
Browse files Browse the repository at this point in the history
Added AudioModeRepository to contain the immersive audio setting which will be used when making playbackinfo requests.
  • Loading branch information
ziad-halabi9 committed May 31, 2024
1 parent dd07b3f commit 6796e71
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ internal class SingleHandlerPlaybackEngineHandlerPostOrThrowTest {
override val events = MutableSharedFlow<Event>()
override var streamingWifiAudioQuality = AudioQuality.HIGH
override var streamingCellularAudioQuality = AudioQuality.LOW
override var immersiveAudio = true
override var loudnessNormalizationMode = LoudnessNormalizationMode.ALBUM
override var loudnessNormalizationPreAmp = LOUDNESS_NORMALIZATION_PRE_AMP_DEFAULT
override var videoSurfaceView: AspectRatioAdjustingSurfaceView? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ internal class SingleHandlerPlaybackEngineThreadingTest {
set(_) = assignThreadAndReleaseLock()
override var streamingCellularAudioQuality = AudioQuality.LOW
set(_) = assignThreadAndReleaseLock()
override var immersiveAudio = true
set(_) = assignThreadAndReleaseLock()
override var loudnessNormalizationMode = LoudnessNormalizationMode.ALBUM
set(_) = assignThreadAndReleaseLock()
override var loudnessNormalizationPreAmp = LOUDNESS_NORMALIZATION_PRE_AMP_DEFAULT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.tidal.sdk.player.events.model.UCPlaybackSession
import com.tidal.sdk.player.events.model.UCPlaybackStatistics
import com.tidal.sdk.player.events.model.VideoPlaybackSession
import com.tidal.sdk.player.events.model.VideoPlaybackStatistics
import com.tidal.sdk.player.playbackengine.audiomode.AudioModeRepository
import com.tidal.sdk.player.playbackengine.dj.DjSessionManager
import com.tidal.sdk.player.playbackengine.dj.DjSessionStatus
import com.tidal.sdk.player.playbackengine.error.ErrorHandler
Expand Down Expand Up @@ -82,6 +83,7 @@ internal class ExoPlayerPlaybackEngine(
private val streamingPrivileges: StreamingPrivileges,
private val playbackContextFactory: PlaybackContextFactory,
private val audioQualityRepository: AudioQualityRepository,
private val audioModeRepository: AudioModeRepository,
private val volumeHelper: VolumeHelper,
private val trueTimeWrapper: TrueTimeWrapper,
private val eventReporter: EventReporter,
Expand Down Expand Up @@ -187,6 +189,12 @@ internal class ExoPlayerPlaybackEngine(
updatePlayerVolume()
}

override var immersiveAudio: Boolean
get() = audioModeRepository.immersiveAudio
set(value) {
audioModeRepository.immersiveAudio = value
}

private var extendedExoPlayer by Delegates.observable(
extendedExoPlayerFactory.create(this, this),
) { _, oldValue, newValue ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,9 @@ interface Configuration {
* Get or set [loudnessNormalizationPreAmp] as [Int] to use when playing.
*/
var loudnessNormalizationPreAmp: Int

/**
* Get or set [immersiveAudio] as [Boolean] to use when playing.
*/
var immersiveAudio: Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ internal class SingleHandlerPlaybackEngine(
get() = delegate.loudnessNormalizationPreAmp
set(value) = postOrThrow { delegate.loudnessNormalizationPreAmp = value }

override var immersiveAudio: Boolean
get() = delegate.immersiveAudio
set(value) = postOrThrow { delegate.immersiveAudio = value }

override var videoSurfaceView: AspectRatioAdjustingSurfaceView?
set(value) = postOrThrow { delegate.videoSurfaceView = value }
get() = delegate.videoSurfaceView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.tidal.sdk.player.events.EventReporter
import com.tidal.sdk.player.events.model.DrmLicenseFetch
import com.tidal.sdk.player.events.model.EndReason
import com.tidal.sdk.player.events.model.PlaybackInfoFetch
import com.tidal.sdk.player.playbackengine.audiomode.AudioModeRepository
import com.tidal.sdk.player.playbackengine.drm.MediaDrmCallbackExceptionFactory
import com.tidal.sdk.player.playbackengine.error.ErrorCodeFactory
import com.tidal.sdk.player.playbackengine.error.ErrorHandler
Expand Down Expand Up @@ -42,6 +43,7 @@ internal class StreamingApiRepository(
private val streamingApi: StreamingApi,
private val audioQualityRepository: AudioQualityRepository,
private val videoQualityRepository: VideoQualityRepository,
private val audioModeRepository: AudioModeRepository,
private val trueTimeWrapper: TrueTimeWrapper,
private val mediaDrmCallbackExceptionFactory: MediaDrmCallbackExceptionFactory,
private val eventReporter: EventReporter,
Expand Down Expand Up @@ -98,6 +100,7 @@ internal class StreamingApiRepository(
forwardingMediaProduct.productId.toInt(),
audioQualityRepository.streamingQuality,
PlaybackMode.STREAM,
audioModeRepository.immersiveAudio,
streamingSessionId,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.tidal.sdk.player.playbackengine.audiomode

import com.tidal.sdk.player.streamingapi.playbackinfo.model.PlaybackInfo

/**
* Repository for getting the [immersiveAudio] to be used in a specific request for [PlaybackInfo].
*/
internal class AudioModeRepository(
var immersiveAudio: Boolean = true,
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.tidal.sdk.player.playbackengine.ExoPlayerPlaybackEngine
import com.tidal.sdk.player.playbackengine.PlaybackContextFactory
import com.tidal.sdk.player.playbackengine.PlaybackEngine
import com.tidal.sdk.player.playbackengine.SingleHandlerPlaybackEngine
import com.tidal.sdk.player.playbackengine.audiomode.AudioModeRepository
import com.tidal.sdk.player.playbackengine.dj.DateParser
import com.tidal.sdk.player.playbackengine.dj.DjSessionManager
import com.tidal.sdk.player.playbackengine.dj.HlsTagsParser
Expand Down Expand Up @@ -140,6 +141,10 @@ internal object ExoPlayerPlaybackEngineModule {
fun undeterminedPlaybackSessionResolver(versionedCdmCalculator: VersionedCdm.Calculator) =
UndeterminedPlaybackSessionResolver(versionedCdmCalculator)

@Provides
@Singleton
fun audioModeRepository() = AudioModeRepository()

@Provides
@Singleton
fun exoPlayerPlaybackEngine(
Expand All @@ -151,6 +156,7 @@ internal object ExoPlayerPlaybackEngineModule {
streamingPrivileges: StreamingPrivileges,
playbackContextFactory: PlaybackContextFactory,
audioQualityRepository: AudioQualityRepository,
audioModeRepository: AudioModeRepository,
volumeHelper: VolumeHelper,
trueTimeWrapper: TrueTimeWrapper,
eventReporter: EventReporter,
Expand All @@ -167,6 +173,7 @@ internal object ExoPlayerPlaybackEngineModule {
streamingPrivileges,
playbackContextFactory,
audioQualityRepository,
audioModeRepository,
volumeHelper,
trueTimeWrapper,
eventReporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ 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
import com.tidal.sdk.player.playbackengine.audiomode.AudioModeRepository
import com.tidal.sdk.player.playbackengine.bts.DefaultBtsManifestFactory
import com.tidal.sdk.player.playbackengine.cache.DefaultCacheKeyFactory
import com.tidal.sdk.player.playbackengine.dash.DashManifestFactory
Expand Down Expand Up @@ -390,6 +391,7 @@ internal object MediaSourcererModule {
streamingApi: StreamingApi,
audioQualityRepository: AudioQualityRepository,
videoQualityRepository: VideoQualityRepository,
audioModeRepository: AudioModeRepository,
trueTimeWrapper: TrueTimeWrapper,
mediaDrmCallbackExceptionFactory: MediaDrmCallbackExceptionFactory,
eventReporter: EventReporter,
Expand All @@ -398,6 +400,7 @@ internal object MediaSourcererModule {
streamingApi,
audioQualityRepository,
videoQualityRepository,
audioModeRepository,
trueTimeWrapper,
mediaDrmCallbackExceptionFactory,
eventReporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.tidal.sdk.player.events.model.PlaybackStatistics.Payload.Adaptation
import com.tidal.sdk.player.events.model.PlaybackStatistics.Payload.Stall
import com.tidal.sdk.player.events.model.PlaybackStatistics.Payload.Stall.Reason
import com.tidal.sdk.player.events.model.VideoPlaybackSession
import com.tidal.sdk.player.playbackengine.audiomode.AudioModeRepository
import com.tidal.sdk.player.playbackengine.dj.DjSessionManager
import com.tidal.sdk.player.playbackengine.dj.DjSessionStatus
import com.tidal.sdk.player.playbackengine.dj.HlsTags
Expand Down Expand Up @@ -108,6 +109,7 @@ internal class ExoPlayerPlaybackEngineTest {
private val streamingPrivileges = mock<StreamingPrivileges>()
private val playbackContextFactory = mock<PlaybackContextFactory>()
private val audioQualityRepository = mock<AudioQualityRepository>()
private val audioModeRepository = mock<AudioModeRepository>()
private val volumeHelper = mock<VolumeHelper>()
private val trueTimeWrapper = mock<TrueTimeWrapper>()
private val eventReporter = mock<EventReporter>()
Expand Down Expand Up @@ -136,6 +138,7 @@ internal class ExoPlayerPlaybackEngineTest {
streamingPrivileges,
playbackContextFactory,
audioQualityRepository,
audioModeRepository,
volumeHelper,
trueTimeWrapper,
eventReporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.tidal.sdk.player.events.EventReporter
import com.tidal.sdk.player.events.model.DrmLicenseFetch
import com.tidal.sdk.player.events.model.EndReason
import com.tidal.sdk.player.events.model.PlaybackInfoFetch
import com.tidal.sdk.player.playbackengine.audiomode.AudioModeRepository
import com.tidal.sdk.player.playbackengine.drm.MediaDrmCallbackExceptionFactory
import com.tidal.sdk.player.playbackengine.error.ErrorCodeFactory
import com.tidal.sdk.player.playbackengine.error.ErrorHandler
Expand Down Expand Up @@ -43,6 +44,7 @@ internal class StreamingApiRepositoryTest {
private val streamingApi = mock<StreamingApi>()
private val audioQualityRepository = mock<AudioQualityRepository>()
private val videoQualityRepository = mock<VideoQualityRepository>()
private val audioModeRepository = mock<AudioModeRepository>()
private val trueTimeWrapper = mock<TrueTimeWrapper>()
private val mediaDrmCallbackExceptionFactory = mock<MediaDrmCallbackExceptionFactory>()
private val eventReporter = mock<EventReporter>()
Expand All @@ -51,6 +53,7 @@ internal class StreamingApiRepositoryTest {
streamingApi,
audioQualityRepository,
videoQualityRepository,
audioModeRepository,
trueTimeWrapper,
mediaDrmCallbackExceptionFactory,
eventReporter,
Expand Down Expand Up @@ -149,6 +152,7 @@ internal class StreamingApiRepositoryTest {
productId.toInt(),
productQuality,
playbackMode,
false,
"streamingSessionId",
),
)
Expand Down Expand Up @@ -262,6 +266,7 @@ internal class StreamingApiRepositoryTest {
productId.toInt(),
productQuality,
playbackMode,
false,
"streamingSessionId",
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ interface StreamingApi {
* @param[trackId] The requested track id as [Int].
* @param[audioQuality] The requested audio quality as [AudioQuality].
* @param[playbackMode] The requested playback mode as [PlaybackMode].
* @param[immersiveAudio] The requested option to include immersive audio or not.
* @param[streamingSessionId] The streaming session uuid as [String], created by the client,
* for this streaming session.
* @param[playlistUuid] The playlistUuid this play originates from as [String]. May be null.
*/
@Suppress("LongParameterList")
suspend fun getTrackPlaybackInfo(
trackId: Int,
audioQuality: AudioQuality,
playbackMode: PlaybackMode,
immersiveAudio: Boolean,
streamingSessionId: String,
playlistUuid: String? = null,
): PlaybackInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ internal class StreamingApiDefault(
trackId: Int,
audioQuality: AudioQuality,
playbackMode: PlaybackMode,
immersiveAudio: Boolean,
streamingSessionId: String,
playlistUuid: String?,
) = playbackInfoRepository.getTrackPlaybackInfo(
trackId,
audioQuality,
playbackMode,
immersiveAudio,
streamingSessionId,
playlistUuid,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ internal interface PlaybackInfoService {
@Query("playbackmode") playbackMode: PlaybackMode,
@Query("assetpresentation") assetPresentation: AssetPresentation,
@Query("audioquality") audioQuality: AudioQuality,
@Query("immersiveaudio") immersiveAudio: Boolean,
@Header("x-tidal-streamingsessionid") streamingSessionId: String,
@Header("x-tidal-playlistuuid") playlistUuid: String?,
): PlaybackInfo.Track
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal interface PlaybackInfoRepository {
* @param[trackId] The requested track id as [Int].
* @param[audioQuality] The requested audio quality as [AudioQuality].
* @param[playbackMode] The requested playback mode as [PlaybackMode].
* @param[immersiveAudio] The requested option to include immersive audio or not.
* @param[streamingSessionId] The streaming session uuid as [String], created by the client,
* for this streaming session.
* @param[playlistUuid] The playlistUuid this play originates from as [String]. May be null.
Expand All @@ -24,6 +25,7 @@ internal interface PlaybackInfoRepository {
trackId: Int,
audioQuality: AudioQuality,
playbackMode: PlaybackMode,
immersiveAudio: Boolean,
streamingSessionId: String,
playlistUuid: String?,
): PlaybackInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ internal class PlaybackInfoRepositoryDefault(
trackId: Int,
audioQuality: AudioQuality,
playbackMode: PlaybackMode,
immersiveAudio: Boolean,
streamingSessionId: String,
playlistUuid: String?,
) = try {
Expand All @@ -39,6 +40,7 @@ internal class PlaybackInfoRepositoryDefault(
playbackMode,
AssetPresentation.FULL,
audioQuality,
immersiveAudio,
streamingSessionId,
playlistUuid,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ internal class StreamingApiDefaultTest {
ApiConstants.PLAYBACK_INFO_ID_FOR_DEFAULT,
AudioQuality.LOW,
PlaybackMode.STREAM,
true,
"streamingSessionId",
null,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal class PlaybackInfoServiceStub : PlaybackInfoService {
playbackMode: PlaybackMode,
assetPresentation: AssetPresentation,
audioQuality: AudioQuality,
immersiveAudio: Boolean,
streamingSessionId: String,
playlistUuid: String?,
) = when (trackId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ internal class PlaybackInfoServiceTest {
PlaybackMode.STREAM,
AssetPresentation.FULL,
AudioQuality.LOW,
true,
ApiConstants.STREAMING_SESSION_ID,
null,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ internal class PlaybackInfoRepositoryDefaultTest {
trackId,
AudioQuality.LOW,
PlaybackMode.STREAM,
true,
"streamingSessionId",
null,
)
Expand Down

0 comments on commit 6796e71

Please sign in to comment.