FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/nutdec.c
Date: 2026-05-02 21:46:34
Exec Total Coverage
Lines: 537 850 63.2%
Functions: 21 23 91.3%
Branches: 309 574 53.8%

Line Branch Exec Source
1 /*
2 * "NUT" Container Format demuxer
3 * Copyright (c) 2004-2006 Michael Niedermayer
4 * Copyright (c) 2003 Alex Beregszaszi
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
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 *
13 * FFmpeg is distributed in the hope that it will be useful,
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
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "libavutil/attributes.h"
24 #include "libavutil/avstring.h"
25 #include "libavutil/avassert.h"
26 #include "libavutil/bswap.h"
27 #include "libavutil/dict.h"
28 #include "libavutil/intreadwrite.h"
29 #include "libavutil/mathematics.h"
30 #include "libavutil/mem.h"
31 #include "libavutil/tree.h"
32 #include "libavcodec/bytestream.h"
33 #include "avio_internal.h"
34 #include "demux.h"
35 #include "isom.h"
36 #include "nut.h"
37 #include "riff.h"
38
39 #define NUT_MAX_STREAMS 256 /* arbitrary sanity check value */
40
41 static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index,
42 int64_t *pos_arg, int64_t pos_limit);
43
44 300 static int get_str(AVIOContext *bc, char *string, unsigned int maxlen)
45 {
46 300 unsigned int len = ffio_read_varlen(bc);
47
48
2/4
✓ Branch 0 taken 300 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 300 times.
✗ Branch 3 not taken.
300 if (len && maxlen)
49 300 avio_read(bc, string, FFMIN(len, maxlen));
50
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 300 times.
300 while (len > maxlen) {
51 avio_r8(bc);
52 len--;
53 if (bc->eof_reached)
54 len = maxlen;
55 }
56
57
1/2
✓ Branch 0 taken 300 times.
✗ Branch 1 not taken.
300 if (maxlen)
58 300 string[FFMIN(len, maxlen - 1)] = 0;
59
60
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 300 times.
300 if (bc->eof_reached)
61 return AVERROR_EOF;
62
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 300 times.
300 if (maxlen == len)
63 return -1;
64 else
65 300 return 0;
66 }
67
68 503 static int64_t get_s(AVIOContext *bc)
69 {
70 503 int64_t v = ffio_read_varlen(bc) + 1;
71
72
2/2
✓ Branch 0 taken 367 times.
✓ Branch 1 taken 136 times.
503 if (v & 1)
73 367 return -(v >> 1);
74 else
75 136 return (v >> 1);
76 }
77
78 50 static uint64_t get_fourcc(AVIOContext *bc)
79 {
80 50 unsigned int len = ffio_read_varlen(bc);
81
82
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if (len == 2)
83 return avio_rl16(bc);
84
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 else if (len == 4)
85 50 return avio_rl32(bc);
86 else {
87 av_log(NULL, AV_LOG_ERROR, "Unsupported fourcc length %d\n", len);
88 return -1;
89 }
90 }
91
92 1089 static int get_packetheader(NUTContext *nut, AVIOContext *bc,
93 int calculate_checksum, uint64_t startcode)
94 {
95 int64_t size;
96
97 1089 startcode = av_be2ne64(startcode);
98 1089 startcode = ff_crc04C11DB7_update(0, (uint8_t*) &startcode, 8);
99
100 1089 ffio_init_checksum(bc, ff_crc04C11DB7_update, startcode);
101 1089 size = ffio_read_varlen(bc);
102
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1089 times.
1089 if (size > 4096)
103 avio_rb32(bc);
104
2/4
✓ Branch 1 taken 1089 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1089 times.
1089 if (ffio_get_checksum(bc) && size > 4096)
105 return -1;
106
107
2/2
✓ Branch 0 taken 1060 times.
✓ Branch 1 taken 29 times.
1089 ffio_init_checksum(bc, calculate_checksum ? ff_crc04C11DB7_update : NULL, 0);
108
109 1089 return size;
110 }
111
112 326 static uint64_t find_any_startcode(AVIOContext *bc, int64_t pos)
113 {
114 326 uint64_t state = 0;
115
116
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 30 times.
326 if (pos >= 0)
117 /* Note, this may fail if the stream is not seekable, but that should
118 * not matter, as in this case we simply start where we currently are */
119 296 avio_seek(bc, pos, SEEK_SET);
120
1/2
✓ Branch 1 taken 17652 times.
✗ Branch 2 not taken.
17652 while (!avio_feof(bc)) {
121 17652 state = (state << 8) | avio_r8(bc);
122
2/2
✓ Branch 0 taken 17295 times.
✓ Branch 1 taken 357 times.
17652 if ((state >> 56) != 'N')
123 17295 continue;
124
2/2
✓ Branch 0 taken 326 times.
✓ Branch 1 taken 31 times.
357 switch (state) {
125 326 case MAIN_STARTCODE:
126 case STREAM_STARTCODE:
127 case SYNCPOINT_STARTCODE:
128 case INFO_STARTCODE:
129 case INDEX_STARTCODE:
130 326 return state;
131 }
132 }
133
134 return 0;
135 }
136
137 /**
138 * Find the given startcode.
139 * @param code the startcode
140 * @param pos the start position of the search, or -1 if the current position
141 * @return the position of the startcode or -1 if not found
142 */
143 106 static int64_t find_startcode(AVIOContext *bc, uint64_t code, int64_t pos)
144 {
145 30 for (;;) {
146 136 uint64_t startcode = find_any_startcode(bc, pos);
147
2/2
✓ Branch 0 taken 106 times.
✓ Branch 1 taken 30 times.
136 if (startcode == code)
148 106 return avio_tell(bc) - 8;
149
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 else if (startcode == 0)
150 return -1;
151 30 pos = -1;
152 }
153 }
154
155 7480 static int nut_probe(const AVProbeData *p)
156 {
157 int i;
158
159
2/2
✓ Branch 0 taken 417484297 times.
✓ Branch 1 taken 7450 times.
417491747 for (i = 0; i < p->buf_size-8; i++) {
160
2/2
✓ Branch 0 taken 417484267 times.
✓ Branch 1 taken 30 times.
417484297 if (AV_RB32(p->buf+i) != MAIN_STARTCODE>>32)
161 417484267 continue;
162
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if (AV_RB32(p->buf+i+4) == (MAIN_STARTCODE & 0xFFFFFFFF))
163 30 return AVPROBE_SCORE_MAX;
164 }
165 7450 return 0;
166 }
167
168 #define GET_V(dst, check) \
169 do { \
170 tmp = ffio_read_varlen(bc); \
171 if (!(check)) { \
172 av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp); \
173 ret = AVERROR_INVALIDDATA; \
174 goto fail; \
175 } \
176 dst = tmp; \
177 } while (0)
178
179 1060 static int skip_reserved(AVIOContext *bc, int64_t pos)
180 {
181 1060 pos -= avio_tell(bc);
182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1060 times.
1060 if (pos < 0) {
183 avio_seek(bc, pos, SEEK_CUR);
184 return AVERROR_INVALIDDATA;
185 } else {
186
2/2
✓ Branch 0 taken 4480 times.
✓ Branch 1 taken 1060 times.
5540 while (pos--) {
187
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4480 times.
4480 if (bc->eof_reached)
188 return AVERROR_INVALIDDATA;
189 4480 avio_r8(bc);
190 }
191 1060 return 0;
192 }
193 }
194
195 30 static int decode_main_header(NUTContext *nut)
196 {
197 30 AVFormatContext *s = nut->avf;
198 30 AVIOContext *bc = s->pb;
199 uint64_t tmp, end, length;
200 unsigned int stream_count;
201 int i, j, count, ret;
202 int tmp_stream, tmp_mul, tmp_pts, tmp_size, tmp_res, tmp_head_idx;
203
204 30 length = get_packetheader(nut, bc, 1, MAIN_STARTCODE);
205
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (length == (uint64_t)-1)
206 return AVERROR_INVALIDDATA;
207 30 end = length + avio_tell(bc);
208
209 30 nut->version = ffio_read_varlen(bc);
210
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if (nut->version < NUT_MIN_VERSION ||
211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 nut->version > NUT_MAX_VERSION) {
212 av_log(s, AV_LOG_ERROR, "Version %d not supported.\n",
213 nut->version);
214 return AVERROR(ENOSYS);
215 }
216
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 28 times.
30 if (nut->version > 3)
217 2 nut->minor_version = ffio_read_varlen(bc);
218
219
2/4
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 30 times.
30 GET_V(stream_count, tmp > 0 && tmp <= NUT_MAX_STREAMS);
220
221 30 nut->max_distance = ffio_read_varlen(bc);
222
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (nut->max_distance > 65536) {
223 av_log(s, AV_LOG_DEBUG, "max_distance %d\n", nut->max_distance);
224 nut->max_distance = 65536;
225 }
226
227
3/6
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 30 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 30 times.
30 GET_V(nut->time_base_count, tmp > 0 && tmp < INT_MAX / sizeof(AVRational) && tmp < length/2);
228 30 nut->time_base = av_malloc_array(nut->time_base_count, sizeof(AVRational));
229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (!nut->time_base)
230 return AVERROR(ENOMEM);
231
232
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 30 times.
72 for (i = 0; i < nut->time_base_count; i++) {
233
2/4
✓ Branch 1 taken 42 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
42 GET_V(nut->time_base[i].num, tmp > 0 && tmp < (1ULL << 31));
234
2/4
✓ Branch 1 taken 42 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
42 GET_V(nut->time_base[i].den, tmp > 0 && tmp < (1ULL << 31));
235
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
42 if (av_gcd(nut->time_base[i].num, nut->time_base[i].den) != 1) {
236 av_log(s, AV_LOG_ERROR, "invalid time base %d/%d\n",
237 nut->time_base[i].num,
238 nut->time_base[i].den);
239 ret = AVERROR_INVALIDDATA;
240 goto fail;
241 }
242 }
243 30 tmp_pts = 0;
244 30 tmp_mul = 1;
245 30 tmp_stream = 0;
246 30 tmp_head_idx = 0;
247
2/2
✓ Branch 0 taken 321 times.
✓ Branch 1 taken 30 times.
351 for (i = 0; i < 256;) {
248 321 int tmp_flags = ffio_read_varlen(bc);
249 321 int tmp_fields = ffio_read_varlen(bc);
250
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 321 times.
321 if (tmp_fields < 0) {
251 av_log(s, AV_LOG_ERROR, "fields %d is invalid\n", tmp_fields);
252 ret = AVERROR_INVALIDDATA;
253 goto fail;
254 }
255
256
2/2
✓ Branch 0 taken 271 times.
✓ Branch 1 taken 50 times.
321 if (tmp_fields > 0)
257 271 tmp_pts = get_s(bc);
258
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 113 times.
321 if (tmp_fields > 1)
259 208 tmp_mul = ffio_read_varlen(bc);
260
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 195 times.
321 if (tmp_fields > 2)
261 126 tmp_stream = ffio_read_varlen(bc);
262
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 213 times.
321 if (tmp_fields > 3)
263 108 tmp_size = ffio_read_varlen(bc);
264 else
265 213 tmp_size = 0;
266
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 259 times.
321 if (tmp_fields > 4)
267 62 tmp_res = ffio_read_varlen(bc);
268 else
269 259 tmp_res = 0;
270
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 259 times.
321 if (tmp_fields > 5)
271 62 count = ffio_read_varlen(bc);
272 else
273 259 count = tmp_mul - (unsigned)tmp_size;
274
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 319 times.
321 if (tmp_fields > 6)
275 2 get_s(bc);
276
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 319 times.
321 if (tmp_fields > 7)
277 2 tmp_head_idx = ffio_read_varlen(bc);
278
279
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 321 times.
321 while (tmp_fields-- > 8) {
280 if (bc->eof_reached) {
281 av_log(s, AV_LOG_ERROR, "reached EOF while decoding main header\n");
282 ret = AVERROR_INVALIDDATA;
283 goto fail;
284 }
285 ffio_read_varlen(bc);
286 }
287
288
4/6
✓ Branch 0 taken 321 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 201 times.
✓ Branch 3 taken 120 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 321 times.
321 if (count <= 0 || count > 256 - (i <= 'N') - i) {
289 av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i);
290 ret = AVERROR_INVALIDDATA;
291 goto fail;
292 }
293
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 321 times.
321 if (tmp_stream >= stream_count) {
294 av_log(s, AV_LOG_ERROR, "illegal stream number %d >= %d\n",
295 tmp_stream, stream_count);
296 ret = AVERROR_INVALIDDATA;
297 goto fail;
298 }
299
2/4
✓ Branch 0 taken 321 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 321 times.
321 if (tmp_size < 0 || tmp_size > INT_MAX - count) {
300 av_log(s, AV_LOG_ERROR, "illegal size\n");
301 ret = AVERROR_INVALIDDATA;
302 goto fail;
303 }
304
305
2/2
✓ Branch 0 taken 7680 times.
✓ Branch 1 taken 321 times.
8001 for (j = 0; j < count; j++, i++) {
306
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 7650 times.
7680 if (i == 'N') {
307 30 nut->frame_code[i].flags = FLAG_INVALID;
308 30 j--;
309 30 continue;
310 }
311 7650 nut->frame_code[i].flags = tmp_flags;
312 7650 nut->frame_code[i].pts_delta = tmp_pts;
313 7650 nut->frame_code[i].stream_id = tmp_stream;
314 7650 nut->frame_code[i].size_mul = tmp_mul;
315 7650 nut->frame_code[i].size_lsb = tmp_size + j;
316 7650 nut->frame_code[i].reserved_count = tmp_res;
317 7650 nut->frame_code[i].header_idx = tmp_head_idx;
318 }
319 }
320
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 av_assert0(nut->frame_code['N'].flags == FLAG_INVALID);
321
322
1/2
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
30 if (end > avio_tell(bc) + 4) {
323 30 int rem = 1024;
324
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
30 GET_V(nut->header_count, tmp < 128U);
325 30 nut->header_count++;
326
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 30 times.
210 for (i = 1; i < nut->header_count; i++) {
327 uint8_t *hdr;
328
2/4
✓ Branch 1 taken 180 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 180 times.
180 GET_V(nut->header_len[i], tmp > 0 && tmp < 256);
329
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 180 times.
180 if (rem < nut->header_len[i]) {
330 av_log(s, AV_LOG_ERROR,
331 "invalid elision header %d : %d > %d\n",
332 i, nut->header_len[i], rem);
333 ret = AVERROR_INVALIDDATA;
334 goto fail;
335 }
336 180 rem -= nut->header_len[i];
337 180 hdr = av_malloc(nut->header_len[i]);
338
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 180 times.
180 if (!hdr) {
339 ret = AVERROR(ENOMEM);
340 goto fail;
341 }
342 180 avio_read(bc, hdr, nut->header_len[i]);
343 180 nut->header[i] = hdr;
344 }
345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 av_assert0(nut->header_len[0] == 0);
346 }
347
348 // flags had been effectively introduced in version 4
349
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 28 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
30 if (nut->version > 3 && end > avio_tell(bc) + 4) {
350 2 nut->flags = ffio_read_varlen(bc);
351 }
352
353
2/4
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 30 times.
30 if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
354 av_log(s, AV_LOG_ERROR, "main header checksum mismatch\n");
355 ret = AVERROR_INVALIDDATA;
356 goto fail;
357 }
358
359 30 nut->stream = av_calloc(stream_count, sizeof(StreamContext));
360
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (!nut->stream) {
361 ret = AVERROR(ENOMEM);
362 goto fail;
363 }
364
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 30 times.
80 for (i = 0; i < stream_count; i++) {
365
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 50 times.
50 if (!avformat_new_stream(s, NULL)) {
366 ret = AVERROR(ENOMEM);
367 goto fail;
368 }
369 }
370
371 30 return 0;
372 fail:
373 av_freep(&nut->time_base);
374 for (i = 1; i < nut->header_count; i++) {
375 av_freep(&nut->header[i]);
376 }
377 nut->header_count = 0;
378 return ret;
379 }
380
381 50 static int decode_stream_header(NUTContext *nut)
382 {
383 50 AVFormatContext *s = nut->avf;
384 50 AVIOContext *bc = s->pb;
385 StreamContext *stc;
386 int class, stream_id, ret;
387 uint64_t tmp, end;
388 50 AVStream *st = NULL;
389
390 50 end = get_packetheader(nut, bc, 1, STREAM_STARTCODE);
391 50 end += avio_tell(bc);
392
393
2/4
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 50 times.
50 GET_V(stream_id, tmp < s->nb_streams && !nut->stream[tmp].time_base);
394 50 stc = &nut->stream[stream_id];
395 50 st = s->streams[stream_id];
396
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if (!st)
397 return AVERROR(ENOMEM);
398
399 50 class = ffio_read_varlen(bc);
400 50 tmp = get_fourcc(bc);
401 50 st->codecpar->codec_tag = tmp;
402
2/5
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 23 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
50 switch (class) {
403 27 case 0:
404 27 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
405 27 st->codecpar->codec_id = av_codec_get_id((const AVCodecTag * const []) {
406 ff_nut_video_tags,
407 ff_codec_bmp_tags,
408 ff_codec_movvideo_tags,
409 0
410 },
411 tmp);
412 27 break;
413 23 case 1:
414 23 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
415 23 st->codecpar->codec_id = av_codec_get_id((const AVCodecTag * const []) {
416 ff_nut_audio_tags,
417 ff_codec_wav_tags,
418 ff_nut_audio_extra_tags,
419 0
420 },
421 tmp);
422 23 break;
423 case 2:
424 st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
425 st->codecpar->codec_id = ff_codec_get_id(ff_nut_subtitle_tags, tmp);
426 break;
427 case 3:
428 st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
429 st->codecpar->codec_id = ff_codec_get_id(ff_nut_data_tags, tmp);
430 break;
431 default:
432 av_log(s, AV_LOG_ERROR, "unknown stream class (%d)\n", class);
433 return AVERROR(ENOSYS);
434 }
435
2/4
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 50 times.
50 if (class < 3 && st->codecpar->codec_id == AV_CODEC_ID_NONE)
436 av_log(s, AV_LOG_ERROR,
437 "Unknown codec tag '0x%04x' for stream number %d\n",
438 (unsigned int) tmp, stream_id);
439
440
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 50 times.
50 GET_V(stc->time_base_id, tmp < nut->time_base_count);
441
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 50 times.
50 GET_V(stc->msb_pts_shift, tmp < 16);
442 50 stc->max_pts_distance = ffio_read_varlen(bc);
443
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 50 times.
50 GET_V(stc->decode_delay, tmp < 1000); // sanity limit, raise this if Moore's law is true
444 50 st->codecpar->video_delay = stc->decode_delay;
445 50 ffio_read_varlen(bc); // stream flags
446
447
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 50 times.
50 GET_V(st->codecpar->extradata_size, tmp < (1 << 30));
448
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 43 times.
50 if (st->codecpar->extradata_size) {
449 7 ret = ff_get_extradata(s, st->codecpar, bc,
450 7 st->codecpar->extradata_size);
451
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (ret < 0)
452 return ret;
453 }
454
455
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 23 times.
50 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
456
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
27 GET_V(st->codecpar->width, tmp > 0);
457
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
27 GET_V(st->codecpar->height, tmp > 0);
458 27 st->sample_aspect_ratio.num = ffio_read_varlen(bc);
459 27 st->sample_aspect_ratio.den = ffio_read_varlen(bc);
460
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if ((!st->sample_aspect_ratio.num) != (!st->sample_aspect_ratio.den)) {
461 av_log(s, AV_LOG_ERROR, "invalid aspect ratio %d/%d\n",
462 st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
463 ret = AVERROR_INVALIDDATA;
464 goto fail;
465 }
466 27 ffio_read_varlen(bc); /* csp type */
467
1/2
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
23 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
468
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
23 GET_V(st->codecpar->sample_rate, tmp > 0);
469 23 ffio_read_varlen(bc); // samplerate_den
470
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
23 GET_V(st->codecpar->ch_layout.nb_channels, tmp > 0);
471 }
472
2/4
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 50 times.
50 if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
473 av_log(s, AV_LOG_ERROR,
474 "stream header %d checksum mismatch\n", stream_id);
475 ret = AVERROR_INVALIDDATA;
476 goto fail;
477 }
478 50 stc->time_base = &nut->time_base[stc->time_base_id];
479 50 avpriv_set_pts_info(s->streams[stream_id], 63, stc->time_base->num,
480 50 stc->time_base->den);
481 50 return 0;
482 fail:
483 if (st && st->codecpar) {
484 av_freep(&st->codecpar->extradata);
485 st->codecpar->extradata_size = 0;
486 }
487 return ret;
488 }
489
490 10 static void set_disposition_bits(AVFormatContext *avf, char *value,
491 int stream_id)
492 {
493 10 int flag = 0, i;
494
495
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 10 times.
70 for (i = 0; ff_nut_dispositions[i].flag; ++i)
496
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 50 times.
60 if (!strcmp(ff_nut_dispositions[i].str, value))
497 10 flag = ff_nut_dispositions[i].flag;
498
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (!flag)
499 av_log(avf, AV_LOG_INFO, "unknown disposition type '%s'\n", value);
500
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 10 times.
36 for (i = 0; i < avf->nb_streams; ++i)
501
3/4
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
26 if (stream_id == i || stream_id == -1)
502 10 avf->streams[i]->disposition |= flag;
503 10 }
504
505 80 static int decode_info_header(NUTContext *nut)
506 {
507 80 AVFormatContext *s = nut->avf;
508 80 AVIOContext *bc = s->pb;
509 uint64_t tmp, chapter_start, chapter_len;
510 unsigned int stream_id_plus1, count;
511 80 int i, ret = 0;
512 int64_t chapter_id, value, end;
513 char name[256], str_value[1024], type_str[256];
514 const char *type;
515 80 int *event_flags = NULL;
516 80 AVChapter *chapter = NULL;
517 80 AVStream *st = NULL;
518 80 AVDictionary **metadata = NULL;
519 80 int metadata_flag = 0;
520
521 80 end = get_packetheader(nut, bc, 1, INFO_STARTCODE);
522 80 end += avio_tell(bc);
523
524
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
80 GET_V(stream_id_plus1, tmp <= s->nb_streams);
525 80 chapter_id = get_s(bc);
526 80 chapter_start = ffio_read_varlen(bc);
527 80 chapter_len = ffio_read_varlen(bc);
528 80 count = ffio_read_varlen(bc);
529
530
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
80 if (chapter_id && !stream_id_plus1) {
531 int64_t start = chapter_start / nut->time_base_count;
532 chapter = avpriv_new_chapter(s, chapter_id,
533 nut->time_base[chapter_start %
534 nut->time_base_count],
535 start, start + chapter_len, NULL);
536 if (!chapter) {
537 av_log(s, AV_LOG_ERROR, "Could not create chapter.\n");
538 return AVERROR(ENOMEM);
539 }
540 metadata = &chapter->metadata;
541
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 30 times.
80 } else if (stream_id_plus1) {
542 50 st = s->streams[stream_id_plus1 - 1];
543 50 metadata = &st->metadata;
544 50 event_flags = &st->event_flags;
545 50 metadata_flag = AVSTREAM_EVENT_FLAG_METADATA_UPDATED;
546 } else {
547 30 metadata = &s->metadata;
548 30 event_flags = &s->event_flags;
549 30 metadata_flag = AVFMT_EVENT_FLAG_METADATA_UPDATED;
550 }
551
552
2/2
✓ Branch 0 taken 149 times.
✓ Branch 1 taken 80 times.
229 for (i = 0; i < count; i++) {
553 149 ret = get_str(bc, name, sizeof(name));
554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149 times.
149 if (ret < 0) {
555 av_log(s, AV_LOG_ERROR, "get_str failed while decoding info header\n");
556 return ret;
557 }
558 149 value = get_s(bc);
559 149 str_value[0] = 0;
560
561
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 if (value == -1) {
562 149 type = "UTF-8";
563 149 ret = get_str(bc, str_value, sizeof(str_value));
564 } else if (value == -2) {
565 ret = get_str(bc, type_str, sizeof(type_str));
566 if (ret < 0) {
567 av_log(s, AV_LOG_ERROR, "get_str failed while decoding info header\n");
568 return ret;
569 }
570 type = type_str;
571 ret = get_str(bc, str_value, sizeof(str_value));
572 } else if (value == -3) {
573 type = "s";
574 value = get_s(bc);
575 } else if (value == -4) {
576 type = "t";
577 value = ffio_read_varlen(bc);
578 } else if (value < -4) {
579 type = "r";
580 get_s(bc);
581 } else {
582 type = "v";
583 }
584
585
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149 times.
149 if (ret < 0) {
586 av_log(s, AV_LOG_ERROR, "get_str failed while decoding info header\n");
587 return ret;
588 }
589
590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149 times.
149 if (stream_id_plus1 > s->nb_streams) {
591 av_log(s, AV_LOG_WARNING,
592 "invalid stream id %d for info packet\n",
593 stream_id_plus1);
594 continue;
595 }
596
597
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 if (!strcmp(type, "UTF-8")) {
598
3/4
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 139 times.
149 if (chapter_id == 0 && !strcmp(name, "Disposition")) {
599 10 set_disposition_bits(s, str_value, stream_id_plus1 - 1);
600 10 continue;
601 }
602
603
4/4
✓ Branch 0 taken 107 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 27 times.
✓ Branch 3 taken 80 times.
139 if (stream_id_plus1 && !strcmp(name, "r_frame_rate")) {
604 27 sscanf(str_value, "%d/%d", &st->r_frame_rate.num, &st->r_frame_rate.den);
605
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 1 times.
27 if (st->r_frame_rate.num >= 1000LL*st->r_frame_rate.den ||
606
2/4
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 26 times.
26 st->r_frame_rate.num < 0 || st->r_frame_rate.den < 0)
607 1 st->r_frame_rate.num = st->r_frame_rate.den = 0;
608 27 continue;
609 }
610
611
3/6
✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 112 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 112 times.
✗ Branch 6 not taken.
224 if (metadata && av_strcasecmp(name, "Uses") &&
612
1/2
✓ Branch 2 taken 112 times.
✗ Branch 3 not taken.
224 av_strcasecmp(name, "Depends") && av_strcasecmp(name, "Replaces")) {
613
1/2
✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
112 if (event_flags)
614 112 *event_flags |= metadata_flag;
615 112 av_dict_set(metadata, name, str_value, 0);
616 }
617 }
618 }
619
620
2/4
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 80 times.
80 if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
621 av_log(s, AV_LOG_ERROR, "info header checksum mismatch\n");
622 return AVERROR_INVALIDDATA;
623 }
624 80 fail:
625 80 return FFMIN(ret, 0);
626 }
627
628 870 static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
629 {
630 870 AVFormatContext *s = nut->avf;
631 870 AVIOContext *bc = s->pb;
632 int64_t end;
633 uint64_t tmp;
634 int ret;
635
636 870 nut->last_syncpoint_pos = avio_tell(bc) - 8;
637
638 870 end = get_packetheader(nut, bc, 1, SYNCPOINT_STARTCODE);
639 870 end += avio_tell(bc);
640
641 870 tmp = ffio_read_varlen(bc);
642 870 *back_ptr = nut->last_syncpoint_pos - 16 * ffio_read_varlen(bc);
643
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 870 times.
870 if (*back_ptr < 0)
644 return AVERROR_INVALIDDATA;
645
646 870 ff_nut_reset_ts(nut, nut->time_base[tmp % nut->time_base_count],
647 870 tmp / nut->time_base_count);
648
649
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 870 times.
870 if (nut->flags & NUT_BROADCAST) {
650 tmp = ffio_read_varlen(bc);
651 av_log(s, AV_LOG_VERBOSE, "Syncpoint wallclock %"PRId64"\n",
652 av_rescale_q(tmp / nut->time_base_count,
653 nut->time_base[tmp % nut->time_base_count],
654 AV_TIME_BASE_Q));
655 }
656
657
2/4
✓ Branch 1 taken 870 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 870 times.
870 if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
658 av_log(s, AV_LOG_ERROR, "sync point checksum mismatch\n");
659 return AVERROR_INVALIDDATA;
660 }
661
662 1740 *ts = tmp / nut->time_base_count *
663 870 av_q2d(nut->time_base[tmp % nut->time_base_count]) * AV_TIME_BASE;
664
665
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 870 times.
870 if ((ret = ff_nut_add_sp(nut, nut->last_syncpoint_pos, *back_ptr, *ts)) < 0)
666 return ret;
667
668 870 return 0;
669 }
670
671 //FIXME calculate exactly, this is just a good approximation.
672 static int64_t find_duration(NUTContext *nut, int64_t filesize)
673 {
674 AVFormatContext *s = nut->avf;
675 int64_t duration = 0;
676
677 ff_find_last_ts(s, -1, &duration, NULL, nut_read_timestamp);
678
679 if(duration > 0)
680 s->duration_estimation_method = AVFMT_DURATION_FROM_PTS;
681 return duration;
682 }
683
684 30 static int find_and_decode_index(NUTContext *nut)
685 {
686 30 AVFormatContext *s = nut->avf;
687 30 AVIOContext *bc = s->pb;
688 uint64_t tmp, end;
689 int i, j, syncpoint_count;
690 30 int64_t filesize = avio_size(bc);
691 30 int64_t *syncpoints = NULL;
692 uint64_t max_pts;
693 30 int8_t *has_keyframe = NULL;
694 30 int ret = AVERROR_INVALIDDATA;
695
696
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if(filesize <= 0)
697 return -1;
698
699 30 avio_seek(bc, filesize - 12, SEEK_SET);
700 30 avio_seek(bc, filesize - avio_rb64(bc), SEEK_SET);
701
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
30 if (avio_rb64(bc) != INDEX_STARTCODE) {
702 av_log(s, AV_LOG_WARNING, "no index at the end\n");
703
704 if(s->duration<=0)
705 s->duration = find_duration(nut, filesize);
706 return ret;
707 }
708
709 30 end = get_packetheader(nut, bc, 1, INDEX_STARTCODE);
710 30 end += avio_tell(bc);
711
712 30 max_pts = ffio_read_varlen(bc);
713 30 s->duration = av_rescale_q(max_pts / nut->time_base_count,
714 30 nut->time_base[max_pts % nut->time_base_count],
715 30 AV_TIME_BASE_Q);
716 30 s->duration_estimation_method = AVFMT_DURATION_FROM_PTS;
717
718
2/4
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 30 times.
30 GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
719 30 syncpoints = av_malloc_array(syncpoint_count, sizeof(int64_t));
720 30 has_keyframe = av_malloc_array(syncpoint_count + 1, sizeof(int8_t));
721
2/4
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 30 times.
30 if (!syncpoints || !has_keyframe) {
722 ret = AVERROR(ENOMEM);
723 goto fail;
724 }
725
2/2
✓ Branch 0 taken 854 times.
✓ Branch 1 taken 30 times.
884 for (i = 0; i < syncpoint_count; i++) {
726 854 syncpoints[i] = ffio_read_varlen(bc);
727
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 854 times.
854 if (syncpoints[i] <= 0)
728 goto fail;
729
2/2
✓ Branch 0 taken 824 times.
✓ Branch 1 taken 30 times.
854 if (i)
730 824 syncpoints[i] += syncpoints[i - 1];
731 }
732
733
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 30 times.
80 for (i = 0; i < s->nb_streams; i++) {
734 50 int64_t last_pts = -1;
735
2/2
✓ Branch 0 taken 159 times.
✓ Branch 1 taken 50 times.
209 for (j = 0; j < syncpoint_count;) {
736 159 uint64_t x = ffio_read_varlen(bc);
737 159 int type = x & 1;
738 159 int n = j;
739 159 x >>= 1;
740
1/2
✓ Branch 0 taken 159 times.
✗ Branch 1 not taken.
159 if (type) {
741 159 int flag = x & 1;
742 159 x >>= 1;
743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 159 times.
159 if (n + x >= syncpoint_count + 1) {
744 av_log(s, AV_LOG_ERROR, "index overflow A %d + %"PRIu64" >= %d\n", n, x, syncpoint_count + 1);
745 goto fail;
746 }
747
2/2
✓ Branch 0 taken 936 times.
✓ Branch 1 taken 159 times.
1095 while (x--)
748 936 has_keyframe[n++] = flag;
749 159 has_keyframe[n++] = !flag;
750 } else {
751 if (x <= 1) {
752 av_log(s, AV_LOG_ERROR, "index: x %"PRIu64" is invalid\n", x);
753 goto fail;
754 }
755 while (x != 1) {
756 if (n >= syncpoint_count + 1) {
757 av_log(s, AV_LOG_ERROR, "index overflow B\n");
758 goto fail;
759 }
760 has_keyframe[n++] = x & 1;
761 x >>= 1;
762 }
763 }
764
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 159 times.
159 if (has_keyframe[0]) {
765 av_log(s, AV_LOG_ERROR, "keyframe before first syncpoint in index\n");
766 goto fail;
767 }
768
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 159 times.
159 av_assert0(n <= syncpoint_count + 1);
769
4/4
✓ Branch 0 taken 1095 times.
✓ Branch 1 taken 136 times.
✓ Branch 2 taken 1072 times.
✓ Branch 3 taken 23 times.
1231 for (; j < n && j < syncpoint_count; j++) {
770
2/2
✓ Branch 0 taken 812 times.
✓ Branch 1 taken 260 times.
1072 if (has_keyframe[j]) {
771 812 uint64_t B, A = ffio_read_varlen(bc);
772
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 812 times.
812 if (!A) {
773 A = ffio_read_varlen(bc);
774 B = ffio_read_varlen(bc);
775 // eor_pts[j][i] = last_pts + A + B
776 } else
777 812 B = 0;
778 812 av_add_index_entry(s->streams[i], 16 * syncpoints[j - 1],
779 812 last_pts + A, 0, 0, AVINDEX_KEYFRAME);
780 812 last_pts += A + B;
781 }
782 }
783 }
784 }
785
786
2/4
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 30 times.
30 if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
787 av_log(s, AV_LOG_ERROR, "index checksum mismatch\n");
788 goto fail;
789 }
790 30 ret = 0;
791
792 30 fail:
793 30 av_free(syncpoints);
794 30 av_free(has_keyframe);
795 30 return ret;
796 }
797
798 30 static int nut_read_close(AVFormatContext *s)
799 {
800 30 NUTContext *nut = s->priv_data;
801 int i;
802
803 30 av_freep(&nut->time_base);
804 30 av_freep(&nut->stream);
805 30 ff_nut_free_sp(nut);
806
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 30 times.
210 for (i = 1; i < nut->header_count; i++)
807 180 av_freep(&nut->header[i]);
808
809 30 return 0;
810 }
811
812 30 static int nut_read_header(AVFormatContext *s)
813 {
814 30 NUTContext *nut = s->priv_data;
815 30 AVIOContext *bc = s->pb;
816 int64_t pos;
817 int initialized_stream_count, ret;
818
819 30 nut->avf = s;
820
821 /* main header */
822 30 pos = 0;
823 30 ret = 0;
824 do {
825
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (ret == AVERROR(ENOMEM))
826 return ret;
827
828 30 pos = find_startcode(bc, MAIN_STARTCODE, pos) + 1;
829
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (pos < 0 + 1) {
830 av_log(s, AV_LOG_ERROR, "No main startcode found.\n");
831 return AVERROR_INVALIDDATA;
832 }
833
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
30 } while ((ret = decode_main_header(nut)) < 0);
834
835 /* stream headers */
836 30 pos = 0;
837
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 30 times.
80 for (initialized_stream_count = 0; initialized_stream_count < s->nb_streams;) {
838 50 pos = find_startcode(bc, STREAM_STARTCODE, pos) + 1;
839
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if (pos < 0 + 1) {
840 av_log(s, AV_LOG_ERROR, "Not all stream headers found.\n");
841 return AVERROR_INVALIDDATA;
842 }
843
1/2
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
50 if (decode_stream_header(nut) >= 0)
844 50 initialized_stream_count++;
845 }
846
847 /* info headers */
848 30 pos = 0;
849 160 for (;;) {
850 190 uint64_t startcode = find_any_startcode(bc, pos);
851 190 pos = avio_tell(bc);
852
853
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 190 times.
190 if (startcode == 0) {
854 av_log(s, AV_LOG_ERROR, "EOF before video frames\n");
855 return AVERROR_INVALIDDATA;
856
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 160 times.
190 } else if (startcode == SYNCPOINT_STARTCODE) {
857 30 nut->next_startcode = startcode;
858 30 break;
859
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 80 times.
160 } else if (startcode != INFO_STARTCODE) {
860 80 continue;
861 }
862
863 80 decode_info_header(nut);
864 }
865
866 30 ffformatcontext(s)->data_offset = pos - 8;
867
868
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if (bc->seekable & AVIO_SEEKABLE_NORMAL) {
869 30 int64_t orig_pos = avio_tell(bc);
870 30 find_and_decode_index(nut);
871 30 avio_seek(bc, orig_pos, SEEK_SET);
872 }
873
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 av_assert0(nut->next_startcode == SYNCPOINT_STARTCODE);
874
875 30 ff_metadata_conv_ctx(s, NULL, ff_nut_metadata_conv);
876
877 30 return 0;
878 }
879
880 2 static int read_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int is_meta, int64_t maxpos)
881 {
882 2 int count = ffio_read_varlen(bc);
883 2 int skip_start = 0;
884 2 int skip_end = 0;
885 2 int sample_rate = 0;
886 2 int width = 0;
887 2 int height = 0;
888 int i, ret;
889
890
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 for (i=0; i<count; i++) {
891 uint8_t name[256], str_value[256], type_str[256];
892 int value;
893
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (avio_tell(bc) >= maxpos)
894 return AVERROR_INVALIDDATA;
895 1 ret = get_str(bc, name, sizeof(name));
896
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0) {
897 av_log(s, AV_LOG_ERROR, "get_str failed while reading sm data\n");
898 return ret;
899 }
900 1 value = get_s(bc);
901
902
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (value == -1) {
903 ret = get_str(bc, str_value, sizeof(str_value));
904 if (ret < 0) {
905 av_log(s, AV_LOG_ERROR, "get_str failed while reading sm data\n");
906 return ret;
907 }
908 av_log(s, AV_LOG_WARNING, "Unknown string %s / %s\n", name, str_value);
909
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 } else if (value == -2) {
910 1 uint8_t *dst = NULL;
911 int64_t v64, value_len;
912
913 1 ret = get_str(bc, type_str, sizeof(type_str));
914
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0) {
915 av_log(s, AV_LOG_ERROR, "get_str failed while reading sm data\n");
916 return ret;
917 }
918 1 value_len = ffio_read_varlen(bc);
919
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if (value_len < 0 || value_len >= maxpos - avio_tell(bc))
920 return AVERROR_INVALIDDATA;
921
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!strcmp(name, "Palette")) {
922 dst = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, value_len);
923
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 } else if (!strcmp(name, "Extradata")) {
924 1 dst = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, value_len);
925 } else if (sscanf(name, "CodecSpecificSide%"SCNd64"", &v64) == 1) {
926 dst = av_packet_new_side_data(pkt, AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL, value_len + 8);
927 if(!dst)
928 return AVERROR(ENOMEM);
929 AV_WB64(dst, v64);
930 dst += 8;
931 } else if (!strcmp(name, "ChannelLayout") && value_len == 8) {
932 // Ignored
933 continue;
934 } else {
935 av_log(s, AV_LOG_WARNING, "Unknown data %s / %s\n", name, type_str);
936 avio_skip(bc, value_len);
937 continue;
938 }
939
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(!dst)
940 return AVERROR(ENOMEM);
941 1 avio_read(bc, dst, value_len);
942 } else if (value == -3) {
943 value = get_s(bc);
944 } else if (value == -4) {
945 value = ffio_read_varlen(bc);
946 } else if (value < -4) {
947 get_s(bc);
948 } else {
949 if (!strcmp(name, "SkipStart")) {
950 skip_start = value;
951 } else if (!strcmp(name, "SkipEnd")) {
952 skip_end = value;
953 } else if (!strcmp(name, "Channels")) {
954 // Ignored
955 } else if (!strcmp(name, "SampleRate")) {
956 sample_rate = value;
957 } else if (!strcmp(name, "Width")) {
958 width = value;
959 } else if (!strcmp(name, "Height")) {
960 height = value;
961 } else {
962 av_log(s, AV_LOG_WARNING, "Unknown integer %s\n", name);
963 }
964 }
965 }
966
967
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
2 if (sample_rate || width || height) {
968 uint8_t *dst = av_packet_new_side_data(pkt, AV_PKT_DATA_PARAM_CHANGE, 16);
969 if (!dst)
970 return AVERROR(ENOMEM);
971 bytestream_put_le32(&dst,
972 AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE*(!!sample_rate) +
973 AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS*(!!(width|height))
974 );
975 if (sample_rate)
976 bytestream_put_le32(&dst, sample_rate);
977 if (width || height){
978 bytestream_put_le32(&dst, width);
979 bytestream_put_le32(&dst, height);
980 }
981 }
982
983
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (skip_start || skip_end) {
984 uint8_t *dst = av_packet_new_side_data(pkt, AV_PKT_DATA_SKIP_SAMPLES, 10);
985 if (!dst)
986 return AVERROR(ENOMEM);
987 AV_WL32(dst, skip_start);
988 AV_WL32(dst+4, skip_end);
989 }
990
991
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (avio_tell(bc) >= maxpos)
992 return AVERROR_INVALIDDATA;
993
994 2 return 0;
995 }
996
997 1381 static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id,
998 uint8_t *header_idx, int frame_code)
999 {
1000 1381 AVFormatContext *s = nut->avf;
1001 1381 AVIOContext *bc = s->pb;
1002 StreamContext *stc;
1003 int size, flags, size_mul, pts_delta, i, reserved_count, ret;
1004 uint64_t tmp;
1005
1006
2/2
✓ Branch 0 taken 1364 times.
✓ Branch 1 taken 17 times.
1381 if (!(nut->flags & NUT_PIPE) &&
1007
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1364 times.
1364 avio_tell(bc) > nut->last_syncpoint_pos + nut->max_distance) {
1008 av_log(s, AV_LOG_ERROR,
1009 "Last frame must have been damaged %"PRId64" > %"PRId64" + %d\n",
1010 avio_tell(bc), nut->last_syncpoint_pos, nut->max_distance);
1011 return AVERROR_INVALIDDATA;
1012 }
1013
1014 1381 flags = nut->frame_code[frame_code].flags;
1015 1381 size_mul = nut->frame_code[frame_code].size_mul;
1016 1381 size = nut->frame_code[frame_code].size_lsb;
1017 1381 *stream_id = nut->frame_code[frame_code].stream_id;
1018 1381 pts_delta = nut->frame_code[frame_code].pts_delta;
1019 1381 reserved_count = nut->frame_code[frame_code].reserved_count;
1020 1381 *header_idx = nut->frame_code[frame_code].header_idx;
1021
1022
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1381 times.
1381 if (flags & FLAG_INVALID)
1023 return AVERROR_INVALIDDATA;
1024
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 1285 times.
1381 if (flags & FLAG_CODED)
1025 96 flags ^= ffio_read_varlen(bc);
1026
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 1349 times.
1381 if (flags & FLAG_STREAM_ID) {
1027
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
32 GET_V(*stream_id, tmp < s->nb_streams);
1028 }
1029 1381 stc = &nut->stream[*stream_id];
1030
2/2
✓ Branch 0 taken 1050 times.
✓ Branch 1 taken 331 times.
1381 if (flags & FLAG_CODED_PTS) {
1031 1050 int64_t coded_pts = ffio_read_varlen(bc);
1032 // FIXME check last_pts validity?
1033
1/2
✓ Branch 0 taken 1050 times.
✗ Branch 1 not taken.
1050 if (coded_pts < (1LL << stc->msb_pts_shift)) {
1034 1050 *pts = ff_lsb2full(stc, coded_pts);
1035 } else
1036 *pts = coded_pts - (1LL << stc->msb_pts_shift);
1037 } else
1038 331 *pts = stc->last_pts + pts_delta;
1039
2/2
✓ Branch 0 taken 1350 times.
✓ Branch 1 taken 31 times.
1381 if (flags & FLAG_SIZE_MSB)
1040 1350 size += size_mul * ffio_read_varlen(bc);
1041
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1381 times.
1381 if (flags & FLAG_MATCH_TIME)
1042 get_s(bc);
1043
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1381 times.
1381 if (flags & FLAG_HEADER_IDX)
1044 *header_idx = ffio_read_varlen(bc);
1045
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1381 times.
1381 if (flags & FLAG_RESERVED)
1046 reserved_count = ffio_read_varlen(bc);
1047
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1381 times.
1381 for (i = 0; i < reserved_count; i++) {
1048 if (bc->eof_reached) {
1049 av_log(s, AV_LOG_ERROR, "reached EOF while decoding frame header\n");
1050 return AVERROR_INVALIDDATA;
1051 }
1052 ffio_read_varlen(bc);
1053 }
1054
1055
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1381 times.
1381 if (*header_idx >= (unsigned)nut->header_count) {
1056 av_log(s, AV_LOG_ERROR, "header_idx invalid\n");
1057 return AVERROR_INVALIDDATA;
1058 }
1059
2/2
✓ Branch 0 taken 903 times.
✓ Branch 1 taken 478 times.
1381 if (size > 4096)
1060 903 *header_idx = 0;
1061 1381 size -= nut->header_len[*header_idx];
1062
1063
2/2
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 1298 times.
1381 if (flags & FLAG_CHECKSUM) {
1064 83 avio_rb32(bc); // FIXME check this
1065
2/2
✓ Branch 0 taken 1282 times.
✓ Branch 1 taken 16 times.
1298 } else if (!(nut->flags & NUT_PIPE) &&
1066
1/2
✓ Branch 0 taken 1282 times.
✗ Branch 1 not taken.
1282 size > 2 * nut->max_distance ||
1067
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1298 times.
1298 FFABS(stc->last_pts - *pts) > stc->max_pts_distance) {
1068 av_log(s, AV_LOG_ERROR, "frame size > 2max_distance and no checksum\n");
1069 return AVERROR_INVALIDDATA;
1070 }
1071
1072 1381 stc->last_pts = *pts;
1073 1381 stc->last_flags = flags;
1074
1075 1381 return size;
1076 fail:
1077 return ret;
1078 }
1079
1080 1381 static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code)
1081 {
1082 1381 AVFormatContext *s = nut->avf;
1083 1381 AVIOContext *bc = s->pb;
1084 int size, stream_id, discard, ret;
1085 int64_t pts, last_IP_pts;
1086 StreamContext *stc;
1087 uint8_t header_idx;
1088
1089 1381 size = decode_frame_header(nut, &pts, &stream_id, &header_idx, frame_code);
1090
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1381 times.
1381 if (size < 0)
1091 return size;
1092
1093 1381 stc = &nut->stream[stream_id];
1094
1095
2/2
✓ Branch 0 taken 1204 times.
✓ Branch 1 taken 177 times.
1381 if (stc->last_flags & FLAG_KEY)
1096 1204 stc->skip_until_key_frame = 0;
1097
1098 1381 discard = s->streams[stream_id]->discard;
1099 1381 last_IP_pts = ffstream(s->streams[stream_id])->last_IP_pts;
1100
5/6
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 1338 times.
✓ Branch 2 taken 43 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 43 times.
✓ Branch 5 taken 1338 times.
1381 if ((discard >= AVDISCARD_NONKEY && !(stc->last_flags & FLAG_KEY)) ||
1101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 (discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE &&
1102
2/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1338 times.
✓ Branch 3 taken 43 times.
1381 last_IP_pts > pts) ||
1103 1338 discard >= AVDISCARD_ALL ||
1104
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1331 times.
1338 stc->skip_until_key_frame) {
1105 50 avio_skip(bc, size);
1106 50 return 1;
1107 }
1108
1109 1331 ret = av_new_packet(pkt, size + nut->header_len[header_idx]);
1110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1331 times.
1331 if (ret < 0)
1111 return ret;
1112
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 1283 times.
1331 if (nut->header[header_idx])
1113 48 memcpy(pkt->data, nut->header[header_idx], nut->header_len[header_idx]);
1114 1331 pkt->pos = avio_tell(bc); // FIXME
1115
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1330 times.
1331 if (stc->last_flags & FLAG_SM_DATA) {
1116 int sm_size;
1117
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (read_sm_data(s, bc, pkt, 0, pkt->pos + size) < 0) {
1118 ret = AVERROR_INVALIDDATA;
1119 goto fail;
1120 }
1121
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (read_sm_data(s, bc, pkt, 1, pkt->pos + size) < 0) {
1122 ret = AVERROR_INVALIDDATA;
1123 goto fail;
1124 }
1125 1 sm_size = avio_tell(bc) - pkt->pos;
1126 1 size -= sm_size;
1127 }
1128
1129 1331 ret = avio_read(bc, pkt->data + nut->header_len[header_idx], size);
1130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1331 times.
1331 if (ret != size) {
1131 if (ret < 0)
1132 goto fail;
1133 }
1134 1331 av_shrink_packet(pkt, nut->header_len[header_idx] + ret);
1135
1136 1331 pkt->stream_index = stream_id;
1137
2/2
✓ Branch 0 taken 1161 times.
✓ Branch 1 taken 170 times.
1331 if (stc->last_flags & FLAG_KEY)
1138 1161 pkt->flags |= AV_PKT_FLAG_KEY;
1139 1331 pkt->pts = pts;
1140
1141 1331 return 0;
1142 fail:
1143 av_packet_unref(pkt);
1144 return ret;
1145 }
1146
1147 1370 static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
1148 {
1149 1370 NUTContext *nut = s->priv_data;
1150 1370 AVIOContext *bc = s->pb;
1151 1370 int i, frame_code = 0, ret, skip;
1152 int64_t ts, back_ptr;
1153
1154 79 for (;;) {
1155 1449 int64_t pos = avio_tell(bc);
1156 1449 uint64_t tmp = nut->next_startcode;
1157 1449 nut->next_startcode = 0;
1158
1159
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 1419 times.
1449 if (tmp) {
1160 30 pos -= 8;
1161 } else {
1162 1419 frame_code = avio_r8(bc);
1163
2/2
✓ Branch 1 taken 39 times.
✓ Branch 2 taken 1380 times.
1419 if (avio_feof(bc))
1164 39 return AVERROR_EOF;
1165
2/2
✓ Branch 0 taken 869 times.
✓ Branch 1 taken 511 times.
1380 if (frame_code == 'N') {
1166 869 tmp = frame_code;
1167
2/2
✓ Branch 0 taken 6083 times.
✓ Branch 1 taken 869 times.
6952 for (i = 1; i < 8; i++)
1168 6083 tmp = (tmp << 8) + avio_r8(bc);
1169 }
1170 }
1171
3/5
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 870 times.
✓ Branch 3 taken 511 times.
✗ Branch 4 not taken.
1410 switch (tmp) {
1172 29 case MAIN_STARTCODE:
1173 case STREAM_STARTCODE:
1174 case INDEX_STARTCODE:
1175 29 skip = get_packetheader(nut, bc, 0, tmp);
1176 29 avio_skip(bc, skip);
1177 29 break;
1178 case INFO_STARTCODE:
1179 if (decode_info_header(nut) < 0)
1180 goto resync;
1181 break;
1182 870 case SYNCPOINT_STARTCODE:
1183
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 870 times.
870 if (decode_syncpoint(nut, &ts, &back_ptr) < 0)
1184 goto resync;
1185 870 frame_code = avio_r8(bc);
1186 av_fallthrough;
1187 1381 case 0:
1188 1381 ret = decode_frame(nut, pkt, frame_code);
1189
2/2
✓ Branch 0 taken 1331 times.
✓ Branch 1 taken 50 times.
1381 if (ret == 0)
1190 1331 return 0;
1191
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 else if (ret == 1) // OK but discard packet
1192 50 break;
1193 av_fallthrough;
1194 default:
1195 resync:
1196 av_log(s, AV_LOG_DEBUG, "syncing from %"PRId64"\n", pos);
1197 tmp = find_any_startcode(bc, FFMAX(nut->last_syncpoint_pos, nut->last_resync_pos) + 1);
1198 nut->last_resync_pos = avio_tell(bc);
1199 if (tmp == 0)
1200 return AVERROR_INVALIDDATA;
1201 av_log(s, AV_LOG_DEBUG, "sync\n");
1202 nut->next_startcode = tmp;
1203 }
1204 }
1205 }
1206
1207 static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index,
1208 int64_t *pos_arg, int64_t pos_limit)
1209 {
1210 NUTContext *nut = s->priv_data;
1211 AVIOContext *bc = s->pb;
1212 int64_t pos, pts, back_ptr;
1213 av_log(s, AV_LOG_DEBUG, "read_timestamp(X,%d,%"PRId64",%"PRId64")\n",
1214 stream_index, *pos_arg, pos_limit);
1215
1216 pos = *pos_arg;
1217 do {
1218 pos = find_startcode(bc, SYNCPOINT_STARTCODE, pos) + 1;
1219 if (pos < 1) {
1220 av_log(s, AV_LOG_ERROR, "read_timestamp failed.\n");
1221 return AV_NOPTS_VALUE;
1222 }
1223 } while (decode_syncpoint(nut, &pts, &back_ptr) < 0);
1224 *pos_arg = pos - 1;
1225 av_assert0(nut->last_syncpoint_pos == *pos_arg);
1226
1227 av_log(s, AV_LOG_DEBUG, "return %"PRId64" %"PRId64"\n", pts, back_ptr);
1228 if (stream_index == -2)
1229 return back_ptr;
1230 av_assert0(stream_index == -1);
1231 return pts;
1232 }
1233
1234 26 static int read_seek(AVFormatContext *s, int stream_index,
1235 int64_t pts, int flags)
1236 {
1237 26 NUTContext *nut = s->priv_data;
1238 26 AVStream *st = s->streams[stream_index];
1239 26 FFStream *const sti = ffstream(st);
1240 26 Syncpoint dummy = { .ts = pts * av_q2d(st->time_base) * AV_TIME_BASE };
1241 26 Syncpoint nopts_sp = { .ts = AV_NOPTS_VALUE, .back_ptr = AV_NOPTS_VALUE };
1242 26 Syncpoint *sp, *next_node[2] = { &nopts_sp, &nopts_sp };
1243 int64_t pos, pos2, ts;
1244 int i;
1245
1246
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (nut->flags & NUT_PIPE) {
1247 return AVERROR(ENOSYS);
1248 }
1249
1250
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if (sti->index_entries) {
1251 26 int index = av_index_search_timestamp(st, pts, flags);
1252
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 15 times.
26 if (index < 0)
1253 11 index = av_index_search_timestamp(st, pts, flags ^ AVSEEK_FLAG_BACKWARD);
1254
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (index < 0)
1255 return -1;
1256
1257 26 pos2 = sti->index_entries[index].pos;
1258 26 ts = sti->index_entries[index].timestamp;
1259 } else {
1260 av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pts_cmp,
1261 (void **) next_node);
1262 av_log(s, AV_LOG_DEBUG, "%"PRIu64"-%"PRIu64" %"PRId64"-%"PRId64"\n",
1263 next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
1264 next_node[1]->ts);
1265 pos = ff_gen_search(s, -1, dummy.ts, next_node[0]->pos,
1266 next_node[1]->pos, next_node[1]->pos,
1267 next_node[0]->ts, next_node[1]->ts,
1268 AVSEEK_FLAG_BACKWARD, &ts, nut_read_timestamp);
1269 if (pos < 0)
1270 return pos;
1271
1272 if (!(flags & AVSEEK_FLAG_BACKWARD)) {
1273 dummy.pos = pos + 16;
1274 next_node[1] = &nopts_sp;
1275 av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp,
1276 (void **) next_node);
1277 pos2 = ff_gen_search(s, -2, dummy.pos, next_node[0]->pos,
1278 next_node[1]->pos, next_node[1]->pos,
1279 next_node[0]->back_ptr, next_node[1]->back_ptr,
1280 flags, &ts, nut_read_timestamp);
1281 if (pos2 >= 0)
1282 pos = pos2;
1283 // FIXME dir but I think it does not matter
1284 }
1285 dummy.pos = pos;
1286 sp = av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp,
1287 NULL);
1288
1289 av_assert0(sp);
1290 pos2 = sp->back_ptr - 15;
1291 }
1292 26 av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos2);
1293 26 pos = find_startcode(s->pb, SYNCPOINT_STARTCODE, pos2);
1294 26 avio_seek(s->pb, pos, SEEK_SET);
1295 26 nut->last_syncpoint_pos = pos;
1296 26 av_log(s, AV_LOG_DEBUG, "SP: %"PRId64"\n", pos);
1297
2/4
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 26 times.
26 if (pos2 > pos || pos2 + 15 < pos)
1298 av_log(s, AV_LOG_ERROR, "no syncpoint at backptr pos\n");
1299
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 26 times.
78 for (i = 0; i < s->nb_streams; i++)
1300 52 nut->stream[i].skip_until_key_frame = 1;
1301
1302 26 nut->last_resync_pos = 0;
1303
1304 26 return 0;
1305 }
1306
1307 const FFInputFormat ff_nut_demuxer = {
1308 .p.name = "nut",
1309 .p.long_name = NULL_IF_CONFIG_SMALL("NUT"),
1310 .p.flags = AVFMT_SEEK_TO_PTS,
1311 .p.extensions = "nut",
1312 .p.codec_tag = ff_nut_codec_tags,
1313 .priv_data_size = sizeof(NUTContext),
1314 .flags_internal = FF_INFMT_FLAG_INIT_CLEANUP,
1315 .read_probe = nut_probe,
1316 .read_header = nut_read_header,
1317 .read_packet = nut_read_packet,
1318 .read_close = nut_read_close,
1319 .read_seek = read_seek,
1320 };
1321