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 Libav.
7  *
8  * Libav 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  * Libav 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 Libav; 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/bswap.h"
25 #include "libavutil/dict.h"
26 #include "libavutil/mathematics.h"
27 #include "libavutil/tree.h"
28 #include "avio_internal.h"
29 #include "nut.h"
30 #include "riff.h"
31 
32 #undef NDEBUG
33 #include <assert.h>
34 
35 #define NUT_MAX_STREAMS 256 /* arbitrary sanity check value */
36 
37 static int get_str(AVIOContext *bc, char *string, unsigned int maxlen)
38 {
39  unsigned int len = ffio_read_varlen(bc);
40 
41  if (len && maxlen)
42  avio_read(bc, string, FFMIN(len, maxlen));
43  while (len > maxlen) {
44  avio_r8(bc);
45  len--;
46  }
47 
48  if (maxlen)
49  string[FFMIN(len, maxlen - 1)] = 0;
50 
51  if (maxlen == len)
52  return -1;
53  else
54  return 0;
55 }
56 
57 static int64_t get_s(AVIOContext *bc)
58 {
59  int64_t v = ffio_read_varlen(bc) + 1;
60 
61  if (v & 1)
62  return -(v >> 1);
63  else
64  return (v >> 1);
65 }
66 
67 static uint64_t get_fourcc(AVIOContext *bc)
68 {
69  unsigned int len = ffio_read_varlen(bc);
70 
71  if (len == 2)
72  return avio_rl16(bc);
73  else if (len == 4)
74  return avio_rl32(bc);
75  else
76  return -1;
77 }
78 
79 #ifdef TRACE
80 static inline uint64_t get_v_trace(AVIOContext *bc, const char *file,
81  const char *func, int line)
82 {
83  uint64_t v = ffio_read_varlen(bc);
84 
85  av_log(NULL, AV_LOG_DEBUG, "get_v %5"PRId64" / %"PRIX64" in %s %s:%d\n",
86  v, v, file, func, line);
87  return v;
88 }
89 
90 static inline int64_t get_s_trace(AVIOContext *bc, const char *file,
91  const char *func, int line)
92 {
93  int64_t v = get_s(bc);
94 
95  av_log(NULL, AV_LOG_DEBUG, "get_s %5"PRId64" / %"PRIX64" in %s %s:%d\n",
96  v, v, file, func, line);
97  return v;
98 }
99 
100 #define ffio_read_varlen(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
101 #define get_s(bc) get_s_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__)
102 #endif
103 
105  int calculate_checksum, uint64_t startcode)
106 {
107  int64_t size;
108 // start = avio_tell(bc) - 8;
109 
110  startcode = av_be2ne64(startcode);
111  startcode = ff_crc04C11DB7_update(0, (uint8_t*) &startcode, 8);
112 
114  size = ffio_read_varlen(bc);
115  if (size > 4096)
116  avio_rb32(bc);
117  if (ffio_get_checksum(bc) && size > 4096)
118  return -1;
119 
120  ffio_init_checksum(bc, calculate_checksum ? ff_crc04C11DB7_update : NULL, 0);
121 
122  return size;
123 }
124 
125 static uint64_t find_any_startcode(AVIOContext *bc, int64_t pos)
126 {
127  uint64_t state = 0;
128 
129  if (pos >= 0)
130  /* Note, this may fail if the stream is not seekable, but that should
131  * not matter, as in this case we simply start where we currently are */
132  avio_seek(bc, pos, SEEK_SET);
133  while (!bc->eof_reached) {
134  state = (state << 8) | avio_r8(bc);
135  if ((state >> 56) != 'N')
136  continue;
137  switch (state) {
138  case MAIN_STARTCODE:
139  case STREAM_STARTCODE:
140  case SYNCPOINT_STARTCODE:
141  case INFO_STARTCODE:
142  case INDEX_STARTCODE:
143  return state;
144  }
145  }
146 
147  return 0;
148 }
149 
156 static int64_t find_startcode(AVIOContext *bc, uint64_t code, int64_t pos)
157 {
158  for (;;) {
159  uint64_t startcode = find_any_startcode(bc, pos);
160  if (startcode == code)
161  return avio_tell(bc) - 8;
162  else if (startcode == 0)
163  return -1;
164  pos = -1;
165  }
166 }
167 
168 static int nut_probe(AVProbeData *p)
169 {
170  int i;
171  uint64_t code = 0;
172 
173  for (i = 0; i < p->buf_size; i++) {
174  code = (code << 8) | p->buf[i];
175  if (code == MAIN_STARTCODE)
176  return AVPROBE_SCORE_MAX;
177  }
178  return 0;
179 }
180 
181 #define GET_V(dst, check) \
182  do { \
183  tmp = ffio_read_varlen(bc); \
184  if (!(check)) { \
185  av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp); \
186  return -1; \
187  } \
188  dst = tmp; \
189  } while (0)
190 
191 static int skip_reserved(AVIOContext *bc, int64_t pos)
192 {
193  pos -= avio_tell(bc);
194  if (pos < 0) {
195  avio_seek(bc, pos, SEEK_CUR);
196  return -1;
197  } else {
198  while (pos--)
199  avio_r8(bc);
200  return 0;
201  }
202 }
203 
205 {
206  AVFormatContext *s = nut->avf;
207  AVIOContext *bc = s->pb;
208  uint64_t tmp, end;
209  unsigned int stream_count;
210  int i, j, count;
211  int tmp_stream, tmp_mul, tmp_pts, tmp_size, tmp_res, tmp_head_idx;
212 
213  end = get_packetheader(nut, bc, 1, MAIN_STARTCODE);
214  end += avio_tell(bc);
215 
216  GET_V(tmp, tmp >= 2 && tmp <= 3);
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));
226  nut->time_base = av_malloc(nut->time_base_count * sizeof(AVRational));
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, "time base invalid\n");
233  return AVERROR_INVALIDDATA;
234  }
235  }
236  tmp_pts = 0;
237  tmp_mul = 1;
238  tmp_stream = 0;
239  tmp_head_idx = 0;
240  for (i = 0; i < 256;) {
241  int tmp_flags = ffio_read_varlen(bc);
242  int tmp_fields = ffio_read_varlen(bc);
243 
244  if (tmp_fields > 0)
245  tmp_pts = get_s(bc);
246  if (tmp_fields > 1)
247  tmp_mul = ffio_read_varlen(bc);
248  if (tmp_fields > 2)
249  tmp_stream = ffio_read_varlen(bc);
250  if (tmp_fields > 3)
251  tmp_size = ffio_read_varlen(bc);
252  else
253  tmp_size = 0;
254  if (tmp_fields > 4)
255  tmp_res = ffio_read_varlen(bc);
256  else
257  tmp_res = 0;
258  if (tmp_fields > 5)
259  count = ffio_read_varlen(bc);
260  else
261  count = tmp_mul - tmp_size;
262  if (tmp_fields > 6)
263  get_s(bc);
264  if (tmp_fields > 7)
265  tmp_head_idx = ffio_read_varlen(bc);
266 
267  while (tmp_fields-- > 8)
268  ffio_read_varlen(bc);
269 
270  if (count == 0 || i + count > 256) {
271  av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i);
272  return AVERROR_INVALIDDATA;
273  }
274  if (tmp_stream >= stream_count) {
275  av_log(s, AV_LOG_ERROR, "illegal stream number\n");
276  return AVERROR_INVALIDDATA;
277  }
278 
279  for (j = 0; j < count; j++, i++) {
280  if (i == 'N') {
281  nut->frame_code[i].flags = FLAG_INVALID;
282  j--;
283  continue;
284  }
285  nut->frame_code[i].flags = tmp_flags;
286  nut->frame_code[i].pts_delta = tmp_pts;
287  nut->frame_code[i].stream_id = tmp_stream;
288  nut->frame_code[i].size_mul = tmp_mul;
289  nut->frame_code[i].size_lsb = tmp_size + j;
290  nut->frame_code[i].reserved_count = tmp_res;
291  nut->frame_code[i].header_idx = tmp_head_idx;
292  }
293  }
294  assert(nut->frame_code['N'].flags == FLAG_INVALID);
295 
296  if (end > avio_tell(bc) + 4) {
297  int rem = 1024;
298  GET_V(nut->header_count, tmp < 128U);
299  nut->header_count++;
300  for (i = 1; i < nut->header_count; i++) {
301  uint8_t *hdr;
302  GET_V(nut->header_len[i], tmp > 0 && tmp < 256);
303  rem -= nut->header_len[i];
304  if (rem < 0) {
305  av_log(s, AV_LOG_ERROR, "invalid elision header\n");
306  return AVERROR_INVALIDDATA;
307  }
308  hdr = av_malloc(nut->header_len[i]);
309  if (!hdr)
310  return AVERROR(ENOMEM);
311  avio_read(bc, hdr, nut->header_len[i]);
312  nut->header[i] = hdr;
313  }
314  assert(nut->header_len[0] == 0);
315  }
316 
317  if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
318  av_log(s, AV_LOG_ERROR, "main header checksum mismatch\n");
319  return AVERROR_INVALIDDATA;
320  }
321 
322  nut->stream = av_mallocz(sizeof(StreamContext) * stream_count);
323  for (i = 0; i < stream_count; i++)
325 
326  return 0;
327 }
328 
330 {
331  AVFormatContext *s = nut->avf;
332  AVIOContext *bc = s->pb;
333  StreamContext *stc;
334  int class, stream_id;
335  uint64_t tmp, end;
336  AVStream *st;
337 
338  end = get_packetheader(nut, bc, 1, STREAM_STARTCODE);
339  end += avio_tell(bc);
340 
341  GET_V(stream_id, tmp < s->nb_streams && !nut->stream[tmp].time_base);
342  stc = &nut->stream[stream_id];
343  st = s->streams[stream_id];
344  if (!st)
345  return AVERROR(ENOMEM);
346 
347  class = ffio_read_varlen(bc);
348  tmp = get_fourcc(bc);
349  st->codec->codec_tag = tmp;
350  switch (class) {
351  case 0:
353  st->codec->codec_id = av_codec_get_id((const AVCodecTag * const []) {
356  0
357  },
358  tmp);
359  break;
360  case 1:
362  st->codec->codec_id = av_codec_get_id((const AVCodecTag * const []) {
365  0
366  },
367  tmp);
368  break;
369  case 2:
372  break;
373  case 3:
376  break;
377  default:
378  av_log(s, AV_LOG_ERROR, "unknown stream class (%d)\n", class);
379  return -1;
380  }
381  if (class < 3 && st->codec->codec_id == AV_CODEC_ID_NONE)
382  av_log(s, AV_LOG_ERROR,
383  "Unknown codec tag '0x%04x' for stream number %d\n",
384  (unsigned int) tmp, stream_id);
385 
386  GET_V(stc->time_base_id, tmp < nut->time_base_count);
387  GET_V(stc->msb_pts_shift, tmp < 16);
389  GET_V(stc->decode_delay, tmp < 1000); // sanity limit, raise this if Moore's law is true
390  st->codec->has_b_frames = stc->decode_delay;
391  ffio_read_varlen(bc); // stream flags
392 
393  GET_V(st->codec->extradata_size, tmp < (1 << 30));
394  if (st->codec->extradata_size) {
397  avio_read(bc, st->codec->extradata, st->codec->extradata_size);
398  }
399 
400  if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
401  GET_V(st->codec->width, tmp > 0);
402  GET_V(st->codec->height, tmp > 0);
405  if ((!st->sample_aspect_ratio.num) != (!st->sample_aspect_ratio.den)) {
406  av_log(s, AV_LOG_ERROR, "invalid aspect ratio %d/%d\n",
408  return -1;
409  }
410  ffio_read_varlen(bc); /* csp type */
411  } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
412  GET_V(st->codec->sample_rate, tmp > 0);
413  ffio_read_varlen(bc); // samplerate_den
414  GET_V(st->codec->channels, tmp > 0);
415  }
416  if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
417  av_log(s, AV_LOG_ERROR,
418  "stream header %d checksum mismatch\n", stream_id);
419  return -1;
420  }
421  stc->time_base = &nut->time_base[stc->time_base_id];
422  avpriv_set_pts_info(s->streams[stream_id], 63, stc->time_base->num,
423  stc->time_base->den);
424  return 0;
425 }
426 
427 static void set_disposition_bits(AVFormatContext *avf, char *value,
428  int stream_id)
429 {
430  int flag = 0, i;
431 
432  for (i = 0; ff_nut_dispositions[i].flag; ++i)
433  if (!strcmp(ff_nut_dispositions[i].str, value))
434  flag = ff_nut_dispositions[i].flag;
435  if (!flag)
436  av_log(avf, AV_LOG_INFO, "unknown disposition type '%s'\n", value);
437  for (i = 0; i < avf->nb_streams; ++i)
438  if (stream_id == i || stream_id == -1)
439  avf->streams[i]->disposition |= flag;
440 }
441 
443 {
444  AVFormatContext *s = nut->avf;
445  AVIOContext *bc = s->pb;
446  uint64_t tmp, chapter_start, chapter_len;
447  unsigned int stream_id_plus1, count;
448  int chapter_id, i;
449  int64_t value, end;
450  char name[256], str_value[1024], type_str[256];
451  const char *type;
452  AVChapter *chapter = NULL;
453  AVStream *st = NULL;
454  AVDictionary **metadata = NULL;
455 
456  end = get_packetheader(nut, bc, 1, INFO_STARTCODE);
457  end += avio_tell(bc);
458 
459  GET_V(stream_id_plus1, tmp <= s->nb_streams);
460  chapter_id = get_s(bc);
461  chapter_start = ffio_read_varlen(bc);
462  chapter_len = ffio_read_varlen(bc);
463  count = ffio_read_varlen(bc);
464 
465  if (chapter_id && !stream_id_plus1) {
466  int64_t start = chapter_start / nut->time_base_count;
467  chapter = avpriv_new_chapter(s, chapter_id,
468  nut->time_base[chapter_start %
469  nut->time_base_count],
470  start, start + chapter_len, NULL);
471  metadata = &chapter->metadata;
472  } else if (stream_id_plus1) {
473  st = s->streams[stream_id_plus1 - 1];
474  metadata = &st->metadata;
475  } else
476  metadata = &s->metadata;
477 
478  for (i = 0; i < count; i++) {
479  get_str(bc, name, sizeof(name));
480  value = get_s(bc);
481  if (value == -1) {
482  type = "UTF-8";
483  get_str(bc, str_value, sizeof(str_value));
484  } else if (value == -2) {
485  get_str(bc, type_str, sizeof(type_str));
486  type = type_str;
487  get_str(bc, str_value, sizeof(str_value));
488  } else if (value == -3) {
489  type = "s";
490  value = get_s(bc);
491  } else if (value == -4) {
492  type = "t";
493  value = ffio_read_varlen(bc);
494  } else if (value < -4) {
495  type = "r";
496  get_s(bc);
497  } else {
498  type = "v";
499  }
500 
501  if (stream_id_plus1 > s->nb_streams) {
502  av_log(s, AV_LOG_ERROR, "invalid stream id for info packet\n");
503  continue;
504  }
505 
506  if (!strcmp(type, "UTF-8")) {
507  if (chapter_id == 0 && !strcmp(name, "Disposition")) {
508  set_disposition_bits(s, str_value, stream_id_plus1 - 1);
509  continue;
510  }
511  if (metadata && av_strcasecmp(name, "Uses") &&
512  av_strcasecmp(name, "Depends") && av_strcasecmp(name, "Replaces"))
513  av_dict_set(metadata, name, str_value, 0);
514  }
515  }
516 
517  if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
518  av_log(s, AV_LOG_ERROR, "info header checksum mismatch\n");
519  return -1;
520  }
521  return 0;
522 }
523 
524 static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
525 {
526  AVFormatContext *s = nut->avf;
527  AVIOContext *bc = s->pb;
528  int64_t end, tmp;
529  int ret;
530 
531  nut->last_syncpoint_pos = avio_tell(bc) - 8;
532 
533  end = get_packetheader(nut, bc, 1, SYNCPOINT_STARTCODE);
534  end += avio_tell(bc);
535 
536  tmp = ffio_read_varlen(bc);
537  *back_ptr = nut->last_syncpoint_pos - 16 * ffio_read_varlen(bc);
538  if (*back_ptr < 0)
539  return -1;
540 
541  ff_nut_reset_ts(nut, nut->time_base[tmp % nut->time_base_count],
542  tmp / nut->time_base_count);
543 
544  if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
545  av_log(s, AV_LOG_ERROR, "sync point checksum mismatch\n");
546  return -1;
547  }
548 
549  *ts = tmp / s->nb_streams *
550  av_q2d(nut->time_base[tmp % s->nb_streams]) * AV_TIME_BASE;
551 
552  if ((ret = ff_nut_add_sp(nut, nut->last_syncpoint_pos, *back_ptr, *ts)) < 0)
553  return ret;
554 
555  return 0;
556 }
557 
559 {
560  AVFormatContext *s = nut->avf;
561  AVIOContext *bc = s->pb;
562  uint64_t tmp, end;
563  int i, j, syncpoint_count;
564  int64_t filesize = avio_size(bc);
565  int64_t *syncpoints;
566  int8_t *has_keyframe;
567  int ret = -1;
568 
569  avio_seek(bc, filesize - 12, SEEK_SET);
570  avio_seek(bc, filesize - avio_rb64(bc), SEEK_SET);
571  if (avio_rb64(bc) != INDEX_STARTCODE) {
572  av_log(s, AV_LOG_ERROR, "no index at the end\n");
573  return -1;
574  }
575 
576  end = get_packetheader(nut, bc, 1, INDEX_STARTCODE);
577  end += avio_tell(bc);
578 
579  ffio_read_varlen(bc); // max_pts
580  GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
581  syncpoints = av_malloc(sizeof(int64_t) * syncpoint_count);
582  has_keyframe = av_malloc(sizeof(int8_t) * (syncpoint_count + 1));
583  for (i = 0; i < syncpoint_count; i++) {
584  syncpoints[i] = ffio_read_varlen(bc);
585  if (syncpoints[i] <= 0)
586  goto fail;
587  if (i)
588  syncpoints[i] += syncpoints[i - 1];
589  }
590 
591  for (i = 0; i < s->nb_streams; i++) {
592  int64_t last_pts = -1;
593  for (j = 0; j < syncpoint_count;) {
594  uint64_t x = ffio_read_varlen(bc);
595  int type = x & 1;
596  int n = j;
597  x >>= 1;
598  if (type) {
599  int flag = x & 1;
600  x >>= 1;
601  if (n + x >= syncpoint_count + 1) {
602  av_log(s, AV_LOG_ERROR, "index overflow A\n");
603  goto fail;
604  }
605  while (x--)
606  has_keyframe[n++] = flag;
607  has_keyframe[n++] = !flag;
608  } else {
609  while (x != 1) {
610  if (n >= syncpoint_count + 1) {
611  av_log(s, AV_LOG_ERROR, "index overflow B\n");
612  goto fail;
613  }
614  has_keyframe[n++] = x & 1;
615  x >>= 1;
616  }
617  }
618  if (has_keyframe[0]) {
619  av_log(s, AV_LOG_ERROR, "keyframe before first syncpoint in index\n");
620  goto fail;
621  }
622  assert(n <= syncpoint_count + 1);
623  for (; j < n && j < syncpoint_count; j++) {
624  if (has_keyframe[j]) {
625  uint64_t B, A = ffio_read_varlen(bc);
626  if (!A) {
627  A = ffio_read_varlen(bc);
628  B = ffio_read_varlen(bc);
629  // eor_pts[j][i] = last_pts + A + B
630  } else
631  B = 0;
632  av_add_index_entry(s->streams[i], 16 * syncpoints[j - 1],
633  last_pts + A, 0, 0, AVINDEX_KEYFRAME);
634  last_pts += A + B;
635  }
636  }
637  }
638  }
639 
640  if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
641  av_log(s, AV_LOG_ERROR, "index checksum mismatch\n");
642  goto fail;
643  }
644  ret = 0;
645 
646 fail:
647  av_free(syncpoints);
648  av_free(has_keyframe);
649  return ret;
650 }
651 
653 {
654  NUTContext *nut = s->priv_data;
655  AVIOContext *bc = s->pb;
656  int64_t pos;
657  int initialized_stream_count;
658 
659  nut->avf = s;
660 
661  /* main header */
662  pos = 0;
663  do {
664  pos = find_startcode(bc, MAIN_STARTCODE, pos) + 1;
665  if (pos < 0 + 1) {
666  av_log(s, AV_LOG_ERROR, "No main startcode found.\n");
667  return AVERROR_INVALIDDATA;
668  }
669  } while (decode_main_header(nut) < 0);
670 
671  /* stream headers */
672  pos = 0;
673  for (initialized_stream_count = 0; initialized_stream_count < s->nb_streams;) {
674  pos = find_startcode(bc, STREAM_STARTCODE, pos) + 1;
675  if (pos < 0 + 1) {
676  av_log(s, AV_LOG_ERROR, "Not all stream headers found.\n");
677  return AVERROR_INVALIDDATA;
678  }
679  if (decode_stream_header(nut) >= 0)
680  initialized_stream_count++;
681  }
682 
683  /* info headers */
684  pos = 0;
685  for (;;) {
686  uint64_t startcode = find_any_startcode(bc, pos);
687  pos = avio_tell(bc);
688 
689  if (startcode == 0) {
690  av_log(s, AV_LOG_ERROR, "EOF before video frames\n");
691  return AVERROR_INVALIDDATA;
692  } else if (startcode == SYNCPOINT_STARTCODE) {
693  nut->next_startcode = startcode;
694  break;
695  } else if (startcode != INFO_STARTCODE) {
696  continue;
697  }
698 
699  decode_info_header(nut);
700  }
701 
702  s->data_offset = pos - 8;
703 
704  if (bc->seekable) {
705  int64_t orig_pos = avio_tell(bc);
707  avio_seek(bc, orig_pos, SEEK_SET);
708  }
709  assert(nut->next_startcode == SYNCPOINT_STARTCODE);
710 
712 
713  return 0;
714 }
715 
716 static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id,
717  uint8_t *header_idx, int frame_code)
718 {
719  AVFormatContext *s = nut->avf;
720  AVIOContext *bc = s->pb;
721  StreamContext *stc;
722  int size, flags, size_mul, pts_delta, i, reserved_count;
723  uint64_t tmp;
724 
725  if (avio_tell(bc) > nut->last_syncpoint_pos + nut->max_distance) {
726  av_log(s, AV_LOG_ERROR,
727  "Last frame must have been damaged %"PRId64" > %"PRId64" + %d\n",
728  avio_tell(bc), nut->last_syncpoint_pos, nut->max_distance);
729  return AVERROR_INVALIDDATA;
730  }
731 
732  flags = nut->frame_code[frame_code].flags;
733  size_mul = nut->frame_code[frame_code].size_mul;
734  size = nut->frame_code[frame_code].size_lsb;
735  *stream_id = nut->frame_code[frame_code].stream_id;
736  pts_delta = nut->frame_code[frame_code].pts_delta;
737  reserved_count = nut->frame_code[frame_code].reserved_count;
738  *header_idx = nut->frame_code[frame_code].header_idx;
739 
740  if (flags & FLAG_INVALID)
741  return AVERROR_INVALIDDATA;
742  if (flags & FLAG_CODED)
743  flags ^= ffio_read_varlen(bc);
744  if (flags & FLAG_STREAM_ID) {
745  GET_V(*stream_id, tmp < s->nb_streams);
746  }
747  stc = &nut->stream[*stream_id];
748  if (flags & FLAG_CODED_PTS) {
749  int coded_pts = ffio_read_varlen(bc);
750  // FIXME check last_pts validity?
751  if (coded_pts < (1 << stc->msb_pts_shift)) {
752  *pts = ff_lsb2full(stc, coded_pts);
753  } else
754  *pts = coded_pts - (1 << stc->msb_pts_shift);
755  } else
756  *pts = stc->last_pts + pts_delta;
757  if (flags & FLAG_SIZE_MSB)
758  size += size_mul * ffio_read_varlen(bc);
759  if (flags & FLAG_MATCH_TIME)
760  get_s(bc);
761  if (flags & FLAG_HEADER_IDX)
762  *header_idx = ffio_read_varlen(bc);
763  if (flags & FLAG_RESERVED)
764  reserved_count = ffio_read_varlen(bc);
765  for (i = 0; i < reserved_count; i++)
766  ffio_read_varlen(bc);
767 
768  if (*header_idx >= (unsigned)nut->header_count) {
769  av_log(s, AV_LOG_ERROR, "header_idx invalid\n");
770  return AVERROR_INVALIDDATA;
771  }
772  if (size > 4096)
773  *header_idx = 0;
774  size -= nut->header_len[*header_idx];
775 
776  if (flags & FLAG_CHECKSUM) {
777  avio_rb32(bc); // FIXME check this
778  } else if (size > 2 * nut->max_distance || FFABS(stc->last_pts - *pts) >
779  stc->max_pts_distance) {
780  av_log(s, AV_LOG_ERROR, "frame size > 2max_distance and no checksum\n");
781  return AVERROR_INVALIDDATA;
782  }
783 
784  stc->last_pts = *pts;
785  stc->last_flags = flags;
786 
787  return size;
788 }
789 
790 static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code)
791 {
792  AVFormatContext *s = nut->avf;
793  AVIOContext *bc = s->pb;
794  int size, stream_id, discard;
795  int64_t pts, last_IP_pts;
796  StreamContext *stc;
797  uint8_t header_idx;
798 
799  size = decode_frame_header(nut, &pts, &stream_id, &header_idx, frame_code);
800  if (size < 0)
801  return size;
802 
803  stc = &nut->stream[stream_id];
804 
805  if (stc->last_flags & FLAG_KEY)
806  stc->skip_until_key_frame = 0;
807 
808  discard = s->streams[stream_id]->discard;
809  last_IP_pts = s->streams[stream_id]->last_IP_pts;
810  if ((discard >= AVDISCARD_NONKEY && !(stc->last_flags & FLAG_KEY)) ||
811  (discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE &&
812  last_IP_pts > pts) ||
813  discard >= AVDISCARD_ALL ||
814  stc->skip_until_key_frame) {
815  avio_skip(bc, size);
816  return 1;
817  }
818 
819  av_new_packet(pkt, size + nut->header_len[header_idx]);
820  memcpy(pkt->data, nut->header[header_idx], nut->header_len[header_idx]);
821  pkt->pos = avio_tell(bc); // FIXME
822  avio_read(bc, pkt->data + nut->header_len[header_idx], size);
823 
824  pkt->stream_index = stream_id;
825  if (stc->last_flags & FLAG_KEY)
826  pkt->flags |= AV_PKT_FLAG_KEY;
827  pkt->pts = pts;
828 
829  return 0;
830 }
831 
833 {
834  NUTContext *nut = s->priv_data;
835  AVIOContext *bc = s->pb;
836  int i, frame_code = 0, ret, skip;
837  int64_t ts, back_ptr;
838 
839  for (;;) {
840  int64_t pos = avio_tell(bc);
841  uint64_t tmp = nut->next_startcode;
842  nut->next_startcode = 0;
843 
844  if (tmp) {
845  pos -= 8;
846  } else {
847  frame_code = avio_r8(bc);
848  if (bc->eof_reached)
849  return -1;
850  if (frame_code == 'N') {
851  tmp = frame_code;
852  for (i = 1; i < 8; i++)
853  tmp = (tmp << 8) + avio_r8(bc);
854  }
855  }
856  switch (tmp) {
857  case MAIN_STARTCODE:
858  case STREAM_STARTCODE:
859  case INDEX_STARTCODE:
860  skip = get_packetheader(nut, bc, 0, tmp);
861  avio_skip(bc, skip);
862  break;
863  case INFO_STARTCODE:
864  if (decode_info_header(nut) < 0)
865  goto resync;
866  break;
867  case SYNCPOINT_STARTCODE:
868  if (decode_syncpoint(nut, &ts, &back_ptr) < 0)
869  goto resync;
870  frame_code = avio_r8(bc);
871  case 0:
872  ret = decode_frame(nut, pkt, frame_code);
873  if (ret == 0)
874  return 0;
875  else if (ret == 1) // OK but discard packet
876  break;
877  default:
878 resync:
879  av_log(s, AV_LOG_DEBUG, "syncing from %"PRId64"\n", pos);
880  tmp = find_any_startcode(bc, nut->last_syncpoint_pos + 1);
881  if (tmp == 0)
882  return AVERROR_INVALIDDATA;
883  av_log(s, AV_LOG_DEBUG, "sync\n");
884  nut->next_startcode = tmp;
885  }
886  }
887 }
888 
889 static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index,
890  int64_t *pos_arg, int64_t pos_limit)
891 {
892  NUTContext *nut = s->priv_data;
893  AVIOContext *bc = s->pb;
894  int64_t pos, pts, back_ptr;
895  av_log(s, AV_LOG_DEBUG, "read_timestamp(X,%d,%"PRId64",%"PRId64")\n",
896  stream_index, *pos_arg, pos_limit);
897 
898  pos = *pos_arg;
899  do {
900  pos = find_startcode(bc, SYNCPOINT_STARTCODE, pos) + 1;
901  if (pos < 1) {
902  assert(nut->next_startcode == 0);
903  av_log(s, AV_LOG_ERROR, "read_timestamp failed.\n");
904  return AV_NOPTS_VALUE;
905  }
906  } while (decode_syncpoint(nut, &pts, &back_ptr) < 0);
907  *pos_arg = pos - 1;
908  assert(nut->last_syncpoint_pos == *pos_arg);
909 
910  av_log(s, AV_LOG_DEBUG, "return %"PRId64" %"PRId64"\n", pts, back_ptr);
911  if (stream_index == -1)
912  return pts;
913  else if (stream_index == -2)
914  return back_ptr;
915 
916  assert(0);
917 }
918 
919 static int read_seek(AVFormatContext *s, int stream_index,
920  int64_t pts, int flags)
921 {
922  NUTContext *nut = s->priv_data;
923  AVStream *st = s->streams[stream_index];
924  Syncpoint dummy = { .ts = pts * av_q2d(st->time_base) * AV_TIME_BASE };
925  Syncpoint nopts_sp = { .ts = AV_NOPTS_VALUE, .back_ptr = AV_NOPTS_VALUE };
926  Syncpoint *sp, *next_node[2] = { &nopts_sp, &nopts_sp };
927  int64_t pos, pos2, ts;
928  int i;
929 
930  if (st->index_entries) {
931  int index = av_index_search_timestamp(st, pts, flags);
932  if (index < 0)
933  return -1;
934 
935  pos2 = st->index_entries[index].pos;
936  ts = st->index_entries[index].timestamp;
937  } else {
938  av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pts_cmp,
939  (void **) next_node);
940  av_log(s, AV_LOG_DEBUG, "%"PRIu64"-%"PRIu64" %"PRId64"-%"PRId64"\n",
941  next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
942  next_node[1]->ts);
943  pos = ff_gen_search(s, -1, dummy.ts, next_node[0]->pos,
944  next_node[1]->pos, next_node[1]->pos,
945  next_node[0]->ts, next_node[1]->ts,
947 
948  if (!(flags & AVSEEK_FLAG_BACKWARD)) {
949  dummy.pos = pos + 16;
950  next_node[1] = &nopts_sp;
951  av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp,
952  (void **) next_node);
953  pos2 = ff_gen_search(s, -2, dummy.pos, next_node[0]->pos,
954  next_node[1]->pos, next_node[1]->pos,
955  next_node[0]->back_ptr, next_node[1]->back_ptr,
956  flags, &ts, nut_read_timestamp);
957  if (pos2 >= 0)
958  pos = pos2;
959  // FIXME dir but I think it does not matter
960  }
961  dummy.pos = pos;
962  sp = av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp,
963  NULL);
964 
965  assert(sp);
966  pos2 = sp->back_ptr - 15;
967  }
968  av_log(NULL, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos2);
969  pos = find_startcode(s->pb, SYNCPOINT_STARTCODE, pos2);
970  avio_seek(s->pb, pos, SEEK_SET);
971  av_log(NULL, AV_LOG_DEBUG, "SP: %"PRId64"\n", pos);
972  if (pos2 > pos || pos2 + 15 < pos)
973  av_log(NULL, AV_LOG_ERROR, "no syncpoint at backptr pos\n");
974  for (i = 0; i < s->nb_streams; i++)
975  nut->stream[i].skip_until_key_frame = 1;
976 
977  return 0;
978 }
979 
981 {
982  NUTContext *nut = s->priv_data;
983  int i;
984 
985  av_freep(&nut->time_base);
986  av_freep(&nut->stream);
987  ff_nut_free_sp(nut);
988  for (i = 1; i < nut->header_count; i++)
989  av_freep(&nut->header[i]);
990 
991  return 0;
992 }
993 
995  .name = "nut",
996  .long_name = NULL_IF_CONFIG_SMALL("NUT"),
997  .priv_data_size = sizeof(NUTContext),
1002  .read_seek = read_seek,
1003  .extensions = "nut",
1004  .codec_tag = ff_nut_codec_tags,
1005 };
uint8_t header_len[128]
Definition: nut.h:93
uint64_t ffio_read_varlen(AVIOContext *bc)
Definition: aviobuf.c:650
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:61
discard all frames except keyframes
Definition: avcodec.h:535
Bytestream IO Context.
Definition: avio.h:68
#define MAIN_STARTCODE
Definition: nut.h:32
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:241
int size
int64_t last_syncpoint_pos
Definition: nut.h:100
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: utils.c:1393
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:2126
#define B
Definition: dsputil.c:1897
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:940
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:3283
int64_t pos
Definition: avformat.h:583
static int get_str(AVIOContext *bc, char *string, unsigned int maxlen)
Definition: nutdec.c:37
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:697
int num
numerator
Definition: rational.h:44
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:186
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: avformat.h:786
Definition: nut.h:56
#define NUT_MAX_STREAMS
Definition: nutdec.c:35
int64_t ts
Definition: nut.h:60
static void set_disposition_bits(AVFormatContext *avf, char *value, int stream_id)
Definition: nutdec.c:427
int64_t data_offset
offset of the first packet
Definition: avformat.h:1029
discard all
Definition: avcodec.h:536
Definition: nut.h:88
uint8_t stream_id
Definition: nut.h:65
AVDictionary * metadata
Definition: avformat.h:817
static int decode_main_header(NUTContext *nut)
Definition: nutdec.c:204
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:151
const uint8_t * header[128]
Definition: nut.h:94
AVChapter * avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title)
Add a new chapter.
Definition: utils.c:2815
Format I/O context.
Definition: avformat.h:828
static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id, uint8_t *header_idx, int frame_code)
Definition: nutdec.c:716
if set, reserved_count is coded in the frame header
Definition: nut.h:49
static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos_arg, int64_t pos_limit)
Definition: nutdec.c:889
Public dictionary API.
void * av_tree_find(const AVTreeNode *t, void *key, int(*cmp)(void *key, const void *b), void *next[2])
Definition: tree.c:40
uint8_t
AVRational * time_base
Definition: nut.h:102
Opaque data information usually continuous.
Definition: avutil.h:181
int decode_delay
Definition: nut.h:81
uint16_t flags
Definition: nut.h:64
static int nut_probe(AVProbeData *p)
Definition: nutdec.c:168
A tree container.
enum AVCodecID av_codec_get_id(const struct AVCodecTag *const *tags, unsigned int tag)
Get the AVCodecID for the given codec tag tag.
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:577
if set, coded_pts is in the frame header
Definition: nut.h:45
#define STREAM_STARTCODE
Definition: nut.h:33
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1454
const char * name
AVStream ** streams
Definition: avformat.h:876
If set, match_time_delta is coded in the frame header.
Definition: nut.h:51
const AVMetadataConv ff_nut_metadata_conv[]
Definition: nut.c:226
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
uint8_t * data
Definition: avcodec.h:915
int last_flags
Definition: nut.h:74
static int flags
Definition: log.c:42
static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code)
Definition: nutdec.c:790
#define sp
Definition: regdef.h:63
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
const AVCodecTag ff_nut_data_tags[]
Definition: nut.c:36
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:642
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:219
int ff_nut_sp_pos_cmp(const Syncpoint *a, const Syncpoint *b)
Definition: nut.c:174
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:446
AVFormatContext * avf
Definition: nut.h:89
struct NUTContext NUTContext
int64_t last_pts
Definition: nut.h:76
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:56
AVDictionary * metadata
Definition: avformat.h:972
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:1634
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:139
void ff_nut_free_sp(NUTContext *nut)
Definition: nut.c:210
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
Definition: utils.c:1435
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:546
discard all bidirectional frames
Definition: avcodec.h:534
uint64_t pos
Definition: nut.h:57
int64_t timestamp
Definition: avformat.h:584
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:88
Definition: graph2dot.c:48
int64_t av_gcd(int64_t a, int64_t b)
Return the greatest common divisor of a and b.
Definition: mathematics.c:53
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:2736
static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: nutdec.c:832
const AVCodecTag ff_nut_audio_tags[]
Definition: nut.c:126
int header_count
Definition: nut.h:101
AVRational * time_base
Definition: nut.h:78
static int decode_stream_header(NUTContext *nut)
Definition: nutdec.c:329
#define av_be2ne64(x)
Definition: bswap.h:94
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:297
if set, frame is keyframe
Definition: nut.h:43
int ff_nut_sp_pts_cmp(const Syncpoint *a, const Syncpoint *b)
Definition: nut.c:178
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:921
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:437
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:641
static int nut_read_close(AVFormatContext *s)
Definition: nutdec.c:980
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:341
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:340
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:875
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:425
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:117
void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val)
Definition: nut.c:157
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:31
int av_strcasecmp(const char *a, const char *b)
Definition: avstring.c:140
uint8_t header_idx
Definition: nut.h:70
static int read_probe(AVProbeData *pd)
Definition: jvdec.c:54
int width
picture width / height.
Definition: avcodec.h:1508
static uint64_t find_any_startcode(AVIOContext *bc, int64_t pos)
Definition: nutdec.c:125
uint16_t size_lsb
Definition: nut.h:67
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:411
int16_t pts_delta
Definition: nut.h:68
static int find_and_decode_index(NUTContext *nut)
Definition: nutdec.c:558
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: avio.h:210
int64_t ff_lsb2full(StreamContext *stream, int64_t lsb)
Definition: nut.c:168
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
if set, frame_code is invalid
Definition: nut.h:53
static uint64_t get_fourcc(AVIOContext *bc)
Definition: nutdec.c:67
static int get_packetheader(NUTContext *nut, AVIOContext *bc, int calculate_checksum, uint64_t startcode)
Definition: nutdec.c:104
struct AVTreeNode * syncpoints
Definition: nut.h:103
if set, data_size_msb is at frame header, otherwise data_size_msb is 0
Definition: nut.h:47
AVDictionary * metadata
Definition: avformat.h:699
static int nut_read_header(AVFormatContext *s)
Definition: nutdec.c:652
if set, the frame header contains a checksum
Definition: nut.h:48
#define INDEX_STARTCODE
Definition: nut.h:35
uint16_t size_mul
Definition: nut.h:66
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:536
static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
Definition: nutdec.c:524
Stream structure.
Definition: avformat.h:622
int msb_pts_shift
Definition: nut.h:79
NULL
Definition: eval.c:52
enum AVMediaType codec_type
Definition: avcodec.h:1347
const AVCodecTag ff_nut_subtitle_tags[]
Definition: nut.c:28
enum AVCodecID codec_id
Definition: avcodec.h:1350
int sample_rate
samples per second
Definition: avcodec.h:2104
AVIOContext * pb
I/O context.
Definition: avformat.h:861
int max_pts_distance
Definition: nut.h:80
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1365
if set, coded_flags are stored in the frame header
Definition: nut.h:52
int extradata_size
Definition: avcodec.h:1455
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:114
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:63
#define GET_V(dst, check)
Definition: nutdec.c:181
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: utils.c:1503
int index
Definition: gxfenc.c:72
rational number numerator/denominator
Definition: rational.h:43
byte swapping routines
unsigned long ffio_get_checksum(AVIOContext *s)
Definition: aviobuf.c:417
StreamContext * stream
Definition: nut.h:96
static int skip_reserved(AVIOContext *bc, int64_t pos)
Definition: nutdec.c:191
static int64_t find_startcode(AVIOContext *bc, uint64_t code, int64_t pos)
Find the given startcode.
Definition: nutdec.c:156
This structure contains the data a format has to probe a file.
Definition: avformat.h:338
static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
Definition: nutdec.c:919
#define INFO_STARTCODE
Definition: nut.h:36
static uint32_t state
Definition: trasher.c:27
Definition: vf_drawbox.c:36
int skip_until_key_frame
Definition: nut.h:75
void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition: metadata.c:59
const Dispositions ff_nut_dispositions[]
Definition: nut.c:216
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:530
uint64_t next_startcode
stores the next startcode if it has already been parsed but the stream is not seekable ...
Definition: nut.h:95
static int decode_info_header(NUTContext *nut)
Definition: nutdec.c:442
FrameCode frame_code[256]
Definition: nut.h:92
int disposition
AV_DISPOSITION_* bit field.
Definition: avformat.h:688
const AVCodecTag ff_nut_video_tags[]
Definition: nut.c:41
int ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts)
Definition: nut.c:182
int den
denominator
Definition: rational.h:45
#define SYNCPOINT_STARTCODE
Definition: nut.h:34
int flag
Definition: nut.h:115
int eof_reached
true if eof reached
Definition: avio.h:96
If set, header_idx is coded in the frame header.
Definition: nut.h:50
int len
AVInputFormat ff_nut_demuxer
Definition: nutdec.c:994
int channels
number of audio channels
Definition: avcodec.h:2105
static int64_t get_s(AVIOContext *bc)
Definition: nutdec.c:57
void * priv_data
Format private data.
Definition: avformat.h:848
int time_base_id
Definition: nut.h:77
int64_t last_IP_pts
Definition: avformat.h:760
if set, stream_id is coded in the frame header
Definition: nut.h:46
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:455
int stream_index
Definition: avcodec.h:917
Definition: vf_drawbox.c:36
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:669
uint64_t back_ptr
Definition: nut.h:58
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:690
const AVCodecTag *const ff_nut_codec_tags[]
Definition: nut.c:152
This structure stores compressed data.
Definition: avcodec.h:898
unsigned int time_base_count
Definition: nut.h:99
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:158
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:908
uint8_t reserved_count
Definition: nut.h:69
unsigned int max_distance
Definition: nut.h:98
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)