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