summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2010-10-13 08:12:23 +0000
committerMartin Storsjö <martin@martin.st>2010-10-13 08:12:23 +0000
commit4ffff36751d7ac47643f088306f7620bd16f391f (patch)
tree2c26eff1444edc8616b8303d76835f85d7d7e258
parentcf5fe8ec9ec0c5b7489ff4ffe1d48eaf1e274d15 (diff)
rtpdec: Split out storing of the depacketization return value to a separate function
This makes the code less fragile and easier to understand. Originally committed as revision 25457 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavformat/rtpdec.c56
1 files changed, 26 insertions, 30 deletions
diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
index 033f336996..51583c081a 100644
--- a/libavformat/rtpdec.c
+++ b/libavformat/rtpdec.c
@@ -471,18 +471,14 @@ static int rtp_parse_packet_internal(RTPDemuxContext *s, AVPacket *pkt,
if (!st) {
/* specific MPEG2TS demux support */
ret = ff_mpegts_parse_packet(s->ts, pkt, buf, len);
- if (ret < 0) {
- s->prev_ret = -1;
+ if (ret < 0)
return -1;
- }
if (ret < len) {
s->read_buf_size = len - ret;
memcpy(s->buf, buf + ret, s->read_buf_size);
s->read_buf_index = 0;
- s->prev_ret = 1;
return 1;
}
- s->prev_ret = 0;
return 0;
} else if (s->parse_packet) {
rv = s->parse_packet(s->ic, s->dynamic_protocol_context,
@@ -531,7 +527,6 @@ static int rtp_parse_packet_internal(RTPDemuxContext *s, AVPacket *pkt,
// now perform timestamp things....
finalize_packet(s, pkt, timestamp);
- s->prev_ret = rv;
return rv;
}
@@ -606,19 +601,10 @@ static int rtp_parse_queued_packet(RTPDemuxContext *s, AVPacket *pkt)
av_free(s->queue);
s->queue = next;
s->queue_len--;
- return rv ? rv : has_next_packet(s);
+ return rv;
}
-/**
- * Parse an RTP or RTCP packet directly sent as a buffer.
- * @param s RTP parse context.
- * @param pkt returned packet
- * @param bufptr pointer to the input buffer or NULL to read the next packets
- * @param len buffer len
- * @return 0 if a packet is returned, 1 if a packet is returned and more can follow
- * (use buf as NULL to read the next). -1 if no packet (error or no more packet).
- */
-int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
+static int rtp_parse_one_packet(RTPDemuxContext *s, AVPacket *pkt,
uint8_t **bufptr, int len)
{
uint8_t* buf = bufptr ? *bufptr : NULL;
@@ -640,27 +626,20 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
rv= s->parse_packet(s->ic, s->dynamic_protocol_context,
s->st, pkt, &timestamp, NULL, 0, flags);
finalize_packet(s, pkt, timestamp);
- s->prev_ret = rv;
- return rv ? rv : has_next_packet(s);
+ return rv;
} else {
// TODO: Move to a dynamic packet handler (like above)
- if (s->read_buf_index >= s->read_buf_size) {
- s->prev_ret = -1;
+ if (s->read_buf_index >= s->read_buf_size)
return -1;
- }
ret = ff_mpegts_parse_packet(s->ts, pkt, s->buf + s->read_buf_index,
s->read_buf_size - s->read_buf_index);
- if (ret < 0) {
- s->prev_ret = -1;
+ if (ret < 0)
return -1;
- }
s->read_buf_index += ret;
if (s->read_buf_index < s->read_buf_size)
return 1;
- else {
- s->prev_ret = 0;
- return has_next_packet(s);
- }
+ else
+ return 0;
}
}
@@ -687,7 +666,7 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
} else if (diff <= 1) {
/* Correct packet */
rv = rtp_parse_packet_internal(s, pkt, buf, len);
- return rv ? rv : has_next_packet(s);
+ return rv;
} else {
/* Still missing some packet, enqueue this one. */
enqueue_packet(s, buf, len);
@@ -701,6 +680,23 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
}
}
+/**
+ * Parse an RTP or RTCP packet directly sent as a buffer.
+ * @param s RTP parse context.
+ * @param pkt returned packet
+ * @param bufptr pointer to the input buffer or NULL to read the next packets
+ * @param len buffer len
+ * @return 0 if a packet is returned, 1 if a packet is returned and more can follow
+ * (use buf as NULL to read the next). -1 if no packet (error or no more packet).
+ */
+int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
+ uint8_t **bufptr, int len)
+{
+ int rv = rtp_parse_one_packet(s, pkt, bufptr, len);
+ s->prev_ret = rv;
+ return rv ? rv : has_next_packet(s);
+}
+
void rtp_parse_close(RTPDemuxContext *s)
{
ff_rtp_reset_packet_queue(s);