-static void metadata_streaminfo(FLACContext *s)
-{
- /* mandatory streaminfo */
- s->min_blocksize = get_bits(&s->gb, 16);
- s->max_blocksize = get_bits(&s->gb, 16);
-
- s->min_framesize = get_bits_long(&s->gb, 24);
- s->max_framesize = get_bits_long(&s->gb, 24);
-
- s->samplerate = get_bits_long(&s->gb, 20);
- s->channels = get_bits(&s->gb, 3) + 1;
- s->bps = get_bits(&s->gb, 5) + 1;
-
- s->avctx->channels = s->channels;
- s->avctx->sample_rate = s->samplerate;
-
- skip_bits(&s->gb, 36); /* total num of samples */
-
- skip_bits(&s->gb, 64); /* md5 sum */
- skip_bits(&s->gb, 64); /* md5 sum */
-
- dump_headers(s);
-}
-
-/**
- * Parse a list of metadata blocks. This list of blocks must begin with
- * the fLaC marker.
- * @param s the flac decoding context containing the gb bit reader used to
- * parse metadata
- * @return 1 if some metadata was read, 0 if no fLaC marker was found
- */
-static int metadata_parse(FLACContext *s)
-{
- int i, metadata_last, metadata_type, metadata_size, streaminfo_updated=0;
-
- if (show_bits_long(&s->gb, 32) == MKBETAG('f','L','a','C')) {
- skip_bits(&s->gb, 32);
-
- av_log(s->avctx, AV_LOG_DEBUG, "STREAM HEADER\n");
- do {
- metadata_last = get_bits1(&s->gb);
- metadata_type = get_bits(&s->gb, 7);
- metadata_size = get_bits_long(&s->gb, 24);
-
- av_log(s->avctx, AV_LOG_DEBUG,
- " metadata block: flag = %d, type = %d, size = %d\n",
- metadata_last, metadata_type, metadata_size);
- if (metadata_size) {
- switch (metadata_type) {
- case METADATA_TYPE_STREAMINFO:
- metadata_streaminfo(s);
- streaminfo_updated = 1;
- break;
-
- default:
- for (i=0; i<metadata_size; i++)
- skip_bits(&s->gb, 8);
- }
- }
- } while (!metadata_last);
-
- if (streaminfo_updated)
- allocate_buffers(s);
- return 1;
- }
- return 0;
-}
-
-static int decode_residuals(FLACContext *s, int channel, int pred_order)
-{
- int i, tmp, partition, method_type, rice_order;
- int sample = 0, samples;
-
- method_type = get_bits(&s->gb, 2);
- if (method_type != 0){
- av_log(s->avctx, AV_LOG_DEBUG, "illegal residual coding method %d\n", method_type);
+ /* channels and decorrelation */
+ fi->ch_mode = get_bits(gb, 4);
+ if (fi->ch_mode < FLAC_MAX_CHANNELS) {
+ fi->channels = fi->ch_mode + 1;
+ fi->ch_mode = FLAC_CHMODE_INDEPENDENT;
+ } else if (fi->ch_mode < FLAC_MAX_CHANNELS + FLAC_CHMODE_MID_SIDE) {
+ fi->channels = 2;
+ fi->ch_mode -= FLAC_MAX_CHANNELS - 1;
+ } else {
+ av_log(avctx, AV_LOG_ERROR + log_level_offset,
+ "invalid channel mode: %d\n", fi->ch_mode);