FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/nutdec.c
Date: 2024-04-19 17:50:32
Exec Total Coverage
Lines: 539 858 62.8%
Functions: 21 23 91.3%
Branches: 311 582 53.4%

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