Commit 43cbb6ec85 for ffmpeg
commit 43cbb6ec85849315e9ad7e9b7eeb9277bd74e942
Author: Furkan Efe Can <caglarf646@gmail.com>
Date: Fri Oct 16 02:22:09 2026 +0300
tests/fate/rtsp: Test the SampleRate SDP attribute
Seven descriptions, all with the rtpmap rate at 44100 and the attribute
asking for something else, so the probed rate shows whether the attribute
was applied or ignored. sdp_flags custom_io keeps the demuxer from
opening a transport, so no socket is involved and the tests need no
sample.
Measured with libavformat/rtsp.c restored from the parent of a7b20ee103,
i.e. with atoi(), and these tests kept in place:
fate-rtsp-sdp-sample-rate passes (48000 applied)
fate-rtsp-sdp-sample-rate-leading-zero passes (048000 -> 48000)
fate-rtsp-sdp-sample-rate-int-max passes (INT_MAX applied)
fate-rtsp-sdp-sample-rate-negative fails (-1 applied)
fate-rtsp-sdp-sample-rate-zero fails (0 applied)
fate-rtsp-sdp-sample-rate-above-int-max fails (converted and applied)
fate-rtsp-sdp-sample-rate-overflow fails (atoi() overflow)
The first test is the positive control: without it the other six could
pass while the attribute was never parsed at all. The leading-zero test
passes either way; it pins the parsing base, so that replacing atoi()
with a base 0 conversion, which reads 048000 as octal, does not go
unnoticed. The two int-max tests bracket the upper bound: where long is
wider than int neither value sets ERANGE, so the bound itself is the only
thing separating them.
Signed-off-by: Furkan Efe Can <caglarf646@gmail.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
diff --git a/tests/Makefile b/tests/Makefile
index f1a3ef2f42..de71678e5c 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -252,6 +252,7 @@ include $(SRC_PATH)/tests/fate/qoa.mak
include $(SRC_PATH)/tests/fate/qt.mak
include $(SRC_PATH)/tests/fate/qtrle.mak
include $(SRC_PATH)/tests/fate/real.mak
+include $(SRC_PATH)/tests/fate/rtsp.mak
include $(SRC_PATH)/tests/fate/sbc.mak
include $(SRC_PATH)/tests/fate/screen.mak
include $(SRC_PATH)/tests/fate/segafilm.mak
diff --git a/tests/fate/rtsp.mak b/tests/fate/rtsp.mak
new file mode 100644
index 0000000000..473f592c66
--- /dev/null
+++ b/tests/fate/rtsp.mak
@@ -0,0 +1,47 @@
+FATE_RTSP_FFPROBE-$(call ALLYES, SDP_DEMUXER FILE_PROTOCOL) \
+ += fate-rtsp-sdp-sample-rate \
+ fate-rtsp-sdp-sample-rate-leading-zero \
+ fate-rtsp-sdp-sample-rate-negative \
+ fate-rtsp-sdp-sample-rate-zero \
+ fate-rtsp-sdp-sample-rate-int-max \
+ fate-rtsp-sdp-sample-rate-above-int-max \
+ fate-rtsp-sdp-sample-rate-overflow
+
+# The RealNetworks "SampleRate:integer;" attribute overrides the rate the
+# rtpmap line established. Every description below keeps the rtpmap rate at
+# 44100 while the attribute asks for something else, so the probed rate tells
+# whether the attribute was applied or ignored. custom_io keeps the demuxer
+# from opening a transport, which keeps these tests offline.
+SDP_SAMPLE_RATE_HEAD = v=0\no=- 0 0 IN IP4 127.0.0.1\ns=SampleRate\nc=IN IP4 127.0.0.1\nt=0 0\nm=audio 5004 RTP/AVP 97\na=rtpmap:97 L16/44100/1\n
+SDP_SAMPLE_RATE_PROBE = run ffprobe$(PROGSSUF)$(EXESUF) -v error \
+ -sdp_flags custom_io -protocol_whitelist file \
+ -analyzeduration 0 -probesize 32 \
+ -show_entries stream=sample_rate -print_format compact
+
+define FATE_SDP_SAMPLE_RATE_CMD
+ cleanfiles="$${cleanfiles} $${outfile}.sdp"; \
+ printf "$(SDP_SAMPLE_RATE_HEAD)a=SampleRate:integer;$(1)\n" \
+ > "$${outfile}.sdp"; \
+ $(SDP_SAMPLE_RATE_PROBE) "$$(target_path "$${outfile}.sdp")"
+endef
+
+# A valid attribute must be applied, otherwise the tests below would pass
+# without the attribute ever being parsed.
+fate-rtsp-sdp-sample-rate: CMD = $(call FATE_SDP_SAMPLE_RATE_CMD,48000)
+
+# A leading zero is part of a decimal rate, not an octal prefix.
+fate-rtsp-sdp-sample-rate-leading-zero: CMD = $(call FATE_SDP_SAMPLE_RATE_CMD,048000)
+
+# An invalid rate must leave the rtpmap rate in place.
+fate-rtsp-sdp-sample-rate-negative: CMD = $(call FATE_SDP_SAMPLE_RATE_CMD,-1)
+fate-rtsp-sdp-sample-rate-zero: CMD = $(call FATE_SDP_SAMPLE_RATE_CMD,0)
+fate-rtsp-sdp-sample-rate-overflow: CMD = $(call FATE_SDP_SAMPLE_RATE_CMD,99999999999999999999)
+
+# The two sides of the upper bound. Where long is wider than int, neither value
+# sets ERANGE, so only the bound itself separates them.
+fate-rtsp-sdp-sample-rate-int-max: CMD = $(call FATE_SDP_SAMPLE_RATE_CMD,2147483647)
+fate-rtsp-sdp-sample-rate-above-int-max: CMD = $(call FATE_SDP_SAMPLE_RATE_CMD,2147483648)
+
+FATE_FFPROBE += $(FATE_RTSP_FFPROBE-yes)
+
+fate-rtsp: $(FATE_RTSP_FFPROBE-yes)
diff --git a/tests/ref/fate/rtsp-sdp-sample-rate b/tests/ref/fate/rtsp-sdp-sample-rate
new file mode 100644
index 0000000000..3060935dce
--- /dev/null
+++ b/tests/ref/fate/rtsp-sdp-sample-rate
@@ -0,0 +1 @@
+stream|sample_rate=48000
diff --git a/tests/ref/fate/rtsp-sdp-sample-rate-above-int-max b/tests/ref/fate/rtsp-sdp-sample-rate-above-int-max
new file mode 100644
index 0000000000..56f4898a49
--- /dev/null
+++ b/tests/ref/fate/rtsp-sdp-sample-rate-above-int-max
@@ -0,0 +1 @@
+stream|sample_rate=44100
diff --git a/tests/ref/fate/rtsp-sdp-sample-rate-int-max b/tests/ref/fate/rtsp-sdp-sample-rate-int-max
new file mode 100644
index 0000000000..7d7bc781b2
--- /dev/null
+++ b/tests/ref/fate/rtsp-sdp-sample-rate-int-max
@@ -0,0 +1 @@
+stream|sample_rate=2147483647
diff --git a/tests/ref/fate/rtsp-sdp-sample-rate-leading-zero b/tests/ref/fate/rtsp-sdp-sample-rate-leading-zero
new file mode 100644
index 0000000000..3060935dce
--- /dev/null
+++ b/tests/ref/fate/rtsp-sdp-sample-rate-leading-zero
@@ -0,0 +1 @@
+stream|sample_rate=48000
diff --git a/tests/ref/fate/rtsp-sdp-sample-rate-negative b/tests/ref/fate/rtsp-sdp-sample-rate-negative
new file mode 100644
index 0000000000..56f4898a49
--- /dev/null
+++ b/tests/ref/fate/rtsp-sdp-sample-rate-negative
@@ -0,0 +1 @@
+stream|sample_rate=44100
diff --git a/tests/ref/fate/rtsp-sdp-sample-rate-overflow b/tests/ref/fate/rtsp-sdp-sample-rate-overflow
new file mode 100644
index 0000000000..56f4898a49
--- /dev/null
+++ b/tests/ref/fate/rtsp-sdp-sample-rate-overflow
@@ -0,0 +1 @@
+stream|sample_rate=44100
diff --git a/tests/ref/fate/rtsp-sdp-sample-rate-zero b/tests/ref/fate/rtsp-sdp-sample-rate-zero
new file mode 100644
index 0000000000..56f4898a49
--- /dev/null
+++ b/tests/ref/fate/rtsp-sdp-sample-rate-zero
@@ -0,0 +1 @@
+stream|sample_rate=44100