From f84c943438b87fb9b250e124fae8a757dbb47479 Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 13 Nov 2026 12:47:48 -0500 Subject: [PATCH] Browse channels before tuning and contain Tunarr memory usage --- .env.example | 2 + README.md | 2 +- compose.yaml | 3 ++ roku/README.md | 9 ++--- roku/components/Guide.brs | 72 +++++++++++++++++++++++++--------- roku/components/RetroScene.brs | 16 ++++---- roku/components/RetroScene.xml | 11 ++++++ 7 files changed, 82 insertions(+), 33 deletions(-) diff --git a/.env.example b/.env.example index 224c41e..5f393bb 100644 --- a/.env.example +++ b/.env.example @@ -5,6 +5,8 @@ RETROTV_NAME=retroLabs RETROTV_MEDIA_DIR=./data/media TUNARR_LOOPBACK_PORT=14242 TUNARR_CPUS=2 +TUNARR_MEMORY_LIMIT=2800m +TUNARR_SESSION_STALENESS_MS=15000 # NWS point coordinates, latitude and longitude. Leave blank to disable. RETROTV_WEATHER_POINT= diff --git a/README.md b/README.md index f5026d4..49a4a10 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ docker compose ps docker compose logs -f bridge tunarr ``` -Use `http://:4242/web/` for the programming UI and `/api/v1/health` for the bridge health check. Tunarr's internal port 8000 is published only on host loopback port 14242. The bridge uses host networking for SSDP on UDP 1900 and binds HTTP to the configured LAN IP. Admin and device access currently share the trusted LAN with no bridge-level authentication. Compose persists Tunarr's configuration and the bridge's UUID in named volumes. Tunarr defaults to two CPU cores of capacity to limit the impact of scans and transcoding on the host. Set `TUNARR_CPUS` in `.env` to change the limit. +Use `http://:4242/web/` for the programming UI and `/api/v1/health` for the bridge health check. Tunarr's internal port 8000 is published only on host loopback port 14242. The bridge uses host networking for SSDP on UDP 1900 and binds HTTP to the configured LAN IP. Admin and device access currently share the trusted LAN with no bridge-level authentication. Compose persists Tunarr's configuration and the bridge's UUID in named volumes. Tunarr defaults to two CPU cores of capacity to limit the impact of scans and transcoding on the host. Set `TUNARR_CPUS` in `.env` to change the limit. Tunarr also defaults to a 2800 MiB memory cap without container swap to contain memory pressure during concurrent streams. Set `TUNARR_MEMORY_LIMIT` to adjust it. Idle HLS connections become eligible for cleanup after 15 seconds, with Tunarr checking on its scheduled cleanup pass. ## NVIDIA transcoding on this host diff --git a/compose.yaml b/compose.yaml index 8592c58..55b7123 100644 --- a/compose.yaml +++ b/compose.yaml @@ -2,10 +2,13 @@ services: tunarr: image: ghcr.io/chrisbenincasa/tunarr:2026.11.2@sha256:50919e89db8c60f7fe9f3561f84ef77fb5710ccaac5db5599e9b9993c519dea9 cpus: ${TUNARR_CPUS:-2} + mem_limit: ${TUNARR_MEMORY_LIMIT:-2800m} + memswap_limit: ${TUNARR_MEMORY_LIMIT:-2800m} restart: unless-stopped environment: TZ: America/New_York TUNARR_SERVER_TRUST_PROXY: "true" + TUNARR_SESSION_STALENESS_MS: ${TUNARR_SESSION_STALENESS_MS:-15000} ports: - "127.0.0.1:${TUNARR_LOOPBACK_PORT:-14242}:8000" volumes: diff --git a/roku/README.md b/roku/README.md index dcc8e9a..caebc00 100644 --- a/roku/README.md +++ b/roku/README.md @@ -17,12 +17,11 @@ On first launch, the app searches for the bridge. If multicast discovery is unavailable, select **Enter server address** and enter the bridge host's LAN IP or hostname. Use `IP:port` if the bridge uses a port other than `4242`. -- **Up / Down** tunes the previous or next channel. -- **OK** shows the banner or retries a failed channel. +- **Up / Down** opens the guide on the adjacent channel. In the guide, it moves the highlight without tuning. +- **OK** tunes the highlighted channel in the guide. During playback it shows the banner or retries a failed channel. - **Left / Replay** returns to the last channel. -- **Star** opens the program guide, channel refresh, and server selection. +- **Star** opens the guide. Press it from the guide for channel refresh and server selection. - **Back** closes the guide or menu, then exits from the tuner. -The guide shows current and upcoming titles. The weather channel is a native -placeholder. Playback starts from the live HLS playlist supplied by the bridge. +The app opens on the guide. The details pane shows current and upcoming titles for the highlighted channel. Channel 99 displays local weather. Playback starts from the live HLS playlist supplied by the bridge. SSDP discovery, playback, and live timing require validation on Roku hardware. diff --git a/roku/components/Guide.brs b/roku/components/Guide.brs index 511612d..cf449c4 100644 --- a/roku/components/Guide.brs +++ b/roku/components/Guide.brs @@ -1,5 +1,7 @@ sub showPanel(mode as string, title as string, status as string, titles as object) m.panelMode = mode + m.guideDetails.visible = false + m.menu.itemSize = [1150, 50] m.panelTitle.text = title m.panelStatus.text = status content = CreateObject("roSGNode", "ContentNode") @@ -51,11 +53,12 @@ sub onMenuSelect(event as object) findServer("", false) end if else if m.panelMode = "guide" + if index < 0 or index >= m.guideIds.Count() then return id = m.guideIds[index] for i = 0 to m.channels.Count() - 1 if m.channels[i].id = id closePanel() - tune(i) + if i <> m.channelIndex then tune(i) exit for end if end for @@ -64,42 +67,73 @@ sub onMenuSelect(event as object) end if end sub -sub openGuide() +sub openGuide(offset = 0 as integer) if m.guideRequest <> invalid m.guideRequest.UnobserveFieldScoped("result") m.guideRequest.control = "stop" end if + m.guideOffset = offset showPanel("guideLoading", "Program guide", "Loading the schedule…", []) m.guideRequest = startRequest({url: m.server.baseUrl + "/api/v1/guide?hours=3"}, "onGuide") end sub sub onGuide(event as object) + if m.guideRequest = invalid or not m.guideRequest.IsSameNode(event.GetRoSGNode()) then return m.guideRequest = invalid if m.panelMode <> "guideLoading" then return data = event.GetData().data - if data = invalid or GetInterface(data.channels, "ifArray") = invalid + if data = invalid or GetInterface(data.channels, "ifArray") = invalid or data.channels.Count() = 0 showPanel("guideError", "Program guide", "Could not load the schedule.", ["Retry"]) return end if syncClock(data.serverTime) - now = currentEpoch() m.guideIds = [] + m.guideChannels = data.channels titles = [] - for each channel in data.channels - current = invalid - upcoming = invalid - if GetInterface(channel.programs, "ifArray") <> invalid - for each program in channel.programs - if parseUtc(program.start) > now - upcoming = program - exit for - else if parseUtc(program.stop) > now - current = program - end if - end for - end if - titles.Push(channelLabel(channel) + " | " + programTitle(current) + " / " + programTitle(upcoming)) + selected = 0 + for each channel in m.guideChannels + if m.channelIndex >= 0 and channel.id = m.channels[m.channelIndex].id then selected = titles.Count() + titles.Push(channelLabel(channel)) m.guideIds.Push(channel.id) end for - showPanel("guide", "Program guide", "CHANNEL | NOW / NEXT", titles) + selected = (selected + m.guideOffset + titles.Count()) mod titles.Count() + showPanel("guide", "Program guide", "Up / Down Browse OK Watch Star Options", titles) + m.menu.itemSize = [430, 50] + m.guideDetails.visible = true + m.menu.jumpToItem = selected + showGuideDetails(selected) +end sub + +sub onGuideFocus(event as object) + if m.panelMode = "guide" then showGuideDetails(event.GetData()) +end sub + +sub showGuideDetails(index as integer) + if index < 0 or index >= m.guideChannels.Count() then return + channel = m.guideChannels[index] + m.guideChannelTitle.text = channelLabel(channel) + m.guideNow.text = "" + m.guideNext.text = "" + m.guideLater.text = "" + if channel.type = "weather" + m.guideNow.text = "LOCAL WEATHER" + m.guideNext.text = "Current conditions, forecasts and alerts" + return + end if + + now = currentEpoch() + upcoming = [] + current = invalid + for each program in channel.programs + if parseUtc(program.start) > now + upcoming.Push(program) + else if parseUtc(program.stop) > now + current = program + end if + end for + m.guideNow.text = "NOW" + Chr(10) + programTitle(current) + nextProgram = invalid + if upcoming.Count() > 0 then nextProgram = upcoming[0] + m.guideNext.text = "NEXT" + Chr(10) + programTitle(nextProgram) + if upcoming.Count() > 1 then m.guideLater.text = "LATER" + Chr(10) + programTitle(upcoming[1]) end sub diff --git a/roku/components/RetroScene.brs b/roku/components/RetroScene.brs index d68bf60..0f457f0 100644 --- a/roku/components/RetroScene.brs +++ b/roku/components/RetroScene.brs @@ -1,5 +1,5 @@ sub init() - for each id in ["video", "weather", "banner", "channelTitle", "clock", "nowTitle", "nextTitle", "progressTrack", "progress", "playbackStatus", "panel", "panelTitle", "panelStatus", "menu", "bannerTimer", "clockTimer", "retryTimer"] + for each id in ["video", "weather", "banner", "channelTitle", "clock", "nowTitle", "nextTitle", "progressTrack", "progress", "playbackStatus", "panel", "panelTitle", "panelStatus", "menu", "bannerTimer", "clockTimer", "retryTimer", "guideDetails", "guideChannelTitle", "guideNow", "guideNext", "guideLater"] m[id] = m.top.FindNode(id) end for m.channels = [] @@ -11,6 +11,7 @@ sub init() m.clockReference = CreateObject("roTimespan") m.menu.ObserveField("itemSelected", "onMenuSelect") + m.menu.ObserveField("itemFocused", "onGuideFocus") m.video.ObserveField("state", "onVideoState") initWeather() m.bannerTimer.ObserveField("fire", "hideBanner") @@ -83,9 +84,8 @@ sub onChannels(event as object) return end if - closePanel() m.previousIndex = -1 - tune(0) + openGuide() end sub function startRequest(request as object, callback as string) as object @@ -305,11 +305,11 @@ function onKeyEvent(key as string, press as boolean) as boolean closePanel() return true end if - if key = "options" and m.channelIndex >= 0 - if m.panel.visible - closePanel() - else + if key = "options" and m.channels.Count() > 0 + if m.panelMode = "guide" showPanel("options", "retroLabs", m.server.name + " " + m.server.baseUrl, ["Program guide", "Refresh channels", "Change server"]) + else + openGuide() end if return true end if @@ -318,7 +318,7 @@ function onKeyEvent(key as string, press as boolean) as boolean if key = "up" or key = "down" direction = 1 if key = "up" then direction = -1 - tune((m.channelIndex + direction + m.channels.Count()) MOD m.channels.Count()) + openGuide(direction) return true else if key = "left" or key = "replay" if m.previousIndex >= 0 then tune(m.previousIndex) diff --git a/roku/components/RetroScene.xml b/roku/components/RetroScene.xml index d799a8a..1cbe20b 100644 --- a/roku/components/RetroScene.xml +++ b/roku/components/RetroScene.xml @@ -47,6 +47,17 @@ + + +