Improve stream reliability with stall detection and buffer management
Add video stall detection that monitors currentTime and auto-reconnects after 15s of frozen video. Add MSE SourceBuffer trimming to prevent QuotaExceededError from killing streams silently. Handle appendBuffer errors with safe wrapper and SourceBuffer error listener. Wait for ICE gathering before sending WebRTC offers. Add go2rtc stream availability endpoint. Improve backend proxy error logging. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,20 @@ logger = logging.getLogger(__name__)
|
||||
router = APIRouter(prefix="/api/go2rtc")
|
||||
|
||||
|
||||
@router.get("/streams")
|
||||
async def get_streams():
|
||||
"""Fetch available streams from go2rtc."""
|
||||
config = get_config()
|
||||
target = f"{config.go2rtc.url}/api/streams"
|
||||
try:
|
||||
async with httpx.AsyncClient() as client:
|
||||
resp = await client.get(target, timeout=5.0)
|
||||
return resp.json()
|
||||
except Exception:
|
||||
logger.error("Failed to fetch go2rtc streams from %s", target)
|
||||
return {}
|
||||
|
||||
|
||||
@router.post("/webrtc")
|
||||
async def proxy_webrtc(request: Request, src: str):
|
||||
"""Proxy WebRTC SDP exchange to go2rtc."""
|
||||
@@ -66,5 +80,11 @@ async def proxy_mse_ws(ws: WebSocket, src: str):
|
||||
forward_to_client(),
|
||||
forward_to_upstream(),
|
||||
)
|
||||
except (WebSocketDisconnect, websockets.ConnectionClosed, Exception):
|
||||
pass
|
||||
except WebSocketDisconnect:
|
||||
logger.debug("Client disconnected from MSE proxy for %s", src)
|
||||
except websockets.ConnectionClosed:
|
||||
logger.debug("Upstream go2rtc closed for %s", src)
|
||||
except ConnectionRefusedError:
|
||||
logger.error("Cannot reach go2rtc at %s for stream %s", target, src)
|
||||
except Exception:
|
||||
logger.exception("MSE proxy error for stream %s", src)
|
||||
|
||||
Reference in New Issue
Block a user