[Ffmpeg-cvslog] CVS: ffmpeg/libavformat matroska.c, 1.11, 1.12 oggparsevorbis.c, 1.2, 1.3

Måns Rullgård CVS mru
Fri May 13 20:10:26 CEST 2005


Update of /cvsroot/ffmpeg/ffmpeg/libavformat
In directory mail:/var2/tmp/cvs-serv25698/libavformat

Modified Files:
	matroska.c oggparsevorbis.c 
Log Message:
change extradata format for vorbis


Index: matroska.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavformat/matroska.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- matroska.c	17 Mar 2005 01:25:01 -0000	1.11
+++ matroska.c	13 May 2005 18:10:23 -0000	1.12
@@ -2243,44 +2243,13 @@
 /*                 codec_id = CODEC_ID_DTS; */
             else if (!strcmp(track->codec_id,
                              MATROSKA_CODEC_ID_AUDIO_VORBIS)) {
-                unsigned char *p = track->codec_priv, *cdp;
-                int cps = track->codec_priv_size;
-                int nf, s[3], cds;
-                int i;
-
-                nf = *p++;
-                cps--;
-
-                if(nf != 2)
-                    continue;
-
-                for(i = 0; i < 2; i++){
-                    int xv;
-                    s[i] = 0;
-                    do {
-                        xv = *p++;
-                        s[i] += xv;
-                        cps--;
-                    } while(xv == 255);
-                }
-
-                s[2] = cps - s[0] - s[1];
-
-                cds = cps + 6;
-                extradata = cdp = av_malloc(cds);
-                if(extradata == NULL)
-                    return AVERROR_NOMEM;
-                extradata_size = cds;
-
-                for(i = 0; i < 3; i++){
-                    *cdp++ = s[i] >> 8;
-                    *cdp++ = s[i] & 0xff;
-                    memcpy(cdp, p, s[i]);
-                    cdp += s[i];
-                    p += s[i];
-                    cps -= s[i];
+                extradata_size = track->codec_priv_size;
+                if(extradata_size) {
+                    extradata = av_malloc(extradata_size);
+                    if(extradata == NULL)
+                        return AVERROR_NOMEM;
+                    memcpy(extradata, track->codec_priv, extradata_size);
                 }
-
                 codec_id = CODEC_ID_VORBIS;
             } else if (!strcmp(track->codec_id,
                                MATROSKA_CODEC_ID_AUDIO_MPEG2) ||

Index: oggparsevorbis.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavformat/oggparsevorbis.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- oggparsevorbis.c	10 Apr 2005 18:03:06 -0000	1.2
+++ oggparsevorbis.c	13 May 2005 18:10:23 -0000	1.3
@@ -126,25 +126,56 @@
  * [framing_flag] = read one bit | Not Used
  *    */
 
+typedef struct {
+    unsigned int len[3];
+    unsigned char *packet[3];
+} oggvorbis_private_t;
+
+
+static unsigned int
+fixup_vorbis_headers(AVFormatContext * as, oggvorbis_private_t *priv,
+                     void **buf)
+{
+    int i,offset, len;
+    unsigned char *ptr;
+
+    len = priv->len[0] + priv->len[1] + priv->len[2];
+    ptr = *buf = av_mallocz(len + len/255 + 64);
+
+    ptr[0] = 2;
+    offset = 1;
+    offset += av_xiphlacing(&ptr[offset], priv->len[0]);
+    offset += av_xiphlacing(&ptr[offset], priv->len[1]);
+    for(i = 0; i < 3; i++) {
+        memcpy(&ptr[offset], priv->packet[i], priv->len[i]);
+        offset += priv->len[i];
+    }
+    *buf = av_realloc(*buf, offset);
+    return offset;
+}
+
+
 static int
 vorbis_header (AVFormatContext * s, int idx)
 {
     ogg_t *ogg = s->priv_data;
     ogg_stream_t *os = ogg->streams + idx;
     AVStream *st = s->streams[idx];
-    int cds = st->codec.extradata_size + os->psize + 2;
-    uint8_t *cdp;
+    oggvorbis_private_t *priv;
 
     if (os->seq > 2)
         return 0;
 
-    st->codec.extradata = av_realloc (st->codec.extradata, cds);
-    cdp = st->codec.extradata + st->codec.extradata_size;
-    *cdp++ = os->psize >> 8;
-    *cdp++ = os->psize & 0xff;
-    memcpy (cdp, os->buf + os->pstart, os->psize);
-    st->codec.extradata_size = cds;
+    if(os->seq == 0) {
+        os->private = av_mallocz(sizeof(oggvorbis_private_t));
+        if(!os->private)
+            return 0;
+    }
 
+    priv = os->private;
+    priv->len[os->seq] = os->psize;
+    priv->packet[os->seq] = av_mallocz(os->psize);
+    memcpy(priv->packet[os->seq], os->buf + os->pstart, os->psize);
     if (os->buf[os->pstart] == 1) {
         uint8_t *p = os->buf + os->pstart + 11; //skip up to the audio channels
         st->codec.channels = *p++;
@@ -157,6 +188,9 @@
 
     } else if (os->buf[os->pstart] == 3) {
         vorbis_comment (s, os->buf + os->pstart + 7, os->psize - 8);
+    } else {
+        st->codec.extradata_size =
+            fixup_vorbis_headers(s, priv, &st->codec.extradata);
     }
 
     return os->seq < 3;





More information about the ffmpeg-cvslog mailing list