Skip to content

Commit

Permalink
Force LiveTV retry with Transcoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimdogx committed Nov 17, 2024
1 parent 25cb9f2 commit 89160be
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
18 changes: 14 additions & 4 deletions components/ItemGrid/LoadVideoContentTask.bs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ sub loadItems()
id = m.top.itemId
mediaSourceId = invalid
audio_stream_idx = m.top.selectedAudioStreamIndex
forceTranscoding = false
if m.top.transcodeLiveTV = true
print "forcing retry of Live TV with transcoding..."
forceTranscoding = true
else
forceTranscoding = false
end if

m.top.content = [LoadItems_VideoPlayer(id, mediaSourceId, audio_stream_idx, forceTranscoding)]
end sub
Expand Down Expand Up @@ -115,6 +120,11 @@ sub LoadItems_AddVideoContent(video as object, mediaSourceId as dynamic, audio_s
end if
end if

' when a retry live TV is happening...
if videotype = "tvchannel"
meta.live = true
end if

video.chapters = meta.json.Chapters
video.content.title = meta.title
video.showID = meta.showID
Expand Down Expand Up @@ -147,7 +157,7 @@ sub LoadItems_AddVideoContent(video as object, mediaSourceId as dynamic, audio_s

currentItem = queueManager.callFunc("getCurrentItem")

if isValid(currentItem) and isValid(currentItem.startingPoint)
if isValid(currentItem) and isValid(currentItem.startingPoint) and not meta.live
playbackPosition = currentItem.startingPoint
end if

Expand All @@ -157,7 +167,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, forceTranscoding)
if not isValid(m.playbackInfo)
video.errorMsg = "Error loading playback info"
video.content = invalid
Expand All @@ -174,7 +184,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, forceTranscoding)
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 @@ -21,5 +21,6 @@
<!-- Total records available from server-->
<field id="totalRecordCount" type="int" value="-1" />
<field id="content" type="array" />
<field id="transcodeLiveTV" type="boolean" value="false" />
</interface>
</component>
17 changes: 16 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 @@ -354,6 +353,15 @@ sub onAudioIndexChange()
m.LoadMetaDataTask.control = "RUN"
end sub

sub RetryLiveTV()
m.LoadMetaDataTask.transcodeLiveTV = 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"
end sub

sub onPlaybackErrorDialogClosed(msg)
sourceNode = msg.getRoSGNode()
sourceNode.unobserveField("buttonSelected")
Expand All @@ -380,6 +388,7 @@ end sub
sub onVideoContentLoaded()
m.LoadMetaDataTask.unobserveField("content")
m.LoadMetaDataTask.control = "STOP"
m.top.observeField("state", "onState")

videoContent = m.LoadMetaDataTask.content
m.LoadMetaDataTask.content = []
Expand Down Expand Up @@ -639,6 +648,12 @@ 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 Instr(1, m.top.errorStr, "Unsupported AAC stream") > 0
' Some Live TV streams use HE-AAC which Roku doesn't support
m.top.unobserveField("state")
m.playbackTimer.control = "stop"
RetryLiveTV()
return
else
' If an error was encountered, Display dialog
showPlaybackErrorDialog(tr("Error During Playback"))
Expand Down
10 changes: 5 additions & 5 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, forceLiveTVTranscode = false)
params = {
"UserId": m.global.session.user.id,
"StartTimeTicks": startTimeTicks,
Expand All @@ -39,16 +39,16 @@ function ItemPostPlaybackInfo(id as string, mediaSourceId = "" as string, audioT

myGLobal = m.global

if audioTrackIndex > -1 and myGLobal.session.video.json.MediaStreams <> invalid
if audioTrackIndex > -1 and myGLobal.session.video.json.MediaStreams <> invalid or forceLiveTVTranscode
selectedAudioStream = myGLobal.session.video.json.MediaStreams[audioTrackIndex]

if selectedAudioStream <> invalid
if selectedAudioStream <> invalid or forceLiveTVTranscode
params.AudioStreamIndex = audioTrackIndex

' force the server to transcode AAC profiles we don't support to MP3 instead of the usual AAC
' 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"
if forceLiveTVTranscode or selectedAudioStream.Codec <> invalid and LCase(selectedAudioStream.Codec) = "aac"
if forceLiveTVTranscode or 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"
Expand Down

0 comments on commit 89160be

Please sign in to comment.