[FFmpeg-devel] [PATCH] Core Audio Format demuxer (v7)

Daniel Verkamp daniel
Tue Sep 8 08:34:16 CEST 2009


On Mon, Sep 7, 2009 at 7:06 AM, Peter Ross<pross at xvid.org> wrote:
[...]

Attached is a patch on top of this revision to allow decoding files
that have >0 frames per packet and bytes per packet but unknown (-1)
data size.  This is a valid combination by my reading of the CAF spec.

Thanks,
-- Daniel Verkamp
-------------- next part --------------
diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
index 26ba158..c4aad1b 100644
--- a/libavformat/cafdec.c
+++ b/libavformat/cafdec.c
@@ -220,7 +220,7 @@ static int read_header(AVFormatContext *s,
         case MKBETAG('d','a','t','a'):
             url_fskip(pb, 4); /* edit count */
             caf->data_start = url_ftell(pb);
-            caf->data_size  = size - 4;
+            caf->data_size  = size < 0 ? -1 : size - 4;
             if (caf->data_size > 0 && !url_is_streamed(pb))
                 url_fskip(pb, caf->data_size);
             found_data = 1;
@@ -258,9 +258,9 @@ static int read_header(AVFormatContext *s,
     if (!found_data)
         return AVERROR_INVALIDDATA;
 
-    if (caf->data_size > 0 && caf->bytes_per_packet > 0 &&
-        caf->frames_per_packet > 0) {
-        st->nb_frames = (caf->data_size / caf->bytes_per_packet) * caf->frames_per_packet;
+    if (caf->bytes_per_packet > 0 && caf->frames_per_packet > 0) {
+        if (caf->data_size > 0)
+            st->nb_frames = (caf->data_size / caf->bytes_per_packet) * caf->frames_per_packet;
     } else if (st->nb_index_entries) {
         st->codec->bit_rate = st->codec->sample_rate * caf->data_size * 8 /
                               st->duration;
@@ -290,15 +290,17 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
     AVStream *st      = s->streams[0];
     CaffContext *caf  = s->priv_data;
     int res, pkt_size = 0, pkt_frames = 0;
-    int64_t left;
+    int64_t left      = CAF_MAX_PKT_SIZE;
 
     if (url_feof(pb))
         return AVERROR_IO;
 
     /* don't read past end of data chunk */
-    left = (caf->data_start + caf->data_size) - url_ftell(pb);
-    if (left <= 0)
-        return AVERROR_IO;
+    if (caf->data_size > 0) {
+        left = (caf->data_start + caf->data_size) - url_ftell(pb);
+        if (left <= 0)
+            return AVERROR_IO;
+    }
 
     pkt_frames = caf->frames_per_packet;
     pkt_size   = caf->bytes_per_packet;
@@ -348,7 +350,8 @@ static int read_seek(AVFormatContext *s, int stream_index,
     if (caf->frames_per_packet > 0 && caf->bytes_per_packet > 0) {
         /* calculate new byte position based on target frame position */
         pos = caf->bytes_per_packet * timestamp / caf->frames_per_packet;
-        pos = FFMIN(pos, caf->data_size);
+        if (caf->data_size > 0)
+            pos = FFMIN(pos, caf->data_size);
         caf->packet_cnt = pos / caf->bytes_per_packet;
         caf->frame_cnt  = caf->frames_per_packet * caf->packet_cnt;
     } else if (st->nb_index_entries) {



More information about the ffmpeg-devel mailing list