diff mbox series

[FFmpeg-devel,v2,5/6] avformat/rtsp: add error code handling for ff_rtsp_skip_packet()

Message ID 1638765904-2521-5-git-send-email-lance.lmwang@gmail.com
State Accepted
Commit 6d42af02f566c2a14a72bc13517add071c1d2a2b
Headers show
Series [FFmpeg-devel,v2,1/6] avformat/rtsp: remove redundant assignment | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Lance Wang Dec. 6, 2021, 4:45 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavformat/rtsp.c    | 15 ++++++++++-----
 libavformat/rtsp.h    |  4 +++-
 libavformat/rtspenc.c |  7 +++++--
 3 files changed, 18 insertions(+), 8 deletions(-)

Comments

Martin Storsjö Dec. 7, 2021, 9:31 a.m. UTC | #1
On Mon, 6 Dec 2021, lance.lmwang@gmail.com wrote:

> From: Limin Wang <lance.lmwang@gmail.com>
>
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
> libavformat/rtsp.c    | 15 ++++++++++-----
> libavformat/rtsp.h    |  4 +++-
> libavformat/rtspenc.c |  7 +++++--
> 3 files changed, 18 insertions(+), 8 deletions(-)
This should be fine.

// Martin
diff mbox series

Patch

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index b3d1e91..4ae810d 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1145,7 +1145,7 @@  void ff_rtsp_parse_line(AVFormatContext *s,
 }
 
 /* skip a RTP/TCP interleaved packet */
-void ff_rtsp_skip_packet(AVFormatContext *s)
+int ff_rtsp_skip_packet(AVFormatContext *s)
 {
     RTSPState *rt = s->priv_data;
     int ret, len, len1;
@@ -1153,7 +1153,7 @@  void ff_rtsp_skip_packet(AVFormatContext *s)
 
     ret = ffurl_read_complete(rt->rtsp_hd, buf, 3);
     if (ret != 3)
-        return;
+        return ret < 0 ? ret : AVERROR(EIO);
     len = AV_RB16(buf + 1);
 
     av_log(s, AV_LOG_TRACE, "skipping RTP packet len=%d\n", len);
@@ -1165,9 +1165,11 @@  void ff_rtsp_skip_packet(AVFormatContext *s)
             len1 = sizeof(buf);
         ret = ffurl_read_complete(rt->rtsp_hd, buf, len1);
         if (ret != len1)
-            return;
+            return ret < 0 ? ret : AVERROR(EIO);
         len -= len1;
     }
+
+    return 0;
 }
 
 int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply,
@@ -1201,8 +1203,11 @@  start:
             if (ch == '$' && q == buf) {
                 if (return_on_interleaved_data) {
                     return 1;
-                } else
-                    ff_rtsp_skip_packet(s);
+                } else {
+                    ret = ff_rtsp_skip_packet(s);
+                    if (ret < 0)
+                        return ret;
+                }
             } else if (ch != '\r') {
                 if ((q - buf) < sizeof(buf) - 1)
                     *q++ = ch;
diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h
index d6fdfe0..8b64e29 100644
--- a/libavformat/rtsp.h
+++ b/libavformat/rtsp.h
@@ -560,8 +560,10 @@  int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply,
 
 /**
  * Skip a RTP/TCP interleaved packet.
+ *
+ * @return 0 on success, < 0 on failure.
  */
-void ff_rtsp_skip_packet(AVFormatContext *s);
+int ff_rtsp_skip_packet(AVFormatContext *s);
 
 /**
  * Connect to the RTSP server and set up the individual media streams.
diff --git a/libavformat/rtspenc.c b/libavformat/rtspenc.c
index e0fed1e..2a00b3e 100644
--- a/libavformat/rtspenc.c
+++ b/libavformat/rtspenc.c
@@ -200,8 +200,11 @@  static int rtsp_write_packet(AVFormatContext *s, AVPacket *pkt)
             ret = ff_rtsp_read_reply(s, &reply, NULL, 1, NULL);
             if (ret < 0)
                 return AVERROR(EPIPE);
-            if (ret == 1)
-                ff_rtsp_skip_packet(s);
+            if (ret == 1) {
+                ret = ff_rtsp_skip_packet(s);
+                if (ret < 0)
+                    return ret;
+            }
             /* XXX: parse message */
             if (rt->state != RTSP_STATE_STREAMING)
                 return AVERROR(EPIPE);