import "pkg:/source/utils/config.brs" import "pkg:/source/utils/misc.brs" import "pkg:/source/utils/deviceCapabilities.brs" import "pkg:/source/api/baserequest.brs" import "pkg:/source/api/sdk.bs" sub init() m.top.functionName = "getPlaybackInfoTask" end sub function ItemPostPlaybackInfo(id as string, mediaSourceId = "" as string, audioTrackIndex = -1 as integer, startTimeTicks = 0 as longinteger) currentView = m.global.sceneManager.callFunc("getActiveScene") currentItem = m.global.queueManager.callFunc("getCurrentItem") body = { "DeviceProfile": getDeviceProfile() } params = { "UserId": m.global.session.user.id, "StartTimeTicks": currentItem.startingPoint, "IsPlayback": true, "AutoOpenLiveStream": true, "MaxStreamingBitrate": "140000000", "MaxStaticBitrate": "140000000", "SubtitleStreamIndex": currentView.selectedSubtitle, "MediaSourceId": currentItem.id, "AudioStreamIndex": currentItem.selectedAudioStreamIndex } req = APIRequest(Substitute("Items/{0}/PlaybackInfo", id), params) req.SetRequest("POST") return postJson(req, FormatJson(body)) end function ' 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. sub getPlaybackInfoTask() sessions = api.sessions.Get({ "deviceId": m.global.device.serverDeviceName }) m.playbackInfo = ItemPostPlaybackInfo(m.top.videoID) if isValid(sessions) and sessions.Count() > 0 m.top.data = { playbackInfo: GetTranscodingStats(sessions[0]) } else m.top.data = { playbackInfo: [tr("Unable to get playback information")] } end if end sub function GetTranscodingStats(deviceSession) sessionStats = { data: [] } 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 if isValid(transcodingReasons) and transcodingReasons.Count() > 0 sessionStats.data.push("
" + tr("Transcoding Information") + "
") for each item in transcodingReasons sessionStats.data.push("• " + tr("Reason") + ": " + item) end for end if if isValid(videoCodec) data = "• " + tr("Video Codec") + ": " + videoCodec if deviceSession.TranscodingInfo.IsVideoDirect data = data + " (" + tr("direct") + ")" end if sessionStats.data.push(data) end if if isValid(audioCodec) data = "• " + tr("Audio Codec") + ": " + audioCodec if deviceSession.TranscodingInfo.IsAudioDirect data = data + " (" + tr("direct") + ")" end if sessionStats.data.push(data) end if if isValid(totalBitrate) data = "• " + tr("Total Bitrate") + ": " + getDisplayBitrate(totalBitrate) sessionStats.data.push(data) end if if isValid(audioChannels) data = "• " + tr("Audio Channels") + ": " + Str(audioChannels) sessionStats.data.push(data) end if else sessionStats.data.push("
" + tr("Direct playing") + "
") sessionStats.data.push("" + tr("The source file is entirely compatible with this client and the session is receiving the file without modifications.") + "") end if if havePlaybackInfo() stream = m.playbackInfo.mediaSources[0].MediaStreams[0] sessionStats.data.push("
" + tr("Stream Information") + "
") if isValid(stream.Container) data = "• " + tr("Container") + ": " + stream.Container sessionStats.data.push(data) end if if isValid(stream.Size) data = "• " + tr("Size") + ": " + stream.Size sessionStats.data.push(data) end if if isValid(stream.BitRate) data = "• " + tr("Bit Rate") + ": " + getDisplayBitrate(stream.BitRate) sessionStats.data.push(data) end if if isValid(stream.Codec) data = "• " + tr("Codec") + ": " + stream.Codec sessionStats.data.push(data) end if if isValid(stream.CodecTag) data = "• " + tr("Codec Tag") + ": " + stream.CodecTag sessionStats.data.push(data) end if if isValid(stream.VideoRangeType) data = "• " + tr("Video range type") + ": " + stream.VideoRangeType sessionStats.data.push(data) end if if isValid(stream.PixelFormat) data = "• " + tr("Pixel format") + ": " + stream.PixelFormat sessionStats.data.push(data) end if if isValid(stream.Width) and isValid(stream.Height) data = "• " + tr("WxH") + ": " + Str(stream.Width) + " x " + Str(stream.Height) sessionStats.data.push(data) end if if isValid(stream.Level) data = "• " + tr("Level") + ": " + Str(stream.Level) sessionStats.data.push(data) end if end if return sessionStats end function 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