2023-04-19 13:59:14 +00:00
function VideoPlayer(id as string, mediaSourceId = invalid as dynamic, audio_stream_idx = 1 as integer, subtitle_idx = -1 as integer, forceTranscoding = false as boolean, showIntro = true as boolean, allowResumeDialog = true as boolean) as dynamic
2021-07-09 20:08:32 +00:00
' Get video controls and UI
video = CreateObject("roSGNode", "JFVideo")
video.id = id
2022-12-08 18:33:08 +00:00
AddVideoContent(video, mediaSourceId, audio_stream_idx, subtitle_idx, -1, forceTranscoding, showIntro, allowResumeDialog)
2022-07-09 08:28:15 +00:00
if video.errorMsg = "introaborted"
return video
end if
2021-06-12 15:03:47 +00:00
2021-07-09 20:08:32 +00:00
if video.content = invalid
2023-02-04 06:15:40 +00:00
stopLoadingSpinner()
2021-07-09 20:08:32 +00:00
return invalid
end if
jellyfin_blue = "#00a4dcFF"
2019-03-19 00:33:44 +00:00
2021-07-09 20:08:32 +00:00
video.retrievingBar.filledBarBlendColor = jellyfin_blue
video.bufferingBar.filledBarBlendColor = jellyfin_blue
video.trickPlayBar.filledBarBlendColor = jellyfin_blue
return video
2019-01-31 04:56:15 +00:00
end function
2023-04-19 13:59:14 +00:00
sub AddVideoContent(video as object, mediaSourceId as dynamic, audio_stream_idx = 1 as integer, subtitle_idx = -1 as integer, playbackPosition = -1 as integer, forceTranscoding = false as boolean, showIntro = true as boolean, allowResumeDialog = true as boolean)
2021-07-09 20:08:32 +00:00
video.content = createObject("RoSGNode", "ContentNode")
meta = ItemMetaData(video.id)
if meta = invalid
2021-06-12 15:03:47 +00:00
video.content = invalid
return
2020-03-04 02:46:26 +00:00
end if
2022-12-28 23:45:52 +00:00
m.videotype = meta.type
2021-06-12 15:03:47 +00:00
2022-09-03 07:49:30 +00:00
' Special handling for "Programs" or "Vidoes" launched from "On Now" or elsewhere on the home screen...
' basically anything that is a Live Channel.
2023-03-09 19:35:29 +00:00
if isValid(meta.json) and isValid(meta.json.ChannelId)
if isValid(meta.json.EpisodeTitle)
2022-09-03 07:49:30 +00:00
meta.title = meta.json.EpisodeTitle
2023-03-09 19:35:29 +00:00
else if isValid(meta.json.Name)
2022-09-03 07:49:30 +00:00
meta.title = meta.json.Name
end if
2021-12-18 06:03:33 +00:00
meta.showID = meta.json.id
meta.live = true
2022-09-03 07:49:30 +00:00
if meta.json.type = "Program"
video.id = meta.json.ChannelId
else
video.id = meta.json.id
end if
2021-12-18 06:03:33 +00:00
end if
2022-11-07 04:35:02 +00:00
if m.videotype = "Episode" or m.videotype = "Series"
video.content.contenttype = "episode"
end if
2021-07-09 20:08:32 +00:00
video.content.title = meta.title
video.showID = meta.showID
2023-01-02 22:50:18 +00:00
if playbackPosition = -1 and isValid(meta.json)
2021-07-09 20:08:32 +00:00
playbackPosition = meta.json.UserData.PlaybackPositionTicks
2022-12-08 18:33:08 +00:00
if allowResumeDialog
if playbackPosition > 0
2023-02-04 06:15:40 +00:00
stopLoadingSpinner()
2022-12-08 18:33:08 +00:00
dialogResult = startPlayBackOver(playbackPosition)
2023-02-04 05:26:55 +00:00
startMediaLoadingSpinner()
2022-12-08 18:33:08 +00:00
'Dialog returns -1 when back pressed, 0 for resume, and 1 for start over
if dialogResult = -1
'User pressed back, return invalid and don't load video
video.content = invalid
return
else if dialogResult = 1
'Start Over selected, change position to 0
playbackPosition = 0
else if dialogResult = 2
'Mark this item as watched, refresh the page, and return invalid so we don't load the video
MarkItemWatched(video.id)
video.content.watched = not video.content.watched
group = m.scene.focusedChild
group.timeLastRefresh = CreateObject("roDateTime").AsSeconds()
group.callFunc("refresh")
video.content = invalid
return
else if dialogResult = 3
'get series ID based off episiode ID
params = {
ids: video.Id
}
2023-06-01 12:43:27 +00:00
url = Substitute("Users/{0}/Items/", m.global.session.user.id)
2022-12-08 18:33:08 +00:00
resp = APIRequest(url, params)
data = getJson(resp)
for each item in data.Items
m.series_id = item.SeriesId
end for
'Get series json data
params = {
ids: m.series_id
}
2023-06-01 12:43:27 +00:00
url = Substitute("Users/{0}/Items/", m.global.session.user.id)
2022-12-08 18:33:08 +00:00
resp = APIRequest(url, params)
data = getJson(resp)
for each item in data.Items
m.tmp = item
end for
2023-02-11 03:57:46 +00:00
stopLoadingSpinner()
2022-12-08 18:33:08 +00:00
'Create Series Scene
CreateSeriesDetailsGroup(m.tmp)
video.content = invalid
return
2022-05-12 18:11:59 +00:00
2022-12-08 18:33:08 +00:00
else if dialogResult = 4
'get Season/Series ID based off episiode ID
params = {
ids: video.Id
}
2023-06-01 12:43:27 +00:00
url = Substitute("Users/{0}/Items/", m.global.session.user.id)
2022-12-08 18:33:08 +00:00
resp = APIRequest(url, params)
data = getJson(resp)
for each item in data.Items
m.season_id = item.SeasonId
m.series_id = item.SeriesId
end for
'Get Series json data
params = {
ids: m.season_id
}
2023-06-01 12:43:27 +00:00
url = Substitute("Users/{0}/Items/", m.global.session.user.id)
2022-12-08 18:33:08 +00:00
resp = APIRequest(url, params)
data = getJson(resp)
for each item in data.Items
m.Season_tmp = item
end for
'Get Season json data
params = {
ids: m.series_id
}
2023-06-01 12:43:27 +00:00
url = Substitute("Users/{0}/Items/", m.global.session.user.id)
2022-12-08 18:33:08 +00:00
resp = APIRequest(url, params)
data = getJson(resp)
for each item in data.Items
m.Series_tmp = item
end for
2023-02-11 03:57:46 +00:00
stopLoadingSpinner()
2022-12-08 18:33:08 +00:00
'Create Season Scene
CreateSeasonDetailsGroup(m.Series_tmp, m.Season_tmp)
video.content = invalid
return
2022-05-12 18:11:59 +00:00
2022-12-08 18:33:08 +00:00
else if dialogResult = 5
'get episiode ID
params = {
ids: video.Id
}
2023-06-01 12:43:27 +00:00
url = Substitute("Users/{0}/Items/", m.global.session.user.id)
2022-12-08 18:33:08 +00:00
resp = APIRequest(url, params)
data = getJson(resp)
for each item in data.Items
m.episode_id = item
end for
2023-02-11 03:57:46 +00:00
stopLoadingSpinner()
2022-12-08 18:33:08 +00:00
'Create Episode Scene
CreateMovieDetailsGroup(m.episode_id)
video.content = invalid
return
end if
2021-07-09 20:08:32 +00:00
end if
end if
end if
2022-05-12 18:11:59 +00:00
2022-07-09 08:28:15 +00:00
' Don't attempt to play an intro for an intro video
if showIntro
' Do not play intros when resuming playback
if playbackPosition = 0
if not PlayIntroVideo(video.id, audio_stream_idx)
video.errorMsg = "introaborted"
return
end if
end if
end if
2022-05-12 18:11:59 +00:00
2021-07-09 20:08:32 +00:00
video.content.PlayStart = int(playbackPosition / 10000000)
' Call PlayInfo from server
2022-03-13 14:22:55 +00:00
if mediaSourceId = invalid
mediaSourceId = video.id
end if
2023-01-02 22:50:18 +00:00
' Don't send mediaSourceId for Live Media
' Note: Recordings in progress will have meta.live = invalid, but we still don't want to send mediaSourceId
2023-01-04 14:09:57 +00:00
if not isValid(meta.live)
2023-01-02 22:50:18 +00:00
meta.live = false
mediaSourceId = ""
else
if meta.live
mediaSourceId = ""
end if
end if
2022-03-13 14:22:55 +00:00
2022-09-06 04:38:37 +00:00
m.playbackInfo = ItemPostPlaybackInfo(video.id, mediaSourceId, audio_stream_idx, subtitle_idx, playbackPosition)
2021-07-09 20:08:32 +00:00
video.videoId = video.id
2022-03-13 14:24:08 +00:00
video.mediaSourceId = mediaSourceId
2021-07-09 20:08:32 +00:00
video.audioIndex = audio_stream_idx
2020-05-31 14:44:58 +00:00
2022-09-06 04:38:37 +00:00
if m.playbackInfo = invalid
2021-07-09 20:08:32 +00:00
video.content = invalid
return
end if
2020-05-31 14:44:58 +00:00
2021-07-09 20:08:32 +00:00
params = {}
2022-09-06 04:38:37 +00:00
video.PlaySessionId = m.playbackInfo.PlaySessionId
2020-05-31 13:46:33 +00:00
2021-07-09 20:08:32 +00:00
if meta.live
video.content.live = true
video.content.StreamFormat = "hls"
end if
2020-05-31 13:46:33 +00:00
2021-07-09 20:08:32 +00:00
video.container = getContainerType(meta)
2020-05-31 13:46:33 +00:00
2023-01-04 14:10:23 +00:00
if not isValid(m.playbackInfo.MediaSources[0]) and isValid(meta.json)
2022-09-06 04:38:37 +00:00
m.playbackInfo = meta.json
2022-07-09 08:28:15 +00:00
end if
2022-09-06 04:38:37 +00:00
subtitles = sortSubtitles(meta.id, m.playbackInfo.MediaSources[0].MediaStreams)
2023-06-01 12:43:27 +00:00
if m.global.session.user.settings["playback.subs.onlytext"] = true
2022-12-14 01:47:26 +00:00
safesubs = []
for each subtitle in subtitles["all"]
if subtitle["IsTextSubtitleStream"]
safesubs.push(subtitle)
end if
end for
video.Subtitles = safesubs
else
video.Subtitles = subtitles["all"]
end if
2020-02-15 15:34:29 +00:00
2021-07-09 20:08:32 +00:00
if meta.live
video.transcodeParams = {
2022-09-06 04:38:37 +00:00
"MediaSourceId": m.playbackInfo.MediaSources[0].Id,
"LiveStreamId": m.playbackInfo.MediaSources[0].LiveStreamId,
2021-07-09 20:08:32 +00:00
"PlaySessionId": video.PlaySessionId
}
end if
2020-05-31 13:46:33 +00:00
2021-07-09 20:08:32 +00:00
video.content.SubtitleTracks = subtitles["text"]
2020-03-28 20:04:57 +00:00
2021-07-09 20:08:32 +00:00
' 'TODO: allow user selection of subtitle track before playback initiated, for now set to no subtitles
2022-09-06 04:38:37 +00:00
video.directPlaySupported = m.playbackInfo.MediaSources[0].SupportsDirectPlay
2022-04-26 08:12:00 +00:00
fully_external = false
2022-07-04 09:09:16 +00:00
2022-09-04 09:11:08 +00:00
' For h264/hevc video, Roku spec states that it supports specfic encoding levels
2022-07-04 09:09:16 +00:00
' The device can decode content with a Higher Encoding level but may play it back with certain
2022-07-04 09:31:28 +00:00
' artifacts. If the user preference is set, and the only reason the server says we need to
2022-09-04 09:11:08 +00:00
' transcode is that the Encoding Level is not supported, then try to direct play but silently
2022-07-04 09:09:16 +00:00
' fall back to the transcode if that fails.
2022-10-06 08:25:03 +00:00
if m.playbackInfo.MediaSources[0].MediaStreams.Count() > 0 and meta.live = false
2023-06-01 12:43:27 +00:00
tryDirectPlay = m.global.session.user.settings["playback.tryDirect.h264ProfileLevel"] = true and m.playbackInfo.MediaSources[0].MediaStreams[0].codec = "h264"
tryDirectPlay = tryDirectPlay or (m.global.session.user.settings["playback.tryDirect.hevcProfileLevel"] = true and m.playbackInfo.MediaSources[0].MediaStreams[0].codec = "hevc")
2023-03-09 19:35:29 +00:00
if tryDirectPlay and isValid(m.playbackInfo.MediaSources[0].TranscodingUrl) and forceTranscoding = false
2022-10-06 08:25:03 +00:00
transcodingReasons = getTranscodeReasons(m.playbackInfo.MediaSources[0].TranscodingUrl)
2022-09-04 13:03:17 +00:00
if transcodingReasons.Count() = 1 and transcodingReasons[0] = "VideoLevelNotSupported"
video.directPlaySupported = true
video.transcodeAvailable = true
end if
2022-07-04 09:09:16 +00:00
end if
2022-07-04 09:31:28 +00:00
end if
2022-07-04 09:09:16 +00:00
2021-07-09 20:08:32 +00:00
if video.directPlaySupported
2022-09-06 04:38:37 +00:00
protocol = LCase(m.playbackInfo.MediaSources[0].Protocol)
2022-04-26 08:12:00 +00:00
if protocol <> "file"
2023-05-22 04:31:35 +00:00
uri = parseUrl(m.playbackInfo.MediaSources[0].Path)
if isLocalhost(uri[2])
' the domain of the URI is local to the server.
2022-04-26 08:12:00 +00:00
' create a new URI by appending the received path to the server URL
' later we will substitute the users provided URL for this case
video.content.url = buildURL(uri[4])
else
fully_external = true
2022-09-06 04:38:37 +00:00
video.content.url = m.playbackInfo.MediaSources[0].Path
2022-04-26 08:12:00 +00:00
end if
else:
params.append({
"Static": "true",
"Container": video.container,
"PlaySessionId": video.PlaySessionId,
"AudioStreamIndex": audio_stream_idx
})
if mediaSourceId <> ""
params.MediaSourceId = mediaSourceId
end if
video.content.url = buildURL(Substitute("Videos/{0}/stream", video.id), params)
2022-03-13 14:22:55 +00:00
end if
2021-07-09 20:08:32 +00:00
video.isTranscoded = false
else
2022-09-06 04:38:37 +00:00
if m.playbackInfo.MediaSources[0].TranscodingUrl = invalid
2022-04-26 08:12:00 +00:00
' If server does not provide a transcode URL, display a message to the user
2021-12-03 09:40:15 +00:00
m.global.sceneManager.callFunc("userMessage", tr("Error Getting Playback Information"), tr("An error was encountered while playing this item. Server did not provide required transcoding data."))
video.content = invalid
return
end if
2021-07-09 20:08:32 +00:00
' Get transcoding reason
2022-09-06 04:38:37 +00:00
video.transcodeReasons = getTranscodeReasons(m.playbackInfo.MediaSources[0].TranscodingUrl)
video.content.url = buildURL(m.playbackInfo.MediaSources[0].TranscodingUrl)
2021-07-09 20:08:32 +00:00
video.isTranscoded = true
end if
2019-01-31 04:56:15 +00:00
2023-06-01 18:09:38 +00:00
setCertificateAuthority(video.content)
2022-04-26 08:12:00 +00:00
video.audioTrack = (audio_stream_idx + 1).ToStr() ' Roku's track indexes count from 1. Our index is zero based
2022-04-17 00:46:08 +00:00
' Perform relevant setup work for selected subtitle, and return the index of the subtitle
' is enabled/will be enabled, indexed on the provided list of subtitles
video.SelectedSubtitle = setupSubtitle(video, video.Subtitles, subtitle_idx)
2022-04-26 08:12:00 +00:00
if not fully_external
2023-08-20 16:48:15 +00:00
video.content = authRequest(video.content)
2022-04-26 08:12:00 +00:00
end if
2021-06-12 15:03:47 +00:00
end sub
2020-10-11 16:32:34 +00:00
2022-07-09 08:28:15 +00:00
function PlayIntroVideo(video_id, audio_stream_idx) as boolean
' Intro videos only play if user has cinema mode setting enabled
2023-06-01 12:43:27 +00:00
if m.global.session.user.settings["playback.cinemamode"] = true
2022-07-09 08:28:15 +00:00
' Check if server has intro videos setup and available
introVideos = GetIntroVideos(video_id)
if introVideos = invalid then return true
if introVideos.TotalRecordCount > 0
' Bypass joke pre-roll
if lcase(introVideos.items[0].name) = "rick roll'd" then return true
2022-07-13 07:08:06 +00:00
introVideo = VideoPlayer(introVideos.items[0].id, introVideos.items[0].id, audio_stream_idx, defaultSubtitleTrackFromVid(video_id), false, false)
2023-03-26 16:13:55 +00:00
if isValid(introVideo)
introVideo.allowCaptions = false
end if
2022-07-09 08:28:15 +00:00
port = CreateObject("roMessagePort")
introVideo.observeField("state", port)
m.global.sceneManager.callFunc("pushScene", introVideo)
introPlaying = true
2023-03-23 22:53:08 +00:00
stopLoadingSpinner()
2022-07-09 08:28:15 +00:00
while introPlaying
msg = wait(0, port)
if type(msg) = "roSGNodeEvent"
if msg.GetData() = "finished"
m.global.sceneManager.callFunc("clearPreviousScene")
introPlaying = false
else if msg.GetData() = "stopped"
introPlaying = false
return false
end if
end if
end while
end if
end if
return true
end function
2021-06-12 15:03:47 +00:00
'
' Extract array of Transcode Reasons from the content URL
' @returns Array of Strings
function getTranscodeReasons(url as string) as object
2021-07-09 20:08:32 +00:00
regex = CreateObject("roRegex", "&TranscodeReasons=([^&]*)", "")
match = regex.Match(url)
2020-10-11 16:32:34 +00:00
2021-07-09 20:08:32 +00:00
if match.count() > 1
return match[1].Split(",")
end if
2020-10-11 16:32:34 +00:00
2021-07-09 20:08:32 +00:00
return []
2020-03-11 03:50:47 +00:00
end function
2022-09-08 19:19:08 +00:00
'Opens dialog asking user if they want to resume video or start playback over only on the home screen
2021-07-09 20:08:32 +00:00
function startPlayBackOver(time as longinteger) as integer
2022-09-08 19:19:08 +00:00
if m.scene.focusedChild.focusedChild.overhangTitle = tr("Home") and (m.videotype = "Episode" or m.videotype = "Series")
2022-05-12 18:11:59 +00:00
return option_dialog([tr("Resume playing at ") + ticksToHuman(time) + ".", tr("Start over from the beginning."), tr("Watched"), tr("Go to series"), tr("Go to season"), tr("Go to episode")])
2021-07-09 20:08:32 +00:00
else
return option_dialog(["Resume playing at " + ticksToHuman(time) + ".", "Start over from the beginning."])
end if
2020-02-22 00:50:20 +00:00
end function
2020-02-15 01:47:06 +00:00
function directPlaySupported(meta as object) as boolean
2021-07-09 20:08:32 +00:00
devinfo = CreateObject("roDeviceInfo")
2023-03-09 19:35:29 +00:00
if isValid(meta.json.MediaSources[0]) and meta.json.MediaSources[0].SupportsDirectPlay = false
2021-07-09 20:08:32 +00:00
return false
end if
2023-03-09 19:35:29 +00:00
if not isValid(meta.json.MediaSources[0])
2021-07-09 20:08:32 +00:00
return false
end if
streamInfo = { Codec: meta.json.MediaStreams[0].codec }
2023-03-09 19:35:29 +00:00
if isValid(meta.json.MediaStreams[0].Profile) and meta.json.MediaStreams[0].Profile.len() > 0
2021-07-09 20:08:32 +00:00
streamInfo.Profile = LCase(meta.json.MediaStreams[0].Profile)
end if
2023-03-09 19:35:29 +00:00
if isValid(meta.json.MediaSources[0].container) and meta.json.MediaSources[0].container.len() > 0
2021-07-09 20:08:32 +00:00
'CanDecodeVideo() requires the .container to be format: “mp4”, “hls”, “mkv”, “ism”, “dash”, “ts” if its to direct stream
if meta.json.MediaSources[0].container = "mov"
streamInfo.Container = "mp4"
else
streamInfo.Container = meta.json.MediaSources[0].container
end if
2021-01-10 20:06:16 +00:00
end if
2021-04-30 07:23:38 +00:00
2021-07-09 20:08:32 +00:00
decodeResult = devinfo.CanDecodeVideo(streamInfo)
2023-03-09 19:35:29 +00:00
return isValid(decodeResult) and decodeResult.result
2020-02-21 04:02:21 +00:00
end function
2019-04-22 05:09:16 +00:00
function getContainerType(meta as object) as string
2021-07-09 20:08:32 +00:00
' Determine the file type of the video file source
2023-01-04 17:22:07 +00:00
if not IsValid(meta.json) or not isValid(meta.json.mediaSources) then return ""
2021-07-09 20:08:32 +00:00
2023-01-04 17:22:07 +00:00
container = meta.json.mediaSources[0].container
if container = invalid
container = ""
else if container = "m4v" or container = "mov"
container = "mp4"
end if
2019-04-22 05:09:16 +00:00
2023-01-04 17:22:07 +00:00
return container
end function
2019-04-22 05:09:16 +00:00
2023-01-04 17:22:07 +00:00
function getAudioFormat(meta as object) as string
' Determine the codec of the audio file source
if meta.json.mediaSources = invalid then return ""
2019-04-22 05:09:16 +00:00
2023-01-04 17:22:07 +00:00
audioInfo = getAudioInfo(meta)
if audioInfo.count() = 0 or audioInfo[0].codec = invalid then return ""
return audioInfo[0].codec
end function
2019-04-22 05:09:16 +00:00
2023-01-04 17:22:07 +00:00
function getAudioInfo(meta as object) as object
' Return audio metadata for a given stream
results = []
for each source in meta.json.mediaSources[0].mediaStreams
if source["type"] = "Audio"
results.push(source)
end if
end for
return results
end function
sub autoPlayNextEpisode(videoID as string, showID as string)
' use web client setting
2023-06-01 12:43:27 +00:00
if m.global.session.user.configuration.EnableNextEpisodeAutoPlay
2023-01-04 17:22:07 +00:00
' query API for next episode ID
url = Substitute("Shows/{0}/Episodes", showID)
2023-06-01 12:43:27 +00:00
urlParams = { "UserId": m.global.session.user.id }
2023-01-04 17:22:07 +00:00
urlParams.Append({ "StartItemId": videoID })
urlParams.Append({ "Limit": 2 })
resp = APIRequest(url, urlParams)
data = getJson(resp)
2023-03-09 19:35:29 +00:00
if isValid(data) and data.Items.Count() = 2
2023-01-04 17:22:07 +00:00
' setup new video node
nextVideo = CreateVideoPlayerGroup(data.Items[1].Id, invalid, 1, false, false)
' remove last videoplayer scene
m.global.sceneManager.callFunc("clearPreviousScene")
2023-03-09 19:35:29 +00:00
if isValid(nextVideo)
2023-01-04 17:22:07 +00:00
m.global.sceneManager.callFunc("pushScene", nextVideo)
2021-09-14 02:03:32 +00:00
else
2021-10-10 01:51:33 +00:00
m.global.sceneManager.callFunc("popScene")
2021-09-14 02:03:32 +00:00
end if
2021-07-09 20:08:32 +00:00
else
2023-01-04 17:22:07 +00:00
' can't play next episode
2021-10-10 01:51:33 +00:00
m.global.sceneManager.callFunc("popScene")
2021-07-09 20:08:32 +00:00
end if
2023-01-04 17:22:07 +00:00
else
m.global.sceneManager.callFunc("popScene")
end if
end sub
2022-09-06 04:38:37 +00:00
2023-01-04 17:22:07 +00:00
' Returns an array of playback info to be displayed during playback.
' In the future, with a custom playback info view, we can return an associated array.
function GetPlaybackInfo()
2023-10-27 14:51:09 +00:00
sessions = api.sessions.Get({ "deviceId": m.global.device.serverDeviceName })
2023-03-09 19:35:29 +00:00
if isValid(sessions) and sessions.Count() > 0
2023-01-04 17:22:07 +00:00
return GetTranscodingStats(sessions[0])
end if
2022-09-06 04:38:37 +00:00
2023-01-04 17:22:07 +00:00
errMsg = tr("Unable to get playback information")
return [errMsg]
end function
2022-09-06 04:38:37 +00:00
2023-06-01 12:43:27 +00:00
function GetTranscodingStats(deviceSession)
2023-01-04 17:22:07 +00:00
sessionStats = []
2023-06-01 12:43:27 +00:00
if isValid(deviceSession.TranscodingInfo) and deviceSession.TranscodingInfo.Count() > 0
transcodingReasons = deviceSession.TranscodingInfo.TranscodeReasons
videoCodec = deviceSession.TranscodingInfo.VideoCodec
audioCodec = deviceSession.TranscodingInfo.AudioCodec
totalBitrate = deviceSession.TranscodingInfo.Bitrate
audioChannels = deviceSession.TranscodingInfo.AudioChannels
2023-01-04 17:22:07 +00:00
if isValid(transcodingReasons) and transcodingReasons.Count() > 0
sessionStats.push("** " + tr("Transcoding Information") + " **")
for each item in transcodingReasons
sessionStats.push(tr("Reason") + ": " + item)
end for
end if
2022-09-06 04:38:37 +00:00
2023-01-04 17:22:07 +00:00
if isValid(videoCodec)
data = tr("Video Codec") + ": " + videoCodec
2023-06-01 12:43:27 +00:00
if deviceSession.TranscodingInfo.IsVideoDirect
2023-01-04 17:22:07 +00:00
data = data + " (" + tr("direct") + ")"
2022-09-06 04:38:37 +00:00
end if
2023-01-04 17:22:07 +00:00
sessionStats.push(data)
2022-09-06 04:38:37 +00:00
end if
2023-01-04 17:22:07 +00:00
if isValid(audioCodec)
data = tr("Audio Codec") + ": " + audioCodec
2023-06-01 12:43:27 +00:00
if deviceSession.TranscodingInfo.IsAudioDirect
2023-01-04 17:22:07 +00:00
data = data + " (" + tr("direct") + ")"
2023-01-04 15:42:35 +00:00
end if
2023-01-04 17:22:07 +00:00
sessionStats.push(data)
2022-09-06 04:38:37 +00:00
end if
2023-01-04 17:22:07 +00:00
if isValid(totalBitrate)
data = tr("Total Bitrate") + ": " + getDisplayBitrate(totalBitrate)
sessionStats.push(data)
2022-09-22 17:43:54 +00:00
end if
2022-09-06 04:38:37 +00:00
2023-01-04 17:22:07 +00:00
if isValid(audioChannels)
data = tr("Audio Channels") + ": " + Str(audioChannels)
sessionStats.push(data)
2023-01-04 15:42:35 +00:00
end if
2023-01-04 17:22:07 +00:00
end if
2022-09-22 17:43:54 +00:00
2023-01-04 17:22:07 +00:00
if havePlaybackInfo()
stream = m.playbackInfo.mediaSources[0].MediaStreams[0]
sessionStats.push("** " + tr("Stream Information") + " **")
if isValid(stream.Container)
data = tr("Container") + ": " + stream.Container
sessionStats.push(data)
2023-01-04 15:42:35 +00:00
end if
2023-01-04 17:22:07 +00:00
if isValid(stream.Size)
data = tr("Size") + ": " + stream.Size
sessionStats.push(data)
2023-01-04 15:42:35 +00:00
end if
2023-01-04 17:22:07 +00:00
if isValid(stream.BitRate)
data = tr("Bit Rate") + ": " + getDisplayBitrate(stream.BitRate)
sessionStats.push(data)
end if
if isValid(stream.Codec)
data = tr("Codec") + ": " + stream.Codec
sessionStats.push(data)
end if
if isValid(stream.CodecTag)
data = tr("Codec Tag") + ": " + stream.CodecTag
sessionStats.push(data)
end if
if isValid(stream.VideoRangeType)
data = tr("Video range type") + ": " + stream.VideoRangeType
sessionStats.push(data)
2023-01-04 15:42:35 +00:00
end if
2023-01-04 17:22:07 +00:00
if isValid(stream.PixelFormat)
data = tr("Pixel format") + ": " + stream.PixelFormat
sessionStats.push(data)
end if
if isValid(stream.Width) and isValid(stream.Height)
data = tr("WxH") + ": " + Str(stream.Width) + " x " + Str(stream.Height)
sessionStats.push(data)
end if
if isValid(stream.Level)
data = tr("Level") + ": " + Str(stream.Level)
sessionStats.push(data)
end if
end if
2022-09-22 17:43:54 +00:00
2023-01-04 17:22:07 +00:00
return sessionStats
end function
2022-09-22 17:43:54 +00:00
2023-01-04 17:22:07 +00:00
function havePlaybackInfo()
if not isValid(m.playbackInfo)
return false
end if
if not isValid(m.playbackInfo.mediaSources)
return false
end if
if m.playbackInfo.mediaSources.Count() <= 0
return false
end if
if not isValid(m.playbackInfo.mediaSources[0].MediaStreams)
return false
end if
if m.playbackInfo.mediaSources[0].MediaStreams.Count() <= 0
return false
end if
return true
end function
function getDisplayBitrate(bitrate)
if bitrate > 1000000
return Str(Fix(bitrate / 1000000)) + " Mbps"
else
return Str(Fix(bitrate / 1000)) + " Kbps"
end if
end function