nut: Mark non-fatal errors as warnings
[libav.git] / libavformat / nutdec.c
CommitLineData
619d8e2e
MN
1/*
2 * "NUT" Container Format demuxer
3 * Copyright (c) 2004-2006 Michael Niedermayer
4 * Copyright (c) 2003 Alex Beregszaszi
5 *
2912e87a 6 * This file is part of Libav.
619d8e2e 7 *
2912e87a 8 * Libav is free software; you can redistribute it and/or
619d8e2e
MN
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
2912e87a 13 * Libav is distributed in the hope that it will be useful,
619d8e2e
MN
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
2912e87a 19 * License along with Libav; if not, write to the Free Software
619d8e2e 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
619d8e2e
MN
21 */
22
245976da 23#include "libavutil/avstring.h"
6a5d31ac 24#include "libavutil/bswap.h"
d2d67e42 25#include "libavutil/dict.h"
0ebcdf5c 26#include "libavutil/mathematics.h"
245976da 27#include "libavutil/tree.h"
4839c192 28#include "avio_internal.h"
619d8e2e 29#include "nut.h"
bfe5454c 30#include "riff.h"
619d8e2e
MN
31
32#undef NDEBUG
33#include <assert.h>
34
3c0eec06 35#define NUT_MAX_STREAMS 256 /* arbitrary sanity check value */
3c0eec06 36
a559d65c
AL
37static int get_str(AVIOContext *bc, char *string, unsigned int maxlen)
38{
39 unsigned int len = ffio_read_varlen(bc);
619d8e2e 40
a559d65c 41 if (len && maxlen)
b7effd4e 42 avio_read(bc, string, FFMIN(len, maxlen));
a559d65c 43 while (len > maxlen) {
b7effd4e 44 avio_r8(bc);
619d8e2e
MN
45 len--;
46 }
47
a559d65c
AL
48 if (maxlen)
49 string[FFMIN(len, maxlen - 1)] = 0;
619d8e2e 50
a559d65c 51 if (maxlen == len)
619d8e2e
MN
52 return -1;
53 else
54 return 0;
55}
56
a559d65c
AL
57static int64_t get_s(AVIOContext *bc)
58{
4839c192 59 int64_t v = ffio_read_varlen(bc) + 1;
619d8e2e 60
a559d65c
AL
61 if (v & 1)
62 return -(v >> 1);
63 else
64 return (v >> 1);
619d8e2e
MN
65}
66
a559d65c
AL
67static uint64_t get_fourcc(AVIOContext *bc)
68{
69 unsigned int len = ffio_read_varlen(bc);
619d8e2e 70
a559d65c
AL
71 if (len == 2)
72 return avio_rl16(bc);
73 else if (len == 4)
74 return avio_rl32(bc);
75 else
76 return -1;
619d8e2e
MN
77}
78
79#ifdef TRACE
93e81ee8
DB
80static inline uint64_t get_v_trace(AVIOContext *bc, const char *file,
81 const char *func, int line)
a559d65c
AL
82{
83 uint64_t v = ffio_read_varlen(bc);
619d8e2e 84
a559d65c
AL
85 av_log(NULL, AV_LOG_DEBUG, "get_v %5"PRId64" / %"PRIX64" in %s %s:%d\n",
86 v, v, file, func, line);
619d8e2e
MN
87 return v;
88}
89
93e81ee8
DB
90static inline int64_t get_s_trace(AVIOContext *bc, const char *file,
91 const char *func, int line)
a559d65c
AL
92{
93 int64_t v = get_s(bc);
619d8e2e 94
a559d65c
AL
95 av_log(NULL, AV_LOG_DEBUG, "get_s %5"PRId64" / %"PRIX64" in %s %s:%d\n",
96 v, v, file, func, line);
619d8e2e
MN
97 return v;
98}
99
a559d65c
AL
100#define ffio_read_varlen(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
101#define get_s(bc) get_s_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
619d8e2e
MN
102#endif
103
a559d65c
AL
104static int get_packetheader(NUTContext *nut, AVIOContext *bc,
105 int calculate_checksum, uint64_t startcode)
619d8e2e 106{
a47ec310 107 int64_t size;
a559d65c 108// start = avio_tell(bc) - 8;
619d8e2e 109
a559d65c
AL
110 startcode = av_be2ne64(startcode);
111 startcode = ff_crc04C11DB7_update(0, (uint8_t*) &startcode, 8);
073811cd 112
4c4427a7 113 ffio_init_checksum(bc, ff_crc04C11DB7_update, startcode);
a559d65c
AL
114 size = ffio_read_varlen(bc);
115 if (size > 4096)
b7effd4e 116 avio_rb32(bc);
a559d65c 117 if (ffio_get_checksum(bc) && size > 4096)
47772399 118 return -1;
619d8e2e 119
4c4427a7 120 ffio_init_checksum(bc, calculate_checksum ? ff_crc04C11DB7_update : NULL, 0);
619d8e2e 121
619d8e2e
MN
122 return size;
123}
124
a559d65c
AL
125static uint64_t find_any_startcode(AVIOContext *bc, int64_t pos)
126{
127 uint64_t state = 0;
128
129 if (pos >= 0)
130 /* Note, this may fail if the stream is not seekable, but that should
131 * not matter, as in this case we simply start where we currently are */
132 avio_seek(bc, pos, SEEK_SET);
133 while (!bc->eof_reached) {
134 state = (state << 8) | avio_r8(bc);
135 if ((state >> 56) != 'N')
619d8e2e 136 continue;
a559d65c 137 switch (state) {
619d8e2e
MN
138 case MAIN_STARTCODE:
139 case STREAM_STARTCODE:
140 case SYNCPOINT_STARTCODE:
141 case INFO_STARTCODE:
142 case INDEX_STARTCODE:
143 return state;
144 }
145 }
146
147 return 0;
148}
149
150/**
93951943 151 * Find the given startcode.
619d8e2e
MN
152 * @param code the startcode
153 * @param pos the start position of the search, or -1 if the current position
32e543f8 154 * @return the position of the startcode or -1 if not found
619d8e2e 155 */
a559d65c
AL
156static int64_t find_startcode(AVIOContext *bc, uint64_t code, int64_t pos)
157{
158 for (;;) {
159 uint64_t startcode = find_any_startcode(bc, pos);
160 if (startcode == code)
a2704c97 161 return avio_tell(bc) - 8;
a559d65c 162 else if (startcode == 0)
619d8e2e 163 return -1;
a559d65c 164 pos = -1;
619d8e2e
MN
165 }
166}
167
a559d65c
AL
168static int nut_probe(AVProbeData *p)
169{
619d8e2e 170 int i;
a559d65c 171 uint64_t code = 0;
619d8e2e
MN
172
173 for (i = 0; i < p->buf_size; i++) {
174 code = (code << 8) | p->buf[i];
175 if (code == MAIN_STARTCODE)
176 return AVPROBE_SCORE_MAX;
177 }
178 return 0;
179}
180
72d30b27
LB
181#define GET_V(dst, check) \
182 do { \
183 tmp = ffio_read_varlen(bc); \
184 if (!(check)) { \
185 av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp); \
e0c53c34 186 return AVERROR_INVALIDDATA; \
72d30b27
LB
187 } \
188 dst = tmp; \
189 } while (0)
619d8e2e 190
a559d65c
AL
191static int skip_reserved(AVIOContext *bc, int64_t pos)
192{
a2704c97 193 pos -= avio_tell(bc);
a559d65c 194 if (pos < 0) {
6b4aa5da 195 avio_seek(bc, pos, SEEK_CUR);
e0c53c34 196 return AVERROR_INVALIDDATA;
a559d65c
AL
197 } else {
198 while (pos--)
b7effd4e 199 avio_r8(bc);
619d8e2e
MN
200 return 0;
201 }
202}
203
a559d65c
AL
204static int decode_main_header(NUTContext *nut)
205{
206 AVFormatContext *s = nut->avf;
207 AVIOContext *bc = s->pb;
619d8e2e
MN
208 uint64_t tmp, end;
209 unsigned int stream_count;
a559d65c
AL
210 int i, j, count;
211 int tmp_stream, tmp_mul, tmp_pts, tmp_size, tmp_res, tmp_head_idx;
619d8e2e 212
a559d65c 213 end = get_packetheader(nut, bc, 1, MAIN_STARTCODE);
a2704c97 214 end += avio_tell(bc);
619d8e2e 215
c94e2e85 216 nut->version = ffio_read_varlen(bc);
52a1c32c
LB
217 if (nut->version < NUT_MIN_VERSION &&
218 nut->version > NUT_MAX_VERSION) {
219 av_log(s, AV_LOG_ERROR, "Version %d not supported.\n",
220 nut->version);
e0c53c34
LB
221 return AVERROR(ENOSYS);
222 }
223
72d30b27 224 GET_V(stream_count, tmp > 0 && tmp <= NUT_MAX_STREAMS);
619d8e2e 225
4839c192 226 nut->max_distance = ffio_read_varlen(bc);
a559d65c 227 if (nut->max_distance > 65536) {
619d8e2e 228 av_log(s, AV_LOG_DEBUG, "max_distance %d\n", nut->max_distance);
a559d65c 229 nut->max_distance = 65536;
619d8e2e
MN
230 }
231
72d30b27 232 GET_V(nut->time_base_count, tmp > 0 && tmp < INT_MAX / sizeof(AVRational));
a559d65c 233 nut->time_base = av_malloc(nut->time_base_count * sizeof(AVRational));
3035d21b
HBL
234 if (!nut->time_base)
235 return AVERROR(ENOMEM);
619d8e2e 236
a559d65c 237 for (i = 0; i < nut->time_base_count; i++) {
72d30b27
LB
238 GET_V(nut->time_base[i].num, tmp > 0 && tmp < (1ULL << 31));
239 GET_V(nut->time_base[i].den, tmp > 0 && tmp < (1ULL << 31));
a559d65c 240 if (av_gcd(nut->time_base[i].num, nut->time_base[i].den) != 1) {
62f72b40
LB
241 av_log(s, AV_LOG_ERROR, "invalid time base %d/%d\n",
242 nut->time_base[i].num,
243 nut->time_base[i].den);
0d3ee135 244 return AVERROR_INVALIDDATA;
619d8e2e
MN
245 }
246 }
a559d65c
AL
247 tmp_pts = 0;
248 tmp_mul = 1;
249 tmp_stream = 0;
250 tmp_head_idx = 0;
251 for (i = 0; i < 256;) {
252 int tmp_flags = ffio_read_varlen(bc);
253 int tmp_fields = ffio_read_varlen(bc);
254
255 if (tmp_fields > 0)
256 tmp_pts = get_s(bc);
257 if (tmp_fields > 1)
258 tmp_mul = ffio_read_varlen(bc);
259 if (tmp_fields > 2)
260 tmp_stream = ffio_read_varlen(bc);
261 if (tmp_fields > 3)
262 tmp_size = ffio_read_varlen(bc);
263 else
264 tmp_size = 0;
265 if (tmp_fields > 4)
266 tmp_res = ffio_read_varlen(bc);
267 else
268 tmp_res = 0;
269 if (tmp_fields > 5)
270 count = ffio_read_varlen(bc);
271 else
272 count = tmp_mul - tmp_size;
273 if (tmp_fields > 6)
274 get_s(bc);
275 if (tmp_fields > 7)
276 tmp_head_idx = ffio_read_varlen(bc);
277
278 while (tmp_fields-- > 8)
279 ffio_read_varlen(bc);
280
281 if (count == 0 || i + count > 256) {
619d8e2e 282 av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i);
0d3ee135 283 return AVERROR_INVALIDDATA;
619d8e2e 284 }
a559d65c 285 if (tmp_stream >= stream_count) {
62f72b40
LB
286 av_log(s, AV_LOG_ERROR, "illegal stream number %d >= %d\n",
287 tmp_stream, stream_count);
0d3ee135 288 return AVERROR_INVALIDDATA;
619d8e2e
MN
289 }
290
a559d65c 291 for (j = 0; j < count; j++, i++) {
619d8e2e 292 if (i == 'N') {
a559d65c 293 nut->frame_code[i].flags = FLAG_INVALID;
619d8e2e
MN
294 j--;
295 continue;
296 }
a559d65c
AL
297 nut->frame_code[i].flags = tmp_flags;
298 nut->frame_code[i].pts_delta = tmp_pts;
299 nut->frame_code[i].stream_id = tmp_stream;
300 nut->frame_code[i].size_mul = tmp_mul;
301 nut->frame_code[i].size_lsb = tmp_size + j;
302 nut->frame_code[i].reserved_count = tmp_res;
303 nut->frame_code[i].header_idx = tmp_head_idx;
619d8e2e
MN
304 }
305 }
306 assert(nut->frame_code['N'].flags == FLAG_INVALID);
307
a559d65c
AL
308 if (end > avio_tell(bc) + 4) {
309 int rem = 1024;
72d30b27 310 GET_V(nut->header_count, tmp < 128U);
3b4f69ae 311 nut->header_count++;
a559d65c 312 for (i = 1; i < nut->header_count; i++) {
9d72c052 313 uint8_t *hdr;
a559d65c 314 GET_V(nut->header_len[i], tmp > 0 && tmp < 256);
62f72b40
LB
315 if (rem < nut->header_len[i]) {
316 av_log(s, AV_LOG_ERROR,
317 "invalid elision header %d : %d > %d\n",
318 i, nut->header_len[i], rem);
0d3ee135 319 return AVERROR_INVALIDDATA;
3b4f69ae 320 }
62f72b40 321 rem -= nut->header_len[i];
9d72c052
MR
322 hdr = av_malloc(nut->header_len[i]);
323 if (!hdr)
324 return AVERROR(ENOMEM);
325 avio_read(bc, hdr, nut->header_len[i]);
326 nut->header[i] = hdr;
3b4f69ae 327 }
a559d65c 328 assert(nut->header_len[0] == 0);
3b4f69ae
MN
329 }
330
c94e2e85
LB
331 // flags had been effectively introduced in version 4
332 if (nut->version > NUT_STABLE_VERSION) {
333 nut->flags = ffio_read_varlen(bc);
334 }
335
a559d65c 336 if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
93951943 337 av_log(s, AV_LOG_ERROR, "main header checksum mismatch\n");
0d3ee135 338 return AVERROR_INVALIDDATA;
619d8e2e
MN
339 }
340
a559d65c 341 nut->stream = av_mallocz(sizeof(StreamContext) * stream_count);
3035d21b
HBL
342 if (!nut->stream)
343 return AVERROR(ENOMEM);
a559d65c 344 for (i = 0; i < stream_count; i++)
84ad31ff 345 avformat_new_stream(s, NULL);
619d8e2e
MN
346
347 return 0;
348}
349
a559d65c
AL
350static int decode_stream_header(NUTContext *nut)
351{
352 AVFormatContext *s = nut->avf;
353 AVIOContext *bc = s->pb;
619d8e2e 354 StreamContext *stc;
c873bc17 355 int class, stream_id;
619d8e2e
MN
356 uint64_t tmp, end;
357 AVStream *st;
358
a559d65c 359 end = get_packetheader(nut, bc, 1, STREAM_STARTCODE);
a2704c97 360 end += avio_tell(bc);
619d8e2e 361
efd8f22a 362 GET_V(stream_id, tmp < s->nb_streams && !nut->stream[tmp].time_base);
a559d65c
AL
363 stc = &nut->stream[stream_id];
364 st = s->streams[stream_id];
619d8e2e 365 if (!st)
769e10f0 366 return AVERROR(ENOMEM);
619d8e2e 367
a559d65c
AL
368 class = ffio_read_varlen(bc);
369 tmp = get_fourcc(bc);
370 st->codec->codec_tag = tmp;
371 switch (class) {
372 case 0:
373 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
374 st->codec->codec_id = av_codec_get_id((const AVCodecTag * const []) {
a559d65c 375 ff_nut_video_tags,
1bd442c2 376 ff_codec_bmp_tags,
a559d65c
AL
377 0
378 },
379 tmp);
380 break;
381 case 1:
382 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
92281850
LB
383 st->codec->codec_id = av_codec_get_id((const AVCodecTag * const []) {
384 ff_nut_audio_tags,
385 ff_codec_wav_tags,
386 0
387 },
388 tmp);
a559d65c
AL
389 break;
390 case 2:
391 st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
392 st->codec->codec_id = ff_codec_get_id(ff_nut_subtitle_tags, tmp);
393 break;
394 case 3:
395 st->codec->codec_type = AVMEDIA_TYPE_DATA;
d4bff9f1 396 st->codec->codec_id = ff_codec_get_id(ff_nut_data_tags, tmp);
a559d65c
AL
397 break;
398 default:
399 av_log(s, AV_LOG_ERROR, "unknown stream class (%d)\n", class);
e0c53c34 400 return AVERROR(ENOSYS);
619d8e2e 401 }
36ef5369 402 if (class < 3 && st->codec->codec_id == AV_CODEC_ID_NONE)
a559d65c
AL
403 av_log(s, AV_LOG_ERROR,
404 "Unknown codec tag '0x%04x' for stream number %d\n",
405 (unsigned int) tmp, stream_id);
406
407 GET_V(stc->time_base_id, tmp < nut->time_base_count);
408 GET_V(stc->msb_pts_shift, tmp < 16);
409 stc->max_pts_distance = ffio_read_varlen(bc);
410 GET_V(stc->decode_delay, tmp < 1000); // sanity limit, raise this if Moore's law is true
a559d65c
AL
411 ffio_read_varlen(bc); // stream flags
412
413 GET_V(st->codec->extradata_size, tmp < (1 << 30));
414 if (st->codec->extradata_size) {
415 st->codec->extradata = av_mallocz(st->codec->extradata_size +
059a9348 416 AV_INPUT_BUFFER_PADDING_SIZE);
3035d21b
HBL
417 if (!st->codec->extradata)
418 return AVERROR(ENOMEM);
b7effd4e 419 avio_read(bc, st->codec->extradata, st->codec->extradata_size);
619d8e2e
MN
420 }
421
a559d65c 422 if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
72d30b27
LB
423 GET_V(st->codec->width, tmp > 0);
424 GET_V(st->codec->height, tmp > 0);
a559d65c
AL
425 st->sample_aspect_ratio.num = ffio_read_varlen(bc);
426 st->sample_aspect_ratio.den = ffio_read_varlen(bc);
427 if ((!st->sample_aspect_ratio.num) != (!st->sample_aspect_ratio.den)) {
428 av_log(s, AV_LOG_ERROR, "invalid aspect ratio %d/%d\n",
429 st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
e0c53c34 430 return AVERROR_INVALIDDATA;
619d8e2e 431 }
4839c192 432 ffio_read_varlen(bc); /* csp type */
a559d65c 433 } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
72d30b27 434 GET_V(st->codec->sample_rate, tmp > 0);
4839c192 435 ffio_read_varlen(bc); // samplerate_den
72d30b27 436 GET_V(st->codec->channels, tmp > 0);
619d8e2e 437 }
a559d65c
AL
438 if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
439 av_log(s, AV_LOG_ERROR,
440 "stream header %d checksum mismatch\n", stream_id);
e0c53c34 441 return AVERROR_INVALIDDATA;
619d8e2e 442 }
a559d65c
AL
443 stc->time_base = &nut->time_base[stc->time_base_id];
444 avpriv_set_pts_info(s->streams[stream_id], 63, stc->time_base->num,
445 stc->time_base->den);
619d8e2e
MN
446 return 0;
447}
448
a559d65c
AL
449static void set_disposition_bits(AVFormatContext *avf, char *value,
450 int stream_id)
451{
90c2295b 452 int flag = 0, i;
a559d65c
AL
453
454 for (i = 0; ff_nut_dispositions[i].flag; ++i)
90c2295b
ES
455 if (!strcmp(ff_nut_dispositions[i].str, value))
456 flag = ff_nut_dispositions[i].flag;
90c2295b
ES
457 if (!flag)
458 av_log(avf, AV_LOG_INFO, "unknown disposition type '%s'\n", value);
459 for (i = 0; i < avf->nb_streams; ++i)
460 if (stream_id == i || stream_id == -1)
461 avf->streams[i]->disposition |= flag;
462}
463
a559d65c
AL
464static int decode_info_header(NUTContext *nut)
465{
466 AVFormatContext *s = nut->avf;
467 AVIOContext *bc = s->pb;
e1c0b00b
AK
468 uint64_t tmp, chapter_start, chapter_len;
469 unsigned int stream_id_plus1, count;
619d8e2e
MN
470 int chapter_id, i;
471 int64_t value, end;
7ebab679 472 char name[256], str_value[1024], type_str[256];
0fca8bc8 473 const char *type;
96bfb677 474 int *event_flags = NULL;
a559d65c
AL
475 AVChapter *chapter = NULL;
476 AVStream *st = NULL;
d2d67e42 477 AVDictionary **metadata = NULL;
fa3a5dd4 478 int metadata_flag = 0;
619d8e2e 479
a559d65c 480 end = get_packetheader(nut, bc, 1, INFO_STARTCODE);
a2704c97 481 end += avio_tell(bc);
619d8e2e 482
72d30b27 483 GET_V(stream_id_plus1, tmp <= s->nb_streams);
a559d65c
AL
484 chapter_id = get_s(bc);
485 chapter_start = ffio_read_varlen(bc);
486 chapter_len = ffio_read_varlen(bc);
487 count = ffio_read_varlen(bc);
488
489 if (chapter_id && !stream_id_plus1) {
490 int64_t start = chapter_start / nut->time_base_count;
491 chapter = avpriv_new_chapter(s, chapter_id,
492 nut->time_base[chapter_start %
493 nut->time_base_count],
494 start, start + chapter_len, NULL);
b34257ee
AC
495 if (!chapter) {
496 av_log(s, AV_LOG_ERROR, "Could not create chapter.\n");
497 return AVERROR(ENOMEM);
498 }
c55f891c 499 metadata = &chapter->metadata;
a559d65c
AL
500 } else if (stream_id_plus1) {
501 st = s->streams[stream_id_plus1 - 1];
c55f891c 502 metadata = &st->metadata;
fa3a5dd4
AS
503 event_flags = &st->event_flags;
504 metadata_flag = AVSTREAM_EVENT_FLAG_METADATA_UPDATED;
505 } else {
c55f891c 506 metadata = &s->metadata;
fa3a5dd4
AS
507 event_flags = &s->event_flags;
508 metadata_flag = AVFMT_EVENT_FLAG_METADATA_UPDATED;
509 }
883fe4d5 510
a559d65c 511 for (i = 0; i < count; i++) {
619d8e2e 512 get_str(bc, name, sizeof(name));
a559d65c
AL
513 value = get_s(bc);
514 if (value == -1) {
515 type = "UTF-8";
619d8e2e 516 get_str(bc, str_value, sizeof(str_value));
a559d65c 517 } else if (value == -2) {
0fca8bc8 518 get_str(bc, type_str, sizeof(type_str));
a559d65c 519 type = type_str;
619d8e2e 520 get_str(bc, str_value, sizeof(str_value));
a559d65c
AL
521 } else if (value == -3) {
522 type = "s";
523 value = get_s(bc);
524 } else if (value == -4) {
525 type = "t";
526 value = ffio_read_varlen(bc);
527 } else if (value < -4) {
528 type = "r";
619d8e2e 529 get_s(bc);
a559d65c
AL
530 } else {
531 type = "v";
619d8e2e
MN
532 }
533
d6f142a1 534 if (stream_id_plus1 > s->nb_streams) {
0e239529
LB
535 av_log(s, AV_LOG_WARNING,
536 "invalid stream id %d for info packet\n",
537 stream_id_plus1);
90c2295b
ES
538 continue;
539 }
540
a559d65c
AL
541 if (!strcmp(type, "UTF-8")) {
542 if (chapter_id == 0 && !strcmp(name, "Disposition")) {
90c2295b 543 set_disposition_bits(s, str_value, stream_id_plus1 - 1);
c55f891c
AK
544 continue;
545 }
a559d65c 546 if (metadata && av_strcasecmp(name, "Uses") &&
fa3a5dd4 547 av_strcasecmp(name, "Depends") && av_strcasecmp(name, "Replaces")) {
96bfb677
LB
548 if (event_flags)
549 *event_flags |= metadata_flag;
d2d67e42 550 av_dict_set(metadata, name, str_value, 0);
fa3a5dd4 551 }
883fe4d5 552 }
619d8e2e
MN
553 }
554
a559d65c 555 if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
93951943 556 av_log(s, AV_LOG_ERROR, "info header checksum mismatch\n");
e0c53c34 557 return AVERROR_INVALIDDATA;
619d8e2e
MN
558 }
559 return 0;
560}
561
a559d65c
AL
562static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
563{
564 AVFormatContext *s = nut->avf;
565 AVIOContext *bc = s->pb;
4d5be986 566 int64_t end, tmp;
b1fcdc08 567 int ret;
619d8e2e 568
a559d65c 569 nut->last_syncpoint_pos = avio_tell(bc) - 8;
619d8e2e 570
a559d65c 571 end = get_packetheader(nut, bc, 1, SYNCPOINT_STARTCODE);
a2704c97 572 end += avio_tell(bc);
619d8e2e 573
a559d65c
AL
574 tmp = ffio_read_varlen(bc);
575 *back_ptr = nut->last_syncpoint_pos - 16 * ffio_read_varlen(bc);
576 if (*back_ptr < 0)
4d5be986 577 return -1;
619d8e2e 578
a559d65c
AL
579 ff_nut_reset_ts(nut, nut->time_base[tmp % nut->time_base_count],
580 tmp / nut->time_base_count);
619d8e2e 581
c94e2e85
LB
582 if (nut->flags & NUT_BROADCAST) {
583 tmp = ffio_read_varlen(bc);
584 av_log(s, AV_LOG_VERBOSE, "Syncpoint wallclock %"PRId64"\n",
585 av_rescale_q(tmp / nut->time_base_count,
586 nut->time_base[tmp % nut->time_base_count],
587 AV_TIME_BASE_Q));
588 }
589
a559d65c 590 if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
faf7cbf1 591 av_log(s, AV_LOG_ERROR, "sync point checksum mismatch\n");
e0c53c34 592 return AVERROR_INVALIDDATA;
619d8e2e 593 }
4d5be986 594
a559d65c
AL
595 *ts = tmp / s->nb_streams *
596 av_q2d(nut->time_base[tmp % s->nb_streams]) * AV_TIME_BASE;
b1fcdc08
DB
597
598 if ((ret = ff_nut_add_sp(nut, nut->last_syncpoint_pos, *back_ptr, *ts)) < 0)
599 return ret;
4d5be986 600
619d8e2e
MN
601 return 0;
602}
603
a559d65c
AL
604static int find_and_decode_index(NUTContext *nut)
605{
606 AVFormatContext *s = nut->avf;
607 AVIOContext *bc = s->pb;
e8272029
MN
608 uint64_t tmp, end;
609 int i, j, syncpoint_count;
a559d65c 610 int64_t filesize = avio_size(bc);
e8272029
MN
611 int64_t *syncpoints;
612 int8_t *has_keyframe;
e0c53c34 613 int ret = AVERROR_INVALIDDATA;
e8272029 614
a559d65c
AL
615 avio_seek(bc, filesize - 12, SEEK_SET);
616 avio_seek(bc, filesize - avio_rb64(bc), SEEK_SET);
617 if (avio_rb64(bc) != INDEX_STARTCODE) {
0e239529 618 av_log(s, AV_LOG_WARNING, "no index at the end\n");
e0c53c34 619 return ret;
e8272029
MN
620 }
621
a559d65c 622 end = get_packetheader(nut, bc, 1, INDEX_STARTCODE);
a2704c97 623 end += avio_tell(bc);
e8272029 624
a559d65c 625 ffio_read_varlen(bc); // max_pts
72d30b27 626 GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
a559d65c
AL
627 syncpoints = av_malloc(sizeof(int64_t) * syncpoint_count);
628 has_keyframe = av_malloc(sizeof(int8_t) * (syncpoint_count + 1));
5a2645ca
VG
629 if (!syncpoints || !has_keyframe) {
630 ret = AVERROR(ENOMEM);
631 goto fail;
632 }
a559d65c 633 for (i = 0; i < syncpoint_count; i++) {
4839c192 634 syncpoints[i] = ffio_read_varlen(bc);
a559d65c 635 if (syncpoints[i] <= 0)
c2a3dcaf 636 goto fail;
a559d65c
AL
637 if (i)
638 syncpoints[i] += syncpoints[i - 1];
639 }
640
641 for (i = 0; i < s->nb_streams; i++) {
642 int64_t last_pts = -1;
643 for (j = 0; j < syncpoint_count;) {
644 uint64_t x = ffio_read_varlen(bc);
645 int type = x & 1;
646 int n = j;
647 x >>= 1;
648 if (type) {
649 int flag = x & 1;
650 x >>= 1;
651 if (n + x >= syncpoint_count + 1) {
e8272029 652 av_log(s, AV_LOG_ERROR, "index overflow A\n");
c2a3dcaf 653 goto fail;
e8272029 654 }
a559d65c
AL
655 while (x--)
656 has_keyframe[n++] = flag;
657 has_keyframe[n++] = !flag;
658 } else {
659 while (x != 1) {
660 if (n >= syncpoint_count + 1) {
e8272029 661 av_log(s, AV_LOG_ERROR, "index overflow B\n");
c2a3dcaf 662 goto fail;
e8272029 663 }
a559d65c
AL
664 has_keyframe[n++] = x & 1;
665 x >>= 1;
e8272029
MN
666 }
667 }
a559d65c 668 if (has_keyframe[0]) {
e8272029 669 av_log(s, AV_LOG_ERROR, "keyframe before first syncpoint in index\n");
c2a3dcaf 670 goto fail;
e8272029 671 }
a559d65c
AL
672 assert(n <= syncpoint_count + 1);
673 for (; j < n && j < syncpoint_count; j++) {
674 if (has_keyframe[j]) {
675 uint64_t B, A = ffio_read_varlen(bc);
676 if (!A) {
677 A = ffio_read_varlen(bc);
678 B = ffio_read_varlen(bc);
679 // eor_pts[j][i] = last_pts + A + B
680 } else
681 B = 0;
682 av_add_index_entry(s->streams[i], 16 * syncpoints[j - 1],
683 last_pts + A, 0, 0, AVINDEX_KEYFRAME);
e8272029
MN
684 last_pts += A + B;
685 }
686 }
687 }
688 }
689
a559d65c 690 if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
93951943 691 av_log(s, AV_LOG_ERROR, "index checksum mismatch\n");
c2a3dcaf 692 goto fail;
e8272029 693 }
a559d65c
AL
694 ret = 0;
695
c2a3dcaf
MN
696fail:
697 av_free(syncpoints);
698 av_free(has_keyframe);
699 return ret;
e8272029
MN
700}
701
254f3dab
LB
702static int nut_read_close(AVFormatContext *s)
703{
704 NUTContext *nut = s->priv_data;
705 int i;
706
707 av_freep(&nut->time_base);
708 av_freep(&nut->stream);
709 ff_nut_free_sp(nut);
710 for (i = 1; i < nut->header_count; i++)
711 av_freep(&nut->header[i]);
712
713 return 0;
714}
715
6e9651d1 716static int nut_read_header(AVFormatContext *s)
619d8e2e
MN
717{
718 NUTContext *nut = s->priv_data;
ae628ec1 719 AVIOContext *bc = s->pb;
619d8e2e 720 int64_t pos;
5e534865 721 int initialized_stream_count;
619d8e2e 722
a559d65c 723 nut->avf = s;
619d8e2e
MN
724
725 /* main header */
a559d65c
AL
726 pos = 0;
727 do {
728 pos = find_startcode(bc, MAIN_STARTCODE, pos) + 1;
729 if (pos < 0 + 1) {
93951943 730 av_log(s, AV_LOG_ERROR, "No main startcode found.\n");
254f3dab 731 goto fail;
619d8e2e 732 }
a559d65c 733 } while (decode_main_header(nut) < 0);
619d8e2e
MN
734
735 /* stream headers */
a559d65c
AL
736 pos = 0;
737 for (initialized_stream_count = 0; initialized_stream_count < s->nb_streams;) {
738 pos = find_startcode(bc, STREAM_STARTCODE, pos) + 1;
739 if (pos < 0 + 1) {
93951943 740 av_log(s, AV_LOG_ERROR, "Not all stream headers found.\n");
254f3dab 741 goto fail;
619d8e2e 742 }
a559d65c 743 if (decode_stream_header(nut) >= 0)
5e534865 744 initialized_stream_count++;
619d8e2e
MN
745 }
746
747 /* info headers */
a559d65c
AL
748 pos = 0;
749 for (;;) {
750 uint64_t startcode = find_any_startcode(bc, pos);
751 pos = avio_tell(bc);
619d8e2e 752
a559d65c 753 if (startcode == 0) {
619d8e2e 754 av_log(s, AV_LOG_ERROR, "EOF before video frames\n");
254f3dab 755 goto fail;
a559d65c
AL
756 } else if (startcode == SYNCPOINT_STARTCODE) {
757 nut->next_startcode = startcode;
619d8e2e 758 break;
a559d65c 759 } else if (startcode != INFO_STARTCODE) {
619d8e2e
MN
760 continue;
761 }
762
763 decode_info_header(nut);
764 }
765
9deaec78 766 s->internal->data_offset = pos - 8;
faf7cbf1 767
a559d65c
AL
768 if (bc->seekable) {
769 int64_t orig_pos = avio_tell(bc);
e8272029 770 find_and_decode_index(nut);
6b4aa5da 771 avio_seek(bc, orig_pos, SEEK_SET);
e8272029
MN
772 }
773 assert(nut->next_startcode == SYNCPOINT_STARTCODE);
774
03700d39
AK
775 ff_metadata_conv_ctx(s, NULL, ff_nut_metadata_conv);
776
619d8e2e 777 return 0;
254f3dab
LB
778
779fail:
780 nut_read_close(s);
781
782 return AVERROR_INVALIDDATA;
619d8e2e
MN
783}
784
a559d65c
AL
785static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id,
786 uint8_t *header_idx, int frame_code)
787{
788 AVFormatContext *s = nut->avf;
789 AVIOContext *bc = s->pb;
619d8e2e
MN
790 StreamContext *stc;
791 int size, flags, size_mul, pts_delta, i, reserved_count;
792 uint64_t tmp;
793
c94e2e85
LB
794 if (!(nut->flags & NUT_PIPE) &&
795 avio_tell(bc) > nut->last_syncpoint_pos + nut->max_distance) {
a559d65c
AL
796 av_log(s, AV_LOG_ERROR,
797 "Last frame must have been damaged %"PRId64" > %"PRId64" + %d\n",
798 avio_tell(bc), nut->last_syncpoint_pos, nut->max_distance);
0d3ee135 799 return AVERROR_INVALIDDATA;
619d8e2e
MN
800 }
801
802 flags = nut->frame_code[frame_code].flags;
803 size_mul = nut->frame_code[frame_code].size_mul;
804 size = nut->frame_code[frame_code].size_lsb;
805 *stream_id = nut->frame_code[frame_code].stream_id;
806 pts_delta = nut->frame_code[frame_code].pts_delta;
807 reserved_count = nut->frame_code[frame_code].reserved_count;
3b4f69ae 808 *header_idx = nut->frame_code[frame_code].header_idx;
619d8e2e 809
a559d65c 810 if (flags & FLAG_INVALID)
0d3ee135 811 return AVERROR_INVALIDDATA;
a559d65c 812 if (flags & FLAG_CODED)
4839c192 813 flags ^= ffio_read_varlen(bc);
a559d65c 814 if (flags & FLAG_STREAM_ID) {
72d30b27 815 GET_V(*stream_id, tmp < s->nb_streams);
619d8e2e 816 }
a559d65c
AL
817 stc = &nut->stream[*stream_id];
818 if (flags & FLAG_CODED_PTS) {
819 int coded_pts = ffio_read_varlen(bc);
820 // FIXME check last_pts validity?
821 if (coded_pts < (1 << stc->msb_pts_shift)) {
822 *pts = ff_lsb2full(stc, coded_pts);
823 } else
824 *pts = coded_pts - (1 << stc->msb_pts_shift);
825 } else
826 *pts = stc->last_pts + pts_delta;
827 if (flags & FLAG_SIZE_MSB)
828 size += size_mul * ffio_read_varlen(bc);
829 if (flags & FLAG_MATCH_TIME)
7eeebcc5 830 get_s(bc);
a559d65c
AL
831 if (flags & FLAG_HEADER_IDX)
832 *header_idx = ffio_read_varlen(bc);
833 if (flags & FLAG_RESERVED)
834 reserved_count = ffio_read_varlen(bc);
835 for (i = 0; i < reserved_count; i++)
4839c192 836 ffio_read_varlen(bc);
3b4f69ae 837
a559d65c 838 if (*header_idx >= (unsigned)nut->header_count) {
3b4f69ae 839 av_log(s, AV_LOG_ERROR, "header_idx invalid\n");
0d3ee135 840 return AVERROR_INVALIDDATA;
3b4f69ae 841 }
a559d65c
AL
842 if (size > 4096)
843 *header_idx = 0;
3b4f69ae
MN
844 size -= nut->header_len[*header_idx];
845
a559d65c
AL
846 if (flags & FLAG_CHECKSUM) {
847 avio_rb32(bc); // FIXME check this
c94e2e85
LB
848 } else if (!(nut->flags & NUT_PIPE) &&
849 size > 2 * nut->max_distance ||
850 FFABS(stc->last_pts - *pts) > stc->max_pts_distance) {
2dbe0bd4 851 av_log(s, AV_LOG_ERROR, "frame size > 2max_distance and no checksum\n");
0d3ee135 852 return AVERROR_INVALIDDATA;
619d8e2e 853 }
619d8e2e 854
a559d65c
AL
855 stc->last_pts = *pts;
856 stc->last_flags = flags;
619d8e2e
MN
857
858 return size;
859}
860
a559d65c
AL
861static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code)
862{
863 AVFormatContext *s = nut->avf;
864 AVIOContext *bc = s->pb;
af7ca6ea 865 int size, stream_id, discard, ret;
619d8e2e 866 int64_t pts, last_IP_pts;
06599638 867 StreamContext *stc;
3b4f69ae 868 uint8_t header_idx;
619d8e2e 869
a559d65c
AL
870 size = decode_frame_header(nut, &pts, &stream_id, &header_idx, frame_code);
871 if (size < 0)
0d3ee135 872 return size;
619d8e2e 873
a559d65c 874 stc = &nut->stream[stream_id];
06599638
MN
875
876 if (stc->last_flags & FLAG_KEY)
a559d65c
AL
877 stc->skip_until_key_frame = 0;
878
879 discard = s->streams[stream_id]->discard;
880 last_IP_pts = s->streams[stream_id]->last_IP_pts;
881 if ((discard >= AVDISCARD_NONKEY && !(stc->last_flags & FLAG_KEY)) ||
882 (discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE &&
883 last_IP_pts > pts) ||
884 discard >= AVDISCARD_ALL ||
885 stc->skip_until_key_frame) {
45a8a02a 886 avio_skip(bc, size);
619d8e2e
MN
887 return 1;
888 }
889
af7ca6ea
VG
890 ret = av_new_packet(pkt, size + nut->header_len[header_idx]);
891 if (ret < 0)
892 return ret;
3b4f69ae 893 memcpy(pkt->data, nut->header[header_idx], nut->header_len[header_idx]);
a559d65c 894 pkt->pos = avio_tell(bc); // FIXME
b7effd4e 895 avio_read(bc, pkt->data + nut->header_len[header_idx], size);
3b4f69ae 896
619d8e2e 897 pkt->stream_index = stream_id;
06599638 898 if (stc->last_flags & FLAG_KEY)
cc947f04 899 pkt->flags |= AV_PKT_FLAG_KEY;
619d8e2e
MN
900 pkt->pts = pts;
901
902 return 0;
903}
904
905static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
906{
907 NUTContext *nut = s->priv_data;
ae628ec1 908 AVIOContext *bc = s->pb;
a559d65c 909 int i, frame_code = 0, ret, skip;
4d5be986 910 int64_t ts, back_ptr;
619d8e2e 911
a559d65c
AL
912 for (;;) {
913 int64_t pos = avio_tell(bc);
914 uint64_t tmp = nut->next_startcode;
915 nut->next_startcode = 0;
619d8e2e 916
a559d65c
AL
917 if (tmp) {
918 pos -= 8;
919 } else {
b7effd4e 920 frame_code = avio_r8(bc);
a559d65c 921 if (bc->eof_reached)
e0c53c34 922 return AVERROR_EOF;
a559d65c
AL
923 if (frame_code == 'N') {
924 tmp = frame_code;
925 for (i = 1; i < 8; i++)
926 tmp = (tmp << 8) + avio_r8(bc);
619d8e2e
MN
927 }
928 }
a559d65c 929 switch (tmp) {
619d8e2e
MN
930 case MAIN_STARTCODE:
931 case STREAM_STARTCODE:
932 case INDEX_STARTCODE:
a559d65c 933 skip = get_packetheader(nut, bc, 0, tmp);
45a8a02a 934 avio_skip(bc, skip);
619d8e2e
MN
935 break;
936 case INFO_STARTCODE:
a559d65c 937 if (decode_info_header(nut) < 0)
619d8e2e
MN
938 goto resync;
939 break;
940 case SYNCPOINT_STARTCODE:
a559d65c 941 if (decode_syncpoint(nut, &ts, &back_ptr) < 0)
619d8e2e 942 goto resync;
b7effd4e 943 frame_code = avio_r8(bc);
619d8e2e 944 case 0:
a559d65c
AL
945 ret = decode_frame(nut, pkt, frame_code);
946 if (ret == 0)
619d8e2e 947 return 0;
a559d65c 948 else if (ret == 1) // OK but discard packet
619d8e2e
MN
949 break;
950 default:
951resync:
a559d65c
AL
952 av_log(s, AV_LOG_DEBUG, "syncing from %"PRId64"\n", pos);
953 tmp = find_any_startcode(bc, nut->last_syncpoint_pos + 1);
954 if (tmp == 0)
0d3ee135 955 return AVERROR_INVALIDDATA;
a559d65c
AL
956 av_log(s, AV_LOG_DEBUG, "sync\n");
957 nut->next_startcode = tmp;
619d8e2e
MN
958 }
959 }
960}
961
a559d65c
AL
962static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index,
963 int64_t *pos_arg, int64_t pos_limit)
964{
faf7cbf1 965 NUTContext *nut = s->priv_data;
ae628ec1 966 AVIOContext *bc = s->pb;
4d5be986 967 int64_t pos, pts, back_ptr;
a559d65c
AL
968 av_log(s, AV_LOG_DEBUG, "read_timestamp(X,%d,%"PRId64",%"PRId64")\n",
969 stream_index, *pos_arg, pos_limit);
faf7cbf1 970
a559d65c
AL
971 pos = *pos_arg;
972 do {
973 pos = find_startcode(bc, SYNCPOINT_STARTCODE, pos) + 1;
974 if (pos < 1) {
faf7cbf1 975 assert(nut->next_startcode == 0);
93951943 976 av_log(s, AV_LOG_ERROR, "read_timestamp failed.\n");
faf7cbf1
MN
977 return AV_NOPTS_VALUE;
978 }
a559d65c
AL
979 } while (decode_syncpoint(nut, &pts, &back_ptr) < 0);
980 *pos_arg = pos - 1;
faf7cbf1
MN
981 assert(nut->last_syncpoint_pos == *pos_arg);
982
a559d65c
AL
983 av_log(s, AV_LOG_DEBUG, "return %"PRId64" %"PRId64"\n", pts, back_ptr);
984 if (stream_index == -1)
985 return pts;
986 else if (stream_index == -2)
987 return back_ptr;
4d5be986 988
d8c772de 989 return AV_NOPTS_VALUE;
faf7cbf1
MN
990}
991
a559d65c
AL
992static int read_seek(AVFormatContext *s, int stream_index,
993 int64_t pts, int flags)
994{
995 NUTContext *nut = s->priv_data;
996 AVStream *st = s->streams[stream_index];
997 Syncpoint dummy = { .ts = pts * av_q2d(st->time_base) * AV_TIME_BASE };
998 Syncpoint nopts_sp = { .ts = AV_NOPTS_VALUE, .back_ptr = AV_NOPTS_VALUE };
999 Syncpoint *sp, *next_node[2] = { &nopts_sp, &nopts_sp };
4d5be986 1000 int64_t pos, pos2, ts;
0a3b575b 1001 int i;
4d5be986 1002
c94e2e85
LB
1003 if (nut->flags & NUT_PIPE) {
1004 return AVERROR(ENOSYS);
1005 }
1006
a559d65c
AL
1007 if (st->index_entries) {
1008 int index = av_index_search_timestamp(st, pts, flags);
1009 if (index < 0)
071790c8
MN
1010 return -1;
1011
a559d65c
AL
1012 pos2 = st->index_entries[index].pos;
1013 ts = st->index_entries[index].timestamp;
1014 } else {
f990f6e3
VS
1015 av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pts_cmp,
1016 (void **) next_node);
a559d65c
AL
1017 av_log(s, AV_LOG_DEBUG, "%"PRIu64"-%"PRIu64" %"PRId64"-%"PRId64"\n",
1018 next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
1019 next_node[1]->ts);
1020 pos = ff_gen_search(s, -1, dummy.ts, next_node[0]->pos,
1021 next_node[1]->pos, next_node[1]->pos,
1022 next_node[0]->ts, next_node[1]->ts,
1023 AVSEEK_FLAG_BACKWARD, &ts, nut_read_timestamp);
1024
1025 if (!(flags & AVSEEK_FLAG_BACKWARD)) {
1026 dummy.pos = pos + 16;
1027 next_node[1] = &nopts_sp;
f990f6e3
VS
1028 av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp,
1029 (void **) next_node);
a559d65c
AL
1030 pos2 = ff_gen_search(s, -2, dummy.pos, next_node[0]->pos,
1031 next_node[1]->pos, next_node[1]->pos,
1032 next_node[0]->back_ptr, next_node[1]->back_ptr,
1033 flags, &ts, nut_read_timestamp);
1034 if (pos2 >= 0)
1035 pos = pos2;
1036 // FIXME dir but I think it does not matter
f32554fa 1037 }
a559d65c
AL
1038 dummy.pos = pos;
1039 sp = av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp,
1040 NULL);
f32554fa
MN
1041
1042 assert(sp);
a559d65c 1043 pos2 = sp->back_ptr - 15;
071790c8
MN
1044 }
1045 av_log(NULL, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos2);
a559d65c 1046 pos = find_startcode(s->pb, SYNCPOINT_STARTCODE, pos2);
6b4aa5da 1047 avio_seek(s->pb, pos, SEEK_SET);
4d5be986 1048 av_log(NULL, AV_LOG_DEBUG, "SP: %"PRId64"\n", pos);
a559d65c 1049 if (pos2 > pos || pos2 + 15 < pos)
4d5be986 1050 av_log(NULL, AV_LOG_ERROR, "no syncpoint at backptr pos\n");
a559d65c
AL
1051 for (i = 0; i < s->nb_streams; i++)
1052 nut->stream[i].skip_until_key_frame = 1;
0a3b575b 1053
4d5be986
MN
1054 return 0;
1055}
1056
c6610a21 1057AVInputFormat ff_nut_demuxer = {
dfc2c4d9 1058 .name = "nut",
6774247a 1059 .long_name = NULL_IF_CONFIG_SMALL("NUT"),
dfc2c4d9
AK
1060 .priv_data_size = sizeof(NUTContext),
1061 .read_probe = nut_probe,
1062 .read_header = nut_read_header,
1063 .read_packet = nut_read_packet,
1064 .read_close = nut_read_close,
1065 .read_seek = read_seek,
20234a4b 1066 .extensions = "nut",
1bd442c2 1067 .codec_tag = ff_nut_codec_tags,
619d8e2e 1068};