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
36
38 16, 20, 24, 0, 0, 0, 0, 0,
39 0, 0, 0, 0, 0, 0, 0, 0,
40 };
41
43 1, 2, 3, 4, 3, 4, 5, 3, 4, 5, 4, 5, 6, 4, 5, 4,
44 5, 6, 5, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45 };
46
69 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
70 };
71
73 // LR C LFE LRs LRvh LRc LRrs Cs Ts LRsd LRw Cvh LFE2
74 2, 1, 1, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1
75 };
76
91 };
92
94 {
95 if (in == 0xF)
96 return 0;
97
98 return (in & 8 ? 44100 : 48000) << (in & 7) ;
99 }
100
102 {
103 int channels = 0, i;
104
105 for (i = 0; i < 13; i++)
107
108 return channels;
109 }
110
112 {
113 int i;
115
116 for (i = 0; i < 13; i++)
117 layout |=
thd_layout[i] * ((chanmap >> i) & 1);
118
120 }
121
122 /** Read a major sync info header - contains high level information about
123 * the stream - sample rate, channel arrangement etc. Most of this
124 * information is not actually necessary for decoding, only for playback.
125 * gb must be a freshly initialized GetBitContext with no bits read.
126 */
127
129 {
130 int ratebits, channel_arrangement;
131 uint16_t checksum;
132
134
137 return -1;
138 }
139
144 }
145
148
150
154
158
160
162 channel_arrangement =
get_bits(gb, 5);
166 mh->
group1_bits = 24;
// TODO: Is this information actually conveyed anywhere?
168
172
174
177
179 channel_arrangement =
get_bits(gb, 5);
182
184
185 channel_arrangement =
get_bits(gb, 13);
188 } else
190
193
195
197
199
201
203
204 return 0;
205 }
206
208 {
210
212
214
217
219 {
221 return 0;
222 }
223
226 const uint8_t **poutbuf,
int *poutbuf_size,
228 {
230 int sync_present;
232 int next;
234 int i, p = 0;
235
236 *poutbuf_size = 0;
237 if (buf_size == 0)
238 return 0;
239
241 // Not in sync - find a major sync header
242
243 for (i = 0; i < buf_size; i++) {
245 if ((mp->
pc.
state & 0xfffffffe) == 0xf8726fba &&
246 // ignore if we do not have the data for the start of header
250 break;
251 }
252 }
253
257 return buf_size;
258 }
259
263 }
264
265 return i - 7;
266 }
267
269 // Find length of this packet
270
271 /* Copy overread bytes from last frame into buffer. */
274 }
275
276 if (mp->
pc.
index + buf_size < 2) {
279 return buf_size;
280 }
281
285 if (mp->
bytes_left <= 0) {
// prevent infinite loop
286 goto lost_sync;
287 }
289 }
290
292
295 return buf_size;
296 }
297
299
300 sync_present = (
AV_RB32(buf + 4) & 0xfffffffe) == 0xf8726fba;
301
302 if (!sync_present) {
303 /* The first nibble of a frame is a parity check of the 4-byte
304 * access unit header and all the 2- or 4-byte substream headers. */
305 // Only check when this isn't a sync frame - syncs have a checksum.
306
307 parity_bits = 0;
309 parity_bits ^= buf[p++];
310 parity_bits ^= buf[p++];
311
312 if (i < 0 || buf[p-2] & 0x80) {
313 parity_bits ^= buf[p++];
314 parity_bits ^= buf[p++];
315 }
316 }
317
318 if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) {
320 goto lost_sync;
321 }
322 } else {
325
328 goto lost_sync;
329
333 else
337
340 /* MLP stream */
341 #if FF_API_REQUEST_CHANNELS
348 } else
349 #endif
356 } else {
359 }
360 } else { /* mh.stream_type == 0xba */
361 /* TrueHD stream */
362 #if FF_API_REQUEST_CHANNELS
373 } else
374 #endif
387 } else {
390 }
391 }
392 }
393
394 if (!mh.
is_vbr)
/* Stream is CBR */
396
398 }
399
401 *poutbuf_size = buf_size;
402
403 return next;
404
405 lost_sync:
407 return 1;
408 }
409
416 };