1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

avformat/rtsp: add error code handling for ff_rtsp_skip_packet()

Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
This commit is contained in:
Limin Wang 2021-12-06 10:37:08 +08:00
parent f210766a55
commit 6d42af02f5
3 changed files with 18 additions and 8 deletions

View File

@ -1145,7 +1145,7 @@ void ff_rtsp_parse_line(AVFormatContext *s,
} }
/* skip a RTP/TCP interleaved packet */ /* 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; RTSPState *rt = s->priv_data;
int ret, len, len1; int ret, len, len1;
@ -1153,7 +1153,7 @@ void ff_rtsp_skip_packet(AVFormatContext *s)
ret = ffurl_read_complete(rt->rtsp_hd, buf, 3); ret = ffurl_read_complete(rt->rtsp_hd, buf, 3);
if (ret != 3) if (ret != 3)
return; return ret < 0 ? ret : AVERROR(EIO);
len = AV_RB16(buf + 1); len = AV_RB16(buf + 1);
av_log(s, AV_LOG_TRACE, "skipping RTP packet len=%d\n", len); 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); len1 = sizeof(buf);
ret = ffurl_read_complete(rt->rtsp_hd, buf, len1); ret = ffurl_read_complete(rt->rtsp_hd, buf, len1);
if (ret != len1) if (ret != len1)
return; return ret < 0 ? ret : AVERROR(EIO);
len -= len1; len -= len1;
} }
return 0;
} }
int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply, int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply,
@ -1201,8 +1203,11 @@ start:
if (ch == '$' && q == buf) { if (ch == '$' && q == buf) {
if (return_on_interleaved_data) { if (return_on_interleaved_data) {
return 1; return 1;
} else } else {
ff_rtsp_skip_packet(s); ret = ff_rtsp_skip_packet(s);
if (ret < 0)
return ret;
}
} else if (ch != '\r') { } else if (ch != '\r') {
if ((q - buf) < sizeof(buf) - 1) if ((q - buf) < sizeof(buf) - 1)
*q++ = ch; *q++ = ch;

View File

@ -560,8 +560,10 @@ int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply,
/** /**
* Skip a RTP/TCP interleaved packet. * 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. * Connect to the RTSP server and set up the individual media streams.

View File

@ -200,8 +200,11 @@ static int rtsp_write_packet(AVFormatContext *s, AVPacket *pkt)
ret = ff_rtsp_read_reply(s, &reply, NULL, 1, NULL); ret = ff_rtsp_read_reply(s, &reply, NULL, 1, NULL);
if (ret < 0) if (ret < 0)
return AVERROR(EPIPE); return AVERROR(EPIPE);
if (ret == 1) if (ret == 1) {
ff_rtsp_skip_packet(s); ret = ff_rtsp_skip_packet(s);
if (ret < 0)
return ret;
}
/* XXX: parse message */ /* XXX: parse message */
if (rt->state != RTSP_STATE_STREAMING) if (rt->state != RTSP_STATE_STREAMING)
return AVERROR(EPIPE); return AVERROR(EPIPE);