1 /*
2 * Functions common to fixed/float MPEG-4 Parametric Stereo decoding
3 * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <stdint.h>
28
30 { 0, 1, 2, 4, },
31 { 1, 2, 3, 4, },
32 };
33
35 10, 20, 34, 10, 20, 34,
36 };
37
39 5, 11, 17, 5, 11, 17,
40 };
41
42 enum {
53 };
54
60 };
61
63
64 #define READ_PAR_DATA(PAR, OFFSET, MASK, ERR_CONDITION, NB_BITS, MAX_DEPTH) \
65 /** \
66 * Read Inter-channel Intensity Difference/Inter-Channel Coherence/ \
67 * Inter-channel Phase Difference/Overall Phase Difference parameters from the \
68 * bitstream. \
69 * \
70 * @param avctx contains the current codec context \
71 * @param gb pointer to the input bitstream \
72 * @param ps pointer to the Parametric Stereo context \
73 * @param PAR pointer to the parameter to be read \
74 * @param e envelope to decode \
75 * @param dt 1: time delta-coded, 0: frequency delta-coded \
76 */ \
77 static int read_ ## PAR ## _data(AVCodecContext *avctx, GetBitContext *gb, PSCommonContext *ps, \
78 int8_t (*PAR)[PS_MAX_NR_IIDICC], int table_idx, int e, int dt) \
79 { \
80 int b, num = ps->nr_ ## PAR ## _par; \
81 VLC_TYPE (*vlc_table)[2] = vlc_ps[table_idx].table; \
82 if (dt) { \
83 int e_prev = e ? e - 1 : ps->num_env_old - 1; \
84 e_prev = FFMAX(e_prev, 0); \
85 for (b = 0; b < num; b++) { \
86 int val = PAR[e_prev][b] + get_vlc2(gb, vlc_table, NB_BITS, MAX_DEPTH) - OFFSET; \
87 if (MASK) val &= MASK; \
88 PAR[e][b] = val; \
89 if (ERR_CONDITION) \
90 goto err; \
91 } \
92 } else { \
93 int val = 0; \
94 for (b = 0; b < num; b++) { \
95 val += get_vlc2(gb, vlc_table, NB_BITS, MAX_DEPTH) - OFFSET; \
96 if (MASK) val &= MASK; \
100 } \
102 return 0; \
103 err: \
104 av_log(avctx, AV_LOG_ERROR, "illegal "#PAR"\n"); \
105 return AVERROR_INVALIDDATA; \
106 }
107
111
113 int ps_extension_id)
114 {
115 int e;
117
118 if (ps_extension_id)
119 return 0;
120
122 if (ps->enable_ipdopd) {
123 for (e = 0; e < ps->num_env; e++) {
128 }
129 }
132 }
133
136 {
137 int e;
140 int bits_consumed;
142
144 if (
header) {
//enable_ps_header
148 if (iid_mode > 5) {
150 iid_mode);
151 goto err;
152 }
156 }
163 goto err;
164 }
166 }
168 }
169
173
176 for (e = 1; e <= ps->
num_env; e++) {
180 goto err;
181 }
182 }
183 } else
184 for (e = 1; e <= ps->
num_env; e++)
186
188 for (e = 0; e < ps->
num_env; e++) {
191 goto err;
192 }
193 } else
195
197 for (e = 0; e < ps->
num_env; e++) {
200 goto err;
201 }
202 else
204
207 if (cnt == 15) {
209 }
210 cnt *= 8;
211 while (cnt > 7) {
212 int ps_extension_id =
get_bits(gb, 2);
214 }
215 if (cnt < 0) {
217 goto err;
218 }
220 }
221
223
224 //Fix up envelopes
226 //Create a fake envelope
232 }
235 }
239 }
240 }
245 goto err;
246 }
247 }
248 }
253 goto err;
254 }
255 }
256 }
259 }
260
261
266
267 //Baseline
271 }
272
275
277 if (bits_consumed <= bits_left) {
279 return bits_consumed;
280 }
281 av_log(avctx,
AV_LOG_ERROR,
"Expected to read %d PS bits actually read %d.\n", bits_left, bits_consumed);
282 err:
289 return bits_left;
291
292 #define PS_INIT_VLC_STATIC(num, nb_bits, size) \
293 INIT_VLC_STATIC(&vlc_ps[num], nb_bits, ps_tmp[num].table_size / ps_tmp[num].elem_size, \
294 ps_tmp[num].ps_bits, 1, 1, \
295 ps_tmp[num].ps_codes, ps_tmp[num].elem_size, ps_tmp[num].elem_size, \
296 size);
297
298 #define PS_VLC_ROW(name) \
299 { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) }
300
302 {
303 // Syntax initialization
304 static const struct {
305 const void *ps_codes, *ps_bits;
306 const unsigned int table_size, elem_size;
307 } ps_tmp[] = {
318 };
319
330 }
331
333 {
336 }