Mercurial > libavcodec.hg
comparison flac.c @ 2071:41d30bae5019 libavcodec
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
author | melanson |
---|---|
date | Thu, 10 Jun 2004 04:13:43 +0000 |
parents | 141a9539e270 |
children | 3dabadc91d19 |
comparison
equal
deleted
inserted
replaced
2070:5914c2b0760f | 2071:41d30bae5019 |
---|---|
19 | 19 |
20 /** | 20 /** |
21 * @file flac.c | 21 * @file flac.c |
22 * FLAC (Free Lossless Audio Codec) decoder | 22 * FLAC (Free Lossless Audio Codec) decoder |
23 * @author Alex Beregszaszi | 23 * @author Alex Beregszaszi |
24 * | |
25 * For more information on the FLAC format, visit: | |
26 * http://flac.sourceforge.net/ | |
27 * | |
28 * This decoder can be used in 1 of 2 ways: Either raw FLAC data can be fed | |
29 * through, starting from the initial 'fLaC' signature; or by passing the | |
30 * 34-byte streaminfo structure through avctx->extradata[_size] followed | |
31 * by data starting with the 0xFFF8 marker. | |
24 */ | 32 */ |
25 | 33 |
26 #include <limits.h> | 34 #include <limits.h> |
27 | 35 |
28 #include "avcodec.h" | 36 #include "avcodec.h" |
31 #undef NDEBUG | 39 #undef NDEBUG |
32 #include <assert.h> | 40 #include <assert.h> |
33 | 41 |
34 #define MAX_CHANNELS 8 | 42 #define MAX_CHANNELS 8 |
35 #define MAX_BLOCKSIZE 65535 | 43 #define MAX_BLOCKSIZE 65535 |
44 #define FLAC_STREAMINFO_SIZE 34 | |
36 | 45 |
37 enum decorrelation_type { | 46 enum decorrelation_type { |
38 INDEPENDENT, | 47 INDEPENDENT, |
39 LEFT_SIDE, | 48 LEFT_SIDE, |
40 RIGHT_SIDE, | 49 RIGHT_SIDE, |
142 } | 151 } |
143 | 152 |
144 return crc; | 153 return crc; |
145 } | 154 } |
146 | 155 |
156 static void metadata_streaminfo(FLACContext *s); | |
157 static void dump_headers(FLACContext *s); | |
158 | |
147 static int flac_decode_init(AVCodecContext * avctx) | 159 static int flac_decode_init(AVCodecContext * avctx) |
148 { | 160 { |
161 FLACContext *s = avctx->priv_data; | |
162 s->avctx = avctx; | |
163 | |
164 /* initialize based on the demuxer-supplied streamdata header */ | |
165 if (avctx->extradata_size == FLAC_STREAMINFO_SIZE) { | |
166 init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8); | |
167 metadata_streaminfo(s); | |
168 dump_headers(s); | |
169 } | |
170 | |
149 return 0; | 171 return 0; |
150 } | 172 } |
151 | 173 |
152 static void dump_headers(FLACContext *s) | 174 static void dump_headers(FLACContext *s) |
153 { | 175 { |
544 FLACContext *s = avctx->priv_data; | 566 FLACContext *s = avctx->priv_data; |
545 int metadata_last, metadata_type, metadata_size; | 567 int metadata_last, metadata_type, metadata_size; |
546 int tmp = 0, i, j = 0, input_buf_size; | 568 int tmp = 0, i, j = 0, input_buf_size; |
547 int16_t *samples = data, *left, *right; | 569 int16_t *samples = data, *left, *right; |
548 | 570 |
549 s->avctx = avctx; | |
550 | |
551 if(s->max_framesize == 0){ | 571 if(s->max_framesize == 0){ |
552 s->max_framesize= 8192; // should hopefully be enough for the first header | 572 s->max_framesize= 8192; // should hopefully be enough for the first header |
553 s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize); | 573 s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize); |
554 } | 574 } |
555 | 575 |