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
30
38
39 #define IS_MARKER(state, i, buf, buf_size) \
40 ((state == DCA_MARKER_14B_LE && (i < buf_size-2) && (buf[i+1] & 0xF0) == 0xF0 && buf[i+2] == 0x07) \
41 || (state == DCA_MARKER_14B_BE && (i < buf_size-2) && buf[i+1] == 0x07 && (buf[i+2] & 0xF0) == 0xF0) \
42 || state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE || state == DCA_HD_MARKER)
43
44 /**
45 * Find the end of the current frame in the bitstream.
46 * @return the position of the first byte of the next frame, or -1
47 */
49 int buf_size)
50 {
51 int start_found, i;
54
57
58 i = 0;
59 if (!start_found) {
60 for (i = 0; i < buf_size; i++) {
61 state = (state << 8) | buf[i];
64 start_found = 1;
66 break;
67 }
68 }
69 }
70 }
71 if (start_found) {
72 for (; i < buf_size; i++) {
74 state = (state << 8) | buf[i];
79 continue;
80 // We have to check that we really read a full frame here, and that it isn't a pure HD frame, because their size is not constant.
83 }
87 return i - 3;
88 }
89 }
90 }
94 }
95
97 {
99
101 return 0;
102 }
103
105 int max_size)
106 {
107 uint32_t mrk;
108 int i, tmp;
109 const uint16_t *ssrc = (const uint16_t *) src;
110 uint16_t *sdst = (uint16_t *) dst;
112
113 if ((unsigned) src_size > (unsigned) max_size)
114 src_size = max_size;
115
117 switch (mrk) {
119 memcpy(dst, src, src_size);
120 return src_size;
122 for (i = 0; i < (src_size + 1) >> 1; i++)
124 return src_size;
128 for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) {
131 }
134 default:
136 }
137 }
138
141 {
144 int ret, sample_blocks, sr_code;
145
146 if (buf_size < 12)
148
150 return ret;
151
153
155 sample_blocks =
get_bits(&gb, 7) + 1;
156 if (sample_blocks < 8)
158 *duration = 256 * (sample_blocks / 8);
159
163 if (*sample_rate == 0)
165
166 return 0;
167 }
168
171 const uint8_t ** poutbuf,
int *poutbuf_size,
172 const uint8_t * buf,
int buf_size)
173 {
177
179 next = buf_size;
180 } else {
182
185 *poutbuf_size = 0;
186 return buf_size;
187 }
188 }
189
190 /* read the duration and sample rate from the frame header */
194 } else
196
197 *poutbuf = buf;
198 *poutbuf_size = buf_size;
199 return next;
200 }
201
208 };