1 /*
2 * NuppelVideo demuxer.
3 * Copyright (c) 2006 Reimar Doeffinger
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
29
34 };
35
41
49
51 {
52 if (!memcmp(p->
buf,
"NuppelVideo", 12))
54 if (!memcmp(p->
buf,
"MythTVVideo", 12))
56 return 0;
57 }
58
59 /// little macro to sanitize packet size
60 #define PKTSIZE(s) (s & 0xffffff)
61
62 /**
63 * @brief read until we found all data needed for decoding
64 * @param vst video stream of which to change parameters
65 * @param ast video stream of which to change parameters
66 * @param myth set if this is a MythTVVideo format file
67 * @return 0 or AVERROR code
68 */
71 {
73
74 if (!vst && !myth)
75 return 1; // no codec data needed
78
80 switch (frametype) {
85 if (vst && subtype == 'R') {
89 }
92 size = 0;
93 if (!myth)
94 return 0;
95 }
96 break;
100 if (size != 128 * 4)
101 break;
103 if (vst) {
109 } else
111
112 if (ast) {
114
120
127 0, 0, ~1);
128 }
130
132 } else
134
135 size -= 6 * 4;
137 return 0;
139 size = 11;
140 break;
141 default:
144 break;
145 }
147 }
148
149 return 0;
150 }
151
153 {
156 char id_string[12];
157 double aspect, fps;
160
162 is_mythtv = !memcmp(id_string, "MythTVVideo", 12);
168 avio_rl32(pb);
// unused, "desiredheight"
169 avio_r8(pb);
// 'P' == progressive, 'I' == interlaced
172 if (aspect > 0.9999 && aspect < 1.0001)
173 aspect = 4.0 / 3.0;
175
176 // number of packets per stream type, -1 means unknown, e.g. streaming
180
182
183 if (v_packs) {
185 if (!vst)
188
190 if (ret < 0)
192
199 10000);
200 #if FF_API_R_FRAME_RATE
202 #endif
205 } else
207
208 if (a_packs) {
210 if (!ast)
212 ctx->
a_id = ast->index;
213
216 ast->codec->channels = 2;
218 ast->codec->sample_rate = 44100;
219 ast->codec->bit_rate = 2 * 2 * 44100 * 8;
220 ast->codec->block_align = 2 * 2;
221 ast->codec->bits_per_coded_sample = 16;
223 } else
225
228
230
231 return 0;
232 }
233
235
237 {
243
247
250 return ret < 0 ? ret :
AVERROR(EIO);
251
252 frametype = hdr[0];
254
255 switch (frametype) {
259 break;
260 }
265 break;
266 }
268 if (ret < 0)
270
275 memcpy(pkt->
data, hdr, copyhdrsize);
277 if (ret < 0) {
280 }
281 if (ret < size)
283 return 0;
288 break;
289 }
295 if (ret < 0)
297 return 0;
299 // contains no data, size value is invalid
300 break;
301 default:
303 break;
304 }
305 }
306
308 }
309
310 /**
311 * \brief looks for the string RTjjjjjjjjjj in the stream too resync reading
312 * \return 1 if the syncword is found 0 otherwise.
313 */
318 tag = (tag << 8) |
avio_r8(pb);
319 if (tag ==
MKBETAG(
'R',
'T',
'j',
'j') &&
322 return 1;
323 }
324 return 0;
325 }
326
327 /**
328 * \brief attempts to read a timestamp from stream at the given stream position
329 * \return timestamp if successful and AV_NOPTS_VALUE if failure
330 */
332 int64_t *ppos, int64_t pos_limit)
333 {
339 int64_t pos, dts;
340
343
346
350 frametype = hdr[0];
352 switch (frametype) {
354 break;
359 key = hdr[2] == 0;
360 } else {
362 key = 1;
363 }
364 if (stream_index == idx) {
365
368
369 // TODO - add general support in av_gen_search, so it adds positions after reading timestamps
372
373 *ppos = pos;
374 return dts;
375 }
376 default:
378 break;
379 }
380 }
382 }
383
384
394 };