From 3a76e5fc53fd9ac9cd6bccd370a022ab4f73494c Mon Sep 17 00:00:00 2001 From: Charles Ewert Date: Mon, 2 Oct 2023 21:12:43 -0400 Subject: [PATCH] move preferred codec logic to global session --- components/ItemGrid/LoadVideoContentTask.brs | 18 ++++++--------- source/utils/session.bs | 23 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/components/ItemGrid/LoadVideoContentTask.brs b/components/ItemGrid/LoadVideoContentTask.brs index ca3161bff..d48cd222b 100644 --- a/components/ItemGrid/LoadVideoContentTask.brs +++ b/components/ItemGrid/LoadVideoContentTask.brs @@ -221,26 +221,22 @@ sub addVideoContentURL(video, mediaSourceId, audio_stream_idx, fully_external) selectedAudioStream = m.playbackInfo.MediaSources[0].MediaStreams[audio_stream_idx] if selectedAudioStream.Channels > 2 and Lcase(selectedAudioStream.Codec) = "aac" or Lcase(selectedAudioStream.Codec) = "opus" - ' does the user have a receiver that can decode this multichannel audio stream? + ' does the user have an HDMI device attached that can decode this multichannel audio stream? di = CreateObject("roDeviceInfo") if not di.CanDecodeAudio({ Codec: selectedAudioStream.Codec, ChCnt: selectedAudioStream.Channels, PassThru: 1 }).Result print "Attached HDMI device can not decode the selected multichannel audio codec" - ' check to see if the receiver can decode our preferred audio codec - preferredCodec = "ac3" - if selectedAudioStream.Container = "webm" or selectedAudioStream.Container = "mkv" - if m.global.session.user.settings["playback.forceDTS"] - preferredCodec = "dts" - end if - end if - if di.CanDecodeAudio({ Codec: preferredCodec, ChCnt: selectedAudioStream.Channels, PassThru: 1 }).Result + ' check to see if the attached HDMI device can decode our preferred audio codec + preferredAudioCodec = m.global.session.user.playback.preferredAudioCodec + + if di.CanDecodeAudio({ Codec: preferredAudioCodec, Container: selectedAudioStream.Container, ChCnt: selectedAudioStream.Channels, PassThru: 1 }).Result print "Attached HDMI device can decode our preferred multichannel audio codec" print "Attempting to transcode audio to the users preferred multichannel audio codec" ' transcode the audio to keep multichannel support ' otherwise the roku device will downmix aac/opus to stereo params.Static = false params.context = "Streaming" - params.audioCodec = preferredCodec - ' force all + params.audioCodec = preferredAudioCodec + ' force all multichannel aac files to use mkv container if selectedAudioStream.Codec = "aac" params.container = "mkv" end if diff --git a/source/utils/session.bs b/source/utils/session.bs index 4f015751b..072eb5d19 100644 --- a/source/utils/session.bs +++ b/source/utils/session.bs @@ -10,6 +10,7 @@ namespace session server: {}, user: { Configuration: {}, + playback: {}, Policy: {}, settings: {} } @@ -107,6 +108,24 @@ namespace session namespace user + sub SavePlaybackSettings() + playbackArray = {} + di = CreateObject("roDeviceInfo") + + ' Preferred Audio Codec + ' Use AAC for everything + playbackArray.preferredAudioCodec = "aac" + if di.GetAudioOutputChannel() <> "Stereo" + ' Use Dolby Digital as default surround sound codec + playbackArray.preferredAudioCodec = "ac3" + if m.global.session.user.settings["playback.forceDTS"] + playbackArray.preferredAudioCodec = "dts" + end if + end if + + session.user.Update("playback", playbackArray) + end sub + ' Add or update one value from the global user session array (m.global.session.user) sub Update(key as string, value as dynamic) ' validate parameters @@ -148,9 +167,13 @@ namespace session session.user.settings.Save(setting, userSettings[setting]) end for + session.user.SavePlaybackSettings() + + ' debugging if m.global.app.isDev print "m.global.session.user.settings = ", m.global.session.user.settings end if + ' ensure registry is updated set_user_setting("username", tmpSession.user.name) set_user_setting("token", tmpSession.user.authToken)