[FFmpeg-devel] [PATCH] RTSP-MS 15/15: move packet_time_start zero value assignment in asf.c

Ronald S. Bultje rsbultje
Wed Apr 15 17:26:37 CEST 2009

Hi Michael & all,

On Fri, Apr 3, 2009 at 1:04 PM, Ronald S. Bultje <rsbultje at gmail.com> wrote:
> OK, ok, I will try to take that approach and send patches for the ASF
> demuxer that fix it.

The attached patch is a minimal set required to make use of public API
possible from the RTP/ASF depacketizer. It contains three hunks (all
small), which do the following:

- the third hunk changes the return value on EOF to AVERROR_EOF. This
isn't necessary, but looks nicer
- the second hunk omits padsize for asf streams, as I mentioned
earlier [1] and documented on MSDN [2]
- the first chunk is critical. During ASF packet header parsing, we
don't do any error handling. Since I get my RTP packets one at a time,
at the end of each packet, I reach EOF and the ASF demuxer should
return so I can load the next RTP packet. Unfortunately, under these
circumstances, the ASF demuxer sets a default (which is always
wrong...) value for packet_size_left (the size of the ASF data
packet), causing the next RTP payload ASF packet header to not be
parsed, resulting in a situation where anything could happen. Instead,
we should error out and read the actual ASF packet header in the next
payload. This 2-liner does exactly that.

If this patch is OK, then I'll have an updated 14/15 implementing
RTP/ASF parsing using the default av_read_*() API coming right after.


[1] http://archives.free.net.ph/message/20081117.221741.c32dfa59.hu.html
[2] http://msdn.microsoft.com/en-us/library/cc245258(PROT.10).aspx
-------------- next part --------------
Index: libavformat/asfdec.c
--- libavformat/asfdec.c	(revision 18507)
+++ libavformat/asfdec.c	(working copy)
@@ -572,6 +572,8 @@
     if (c != 0x82) {
         if (!url_feof(pb))
             av_log(s, AV_LOG_ERROR, "ff asf bad header %x  at:%"PRId64"\n", c, url_ftell(pb));
+        else
+            return AVERROR_EOF;
     if ((c & 0x8f) == 0x82) {
         if (d || e) {
@@ -615,7 +617,7 @@
         asf->packet_segsizetype = 0x80;
     asf->packet_size_left = packet_length - padsize - rsize;
-    if (packet_length < asf->hdr.min_pktsize)
+    if (packet_length < asf->hdr.min_pktsize && !(asf->hdr.flags & 1))
         padsize += asf->hdr.min_pktsize - packet_length;
     asf->packet_padsize = padsize;
     dprintf(s, "packet: size=%d padsize=%d  left=%d\n", asf->packet_size, asf->packet_padsize, asf->packet_size_left);
@@ -702,7 +704,7 @@
     ASFStream *asf_st = 0;
     for (;;) {
-            return AVERROR(EIO);
+            return AVERROR_EOF;
         if (asf->packet_size_left < FRAME_HEADER_SIZE
             || asf->packet_segments < 1) {
             //asf->packet_size_left <= asf->packet_padsize) {

More information about the ffmpeg-devel mailing list