Mercurial > libavcodec.hg
comparison flacdec.c @ 9188:f534d0cca450 libavcodec
share some constants between the FLAC encoder and FLAC decoder
author | jbr |
---|---|
date | Thu, 19 Mar 2009 03:04:21 +0000 |
parents | b980183eb831 |
children | 443f056ba7e7 |
comparison
equal
deleted
inserted
replaced
9187:e10efe27c6b1 | 9188:f534d0cca450 |
---|---|
44 #include "flac.h" | 44 #include "flac.h" |
45 | 45 |
46 #undef NDEBUG | 46 #undef NDEBUG |
47 #include <assert.h> | 47 #include <assert.h> |
48 | 48 |
49 #define MAX_CHANNELS 8 | |
50 #define MAX_BLOCKSIZE 65535 | |
51 | |
52 enum decorrelation_type { | 49 enum decorrelation_type { |
53 INDEPENDENT, | 50 INDEPENDENT, |
54 LEFT_SIDE, | 51 LEFT_SIDE, |
55 RIGHT_SIDE, | 52 RIGHT_SIDE, |
56 MID_SIDE, | 53 MID_SIDE, |
67 int sample_shift; ///< shift required to make output samples 16-bit or 32-bit | 64 int sample_shift; ///< shift required to make output samples 16-bit or 32-bit |
68 int is32; ///< flag to indicate if output should be 32-bit instead of 16-bit | 65 int is32; ///< flag to indicate if output should be 32-bit instead of 16-bit |
69 enum decorrelation_type decorrelation; ///< channel decorrelation type in the current frame | 66 enum decorrelation_type decorrelation; ///< channel decorrelation type in the current frame |
70 int got_streaminfo; ///< indicates if the STREAMINFO has been read | 67 int got_streaminfo; ///< indicates if the STREAMINFO has been read |
71 | 68 |
72 int32_t *decoded[MAX_CHANNELS]; ///< decoded samples | 69 int32_t *decoded[FLAC_MAX_CHANNELS]; ///< decoded samples |
73 uint8_t *bitstream; | 70 uint8_t *bitstream; |
74 unsigned int bitstream_size; | 71 unsigned int bitstream_size; |
75 unsigned int bitstream_index; | 72 unsigned int bitstream_index; |
76 unsigned int allocated_bitstream_size; | 73 unsigned int allocated_bitstream_size; |
77 } FLACContext; | 74 } FLACContext; |
188 GetBitContext gb; | 185 GetBitContext gb; |
189 init_get_bits(&gb, buffer, FLAC_STREAMINFO_SIZE*8); | 186 init_get_bits(&gb, buffer, FLAC_STREAMINFO_SIZE*8); |
190 | 187 |
191 skip_bits(&gb, 16); /* skip min blocksize */ | 188 skip_bits(&gb, 16); /* skip min blocksize */ |
192 s->max_blocksize = get_bits(&gb, 16); | 189 s->max_blocksize = get_bits(&gb, 16); |
193 if (s->max_blocksize < 16) { | 190 if (s->max_blocksize < FLAC_MIN_BLOCKSIZE) { |
194 av_log(avctx, AV_LOG_WARNING, "invalid max blocksize: %d\n", | 191 av_log(avctx, AV_LOG_WARNING, "invalid max blocksize: %d\n", |
195 s->max_blocksize); | 192 s->max_blocksize); |
196 s->max_blocksize = 16; | 193 s->max_blocksize = 16; |
197 } | 194 } |
198 | 195 |
508 blocksize_code = get_bits(&s->gb, 4); | 505 blocksize_code = get_bits(&s->gb, 4); |
509 | 506 |
510 sample_rate_code = get_bits(&s->gb, 4); | 507 sample_rate_code = get_bits(&s->gb, 4); |
511 | 508 |
512 assignment = get_bits(&s->gb, 4); /* channel assignment */ | 509 assignment = get_bits(&s->gb, 4); /* channel assignment */ |
513 if (assignment < 8 && s->channels == assignment+1) | 510 if (assignment < FLAC_MAX_CHANNELS && s->channels == assignment+1) |
514 decorrelation = INDEPENDENT; | 511 decorrelation = INDEPENDENT; |
515 else if (assignment >=8 && assignment < 11 && s->channels == 2) | 512 else if (assignment >= FLAC_MAX_CHANNELS && assignment < 11 && s->channels == 2) |
516 decorrelation = LEFT_SIDE + assignment - 8; | 513 decorrelation = LEFT_SIDE + assignment - 8; |
517 else { | 514 else { |
518 av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n", | 515 av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n", |
519 assignment, s->channels); | 516 assignment, s->channels); |
520 return -1; | 517 return -1; |