Libav
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 AVERROR_INVALIDDATA; \
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 AVERROR_INVALIDDATA;
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  nut->version = ffio_read_varlen(bc);
217  if (nut->version < NUT_MIN_VERSION &&
218  nut->version > NUT_MAX_VERSION) {
219  av_log(s, AV_LOG_ERROR, "Version %d not supported.\n",
220  nut->version);
221  return AVERROR(ENOSYS);
222  }
223 
224  GET_V(stream_count, tmp > 0 && tmp <= NUT_MAX_STREAMS);
225 
226  nut->max_distance = ffio_read_varlen(bc);
227  if (nut->max_distance > 65536) {
228  av_log(s, AV_LOG_DEBUG, "max_distance %d\n", nut->max_distance);
229  nut->max_distance = 65536;
230  }
231 
232  GET_V(nut->time_base_count, tmp > 0 && tmp < INT_MAX / sizeof(AVRational));
233  nut->time_base = av_malloc(nut->time_base_count * sizeof(AVRational));
234 
235  for (i = 0; i < nut->time_base_count; i++) {
236  GET_V(nut->time_base[i].num, tmp > 0 && tmp < (1ULL << 31));
237  GET_V(nut->time_base[i].den, tmp > 0 && tmp < (1ULL << 31));
238  if (av_gcd(nut->time_base[i].num, nut->time_base[i].den) != 1) {
239  av_log(s, AV_LOG_ERROR, "time base invalid\n");
240  return AVERROR_INVALIDDATA;
241  }
242  }
243  tmp_pts = 0;
244  tmp_mul = 1;
245  tmp_stream = 0;
246  tmp_head_idx = 0;
247  for (i = 0; i < 256;) {
248  int tmp_flags = ffio_read_varlen(bc);
249  int tmp_fields = ffio_read_varlen(bc);
250 
251  if (tmp_fields > 0)
252  tmp_pts = get_s(bc);
253  if (tmp_fields > 1)
254  tmp_mul = ffio_read_varlen(bc);
255  if (tmp_fields > 2)
256  tmp_stream = ffio_read_varlen(bc);
257  if (tmp_fields > 3)
258  tmp_size = ffio_read_varlen(bc);
259  else
260  tmp_size = 0;
261  if (tmp_fields > 4)
262  tmp_res = ffio_read_varlen(bc);
263  else
264  tmp_res = 0;
265  if (tmp_fields > 5)
266  count = ffio_read_varlen(bc);
267  else
268  count = tmp_mul - tmp_size;
269  if (tmp_fields > 6)
270  get_s(bc);
271  if (tmp_fields > 7)
272  tmp_head_idx = ffio_read_varlen(bc);
273 
274  while (tmp_fields-- > 8)
275  ffio_read_varlen(bc);
276 
277  if (count == 0 || i + count > 256) {
278  av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i);
279  return AVERROR_INVALIDDATA;
280  }
281  if (tmp_stream >= stream_count) {
282  av_log(s, AV_LOG_ERROR, "illegal stream number\n");
283  return AVERROR_INVALIDDATA;
284  }
285 
286  for (j = 0; j < count; j++, i++) {
287  if (i == 'N') {
288  nut->frame_code[i].flags = FLAG_INVALID;
289  j--;
290  continue;
291  }
292  nut->frame_code[i].flags = tmp_flags;
293  nut->frame_code[i].pts_delta = tmp_pts;
294  nut->frame_code[i].stream_id = tmp_stream;
295  nut->frame_code[i].size_mul = tmp_mul;
296  nut->frame_code[i].size_lsb = tmp_size + j;
297  nut->frame_code[i].reserved_count = tmp_res;
298  nut->frame_code[i].header_idx = tmp_head_idx;
299  }
300  }
301  assert(nut->frame_code['N'].flags == FLAG_INVALID);
302 
303  if (end > avio_tell(bc) + 4) {
304  int rem = 1024;
305  GET_V(nut->header_count, tmp < 128U);
306  nut->header_count++;
307  for (i = 1; i < nut->header_count; i++) {
308  uint8_t *hdr;
309  GET_V(nut->header_len[i], tmp > 0 && tmp < 256);
310  rem -= nut->header_len[i];
311  if (rem < 0) {
312  av_log(s, AV_LOG_ERROR, "invalid elision header\n");
313  return AVERROR_INVALIDDATA;
314  }
315  hdr = av_malloc(nut->header_len[i]);
316  if (!hdr)
317  return AVERROR(ENOMEM);
318  avio_read(bc, hdr, nut->header_len[i]);
319  nut->header[i] = hdr;
320  }
321  assert(nut->header_len[0] == 0);
322  }
323 
324  // flags had been effectively introduced in version 4
325  if (nut->version > NUT_STABLE_VERSION) {
326  nut->flags = ffio_read_varlen(bc);
327  }
328 
329  if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
330  av_log(s, AV_LOG_ERROR, "main header checksum mismatch\n");
331  return AVERROR_INVALIDDATA;
332  }
333 
334  nut->stream = av_mallocz(sizeof(StreamContext) * stream_count);
335  for (i = 0; i < stream_count; i++)
337 
338  return 0;
339 }
340 
342 {
343  AVFormatContext *s = nut->avf;
344  AVIOContext *bc = s->pb;
345  StreamContext *stc;
346  int class, stream_id;
347  uint64_t tmp, end;
348  AVStream *st;
349 
350  end = get_packetheader(nut, bc, 1, STREAM_STARTCODE);
351  end += avio_tell(bc);
352 
353  GET_V(stream_id, tmp < s->nb_streams && !nut->stream[tmp].time_base);
354  stc = &nut->stream[stream_id];
355  st = s->streams[stream_id];
356  if (!st)
357  return AVERROR(ENOMEM);
358 
359  class = ffio_read_varlen(bc);
360  tmp = get_fourcc(bc);
361  st->codec->codec_tag = tmp;
362  switch (class) {
363  case 0:
365  st->codec->codec_id = av_codec_get_id((const AVCodecTag * const []) {
368  0
369  },
370  tmp);
371  break;
372  case 1:
374  st->codec->codec_id = av_codec_get_id((const AVCodecTag * const []) {
377  0
378  },
379  tmp);
380  break;
381  case 2:
384  break;
385  case 3:
388  break;
389  default:
390  av_log(s, AV_LOG_ERROR, "unknown stream class (%d)\n", class);
391  return AVERROR(ENOSYS);
392  }
393  if (class < 3 && st->codec->codec_id == AV_CODEC_ID_NONE)
394  av_log(s, AV_LOG_ERROR,
395  "Unknown codec tag '0x%04x' for stream number %d\n",
396  (unsigned int) tmp, stream_id);
397 
398  GET_V(stc->time_base_id, tmp < nut->time_base_count);
399  GET_V(stc->msb_pts_shift, tmp < 16);
401  GET_V(stc->decode_delay, tmp < 1000); // sanity limit, raise this if Moore's law is true
402  st->codec->has_b_frames = stc->decode_delay;
403  ffio_read_varlen(bc); // stream flags
404 
405  GET_V(st->codec->extradata_size, tmp < (1 << 30));
406  if (st->codec->extradata_size) {
409  avio_read(bc, st->codec->extradata, st->codec->extradata_size);
410  }
411 
412  if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
413  GET_V(st->codec->width, tmp > 0);
414  GET_V(st->codec->height, tmp > 0);
417  if ((!st->sample_aspect_ratio.num) != (!st->sample_aspect_ratio.den)) {
418  av_log(s, AV_LOG_ERROR, "invalid aspect ratio %d/%d\n",
420  return AVERROR_INVALIDDATA;
421  }
422  ffio_read_varlen(bc); /* csp type */
423  } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
424  GET_V(st->codec->sample_rate, tmp > 0);
425  ffio_read_varlen(bc); // samplerate_den
426  GET_V(st->codec->channels, tmp > 0);
427  }
428  if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
429  av_log(s, AV_LOG_ERROR,
430  "stream header %d checksum mismatch\n", stream_id);
431  return AVERROR_INVALIDDATA;
432  }
433  stc->time_base = &nut->time_base[stc->time_base_id];
434  avpriv_set_pts_info(s->streams[stream_id], 63, stc->time_base->num,
435  stc->time_base->den);
436  return 0;
437 }
438 
439 static void set_disposition_bits(AVFormatContext *avf, char *value,
440  int stream_id)
441 {
442  int flag = 0, i;
443 
444  for (i = 0; ff_nut_dispositions[i].flag; ++i)
445  if (!strcmp(ff_nut_dispositions[i].str, value))
446  flag = ff_nut_dispositions[i].flag;
447  if (!flag)
448  av_log(avf, AV_LOG_INFO, "unknown disposition type '%s'\n", value);
449  for (i = 0; i < avf->nb_streams; ++i)
450  if (stream_id == i || stream_id == -1)
451  avf->streams[i]->disposition |= flag;
452 }
453 
455 {
456  AVFormatContext *s = nut->avf;
457  AVIOContext *bc = s->pb;
458  uint64_t tmp, chapter_start, chapter_len;
459  unsigned int stream_id_plus1, count;
460  int chapter_id, i;
461  int64_t value, end;
462  char name[256], str_value[1024], type_str[256];
463  const char *type;
464  int *event_flags;
465  AVChapter *chapter = NULL;
466  AVStream *st = NULL;
467  AVDictionary **metadata = NULL;
468  int metadata_flag = 0;
469 
470  end = get_packetheader(nut, bc, 1, INFO_STARTCODE);
471  end += avio_tell(bc);
472 
473  GET_V(stream_id_plus1, tmp <= s->nb_streams);
474  chapter_id = get_s(bc);
475  chapter_start = ffio_read_varlen(bc);
476  chapter_len = ffio_read_varlen(bc);
477  count = ffio_read_varlen(bc);
478 
479  if (chapter_id && !stream_id_plus1) {
480  int64_t start = chapter_start / nut->time_base_count;
481  chapter = avpriv_new_chapter(s, chapter_id,
482  nut->time_base[chapter_start %
483  nut->time_base_count],
484  start, start + chapter_len, NULL);
485  if (!chapter) {
486  av_log(s, AV_LOG_ERROR, "Could not create chapter.\n");
487  return AVERROR(ENOMEM);
488  }
489  metadata = &chapter->metadata;
490  } else if (stream_id_plus1) {
491  st = s->streams[stream_id_plus1 - 1];
492  metadata = &st->metadata;
493  event_flags = &st->event_flags;
494  metadata_flag = AVSTREAM_EVENT_FLAG_METADATA_UPDATED;
495  } else {
496  metadata = &s->metadata;
497  event_flags = &s->event_flags;
498  metadata_flag = AVFMT_EVENT_FLAG_METADATA_UPDATED;
499  }
500 
501  for (i = 0; i < count; i++) {
502  get_str(bc, name, sizeof(name));
503  value = get_s(bc);
504  if (value == -1) {
505  type = "UTF-8";
506  get_str(bc, str_value, sizeof(str_value));
507  } else if (value == -2) {
508  get_str(bc, type_str, sizeof(type_str));
509  type = type_str;
510  get_str(bc, str_value, sizeof(str_value));
511  } else if (value == -3) {
512  type = "s";
513  value = get_s(bc);
514  } else if (value == -4) {
515  type = "t";
516  value = ffio_read_varlen(bc);
517  } else if (value < -4) {
518  type = "r";
519  get_s(bc);
520  } else {
521  type = "v";
522  }
523 
524  if (stream_id_plus1 > s->nb_streams) {
525  av_log(s, AV_LOG_ERROR, "invalid stream id for info packet\n");
526  continue;
527  }
528 
529  if (!strcmp(type, "UTF-8")) {
530  if (chapter_id == 0 && !strcmp(name, "Disposition")) {
531  set_disposition_bits(s, str_value, stream_id_plus1 - 1);
532  continue;
533  }
534  if (metadata && av_strcasecmp(name, "Uses") &&
535  av_strcasecmp(name, "Depends") && av_strcasecmp(name, "Replaces")) {
536  *event_flags |= metadata_flag;
537  av_dict_set(metadata, name, str_value, 0);
538  }
539  }
540  }
541 
542  if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
543  av_log(s, AV_LOG_ERROR, "info header checksum mismatch\n");
544  return AVERROR_INVALIDDATA;
545  }
546  return 0;
547 }
548 
549 static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
550 {
551  AVFormatContext *s = nut->avf;
552  AVIOContext *bc = s->pb;
553  int64_t end, tmp;
554  int ret;
555 
556  nut->last_syncpoint_pos = avio_tell(bc) - 8;
557 
558  end = get_packetheader(nut, bc, 1, SYNCPOINT_STARTCODE);
559  end += avio_tell(bc);
560 
561  tmp = ffio_read_varlen(bc);
562  *back_ptr = nut->last_syncpoint_pos - 16 * ffio_read_varlen(bc);
563  if (*back_ptr < 0)
564  return -1;
565 
566  ff_nut_reset_ts(nut, nut->time_base[tmp % nut->time_base_count],
567  tmp / nut->time_base_count);
568 
569  if (nut->flags & NUT_BROADCAST) {
570  tmp = ffio_read_varlen(bc);
571  av_log(s, AV_LOG_VERBOSE, "Syncpoint wallclock %"PRId64"\n",
572  av_rescale_q(tmp / nut->time_base_count,
573  nut->time_base[tmp % nut->time_base_count],
574  AV_TIME_BASE_Q));
575  }
576 
577  if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
578  av_log(s, AV_LOG_ERROR, "sync point checksum mismatch\n");
579  return AVERROR_INVALIDDATA;
580  }
581 
582  *ts = tmp / s->nb_streams *
583  av_q2d(nut->time_base[tmp % s->nb_streams]) * AV_TIME_BASE;
584 
585  if ((ret = ff_nut_add_sp(nut, nut->last_syncpoint_pos, *back_ptr, *ts)) < 0)
586  return ret;
587 
588  return 0;
589 }
590 
592 {
593  AVFormatContext *s = nut->avf;
594  AVIOContext *bc = s->pb;
595  uint64_t tmp, end;
596  int i, j, syncpoint_count;
597  int64_t filesize = avio_size(bc);
598  int64_t *syncpoints;
599  int8_t *has_keyframe;
600  int ret = AVERROR_INVALIDDATA;
601 
602  avio_seek(bc, filesize - 12, SEEK_SET);
603  avio_seek(bc, filesize - avio_rb64(bc), SEEK_SET);
604  if (avio_rb64(bc) != INDEX_STARTCODE) {
605  av_log(s, AV_LOG_ERROR, "no index at the end\n");
606  return ret;
607  }
608 
609  end = get_packetheader(nut, bc, 1, INDEX_STARTCODE);
610  end += avio_tell(bc);
611 
612  ffio_read_varlen(bc); // max_pts
613  GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
614  syncpoints = av_malloc(sizeof(int64_t) * syncpoint_count);
615  has_keyframe = av_malloc(sizeof(int8_t) * (syncpoint_count + 1));
616  for (i = 0; i < syncpoint_count; i++) {
617  syncpoints[i] = ffio_read_varlen(bc);
618  if (syncpoints[i] <= 0)
619  goto fail;
620  if (i)
621  syncpoints[i] += syncpoints[i - 1];
622  }
623 
624  for (i = 0; i < s->nb_streams; i++) {
625  int64_t last_pts = -1;
626  for (j = 0; j < syncpoint_count;) {
627  uint64_t x = ffio_read_varlen(bc);
628  int type = x & 1;
629  int n = j;
630  x >>= 1;
631  if (type) {
632  int flag = x & 1;
633  x >>= 1;
634  if (n + x >= syncpoint_count + 1) {
635  av_log(s, AV_LOG_ERROR, "index overflow A\n");
636  goto fail;
637  }
638  while (x--)
639  has_keyframe[n++] = flag;
640  has_keyframe[n++] = !flag;
641  } else {
642  while (x != 1) {
643  if (n >= syncpoint_count + 1) {
644  av_log(s, AV_LOG_ERROR, "index overflow B\n");
645  goto fail;
646  }
647  has_keyframe[n++] = x & 1;
648  x >>= 1;
649  }
650  }
651  if (has_keyframe[0]) {
652  av_log(s, AV_LOG_ERROR, "keyframe before first syncpoint in index\n");
653  goto fail;
654  }
655  assert(n <= syncpoint_count + 1);
656  for (; j < n && j < syncpoint_count; j++) {
657  if (has_keyframe[j]) {
658  uint64_t B, A = ffio_read_varlen(bc);
659  if (!A) {
660  A = ffio_read_varlen(bc);
661  B = ffio_read_varlen(bc);
662  // eor_pts[j][i] = last_pts + A + B
663  } else
664  B = 0;
665  av_add_index_entry(s->streams[i], 16 * syncpoints[j - 1],
666  last_pts + A, 0, 0, AVINDEX_KEYFRAME);
667  last_pts += A + B;
668  }
669  }
670  }
671  }
672 
673  if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
674  av_log(s, AV_LOG_ERROR, "index checksum mismatch\n");
675  goto fail;
676  }
677  ret = 0;
678 
679 fail:
680  av_free(syncpoints);
681  av_free(has_keyframe);
682  return ret;
683 }
684 
686 {
687  NUTContext *nut = s->priv_data;
688  int i;
689 
690  av_freep(&nut->time_base);
691  av_freep(&nut->stream);
692  ff_nut_free_sp(nut);
693  for (i = 1; i < nut->header_count; i++)
694  av_freep(&nut->header[i]);
695 
696  return 0;
697 }
698 
700 {
701  NUTContext *nut = s->priv_data;
702  AVIOContext *bc = s->pb;
703  int64_t pos;
704  int initialized_stream_count;
705 
706  nut->avf = s;
707 
708  /* main header */
709  pos = 0;
710  do {
711  pos = find_startcode(bc, MAIN_STARTCODE, pos) + 1;
712  if (pos < 0 + 1) {
713  av_log(s, AV_LOG_ERROR, "No main startcode found.\n");
714  goto fail;
715  }
716  } while (decode_main_header(nut) < 0);
717 
718  /* stream headers */
719  pos = 0;
720  for (initialized_stream_count = 0; initialized_stream_count < s->nb_streams;) {
721  pos = find_startcode(bc, STREAM_STARTCODE, pos) + 1;
722  if (pos < 0 + 1) {
723  av_log(s, AV_LOG_ERROR, "Not all stream headers found.\n");
724  goto fail;
725  }
726  if (decode_stream_header(nut) >= 0)
727  initialized_stream_count++;
728  }
729 
730  /* info headers */
731  pos = 0;
732  for (;;) {
733  uint64_t startcode = find_any_startcode(bc, pos);
734  pos = avio_tell(bc);
735 
736  if (startcode == 0) {
737  av_log(s, AV_LOG_ERROR, "EOF before video frames\n");
738  goto fail;
739  } else if (startcode == SYNCPOINT_STARTCODE) {
740  nut->next_startcode = startcode;
741  break;
742  } else if (startcode != INFO_STARTCODE) {
743  continue;
744  }
745 
746  decode_info_header(nut);
747  }
748 
749  s->data_offset = pos - 8;
750 
751  if (bc->seekable) {
752  int64_t orig_pos = avio_tell(bc);
754  avio_seek(bc, orig_pos, SEEK_SET);
755  }
756  assert(nut->next_startcode == SYNCPOINT_STARTCODE);
757 
759 
760  return 0;
761 
762 fail:
763  nut_read_close(s);
764 
765  return AVERROR_INVALIDDATA;
766 }
767 
768 static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id,
769  uint8_t *header_idx, int frame_code)
770 {
771  AVFormatContext *s = nut->avf;
772  AVIOContext *bc = s->pb;
773  StreamContext *stc;
774  int size, flags, size_mul, pts_delta, i, reserved_count;
775  uint64_t tmp;
776 
777  if (!(nut->flags & NUT_PIPE) &&
778  avio_tell(bc) > nut->last_syncpoint_pos + nut->max_distance) {
779  av_log(s, AV_LOG_ERROR,
780  "Last frame must have been damaged %"PRId64" > %"PRId64" + %d\n",
781  avio_tell(bc), nut->last_syncpoint_pos, nut->max_distance);
782  return AVERROR_INVALIDDATA;
783  }
784 
785  flags = nut->frame_code[frame_code].flags;
786  size_mul = nut->frame_code[frame_code].size_mul;
787  size = nut->frame_code[frame_code].size_lsb;
788  *stream_id = nut->frame_code[frame_code].stream_id;
789  pts_delta = nut->frame_code[frame_code].pts_delta;
790  reserved_count = nut->frame_code[frame_code].reserved_count;
791  *header_idx = nut->frame_code[frame_code].header_idx;
792 
793  if (flags & FLAG_INVALID)
794  return AVERROR_INVALIDDATA;
795  if (flags & FLAG_CODED)
796  flags ^= ffio_read_varlen(bc);
797  if (flags & FLAG_STREAM_ID) {
798  GET_V(*stream_id, tmp < s->nb_streams);
799  }
800  stc = &nut->stream[*stream_id];
801  if (flags & FLAG_CODED_PTS) {
802  int coded_pts = ffio_read_varlen(bc);
803  // FIXME check last_pts validity?
804  if (coded_pts < (1 << stc->msb_pts_shift)) {
805  *pts = ff_lsb2full(stc, coded_pts);
806  } else
807  *pts = coded_pts - (1 << stc->msb_pts_shift);
808  } else
809  *pts = stc->last_pts + pts_delta;
810  if (flags & FLAG_SIZE_MSB)
811  size += size_mul * ffio_read_varlen(bc);
812  if (flags & FLAG_MATCH_TIME)
813  get_s(bc);
814  if (flags & FLAG_HEADER_IDX)
815  *header_idx = ffio_read_varlen(bc);
816  if (flags & FLAG_RESERVED)
817  reserved_count = ffio_read_varlen(bc);
818  for (i = 0; i < reserved_count; i++)
819  ffio_read_varlen(bc);
820 
821  if (*header_idx >= (unsigned)nut->header_count) {
822  av_log(s, AV_LOG_ERROR, "header_idx invalid\n");
823  return AVERROR_INVALIDDATA;
824  }
825  if (size > 4096)
826  *header_idx = 0;
827  size -= nut->header_len[*header_idx];
828 
829  if (flags & FLAG_CHECKSUM) {
830  avio_rb32(bc); // FIXME check this
831  } else if (!(nut->flags & NUT_PIPE) &&
832  size > 2 * nut->max_distance ||
833  FFABS(stc->last_pts - *pts) > stc->max_pts_distance) {
834  av_log(s, AV_LOG_ERROR, "frame size > 2max_distance and no checksum\n");
835  return AVERROR_INVALIDDATA;
836  }
837 
838  stc->last_pts = *pts;
839  stc->last_flags = flags;
840 
841  return size;
842 }
843 
844 static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code)
845 {
846  AVFormatContext *s = nut->avf;
847  AVIOContext *bc = s->pb;
848  int size, stream_id, discard, ret;
849  int64_t pts, last_IP_pts;
850  StreamContext *stc;
851  uint8_t header_idx;
852 
853  size = decode_frame_header(nut, &pts, &stream_id, &header_idx, frame_code);
854  if (size < 0)
855  return size;
856 
857  stc = &nut->stream[stream_id];
858 
859  if (stc->last_flags & FLAG_KEY)
860  stc->skip_until_key_frame = 0;
861 
862  discard = s->streams[stream_id]->discard;
863  last_IP_pts = s->streams[stream_id]->last_IP_pts;
864  if ((discard >= AVDISCARD_NONKEY && !(stc->last_flags & FLAG_KEY)) ||
865  (discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE &&
866  last_IP_pts > pts) ||
867  discard >= AVDISCARD_ALL ||
868  stc->skip_until_key_frame) {
869  avio_skip(bc, size);
870  return 1;
871  }
872 
873  ret = av_new_packet(pkt, size + nut->header_len[header_idx]);
874  if (ret < 0)
875  return ret;
876  memcpy(pkt->data, nut->header[header_idx], nut->header_len[header_idx]);
877  pkt->pos = avio_tell(bc); // FIXME
878  avio_read(bc, pkt->data + nut->header_len[header_idx], size);
879 
880  pkt->stream_index = stream_id;
881  if (stc->last_flags & FLAG_KEY)
882  pkt->flags |= AV_PKT_FLAG_KEY;
883  pkt->pts = pts;
884 
885  return 0;
886 }
887 
889 {
890  NUTContext *nut = s->priv_data;
891  AVIOContext *bc = s->pb;
892  int i, frame_code = 0, ret, skip;
893  int64_t ts, back_ptr;
894 
895  for (;;) {
896  int64_t pos = avio_tell(bc);
897  uint64_t tmp = nut->next_startcode;
898  nut->next_startcode = 0;
899 
900  if (tmp) {
901  pos -= 8;
902  } else {
903  frame_code = avio_r8(bc);
904  if (bc->eof_reached)
905  return AVERROR_EOF;
906  if (frame_code == 'N') {
907  tmp = frame_code;
908  for (i = 1; i < 8; i++)
909  tmp = (tmp << 8) + avio_r8(bc);
910  }
911  }
912  switch (tmp) {
913  case MAIN_STARTCODE:
914  case STREAM_STARTCODE:
915  case INDEX_STARTCODE:
916  skip = get_packetheader(nut, bc, 0, tmp);
917  avio_skip(bc, skip);
918  break;
919  case INFO_STARTCODE:
920  if (decode_info_header(nut) < 0)
921  goto resync;
922  break;
923  case SYNCPOINT_STARTCODE:
924  if (decode_syncpoint(nut, &ts, &back_ptr) < 0)
925  goto resync;
926  frame_code = avio_r8(bc);
927  case 0:
928  ret = decode_frame(nut, pkt, frame_code);
929  if (ret == 0)
930  return 0;
931  else if (ret == 1) // OK but discard packet
932  break;
933  default:
934 resync:
935  av_log(s, AV_LOG_DEBUG, "syncing from %"PRId64"\n", pos);
936  tmp = find_any_startcode(bc, nut->last_syncpoint_pos + 1);
937  if (tmp == 0)
938  return AVERROR_INVALIDDATA;
939  av_log(s, AV_LOG_DEBUG, "sync\n");
940  nut->next_startcode = tmp;
941  }
942  }
943 }
944 
945 static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index,
946  int64_t *pos_arg, int64_t pos_limit)
947 {
948  NUTContext *nut = s->priv_data;
949  AVIOContext *bc = s->pb;
950  int64_t pos, pts, back_ptr;
951  av_log(s, AV_LOG_DEBUG, "read_timestamp(X,%d,%"PRId64",%"PRId64")\n",
952  stream_index, *pos_arg, pos_limit);
953 
954  pos = *pos_arg;
955  do {
956  pos = find_startcode(bc, SYNCPOINT_STARTCODE, pos) + 1;
957  if (pos < 1) {
958  assert(nut->next_startcode == 0);
959  av_log(s, AV_LOG_ERROR, "read_timestamp failed.\n");
960  return AV_NOPTS_VALUE;
961  }
962  } while (decode_syncpoint(nut, &pts, &back_ptr) < 0);
963  *pos_arg = pos - 1;
964  assert(nut->last_syncpoint_pos == *pos_arg);
965 
966  av_log(s, AV_LOG_DEBUG, "return %"PRId64" %"PRId64"\n", pts, back_ptr);
967  if (stream_index == -1)
968  return pts;
969  else if (stream_index == -2)
970  return back_ptr;
971 
972  return AV_NOPTS_VALUE;
973 }
974 
975 static int read_seek(AVFormatContext *s, int stream_index,
976  int64_t pts, int flags)
977 {
978  NUTContext *nut = s->priv_data;
979  AVStream *st = s->streams[stream_index];
980  Syncpoint dummy = { .ts = pts * av_q2d(st->time_base) * AV_TIME_BASE };
981  Syncpoint nopts_sp = { .ts = AV_NOPTS_VALUE, .back_ptr = AV_NOPTS_VALUE };
982  Syncpoint *sp, *next_node[2] = { &nopts_sp, &nopts_sp };
983  int64_t pos, pos2, ts;
984  int i;
985 
986  if (nut->flags & NUT_PIPE) {
987  return AVERROR(ENOSYS);
988  }
989 
990  if (st->index_entries) {
991  int index = av_index_search_timestamp(st, pts, flags);
992  if (index < 0)
993  return -1;
994 
995  pos2 = st->index_entries[index].pos;
996  ts = st->index_entries[index].timestamp;
997  } else {
998  av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pts_cmp,
999  (void **) next_node);
1000  av_log(s, AV_LOG_DEBUG, "%"PRIu64"-%"PRIu64" %"PRId64"-%"PRId64"\n",
1001  next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
1002  next_node[1]->ts);
1003  pos = ff_gen_search(s, -1, dummy.ts, next_node[0]->pos,
1004  next_node[1]->pos, next_node[1]->pos,
1005  next_node[0]->ts, next_node[1]->ts,
1007 
1008  if (!(flags & AVSEEK_FLAG_BACKWARD)) {
1009  dummy.pos = pos + 16;
1010  next_node[1] = &nopts_sp;
1011  av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp,
1012  (void **) next_node);
1013  pos2 = ff_gen_search(s, -2, dummy.pos, next_node[0]->pos,
1014  next_node[1]->pos, next_node[1]->pos,
1015  next_node[0]->back_ptr, next_node[1]->back_ptr,
1016  flags, &ts, nut_read_timestamp);
1017  if (pos2 >= 0)
1018  pos = pos2;
1019  // FIXME dir but I think it does not matter
1020  }
1021  dummy.pos = pos;
1022  sp = av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp,
1023  NULL);
1024 
1025  assert(sp);
1026  pos2 = sp->back_ptr - 15;
1027  }
1028  av_log(NULL, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos2);
1029  pos = find_startcode(s->pb, SYNCPOINT_STARTCODE, pos2);
1030  avio_seek(s->pb, pos, SEEK_SET);
1031  av_log(NULL, AV_LOG_DEBUG, "SP: %"PRId64"\n", pos);
1032  if (pos2 > pos || pos2 + 15 < pos)
1033  av_log(NULL, AV_LOG_ERROR, "no syncpoint at backptr pos\n");
1034  for (i = 0; i < s->nb_streams; i++)
1035  nut->stream[i].skip_until_key_frame = 1;
1036 
1037  return 0;
1038 }
1039 
1041  .name = "nut",
1042  .long_name = NULL_IF_CONFIG_SMALL("NUT"),
1043  .priv_data_size = sizeof(NUTContext),
1044  .read_probe = nut_probe,
1048  .read_seek = read_seek,
1049  .extensions = "nut",
1050  .codec_tag = ff_nut_codec_tags,
1051 };
#define NUT_STABLE_VERSION
Definition: nut.h:40
#define AVSEEK_FLAG_BACKWARD
Definition: avformat.h:1609
uint8_t header_len[128]
Definition: nut.h:95
uint64_t ffio_read_varlen(AVIOContext *bc)
Definition: aviobuf.c:668
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:62
discard all frames except keyframes
Definition: avcodec.h:567
Bytestream IO Context.
Definition: avio.h:68
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
#define MAIN_STARTCODE
Definition: nut.h:29
void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition: metadata.c:59
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:241
#define AVSTREAM_EVENT_FLAG_METADATA_UPDATED
The call resulted in updated metadata.
Definition: avformat.h:819
int size
int64_t last_syncpoint_pos
Definition: nut.h:102
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:1181
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:1943
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:998
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:2829
int64_t pos
Definition: avformat.h:660
int event_flags
Flags for the user to detect events happening on the stream.
Definition: avformat.h:818
static int get_str(AVIOContext *bc, char *string, unsigned int maxlen)
Definition: nutdec.c:37
Definition: vf_drawbox.c:37
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:769
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:878
Definition: nut.h:57
#define NUT_MAX_STREAMS
Definition: nutdec.c:35
int64_t ts
Definition: nut.h:61
int event_flags
Flags for the user to detect events happening on the file.
Definition: avformat.h:1200
static void set_disposition_bits(AVFormatContext *avf, char *value, int stream_id)
Definition: nutdec.c:439
int64_t data_offset
offset of the first packet
Definition: avformat.h:1220
discard all
Definition: avcodec.h:568
Definition: nut.h:89
uint8_t stream_id
Definition: nut.h:66
AVDictionary * metadata
Definition: avformat.h:909
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:198
const uint8_t * header[128]
Definition: nut.h:96
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:2601
Format I/O context.
Definition: avformat.h:922
static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id, uint8_t *header_idx, int frame_code)
Definition: nutdec.c:768
if set, reserved_count is coded in the frame header
Definition: nut.h:50
static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos_arg, int64_t pos_limit)
Definition: nutdec.c:945
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:41
uint8_t
AVRational * time_base
Definition: nut.h:104
Opaque data information usually continuous.
Definition: avutil.h:189
int decode_delay
Definition: nut.h:82
uint16_t flags
Definition: nut.h:65
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:595
#define NUT_MAX_VERSION
Definition: nut.h:39
if set, coded_pts is in the frame header
Definition: nut.h:46
#define STREAM_STARTCODE
Definition: nut.h:30
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1164
const char * name
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:2521
#define NUT_PIPE
Definition: nut.h:107
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:990
If set, match_time_delta is coded in the frame header.
Definition: nut.h:52
const AVMetadataConv ff_nut_metadata_conv[]
Definition: nut.c:237
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
uint8_t * data
Definition: avcodec.h:973
int last_flags
Definition: nut.h:75
static int flags
Definition: log.c:44
static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code)
Definition: nutdec.c:844
#define AVERROR_EOF
End of file.
Definition: error.h:51
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:139
const AVCodecTag ff_nut_data_tags[]
Definition: nut.c:36
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:660
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:219
#define B
Definition: huffyuv.h:49
int ff_nut_sp_pos_cmp(const Syncpoint *a, const Syncpoint *b)
Definition: nut.c:182
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:452
AVFormatContext * avf
Definition: nut.h:91
int64_t last_pts
Definition: nut.h:77
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1019
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:129
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:81
#define AVINDEX_KEYFRAME
Definition: avformat.h:662
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1130
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:1355
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:186
void ff_nut_free_sp(NUTContext *nut)
Definition: nut.c:221
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
Definition: utils.c:1222
#define NUT_BROADCAST
Definition: nut.h:106
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:564
discard all bidirectional frames
Definition: avcodec.h:566
#define AVERROR(e)
Definition: error.h:43
uint64_t pos
Definition: nut.h:58
int64_t timestamp
Definition: avformat.h:661
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:145
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
Definition: graph2dot.c:49
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:169
static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: nutdec.c:888
const AVCodecTag ff_nut_audio_tags[]
Definition: nut.c:131
int header_count
Definition: nut.h:103
AVRational * time_base
Definition: nut.h:79
#define NUT_MIN_VERSION
Definition: nut.h:41
static int decode_stream_header(NUTContext *nut)
Definition: nutdec.c:341
#define av_be2ne64(x)
Definition: bswap.h:96
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:353
if set, frame is keyframe
Definition: nut.h:44
int ff_nut_sp_pts_cmp(const Syncpoint *a, const Syncpoint *b)
Definition: nut.c:187
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:979
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:443
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:718
static int nut_read_close(AVFormatContext *s)
Definition: nutdec.c:685
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:398
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:397
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:531
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:978
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:431
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:164
int flags
Definition: nut.h:108
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:234
#define FFMIN(a, b)
Definition: common.h:57
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:29
int av_strcasecmp(const char *a, const char *b)
Definition: avstring.c:156
uint8_t header_idx
Definition: nut.h:71
static int read_probe(AVProbeData *pd)
Definition: jvdec.c:55
int width
picture width / height.
Definition: avcodec.h:1229
static uint64_t find_any_startcode(AVIOContext *bc, int64_t pos)
Definition: nutdec.c:125
uint16_t size_lsb
Definition: nut.h:68
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:69
static int find_and_decode_index(NUTContext *nut)
Definition: nutdec.c:591
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:175
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
if set, frame_code is invalid
Definition: nut.h:54
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
#define AVFMT_EVENT_FLAG_METADATA_UPDATED
The call resulted in updated metadata.
Definition: avformat.h:1201
#define FFABS(a)
Definition: common.h:52
struct AVTreeNode * syncpoints
Definition: nut.h:105
if set, data_size_msb is at frame header, otherwise data_size_msb is 0
Definition: nut.h:48
AVDictionary * metadata
Definition: avformat.h:771
static int nut_read_header(AVFormatContext *s)
Definition: nutdec.c:699
if set, the frame header contains a checksum
Definition: nut.h:49
#define INDEX_STARTCODE
Definition: nut.h:32
uint16_t size_mul
Definition: nut.h:67
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:544
if(ac->has_optimized_func)
static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
Definition: nutdec.c:549
Stream structure.
Definition: avformat.h:699
int msb_pts_shift
Definition: nut.h:80
NULL
Definition: eval.c:55
#define AV_LOG_INFO
Standard information.
Definition: log.h:134
enum AVMediaType codec_type
Definition: avcodec.h:1058
const AVCodecTag ff_nut_subtitle_tags[]
Definition: nut.c:28
enum AVCodecID codec_id
Definition: avcodec.h:1067
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:240
int sample_rate
samples per second
Definition: avcodec.h:1807
AVIOContext * pb
I/O context.
Definition: avformat.h:964
int max_pts_distance
Definition: nut.h:81
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
Definition: avcodec.h:1082
if set, coded_flags are stored in the frame header
Definition: nut.h:53
int extradata_size
Definition: avcodec.h:1165
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:68
#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:1295
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:423
StreamContext * stream
Definition: nut.h:98
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:395
static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
Definition: nutdec.c:975
Definition: vf_drawbox.c:37
#define INFO_STARTCODE
Definition: nut.h:33
static uint32_t state
Definition: trasher.c:27
int version
Definition: nut.h:109
int skip_until_key_frame
Definition: nut.h:76
const Dispositions ff_nut_dispositions[]
Definition: nut.c:227
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:404
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:548
uint64_t next_startcode
stores the next startcode if it has already been parsed but the stream is not seekable ...
Definition: nut.h:97
static int decode_info_header(NUTContext *nut)
Definition: nutdec.c:454
FrameCode frame_code[256]
Definition: nut.h:94
int disposition
AV_DISPOSITION_* bit field.
Definition: avformat.h:760
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:192
int den
denominator
Definition: rational.h:45
#define SYNCPOINT_STARTCODE
Definition: nut.h:31
int flag
Definition: nut.h:121
int eof_reached
true if eof reached
Definition: avio.h:96
If set, header_idx is coded in the frame header.
Definition: nut.h:51
int len
AVInputFormat ff_nut_demuxer
Definition: nutdec.c:1040
int channels
number of audio channels
Definition: avcodec.h:1808
static int64_t get_s(AVIOContext *bc)
Definition: nutdec.c:57
void * priv_data
Format private data.
Definition: avformat.h:950
int time_base_id
Definition: nut.h:78
int64_t last_IP_pts
Definition: avformat.h:852
if set, stream_id is coded in the frame header
Definition: nut.h:47
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:525
int stream_index
Definition: avcodec.h:975
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:741
uint64_t back_ptr
Definition: nut.h:59
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:762
const AVCodecTag *const ff_nut_codec_tags[]
Definition: nut.c:159
This structure stores compressed data.
Definition: avcodec.h:950
unsigned int time_base_count
Definition: nut.h:101
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:205
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:966
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:228
uint8_t reserved_count
Definition: nut.h:70
unsigned int max_distance
Definition: nut.h:100