mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-09-30 11:12:35 +02:00
An external camera could pass the connection test, play in VLC, and show a black live view that gave up after a few seconds. The two RTSP paths were not asking ffmpeg for the same thing. The one-shot _capture_rtsp_frame passed no probe settings and got ffmpeg's defaults; _stream_rtsp hard-coded -probesize 32 -analyzeduration 0. Thirty-two bytes is enough for a camera that puts its H.264 parameters in the SDP, and not enough for one that sends them in-band a moment later -- a WebRTC source republished through go2rtc, in the reporter's case. ffmpeg then starts no decoder and yields nothing at all, which is why the test button kept passing while the live view stayed black. Those settings were never chosen for external cameras: they arrived with the P2S TLS proxy (#661) as fast-start tuning for the printer camera path, where the source is a known Bambu model, and were copied here in the same commit. This path has no model to tune against and belongs on the defaults, which are a ceiling rather than a wait -- a camera that announces itself in the first packet still starts as fast as it did. Drop the probe cap from _stream_rtsp. Keep -fflags nobuffer and -flags low_delay, which bear on how long ffmpeg sits on frames it already has rather than how long it may look before it has any. Leave _capture_rtsp_frame and the per-model printer profiles alone. Tests pin the absence of both flags, the presence of the low-latency ones, and the property underneath: both RTSP paths must probe alike, or passing the test button again means nothing about the live view. The ffmpeg subprocess fakes move to backend/tests/_fixtures/external_camera.py so the SSRF suite and this one share one definition.
37 lines
1.5 KiB
Python
37 lines
1.5 KiB
Python
"""Stand-ins for the ffmpeg subprocess the external-camera paths spawn.
|
|
|
|
Both RTSP paths in ``backend.app.services.external_camera`` build an argv and
|
|
hand it to ``asyncio.create_subprocess_exec``. Tests that care about *what we
|
|
asked ffmpeg to do* — the SSRF guards, the probe settings — need to see that
|
|
argv without an ffmpeg binary being involved, so these patch the lookup and the
|
|
spawn and record the call.
|
|
"""
|
|
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
|
|
def fake_ffmpeg():
|
|
"""Pretend ffmpeg is installed, so the paths get as far as building argv."""
|
|
return patch("backend.app.services.external_camera.get_ffmpeg_path", return_value="/usr/bin/ffmpeg")
|
|
|
|
|
|
def spawn_spy(returncode: int | None = 0, stdout: bytes = b"\xff\xd8" + b"\x00" * 200):
|
|
"""Stand in for the ffmpeg subprocess, recording the argv it was handed.
|
|
|
|
The streaming path reads until EOF, so stdout.read returns b"" and the
|
|
generator finishes immediately — these tests are about whether ffmpeg was
|
|
launched and with what, not about frame extraction.
|
|
"""
|
|
process = MagicMock()
|
|
process.returncode = returncode
|
|
process.communicate = AsyncMock(return_value=(stdout, b""))
|
|
process.stdout.read = AsyncMock(return_value=b"")
|
|
process.stderr.read = AsyncMock(return_value=b"")
|
|
process.wait = AsyncMock(return_value=returncode)
|
|
process.kill = MagicMock()
|
|
process.terminate = MagicMock()
|
|
return patch(
|
|
"backend.app.services.external_camera.asyncio.create_subprocess_exec",
|
|
new=AsyncMock(return_value=process),
|
|
)
|