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

Submitted by Hyun Yoo on Sept. 8, 2019, 11:51 p.m.

Details

Message ID 20190908235138.257-1-easetheworld@gmail.com
State New
Headers show

Commit Message

Hyun Yoo Sept. 8, 2019, 11:51 p.m.
From: EaseTheWorld <easetheworld@gmail.com>

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: EaseTheWorld <easetheworld@gmail.com>
---
 libavformat/rtsp.c | 7 +++++++
 1 file changed, 7 insertions(+)

Patch hide | download patch | download mbox

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index c153cac88b..be3002690e 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 {