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

Force mp3 when playback fails because of unsupported aac stream #2055

Merged
merged 1 commit into from
Nov 19, 2024
Merged
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
5 changes: 3 additions & 2 deletions components/ItemGrid/LoadVideoContentTask.bs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ sub loadItems()
forceTranscoding = false

m.top.content = [LoadItems_VideoPlayer(id, mediaSourceId, audio_stream_idx, forceTranscoding)]
m.top.forceMp3 = false
end sub

function LoadItems_VideoPlayer(id as string, mediaSourceId = invalid as dynamic, audio_stream_idx = 1 as integer, forceTranscoding = false as boolean) as dynamic
Expand Down Expand Up @@ -157,7 +158,7 @@ sub LoadItems_AddVideoContent(video as object, mediaSourceId as dynamic, audio_s
if not isValid(mediaSourceId) then mediaSourceId = video.id
if meta.live then mediaSourceId = ""

m.playbackInfo = ItemPostPlaybackInfo(video.id, mediaSourceId, audio_stream_idx, subtitle_idx, playbackPosition)
m.playbackInfo = ItemPostPlaybackInfo(video.id, mediaSourceId, audio_stream_idx, subtitle_idx, playbackPosition, m.top.forceMp3)
if not isValid(m.playbackInfo)
video.errorMsg = "Error loading playback info"
video.content = invalid
Expand All @@ -174,7 +175,7 @@ sub LoadItems_AddVideoContent(video as object, mediaSourceId as dynamic, audio_s
video.SelectedSubtitle = defaultSubtitleIndex
subtitle_idx = defaultSubtitleIndex

m.playbackInfo = ItemPostPlaybackInfo(video.id, mediaSourceId, audio_stream_idx, subtitle_idx, playbackPosition)
m.playbackInfo = ItemPostPlaybackInfo(video.id, mediaSourceId, audio_stream_idx, subtitle_idx, playbackPosition, m.top.forceMp3)
if not isValid(m.playbackInfo)
video.errorMsg = "Error loading playback info"
video.content = invalid
Expand Down
1 change: 1 addition & 0 deletions components/ItemGrid/LoadVideoContentTask.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<field id="studioIds" type="string" value="" />
<field id="genreIds" type="string" value="" />
<field id="view" type="string" value="" />
<field id="forceMp3" type="boolean" value="false" />
<!-- Total records available from server-->
<field id="totalRecordCount" type="int" value="-1" />
<field id="content" type="array" />
Expand Down
14 changes: 13 additions & 1 deletion components/video/VideoPlayerView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ sub init()

m.playbackTimer = m.top.findNode("playbackTimer")
m.bufferCheckTimer = m.top.findNode("bufferCheckTimer")
m.top.observeField("state", "onState")
m.top.observeField("content", "onContentChange")
m.top.observeField("selectedSubtitle", "onSubtitleChange")
m.top.observeField("audioIndex", "onAudioIndexChange")
Expand Down Expand Up @@ -397,6 +396,8 @@ sub onVideoContentLoaded()
return
end if

m.top.observeField("state", "onState")

m.top.content = videoContent[0].content
m.top.PlaySessionId = videoContent[0].PlaySessionId
m.top.videoId = videoContent[0].id
Expand Down Expand Up @@ -639,6 +640,17 @@ sub onState(msg)

if not m.playReported and m.top.transcodeAvailable
m.top.retryWithTranscoding = true ' If playback was not reported, retry with transcoding
else if m.top.errorStr = "decoder:pump:Unsupported AAC stream."
m.log.info("retrying video with mp3 audio stream", m.currentItem.id, m.top.SelectedSubtitle, m.top.audioIndex)

m.top.unobserveField("state")
m.LoadMetaDataTask.forceMp3 = true
m.LoadMetaDataTask.selectedSubtitleIndex = m.top.SelectedSubtitle
m.LoadMetaDataTask.selectedAudioStreamIndex = m.top.audioIndex
m.LoadMetaDataTask.itemId = m.currentItem.id
m.LoadMetaDataTask.observeField("content", "onVideoContentLoaded")

m.LoadMetaDataTask.control = "RUN"
else
' If an error was encountered, Display dialog
showPlaybackErrorDialog(tr("Error During Playback"))
Expand Down
1 change: 1 addition & 0 deletions components/video/VideoPlayerView.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<field id="retryWithTranscoding" type="boolean" value="false" />
<field id="isTranscoded" type="boolean" />
<field id="transcodeReasons" type="array" />
<field id="forceMp3" type="boolean" value="false" />

<field id="videoId" type="string" />
<field id="mediaSourceId" type="string" />
Expand Down
35 changes: 21 additions & 14 deletions source/api/Items.bs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function ItemGetPlaybackInfo(id as string, startTimeTicks = 0 as longinteger)
return getJson(resp)
end function

function ItemPostPlaybackInfo(id as string, mediaSourceId = "" as string, audioTrackIndex = -1 as integer, subtitleTrackIndex = -1 as integer, startTimeTicks = 0 as longinteger)
function ItemPostPlaybackInfo(id as string, mediaSourceId = "" as string, audioTrackIndex = -1 as integer, subtitleTrackIndex = -1 as integer, startTimeTicks = 0 as longinteger, forceMp3 = false as boolean)
params = {
"UserId": m.global.session.user.id,
"StartTimeTicks": startTimeTicks,
Expand Down Expand Up @@ -49,24 +49,14 @@ function ItemPostPlaybackInfo(id as string, mediaSourceId = "" as string, audioT
' TODO: Remove this after server adds support for transcoding AAC from one profile to another
if selectedAudioStream.Codec <> invalid and LCase(selectedAudioStream.Codec) = "aac"
if selectedAudioStream.Profile <> invalid and LCase(selectedAudioStream.Profile) = "main" or LCase(selectedAudioStream.Profile) = "he-aac"
for each rule in deviceProfile.TranscodingProfiles
if rule.Container = "ts" or rule.Container = "mp4"
if rule.AudioCodec = "aac"
rule.AudioCodec = "mp3"
else if rule.AudioCodec.Left(4) = "aac,"
rule.AudioCodec = mid(rule.AudioCodec, 5)

if rule.AudioCodec.Left(3) <> "mp3"
rule.AudioCodec = "mp3," + rule.AudioCodec
end if
end if
end if
end for
forceMp3 = true
end if
end if
end if
end if

if forceMp3 then forceMp3Audio(deviceProfile)

req = APIRequest(Substitute("Items/{0}/PlaybackInfo", id), params)
req.SetRequest("POST")
return postJson(req, FormatJson({ "DeviceProfile": deviceProfile }))
Expand Down Expand Up @@ -538,3 +528,20 @@ function TVEpisodeShuffleList(show_id as string)

return data
end function

' updates the device profile we send the server to force mp3 audio transcoding instead of the default aac
sub forceMp3Audio(deviceProfile as object)
for each rule in deviceProfile.TranscodingProfiles
if rule.Container = "ts" or rule.Container = "mp4"
if rule.AudioCodec = "aac"
rule.AudioCodec = "mp3"
else if rule.AudioCodec.Left(4) = "aac,"
rule.AudioCodec = mid(rule.AudioCodec, 5)

if rule.AudioCodec.Left(3) <> "mp3"
rule.AudioCodec = "mp3," + rule.AudioCodec
end if
end if
end if
end for
end sub
Loading