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