FFmpeg
nutdec.c
Go to the documentation of this file.
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 static int get_str(AVIOContext *bc, char *string, unsigned int maxlen)
44 {
45  unsigned int len = ffio_read_varlen(bc);
46 
47  if (len && maxlen)
48  avio_read(bc, string, FFMIN(len, maxlen));
49  while (len > maxlen) {
50  avio_r8(bc);
51  len--;
52  if (bc->eof_reached)
53  len = maxlen;
54  }
55 
56  if (maxlen)
57  string[FFMIN(len, maxlen - 1)] = 0;
58 
59  if (bc->eof_reached)
60  return AVERROR_EOF;
61  if (maxlen == len)
62  return -1;
63  else
64  return 0;
65 }
66 
67 static int64_t get_s(AVIOContext *bc)
68 {
69  int64_t v = ffio_read_varlen(bc) + 1;
70 
71  if (v & 1)
72  return -(v >> 1);
73  else
74  return (v >> 1);
75 }
76 
77 static uint64_t get_fourcc(AVIOContext *bc)
78 {
79  unsigned int len = ffio_read_varlen(bc);
80 
81  if (len == 2)
82  return avio_rl16(bc);
83  else if (len == 4)
84  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 
92  int calculate_checksum, uint64_t startcode)
93 {
94  int64_t size;
95 
96  startcode = av_be2ne64(startcode);
97  startcode = ff_crc04C11DB7_update(0, (uint8_t*) &startcode, 8);
98 
100  size = ffio_read_varlen(bc);
101  if (size > 4096)
102  avio_rb32(bc);
103  if (ffio_get_checksum(bc) && size > 4096)
104  return -1;
105 
106  ffio_init_checksum(bc, calculate_checksum ? ff_crc04C11DB7_update : NULL, 0);
107 
108  return size;
109 }
110 
111 static uint64_t find_any_startcode(AVIOContext *bc, int64_t pos)
112 {
113  uint64_t state = 0;
114 
115  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  avio_seek(bc, pos, SEEK_SET);
119  while (!avio_feof(bc)) {
120  state = (state << 8) | avio_r8(bc);
121  if ((state >> 56) != 'N')
122  continue;
123  switch (state) {
124  case MAIN_STARTCODE:
125  case STREAM_STARTCODE:
126  case SYNCPOINT_STARTCODE:
127  case INFO_STARTCODE:
128  case INDEX_STARTCODE:
129  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 static int64_t find_startcode(AVIOContext *bc, uint64_t code, int64_t pos)
143 {
144  for (;;) {
145  uint64_t startcode = find_any_startcode(bc, pos);
146  if (startcode == code)
147  return avio_tell(bc) - 8;
148  else if (startcode == 0)
149  return -1;
150  pos = -1;
151  }
152 }
153 
154 static int nut_probe(const AVProbeData *p)
155 {
156  int i;
157 
158  for (i = 0; i < p->buf_size-8; i++) {
159  if (AV_RB32(p->buf+i) != MAIN_STARTCODE>>32)
160  continue;
161  if (AV_RB32(p->buf+i+4) == (MAIN_STARTCODE & 0xFFFFFFFF))
162  return AVPROBE_SCORE_MAX;
163  }
164  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 static int skip_reserved(AVIOContext *bc, int64_t pos)
179 {
180  pos -= avio_tell(bc);
181  if (pos < 0) {
182  avio_seek(bc, pos, SEEK_CUR);
183  return AVERROR_INVALIDDATA;
184  } else {
185  while (pos--) {
186  if (bc->eof_reached)
187  return AVERROR_INVALIDDATA;
188  avio_r8(bc);
189  }
190  return 0;
191  }
192 }
193 
195 {
196  AVFormatContext *s = nut->avf;
197  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  length = get_packetheader(nut, bc, 1, MAIN_STARTCODE);
204  if (length == (uint64_t)-1)
205  return AVERROR_INVALIDDATA;
206  end = length + avio_tell(bc);
207 
208  nut->version = ffio_read_varlen(bc);
209  if (nut->version < NUT_MIN_VERSION ||
210  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  if (nut->version > 3)
216  nut->minor_version = ffio_read_varlen(bc);
217 
218  GET_V(stream_count, tmp > 0 && tmp <= NUT_MAX_STREAMS);
219 
220  nut->max_distance = ffio_read_varlen(bc);
221  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  GET_V(nut->time_base_count, tmp > 0 && tmp < INT_MAX / sizeof(AVRational) && tmp < length/2);
227  nut->time_base = av_malloc_array(nut->time_base_count, sizeof(AVRational));
228  if (!nut->time_base)
229  return AVERROR(ENOMEM);
230 
231  for (i = 0; i < nut->time_base_count; i++) {
232  GET_V(nut->time_base[i].num, tmp > 0 && tmp < (1ULL << 31));
233  GET_V(nut->time_base[i].den, tmp > 0 && tmp < (1ULL << 31));
234  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);
239  goto fail;
240  }
241  }
242  tmp_pts = 0;
243  tmp_mul = 1;
244  tmp_stream = 0;
245  tmp_head_idx = 0;
246  for (i = 0; i < 256;) {
247  int tmp_flags = ffio_read_varlen(bc);
248  int tmp_fields = ffio_read_varlen(bc);
249  if (tmp_fields < 0) {
250  av_log(s, AV_LOG_ERROR, "fields %d is invalid\n", tmp_fields);
252  goto fail;
253  }
254 
255  if (tmp_fields > 0)
256  tmp_pts = get_s(bc);
257  if (tmp_fields > 1)
258  tmp_mul = ffio_read_varlen(bc);
259  if (tmp_fields > 2)
260  tmp_stream = ffio_read_varlen(bc);
261  if (tmp_fields > 3)
262  tmp_size = ffio_read_varlen(bc);
263  else
264  tmp_size = 0;
265  if (tmp_fields > 4)
266  tmp_res = ffio_read_varlen(bc);
267  else
268  tmp_res = 0;
269  if (tmp_fields > 5)
270  count = ffio_read_varlen(bc);
271  else
272  count = tmp_mul - (unsigned)tmp_size;
273  if (tmp_fields > 6)
274  get_s(bc);
275  if (tmp_fields > 7)
276  tmp_head_idx = ffio_read_varlen(bc);
277 
278  while (tmp_fields-- > 8) {
279  if (bc->eof_reached) {
280  av_log(s, AV_LOG_ERROR, "reached EOF while decoding main header\n");
282  goto fail;
283  }
284  ffio_read_varlen(bc);
285  }
286 
287  if (count <= 0 || count > 256 - (i <= 'N') - i) {
288  av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i);
290  goto fail;
291  }
292  if (tmp_stream >= stream_count) {
293  av_log(s, AV_LOG_ERROR, "illegal stream number %d >= %d\n",
294  tmp_stream, stream_count);
296  goto fail;
297  }
298  if (tmp_size < 0 || tmp_size > INT_MAX - count) {
299  av_log(s, AV_LOG_ERROR, "illegal size\n");
301  goto fail;
302  }
303 
304  for (j = 0; j < count; j++, i++) {
305  if (i == 'N') {
306  nut->frame_code[i].flags = FLAG_INVALID;
307  j--;
308  continue;
309  }
310  nut->frame_code[i].flags = tmp_flags;
311  nut->frame_code[i].pts_delta = tmp_pts;
312  nut->frame_code[i].stream_id = tmp_stream;
313  nut->frame_code[i].size_mul = tmp_mul;
314  nut->frame_code[i].size_lsb = tmp_size + j;
315  nut->frame_code[i].reserved_count = tmp_res;
316  nut->frame_code[i].header_idx = tmp_head_idx;
317  }
318  }
319  av_assert0(nut->frame_code['N'].flags == FLAG_INVALID);
320 
321  if (end > avio_tell(bc) + 4) {
322  int rem = 1024;
323  GET_V(nut->header_count, tmp < 128U);
324  nut->header_count++;
325  for (i = 1; i < nut->header_count; i++) {
326  uint8_t *hdr;
327  GET_V(nut->header_len[i], tmp > 0 && tmp < 256);
328  if (rem < nut->header_len[i]) {
330  "invalid elision header %d : %d > %d\n",
331  i, nut->header_len[i], rem);
333  goto fail;
334  }
335  rem -= nut->header_len[i];
336  hdr = av_malloc(nut->header_len[i]);
337  if (!hdr) {
338  ret = AVERROR(ENOMEM);
339  goto fail;
340  }
341  avio_read(bc, hdr, nut->header_len[i]);
342  nut->header[i] = hdr;
343  }
344  av_assert0(nut->header_len[0] == 0);
345  }
346 
347  // flags had been effectively introduced in version 4
348  if (nut->version > 3 && end > avio_tell(bc) + 4) {
349  nut->flags = ffio_read_varlen(bc);
350  }
351 
352  if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
353  av_log(s, AV_LOG_ERROR, "main header checksum mismatch\n");
355  goto fail;
356  }
357 
358  nut->stream = av_calloc(stream_count, sizeof(StreamContext));
359  if (!nut->stream) {
360  ret = AVERROR(ENOMEM);
361  goto fail;
362  }
363  for (i = 0; i < stream_count; i++) {
364  if (!avformat_new_stream(s, NULL)) {
365  ret = AVERROR(ENOMEM);
366  goto fail;
367  }
368  }
369 
370  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 
381 {
382  AVFormatContext *s = nut->avf;
383  AVIOContext *bc = s->pb;
384  StreamContext *stc;
385  int class, stream_id, ret;
386  uint64_t tmp, end;
387  AVStream *st = NULL;
388 
389  end = get_packetheader(nut, bc, 1, STREAM_STARTCODE);
390  end += avio_tell(bc);
391 
392  GET_V(stream_id, tmp < s->nb_streams && !nut->stream[tmp].time_base);
393  stc = &nut->stream[stream_id];
394  st = s->streams[stream_id];
395  if (!st)
396  return AVERROR(ENOMEM);
397 
398  class = ffio_read_varlen(bc);
399  tmp = get_fourcc(bc);
400  st->codecpar->codec_tag = tmp;
401  switch (class) {
402  case 0:
404  st->codecpar->codec_id = av_codec_get_id((const AVCodecTag * const []) {
408  0
409  },
410  tmp);
411  break;
412  case 1:
414  st->codecpar->codec_id = av_codec_get_id((const AVCodecTag * const []) {
418  0
419  },
420  tmp);
421  break;
422  case 2:
425  break;
426  case 3:
429  break;
430  default:
431  av_log(s, AV_LOG_ERROR, "unknown stream class (%d)\n", class);
432  return AVERROR(ENOSYS);
433  }
434  if (class < 3 && st->codecpar->codec_id == AV_CODEC_ID_NONE)
436  "Unknown codec tag '0x%04x' for stream number %d\n",
437  (unsigned int) tmp, stream_id);
438 
439  GET_V(stc->time_base_id, tmp < nut->time_base_count);
440  GET_V(stc->msb_pts_shift, tmp < 16);
442  GET_V(stc->decode_delay, tmp < 1000); // sanity limit, raise this if Moore's law is true
443  st->codecpar->video_delay = stc->decode_delay;
444  ffio_read_varlen(bc); // stream flags
445 
446  GET_V(st->codecpar->extradata_size, tmp < (1 << 30));
447  if (st->codecpar->extradata_size) {
448  ret = ff_get_extradata(s, st->codecpar, bc,
449  st->codecpar->extradata_size);
450  if (ret < 0)
451  return ret;
452  }
453 
454  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
455  GET_V(st->codecpar->width, tmp > 0);
456  GET_V(st->codecpar->height, tmp > 0);
459  if ((!st->sample_aspect_ratio.num) != (!st->sample_aspect_ratio.den)) {
460  av_log(s, AV_LOG_ERROR, "invalid aspect ratio %d/%d\n",
463  goto fail;
464  }
465  ffio_read_varlen(bc); /* csp type */
466  } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
467  GET_V(st->codecpar->sample_rate, tmp > 0);
468  ffio_read_varlen(bc); // samplerate_den
470  }
471  if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
473  "stream header %d checksum mismatch\n", stream_id);
475  goto fail;
476  }
477  stc->time_base = &nut->time_base[stc->time_base_id];
478  avpriv_set_pts_info(s->streams[stream_id], 63, stc->time_base->num,
479  stc->time_base->den);
480  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 
490  int stream_id)
491 {
492  int flag = 0, i;
493 
494  for (i = 0; ff_nut_dispositions[i].flag; ++i)
495  if (!strcmp(ff_nut_dispositions[i].str, value))
497  if (!flag)
498  av_log(avf, AV_LOG_INFO, "unknown disposition type '%s'\n", value);
499  for (i = 0; i < avf->nb_streams; ++i)
500  if (stream_id == i || stream_id == -1)
501  avf->streams[i]->disposition |= flag;
502 }
503 
505 {
506  AVFormatContext *s = nut->avf;
507  AVIOContext *bc = s->pb;
508  uint64_t tmp, chapter_start, chapter_len;
509  unsigned int stream_id_plus1, count;
510  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  int *event_flags = NULL;
515  AVChapter *chapter = NULL;
516  AVStream *st = NULL;
517  AVDictionary **metadata = NULL;
518  int metadata_flag = 0;
519 
520  end = get_packetheader(nut, bc, 1, INFO_STARTCODE);
521  end += avio_tell(bc);
522 
523  GET_V(stream_id_plus1, tmp <= s->nb_streams);
524  chapter_id = get_s(bc);
525  chapter_start = ffio_read_varlen(bc);
526  chapter_len = ffio_read_varlen(bc);
527  count = ffio_read_varlen(bc);
528 
529  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  } else if (stream_id_plus1) {
541  st = s->streams[stream_id_plus1 - 1];
542  metadata = &st->metadata;
543  event_flags = &st->event_flags;
544  metadata_flag = AVSTREAM_EVENT_FLAG_METADATA_UPDATED;
545  } else {
546  metadata = &s->metadata;
547  event_flags = &s->event_flags;
548  metadata_flag = AVFMT_EVENT_FLAG_METADATA_UPDATED;
549  }
550 
551  for (i = 0; i < count; i++) {
552  ret = get_str(bc, name, sizeof(name));
553  if (ret < 0) {
554  av_log(s, AV_LOG_ERROR, "get_str failed while decoding info header\n");
555  return ret;
556  }
557  value = get_s(bc);
558  str_value[0] = 0;
559 
560  if (value == -1) {
561  type = "UTF-8";
562  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  if (ret < 0) {
585  av_log(s, AV_LOG_ERROR, "get_str failed while decoding info header\n");
586  return ret;
587  }
588 
589  if (stream_id_plus1 > s->nb_streams) {
591  "invalid stream id %d for info packet\n",
592  stream_id_plus1);
593  continue;
594  }
595 
596  if (!strcmp(type, "UTF-8")) {
597  if (chapter_id == 0 && !strcmp(name, "Disposition")) {
598  set_disposition_bits(s, str_value, stream_id_plus1 - 1);
599  continue;
600  }
601 
602  if (stream_id_plus1 && !strcmp(name, "r_frame_rate")) {
603  sscanf(str_value, "%d/%d", &st->r_frame_rate.num, &st->r_frame_rate.den);
604  if (st->r_frame_rate.num >= 1000LL*st->r_frame_rate.den ||
605  st->r_frame_rate.num < 0 || st->r_frame_rate.den < 0)
606  st->r_frame_rate.num = st->r_frame_rate.den = 0;
607  continue;
608  }
609 
610  if (metadata && av_strcasecmp(name, "Uses") &&
611  av_strcasecmp(name, "Depends") && av_strcasecmp(name, "Replaces")) {
612  if (event_flags)
613  *event_flags |= metadata_flag;
614  av_dict_set(metadata, name, str_value, 0);
615  }
616  }
617  }
618 
619  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 fail:
624  return FFMIN(ret, 0);
625 }
626 
627 static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
628 {
629  AVFormatContext *s = nut->avf;
630  AVIOContext *bc = s->pb;
631  int64_t end;
632  uint64_t tmp;
633  int ret;
634 
635  nut->last_syncpoint_pos = avio_tell(bc) - 8;
636 
637  end = get_packetheader(nut, bc, 1, SYNCPOINT_STARTCODE);
638  end += avio_tell(bc);
639 
640  tmp = ffio_read_varlen(bc);
641  *back_ptr = nut->last_syncpoint_pos - 16 * ffio_read_varlen(bc);
642  if (*back_ptr < 0)
643  return AVERROR_INVALIDDATA;
644 
645  ff_nut_reset_ts(nut, nut->time_base[tmp % nut->time_base_count],
646  tmp / nut->time_base_count);
647 
648  if (nut->flags & NUT_BROADCAST) {
649  tmp = ffio_read_varlen(bc);
650  av_log(s, AV_LOG_VERBOSE, "Syncpoint wallclock %"PRId64"\n",
652  nut->time_base[tmp % nut->time_base_count],
653  AV_TIME_BASE_Q));
654  }
655 
656  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  *ts = tmp / nut->time_base_count *
663 
664  if ((ret = ff_nut_add_sp(nut, nut->last_syncpoint_pos, *back_ptr, *ts)) < 0)
665  return ret;
666 
667  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 
677 
678  if(duration > 0)
679  s->duration_estimation_method = AVFMT_DURATION_FROM_PTS;
680  return duration;
681 }
682 
684 {
685  AVFormatContext *s = nut->avf;
686  AVIOContext *bc = s->pb;
687  uint64_t tmp, end;
688  int i, j, syncpoint_count;
689  int64_t filesize = avio_size(bc);
690  int64_t *syncpoints = NULL;
691  uint64_t max_pts;
692  int8_t *has_keyframe = NULL;
693  int ret = AVERROR_INVALIDDATA;
694 
695  if(filesize <= 0)
696  return -1;
697 
698  avio_seek(bc, filesize - 12, SEEK_SET);
699  avio_seek(bc, filesize - avio_rb64(bc), SEEK_SET);
700  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  end = get_packetheader(nut, bc, 1, INDEX_STARTCODE);
709  end += avio_tell(bc);
710 
711  max_pts = ffio_read_varlen(bc);
712  s->duration = av_rescale_q(max_pts / nut->time_base_count,
713  nut->time_base[max_pts % nut->time_base_count],
715  s->duration_estimation_method = AVFMT_DURATION_FROM_PTS;
716 
717  GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
718  syncpoints = av_malloc_array(syncpoint_count, sizeof(int64_t));
719  has_keyframe = av_malloc_array(syncpoint_count + 1, sizeof(int8_t));
720  if (!syncpoints || !has_keyframe) {
721  ret = AVERROR(ENOMEM);
722  goto fail;
723  }
724  for (i = 0; i < syncpoint_count; i++) {
725  syncpoints[i] = ffio_read_varlen(bc);
726  if (syncpoints[i] <= 0)
727  goto fail;
728  if (i)
729  syncpoints[i] += syncpoints[i - 1];
730  }
731 
732  for (i = 0; i < s->nb_streams; i++) {
733  int64_t last_pts = -1;
734  for (j = 0; j < syncpoint_count;) {
735  uint64_t x = ffio_read_varlen(bc);
736  int type = x & 1;
737  int n = j;
738  x >>= 1;
739  if (type) {
740  int flag = x & 1;
741  x >>= 1;
742  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  while (x--)
747  has_keyframe[n++] = flag;
748  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  if (has_keyframe[0]) {
764  av_log(s, AV_LOG_ERROR, "keyframe before first syncpoint in index\n");
765  goto fail;
766  }
767  av_assert0(n <= syncpoint_count + 1);
768  for (; j < n && j < syncpoint_count; j++) {
769  if (has_keyframe[j]) {
770  uint64_t B, A = ffio_read_varlen(bc);
771  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  B = 0;
777  av_add_index_entry(s->streams[i], 16 * syncpoints[j - 1],
778  last_pts + A, 0, 0, AVINDEX_KEYFRAME);
779  last_pts += A + B;
780  }
781  }
782  }
783  }
784 
785  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  ret = 0;
790 
791 fail:
792  av_free(syncpoints);
793  av_free(has_keyframe);
794  return ret;
795 }
796 
798 {
799  NUTContext *nut = s->priv_data;
800  int i;
801 
802  av_freep(&nut->time_base);
803  av_freep(&nut->stream);
804  ff_nut_free_sp(nut);
805  for (i = 1; i < nut->header_count; i++)
806  av_freep(&nut->header[i]);
807 
808  return 0;
809 }
810 
812 {
813  NUTContext *nut = s->priv_data;
814  AVIOContext *bc = s->pb;
815  int64_t pos;
816  int initialized_stream_count, ret;
817 
818  nut->avf = s;
819 
820  /* main header */
821  pos = 0;
822  ret = 0;
823  do {
824  if (ret == AVERROR(ENOMEM))
825  return ret;
826 
827  pos = find_startcode(bc, MAIN_STARTCODE, pos) + 1;
828  if (pos < 0 + 1) {
829  av_log(s, AV_LOG_ERROR, "No main startcode found.\n");
830  return AVERROR_INVALIDDATA;
831  }
832  } while ((ret = decode_main_header(nut)) < 0);
833 
834  /* stream headers */
835  pos = 0;
836  for (initialized_stream_count = 0; initialized_stream_count < s->nb_streams;) {
838  if (pos < 0 + 1) {
839  av_log(s, AV_LOG_ERROR, "Not all stream headers found.\n");
840  return AVERROR_INVALIDDATA;
841  }
842  if (decode_stream_header(nut) >= 0)
843  initialized_stream_count++;
844  }
845 
846  /* info headers */
847  pos = 0;
848  for (;;) {
849  uint64_t startcode = find_any_startcode(bc, pos);
850  pos = avio_tell(bc);
851 
852  if (startcode == 0) {
853  av_log(s, AV_LOG_ERROR, "EOF before video frames\n");
854  return AVERROR_INVALIDDATA;
855  } else if (startcode == SYNCPOINT_STARTCODE) {
856  nut->next_startcode = startcode;
857  break;
858  } else if (startcode != INFO_STARTCODE) {
859  continue;
860  }
861 
862  decode_info_header(nut);
863  }
864 
866 
867  if (bc->seekable & AVIO_SEEKABLE_NORMAL) {
868  int64_t orig_pos = avio_tell(bc);
870  avio_seek(bc, orig_pos, SEEK_SET);
871  }
873 
875 
876  return 0;
877 }
878 
879 static int read_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int is_meta, int64_t maxpos)
880 {
881  int count = ffio_read_varlen(bc);
882  int skip_start = 0;
883  int skip_end = 0;
884  int channels = 0;
885  int64_t channel_layout = 0;
886  int sample_rate = 0;
887  int width = 0;
888  int height = 0;
889  int i, ret;
890 
891  for (i=0; i<count; i++) {
892  uint8_t name[256], str_value[256], type_str[256];
893  int value;
894  if (avio_tell(bc) >= maxpos)
895  return AVERROR_INVALIDDATA;
896  ret = get_str(bc, name, sizeof(name));
897  if (ret < 0) {
898  av_log(s, AV_LOG_ERROR, "get_str failed while reading sm data\n");
899  return ret;
900  }
901  value = get_s(bc);
902 
903  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  } else if (value == -2) {
911  uint8_t *dst = NULL;
912  int64_t v64, value_len;
913 
914  ret = get_str(bc, type_str, sizeof(type_str));
915  if (ret < 0) {
916  av_log(s, AV_LOG_ERROR, "get_str failed while reading sm data\n");
917  return ret;
918  }
919  value_len = ffio_read_varlen(bc);
920  if (value_len < 0 || value_len >= maxpos - avio_tell(bc))
921  return AVERROR_INVALIDDATA;
922  if (!strcmp(name, "Palette")) {
924  } else if (!strcmp(name, "Extradata")) {
926  } else if (sscanf(name, "CodecSpecificSide%"SCNd64"", &v64) == 1) {
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  if(!dst)
941  return AVERROR(ENOMEM);
942  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  if (channels || channel_layout || sample_rate || width || height) {
970  if (!dst)
971  return AVERROR(ENOMEM);
972  bytestream_put_le32(&dst,
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  if (skip_start || skip_end) {
990  if (!dst)
991  return AVERROR(ENOMEM);
992  AV_WL32(dst, skip_start);
993  AV_WL32(dst+4, skip_end);
994  }
995 
996  if (avio_tell(bc) >= maxpos)
997  return AVERROR_INVALIDDATA;
998 
999  return 0;
1000 }
1001 
1002 static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id,
1003  uint8_t *header_idx, int frame_code)
1004 {
1005  AVFormatContext *s = nut->avf;
1006  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  if (!(nut->flags & NUT_PIPE) &&
1012  avio_tell(bc) > nut->last_syncpoint_pos + nut->max_distance) {
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  flags = nut->frame_code[frame_code].flags;
1020  size_mul = nut->frame_code[frame_code].size_mul;
1021  size = nut->frame_code[frame_code].size_lsb;
1022  *stream_id = nut->frame_code[frame_code].stream_id;
1023  pts_delta = nut->frame_code[frame_code].pts_delta;
1024  reserved_count = nut->frame_code[frame_code].reserved_count;
1025  *header_idx = nut->frame_code[frame_code].header_idx;
1026 
1027  if (flags & FLAG_INVALID)
1028  return AVERROR_INVALIDDATA;
1029  if (flags & FLAG_CODED)
1030  flags ^= ffio_read_varlen(bc);
1031  if (flags & FLAG_STREAM_ID) {
1032  GET_V(*stream_id, tmp < s->nb_streams);
1033  }
1034  stc = &nut->stream[*stream_id];
1035  if (flags & FLAG_CODED_PTS) {
1036  int64_t coded_pts = ffio_read_varlen(bc);
1037  // FIXME check last_pts validity?
1038  if (coded_pts < (1LL << stc->msb_pts_shift)) {
1039  *pts = ff_lsb2full(stc, coded_pts);
1040  } else
1041  *pts = coded_pts - (1LL << stc->msb_pts_shift);
1042  } else
1043  *pts = stc->last_pts + pts_delta;
1044  if (flags & FLAG_SIZE_MSB)
1045  size += size_mul * ffio_read_varlen(bc);
1046  if (flags & FLAG_MATCH_TIME)
1047  get_s(bc);
1048  if (flags & FLAG_HEADER_IDX)
1049  *header_idx = ffio_read_varlen(bc);
1050  if (flags & FLAG_RESERVED)
1051  reserved_count = ffio_read_varlen(bc);
1052  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  if (*header_idx >= (unsigned)nut->header_count) {
1061  av_log(s, AV_LOG_ERROR, "header_idx invalid\n");
1062  return AVERROR_INVALIDDATA;
1063  }
1064  if (size > 4096)
1065  *header_idx = 0;
1066  size -= nut->header_len[*header_idx];
1067 
1068  if (flags & FLAG_CHECKSUM) {
1069  avio_rb32(bc); // FIXME check this
1070  } else if (!(nut->flags & NUT_PIPE) &&
1071  size > 2 * nut->max_distance ||
1072  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  stc->last_pts = *pts;
1078  stc->last_flags = flags;
1079 
1080  return size;
1081 fail:
1082  return ret;
1083 }
1084 
1085 static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code)
1086 {
1087  AVFormatContext *s = nut->avf;
1088  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  size = decode_frame_header(nut, &pts, &stream_id, &header_idx, frame_code);
1095  if (size < 0)
1096  return size;
1097 
1098  stc = &nut->stream[stream_id];
1099 
1100  if (stc->last_flags & FLAG_KEY)
1101  stc->skip_until_key_frame = 0;
1102 
1103  discard = s->streams[stream_id]->discard;
1104  last_IP_pts = ffstream(s->streams[stream_id])->last_IP_pts;
1105  if ((discard >= AVDISCARD_NONKEY && !(stc->last_flags & FLAG_KEY)) ||
1106  (discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE &&
1107  last_IP_pts > pts) ||
1108  discard >= AVDISCARD_ALL ||
1109  stc->skip_until_key_frame) {
1110  avio_skip(bc, size);
1111  return 1;
1112  }
1113 
1114  ret = av_new_packet(pkt, size + nut->header_len[header_idx]);
1115  if (ret < 0)
1116  return ret;
1117  if (nut->header[header_idx])
1118  memcpy(pkt->data, nut->header[header_idx], nut->header_len[header_idx]);
1119  pkt->pos = avio_tell(bc); // FIXME
1120  if (stc->last_flags & FLAG_SM_DATA) {
1121  int sm_size;
1122  if (read_sm_data(s, bc, pkt, 0, pkt->pos + size) < 0) {
1124  goto fail;
1125  }
1126  if (read_sm_data(s, bc, pkt, 1, pkt->pos + size) < 0) {
1128  goto fail;
1129  }
1130  sm_size = avio_tell(bc) - pkt->pos;
1131  size -= sm_size;
1132  }
1133 
1134  ret = avio_read(bc, pkt->data + nut->header_len[header_idx], size);
1135  if (ret != size) {
1136  if (ret < 0)
1137  goto fail;
1138  }
1139  av_shrink_packet(pkt, nut->header_len[header_idx] + ret);
1140 
1141  pkt->stream_index = stream_id;
1142  if (stc->last_flags & FLAG_KEY)
1144  pkt->pts = pts;
1145 
1146  return 0;
1147 fail:
1149  return ret;
1150 }
1151 
1153 {
1154  NUTContext *nut = s->priv_data;
1155  AVIOContext *bc = s->pb;
1156  int i, frame_code = 0, ret, skip;
1157  int64_t ts, back_ptr;
1158 
1159  for (;;) {
1160  int64_t pos = avio_tell(bc);
1161  uint64_t tmp = nut->next_startcode;
1162  nut->next_startcode = 0;
1163 
1164  if (tmp) {
1165  pos -= 8;
1166  } else {
1167  frame_code = avio_r8(bc);
1168  if (avio_feof(bc))
1169  return AVERROR_EOF;
1170  if (frame_code == 'N') {
1171  tmp = frame_code;
1172  for (i = 1; i < 8; i++)
1173  tmp = (tmp << 8) + avio_r8(bc);
1174  }
1175  }
1176  switch (tmp) {
1177  case MAIN_STARTCODE:
1178  case STREAM_STARTCODE:
1179  case INDEX_STARTCODE:
1180  skip = get_packetheader(nut, bc, 0, tmp);
1181  avio_skip(bc, skip);
1182  break;
1183  case INFO_STARTCODE:
1184  if (decode_info_header(nut) < 0)
1185  goto resync;
1186  break;
1187  case SYNCPOINT_STARTCODE:
1188  if (decode_syncpoint(nut, &ts, &back_ptr) < 0)
1189  goto resync;
1190  frame_code = avio_r8(bc);
1191  case 0:
1192  ret = decode_frame(nut, pkt, frame_code);
1193  if (ret == 0)
1194  return 0;
1195  else if (ret == 1) // OK but discard packet
1196  break;
1197  default:
1198 resync:
1199  av_log(s, AV_LOG_DEBUG, "syncing from %"PRId64"\n", pos);
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 {
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 static int read_seek(AVFormatContext *s, int stream_index,
1238  int64_t pts, int flags)
1239 {
1240  NUTContext *nut = s->priv_data;
1241  AVStream *st = s->streams[stream_index];
1242  FFStream *const sti = ffstream(st);
1243  Syncpoint dummy = { .ts = pts * av_q2d(st->time_base) * AV_TIME_BASE };
1244  Syncpoint nopts_sp = { .ts = AV_NOPTS_VALUE, .back_ptr = AV_NOPTS_VALUE };
1245  Syncpoint *sp, *next_node[2] = { &nopts_sp, &nopts_sp };
1246  int64_t pos, pos2, ts;
1247  int i;
1248 
1249  if (nut->flags & NUT_PIPE) {
1250  return AVERROR(ENOSYS);
1251  }
1252 
1253  if (sti->index_entries) {
1255  if (index < 0)
1257  if (index < 0)
1258  return -1;
1259 
1260  pos2 = sti->index_entries[index].pos;
1261  ts = sti->index_entries[index].timestamp;
1262  } else {
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,
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;
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;
1290  NULL);
1291 
1292  av_assert0(sp);
1293  pos2 = sp->back_ptr - 15;
1294  }
1295  av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos2);
1296  pos = find_startcode(s->pb, SYNCPOINT_STARTCODE, pos2);
1297  avio_seek(s->pb, pos, SEEK_SET);
1298  nut->last_syncpoint_pos = pos;
1299  av_log(s, AV_LOG_DEBUG, "SP: %"PRId64"\n", pos);
1300  if (pos2 > pos || pos2 + 15 < pos)
1301  av_log(s, AV_LOG_ERROR, "no syncpoint at backptr pos\n");
1302  for (i = 0; i < s->nb_streams; i++)
1303  nut->stream[i].skip_until_key_frame = 1;
1304 
1305  nut->last_resync_pos = 0;
1306 
1307  return 0;
1308 }
1309 
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,
1322  .read_seek = read_seek,
1323 };
avpriv_new_chapter
AVChapter * avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base, int64_t start, int64_t end, const char *title)
Add a new chapter.
Definition: demux_utils.c:42
ff_gen_search
int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, int64_t pos_min, int64_t pos_max, int64_t pos_limit, int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret, int64_t(*read_timestamp)(struct AVFormatContext *, int, int64_t *, int64_t))
Perform a binary search using read_timestamp().
Definition: seek.c:397
A
#define A(x)
Definition: vpx_arith.h:28
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:427
nut_read_close
static int nut_read_close(AVFormatContext *s)
Definition: nutdec.c:797
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
av_codec_get_id
enum AVCodecID av_codec_get_id(const struct AVCodecTag *const *tags, unsigned int tag)
Get the AVCodecID for the given codec tag tag.
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:69
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
ff_nut_audio_extra_tags
const AVCodecTag ff_nut_audio_extra_tags[]
Definition: nut.c:214
FrameCode::stream_id
uint8_t stream_id
Definition: nut.h:67
AVChapter::metadata
AVDictionary * metadata
Definition: avformat.h:1218
NUT_PIPE
#define NUT_PIPE
Definition: nut.h:114
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
decode_frame
static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code)
Definition: nutdec.c:1085
StreamContext::last_flags
int last_flags
Definition: nut.h:76
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
NUTContext::time_base_count
unsigned int time_base_count
Definition: nut.h:103
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:424
NUT_MAX_VERSION
#define NUT_MAX_VERSION
Definition: nut.h:39
NUTContext::minor_version
int minor_version
Definition: nut.h:117
FFStream::last_IP_pts
int64_t last_IP_pts
Definition: internal.h:377
ffformatcontext
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition: internal.h:188
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
NUTContext::max_distance
unsigned int max_distance
Definition: nut.h:102
AV_PKT_DATA_NEW_EXTRADATA
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition: packet.h:56
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
nut_read_packet
static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: nutdec.c:1152
ff_find_last_ts
int ff_find_last_ts(AVFormatContext *s, int stream_index, int64_t *ts, int64_t *pos, int64_t(*read_timestamp)(struct AVFormatContext *, int, int64_t *, int64_t))
Definition: seek.c:359
ff_nut_data_tags
const AVCodecTag ff_nut_data_tags[]
Definition: nut.c:39
SYNCPOINT_STARTCODE
#define SYNCPOINT_STARTCODE
Definition: nut.h:31
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:264
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:207
FLAG_RESERVED
@ FLAG_RESERVED
Definition: nut.h:50
STREAM_STARTCODE
#define STREAM_STARTCODE
Definition: nut.h:30
av_be2ne64
#define av_be2ne64(x)
Definition: bswap.h:96
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1323
AVPacket::data
uint8_t * data
Definition: packet.h:524
ff_nut_dispositions
const Dispositions ff_nut_dispositions[]
Definition: nut.c:327
NUTContext::last_syncpoint_pos
int64_t last_syncpoint_pos
Definition: nut.h:104
NUTContext::header_len
uint8_t header_len[128]
Definition: nut.h:97
AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
@ AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
Definition: packet.h:601
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
ff_codec_wav_tags
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:518
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:59
find_any_startcode
static uint64_t find_any_startcode(AVIOContext *bc, int64_t pos)
Definition: nutdec.c:111
StreamContext::decode_delay
int decode_delay
Definition: nut.h:83
mathematics.h
ff_nut_reset_ts
void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val)
Definition: nut.c:258
AVDictionary
Definition: dict.c:34
FrameCode::size_lsb
uint16_t size_lsb
Definition: nut.h:69
AVProbeData::buf_size
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:454
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
nut_probe
static int nut_probe(const AVProbeData *p)
Definition: nutdec.c:154
Syncpoint
Definition: nut.h:58
read_sm_data
static int read_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int is_meta, int64_t maxpos)
Definition: nutdec.c:879
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:313
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:323
get_fourcc
static uint64_t get_fourcc(AVIOContext *bc)
Definition: nutdec.c:77
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:579
sample_rate
sample_rate
Definition: ffmpeg_filter.c:424
ffio_get_checksum
unsigned long ffio_get_checksum(AVIOContext *s)
Definition: aviobuf.c:583
AV_WB64
#define AV_WB64(p, v)
Definition: intreadwrite.h:431
NUTContext::last_resync_pos
int64_t last_resync_pos
Definition: nut.h:105
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
AVINDEX_KEYFRAME
#define AVINDEX_KEYFRAME
Definition: avformat.h:610
ff_nut_demuxer
const FFInputFormat ff_nut_demuxer
Definition: nutdec.c:1310
av_gcd
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
Definition: mathematics.c:37
ff_get_extradata
int ff_get_extradata(void *logctx, AVCodecParameters *par, AVIOContext *pb, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0 and f...
Definition: demux_utils.c:335
ff_nut_sp_pos_cmp
int ff_nut_sp_pos_cmp(const void *a, const void *b)
Definition: nut.c:276
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:463
ff_nut_free_sp
void ff_nut_free_sp(NUTContext *nut)
Definition: nut.c:319
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: avformat.c:853
get_s
static int64_t get_s(AVIOContext *bc)
Definition: nutdec.c:67
AV_PKT_DATA_PALETTE
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
Definition: packet.h:47
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:417
AVFMT_SEEK_TO_PTS
#define AVFMT_SEEK_TO_PTS
Seeking is based on PTS.
Definition: avformat.h:503
fail
#define fail()
Definition: checkasm.h:179
av_shrink_packet
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition: packet.c:113
av_add_index_entry
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
Definition: seek.c:121
dummy
int dummy
Definition: motion.c:66
read_close
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:143
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:494
NUTContext::avf
AVFormatContext * avf
Definition: nut.h:93
AVChapter
Definition: avformat.h:1214
AVFMT_DURATION_FROM_PTS
@ AVFMT_DURATION_FROM_PTS
Duration accurately estimated from PTSes.
Definition: avformat.h:1236
skip_reserved
static int skip_reserved(AVIOContext *bc, int64_t pos)
Definition: nutdec.c:178
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
pts
static int64_t pts
Definition: transcode_aac.c:644
NUTContext::header
const uint8_t * header[128]
Definition: nut.h:98
NUT_MAX_STREAMS
#define NUT_MAX_STREAMS
Definition: nutdec.c:38
avio_rl16
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:714
Syncpoint::ts
int64_t ts
Definition: nut.h:62
AVRational::num
int num
Numerator.
Definition: rational.h:59
NUTContext::header_count
int header_count
Definition: nut.h:106
avassert.h
avio_rb32
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:761
AV_PKT_DATA_PARAM_CHANGE
@ AV_PKT_DATA_PARAM_CHANGE
An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
Definition: packet.h:73
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
NUTContext
Definition: nut.h:91
AVCodecTag
Definition: internal.h:42
duration
int64_t duration
Definition: movenc.c:65
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_read_callback.c:42
AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
@ AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
Definition: packet.h:602
width
#define width
intreadwrite.h
ff_nut_metadata_conv
const AVMetadataConv ff_nut_metadata_conv[]
Definition: nut.c:337
s
#define s(width, name)
Definition: cbs_vp9.c:198
nut.h
av_new_packet
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: packet.c:98
FrameCode::reserved_count
uint8_t reserved_count
Definition: nut.h:71
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:553
get_str
static int get_str(AVIOContext *bc, char *string, unsigned int maxlen)
Definition: nutdec.c:43
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:453
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:134
NUTContext::time_base
AVRational * time_base
Definition: nut.h:107
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
find_startcode
static int64_t find_startcode(AVIOContext *bc, uint64_t code, int64_t pos)
Find the given startcode.
Definition: nutdec.c:142
AVIndexEntry::timestamp
int64_t timestamp
Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are...
Definition: avformat.h:604
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
B
#define B
Definition: huffyuv.h:42
nut_read_timestamp
static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos_arg, int64_t pos_limit)
Definition: nutdec.c:1210
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
FFFormatContext::data_offset
int64_t data_offset
offset of the first packet
Definition: internal.h:101
StreamContext::last_pts
int64_t last_pts
Definition: nut.h:78
channels
channels
Definition: aptx.h:31
nb_streams
static int nb_streams
Definition: ffprobe.c:384
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
FrameCode::size_mul
uint16_t size_mul
Definition: nut.h:68
FLAG_INVALID
@ FLAG_INVALID
Definition: nut.h:55
AVDISCARD_BIDIR
@ AVDISCARD_BIDIR
discard all bidirectional frames
Definition: defs.h:216
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:73
FF_INFMT_FLAG_INIT_CLEANUP
#define FF_INFMT_FLAG_INIT_CLEANUP
For an FFInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
Definition: demux.h:35
GET_V
#define GET_V(dst, check)
Definition: nutdec.c:167
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:219
AVFormatContext
Format I/O context.
Definition: avformat.h:1255
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:766
AVSEEK_FLAG_BACKWARD
#define AVSEEK_FLAG_BACKWARD
Definition: avformat.h:2445
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:550
Dispositions::flag
int flag
Definition: nut.h:130
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:782
NULL
#define NULL
Definition: coverity.c:32
NUT_BROADCAST
#define NUT_BROADCAST
Definition: nut.h:113
isom.h
ff_nut_sp_pts_cmp
int ff_nut_sp_pts_cmp(const void *a, const void *b)
Definition: nut.c:282
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
avio_rb64
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:908
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:451
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:823
read_seek
static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
Definition: nutdec.c:1237
ff_nut_video_tags
const AVCodecTag ff_nut_video_tags[]
Definition: nut.c:44
ff_codec_movvideo_tags
const AVCodecTag ff_codec_movvideo_tags[]
Definition: isom_tags.c:29
FLAG_MATCH_TIME
@ FLAG_MATCH_TIME
Definition: nut.h:53
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:180
AVSTREAM_EVENT_FLAG_METADATA_UPDATED
#define AVSTREAM_EVENT_FLAG_METADATA_UPDATED
Definition: avformat.h:893
index
int index
Definition: gxfenc.c:90
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:184
FLAG_CODED
@ FLAG_CODED
Definition: nut.h:54
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:73
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1311
StreamContext
Definition: transcode.c:54
decode_main_header
static int decode_main_header(NUTContext *nut)
Definition: nutdec.c:194
StreamContext::time_base_id
int time_base_id
Definition: nut.h:79
FLAG_SIZE_MSB
@ FLAG_SIZE_MSB
Definition: nut.h:48
avio_rl32
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:730
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: defs.h:218
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
FrameCode::pts_delta
int16_t pts_delta
Definition: nut.h:70
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
ff_codec_get_id
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:146
AVIOContext::seekable
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:261
FFStream
Definition: internal.h:193
sp
#define sp
Definition: regdef.h:63
NUTContext::flags
int flags
Definition: nut.h:115
ff_nut_audio_tags
const AVCodecTag ff_nut_audio_tags[]
Definition: nut.c:224
size
int size
Definition: twinvq_data.h:10344
NUTContext::stream
StreamContext * stream
Definition: nut.h:100
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
AVStream::event_flags
int event_flags
Flags indicating events happening on the stream, a combination of AVSTREAM_EVENT_FLAG_*.
Definition: avformat.h:886
FrameCode::flags
uint16_t flags
Definition: nut.h:66
ffio_init_checksum
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
Definition: aviobuf.c:591
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:821
FFInputFormat::p
AVInputFormat p
The public AVInputFormat.
Definition: demux.h:41
tree.h
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:603
height
#define height
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:530
ffio_read_varlen
uint64_t ffio_read_varlen(AVIOContext *bc)
Definition: aviobuf.c:916
NUTContext::version
int version
Definition: nut.h:116
StreamContext::msb_pts_shift
int msb_pts_shift
Definition: nut.h:81
ff_crc04C11DB7_update
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:565
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
filesize
static int64_t filesize(AVIOContext *pb)
Definition: ffmpeg_mux.c:51
flag
#define flag(name)
Definition: cbs_av1.c:466
ff_nut_add_sp
int ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts)
Definition: nut.c:288
NUTContext::syncpoints
struct AVTreeNode * syncpoints
Definition: nut.h:108
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:517
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
avio_internal.h
ff_lsb2full
int64_t ff_lsb2full(StreamContext *stream, int64_t lsb)
Definition: nut.c:269
NUTContext::next_startcode
uint64_t next_startcode
Definition: nut.h:99
find_and_decode_index
static int find_and_decode_index(NUTContext *nut)
Definition: nutdec.c:683
AVCodecParameters::height
int height
Definition: codec_par.h:135
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
resync
static int resync(AVFormatContext *s)
Definition: flvdec.c:1053
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
StreamContext::skip_until_key_frame
int skip_until_key_frame
Definition: nut.h:77
get_packetheader
static int get_packetheader(NUTContext *nut, AVIOContext *bc, int calculate_checksum, uint64_t startcode)
Definition: nutdec.c:91
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
demux.h
len
int len
Definition: vorbis_enc_data.h:426
last_pts
static int64_t last_pts
Definition: decode_filter_video.c:53
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
NUTContext::frame_code
FrameCode frame_code[256]
Definition: nut.h:96
FLAG_SM_DATA
@ FLAG_SM_DATA
Definition: nut.h:51
decode_frame_header
static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id, uint8_t *header_idx, int frame_code)
Definition: nutdec.c:1002
AVStream::disposition
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition: avformat.h:812
AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL
@ AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL
Data found in BlockAdditional element of matroska container.
Definition: packet.h:192
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:743
bswap.h
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:231
FLAG_STREAM_ID
@ FLAG_STREAM_ID
Definition: nut.h:47
decode_syncpoint
static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
Definition: nutdec.c:627
pos
unsigned int pos
Definition: spdifenc.c:414
dict.h
FrameCode::header_idx
uint8_t header_idx
Definition: nut.h:72
set_disposition_bits
static void set_disposition_bits(AVFormatContext *avf, char *value, int stream_id)
Definition: nutdec.c:489
U
#define U(x)
Definition: vpx_arith.h:37
FLAG_CHECKSUM
@ FLAG_CHECKSUM
Definition: nut.h:49
FLAG_KEY
@ FLAG_KEY
Definition: nut.h:44
state
static struct @399 state
ff_codec_bmp_tags
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:36
ff_nut_codec_tags
const AVCodecTag *const ff_nut_codec_tags[]
Definition: nut.c:253
FLAG_HEADER_IDX
@ FLAG_HEADER_IDX
Definition: nut.h:52
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:41
av_packet_new_side_data
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
Definition: packet.c:231
AVRational::den
int den
Denominator.
Definition: rational.h:60
nut_read_header
static int nut_read_header(AVFormatContext *s)
Definition: nutdec.c:811
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:612
AVStream::r_frame_rate
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:909
AV_PKT_DATA_SKIP_SAMPLES
@ AV_PKT_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
Definition: packet.h:157
AVIndexEntry::pos
int64_t pos
Definition: avformat.h:603
AVIOContext::eof_reached
int eof_reached
true if was unable to read due to error or eof
Definition: avio.h:238
AVPacket::stream_index
int stream_index
Definition: packet.h:526
av_tree_find
void * av_tree_find(const AVTreeNode *t, void *key, int(*cmp)(const void *key, const void *b), void *next[2])
Definition: tree.c:39
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:318
FFStream::index_entries
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: internal.h:249
NUT_MIN_VERSION
#define NUT_MIN_VERSION
Definition: nut.h:41
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
read_probe
static int read_probe(const AVProbeData *p)
Definition: cdg.c:30
mem.h
ff_nut_subtitle_tags
const AVCodecTag ff_nut_subtitle_tags[]
Definition: nut.c:29
AVCodecParameters::video_delay
int video_delay
Video only.
Definition: codec_par.h:175
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
FLAG_CODED_PTS
@ FLAG_CODED_PTS
Definition: nut.h:46
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
decode_stream_header
static int decode_stream_header(NUTContext *nut)
Definition: nutdec.c:380
AVPacket
This structure stores compressed data.
Definition: packet.h:501
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:88
riff.h
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:544
FFInputFormat
Definition: demux.h:37
avio_rl64
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:738
INDEX_STARTCODE
#define INDEX_STARTCODE
Definition: nut.h:32
bytestream.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
avstring.h
StreamContext::time_base
AVRational time_base
Definition: signature.h:103
find_duration
static int64_t find_duration(NUTContext *nut, int64_t filesize)
Definition: nutdec.c:671
INFO_STARTCODE
#define INFO_STARTCODE
Definition: nut.h:33
MAIN_STARTCODE
#define MAIN_STARTCODE
Definition: nut.h:29
StreamContext::max_pts_distance
int max_pts_distance
Definition: nut.h:82
skip
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
Definition: bitstream_template.h:375
AVFMT_EVENT_FLAG_METADATA_UPDATED
#define AVFMT_EVENT_FLAG_METADATA_UPDATED
Definition: avformat.h:1632
decode_info_header
static int decode_info_header(NUTContext *nut)
Definition: nutdec.c:504
ff_metadata_conv_ctx
void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition: metadata.c:59
av_index_search_timestamp
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
Definition: seek.c:244
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:346