1 /*
2 * MLP parser
3 * Copyright (c) 2007 Ian Caulfield
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 /**
23 * @file
24 * MLP parser
25 */
26
27 #include <stdint.h>
28
35
37 16, 20, 24, 0, 0, 0, 0, 0,
38 0, 0, 0, 0, 0, 0, 0, 0,
39 };
40
42 1, 2, 3, 4, 3, 4, 5, 3, 4, 5, 4, 5, 6, 4, 5, 4,
43 5, 6, 5, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 };
45
68 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
69 };
70
72 // LR C LFE LRs LRvh LRc LRrs Cs Ts LRsd LRw Cvh LFE2
73 2, 1, 1, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1
74 };
75
90 };
91
93 {
94 if (in == 0xF)
95 return 0;
96
97 return (in & 8 ? 44100 : 48000) << (in & 7) ;
98 }
99
101 {
102 int channels = 0, i;
103
104 for (i = 0; i < 13; i++)
106
107 return channels;
108 }
109
111 {
112 int i;
114
115 for (i = 0; i < 13; i++)
116 layout |=
thd_layout[i] * ((chanmap >> i) & 1);
117
119 }
120
121 /** Read a major sync info header - contains high level information about
122 * the stream - sample rate, channel arrangement etc. Most of this
123 * information is not actually necessary for decoding, only for playback.
124 * gb must be a freshly initialized GetBitContext with no bits read.
125 */
126
128 {
129 int ratebits, channel_arrangement;
130 uint16_t checksum;
131
133
136 return -1;
137 }
138
143 }
144
147
149
153
157
159
161 channel_arrangement =
get_bits(gb, 5);
165 mh->
group1_bits = 24;
// TODO: Is this information actually conveyed anywhere?
167
171
173
175 channel_arrangement =
get_bits(gb, 5);
178
180
181 channel_arrangement =
get_bits(gb, 13);
184 } else
186
189
191
193
195
197
199
200 return 0;
201 }
202
204 {
206
208
210
213
215 {
217 return 0;
218 }
219
222 const uint8_t **poutbuf,
int *poutbuf_size,
224 {
226 int sync_present;
228 int next;
229 int i, p = 0;
230
231 *poutbuf_size = 0;
232 if (buf_size == 0)
233 return 0;
234
236 // Not in sync - find a major sync header
237
238 for (i = 0; i < buf_size; i++) {
240 if ((mp->
pc.
state & 0xfffffffe) == 0xf8726fba &&
241 // ignore if we do not have the data for the start of header
245 break;
246 }
247 }
248
252 return buf_size;
253 }
254
256
257 return i - 7;
258 }
259
261 // Find length of this packet
262
263 /* Copy overread bytes from last frame into buffer. */
266 }
267
268 if (mp->
pc.
index + buf_size < 2) {
271 return buf_size;
272 }
273
277 if (mp->
bytes_left <= 0) {
// prevent infinite loop
278 goto lost_sync;
279 }
281 }
282
284
287 return buf_size;
288 }
289
291
292 sync_present = (
AV_RB32(buf + 4) & 0xfffffffe) == 0xf8726fba;
293
294 if (!sync_present) {
295 /* The first nibble of a frame is a parity check of the 4-byte
296 * access unit header and all the 2- or 4-byte substream headers. */
297 // Only check when this isn't a sync frame - syncs have a checksum.
298
299 parity_bits = 0;
301 parity_bits ^= buf[p++];
302 parity_bits ^= buf[p++];
303
304 if (i < 0 || buf[p-2] & 0x80) {
305 parity_bits ^= buf[p++];
306 parity_bits ^= buf[p++];
307 }
308 }
309
310 if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) {
312 goto lost_sync;
313 }
314 } else {
317
320 goto lost_sync;
321
325 else
329
332 /* MLP stream */
333 #if FF_API_REQUEST_CHANNELS
334 if (avctx->request_channels > 0 && avctx->request_channels <= 2 &&
338 } else
339 #endif
344 } else {
347 }
348 } else { /* mh.stream_type == 0xba */
349 /* TrueHD stream */
350 #if FF_API_REQUEST_CHANNELS
351 if (avctx->request_channels > 0 && avctx->request_channels <= 2 &&
355 } else if (avctx->request_channels > 0 &&
359 } else
360 #endif
369 } else {
372 }
373 }
374 }
375
376 if (!mh.
is_vbr)
/* Stream is CBR */
378
380 }
381
383 *poutbuf_size = buf_size;
384
385 return next;
386
387 lost_sync:
389 return 1;
390 }
391
398 };