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
28
36
37 #define IS_MARKER(state, i, buf, buf_size) \
38 ((state == DCA_MARKER_14B_LE && (i < buf_size-2) && (buf[i+1] & 0xF0) == 0xF0 && buf[i+2] == 0x07) \
39 || (state == DCA_MARKER_14B_BE && (i < buf_size-2) && buf[i+1] == 0x07 && (buf[i+2] & 0xF0) == 0xF0) \
40 || state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE || state == DCA_HD_MARKER)
41
42 /**
43 * Find the end of the current frame in the bitstream.
44 * @return the position of the first byte of the next frame, or -1
45 */
47 int buf_size)
48 {
49 int start_found, i;
52
55
56 i = 0;
57 if (!start_found) {
58 for (i = 0; i < buf_size; i++) {
59 state = (state << 8) | buf[i];
62 start_found = 1;
64 i++;
65 break;
66 }
67 }
68 }
69 }
70 if (start_found) {
71 for (; i < buf_size; i++) {
73 state = (state << 8) | buf[i];
78 continue;
82 return i - 3;
83 }
84 }
85 }
89 }
90
92 {
94
96 return 0;
97 }
98
101 {
104 int ret, sample_blocks, sr_code;
105
106 if (buf_size < 12)
108
111
113
115 sample_blocks =
get_bits(&gb, 7) + 1;
116 if (sample_blocks < 8)
118 *duration = 256 * (sample_blocks / 8);
119
121 if (*framesize < 95)
123
127 if (*sample_rate == 0)
129
130 return 0;
131 }
132
135 const uint8_t ** poutbuf,
int *poutbuf_size,
137 {
141
143 next = buf_size;
144 } else {
146
148 *poutbuf = NULL;
149 *poutbuf_size = 0;
150 return buf_size;
151 }
152 }
153
154 /* read the duration and sample rate from the frame header */
158 } else
160
162 *poutbuf_size = buf_size;
163 return next;
164 }
165
172 };