]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/flac.c
move h264 idct to its own file and call via function pointer in DspContext
[ffmpeg] / libavcodec / flac.c
index 38e09363ab1c096e2eddde70cf29614431b42cec..9ccffe7f1e71613f9bdaaa28220d97b87029baa2 100644 (file)
  * @file flac.c
  * FLAC (Free Lossless Audio Codec) decoder
  * @author Alex Beregszaszi
+ *
+ * For more information on the FLAC format, visit:
+ *  http://flac.sourceforge.net/
+ *
+ * This decoder can be used in 1 of 2 ways: Either raw FLAC data can be fed
+ * through, starting from the initial 'fLaC' signature; or by passing the
+ * 34-byte streaminfo structure through avctx->extradata[_size] followed
+ * by data starting with the 0xFFF8 marker.
  */
  
 #include <limits.h>
@@ -33,6 +41,7 @@
 
 #define MAX_CHANNELS 8
 #define MAX_BLOCKSIZE 65535
+#define FLAC_STREAMINFO_SIZE 34
 
 enum decorrelation_type {
     INDEPENDENT,
@@ -133,6 +142,27 @@ static int64_t get_utf8(GetBitContext *gb)
     return val;
 }
 
+static int skip_utf8(GetBitContext *gb)
+{
+    int ones=0, bytes;
+    
+    while(get_bits1(gb))
+        ones++;
+
+    if     (ones==0) bytes=0;
+    else if(ones==1) return -1;
+    else             bytes= ones - 1;
+    
+    skip_bits(gb, 7-ones);
+    while(bytes--){
+        const int tmp = get_bits(gb, 8);
+        
+        if((tmp>>6) != 2)
+            return -1;
+    }
+    return 0;
+}
+
 static int get_crc8(const uint8_t *buf, int count){
     int crc=0;
     int i;
@@ -144,8 +174,21 @@ static int get_crc8(const uint8_t *buf, int count){
     return crc;
 }
 
+static void metadata_streaminfo(FLACContext *s);
+static void dump_headers(FLACContext *s);
+
 static int flac_decode_init(AVCodecContext * avctx)
 {
+    FLACContext *s = avctx->priv_data;
+    s->avctx = avctx;
+
+    /* initialize based on the demuxer-supplied streamdata header */
+    if (avctx->extradata_size == FLAC_STREAMINFO_SIZE) {
+        init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
+        metadata_streaminfo(s);
+        dump_headers(s);
+    }
+
     return 0;
 }
 
@@ -543,13 +586,9 @@ static int flac_decode_frame(AVCodecContext *avctx,
 {
     FLACContext *s = avctx->priv_data;
     int metadata_last, metadata_type, metadata_size;
-    int tmp = 0, i, j = 0, input_buf_size;
-    int16_t *samples = data, *left, *right;
+    int tmp = 0, i, j = 0, input_buf_size = 0;
+    int16_t *samples = data;
 
-    *data_size = 0;
-
-    s->avctx = avctx;
-    
     if(s->max_framesize == 0){
         s->max_framesize= 8192; // should hopefully be enough for the first header
         s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize);