1 /*
2 * IEC 61937 demuxer
3 * Copyright (c) 2010 Anssi Hannula <anssi.hannula at iki.fi>
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 * IEC 61937 demuxer, used for compressed data in S/PDIF
25 * @author Anssi Hannula
26 */
27
32
37 {
40
41 switch (data_type & 0xff) {
45 break;
49 break;
53 break;
55 *offset = 4608;
57 break;
61 if (s) /* be silent during a probe */
64 }
67 break;
71 break;
75 break;
79 break;
81 *offset = 2048;
83 break;
85 *offset = 4096;
87 break;
89 *offset = 8192;
91 break;
92 default:
93 if (s) { /* be silent during a probe */
95 data_type);
96 }
98 }
99 return 0;
100 }
101
102 /* Largest offset between bursts we currently handle, i.e. AAC with
103 aac_hdr.samples = 4096 */
104 #define SPDIF_MAX_OFFSET 16384
105
107 {
110 }
111
113 {
116 const uint8_t *expected_code = buf + 7;
118 int sync_codes = 0;
119 int consecutive_codes = 0;
121
122 for (; buf < probe_end; buf++) {
123 state = (state << 8) | *buf;
124
126 && buf[1] < 0x37) {
127 sync_codes++;
128
129 if (buf == expected_code) {
130 if (++consecutive_codes >= 2)
132 } else
133 consecutive_codes = 0;
134
136 break;
137
138 /* continue probing to find more sync codes */
140
141 /* skip directly to the next sync code */
143 &buf[5], &offset, codec)) {
144 if (buf + offset >= p_buf + buf_size)
145 break;
146 expected_code = buf +
offset;
147 buf = expected_code - 7;
148 }
149 }
150 }
151
152 if (!sync_codes)
153 return 0;
154
155 if (sync_codes >= 6)
156 /* good amount of sync codes but with unexpected offsets */
158
159 /* some sync codes were found */
161 }
162
164 {
166 return 0;
167 }
168
170 {
176
178 state = (state << 8) |
avio_r8(pb);
181 }
182
185
186 if (pkt_size_bits % 16)
188
190 if (ret)
192
194
198 }
200
202 &offset, &codec_id);
203 if (ret) {
206 }
207
208 /* skip over the padding to the beginning of the next frame */
210
212 /* first packet, create a stream */
214 if (!st) {
217 }
223 }
224
226 /* stream bitrate matches 16-bit stereo PCM bitrate for currently
227 supported codecs */
229
230 return 0;
231 }
232
240 };