~ubuntu-branches/ubuntu/utopic/libav/utopic-proposed

« back to all changes in this revision

Viewing changes to libavcodec/mlpdec.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler, Reinhard Tartler, Rico Tzschichholz
  • Date: 2014-08-30 11:02:45 UTC
  • mfrom: (1.3.47 sid)
  • Revision ID: package-import@ubuntu.com-20140830110245-io3dg7q85wfr7125
Tags: 6:11~beta1-2
[ Reinhard Tartler ]
* Make libavcodec-dev depend on libavresample-dev

[ Rico Tzschichholz ]
* Some fixes and leftovers from soname bumps

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "mlp_parser.h"
38
38
#include "mlpdsp.h"
39
39
#include "mlp.h"
 
40
#include "config.h"
40
41
 
41
42
/** number of bits used for VLC lookup - longest Huffman code is 9 */
 
43
#if ARCH_ARM
 
44
#define VLC_BITS            5
 
45
#define VLC_STATIC_SIZE     64
 
46
#else
42
47
#define VLC_BITS            9
 
48
#define VLC_STATIC_SIZE     512
 
49
#endif
43
50
 
44
51
typedef struct SubStream {
45
52
    /// Set if a valid restart header has been read. Otherwise the substream cannot be decoded.
190
197
    if (!huff_vlc[0].bits) {
191
198
        INIT_VLC_STATIC(&huff_vlc[0], VLC_BITS, 18,
192
199
                    &ff_mlp_huffman_tables[0][0][1], 2, 1,
193
 
                    &ff_mlp_huffman_tables[0][0][0], 2, 1, 512);
 
200
                    &ff_mlp_huffman_tables[0][0][0], 2, 1, VLC_STATIC_SIZE);
194
201
        INIT_VLC_STATIC(&huff_vlc[1], VLC_BITS, 16,
195
202
                    &ff_mlp_huffman_tables[1][0][1], 2, 1,
196
 
                    &ff_mlp_huffman_tables[1][0][0], 2, 1, 512);
 
203
                    &ff_mlp_huffman_tables[1][0][0], 2, 1, VLC_STATIC_SIZE);
197
204
        INIT_VLC_STATIC(&huff_vlc[2], VLC_BITS, 15,
198
205
                    &ff_mlp_huffman_tables[2][0][1], 2, 1,
199
 
                    &ff_mlp_huffman_tables[2][0][0], 2, 1, 512);
 
206
                    &ff_mlp_huffman_tables[2][0][0], 2, 1, VLC_STATIC_SIZE);
200
207
    }
201
208
 
202
209
    ff_mlp_init_crc();
353
360
        m->avctx->sample_fmt = AV_SAMPLE_FMT_S32;
354
361
    else
355
362
        m->avctx->sample_fmt = AV_SAMPLE_FMT_S16;
 
363
    m->dsp.mlp_pack_output = m->dsp.mlp_select_pack_output(m->substream[m->max_decoded_substream].ch_assign,
 
364
                                                           m->substream[m->max_decoded_substream].output_shift,
 
365
                                                           m->substream[m->max_decoded_substream].max_matrix_channel,
 
366
                                                           m->avctx->sample_fmt == AV_SAMPLE_FMT_S32);
356
367
 
357
368
    m->params_valid = 1;
358
369
    for (substr = 0; substr < MAX_SUBSTREAMS; substr++)
581
592
    if (substr == m->max_decoded_substream) {
582
593
        m->avctx->channels       = s->max_matrix_channel + 1;
583
594
        m->avctx->channel_layout = s->ch_layout;
 
595
        m->dsp.mlp_pack_output = m->dsp.mlp_select_pack_output(s->ch_assign,
 
596
                                                               s->output_shift,
 
597
                                                               s->max_matrix_channel,
 
598
                                                               m->avctx->sample_fmt == AV_SAMPLE_FMT_S32);
584
599
    }
585
600
 
586
601
    return 0;
811
826
                return ret;
812
827
 
813
828
    if (s->param_presence_flags & PARAM_OUTSHIFT)
814
 
        if (get_bits1(gbp))
 
829
        if (get_bits1(gbp)) {
815
830
            for (ch = 0; ch <= s->max_matrix_channel; ch++)
816
831
                s->output_shift[ch] = get_sbits(gbp, 4);
 
832
            if (substr == m->max_decoded_substream)
 
833
                m->dsp.mlp_pack_output = m->dsp.mlp_select_pack_output(s->ch_assign,
 
834
                                                                       s->output_shift,
 
835
                                                                       s->max_matrix_channel,
 
836
                                                                       m->avctx->sample_fmt == AV_SAMPLE_FMT_S32);
 
837
        }
817
838
 
818
839
    if (s->param_presence_flags & PARAM_QUANTSTEP)
819
840
        if (get_bits1(gbp))
978
999
static void rematrix_channels(MLPDecodeContext *m, unsigned int substr)
979
1000
{
980
1001
    SubStream *s = &m->substream[substr];
981
 
    unsigned int mat, src_ch, i;
 
1002
    unsigned int mat;
982
1003
    unsigned int maxchan;
983
1004
 
984
1005
    maxchan = s->max_matrix_channel;
990
1011
    }
991
1012
 
992
1013
    for (mat = 0; mat < s->num_primitive_matrices; mat++) {
993
 
        int matrix_noise_shift = s->matrix_noise_shift[mat];
994
1014
        unsigned int dest_ch = s->matrix_out_ch[mat];
995
 
        int32_t mask = MSB_MASK(s->quant_step_size[dest_ch]);
996
 
        int32_t *coeffs = s->matrix_coeff[mat];
997
 
        int index  = s->num_primitive_matrices - mat;
998
 
        int index2 = 2 * index + 1;
999
 
 
1000
 
        /* TODO: DSPContext? */
1001
 
 
1002
 
        for (i = 0; i < s->blockpos; i++) {
1003
 
            int32_t bypassed_lsb = m->bypassed_lsbs[i][mat];
1004
 
            int32_t *samples = m->sample_buffer[i];
1005
 
            int64_t accum = 0;
1006
 
 
1007
 
            for (src_ch = 0; src_ch <= maxchan; src_ch++)
1008
 
                accum += (int64_t) samples[src_ch] * coeffs[src_ch];
1009
 
 
1010
 
            if (matrix_noise_shift) {
1011
 
                index &= m->access_unit_size_pow2 - 1;
1012
 
                accum += m->noise_buffer[index] << (matrix_noise_shift + 7);
1013
 
                index += index2;
1014
 
            }
1015
 
 
1016
 
            samples[dest_ch] = ((accum >> 14) & mask) + bypassed_lsb;
1017
 
        }
 
1015
        m->dsp.mlp_rematrix_channel(&m->sample_buffer[0][0],
 
1016
                                    s->matrix_coeff[mat],
 
1017
                                    &m->bypassed_lsbs[0][mat],
 
1018
                                    m->noise_buffer,
 
1019
                                    s->num_primitive_matrices - mat,
 
1020
                                    dest_ch,
 
1021
                                    s->blockpos,
 
1022
                                    maxchan,
 
1023
                                    s->matrix_noise_shift[mat],
 
1024
                                    m->access_unit_size_pow2,
 
1025
                                    MSB_MASK(s->quant_step_size[dest_ch]));
1018
1026
    }
1019
1027
}
1020
1028
 
1025
1033
{
1026
1034
    AVCodecContext *avctx = m->avctx;
1027
1035
    SubStream *s = &m->substream[substr];
1028
 
    unsigned int i, out_ch = 0;
1029
 
    int32_t *data_32;
1030
 
    int16_t *data_16;
1031
1036
    int ret;
1032
1037
    int is32 = (m->avctx->sample_fmt == AV_SAMPLE_FMT_S32);
1033
1038
 
1047
1052
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1048
1053
        return ret;
1049
1054
    }
1050
 
    data_32 = (int32_t *)frame->data[0];
1051
 
    data_16 = (int16_t *)frame->data[0];
1052
 
 
1053
 
    for (i = 0; i < s->blockpos; i++) {
1054
 
        for (out_ch = 0; out_ch <= s->max_matrix_channel; out_ch++) {
1055
 
            int mat_ch = s->ch_assign[out_ch];
1056
 
            int32_t sample = m->sample_buffer[i][mat_ch]
1057
 
                          << s->output_shift[mat_ch];
1058
 
            s->lossless_check_data ^= (sample & 0xffffff) << mat_ch;
1059
 
            if (is32) *data_32++ = sample << 8;
1060
 
            else      *data_16++ = sample >> 8;
1061
 
        }
1062
 
    }
 
1055
    s->lossless_check_data = m->dsp.mlp_pack_output(s->lossless_check_data,
 
1056
                                                    s->blockpos,
 
1057
                                                    m->sample_buffer,
 
1058
                                                    frame->data[0],
 
1059
                                                    s->ch_assign,
 
1060
                                                    s->output_shift,
 
1061
                                                    s->max_matrix_channel,
 
1062
                                                    is32);
1063
1063
 
1064
1064
    /* Update matrix encoding side data */
1065
1065
    if ((ret = ff_side_data_update_matrix_encoding(frame, s->matrix_encoding)) < 0)