Revision 9731e7f1 libavcodec/mlpdec.c

View differences:

libavcodec/mlpdec.c
58 58
    uint8_t     max_channel;
59 59
    //! The number of channels input into the rematrix stage.
60 60
    uint8_t     max_matrix_channel;
61
    //! For each channel output by the matrix, the output channel to map it to
62
    uint8_t     ch_assign[MAX_CHANNELS];
61 63

  
62 64
    //! The left shift applied to random noise in 0x31ea substreams.
63 65
    uint8_t     noise_shift;
......
380 382

  
381 383
    skip_bits(gbp, 16);
382 384

  
385
    memset(s->ch_assign, 0, sizeof(s->ch_assign));
386

  
383 387
    for (ch = 0; ch <= s->max_matrix_channel; ch++) {
384 388
        int ch_assign = get_bits(gbp, 6);
385 389
        dprintf(m->avctx, "ch_assign[%d][%d] = %d\n", substr, ch,
386 390
                ch_assign);
387
        if (ch_assign != ch) {
391
        if (ch_assign > s->max_matrix_channel) {
388 392
            av_log(m->avctx, AV_LOG_ERROR,
389
                   "Non-1:1 channel assignments are used in this stream. %s\n",
390
                   sample_message);
393
                   "Assignment of matrix channel %d to invalid output channel %d. %s\n",
394
                   ch, ch_assign, sample_message);
391 395
            return -1;
392 396
        }
397
        s->ch_assign[ch_assign] = ch;
393 398
    }
394 399

  
395 400
    checksum = ff_mlp_restart_checksum(buf, get_bits_count(gbp) - start_count);
......
421 426
    }
422 427

  
423 428
    if (substr == m->max_decoded_substream) {
424
        m->avctx->channels = s->max_channel + 1;
429
        m->avctx->channels = s->max_matrix_channel + 1;
425 430
    }
426 431

  
427 432
    return 0;
......
831 836
                                uint8_t *data, unsigned int *data_size, int is32)
832 837
{
833 838
    SubStream *s = &m->substream[substr];
834
    unsigned int i, ch = 0;
839
    unsigned int i, out_ch = 0;
835 840
    int32_t *data_32 = (int32_t*) data;
836 841
    int16_t *data_16 = (int16_t*) data;
837 842

  
......
839 844
        return -1;
840 845

  
841 846
    for (i = 0; i < s->blockpos; i++) {
842
        for (ch = 0; ch <= s->max_channel; ch++) {
843
            int32_t sample = m->sample_buffer[i][ch] << s->output_shift[ch];
844
            s->lossless_check_data ^= (sample & 0xffffff) << ch;
847
        for (out_ch = 0; out_ch <= s->max_matrix_channel; out_ch++) {
848
            int mat_ch = s->ch_assign[out_ch];
849
            int32_t sample = m->sample_buffer[i][mat_ch]
850
                          << s->output_shift[mat_ch];
851
            s->lossless_check_data ^= (sample & 0xffffff) << mat_ch;
845 852
            if (is32) *data_32++ = sample << 8;
846 853
            else      *data_16++ = sample >> 8;
847 854
        }
848 855
    }
849 856

  
850
    *data_size = i * ch * (is32 ? 4 : 2);
857
    *data_size = i * out_ch * (is32 ? 4 : 2);
851 858

  
852 859
    return 0;
853 860
}

Also available in: Unified diff