~ubuntu-branches/ubuntu/utopic/ffmpeg-debian/utopic

« back to all changes in this revision

Viewing changes to libavcodec/dca.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-01-20 09:20:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090120092053-izz63p40hc98qfgp
Tags: 3:0.svn20090119-1ubuntu1
* merge from debian. LP: #318501
* new version fixes CVE-2008-3230, LP: #253767

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
    CH_FRONT_LEFT_OF_CENTER|CH_FRONT_CENTER|CH_FRONT_RIGHT_OF_CENTER|CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_BACK_CENTER|CH_SIDE_RIGHT, ///< 8, CL + C+ CR + L + R + SL + S+ SR
89
89
};
90
90
 
 
91
static const int8_t dca_lfe_index[] = {
 
92
    1,2,2,2,2,3,2,3,2,3,2,3,1,3,2,3
 
93
};
 
94
 
 
95
static const int8_t dca_channel_reorder_lfe[][8] = {
 
96
    { 0, -1, -1, -1, -1, -1, -1, -1},
 
97
    { 0,  1, -1, -1, -1, -1, -1, -1},
 
98
    { 0,  1, -1, -1, -1, -1, -1, -1},
 
99
    { 0,  1, -1, -1, -1, -1, -1, -1},
 
100
    { 0,  1, -1, -1, -1, -1, -1, -1},
 
101
    { 2,  0,  1, -1, -1, -1, -1, -1},
 
102
    { 0,  1,  3, -1, -1, -1, -1, -1},
 
103
    { 2,  0,  1,  4, -1, -1, -1, -1},
 
104
    { 0,  1,  3,  4, -1, -1, -1, -1},
 
105
    { 2,  0,  1,  4,  5, -1, -1, -1},
 
106
    { 3,  4,  0,  1,  5,  6, -1, -1},
 
107
    { 2,  0,  1,  4,  5,  6, -1, -1},
 
108
    { 0,  6,  4,  5,  2,  3, -1, -1},
 
109
    { 4,  2,  5,  0,  1,  6,  7, -1},
 
110
    { 5,  6,  0,  1,  7,  3,  8,  4},
 
111
    { 4,  2,  5,  0,  1,  6,  8,  7},
 
112
};
 
113
 
 
114
static const int8_t dca_channel_reorder_nolfe[][8] = {
 
115
    { 0, -1, -1, -1, -1, -1, -1, -1},
 
116
    { 0,  1, -1, -1, -1, -1, -1, -1},
 
117
    { 0,  1, -1, -1, -1, -1, -1, -1},
 
118
    { 0,  1, -1, -1, -1, -1, -1, -1},
 
119
    { 0,  1, -1, -1, -1, -1, -1, -1},
 
120
    { 2,  0,  1, -1, -1, -1, -1, -1},
 
121
    { 0,  1,  2, -1, -1, -1, -1, -1},
 
122
    { 2,  0,  1,  3, -1, -1, -1, -1},
 
123
    { 0,  1,  2,  3, -1, -1, -1, -1},
 
124
    { 2,  0,  1,  3,  4, -1, -1, -1},
 
125
    { 2,  3,  0,  1,  4,  5, -1, -1},
 
126
    { 2,  0,  1,  3,  4,  5, -1, -1},
 
127
    { 0,  5,  3,  4,  1,  2, -1, -1},
 
128
    { 3,  2,  4,  0,  1,  5,  6, -1},
 
129
    { 4,  5,  0,  1,  6,  2,  7,  3},
 
130
    { 3,  2,  4,  0,  1,  5,  7,  6},
 
131
};
 
132
 
91
133
 
92
134
#define DCA_DOLBY 101           /* FIXME */
93
135
 
198
240
    uint8_t dca_buffer[DCA_MAX_FRAME_SIZE];
199
241
    int dca_buffer_size;        ///< how much data is in the dca_buffer
200
242
 
 
243
    const int8_t* channel_order_tab;                             ///< channel reordering table, lfe and non lfe
201
244
    GetBitContext gb;
202
245
    /* Current position in DCA frame */
203
246
    int current_subframe;
1013
1056
    for (k = 0; k < s->prim_channels; k++) {
1014
1057
/*        static float pcm_to_double[8] =
1015
1058
            {32768.0, 32768.0, 524288.0, 524288.0, 0, 8388608.0, 8388608.0};*/
1016
 
         qmf_32_subbands(s, k, subband_samples[k], &s->samples[256 * k],
 
1059
         qmf_32_subbands(s, k, subband_samples[k], &s->samples[256 * s->channel_order_tab[k]],
1017
1060
                            M_SQRT1_2*s->scale_bias /*pcm_to_double[s->source_pcm_res] */ ,
1018
1061
                            s->add_bias );
1019
1062
    }
1027
1070
    /* Generate LFE samples for this subsubframe FIXME!!! */
1028
1071
    if (s->output & DCA_LFE) {
1029
1072
        int lfe_samples = 2 * s->lfe * s->subsubframes;
1030
 
        int i_channels = dca_channels[s->output & DCA_CHANNEL_MASK];
1031
1073
 
1032
1074
        lfe_interpolation_fir(s->lfe, 2 * s->lfe,
1033
1075
                              s->lfe_data + lfe_samples +
1034
1076
                              2 * s->lfe * subsubframe,
1035
 
                              &s->samples[256 * i_channels],
 
1077
                              &s->samples[256 * dca_lfe_index[s->amode]],
1036
1078
                              (1.0/256.0)*s->scale_bias,  s->add_bias);
1037
1079
        /* Outputs 20bits pcm samples */
1038
1080
    }
1133
1175
    PutBitContext pb;
1134
1176
 
1135
1177
    if((unsigned)src_size > (unsigned)max_size) {
1136
 
        av_log(NULL, AV_LOG_ERROR, "Input frame size larger then DCA_MAX_FRAME_SIZE!\n");
1137
 
        return -1;
 
1178
//        av_log(NULL, AV_LOG_ERROR, "Input frame size larger then DCA_MAX_FRAME_SIZE!\n");
 
1179
//        return -1;
 
1180
        src_size = max_size;
1138
1181
    }
1139
1182
 
1140
1183
    mrk = AV_RB32(src);
1192
1235
    avctx->bit_rate = s->bit_rate;
1193
1236
 
1194
1237
    channels = s->prim_channels + !!s->lfe;
1195
 
    if(avctx->request_channels == 2 && s->prim_channels > 2) {
1196
 
        channels = 2;
1197
 
        s->output = DCA_STEREO;
1198
 
        avctx->channel_layout = CH_LAYOUT_STEREO;
1199
 
    }
1200
 
    if (s->amode<16)
 
1238
 
 
1239
    if (s->amode<16) {
1201
1240
        avctx->channel_layout = dca_core_channel_layout[s->amode];
1202
1241
 
1203
 
    if (s->lfe) avctx->channel_layout |= CH_LOW_FREQUENCY;
 
1242
        if (s->lfe) {
 
1243
            avctx->channel_layout |= CH_LOW_FREQUENCY;
 
1244
            s->channel_order_tab = dca_channel_reorder_lfe[s->amode];
 
1245
        } else
 
1246
            s->channel_order_tab = dca_channel_reorder_nolfe[s->amode];
 
1247
 
 
1248
        if(avctx->request_channels == 2 && s->prim_channels > 2) {
 
1249
            channels = 2;
 
1250
            s->output = DCA_STEREO;
 
1251
            avctx->channel_layout = CH_LAYOUT_STEREO;
 
1252
        }
 
1253
    } else {
 
1254
        av_log(avctx, AV_LOG_ERROR, "Non standard configuration %d !\n",s->amode);
 
1255
        return -1;
 
1256
    }
 
1257
 
1204
1258
 
1205
1259
    /* There is nothing that prevents a dts frame to change channel configuration
1206
1260
       but FFmpeg doesn't support that so only set the channels if it is previously