1 /*
2 * Copyright (C) 2016 foo86
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
24
29
30 #define MIN_PACKET_SIZE 16
31 #define MAX_PACKET_SIZE 0x104000
32
34 {
35 static const uint8_t dca2wav_norm[28] = {
36 2, 0, 1, 9, 10, 3, 8, 4, 5, 9, 10, 6, 7, 12,
37 13, 14, 3, 6, 7, 11, 12, 14, 16, 15, 17, 8, 4, 5,
38 };
39
40 static const uint8_t dca2wav_wide[28] = {
41 2, 0, 1, 4, 5, 3, 8, 4, 5, 9, 10, 6, 7, 12,
42 13, 14, 3, 9, 10, 11, 12, 14, 16, 15, 17, 8, 4, 5,
43 };
44
45 int dca_ch, wav_ch, nchannels = 0;
46
49 if (dca_mask & (1
U << dca_ch))
50 ch_remap[nchannels++] = dca_ch;
52 } else {
53 int wav_mask = 0;
54 int wav_map[18];
55 const uint8_t *dca2wav;
58 dca2wav = dca2wav_wide;
59 else
60 dca2wav = dca2wav_norm;
61 for (dca_ch = 0; dca_ch < 28; dca_ch++) {
62 if (dca_mask & (1 << dca_ch)) {
63 wav_ch = dca2wav[dca_ch];
64 if (!(wav_mask & (1 << wav_ch))) {
65 wav_map[wav_ch] = dca_ch;
66 wav_mask |= 1 << wav_ch;
67 }
68 }
69 }
70 for (wav_ch = 0; wav_ch < 18; wav_ch++)
71 if (wav_mask & (1 << wav_ch))
72 ch_remap[nchannels++] = wav_map[wav_ch];
74 }
75
77 return nchannels;
78 }
79
81 int *coeff_l, int nsamples, int ch_mask)
82 {
85
87
88 // Scale left and right channels
92
93 // Downmix remaining channels
94 for (spkr = 0; spkr <= max_spkr; spkr++) {
95 if (!(ch_mask & (1
U << spkr)))
96 continue;
97
100 *coeff_l, nsamples);
101
104 *coeff_r, nsamples);
105
106 coeff_l++;
107 coeff_r++;
108 }
109 }
110
112 int *coeff_l, int nsamples, int ch_mask)
113 {
116 const float scale = 1.0f / (1 << 15);
117
119
120 // Scale left and right channels
125 coeff_r[
pos + 1] *
scale, nsamples);
126
127 // Downmix remaining channels
128 for (spkr = 0; spkr <= max_spkr; spkr++) {
129 if (!(ch_mask & (1
U << spkr)))
130 continue;
131
134 *coeff_l *
scale, nsamples);
135
138 *coeff_r *
scale, nsamples);
139
140 coeff_l++;
141 coeff_r++;
142 }
143 }
144
146 int *got_frame_ptr,
AVPacket *avpkt)
147 {
151 int input_size = avpkt->
size;
152 int i,
ret, prev_packet =
s->packet;
153 uint32_t mrk;
154
158 }
159
160 // Convert input to BE format
166
169
173 }
174
177 }
178
180
181 // Parse backward compatible core sub-stream
184
187
189
190 // EXXS data must be aligned on 4-byte boundary
195 }
196 }
197
200
201 // Parse extension sub-stream (EXSS)
206 } else {
208 asset = &
s->exss.assets[0];
209 }
210 }
211
212 // Parse XLL component in EXSS
215 // Conceal XLL synchronization error
222 } else {
224 }
225 }
226
227 // Parse LBR component in EXSS
232 } else {
234 }
235 }
236
237 // Parse core extensions in EXSS or backward compatible core sub-stream
241 }
242
243 // Filter the frame
249 int x96_synth = -1;
250
251 // Enable X96 synthesis if needed
252 if (
s->xll.chset[0].freq == 96000 &&
s->core.sample_rate == 48000)
253 x96_synth = 1;
254
257
258 // Force lossy downmixed output on the first core frame filtered.
259 // This prevents audible clicks when seeking and is consistent with
260 // what reference decoder does when there are multiple channel sets.
262 &&
s->xll.nchsets > 1) {
265 }
266
267 // Set 'residual ok' flag for the next frame
269 }
270
272 // Fall back to core unless hard error
279 }
285 } else {
290 }
291
292 *got_frame_ptr = 1;
293
295 }
296
298 {
300
304
306 }
307
309 {
311
315
318
319 return 0;
320 }
321
323 {
326 }
327
329 {
332
334 s->core.avctx = avctx;
335 s->exss.avctx = avctx;
336 s->xll.avctx = avctx;
337 s->lbr.avctx = avctx;
338
341
344
346 s->core.dcadsp = &
s->dcadsp;
347 s->xll.dcadsp = &
s->dcadsp;
348 s->lbr.dcadsp = &
s->dcadsp;
349
351
353 case 0:
354 s->request_channel_layout = 0;
355 break;
359 break;
362 break;
365 break;
366 default:
368 break;
369 }
370
372
373 return 0;
374 }
375
376 #define OFFSET(x) offsetof(DCAContext, x)
377 #define PARAM AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
378
382 };
383
390 };
391
408 };