Skip to content

Commit

Permalink
move preferred codec logic to global session
Browse files Browse the repository at this point in the history
  • Loading branch information
cewert committed Oct 3, 2023
1 parent 31711c0 commit 3a76e5f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
18 changes: 7 additions & 11 deletions components/ItemGrid/LoadVideoContentTask.brs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions source/utils/session.bs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace session
server: {},
user: {
Configuration: {},
playback: {},
Policy: {},
settings: {}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3a76e5f

Please sign in to comment.