summaryrefslogtreecommitdiff
path: root/libavcodec/flac.c
diff options
context:
space:
mode:
authorMike Melanson <mike@multimedia.cx>2004-06-10 04:13:43 +0000
committerMike Melanson <mike@multimedia.cx>2004-06-10 04:13:43 +0000
commit9eda2f94c7ea238ecdebf19d8cb69748c921bda7 (patch)
treeb47e29a066f23fa1c07bd058ed9e035510c8b958 /libavcodec/flac.c
parentf777e5de84d84ad36edf64734f09f0d0d0e27652 (diff)
attempt to create some separation in the FLAC system with respect to
demuxer and decoder layers by enabling the FLAC decoder to decode data without needing the entire file, from start to finish Originally committed as revision 3211 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/flac.c')
-rw-r--r--libavcodec/flac.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/libavcodec/flac.c b/libavcodec/flac.c
index 7e92fa59ec..382082627b 100644
--- a/libavcodec/flac.c
+++ b/libavcodec/flac.c
@@ -21,6 +21,14 @@
* @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,
@@ -144,8 +153,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;
}
@@ -546,8 +568,6 @@ static int flac_decode_frame(AVCodecContext *avctx,
int tmp = 0, i, j = 0, input_buf_size;
int16_t *samples = data, *left, *right;
- 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);