rpi: prevent invalid MJPEG sizes (#6080)

width and height of MJPEG frames must be multiple of 8 and less than
2048, otherwise they cannot be routed with RTP/RTSP.
This commit is contained in:
Alessandro Ros
2026-08-15 16:27:41 +02:00
committed by GitHub
parent c990fad680
commit 78081d71d5
2 changed files with 29 additions and 1 deletions
+18
View File
@@ -414,6 +414,24 @@ func TestConfErrors(t *testing.T) {
" source: rpiCamera\n",
"'rpiCamera' with same camera ID 0 is used as source in two paths, 'cam1' and 'cam2'",
},
{
"invalid rpi camera mjpeg width",
"paths:\n" +
" cam:\n" +
" source: rpiCamera\n" +
" rpiCameraCodec: mjpeg\n" +
" rpiCameraWidth: 1921\n",
"'rpiCameraWidth' must be a multiple of 8 and less than 2048 when using MJPEG",
},
{
"invalid rpi camera mjpeg height",
"paths:\n" +
" cam:\n" +
" source: rpiCamera\n" +
" rpiCameraCodec: mjpeg\n" +
" rpiCameraHeight: 2048\n",
"'rpiCameraHeight' must be a multiple of 8 and less than 2048 when using MJPEG",
},
{
"invalid srt publish passphrase",
"paths:\n" +
+11 -1
View File
@@ -585,7 +585,6 @@ func (pconf *Path) validate(
}
case pconf.Source == "rpiCamera":
if pconf.RPICameraWidth == 0 {
return fmt.Errorf("invalid 'rpiCameraWidth' value")
}
@@ -594,6 +593,17 @@ func (pconf *Path) validate(
return fmt.Errorf("invalid 'rpiCameraHeight' value")
}
if pconf.RPICameraCodec == "mjpeg" ||
(pconf.RPICameraSecondary && pconf.RPICameraCodec == "auto") {
if pconf.RPICameraWidth >= 2048 || (pconf.RPICameraWidth%8) != 0 {
return fmt.Errorf("'rpiCameraWidth' must be a multiple of 8 and less than 2048 when using MJPEG")
}
if pconf.RPICameraHeight >= 2048 || (pconf.RPICameraHeight%8) != 0 {
return fmt.Errorf("'rpiCameraHeight' must be a multiple of 8 and less than 2048 when using MJPEG")
}
}
switch pconf.RPICameraExposure {
case "normal", "short", "long", "custom":
default: