Frontend
- Replace the Ant Design app with the shadcn/ui app as the single frontend,
keeping the portfolio side-by-side revertible in this commit.
- Drop the abandoned mdui experiment and the AntD tree so there is one app,
one router and one design system to maintain.
Live playback
- Stop racing the encoder. lowLatencyMode + liveSyncDurationCount:1 targeted a
single 4s segment, so playback ran at up to 1.10x and the forward buffer
bottomed out at 0.1s, re-buffering every segment. Measured over 40s:
buffer min 0.1s -> 8.9s, rate 1.00 constant, 0 stalls.
- Remove the 落后 labels and the page-level edge-snapping timer that fought
hls.js over two different definitions of "latency".
- Live can no longer be paused: the control is not rendered while it plays, so
the icon can never misreport state.
- Fix autoplay: muted autoplay started silently and never unmuted, and the
gesture that restored sound also toggled playback off. One owner now.
Source ("原画") rendition
- Publish the publisher's stream remuxed losslessly via -c:v copy alongside the
transcoded ones, so a source option exists even when every ladder entry
downsizes.
- Give renditions an ASCII path slug: the HLS path is part of the URL and
MediaMTX rejects non-alphanumeric paths, so 原画 could never be served.
Backend
- Supervise MediaMTX from the backend: start it at boot and restart it on exit,
never killing an origin it did not start.
- Clear stale HLS output before restarting an encoder; an ENDLIST-less playlist
left by a dead encoder hangs hls.js forever.
- Mark JSON timestamps as UTC. utcnow().isoformat() emitted a naive string that
JS read as local time, so every viewer heartbeat looked 8 hours old in UTC+8
and the live board's active-viewer count was permanently zero.
- Rebind a viewer session when it arrives on another stream instead of failing,
and survive the StrictMode double-heartbeat race on first insert.
- Replace the Linux-only /proc and os.getloadavg metrics with psutil.
- Complete MediaMTX's cookieCheck redirect inside /hls proxying, and hold the
httpx client open for the streamed body.
Housekeeping
- Ignore RainOSS (it stores accessKeySecret), runtime output, TLS keys and
.venv; remove generated screenshots, load test scripts and stray files.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
86 lines
3.4 KiB
Python
86 lines
3.4 KiB
Python
from pydantic_settings import BaseSettings
|
|
from pathlib import Path
|
|
from typing import Literal
|
|
|
|
|
|
APP_DIR = Path(__file__).resolve().parent
|
|
DEFAULT_DATA_DIR = APP_DIR / "data"
|
|
DEFAULT_DATA_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
database_url: str = f"sqlite+aiosqlite:///{(DEFAULT_DATA_DIR / 'streamcore.db').as_posix()}"
|
|
admin_password: str = "admin123"
|
|
|
|
media_origin_host: str = "127.0.0.1"
|
|
media_origin_rtmp_port: int = 1935
|
|
media_origin_api_port: int = 9997
|
|
media_origin_hls_port: int = 8888
|
|
# MediaMTX is supervised by the backend: started at boot if the origin is not
|
|
# already answering, and restarted if it dies. Set LS_MEDIA_ORIGIN_AUTOSTART=false
|
|
# to manage it externally (e.g. systemd, or an edge node's own launcher).
|
|
media_origin_autostart: bool = True
|
|
# "mediamtx" resolves via PATH; the repo-local copies are the fallback so a
|
|
# checkout works without a system-wide install. On Windows the binary sits in
|
|
# mediamtx\, on Linux/macOS it is usually a bare `mediamtx` on PATH.
|
|
media_origin_binary: str = "mediamtx"
|
|
media_origin_config: str = str(APP_DIR.parent / "mediamtx" / "mediamtx.yml")
|
|
replay_media_dir: str = str(APP_DIR.parent / "media")
|
|
hls_runtime_dir: str = str(APP_DIR.parent / "runtime" / "hls")
|
|
hls_segment_seconds: int = 4
|
|
|
|
edge_nodes: list[dict] = [
|
|
{
|
|
"id": "default",
|
|
"name": "Origin (Default)",
|
|
"host": "127.0.0.1",
|
|
"hls_port": 8888,
|
|
"api_port": 9997,
|
|
"weight": 100,
|
|
"enabled": True,
|
|
"subnet": "0.0.0.0/0",
|
|
"is_origin": True,
|
|
},
|
|
]
|
|
|
|
load_balance_strategy: Literal["round-robin", "weighted", "least-conn", "subnet"] = "subnet"
|
|
|
|
qualities: list[dict] = [
|
|
{"label": "1080p", "width": 1920, "height": 1080, "bitrate": "5000k"},
|
|
{"label": "720p", "width": 1280, "height": 720, "bitrate": "2500k"},
|
|
{"label": "480p", "width": 854, "height": 480, "bitrate": "1000k"},
|
|
{"label": "360p", "width": 640, "height": 360, "bitrate": "600k"},
|
|
]
|
|
|
|
# Extra rendition that is published alongside the configured ones: the
|
|
# publisher's own video+audio stream remuxed into HLS without re-encoding.
|
|
# It costs almost no CPU (stream copy) and gives viewers a lossless
|
|
# "原画" (source) option even when every configured rendition downsizes.
|
|
source_rendition_label: str = "原画"
|
|
source_rendition_enabled: bool = True
|
|
# On-disk/URL name for that rendition. It IS the HLS path segment, and MediaMTX
|
|
# rejects any path containing non-alphanumeric characters, so the Chinese
|
|
# display label above cannot be used here — a CI would 500 trying to serve it.
|
|
source_rendition_slug: str = "source"
|
|
|
|
transcode_profiles: dict[str, list[dict]] = {
|
|
"standard": qualities,
|
|
"bandwidth-saver": [
|
|
{"label": "720p", "width": 1280, "height": 720, "bitrate": "1800k"},
|
|
{"label": "480p", "width": 854, "height": 480, "bitrate": "800k"},
|
|
{"label": "360p", "width": 640, "height": 360, "bitrate": "450k"},
|
|
],
|
|
}
|
|
|
|
multicast_enabled: bool = True
|
|
multicast_address_base: str = "239.0.0.1"
|
|
multicast_port_base: int = 5000
|
|
|
|
brand_name: str = "StreamCore"
|
|
brand_tagline: str = "Enterprise Streaming Platform"
|
|
brand_logo_url: str = ""
|
|
|
|
model_config = {"env_prefix": "LS_"}
|
|
|
|
|
|
settings = Settings() |