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  end = length + avio_tell(bc);
204 
205  nut->version = ffio_read_varlen(bc);
206  if (nut->version < NUT_MIN_VERSION ||
207  nut->version > NUT_MAX_VERSION) {
208  av_log(s, AV_LOG_ERROR, "Version %d not supported.\n",
209  nut->version);
210  return AVERROR(ENOSYS);
211  }
212  if (nut->version > 3)
213  nut->minor_version = ffio_read_varlen(bc);
214 
215  GET_V(stream_count, tmp > 0 && tmp <= NUT_MAX_STREAMS);
216 
217  nut->max_distance = ffio_read_varlen(bc);
218  if (nut->max_distance > 65536) {
219  av_log(s, AV_LOG_DEBUG, "max_distance %d\n", nut->max_distance);
220  nut->max_distance = 65536;
221  }
222 
223  GET_V(nut->time_base_count, tmp > 0 && tmp < INT_MAX / sizeof(AVRational) && tmp < length/2);
224  nut->time_base = av_malloc_array(nut->time_base_count, sizeof(AVRational));
225  if (!nut->time_base)
226  return AVERROR(ENOMEM);
227 
228  for (i = 0; i < nut->time_base_count; i++) {
229  GET_V(nut->time_base[i].num, tmp > 0 && tmp < (1ULL << 31));
230  GET_V(nut->time_base[i].den, tmp > 0 && tmp < (1ULL << 31));
231  if (av_gcd(nut->time_base[i].num, nut->time_base[i].den) != 1) {
232  av_log(s, AV_LOG_ERROR, "invalid time base %d/%d\n",
233  nut->time_base[i].num,
234  nut->time_base[i].den);
236  goto fail;
237  }
238  }
239  tmp_pts = 0;
240  tmp_mul = 1;
241  tmp_stream = 0;
242  tmp_head_idx = 0;
243  for (i = 0; i < 256;) {
244  int tmp_flags = ffio_read_varlen(bc);
245  int tmp_fields = ffio_read_varlen(bc);
246 
247  if (tmp_fields > 0)
248  tmp_pts = get_s(bc);
249  if (tmp_fields > 1)
250  tmp_mul = ffio_read_varlen(bc);
251  if (tmp_fields > 2)
252  tmp_stream = ffio_read_varlen(bc);
253  if (tmp_fields > 3)
254  tmp_size = ffio_read_varlen(bc);
255  else
256  tmp_size = 0;
257  if (tmp_fields > 4)
258  tmp_res = ffio_read_varlen(bc);
259  else
260  tmp_res = 0;
261  if (tmp_fields > 5)
262  count = ffio_read_varlen(bc);
263  else
264  count = tmp_mul - (unsigned)tmp_size;
265  if (tmp_fields > 6)
266  get_s(bc);
267  if (tmp_fields > 7)
268  tmp_head_idx = ffio_read_varlen(bc);
269 
270  while (tmp_fields-- > 8) {
271  if (bc->eof_reached) {
272  av_log(s, AV_LOG_ERROR, "reached EOF while decoding main header\n");
274  goto fail;
275  }
276  ffio_read_varlen(bc);
277  }
278 
279  if (count <= 0 || count > 256 - (i <= 'N') - i) {
280  av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i);
282  goto fail;
283  }
284  if (tmp_stream >= stream_count) {
285  av_log(s, AV_LOG_ERROR, "illegal stream number %d >= %d\n",
286  tmp_stream, stream_count);
288  goto fail;
289  }
290  if (tmp_size < 0 || tmp_size > INT_MAX - count) {
291  av_log(s, AV_LOG_ERROR, "illegal size\n");
293  goto fail;
294  }
295 
296  for (j = 0; j < count; j++, i++) {
297  if (i == 'N') {
298  nut->frame_code[i].flags = FLAG_INVALID;
299  j--;
300  continue;
301  }
302  nut->frame_code[i].flags = tmp_flags;
303  nut->frame_code[i].pts_delta = tmp_pts;
304  nut->frame_code[i].stream_id = tmp_stream;
305  nut->frame_code[i].size_mul = tmp_mul;
306  nut->frame_code[i].size_lsb = tmp_size + j;
307  nut->frame_code[i].reserved_count = tmp_res;
308  nut->frame_code[i].header_idx = tmp_head_idx;
309  }
310  }
311  av_assert0(nut->frame_code['N'].flags == FLAG_INVALID);
312 
313  if (end > avio_tell(bc) + 4) {
314  int rem = 1024;
315  GET_V(nut->header_count, tmp < 128U);
316  nut->header_count++;
317  for (i = 1; i < nut->header_count; i++) {
318  uint8_t *hdr;
319  GET_V(nut->header_len[i], tmp > 0 && tmp < 256);
320  if (rem < nut->header_len[i]) {
322  "invalid elision header %d : %d > %d\n",
323  i, nut->header_len[i], rem);
325  goto fail;
326  }
327  rem -= nut->header_len[i];
328  hdr = av_malloc(nut->header_len[i]);
329  if (!hdr) {
330  ret = AVERROR(ENOMEM);
331  goto fail;
332  }
333  avio_read(bc, hdr, nut->header_len[i]);
334  nut->header[i] = hdr;
335  }
336  av_assert0(nut->header_len[0] == 0);
337  }
338 
339  // flags had been effectively introduced in version 4
340  if (nut->version > 3 && end > avio_tell(bc) + 4) {
341  nut->flags = ffio_read_varlen(bc);
342  }
343 
344  if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
345  av_log(s, AV_LOG_ERROR, "main header checksum mismatch\n");
347  goto fail;
348  }
349 
350  nut->stream = av_calloc(stream_count, sizeof(StreamContext));
351  if (!nut->stream) {
352  ret = AVERROR(ENOMEM);
353  goto fail;
354  }
355  for (i = 0; i < stream_count; i++) {
356  if (!avformat_new_stream(s, NULL)) {
357  ret = AVERROR(ENOMEM);
358  goto fail;
359  }
360  }
361 
362  return 0;
363 fail:
364  av_freep(&nut->time_base);
365  for (i = 1; i < nut->header_count; i++) {
366  av_freep(&nut->header[i]);
367  }
368  nut->header_count = 0;
369  return ret;
370 }
371 
373 {
374  AVFormatContext *s = nut->avf;
375  AVIOContext *bc = s->pb;
376  StreamContext *stc;
377  int class, stream_id, ret;
378  uint64_t tmp, end;
379  AVStream *st = NULL;
380 
381  end = get_packetheader(nut, bc, 1, STREAM_STARTCODE);
382  end += avio_tell(bc);
383 
384  GET_V(stream_id, tmp < s->nb_streams && !nut->stream[tmp].time_base);
385  stc = &nut->stream[stream_id];
386  st = s->streams[stream_id];
387  if (!st)
388  return AVERROR(ENOMEM);
389 
390  class = ffio_read_varlen(bc);
391  tmp = get_fourcc(bc);
392  st->codecpar->codec_tag = tmp;
393  switch (class) {
394  case 0:
396  st->codecpar->codec_id = av_codec_get_id((const AVCodecTag * const []) {
400  0
401  },
402  tmp);
403  break;
404  case 1:
406  st->codecpar->codec_id = av_codec_get_id((const AVCodecTag * const []) {
410  0
411  },
412  tmp);
413  break;
414  case 2:
417  break;
418  case 3:
421  break;
422  default:
423  av_log(s, AV_LOG_ERROR, "unknown stream class (%d)\n", class);
424  return AVERROR(ENOSYS);
425  }
426  if (class < 3 && st->codecpar->codec_id == AV_CODEC_ID_NONE)
428  "Unknown codec tag '0x%04x' for stream number %d\n",
429  (unsigned int) tmp, stream_id);
430 
431  GET_V(stc->time_base_id, tmp < nut->time_base_count);
432  GET_V(stc->msb_pts_shift, tmp < 16);
434  GET_V(stc->decode_delay, tmp < 1000); // sanity limit, raise this if Moore's law is true
435  st->codecpar->video_delay = stc->decode_delay;
436  ffio_read_varlen(bc); // stream flags
437 
438  GET_V(st->codecpar->extradata_size, tmp < (1 << 30));
439  if (st->codecpar->extradata_size) {
440  ret = ff_get_extradata(s, st->codecpar, bc,
441  st->codecpar->extradata_size);
442  if (ret < 0)
443  return ret;
444  }
445 
446  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
447  GET_V(st->codecpar->width, tmp > 0);
448  GET_V(st->codecpar->height, tmp > 0);
451  if ((!st->sample_aspect_ratio.num) != (!st->sample_aspect_ratio.den)) {
452  av_log(s, AV_LOG_ERROR, "invalid aspect ratio %d/%d\n",
455  goto fail;
456  }
457  ffio_read_varlen(bc); /* csp type */
458  } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
459  GET_V(st->codecpar->sample_rate, tmp > 0);
460  ffio_read_varlen(bc); // samplerate_den
462  }
463  if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
465  "stream header %d checksum mismatch\n", stream_id);
467  goto fail;
468  }
469  stc->time_base = &nut->time_base[stc->time_base_id];
470  avpriv_set_pts_info(s->streams[stream_id], 63, stc->time_base->num,
471  stc->time_base->den);
472  return 0;
473 fail:
474  if (st && st->codecpar) {
475  av_freep(&st->codecpar->extradata);
476  st->codecpar->extradata_size = 0;
477  }
478  return ret;
479 }
480 
482  int stream_id)
483 {
484  int flag = 0, i;
485 
486  for (i = 0; ff_nut_dispositions[i].flag; ++i)
487  if (!strcmp(ff_nut_dispositions[i].str, value))
489  if (!flag)
490  av_log(avf, AV_LOG_INFO, "unknown disposition type '%s'\n", value);
491  for (i = 0; i < avf->nb_streams; ++i)
492  if (stream_id == i || stream_id == -1)
493  avf->streams[i]->disposition |= flag;
494 }
495 
497 {
498  AVFormatContext *s = nut->avf;
499  AVIOContext *bc = s->pb;
500  uint64_t tmp, chapter_start, chapter_len;
501  unsigned int stream_id_plus1, count;
502  int i, ret = 0;
503  int64_t chapter_id, value, end;
504  char name[256], str_value[1024], type_str[256];
505  const char *type;
506  int *event_flags = NULL;
507  AVChapter *chapter = NULL;
508  AVStream *st = NULL;
509  AVDictionary **metadata = NULL;
510  int metadata_flag = 0;
511 
512  end = get_packetheader(nut, bc, 1, INFO_STARTCODE);
513  end += avio_tell(bc);
514 
515  GET_V(stream_id_plus1, tmp <= s->nb_streams);
516  chapter_id = get_s(bc);
517  chapter_start = ffio_read_varlen(bc);
518  chapter_len = ffio_read_varlen(bc);
519  count = ffio_read_varlen(bc);
520 
521  if (chapter_id && !stream_id_plus1) {
522  int64_t start = chapter_start / nut->time_base_count;
523  chapter = avpriv_new_chapter(s, chapter_id,
524  nut->time_base[chapter_start %
525  nut->time_base_count],
526  start, start + chapter_len, NULL);
527  if (!chapter) {
528  av_log(s, AV_LOG_ERROR, "Could not create chapter.\n");
529  return AVERROR(ENOMEM);
530  }
531  metadata = &chapter->metadata;
532  } else if (stream_id_plus1) {
533  st = s->streams[stream_id_plus1 - 1];
534  metadata = &st->metadata;
535  event_flags = &st->event_flags;
536  metadata_flag = AVSTREAM_EVENT_FLAG_METADATA_UPDATED;
537  } else {
538  metadata = &s->metadata;
539  event_flags = &s->event_flags;
540  metadata_flag = AVFMT_EVENT_FLAG_METADATA_UPDATED;
541  }
542 
543  for (i = 0; i < count; i++) {
544  ret = get_str(bc, name, sizeof(name));
545  if (ret < 0) {
546  av_log(s, AV_LOG_ERROR, "get_str failed while decoding info header\n");
547  return ret;
548  }
549  value = get_s(bc);
550  str_value[0] = 0;
551 
552  if (value == -1) {
553  type = "UTF-8";
554  ret = get_str(bc, str_value, sizeof(str_value));
555  } else if (value == -2) {
556  ret = get_str(bc, type_str, sizeof(type_str));
557  if (ret < 0) {
558  av_log(s, AV_LOG_ERROR, "get_str failed while decoding info header\n");
559  return ret;
560  }
561  type = type_str;
562  ret = get_str(bc, str_value, sizeof(str_value));
563  } else if (value == -3) {
564  type = "s";
565  value = get_s(bc);
566  } else if (value == -4) {
567  type = "t";
568  value = ffio_read_varlen(bc);
569  } else if (value < -4) {
570  type = "r";
571  get_s(bc);
572  } else {
573  type = "v";
574  }
575 
576  if (ret < 0) {
577  av_log(s, AV_LOG_ERROR, "get_str failed while decoding info header\n");
578  return ret;
579  }
580 
581  if (stream_id_plus1 > s->nb_streams) {
583  "invalid stream id %d for info packet\n",
584  stream_id_plus1);
585  continue;
586  }
587 
588  if (!strcmp(type, "UTF-8")) {
589  if (chapter_id == 0 && !strcmp(name, "Disposition")) {
590  set_disposition_bits(s, str_value, stream_id_plus1 - 1);
591  continue;
592  }
593 
594  if (stream_id_plus1 && !strcmp(name, "r_frame_rate")) {
595  sscanf(str_value, "%d/%d", &st->r_frame_rate.num, &st->r_frame_rate.den);
596  if (st->r_frame_rate.num >= 1000LL*st->r_frame_rate.den ||
597  st->r_frame_rate.num < 0 || st->r_frame_rate.den < 0)
598  st->r_frame_rate.num = st->r_frame_rate.den = 0;
599  continue;
600  }
601 
602  if (metadata && av_strcasecmp(name, "Uses") &&
603  av_strcasecmp(name, "Depends") && av_strcasecmp(name, "Replaces")) {
604  if (event_flags)
605  *event_flags |= metadata_flag;
606  av_dict_set(metadata, name, str_value, 0);
607  }
608  }
609  }
610 
611  if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
612  av_log(s, AV_LOG_ERROR, "info header checksum mismatch\n");
613  return AVERROR_INVALIDDATA;
614  }
615 fail:
616  return FFMIN(ret, 0);
617 }
618 
619 static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
620 {
621  AVFormatContext *s = nut->avf;
622  AVIOContext *bc = s->pb;
623  int64_t end;
624  uint64_t tmp;
625  int ret;
626 
627  nut->last_syncpoint_pos = avio_tell(bc) - 8;
628 
629  end = get_packetheader(nut, bc, 1, SYNCPOINT_STARTCODE);
630  end += avio_tell(bc);
631 
632  tmp = ffio_read_varlen(bc);
633  *back_ptr = nut->last_syncpoint_pos - 16 * ffio_read_varlen(bc);
634  if (*back_ptr < 0)
635  return AVERROR_INVALIDDATA;
636 
637  ff_nut_reset_ts(nut, nut->time_base[tmp % nut->time_base_count],
638  tmp / nut->time_base_count);
639 
640  if (nut->flags & NUT_BROADCAST) {
641  tmp = ffio_read_varlen(bc);
642  av_log(s, AV_LOG_VERBOSE, "Syncpoint wallclock %"PRId64"\n",
644  nut->time_base[tmp % nut->time_base_count],
645  AV_TIME_BASE_Q));
646  }
647 
648  if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
649  av_log(s, AV_LOG_ERROR, "sync point checksum mismatch\n");
650  return AVERROR_INVALIDDATA;
651  }
652 
653  *ts = tmp / nut->time_base_count *
655 
656  if ((ret = ff_nut_add_sp(nut, nut->last_syncpoint_pos, *back_ptr, *ts)) < 0)
657  return ret;
658 
659  return 0;
660 }
661 
662 //FIXME calculate exactly, this is just a good approximation.
663 static int64_t find_duration(NUTContext *nut, int64_t filesize)
664 {
665  AVFormatContext *s = nut->avf;
666  int64_t duration = 0;
667 
669 
670  if(duration > 0)
671  s->duration_estimation_method = AVFMT_DURATION_FROM_PTS;
672  return duration;
673 }
674 
676 {
677  AVFormatContext *s = nut->avf;
678  AVIOContext *bc = s->pb;
679  uint64_t tmp, end;
680  int i, j, syncpoint_count;
681  int64_t filesize = avio_size(bc);
682  int64_t *syncpoints = NULL;
683  uint64_t max_pts;
684  int8_t *has_keyframe = NULL;
685  int ret = AVERROR_INVALIDDATA;
686 
687  if(filesize <= 0)
688  return -1;
689 
690  avio_seek(bc, filesize - 12, SEEK_SET);
691  avio_seek(bc, filesize - avio_rb64(bc), SEEK_SET);
692  if (avio_rb64(bc) != INDEX_STARTCODE) {
693  av_log(s, AV_LOG_WARNING, "no index at the end\n");
694 
695  if(s->duration<=0)
696  s->duration = find_duration(nut, filesize);
697  return ret;
698  }
699 
700  end = get_packetheader(nut, bc, 1, INDEX_STARTCODE);
701  end += avio_tell(bc);
702 
703  max_pts = ffio_read_varlen(bc);
704  s->duration = av_rescale_q(max_pts / nut->time_base_count,
705  nut->time_base[max_pts % nut->time_base_count],
707  s->duration_estimation_method = AVFMT_DURATION_FROM_PTS;
708 
709  GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
710  syncpoints = av_malloc_array(syncpoint_count, sizeof(int64_t));
711  has_keyframe = av_malloc_array(syncpoint_count + 1, sizeof(int8_t));
712  if (!syncpoints || !has_keyframe) {
713  ret = AVERROR(ENOMEM);
714  goto fail;
715  }
716  for (i = 0; i < syncpoint_count; i++) {
717  syncpoints[i] = ffio_read_varlen(bc);
718  if (syncpoints[i] <= 0)
719  goto fail;
720  if (i)
721  syncpoints[i] += syncpoints[i - 1];
722  }
723 
724  for (i = 0; i < s->nb_streams; i++) {
725  int64_t last_pts = -1;
726  for (j = 0; j < syncpoint_count;) {
727  uint64_t x = ffio_read_varlen(bc);
728  int type = x & 1;
729  int n = j;
730  x >>= 1;
731  if (type) {
732  int flag = x & 1;
733  x >>= 1;
734  if (n + x >= syncpoint_count + 1) {
735  av_log(s, AV_LOG_ERROR, "index overflow A %d + %"PRIu64" >= %d\n", n, x, syncpoint_count + 1);
736  goto fail;
737  }
738  while (x--)
739  has_keyframe[n++] = flag;
740  has_keyframe[n++] = !flag;
741  } else {
742  if (x <= 1) {
743  av_log(s, AV_LOG_ERROR, "index: x %"PRIu64" is invalid\n", x);
744  goto fail;
745  }
746  while (x != 1) {
747  if (n >= syncpoint_count + 1) {
748  av_log(s, AV_LOG_ERROR, "index overflow B\n");
749  goto fail;
750  }
751  has_keyframe[n++] = x & 1;
752  x >>= 1;
753  }
754  }
755  if (has_keyframe[0]) {
756  av_log(s, AV_LOG_ERROR, "keyframe before first syncpoint in index\n");
757  goto fail;
758  }
759  av_assert0(n <= syncpoint_count + 1);
760  for (; j < n && j < syncpoint_count; j++) {
761  if (has_keyframe[j]) {
762  uint64_t B, A = ffio_read_varlen(bc);
763  if (!A) {
764  A = ffio_read_varlen(bc);
765  B = ffio_read_varlen(bc);
766  // eor_pts[j][i] = last_pts + A + B
767  } else
768  B = 0;
769  av_add_index_entry(s->streams[i], 16 * syncpoints[j - 1],
770  last_pts + A, 0, 0, AVINDEX_KEYFRAME);
771  last_pts += A + B;
772  }
773  }
774  }
775  }
776 
777  if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
778  av_log(s, AV_LOG_ERROR, "index checksum mismatch\n");
779  goto fail;
780  }
781  ret = 0;
782 
783 fail:
784  av_free(syncpoints);
785  av_free(has_keyframe);
786  return ret;
787 }
788 
790 {
791  NUTContext *nut = s->priv_data;
792  int i;
793 
794  av_freep(&nut->time_base);
795  av_freep(&nut->stream);
796  ff_nut_free_sp(nut);
797  for (i = 1; i < nut->header_count; i++)
798  av_freep(&nut->header[i]);
799 
800  return 0;
801 }
802 
804 {
805  NUTContext *nut = s->priv_data;
806  AVIOContext *bc = s->pb;
807  int64_t pos;
808  int initialized_stream_count, ret;
809 
810  nut->avf = s;
811 
812  /* main header */
813  pos = 0;
814  ret = 0;
815  do {
816  if (ret == AVERROR(ENOMEM))
817  return ret;
818 
819  pos = find_startcode(bc, MAIN_STARTCODE, pos) + 1;
820  if (pos < 0 + 1) {
821  av_log(s, AV_LOG_ERROR, "No main startcode found.\n");
822  return AVERROR_INVALIDDATA;
823  }
824  } while ((ret = decode_main_header(nut)) < 0);
825 
826  /* stream headers */
827  pos = 0;
828  for (initialized_stream_count = 0; initialized_stream_count < s->nb_streams;) {
830  if (pos < 0 + 1) {
831  av_log(s, AV_LOG_ERROR, "Not all stream headers found.\n");
832  return AVERROR_INVALIDDATA;
833  }
834  if (decode_stream_header(nut) >= 0)
835  initialized_stream_count++;
836  }
837 
838  /* info headers */
839  pos = 0;
840  for (;;) {
841  uint64_t startcode = find_any_startcode(bc, pos);
842  pos = avio_tell(bc);
843 
844  if (startcode == 0) {
845  av_log(s, AV_LOG_ERROR, "EOF before video frames\n");
846  return AVERROR_INVALIDDATA;
847  } else if (startcode == SYNCPOINT_STARTCODE) {
848  nut->next_startcode = startcode;
849  break;
850  } else if (startcode != INFO_STARTCODE) {
851  continue;
852  }
853 
854  decode_info_header(nut);
855  }
856 
858 
859  if (bc->seekable & AVIO_SEEKABLE_NORMAL) {
860  int64_t orig_pos = avio_tell(bc);
862  avio_seek(bc, orig_pos, SEEK_SET);
863  }
865 
867 
868  return 0;
869 }
870 
871 static int read_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int is_meta, int64_t maxpos)
872 {
873  int count = ffio_read_varlen(bc);
874  int skip_start = 0;
875  int skip_end = 0;
876  int channels = 0;
877  int64_t channel_layout = 0;
878  int sample_rate = 0;
879  int width = 0;
880  int height = 0;
881  int i, ret;
882 
883  for (i=0; i<count; i++) {
884  uint8_t name[256], str_value[256], type_str[256];
885  int value;
886  if (avio_tell(bc) >= maxpos)
887  return AVERROR_INVALIDDATA;
888  ret = get_str(bc, name, sizeof(name));
889  if (ret < 0) {
890  av_log(s, AV_LOG_ERROR, "get_str failed while reading sm data\n");
891  return ret;
892  }
893  value = get_s(bc);
894 
895  if (value == -1) {
896  ret = get_str(bc, str_value, sizeof(str_value));
897  if (ret < 0) {
898  av_log(s, AV_LOG_ERROR, "get_str failed while reading sm data\n");
899  return ret;
900  }
901  av_log(s, AV_LOG_WARNING, "Unknown string %s / %s\n", name, str_value);
902  } else if (value == -2) {
903  uint8_t *dst = NULL;
904  int64_t v64, value_len;
905 
906  ret = get_str(bc, type_str, sizeof(type_str));
907  if (ret < 0) {
908  av_log(s, AV_LOG_ERROR, "get_str failed while reading sm data\n");
909  return ret;
910  }
911  value_len = ffio_read_varlen(bc);
912  if (value_len < 0 || value_len >= maxpos - avio_tell(bc))
913  return AVERROR_INVALIDDATA;
914  if (!strcmp(name, "Palette")) {
916  } else if (!strcmp(name, "Extradata")) {
918  } else if (sscanf(name, "CodecSpecificSide%"SCNd64"", &v64) == 1) {
920  if(!dst)
921  return AVERROR(ENOMEM);
922  AV_WB64(dst, v64);
923  dst += 8;
924  } else if (!strcmp(name, "ChannelLayout") && value_len == 8) {
925  channel_layout = avio_rl64(bc);
926  continue;
927  } else {
928  av_log(s, AV_LOG_WARNING, "Unknown data %s / %s\n", name, type_str);
929  avio_skip(bc, value_len);
930  continue;
931  }
932  if(!dst)
933  return AVERROR(ENOMEM);
934  avio_read(bc, dst, value_len);
935  } else if (value == -3) {
936  value = get_s(bc);
937  } else if (value == -4) {
938  value = ffio_read_varlen(bc);
939  } else if (value < -4) {
940  get_s(bc);
941  } else {
942  if (!strcmp(name, "SkipStart")) {
943  skip_start = value;
944  } else if (!strcmp(name, "SkipEnd")) {
945  skip_end = value;
946  } else if (!strcmp(name, "Channels")) {
947  channels = value;
948  } else if (!strcmp(name, "SampleRate")) {
949  sample_rate = value;
950  } else if (!strcmp(name, "Width")) {
951  width = value;
952  } else if (!strcmp(name, "Height")) {
953  height = value;
954  } else {
955  av_log(s, AV_LOG_WARNING, "Unknown integer %s\n", name);
956  }
957  }
958  }
959 
960  if (channels || channel_layout || sample_rate || width || height) {
962  if (!dst)
963  return AVERROR(ENOMEM);
964  bytestream_put_le32(&dst,
966  AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT*(!!channels) +
967  AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT*(!!channel_layout) +
968 #endif
971  );
972  if (channels)
973  bytestream_put_le32(&dst, channels);
974  if (channel_layout)
975  bytestream_put_le64(&dst, channel_layout);
976  if (sample_rate)
977  bytestream_put_le32(&dst, sample_rate);
978  if (width || height){
979  bytestream_put_le32(&dst, width);
980  bytestream_put_le32(&dst, height);
981  }
982  }
983 
984  if (skip_start || skip_end) {
986  if (!dst)
987  return AVERROR(ENOMEM);
988  AV_WL32(dst, skip_start);
989  AV_WL32(dst+4, skip_end);
990  }
991 
992  if (avio_tell(bc) >= maxpos)
993  return AVERROR_INVALIDDATA;
994 
995  return 0;
996 }
997 
998 static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id,
999  uint8_t *header_idx, int frame_code)
1000 {
1001  AVFormatContext *s = nut->avf;
1002  AVIOContext *bc = s->pb;
1003  StreamContext *stc;
1004  int size, flags, size_mul, pts_delta, i, reserved_count, ret;
1005  uint64_t tmp;
1006 
1007  if (!(nut->flags & NUT_PIPE) &&
1008  avio_tell(bc) > nut->last_syncpoint_pos + nut->max_distance) {
1010  "Last frame must have been damaged %"PRId64" > %"PRId64" + %d\n",
1011  avio_tell(bc), nut->last_syncpoint_pos, nut->max_distance);
1012  return AVERROR_INVALIDDATA;
1013  }
1014 
1015  flags = nut->frame_code[frame_code].flags;
1016  size_mul = nut->frame_code[frame_code].size_mul;
1017  size = nut->frame_code[frame_code].size_lsb;
1018  *stream_id = nut->frame_code[frame_code].stream_id;
1019  pts_delta = nut->frame_code[frame_code].pts_delta;
1020  reserved_count = nut->frame_code[frame_code].reserved_count;
1021  *header_idx = nut->frame_code[frame_code].header_idx;
1022 
1023  if (flags & FLAG_INVALID)
1024  return AVERROR_INVALIDDATA;
1025  if (flags & FLAG_CODED)
1026  flags ^= ffio_read_varlen(bc);
1027  if (flags & FLAG_STREAM_ID) {
1028  GET_V(*stream_id, tmp < s->nb_streams);
1029  }
1030  stc = &nut->stream[*stream_id];
1031  if (flags & FLAG_CODED_PTS) {
1032  int64_t coded_pts = ffio_read_varlen(bc);
1033  // FIXME check last_pts validity?
1034  if (coded_pts < (1LL << stc->msb_pts_shift)) {
1035  *pts = ff_lsb2full(stc, coded_pts);
1036  } else
1037  *pts = coded_pts - (1LL << stc->msb_pts_shift);
1038  } else
1039  *pts = stc->last_pts + pts_delta;
1040  if (flags & FLAG_SIZE_MSB)
1041  size += size_mul * ffio_read_varlen(bc);
1042  if (flags & FLAG_MATCH_TIME)
1043  get_s(bc);
1044  if (flags & FLAG_HEADER_IDX)
1045  *header_idx = ffio_read_varlen(bc);
1046  if (flags & FLAG_RESERVED)
1047  reserved_count = ffio_read_varlen(bc);
1048  for (i = 0; i < reserved_count; i++) {
1049  if (bc->eof_reached) {
1050  av_log(s, AV_LOG_ERROR, "reached EOF while decoding frame header\n");
1051  return AVERROR_INVALIDDATA;
1052  }
1053  ffio_read_varlen(bc);
1054  }
1055 
1056  if (*header_idx >= (unsigned)nut->header_count) {
1057  av_log(s, AV_LOG_ERROR, "header_idx invalid\n");
1058  return AVERROR_INVALIDDATA;
1059  }
1060  if (size > 4096)
1061  *header_idx = 0;
1062  size -= nut->header_len[*header_idx];
1063 
1064  if (flags & FLAG_CHECKSUM) {
1065  avio_rb32(bc); // FIXME check this
1066  } else if (!(nut->flags & NUT_PIPE) &&
1067  size > 2 * nut->max_distance ||
1068  FFABS(stc->last_pts - *pts) > stc->max_pts_distance) {
1069  av_log(s, AV_LOG_ERROR, "frame size > 2max_distance and no checksum\n");
1070  return AVERROR_INVALIDDATA;
1071  }
1072 
1073  stc->last_pts = *pts;
1074  stc->last_flags = flags;
1075 
1076  return size;
1077 fail:
1078  return ret;
1079 }
1080 
1081 static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code)
1082 {
1083  AVFormatContext *s = nut->avf;
1084  AVIOContext *bc = s->pb;
1085  int size, stream_id, discard, ret;
1086  int64_t pts, last_IP_pts;
1087  StreamContext *stc;
1088  uint8_t header_idx;
1089 
1090  size = decode_frame_header(nut, &pts, &stream_id, &header_idx, frame_code);
1091  if (size < 0)
1092  return size;
1093 
1094  stc = &nut->stream[stream_id];
1095 
1096  if (stc->last_flags & FLAG_KEY)
1097  stc->skip_until_key_frame = 0;
1098 
1099  discard = s->streams[stream_id]->discard;
1100  last_IP_pts = ffstream(s->streams[stream_id])->last_IP_pts;
1101  if ((discard >= AVDISCARD_NONKEY && !(stc->last_flags & FLAG_KEY)) ||
1102  (discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE &&
1103  last_IP_pts > pts) ||
1104  discard >= AVDISCARD_ALL ||
1105  stc->skip_until_key_frame) {
1106  avio_skip(bc, size);
1107  return 1;
1108  }
1109 
1110  ret = av_new_packet(pkt, size + nut->header_len[header_idx]);
1111  if (ret < 0)
1112  return ret;
1113  if (nut->header[header_idx])
1114  memcpy(pkt->data, nut->header[header_idx], nut->header_len[header_idx]);
1115  pkt->pos = avio_tell(bc); // FIXME
1116  if (stc->last_flags & FLAG_SM_DATA) {
1117  int sm_size;
1118  if (read_sm_data(s, bc, pkt, 0, pkt->pos + size) < 0) {
1120  goto fail;
1121  }
1122  if (read_sm_data(s, bc, pkt, 1, pkt->pos + size) < 0) {
1124  goto fail;
1125  }
1126  sm_size = avio_tell(bc) - pkt->pos;
1127  size -= sm_size;
1128  pkt->size -= sm_size;
1129  }
1130 
1131  ret = avio_read(bc, pkt->data + nut->header_len[header_idx], size);
1132  if (ret != size) {
1133  if (ret < 0)
1134  goto fail;
1135  }
1136  av_shrink_packet(pkt, nut->header_len[header_idx] + ret);
1137 
1138  pkt->stream_index = stream_id;
1139  if (stc->last_flags & FLAG_KEY)
1141  pkt->pts = pts;
1142 
1143  return 0;
1144 fail:
1146  return ret;
1147 }
1148 
1150 {
1151  NUTContext *nut = s->priv_data;
1152  AVIOContext *bc = s->pb;
1153  int i, frame_code = 0, ret, skip;
1154  int64_t ts, back_ptr;
1155 
1156  for (;;) {
1157  int64_t pos = avio_tell(bc);
1158  uint64_t tmp = nut->next_startcode;
1159  nut->next_startcode = 0;
1160 
1161  if (tmp) {
1162  pos -= 8;
1163  } else {
1164  frame_code = avio_r8(bc);
1165  if (avio_feof(bc))
1166  return AVERROR_EOF;
1167  if (frame_code == 'N') {
1168  tmp = frame_code;
1169  for (i = 1; i < 8; i++)
1170  tmp = (tmp << 8) + avio_r8(bc);
1171  }
1172  }
1173  switch (tmp) {
1174  case MAIN_STARTCODE:
1175  case STREAM_STARTCODE:
1176  case INDEX_STARTCODE:
1177  skip = get_packetheader(nut, bc, 0, tmp);
1178  avio_skip(bc, skip);
1179  break;
1180  case INFO_STARTCODE:
1181  if (decode_info_header(nut) < 0)
1182  goto resync;
1183  break;
1184  case SYNCPOINT_STARTCODE:
1185  if (decode_syncpoint(nut, &ts, &back_ptr) < 0)
1186  goto resync;
1187  frame_code = avio_r8(bc);
1188  case 0:
1189  ret = decode_frame(nut, pkt, frame_code);
1190  if (ret == 0)
1191  return 0;
1192  else if (ret == 1) // OK but discard packet
1193  break;
1194  default:
1195 resync:
1196  av_log(s, AV_LOG_DEBUG, "syncing from %"PRId64"\n", pos);
1198  nut->last_resync_pos = avio_tell(bc);
1199  if (tmp == 0)
1200  return AVERROR_INVALIDDATA;
1201  av_log(s, AV_LOG_DEBUG, "sync\n");
1202  nut->next_startcode = tmp;
1203  }
1204  }
1205 }
1206 
1207 static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index,
1208  int64_t *pos_arg, int64_t pos_limit)
1209 {
1210  NUTContext *nut = s->priv_data;
1211  AVIOContext *bc = s->pb;
1212  int64_t pos, pts, back_ptr;
1213  av_log(s, AV_LOG_DEBUG, "read_timestamp(X,%d,%"PRId64",%"PRId64")\n",
1214  stream_index, *pos_arg, pos_limit);
1215 
1216  pos = *pos_arg;
1217  do {
1219  if (pos < 1) {
1220  av_log(s, AV_LOG_ERROR, "read_timestamp failed.\n");
1221  return AV_NOPTS_VALUE;
1222  }
1223  } while (decode_syncpoint(nut, &pts, &back_ptr) < 0);
1224  *pos_arg = pos - 1;
1225  av_assert0(nut->last_syncpoint_pos == *pos_arg);
1226 
1227  av_log(s, AV_LOG_DEBUG, "return %"PRId64" %"PRId64"\n", pts, back_ptr);
1228  if (stream_index == -2)
1229  return back_ptr;
1230  av_assert0(stream_index == -1);
1231  return pts;
1232 }
1233 
1234 static int read_seek(AVFormatContext *s, int stream_index,
1235  int64_t pts, int flags)
1236 {
1237  NUTContext *nut = s->priv_data;
1238  AVStream *st = s->streams[stream_index];
1239  FFStream *const sti = ffstream(st);
1240  Syncpoint dummy = { .ts = pts * av_q2d(st->time_base) * AV_TIME_BASE };
1241  Syncpoint nopts_sp = { .ts = AV_NOPTS_VALUE, .back_ptr = AV_NOPTS_VALUE };
1242  Syncpoint *sp, *next_node[2] = { &nopts_sp, &nopts_sp };
1243  int64_t pos, pos2, ts;
1244  int i;
1245 
1246  if (nut->flags & NUT_PIPE) {
1247  return AVERROR(ENOSYS);
1248  }
1249 
1250  if (sti->index_entries) {
1252  if (index < 0)
1254  if (index < 0)
1255  return -1;
1256 
1257  pos2 = sti->index_entries[index].pos;
1258  ts = sti->index_entries[index].timestamp;
1259  } else {
1261  (void **) next_node);
1262  av_log(s, AV_LOG_DEBUG, "%"PRIu64"-%"PRIu64" %"PRId64"-%"PRId64"\n",
1263  next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
1264  next_node[1]->ts);
1265  pos = ff_gen_search(s, -1, dummy.ts, next_node[0]->pos,
1266  next_node[1]->pos, next_node[1]->pos,
1267  next_node[0]->ts, next_node[1]->ts,
1269  if (pos < 0)
1270  return pos;
1271 
1272  if (!(flags & AVSEEK_FLAG_BACKWARD)) {
1273  dummy.pos = pos + 16;
1274  next_node[1] = &nopts_sp;
1276  (void **) next_node);
1277  pos2 = ff_gen_search(s, -2, dummy.pos, next_node[0]->pos,
1278  next_node[1]->pos, next_node[1]->pos,
1279  next_node[0]->back_ptr, next_node[1]->back_ptr,
1280  flags, &ts, nut_read_timestamp);
1281  if (pos2 >= 0)
1282  pos = pos2;
1283  // FIXME dir but I think it does not matter
1284  }
1285  dummy.pos = pos;
1287  NULL);
1288 
1289  av_assert0(sp);
1290  pos2 = sp->back_ptr - 15;
1291  }
1292  av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos2);
1293  pos = find_startcode(s->pb, SYNCPOINT_STARTCODE, pos2);
1294  avio_seek(s->pb, pos, SEEK_SET);
1295  nut->last_syncpoint_pos = pos;
1296  av_log(s, AV_LOG_DEBUG, "SP: %"PRId64"\n", pos);
1297  if (pos2 > pos || pos2 + 15 < pos)
1298  av_log(s, AV_LOG_ERROR, "no syncpoint at backptr pos\n");
1299  for (i = 0; i < s->nb_streams; i++)
1300  nut->stream[i].skip_until_key_frame = 1;
1301 
1302  nut->last_resync_pos = 0;
1303 
1304  return 0;
1305 }
1306 
1308  .name = "nut",
1309  .long_name = NULL_IF_CONFIG_SMALL("NUT"),
1310  .flags = AVFMT_SEEK_TO_PTS,
1311  .priv_data_size = sizeof(NUTContext),
1312  .flags_internal = FF_FMT_INIT_CLEANUP,
1313  .read_probe = nut_probe,
1317  .read_seek = read_seek,
1318  .extensions = "nut",
1319  .codec_tag = ff_nut_codec_tags,
1320 };
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:789
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:1081
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:1149
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:871
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:1207
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:529
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:1234
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:1307
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:271
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:675
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:969
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:998
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:619
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:481
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:803
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:372
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:663
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:496
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