FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/nutdec.c
Date: 2022-11-26 13:19:19
Exec Total Coverage
Lines: 538 860 62.6%
Branches: 310 584 53.1%

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