1 /*
2 * DCA parser
3 * Copyright (C) 2004 Gildas Bazin
4 * Copyright (C) 2004 Benjamin Zores
5 * Copyright (C) 2006 Benjamin Larsson
6 * Copyright (C) 2007 Konstantin Shishkov
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
32
42
43 #define IS_CORE_MARKER(state) \
44 (((state & 0xFFFFFFFFF0FF) == (((uint64_t)DCA_SYNCWORD_CORE_14B_LE << 16) | 0xF007)) || \
45 ((state & 0xFFFFFFFFFFF0) == (((uint64_t)DCA_SYNCWORD_CORE_14B_BE << 16) | 0x07F0)) || \
46 ((state & 0xFFFFFFFF00FC) == (((uint64_t)DCA_SYNCWORD_CORE_LE << 16) | 0x00FC)) || \
47 ((state & 0xFFFFFFFFFC00) == (((uint64_t)DCA_SYNCWORD_CORE_BE << 16) | 0xFC00)))
48
49 #define IS_EXSS_MARKER(state) ((state & 0xFFFFFFFF) == DCA_SYNCWORD_SUBSTREAM)
50
51 #define IS_MARKER(state) (IS_CORE_MARKER(state) || IS_EXSS_MARKER(state))
52
53 #define CORE_MARKER(state) ((state >> 16) & 0xFFFFFFFF)
54 #define EXSS_MARKER(state) (state & 0xFFFFFFFF)
55
56 #define STATE_LE(state) (((state & 0xFF00FF00) >> 8) | ((state & 0x00FF00FF) << 8))
57 #define STATE_14(state) (((state & 0x3FFF0000) >> 8) | ((state & 0x00003FFF) >> 6))
58
59 #define CORE_FRAMESIZE(state) (((state >> 4) & 0x3FFF) + 1)
60 #define EXSS_FRAMESIZE(state) ((state & 0x2000000000) ? \
61 ((state >> 5) & 0xFFFFF) + 1 : \
62 ((state >> 13) & 0x0FFFF) + 1)
63
64 /**
65 * Find the end of the current frame in the bitstream.
66 * @return the position of the first byte of the next frame, or -1
67 */
69 int buf_size)
70 {
71 int start_found,
size,
i;
74
78
80 if (!start_found) {
81 for (;
i < buf_size;
i++) {
84
91
94 else
96
97 start_found = 1;
99
101 break;
102 }
103 }
104 }
105
106 if (start_found) {
107 for (;
i < buf_size;
i++) {
110
111 if (start_found == 1) {
116 start_found = 2;
117 }
118 break;
122 start_found = 4;
123 }
124 break;
128 start_found = 4;
129 }
130 break;
134 start_found = 4;
135 }
136 break;
140 start_found = 4;
141 }
142 break;
143 default:
145 }
146 continue;
147 }
148
152 start_found = 3;
153 continue;
154 }
155
156 if (start_found == 3) {
159 start_found = 4;
160 }
161 continue;
162 }
163
165 continue;
166
174 }
175 }
176 }
177
182 }
183
185 {
187
190 return 0;
191 }
192
194 int buf_size,
int *
duration,
int *sample_rate,
196 {
202
205
209
213
216
221 break;
222 default:
224 }
225
228
232 return 0;
233 }
234
236 int nsamples_log2;
237
240
243
246
251 if (nsamples_log2 > 24)
253
255 *
duration = (1 + (*sample_rate > 96000)) << nsamples_log2;
257 return 0;
258 }
259
261 }
262
268
272 return 0;
273
275 if (
h.ext_audio_present) {
276 switch (
h.ext_audio_type) {
280 break;
283 break;
284 }
285 }
286
289 return 0;
290
294 return 0;
296 return 0;
297
302
303 return 0;
304 }
305
307 const uint8_t **poutbuf, int *poutbuf_size,
308 const uint8_t *buf, int buf_size)
309 {
313
315 next = buf_size;
316 } else {
318
321 *poutbuf_size = 0;
322 return buf_size;
323 }
324
325 /* skip initial padding */
329 }
331 }
332
333 /* read the duration and sample rate from the frame header */
338 } else
340
341 *poutbuf = buf;
342 *poutbuf_size = buf_size;
343 return next;
344 }
345
352 };