Mercurial > libavcodec.hg
annotate eac3dec.c @ 11352:6e0af2cfdcfe libavcodec
Do MC and IDCT in coding (hilbert) order
This increases the slice size to 64 pixels, due to having to decode an
entire chroma superblock row per slice.
This can be up to 6% slower depending on clip and CPU, but is necessary
for future optimizations that gain significantly more than was lost.
author | conrad |
---|---|
date | Wed, 03 Mar 2010 23:27:40 +0000 |
parents | 68de5143aa45 |
children | 444f4b594fdb |
rev | line source |
---|---|
7666 | 1 /* |
2 * E-AC-3 decoder | |
3 * Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com> | |
4 * Copyright (c) 2008 Justin Ruggles | |
5 * | |
6 * This file is part of FFmpeg. | |
7 * | |
8 * FFmpeg is free software; you can redistribute it and/or | |
7679 | 9 * modify it under the terms of the GNU Lesser General Public |
7666 | 10 * License as published by the Free Software Foundation; either |
7679 | 11 * version 2.1 of the License, or (at your option) any later version. |
7666 | 12 * |
13 * FFmpeg is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
7679 | 16 * Lesser General Public License for more details. |
7666 | 17 * |
7679 | 18 * You should have received a copy of the GNU Lesser General Public |
7666 | 19 * License along with FFmpeg; if not, write to the Free Software |
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
21 */ | |
22 | |
9181 | 23 /* |
24 * There are several features of E-AC-3 that this decoder does not yet support. | |
25 * | |
26 * Spectral Extension | |
27 * There is a patch to get this working for the two samples we have that | |
28 * use it, but it needs some minor changes in order to be accepted. | |
29 * | |
30 * Enhanced Coupling | |
31 * No known samples exist. If any ever surface, this feature should not be | |
32 * too difficult to implement. | |
33 * | |
34 * Reduced Sample Rates | |
35 * No known samples exist. The spec also does not give clear information | |
36 * on how this is to be implemented. | |
37 * | |
38 * Dependent Streams | |
39 * Only the independent stream is currently decoded. Any dependent | |
40 * streams are skipped. We have only come across two examples of this, and | |
41 * they are both just test streams, one for HD-DVD and the other for | |
42 * Blu-ray. | |
43 * | |
44 * Transient Pre-noise Processing | |
45 * This is side information which a decoder should use to reduce artifacts | |
46 * caused by transients. There are samples which are known to have this | |
47 * information, but this decoder currently ignores it. | |
48 */ | |
49 | |
50 | |
7666 | 51 #include "avcodec.h" |
8281
f93efc084e41
Make av_log_missing_feature an internal function, and change its name
stefano
parents:
8273
diff
changeset
|
52 #include "internal.h" |
8545
a5402e89a80c
Factorise enum of AC3 error types to be usable by AAC in the ADTS patch that
superdump
parents:
8281
diff
changeset
|
53 #include "aac_ac3_parser.h" |
7666 | 54 #include "ac3.h" |
55 #include "ac3_parser.h" | |
56 #include "ac3dec.h" | |
57 #include "ac3dec_data.h" | |
9983 | 58 #include "eac3dec_data.h" |
7666 | 59 |
60 /** gain adaptive quantization mode */ | |
61 typedef enum { | |
62 EAC3_GAQ_NO =0, | |
63 EAC3_GAQ_12, | |
64 EAC3_GAQ_14, | |
65 EAC3_GAQ_124 | |
66 } EAC3GaqMode; | |
67 | |
68 #define EAC3_SR_CODE_REDUCED 3 | |
69 | |
9680
debe2623a70a
eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents:
9661
diff
changeset
|
70 /** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */ |
debe2623a70a
eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents:
9661
diff
changeset
|
71 #define COEFF_0 10273905LL |
7666 | 72 |
9680
debe2623a70a
eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents:
9661
diff
changeset
|
73 /** lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23)) */ |
debe2623a70a
eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents:
9661
diff
changeset
|
74 #define COEFF_1 11863283LL |
7666 | 75 |
9680
debe2623a70a
eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents:
9661
diff
changeset
|
76 /** lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23)) */ |
debe2623a70a
eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents:
9661
diff
changeset
|
77 #define COEFF_2 3070444LL |
7666 | 78 |
79 /** | |
80 * Calculate 6-point IDCT of the pre-mantissas. | |
9680
debe2623a70a
eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents:
9661
diff
changeset
|
81 * All calculations are 24-bit fixed-point. |
7666 | 82 */ |
83 static void idct6(int pre_mant[6]) | |
84 { | |
85 int tmp; | |
86 int even0, even1, even2, odd0, odd1, odd2; | |
87 | |
88 odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5]; | |
89 | |
9680
debe2623a70a
eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents:
9661
diff
changeset
|
90 even2 = ( pre_mant[2] * COEFF_0) >> 23; |
debe2623a70a
eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents:
9661
diff
changeset
|
91 tmp = ( pre_mant[4] * COEFF_1) >> 23; |
debe2623a70a
eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents:
9661
diff
changeset
|
92 odd0 = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23; |
7666 | 93 |
94 even0 = pre_mant[0] + (tmp >> 1); | |
95 even1 = pre_mant[0] - tmp; | |
96 | |
97 tmp = even0; | |
98 even0 = tmp + even2; | |
99 even2 = tmp - even2; | |
100 | |
101 tmp = odd0; | |
102 odd0 = tmp + pre_mant[1] + pre_mant[3]; | |
103 odd2 = tmp + pre_mant[5] - pre_mant[3]; | |
104 | |
105 pre_mant[0] = even0 + odd0; | |
106 pre_mant[1] = even1 + odd1; | |
107 pre_mant[2] = even2 + odd2; | |
108 pre_mant[3] = even2 - odd2; | |
109 pre_mant[4] = even1 - odd1; | |
110 pre_mant[5] = even0 - odd0; | |
111 } | |
7745 | 112 |
113 void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch) | |
114 { | |
115 int bin, blk, gs; | |
116 int end_bap, gaq_mode; | |
117 GetBitContext *gbc = &s->gbc; | |
118 int gaq_gain[AC3_MAX_COEFS]; | |
119 | |
120 gaq_mode = get_bits(gbc, 2); | |
121 end_bap = (gaq_mode < 2) ? 12 : 17; | |
122 | |
123 /* if GAQ gain is used, decode gain codes for bins with hebap between | |
124 8 and end_bap */ | |
125 gs = 0; | |
126 if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) { | |
127 /* read 1-bit GAQ gain codes */ | |
128 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) { | |
129 if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap) | |
130 gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1); | |
131 } | |
132 } else if (gaq_mode == EAC3_GAQ_124) { | |
133 /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */ | |
134 int gc = 2; | |
135 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) { | |
136 if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) { | |
137 if (gc++ == 2) { | |
138 int group_code = get_bits(gbc, 5); | |
139 if (group_code > 26) { | |
140 av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n"); | |
141 group_code = 26; | |
142 } | |
143 gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0]; | |
144 gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1]; | |
145 gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2]; | |
146 gc = 0; | |
147 } | |
148 } | |
149 } | |
150 } | |
151 | |
152 gs=0; | |
153 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) { | |
154 int hebap = s->bap[ch][bin]; | |
155 int bits = ff_eac3_bits_vs_hebap[hebap]; | |
156 if (!hebap) { | |
157 /* zero-mantissa dithering */ | |
158 for (blk = 0; blk < 6; blk++) { | |
9680
debe2623a70a
eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents:
9661
diff
changeset
|
159 s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000; |
7745 | 160 } |
161 } else if (hebap < 8) { | |
162 /* Vector Quantization */ | |
163 int v = get_bits(gbc, bits); | |
164 for (blk = 0; blk < 6; blk++) { | |
9680
debe2623a70a
eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents:
9661
diff
changeset
|
165 s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] << 8; |
7745 | 166 } |
167 } else { | |
168 /* Gain Adaptive Quantization */ | |
169 int gbits, log_gain; | |
170 if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) { | |
171 log_gain = gaq_gain[gs++]; | |
172 } else { | |
173 log_gain = 0; | |
174 } | |
175 gbits = bits - log_gain; | |
176 | |
177 for (blk = 0; blk < 6; blk++) { | |
178 int mant = get_sbits(gbc, gbits); | |
9682
0596729ae4af
eac3dec: fix bug in GAQ dequantization. large mantissas should only be
jbr
parents:
9681
diff
changeset
|
179 if (log_gain && mant == -(1 << (gbits-1))) { |
7745 | 180 /* large mantissa */ |
181 int b; | |
9681 | 182 int mbits = bits - (2 - log_gain); |
183 mant = get_sbits(gbc, mbits); | |
184 mant <<= (23 - (mbits - 1)); | |
7745 | 185 /* remap mantissa value to correct for asymmetric quantization */ |
186 if (mant >= 0) | |
9683 | 187 b = 1 << (23 - log_gain); |
7745 | 188 else |
9681 | 189 b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] << 8; |
9708
d23332ab364f
eac3dec: get rid of unnecessary left shifts in 16-bit * 24-bit
jbr
parents:
9683
diff
changeset
|
190 mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b; |
7745 | 191 } else { |
192 /* small mantissa, no GAQ, or Gk=1 */ | |
9680
debe2623a70a
eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents:
9661
diff
changeset
|
193 mant <<= 24 - bits; |
7745 | 194 if (!log_gain) { |
195 /* remap mantissa value for no GAQ or Gk=1 */ | |
9708
d23332ab364f
eac3dec: get rid of unnecessary left shifts in 16-bit * 24-bit
jbr
parents:
9683
diff
changeset
|
196 mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15; |
7745 | 197 } |
198 } | |
199 s->pre_mantissa[ch][bin][blk] = mant; | |
200 } | |
201 } | |
202 idct6(s->pre_mantissa[ch][bin]); | |
203 } | |
204 } | |
205 | |
206 int ff_eac3_parse_header(AC3DecodeContext *s) | |
207 { | |
208 int i, blk, ch; | |
209 int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data; | |
210 int parse_transient_proc_info; | |
211 int num_cpl_blocks; | |
212 GetBitContext *gbc = &s->gbc; | |
213 | |
214 /* An E-AC-3 stream can have multiple independent streams which the | |
215 application can select from. each independent stream can also contain | |
216 dependent streams which are used to add or replace channels. */ | |
217 if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) { | |
9891
7ad7d4094d1f
Rename ff_log_missing_feature() to av_log_missing_feature().
rbultje
parents:
9708
diff
changeset
|
218 av_log_missing_feature(s->avctx, "Dependent substream decoding", 1); |
8545
a5402e89a80c
Factorise enum of AC3 error types to be usable by AAC in the ADTS patch that
superdump
parents:
8281
diff
changeset
|
219 return AAC_AC3_PARSE_ERROR_FRAME_TYPE; |
7745 | 220 } else if (s->frame_type == EAC3_FRAME_TYPE_RESERVED) { |
221 av_log(s->avctx, AV_LOG_ERROR, "Reserved frame type\n"); | |
8545
a5402e89a80c
Factorise enum of AC3 error types to be usable by AAC in the ADTS patch that
superdump
parents:
8281
diff
changeset
|
222 return AAC_AC3_PARSE_ERROR_FRAME_TYPE; |
7745 | 223 } |
224 | |
225 /* The substream id indicates which substream this frame belongs to. each | |
226 independent stream has its own substream id, and the dependent streams | |
227 associated to an independent stream have matching substream id's. */ | |
228 if (s->substreamid) { | |
229 /* only decode substream with id=0. skip any additional substreams. */ | |
9891
7ad7d4094d1f
Rename ff_log_missing_feature() to av_log_missing_feature().
rbultje
parents:
9708
diff
changeset
|
230 av_log_missing_feature(s->avctx, "Additional substreams", 1); |
8545
a5402e89a80c
Factorise enum of AC3 error types to be usable by AAC in the ADTS patch that
superdump
parents:
8281
diff
changeset
|
231 return AAC_AC3_PARSE_ERROR_FRAME_TYPE; |
7745 | 232 } |
233 | |
234 if (s->bit_alloc_params.sr_code == EAC3_SR_CODE_REDUCED) { | |
235 /* The E-AC-3 specification does not tell how to handle reduced sample | |
236 rates in bit allocation. The best assumption would be that it is | |
237 handled like AC-3 DolbyNet, but we cannot be sure until we have a | |
238 sample which utilizes this feature. */ | |
9891
7ad7d4094d1f
Rename ff_log_missing_feature() to av_log_missing_feature().
rbultje
parents:
9708
diff
changeset
|
239 av_log_missing_feature(s->avctx, "Reduced sampling rates", 1); |
7745 | 240 return -1; |
241 } | |
242 skip_bits(gbc, 5); // skip bitstream id | |
243 | |
244 /* volume control params */ | |
245 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) { | |
246 skip_bits(gbc, 5); // skip dialog normalization | |
247 if (get_bits1(gbc)) { | |
248 skip_bits(gbc, 8); // skip compression gain word | |
249 } | |
250 } | |
251 | |
252 /* dependent stream channel map */ | |
253 if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) { | |
254 if (get_bits1(gbc)) { | |
255 skip_bits(gbc, 16); // skip custom channel map | |
256 } | |
257 } | |
258 | |
259 /* mixing metadata */ | |
260 if (get_bits1(gbc)) { | |
261 /* center and surround mix levels */ | |
262 if (s->channel_mode > AC3_CHMODE_STEREO) { | |
263 skip_bits(gbc, 2); // skip preferred stereo downmix mode | |
264 if (s->channel_mode & 1) { | |
265 /* if three front channels exist */ | |
266 skip_bits(gbc, 3); //skip Lt/Rt center mix level | |
267 s->center_mix_level = get_bits(gbc, 3); | |
268 } | |
269 if (s->channel_mode & 4) { | |
270 /* if a surround channel exists */ | |
271 skip_bits(gbc, 3); //skip Lt/Rt surround mix level | |
272 s->surround_mix_level = get_bits(gbc, 3); | |
273 } | |
274 } | |
275 | |
276 /* lfe mix level */ | |
277 if (s->lfe_on && get_bits1(gbc)) { | |
278 // TODO: use LFE mix level | |
279 skip_bits(gbc, 5); // skip LFE mix level code | |
280 } | |
281 | |
282 /* info for mixing with other streams and substreams */ | |
283 if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT) { | |
284 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) { | |
285 // TODO: apply program scale factor | |
286 if (get_bits1(gbc)) { | |
287 skip_bits(gbc, 6); // skip program scale factor | |
288 } | |
289 } | |
290 if (get_bits1(gbc)) { | |
291 skip_bits(gbc, 6); // skip external program scale factor | |
292 } | |
293 /* skip mixing parameter data */ | |
294 switch(get_bits(gbc, 2)) { | |
295 case 1: skip_bits(gbc, 5); break; | |
296 case 2: skip_bits(gbc, 12); break; | |
297 case 3: { | |
298 int mix_data_size = (get_bits(gbc, 5) + 2) << 3; | |
299 skip_bits_long(gbc, mix_data_size); | |
300 break; | |
301 } | |
302 } | |
303 /* skip pan information for mono or dual mono source */ | |
304 if (s->channel_mode < AC3_CHMODE_STEREO) { | |
305 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) { | |
306 if (get_bits1(gbc)) { | |
307 /* note: this is not in the ATSC A/52B specification | |
308 reference: ETSI TS 102 366 V1.1.1 | |
309 section: E.1.3.1.25 */ | |
310 skip_bits(gbc, 8); // skip pan mean direction index | |
311 skip_bits(gbc, 6); // skip reserved paninfo bits | |
312 } | |
313 } | |
314 } | |
315 /* skip mixing configuration information */ | |
316 if (get_bits1(gbc)) { | |
317 for (blk = 0; blk < s->num_blocks; blk++) { | |
318 if (s->num_blocks == 1 || get_bits1(gbc)) { | |
319 skip_bits(gbc, 5); | |
320 } | |
321 } | |
322 } | |
323 } | |
324 } | |
325 | |
326 /* informational metadata */ | |
327 if (get_bits1(gbc)) { | |
328 skip_bits(gbc, 3); // skip bit stream mode | |
329 skip_bits(gbc, 2); // skip copyright bit and original bitstream bit | |
330 if (s->channel_mode == AC3_CHMODE_STEREO) { | |
331 skip_bits(gbc, 4); // skip Dolby surround and headphone mode | |
332 } | |
333 if (s->channel_mode >= AC3_CHMODE_2F2R) { | |
334 skip_bits(gbc, 2); // skip Dolby surround EX mode | |
335 } | |
336 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) { | |
337 if (get_bits1(gbc)) { | |
338 skip_bits(gbc, 8); // skip mix level, room type, and A/D converter type | |
339 } | |
340 } | |
341 if (s->bit_alloc_params.sr_code != EAC3_SR_CODE_REDUCED) { | |
342 skip_bits1(gbc); // skip source sample rate code | |
343 } | |
344 } | |
345 | |
346 /* converter synchronization flag | |
347 If frames are less than six blocks, this bit should be turned on | |
348 once every 6 blocks to indicate the start of a frame set. | |
349 reference: RFC 4598, Section 2.1.3 Frame Sets */ | |
350 if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && s->num_blocks != 6) { | |
351 skip_bits1(gbc); // skip converter synchronization flag | |
352 } | |
353 | |
354 /* original frame size code if this stream was converted from AC-3 */ | |
355 if (s->frame_type == EAC3_FRAME_TYPE_AC3_CONVERT && | |
356 (s->num_blocks == 6 || get_bits1(gbc))) { | |
357 skip_bits(gbc, 6); // skip frame size code | |
358 } | |
359 | |
360 /* additional bitstream info */ | |
361 if (get_bits1(gbc)) { | |
362 int addbsil = get_bits(gbc, 6); | |
363 for (i = 0; i < addbsil + 1; i++) { | |
364 skip_bits(gbc, 8); // skip additional bit stream info | |
365 } | |
366 } | |
367 | |
368 /* audio frame syntax flags, strategy data, and per-frame data */ | |
369 | |
370 if (s->num_blocks == 6) { | |
371 ac3_exponent_strategy = get_bits1(gbc); | |
372 parse_aht_info = get_bits1(gbc); | |
373 } else { | |
374 /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and | |
375 do not use AHT */ | |
376 ac3_exponent_strategy = 1; | |
377 parse_aht_info = 0; | |
378 } | |
379 | |
380 s->snr_offset_strategy = get_bits(gbc, 2); | |
381 parse_transient_proc_info = get_bits1(gbc); | |
382 | |
383 s->block_switch_syntax = get_bits1(gbc); | |
384 if (!s->block_switch_syntax) | |
385 memset(s->block_switch, 0, sizeof(s->block_switch)); | |
386 | |
387 s->dither_flag_syntax = get_bits1(gbc); | |
388 if (!s->dither_flag_syntax) { | |
389 for (ch = 1; ch <= s->fbw_channels; ch++) | |
390 s->dither_flag[ch] = 1; | |
391 } | |
392 s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0; | |
393 | |
394 s->bit_allocation_syntax = get_bits1(gbc); | |
395 if (!s->bit_allocation_syntax) { | |
396 /* set default bit allocation parameters */ | |
397 s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2]; | |
398 s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[1]; | |
399 s->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab [1]; | |
400 s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[2]; | |
401 s->bit_alloc_params.floor = ff_ac3_floor_tab [7]; | |
402 } | |
403 | |
404 s->fast_gain_syntax = get_bits1(gbc); | |
405 s->dba_syntax = get_bits1(gbc); | |
406 s->skip_syntax = get_bits1(gbc); | |
407 parse_spx_atten_data = get_bits1(gbc); | |
408 | |
409 /* coupling strategy occurance and coupling use per block */ | |
410 num_cpl_blocks = 0; | |
411 if (s->channel_mode > 1) { | |
412 for (blk = 0; blk < s->num_blocks; blk++) { | |
413 s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc)); | |
414 if (s->cpl_strategy_exists[blk]) { | |
415 s->cpl_in_use[blk] = get_bits1(gbc); | |
416 } else { | |
417 s->cpl_in_use[blk] = s->cpl_in_use[blk-1]; | |
418 } | |
419 num_cpl_blocks += s->cpl_in_use[blk]; | |
420 } | |
421 } else { | |
422 memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use)); | |
423 } | |
424 | |
425 /* exponent strategy data */ | |
426 if (ac3_exponent_strategy) { | |
427 /* AC-3-style exponent strategy syntax */ | |
428 for (blk = 0; blk < s->num_blocks; blk++) { | |
429 for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) { | |
430 s->exp_strategy[blk][ch] = get_bits(gbc, 2); | |
431 } | |
432 } | |
433 } else { | |
434 /* LUT-based exponent strategy syntax */ | |
435 for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) { | |
7750
f9bd775992d4
merge declaration and init. variable is not used outside the loop.
jbr
parents:
7745
diff
changeset
|
436 int frmchexpstr = get_bits(gbc, 5); |
7745 | 437 for (blk = 0; blk < 6; blk++) { |
438 s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk]; | |
439 } | |
440 } | |
441 } | |
442 /* LFE exponent strategy */ | |
443 if (s->lfe_on) { | |
444 for (blk = 0; blk < s->num_blocks; blk++) { | |
445 s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc); | |
446 } | |
447 } | |
448 /* original exponent strategies if this stream was converted from AC-3 */ | |
449 if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && | |
450 (s->num_blocks == 6 || get_bits1(gbc))) { | |
7752
e3fb2606d5b5
skip converter exponent strategy for all channels at once
jbr
parents:
7750
diff
changeset
|
451 skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy |
7745 | 452 } |
453 | |
454 /* determine which channels use AHT */ | |
455 if (parse_aht_info) { | |
7755
1c0e498ac7bd
simplify code and comment regarding determination whether or not AHT is used.
jbr
parents:
7754
diff
changeset
|
456 /* For AHT to be used, all non-zero blocks must reuse exponents from |
1c0e498ac7bd
simplify code and comment regarding determination whether or not AHT is used.
jbr
parents:
7754
diff
changeset
|
457 the first block. Furthermore, for AHT to be used in the coupling |
1c0e498ac7bd
simplify code and comment regarding determination whether or not AHT is used.
jbr
parents:
7754
diff
changeset
|
458 channel, all blocks must use coupling and use the same coupling |
1c0e498ac7bd
simplify code and comment regarding determination whether or not AHT is used.
jbr
parents:
7754
diff
changeset
|
459 strategy. */ |
7745 | 460 s->channel_uses_aht[CPL_CH]=0; |
461 for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) { | |
7755
1c0e498ac7bd
simplify code and comment regarding determination whether or not AHT is used.
jbr
parents:
7754
diff
changeset
|
462 int use_aht = 1; |
1c0e498ac7bd
simplify code and comment regarding determination whether or not AHT is used.
jbr
parents:
7754
diff
changeset
|
463 for (blk = 1; blk < 6; blk++) { |
1c0e498ac7bd
simplify code and comment regarding determination whether or not AHT is used.
jbr
parents:
7754
diff
changeset
|
464 if ((s->exp_strategy[blk][ch] != EXP_REUSE) || |
1c0e498ac7bd
simplify code and comment regarding determination whether or not AHT is used.
jbr
parents:
7754
diff
changeset
|
465 (!ch && s->cpl_strategy_exists[blk])) { |
1c0e498ac7bd
simplify code and comment regarding determination whether or not AHT is used.
jbr
parents:
7754
diff
changeset
|
466 use_aht = 0; |
1c0e498ac7bd
simplify code and comment regarding determination whether or not AHT is used.
jbr
parents:
7754
diff
changeset
|
467 break; |
1c0e498ac7bd
simplify code and comment regarding determination whether or not AHT is used.
jbr
parents:
7754
diff
changeset
|
468 } |
7745 | 469 } |
7755
1c0e498ac7bd
simplify code and comment regarding determination whether or not AHT is used.
jbr
parents:
7754
diff
changeset
|
470 s->channel_uses_aht[ch] = use_aht && get_bits1(gbc); |
7745 | 471 } |
472 } else { | |
473 memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht)); | |
474 } | |
475 | |
476 /* per-frame SNR offset */ | |
477 if (!s->snr_offset_strategy) { | |
478 int csnroffst = (get_bits(gbc, 6) - 15) << 4; | |
479 int snroffst = (csnroffst + get_bits(gbc, 4)) << 2; | |
480 for (ch = 0; ch <= s->channels; ch++) | |
481 s->snr_offset[ch] = snroffst; | |
482 } | |
483 | |
484 /* transient pre-noise processing data */ | |
485 if (parse_transient_proc_info) { | |
486 for (ch = 1; ch <= s->fbw_channels; ch++) { | |
487 if (get_bits1(gbc)) { // channel in transient processing | |
488 skip_bits(gbc, 10); // skip transient processing location | |
489 skip_bits(gbc, 8); // skip transient processing length | |
490 } | |
491 } | |
492 } | |
493 | |
494 /* spectral extension attenuation data */ | |
8142
f17b1eb9ccd1
revert r15812 (E-AC-3 Spectral Extension) pending further review
jbr
parents:
8136
diff
changeset
|
495 if (parse_spx_atten_data) { |
9891
7ad7d4094d1f
Rename ff_log_missing_feature() to av_log_missing_feature().
rbultje
parents:
9708
diff
changeset
|
496 av_log_missing_feature(s->avctx, "Spectral extension attenuation", 1); |
8142
f17b1eb9ccd1
revert r15812 (E-AC-3 Spectral Extension) pending further review
jbr
parents:
8136
diff
changeset
|
497 for (ch = 1; ch <= s->fbw_channels; ch++) { |
f17b1eb9ccd1
revert r15812 (E-AC-3 Spectral Extension) pending further review
jbr
parents:
8136
diff
changeset
|
498 if (get_bits1(gbc)) { // channel has spx attenuation |
f17b1eb9ccd1
revert r15812 (E-AC-3 Spectral Extension) pending further review
jbr
parents:
8136
diff
changeset
|
499 skip_bits(gbc, 5); // skip spx attenuation code |
f17b1eb9ccd1
revert r15812 (E-AC-3 Spectral Extension) pending further review
jbr
parents:
8136
diff
changeset
|
500 } |
f17b1eb9ccd1
revert r15812 (E-AC-3 Spectral Extension) pending further review
jbr
parents:
8136
diff
changeset
|
501 } |
f17b1eb9ccd1
revert r15812 (E-AC-3 Spectral Extension) pending further review
jbr
parents:
8136
diff
changeset
|
502 } |
7745 | 503 |
504 /* block start information */ | |
505 if (s->num_blocks > 1 && get_bits1(gbc)) { | |
506 /* reference: Section E2.3.2.27 | |
507 nblkstrtbits = (numblks - 1) * (4 + ceiling(log2(words_per_frame))) | |
508 The spec does not say what this data is or what it's used for. | |
509 It is likely the offset of each block within the frame. */ | |
510 int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2)); | |
8272 | 511 skip_bits_long(gbc, block_start_bits); |
9891
7ad7d4094d1f
Rename ff_log_missing_feature() to av_log_missing_feature().
rbultje
parents:
9708
diff
changeset
|
512 av_log_missing_feature(s->avctx, "Block start info", 1); |
7745 | 513 } |
514 | |
515 /* syntax state initialization */ | |
516 for (ch = 1; ch <= s->fbw_channels; ch++) { | |
517 s->first_cpl_coords[ch] = 1; | |
518 } | |
519 s->first_cpl_leak = 1; | |
520 | |
521 return 0; | |
522 } |