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
28
33 };
34
40
48
50 {
51 if (!memcmp(p->
buf,
"NuppelVideo", 12))
53 if (!memcmp(p->
buf,
"MythTVVideo", 12))
55 return 0;
56 }
57
58 /// little macro to sanitize packet size
59 #define PKTSIZE(s) (s & 0xffffff)
60
61 /**
62 * @brief read until we found all data needed for decoding
63 * @param vst video stream of which to change parameters
64 * @param ast video stream of which to change parameters
65 * @param myth set if this is a MythTVVideo format file
66 * @return 0 or AVERROR code
67 */
70 {
72
73 if (!vst && !myth)
74 return 1; // no codec data needed
77
79 switch (frametype) {
84 if (vst && subtype == 'R') {
88 }
94 size = 0;
95 if (!myth)
96 return 0;
97 }
98 break;
102 if (size != 128 * 4)
103 break;
105 if (vst) {
111 } else
113
114 if (ast) {
116
122
129 0, 0, ~1);
130 }
132
134 } else
136
137 size -= 6 * 4;
139 return 0;
141 size = 11;
142 break;
143 default:
146 break;
147 }
149 }
150
151 return 0;
152 }
153
155 {
158 char id_string[12];
159 double aspect, fps;
162
164 is_mythtv = !memcmp(id_string, "MythTVVideo", 12);
170 avio_rl32(pb);
// unused, "desiredheight"
171 avio_r8(pb);
// 'P' == progressive, 'I' == interlaced
174 if (aspect > 0.9999 && aspect < 1.0001)
175 aspect = 4.0 / 3.0;
177
178 // number of packets per stream type, -1 means unknown, e.g. streaming
182
184
185 if (v_packs) {
187 if (!vst)
190
197 10000);
198 #if FF_API_R_FRAME_RATE
200 #endif
203 } else
205
206 if (a_packs) {
208 if (!ast)
210 ctx->
a_id = ast->index;
211
214 ast->codec->channels = 2;
216 ast->codec->sample_rate = 44100;
217 ast->codec->bit_rate = 2 * 2 * 44100 * 8;
218 ast->codec->block_align = 2 * 2;
219 ast->codec->bits_per_coded_sample = 16;
221 } else
223
226
228
229 return 0;
230 }
231
233
235 {
241
245
248 return ret < 0 ? ret :
AVERROR(EIO);
249
250 frametype = hdr[0];
252
253 switch (frametype) {
257 break;
258 }
263 break;
264 }
266 if (ret < 0)
268
273 memcpy(pkt->
data, hdr, copyhdrsize);
275 if (ret < 0) {
278 }
279 if (ret < size)
281 return 0;
286 break;
287 }
293 if (ret < 0)
295 return 0;
297 // contains no data, size value is invalid
298 break;
299 default:
301 break;
302 }
303 }
304
306 }
307
308 /**
309 * \brief looks for the string RTjjjjjjjjjj in the stream too resync reading
310 * \return 1 if the syncword is found 0 otherwise.
311 */
316 tag = (tag << 8) |
avio_r8(pb);
317 if (tag ==
MKBETAG(
'R',
'T',
'j',
'j') &&
320 return 1;
321 }
322 return 0;
323 }
324
325 /**
326 * \brief attempts to read a timestamp from stream at the given stream position
327 * \return timestamp if successful and AV_NOPTS_VALUE if failure
328 */
330 int64_t *ppos, int64_t pos_limit)
331 {
337 int64_t pos, dts;
338
341
344
348 frametype = hdr[0];
350 switch (frametype) {
352 break;
357 key = hdr[2] == 0;
358 } else {
360 key = 1;
361 }
362 if (stream_index == idx) {
363
366
367 // TODO - add general support in av_gen_search, so it adds positions after reading timestamps
370
371 *ppos = pos;
372 return dts;
373 }
374 default:
376 break;
377 }
378 }
380 }
381
382
392 };