1 /*
2 * LXF demuxer
3 * Copyright (c) 2010 Tomas Härdin
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 #include <inttypes.h>
23
29
30 #define LXF_MAX_PACKET_HEADER_SIZE 256
31 #define LXF_HEADER_DATA_SIZE 120
32 #define LXF_IDENT "LEITCH0円"
33 #define LXF_IDENT_LENGTH 8
34 #define LXF_SAMPLERATE 48000
35
48 };
49
51 int channels;
///< number of audio channels. zero means no audio
55
57 {
60
61 return 0;
62 }
63
64 /**
65 * Verify the checksum of an LXF packet header
66 *
67 * @param[in] header the packet header to check
68 * @return zero if the checksum is OK, non-zero otherwise
69 */
71 {
72 int x;
73 uint32_t sum = 0;
74
75 for (x = 0; x <
size; x += 4)
77
78 return sum;
79 }
80
81 /**
82 * Read input until we find the next ident. If found, copy it to the header buffer
83 *
84 * @param[out] header where to copy the ident to
85 * @return 0 if an ident was found, < 0 on I/O error
86 */
88 {
91
94
98
101 }
102
104
105 return 0;
106 }
107
108 /**
109 * Read and checksum the next packet header
110 *
111 * @return the size of the payload following the header or < 0 on failure
112 */
114 {
122
123 //find and read the ident
126
130
131 version = bytestream_get_le32(&p);
132 header_size = bytestream_get_le32(&p);
135
136 if (header_size < (
version ? 72 : 60) ||
138 (header_size & 3)) {
141 }
142
143 //read the rest of the packet header
145 header_size - (p -
header))) !=
146 header_size - (p -
header))
148
151
154
157 case 0:
158 //video
160 ret = bytestream_get_le32(&p);
161 //skip VBI data and metadata
164 break;
165 case 1:
166 //audio
167 if (
s->nb_streams < 2) {
169 break;
170 }
171
173 p += 8;
174 audio_format = bytestream_get_le32(&p);
176 track_size = bytestream_get_le32(&p);
177
179
180 //set codec based on specified audio bitdepth
181 //we only support tightly packed 16-, 20-, 24- and 32-bit PCM at the moment
183
187 }
188
194 default:
197 }
198
200
201 //use audio packet size to determine video standard
202 //for NTSC we have one 8008-sample audio frame per five video frames
205 } else {
206 //assume PAL, but warn if we don't have 1920 samples
209 "video doesn't seem to be PAL or NTSC. guessing PAL\n");
210
212 }
213
216 //TODO: warning if track mask != (1 << channels) - 1?
218
219 break;
220 default:
221 tmp = bytestream_get_le32(&p);
222 ret = bytestream_get_le32(&p);
225 break;
226 }
227
229 }
230
232 {
238 uint32_t video_params, disk_params;
239 uint16_t record_date, expiration_date;
240
243
248 }
249
252
255
257 video_params =
AV_RL32(&header_data[40]);
258 record_date =
AV_RL16(&header_data[56]);
259 expiration_date =
AV_RL16(&header_data[58]);
260 disk_params =
AV_RL32(&header_data[116]);
261
267
269 record_date, 1900 + (record_date & 0x7F), (record_date >> 7) & 0xF,
270 (record_date >> 11) & 0x1F);
271
273 expiration_date, 1900 + (expiration_date & 0x7F), (expiration_date >> 7) & 0xF,
274 (expiration_date >> 11) & 0x1F);
275
276 if ((video_params >> 22) & 1)
278
279 if ((lxf->
channels = 1 << (disk_params >> 4 & 3) + 1)) {
282
286
288 }
289
291
292 return 0;
293 }
294
296 {
299 uint32_t stream;
301
304
306
307 if (stream > 1) {
309 "got packet with illegal stream index %"PRIu32"\n", stream);
311 }
312
313 if (stream == 1 &&
s->nb_streams < 2) {
316 }
317
319 return ret2;
320
323 }
324
326
327 if (!stream) {
328 //picture type (0 = closed I, 1 = open I, 2 = P, 3 = B)
331
333 }
334
336 }
337
346 };