[FFmpeg-devel] [PATCH] avformat/rtsp: fix wrong codec setup for some sdp

Hyun Yoo easetheworld at gmail.com
Mon Oct 28 10:23:05 EET 2019


rtsp_st->sdp_payload_type is the first codec in 'm=' tag
st->codecpar->id is the first supported codec in 'a=' tag
the two is not guaranteed to be same for example when
1) the order between attributes is random(rfc4566 doesn't force it)
2) the first codec is same for 'm=' and 'a=' but it is unsupported codec
   then st->codecpar->id will be the next one in 'a='(if it's supported)

Signed-off-by: Hyun Yoo <easetheworld at gmail.com>
---
 libavformat/rtsp.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 859defa592..d0b246feb1 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -569,6 +569,9 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
             get_word(buf1, sizeof(buf1), &p);
             payload_type = atoi(buf1);
             rtsp_st = rt->rtsp_streams[rt->nb_rtsp_streams - 1];
+            // parse only sdp_payload_type specified in 'm=' tag
+            if (rtsp_st->sdp_payload_type != payload_type)
+                return;
             if (rtsp_st->stream_index >= 0) {
                 st = s->streams[rtsp_st->stream_index];
                 sdp_parse_rtpmap(s, st, rtsp_st, payload_type, p);
@@ -582,6 +585,10 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
             // let dynamic protocol handlers have a stab at the line.
             get_word(buf1, sizeof(buf1), &p);
             payload_type = atoi(buf1);
+            rtsp_st = rt->rtsp_streams[rt->nb_rtsp_streams - 1];
+            // parse only sdp_payload_type specified in 'm=' tag
+            if (rtsp_st->sdp_payload_type != payload_type)
+                return;
             if (s1->seen_rtpmap) {
                 parse_fmtp(s, rt, payload_type, buf);
             } else {
-- 
2.23.0.windows.1



More information about the ffmpeg-devel mailing list