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
79 i = 0;
80 if (!start_found) {
81 for (; i < buf_size; i++) {
82 size++;
83 state = (state << 8) | buf[i];
84
91
94 else
96
97 start_found = 1;
98 size = 0;
99
100 i++;
101 break;
102 }
103 }
104 }
105
106 if (start_found) {
107 for (; i < buf_size; i++) {
108 size++;
109 state = (state << 8) | buf[i];
110
111 if (start_found == 1) {
114 if (size == 2) {
116 start_found = 2;
117 }
118 break;
120 if (size == 2) {
122 start_found = 4;
123 }
124 break;
126 if (size == 4) {
128 start_found = 4;
129 }
130 break;
132 if (size == 4) {
134 start_found = 4;
135 }
136 break;
138 if (size == 6) {
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
196 {
202
205
208 return ret;
209
212 return ret;
213
216
221 break;
222 default:
224 }
225
228
232 return 0;
233 }
234
236 int nsamples_log2;
237
239 return ret;
240
243
246
251 if (nsamples_log2 > 24)
253
255 *duration = (1 + (*sample_rate > 96000)) << nsamples_log2;
257 return 0;
258 }
259
261 }
262
265 return ret;
268
272 return 0;
273
280 break;
283 break;
284 }
285 }
286
288 if (buf_size - 4 < frame_size)
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,
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
342 *poutbuf_size = buf_size;
343 return next;
344 }
345
352 };
static av_cold int dca_parse_init(AVCodecParserContext *s)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static void skip_bits_long(GetBitContext *s, int n)
#define FF_PROFILE_DTS_HD_HRA
static int dca_find_frame_end(DCAParseContext *pc1, const uint8_t *buf, int buf_size)
Find the end of the current frame in the bitstream.
#define FF_PROFILE_DTS_EXPRESS
int duration
Duration of the current frame.
const uint8_t ff_dca_freq_ranges[16]
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define IS_EXSS_MARKER(state)
#define DCA_SYNCWORD_CORE_14B_BE
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
int extension_mask
Coding components used in asset.
bitstream reader API header.
AVCodecParser ff_dca_parser
#define DCA_SYNCWORD_CORE_BE
#define DCA_PCMBLOCK_SAMPLES
int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size)
Combine the (truncated) bitstream to a complete frame.
#define FF_PROFILE_DTS_ES
const uint32_t ff_dca_sampling_freqs[16]
int lbr_offset
Offset to LBR component from start of substream.
#define DCA_SYNCWORD_CORE_14B_LE
int avpriv_dca_parse_core_frame_header(DCACoreFrameHeader *h, uint8_t *buf, int size)
Parse and validate core frame header.
void ff_parse_close(AVCodecParserContext *s)
static int dca_parse_params(DCAParseContext *pc1, const uint8_t *buf, int buf_size, int *duration, int *sample_rate, int *profile)
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int xll_offset
Offset to XLL data from start of substream.
#define FF_PROFILE_UNKNOWN
int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst, int max_size)
Convert bitstream to one representation based on sync marker.
const uint32_t avpriv_dca_sample_rates[16]
DCAExssAsset assets[1]
Audio asset descriptors.
int xll_size
Size of XLL data in extension substream.
#define FF_ARRAY_ELEMS(a)
#define EXSS_MARKER(state)
int max_sample_rate
Maximum sample rate.
static int dca_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
#define FF_PROFILE_DTS_96_24
#define DCA_CORE_FRAME_HEADER_SIZE
int sample_rate
samples per second
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define DCA_SYNCWORD_CORE_LE
main external API structure.
#define CORE_FRAMESIZE(state)
int lbr_size
Size of LBR component in extension substream.
static void skip_bits(GetBitContext *s, int n)
uint64_t state64
contains the last 8 bytes in MSB order
#define CORE_MARKER(state)
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
#define EXSS_FRAMESIZE(state)
#define PARSER_FLAG_COMPLETE_FRAMES
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
#define DCA_SYNCWORD_SUBSTREAM
int ff_dca_exss_parse(DCAExssParser *s, const uint8_t *data, int size)
#define FF_PROFILE_DTS_HD_MA