Justin Ruggles <[EMAIL PROTECTED]> added the comment:

I can confirm that this bug is still present in SVN.

Patch to fix is attached.  The patch was also submitted to ffmpeg-devel.
http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2007-September/036071.html

----------
status: new -> open
substatus: needs_more_info -> reproduced

______________________________________________________
FFmpeg issue tracker <[EMAIL PROTECTED]>
<https://roundup.mplayerhq.hu/roundup/ffmpeg/issue187>
______________________________________________________
Index: libavformat/Makefile
===================================================================
--- libavformat/Makefile	(revision 10629)
+++ libavformat/Makefile	(working copy)
@@ -44,7 +44,7 @@
 OBJS-$(CONFIG_EA_DEMUXER)                += electronicarts.o
 OBJS-$(CONFIG_FFM_DEMUXER)               += ffm.o
 OBJS-$(CONFIG_FFM_MUXER)                 += ffm.o
-OBJS-$(CONFIG_FLAC_DEMUXER)              += raw.o
+OBJS-$(CONFIG_FLAC_DEMUXER)              += raw.o oggparsevorbis.o
 OBJS-$(CONFIG_FLAC_MUXER)                += raw.o
 OBJS-$(CONFIG_FLIC_DEMUXER)              += flic.o
 OBJS-$(CONFIG_FLV_DEMUXER)               += flvdec.o
Index: libavformat/raw.c
===================================================================
--- libavformat/raw.c	(revision 10629)
+++ libavformat/raw.c	(working copy)
@@ -21,6 +21,8 @@
  */
 #include "avformat.h"
 #include "ac3_parser.h"
+#include "bitstream.h"
+#include "ogg2.h"
 #include "raw.h"
 
 #ifdef CONFIG_MUXERS
@@ -242,19 +244,71 @@
     return 0;
 }
 
+#define FLAC_STREAMINFO_SIZE 34
+
 /* flac read */
 static int flac_read_header(AVFormatContext *s,
                             AVFormatParameters *ap)
 {
+    ByteIOContext *pb = &s->pb;
     AVStream *st;
+    int last_metablock;
 
+    /* create AVStream */
     st = av_new_stream(s, 0);
     if (!st)
         return AVERROR(ENOMEM);
     st->codec->codec_type = CODEC_TYPE_AUDIO;
     st->codec->codec_id = CODEC_ID_FLAC;
-    st->need_parsing = AVSTREAM_PARSE_FULL;
-    /* the parameters will be extracted from the compressed bitstream */
+
+    /* verify fLaC tag */
+    if(get_be32(pb) != MKBETAG('f','L','a','C'))
+        return -1;
+
+    /* read metadata blocks */
+    do {
+        int tmp, type, size;
+        tmp = get_byte(pb);
+        last_metablock = tmp >> 7;
+        type = tmp & 0x7F;
+        size = get_be24(pb);
+        if(size) {
+            if(type == 0) {
+                /* read streaminfo to codec extradata */
+                GetBitContext gb;
+                int64_t samples;
+                st->codec->extradata = av_malloc(FLAC_STREAMINFO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
+                get_buffer(pb, st->codec->extradata, size);
+                init_get_bits(&gb, st->codec->extradata, FLAC_STREAMINFO_SIZE*8);
+
+                skip_bits(&gb, 16*2+24*2);
+                st->codec->sample_rate = get_bits_long(&gb, 20);
+                st->codec->channels = get_bits(&gb, 3) + 1;
+                skip_bits(&gb, 5);
+                samples = get_bits(&gb, 4);
+                samples = (samples << 32) | get_bits_long(&gb, 32);
+                if(!st->codec->sample_rate) {
+                    av_freep(&st->codec->extradata);
+                    return -1;
+                }
+                st->codec->extradata_size = FLAC_STREAMINFO_SIZE;
+                av_set_pts_info(st, 64, 1, st->codec->sample_rate);
+                if(samples) {
+                    s->start_time = 0;
+                    s->duration = samples * AV_TIME_BASE / st->codec->sample_rate;
+                }
+            } else if(type == 4) {
+                /* read and parse vorbiscomment metadata block */
+                uint8_t *vorbiscomment = av_malloc(size);
+                get_buffer(pb, vorbiscomment, size);
+                vorbis_comment(s, vorbiscomment, size);
+                av_freep(&vorbiscomment);
+            } else {
+                url_fskip(pb, size);
+            }
+        }
+    } while(!last_metablock);
+
     return 0;
 }
 

Reply via email to