Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transcode audio to keep multichannel support #1466

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions components/ItemGrid/LoadVideoContentTask.bs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ function LoadItems_VideoPlayer(id as string, mediaSourceId = invalid as dynamic,
return invalid
end if

print "video=", video
print "video.content=", video.content
return video
end function

Expand Down Expand Up @@ -140,12 +142,18 @@ sub LoadItems_AddVideoContent(video as object, mediaSourceId as dynamic, audio_s
}
end if


' 'TODO: allow user selection of subtitle track before playback initiated, for now set to no subtitles
print "m.playbackInfo.MediaSources[0]", m.playbackInfo.MediaSources[0]
print "m.playbackInfo.MediaSources[0].Formats", m.playbackInfo.MediaSources[0].Formats
print "m.playbackInfo.MediaSources[0].MediaStreams", m.playbackInfo.MediaSources[0].MediaStreams
for each stream in m.playbackInfo.MediaSources[0].MediaStreams
print "stream=", stream
end for
print "video.audioIndex=", video.audioIndex

video.directPlaySupported = m.playbackInfo.MediaSources[0].SupportsDirectPlay
fully_external = false


' For h264/hevc video, Roku spec states that it supports specfic encoding levels
' The device can decode content with a Higher Encoding level but may play it back with certain
' artifacts. If the user preference is set, and the only reason the server says we need to
Expand Down Expand Up @@ -211,6 +219,36 @@ sub addVideoContentURL(video, mediaSourceId, audio_stream_idx, fully_external)
"AudioStreamIndex": audio_stream_idx
}

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 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 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 = preferredAudioCodec
' force all multichannel aac files to use mkv container
if selectedAudioStream.Codec = "aac"
params.container = "mkv"
end if

video.isTranscoded = true
video.directplaysupported = false
params.transcodeReasons = "Switching audio codecs to preserve multichannel audio support"
video.transcodeReasons = params.transcodeReasons
end if
end if
end if

if mediaSourceId <> ""
params.MediaSourceId = mediaSourceId
end if
Expand Down
24 changes: 22 additions & 2 deletions source/utils/session.bs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ namespace session
server: {},
user: {
Configuration: {},
lastRunVersion: invalid,
playback: {},
Policy: {},
settings: {},
lastRunVersion: invalid
settings: {}
}
}
})
Expand Down Expand Up @@ -115,6 +116,22 @@ namespace session

namespace user

sub SavePlaybackSettings()
playbackArray = {}
di = CreateObject("roDeviceInfo")

' Preferred Audio Codecs
playbackArray.preferredAudioCodec = "aac" ' AAC for stereo
if di.GetAudioOutputChannel() <> "Stereo"
playbackArray.preferredAudioCodec = "ac3" ' Dolby Digital for surround sound
if m.global.session.user.settings["playback.forceDTS"]
playbackArray.preferredAudioCodec = "dts" ' DTS for surround sound when asked
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 @@ -169,6 +186,9 @@ namespace session
end if
end for

session.user.SavePlaybackSettings()

' debugging
if m.global.app.isDev
print "m.global.session.user = ", m.global.session.user
print "m.global.session.user.Configuration = ", m.global.session.user.Configuration
Expand Down