FFmpeg
asfdec_o.c
Go to the documentation of this file.
1 /*
2  * Microsoft Advanced Streaming Format demuxer
3  * Copyright (c) 2014 Alexandra Hájková
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/attributes.h"
23 #include "libavutil/common.h"
24 #include "libavutil/dict.h"
25 #include "libavutil/internal.h"
26 #include "libavutil/mathematics.h"
28 
29 #include "avformat.h"
30 #include "avio_internal.h"
31 #include "avlanguage.h"
32 #include "internal.h"
33 #include "riff.h"
34 #include "asf.h"
35 #include "asfcrypt.h"
36 
37 #define ASF_BOOL 0x2
38 #define ASF_WORD 0x5
39 #define ASF_GUID 0x6
40 #define ASF_DWORD 0x3
41 #define ASF_QWORD 0x4
42 #define ASF_UNICODE 0x0
43 #define ASF_FLAG_BROADCAST 0x1
44 #define ASF_BYTE_ARRAY 0x1
45 #define ASF_TYPE_AUDIO 0x2
46 #define ASF_TYPE_VIDEO 0x1
47 #define ASF_STREAM_NUM 0x7F
48 #define ASF_MAX_STREAMS 128
49 #define BMP_HEADER_SIZE 40
50 #define ASF_NUM_OF_PAYLOADS 0x3F
51 #define ASF_ERROR_CORRECTION_LENGTH_TYPE 0x60
52 #define ASF_PACKET_ERROR_CORRECTION_DATA_SIZE 0x2
53 
54 typedef struct GUIDParseTable {
55  const char *name;
60 
61 typedef struct ASFPacket {
63  int64_t dts;
64  uint32_t frame_num; // ASF payloads with the same number are parts of the same frame
65  int flags;
66  int data_size;
67  int duration;
68  int size_left;
70 } ASFPacket;
71 
72 typedef struct ASFStream {
73  uint8_t stream_index; // from packet header
74  int index; // stream index in AVFormatContext, set in asf_read_stream_properties
75  int type;
76  int indexed; // added index entries from the Simple Index Object or not
77  int8_t span; // for deinterleaving
78  uint16_t virtual_pkt_len;
80  int16_t lang_idx;
82 } ASFStream;
83 
84 typedef struct ASFStreamData{
85  char langs[32];
86  AVDictionary *asf_met; // for storing per-stream metadata
89 
90 typedef struct ASFContext {
92  int is_simple_index; // is simple index present or not 1/0
93  int is_header;
94 
95  uint64_t preroll;
96  uint64_t nb_packets; // ASF packets
97  uint32_t packet_size;
98  int64_t send_time;
99  int duration;
100 
101  uint32_t b_flags; // flags with broadcast flag
102  uint32_t prop_flags; // file properties object flags
103 
104  uint64_t data_size; // data object size
105  uint64_t unknown_size; // size of the unknown object
106 
107  int64_t offset; // offset of the current object
108 
109  int64_t data_offset;
110  int64_t first_packet_offset; // packet offset
111  int64_t unknown_offset; // for top level header objects or subobjects without specified behavior
112 
113  // ASF file must not contain more than 128 streams according to the specification
117 
118  int stream_index; // from packet header, for the subpayload case
119 
120  // packet parameters
121  uint64_t sub_header_offset; // offset of subpayload header
122  int64_t sub_dts;
123  uint8_t dts_delta; // for subpayloads
124  uint32_t packet_size_internal; // packet size stored inside ASFPacket, can be 0
125  int64_t packet_offset; // offset of the current packet inside Data Object
126  uint32_t pad_len; // padding after payload
127  uint32_t rep_data_len;
128 
129  // packet state
130  uint64_t sub_left; // subpayloads left or not
131  unsigned int nb_sub; // number of subpayloads read so far from the current ASF packet
132  uint16_t mult_sub_len; // total length of subpayloads array inside multiple payload
133  uint64_t nb_mult_left; // multiple payloads left
135  enum {
140  } state;
141 } ASFContext;
142 
143 static int detect_unknown_subobject(AVFormatContext *s, int64_t offset, int64_t size);
144 static const GUIDParseTable *find_guid(ff_asf_guid guid);
145 
146 static int asf_probe(const AVProbeData *pd)
147 {
148  /* check file header */
149  if (!ff_guidcmp(pd->buf, &ff_asf_header))
150  return AVPROBE_SCORE_MAX/2;
151  else
152  return 0;
153 }
154 
155 static void swap_guid(ff_asf_guid guid)
156 {
157  FFSWAP(unsigned char, guid[0], guid[3]);
158  FFSWAP(unsigned char, guid[1], guid[2]);
159  FFSWAP(unsigned char, guid[4], guid[5]);
160  FFSWAP(unsigned char, guid[6], guid[7]);
161 }
162 
163 static void align_position(AVIOContext *pb, int64_t offset, uint64_t size)
164 {
165  if (size < INT64_MAX - offset && avio_tell(pb) != offset + size)
166  avio_seek(pb, offset + size, SEEK_SET);
167 }
168 
170 {
171  ASFContext *asf = s->priv_data;
172  AVIOContext *pb = s->pb;
173  uint64_t size = avio_rl64(pb);
174  int ret;
175 
176  if (size > INT64_MAX)
177  return AVERROR_INVALIDDATA;
178 
179  if (asf->is_header)
180  asf->unknown_size = size;
181  asf->is_header = 0;
182  if (!g->is_subobject) {
183  if (!(ret = strcmp(g->name, "Header Extension")))
184  avio_skip(pb, 22); // skip reserved fields and Data Size
186  asf->unknown_size)) < 0)
187  return ret;
188  } else {
189  if (size < 24) {
190  av_log(s, AV_LOG_ERROR, "Too small size %"PRIu64" (< 24).\n", size);
191  return AVERROR_INVALIDDATA;
192  }
193  avio_skip(pb, size - 24);
194  }
195 
196  return 0;
197 }
198 
199 static int get_asf_string(AVIOContext *pb, int maxlen, char *buf, int buflen)
200 {
201  char *q = buf;
202  int ret = 0;
203  if (buflen <= 0)
204  return AVERROR(EINVAL);
205  while (ret + 1 < maxlen) {
206  uint8_t tmp;
207  uint32_t ch;
208  GET_UTF16(ch, (ret += 2) <= maxlen ? avio_rl16(pb) : 0, break;);
209  PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)
210  }
211  *q = 0;
212 
213  return ret;
214 }
215 
217 {
218  ASFContext *asf = s->priv_data;
219  AVIOContext *pb = s->pb;
220  uint64_t size = avio_rl64(pb);
221  int i, nb_markers, ret;
222  size_t len;
223  char name[1024];
224 
225  avio_skip(pb, 8);
226  avio_skip(pb, 8); // skip reserved GUID
227  nb_markers = avio_rl32(pb);
228  avio_skip(pb, 2); // skip reserved field
229  len = avio_rl16(pb);
230  for (i = 0; i < len; i++)
231  avio_skip(pb, 1);
232 
233  for (i = 0; i < nb_markers; i++) {
234  int64_t pts;
235 
236  avio_skip(pb, 8);
237  pts = avio_rl64(pb);
238  pts -= asf->preroll * 10000;
239  avio_skip(pb, 2); // entry length
240  avio_skip(pb, 4); // send time
241  avio_skip(pb, 4); // flags
242  len = avio_rl32(pb);
243 
244  if (avio_feof(pb))
245  return AVERROR_INVALIDDATA;
246 
247  if ((ret = avio_get_str16le(pb, len, name,
248  sizeof(name))) < len)
249  avio_skip(pb, len - ret);
250  avpriv_new_chapter(s, i, (AVRational) { 1, 10000000 }, pts,
252  }
253  align_position(pb, asf->offset, size);
254 
255  return 0;
256 }
257 
258 static int asf_read_metadata(AVFormatContext *s, const char *title, uint16_t len,
259  unsigned char *ch, uint16_t buflen)
260 {
261  AVIOContext *pb = s->pb;
262 
263  avio_get_str16le(pb, len, ch, buflen);
264  if (ch[0]) {
265  if (av_dict_set(&s->metadata, title, ch, 0) < 0)
266  av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");
267  }
268 
269  return 0;
270 }
271 
273  uint16_t val_len, int type, AVDictionary **met)
274 {
275  int ret;
276  uint8_t *value;
277  uint16_t buflen = 2 * val_len + 1;
278  AVIOContext *pb = s->pb;
279 
280  value = av_malloc(buflen);
281  if (!value)
282  return AVERROR(ENOMEM);
283  if (type == ASF_UNICODE) {
284  // get_asf_string reads UTF-16 and converts it to UTF-8 which needs longer buffer
285  if ((ret = get_asf_string(pb, val_len, value, buflen)) < 0)
286  goto failed;
287  if (av_dict_set(met, name, value, 0) < 0)
288  av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");
289  } else {
290  char buf[256];
291  if (val_len > sizeof(buf)) {
293  goto failed;
294  }
295  if ((ret = avio_read(pb, value, val_len)) < 0)
296  goto failed;
297  if (ret < 2 * val_len)
298  value[ret] = '\0';
299  else
300  value[2 * val_len - 1] = '\0';
301  snprintf(buf, sizeof(buf), "%s", value);
302  if (av_dict_set(met, name, buf, 0) < 0)
303  av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");
304  }
305  av_freep(&value);
306 
307  return 0;
308 
309 failed:
310  av_freep(&value);
311  return ret;
312 }
313 static int asf_read_generic_value(AVIOContext *pb, int type, uint64_t *value)
314 {
315 
316  switch (type) {
317  case ASF_BOOL:
318  *value = avio_rl16(pb);
319  break;
320  case ASF_DWORD:
321  *value = avio_rl32(pb);
322  break;
323  case ASF_QWORD:
324  *value = avio_rl64(pb);
325  break;
326  case ASF_WORD:
327  *value = avio_rl16(pb);
328  break;
329  default:
330  return AVERROR_INVALIDDATA;
331  }
332 
333  return 0;
334 }
335 
337  int type, AVDictionary **met)
338 {
339  AVIOContext *pb = s->pb;
340  uint64_t value;
341  char buf[32];
342  int ret;
343 
345  if (ret < 0)
346  return ret;
347 
348  snprintf(buf, sizeof(buf), "%"PRIu64, value);
349  if (av_dict_set(met, name, buf, 0) < 0)
350  av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");
351 
352  return 0;
353 }
354 
355 static int process_metadata(AVFormatContext *s, const uint8_t *name, uint16_t name_len,
356  uint16_t val_len, uint16_t type, AVDictionary **met)
357 {
358  int ret;
359  ff_asf_guid guid;
360 
361  if (val_len) {
362  switch (type) {
363  case ASF_UNICODE:
364  asf_read_value(s, name, val_len, type, met);
365  break;
366  case ASF_BYTE_ARRAY:
367  if (ff_asf_handle_byte_array(s, name, val_len) > 0)
368  asf_read_value(s, name, val_len, type, met);
369  break;
370  case ASF_GUID:
371  ff_get_guid(s->pb, &guid);
372  break;
373  default:
374  if ((ret = asf_set_metadata(s, name, type, met)) < 0)
375  return ret;
376  break;
377  }
378  }
379 
380  return 0;
381 }
382 
384 {
385  ASFContext *asf = s->priv_data;
386  AVIOContext *pb = s->pb;
387  uint64_t size = avio_rl64(pb);
388  uint16_t nb_desc = avio_rl16(pb);
389  int i, ret;
390 
391  for (i = 0; i < nb_desc; i++) {
392  uint16_t name_len, type, val_len;
393  uint8_t *name = NULL;
394 
395  name_len = avio_rl16(pb);
396  if (!name_len)
397  return AVERROR_INVALIDDATA;
398  name = av_malloc(name_len);
399  if (!name)
400  return AVERROR(ENOMEM);
401  avio_get_str16le(pb, name_len, name,
402  name_len);
403  type = avio_rl16(pb);
404  // BOOL values are 16 bits long in the Metadata Object
405  // but 32 bits long in the Extended Content Description Object
406  if (type == ASF_BOOL)
407  type = ASF_DWORD;
408  val_len = avio_rl16(pb);
409 
410  ret = process_metadata(s, name, name_len, val_len, type, &s->metadata);
411  av_freep(&name);
412  if (ret < 0)
413  return ret;
414  }
415 
416  align_position(pb, asf->offset, size);
417  return 0;
418 }
419 
420 static AVStream *find_stream(AVFormatContext *s, uint16_t st_num)
421 {
422  AVStream *st = NULL;
423  ASFContext *asf = s->priv_data;
424  int i;
425 
426  for (i = 0; i < asf->nb_streams; i++) {
427  if (asf->asf_st[i]->stream_index == st_num) {
428  st = s->streams[asf->asf_st[i]->index];
429  break;
430  }
431  }
432 
433  return st;
434 }
435 
437 {
438  ASFContext *asf = s->priv_data;
439  AVIOContext *pb = s->pb;
440  uint64_t value = 0;
441  int ret;
442 
444  if (ret < 0)
445  return ret;
446 
447  if (st_num < ASF_MAX_STREAMS) {
448  if (!strcmp(name, "AspectRatioX"))
449  asf->asf_sd[st_num].aspect_ratio.num = value;
450  else
451  asf->asf_sd[st_num].aspect_ratio.den = value;
452  }
453  return 0;
454 }
455 
457 {
458  ASFContext *asf = s->priv_data;
459  AVIOContext *pb = s->pb;
460  uint64_t size = avio_rl64(pb);
461  uint16_t nb_recs = avio_rl16(pb); // number of records in the Description Records list
462  int i, ret;
463 
464  for (i = 0; i < nb_recs; i++) {
465  uint16_t name_len, buflen, type, val_len, st_num;
466  uint8_t *name = NULL;
467 
468  avio_skip(pb, 2); // skip reserved field
469  st_num = avio_rl16(pb);
470  name_len = avio_rl16(pb);
471  buflen = 2 * name_len + 1;
472  if (!name_len)
473  break;
474  type = avio_rl16(pb);
475  val_len = avio_rl32(pb);
476  name = av_malloc(buflen);
477  if (!name)
478  return AVERROR(ENOMEM);
479  avio_get_str16le(pb, name_len, name,
480  buflen);
481  if (!strcmp(name, "AspectRatioX") || !strcmp(name, "AspectRatioY")) {
482  ret = asf_store_aspect_ratio(s, st_num, name, type);
483  if (ret < 0) {
484  av_freep(&name);
485  break;
486  }
487  } else {
488  if (st_num < ASF_MAX_STREAMS) {
489  if ((ret = process_metadata(s, name, name_len, val_len, type,
490  st_num ? &asf->asf_sd[st_num].asf_met
491  : &s->metadata)) < 0) {
492  av_freep(&name);
493  break;
494  }
495  }
496  }
497  av_freep(&name);
498  }
499 
500  align_position(pb, asf->offset, size);
501  return 0;
502 }
503 
505 {
506  ASFContext *asf = s->priv_data;
507  AVIOContext *pb = s->pb;
508  int i;
509  static const char *const titles[] =
510  { "Title", "Author", "Copyright", "Description", "Rate" };
511  uint16_t len[5], buflen[5] = { 0 };
512  uint8_t *ch;
513  uint64_t size = avio_rl64(pb);
514 
515  for (i = 0; i < 5; i++) {
516  len[i] = avio_rl16(pb);
517  // utf8 string should be <= 2 * utf16 string, extra byte for the terminator
518  buflen[i] = 2 * len[i] + 1;
519  }
520 
521  for (i = 0; i < 5; i++) {
522  ch = av_malloc(buflen[i]);
523  if (!ch)
524  return(AVERROR(ENOMEM));
525  asf_read_metadata(s, titles[i], len[i], ch, buflen[i]);
526  av_freep(&ch);
527  }
528  align_position(pb, asf->offset, size);
529 
530  return 0;
531 }
532 
534 {
535  ASFContext *asf = s->priv_data;
536  AVIOContext *pb = s->pb;
537  time_t creation_time;
538 
539  avio_rl64(pb); // read object size
540  avio_skip(pb, 16); // skip File ID
541  avio_skip(pb, 8); // skip File size
542  creation_time = avio_rl64(pb);
543  if (!(asf->b_flags & ASF_FLAG_BROADCAST)) {
544  struct tm tmbuf;
545  struct tm *tm;
546  char buf[64];
547 
548  // creation date is in 100 ns units from 1 Jan 1601, conversion to s
549  creation_time /= 10000000;
550  // there are 11644473600 seconds between 1 Jan 1601 and 1 Jan 1970
551  creation_time -= 11644473600;
552  tm = gmtime_r(&creation_time, &tmbuf);
553  if (tm) {
554  if (!strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm))
555  buf[0] = '\0';
556  } else
557  buf[0] = '\0';
558  if (buf[0]) {
559  if (av_dict_set(&s->metadata, "creation_time", buf, 0) < 0)
560  av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");
561  }
562  }
563  asf->nb_packets = avio_rl64(pb);
564  asf->duration = avio_rl64(pb) / 10000; // stream duration
565  avio_skip(pb, 8); // skip send duration
566  asf->preroll = avio_rl64(pb);
567  asf->duration -= asf->preroll;
568  asf->b_flags = avio_rl32(pb);
569  avio_skip(pb, 4); // skip minimal packet size
570  asf->packet_size = avio_rl32(pb);
571  avio_skip(pb, 4); // skip max_bitrate
572 
573  return 0;
574 }
575 
577 {
578  uint16_t size_asf; // ASF-specific Format Data size
579  uint32_t size_bmp; // BMP_HEADER-specific Format Data size
580  unsigned int tag;
581 
582  st->codecpar->width = avio_rl32(pb);
583  st->codecpar->height = avio_rl32(pb);
584  avio_skip(pb, 1); // skip reserved flags
585  size_asf = avio_rl16(pb);
586  tag = ff_get_bmp_header(pb, st, &size_bmp);
587  st->codecpar->codec_tag = tag;
589  size_bmp = FFMAX(size_asf, size_bmp);
590 
591  if (size_bmp > BMP_HEADER_SIZE &&
592  size_bmp < INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
593  int ret;
594  st->codecpar->extradata_size = size_bmp - BMP_HEADER_SIZE;
597  st->codecpar->extradata_size = 0;
598  return AVERROR(ENOMEM);
599  }
600  memset(st->codecpar->extradata + st->codecpar->extradata_size , 0,
602  if ((ret = avio_read(pb, st->codecpar->extradata,
603  st->codecpar->extradata_size)) < 0)
604  return ret;
605  }
606  return 0;
607 }
608 
610 {
611  ASFContext *asf = s->priv_data;
612  AVIOContext *pb = s->pb;
613  uint64_t size;
614  uint32_t err_data_len, ts_data_len; // type specific data length
615  uint16_t flags;
616  ff_asf_guid stream_type;
617  enum AVMediaType type;
618  int i, ret;
619  uint8_t stream_index;
620  AVStream *st;
621  ASFStream *asf_st;
622 
623  // ASF file must not contain more than 128 streams according to the specification
624  if (asf->nb_streams >= ASF_MAX_STREAMS)
625  return AVERROR_INVALIDDATA;
626 
627  size = avio_rl64(pb);
628  ff_get_guid(pb, &stream_type);
629  if (!ff_guidcmp(&stream_type, &ff_asf_audio_stream))
631  else if (!ff_guidcmp(&stream_type, &ff_asf_video_stream))
633  else if (!ff_guidcmp(&stream_type, &ff_asf_jfif_media))
635  else if (!ff_guidcmp(&stream_type, &ff_asf_command_stream))
637  else if (!ff_guidcmp(&stream_type,
640  else
641  return AVERROR_INVALIDDATA;
642 
643  ff_get_guid(pb, &stream_type); // error correction type
644  avio_skip(pb, 8); // skip the time offset
645  ts_data_len = avio_rl32(pb);
646  err_data_len = avio_rl32(pb);
647  flags = avio_rl16(pb); // bit 15 - Encrypted Content
648 
649  stream_index = flags & ASF_STREAM_NUM;
650  for (i = 0; i < asf->nb_streams; i++)
651  if (stream_index == asf->asf_st[i]->stream_index) {
653  "Duplicate stream found, this stream will be ignored.\n");
654  align_position(pb, asf->offset, size);
655  return 0;
656  }
657 
658  st = avformat_new_stream(s, NULL);
659  if (!st)
660  return AVERROR(ENOMEM);
661  avpriv_set_pts_info(st, 32, 1, 1000); // pts should be dword, in milliseconds
662  st->codecpar->codec_type = type;
663  asf->asf_st[asf->nb_streams] = av_mallocz(sizeof(*asf_st));
664  if (!asf->asf_st[asf->nb_streams])
665  return AVERROR(ENOMEM);
666  asf_st = asf->asf_st[asf->nb_streams];
667  asf->nb_streams++;
668  asf_st->stream_index = stream_index;
669  asf_st->index = st->index;
670  asf_st->indexed = 0;
671  st->id = flags & ASF_STREAM_NUM;
672  asf_st->pkt.data_size = 0;
673  asf_st->pkt.avpkt = av_packet_alloc();
674  if (!asf_st->pkt.avpkt)
675  return AVERROR(ENOMEM);
676  avio_skip(pb, 4); // skip reserved field
677 
678  switch (type) {
679  case AVMEDIA_TYPE_AUDIO:
680  asf_st->type = AVMEDIA_TYPE_AUDIO;
681  if ((ret = ff_get_wav_header(s, pb, st->codecpar, ts_data_len, 0)) < 0)
682  return ret;
683  break;
684  case AVMEDIA_TYPE_VIDEO:
685  asf_st->type = AVMEDIA_TYPE_VIDEO;
686  if ((ret = parse_video_info(pb, st)) < 0)
687  return ret;
688  break;
689  default:
690  avio_skip(pb, ts_data_len);
691  break;
692  }
693 
694  if (err_data_len) {
695  if (type == AVMEDIA_TYPE_AUDIO) {
696  uint8_t span = avio_r8(pb);
697  if (span > 1) {
698  asf_st->span = span;
699  asf_st->virtual_pkt_len = avio_rl16(pb);
700  asf_st->virtual_chunk_len = avio_rl16(pb);
701  if (!asf_st->virtual_chunk_len || !asf_st->virtual_pkt_len)
702  return AVERROR_INVALIDDATA;
703  avio_skip(pb, err_data_len - 5);
704  } else
705  avio_skip(pb, err_data_len - 1);
706  } else
707  avio_skip(pb, err_data_len);
708  }
709 
710  align_position(pb, asf->offset, size);
711 
712  return 0;
713 }
714 
715 static void set_language(AVFormatContext *s, const char *rfc1766, AVDictionary **met)
716 {
717  // language abbr should contain at least 2 chars
718  if (rfc1766 && strlen(rfc1766) > 1) {
719  const char primary_tag[3] = { rfc1766[0], rfc1766[1], '\0' }; // ignore country code if any
720  const char *iso6392 = ff_convert_lang_to(primary_tag,
722  if (iso6392)
723  if (av_dict_set(met, "language", iso6392, 0) < 0)
724  av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");
725  }
726 }
727 
729 {
730  ASFContext *asf = s->priv_data;
731  AVIOContext *pb = s->pb;
732  AVStream *st = NULL;
733  ff_asf_guid guid;
734  uint16_t nb_st_name, nb_pay_exts, st_num, lang_idx;
735  int i, ret;
736  uint32_t bitrate;
737  uint64_t start_time, end_time, time_per_frame;
738  uint64_t size = avio_rl64(pb);
739 
740  start_time = avio_rl64(pb);
741  end_time = avio_rl64(pb);
742  bitrate = avio_rl32(pb);
743  avio_skip(pb, 28); // skip some unused values
744  st_num = avio_rl16(pb);
745  st_num &= ASF_STREAM_NUM;
746  lang_idx = avio_rl16(pb); // Stream Language ID Index
747  if (lang_idx >= ASF_MAX_STREAMS)
748  return AVERROR_INVALIDDATA;
749  for (i = 0; i < asf->nb_streams; i++) {
750  if (st_num == asf->asf_st[i]->stream_index) {
751  st = s->streams[asf->asf_st[i]->index];
752  asf->asf_st[i]->lang_idx = lang_idx;
753  break;
754  }
755  }
756  time_per_frame = avio_rl64(pb); // average time per frame
757  if (st) {
758  st->start_time = start_time;
759  st->duration = end_time - start_time;
760  st->codecpar->bit_rate = bitrate;
761  st->avg_frame_rate.num = 10000000;
762  st->avg_frame_rate.den = time_per_frame;
763  }
764  nb_st_name = avio_rl16(pb);
765  nb_pay_exts = avio_rl16(pb);
766  for (i = 0; i < nb_st_name; i++) {
767  uint16_t len;
768 
769  avio_rl16(pb); // Language ID Index
770  len = avio_rl16(pb);
771  avio_skip(pb, len);
772  }
773 
774  for (i = 0; i < nb_pay_exts; i++) {
775  uint32_t len;
776  avio_skip(pb, 16); // Extension System ID
777  avio_skip(pb, 2); // Extension Data Size
778  len = avio_rl32(pb);
779  avio_skip(pb, len);
780  }
781 
782  if ((ret = ff_get_guid(pb, &guid)) < 0) {
783  align_position(pb, asf->offset, size);
784 
785  return 0;
786  }
787 
788  g = find_guid(guid);
789  if (g && !(strcmp(g->name, "Stream Properties"))) {
790  if ((ret = g->read_object(s, g)) < 0)
791  return ret;
792  }
793 
794  align_position(pb, asf->offset, size);
795  return 0;
796 }
797 
799 {
800  ASFContext *asf = s->priv_data;
801  AVIOContext *pb = s->pb;
802  int i, ret;
803  uint64_t size = avio_rl64(pb);
804  uint16_t nb_langs = avio_rl16(pb);
805 
806  if (nb_langs < ASF_MAX_STREAMS) {
807  for (i = 0; i < nb_langs; i++) {
808  size_t len;
809  len = avio_r8(pb);
810  if (!len)
811  len = 6;
812  if ((ret = get_asf_string(pb, len, asf->asf_sd[i].langs,
813  sizeof(asf->asf_sd[i].langs))) < 0) {
814  return ret;
815  }
816  }
817  }
818 
819  align_position(pb, asf->offset, size);
820  return 0;
821 }
822 
823 // returns data object offset when reading this object for the first time
825 {
826  ASFContext *asf = s->priv_data;
827  AVIOContext *pb = s->pb;
828  uint64_t size = asf->data_size = avio_rl64(pb);
829  int i;
830 
831  if (!asf->data_reached) {
832  asf->data_reached = 1;
833  asf->data_offset = asf->offset;
834  }
835 
836  for (i = 0; i < asf->nb_streams; i++) {
837  if (!(asf->b_flags & ASF_FLAG_BROADCAST))
838  s->streams[i]->duration = asf->duration;
839  }
840  asf->nb_mult_left = 0;
841  asf->sub_left = 0;
842  asf->state = PARSE_PACKET_HEADER;
843  asf->return_subpayload = 0;
844  asf->packet_size_internal = 0;
845  avio_skip(pb, 16); // skip File ID
846  size = avio_rl64(pb); // Total Data Packets
847  if (size != asf->nb_packets)
849  "Number of Packets from File Properties Object is not equal to Total"
850  "Datapackets value! num of packets %"PRIu64" total num %"PRIu64".\n",
851  size, asf->nb_packets);
852  avio_skip(pb, 2); // skip reserved field
853  asf->first_packet_offset = avio_tell(pb);
854  if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !(asf->b_flags & ASF_FLAG_BROADCAST))
855  align_position(pb, asf->offset, asf->data_size);
856 
857  return 0;
858 }
859 
861 {
862  ASFContext *asf = s->priv_data;
863  AVIOContext *pb = s->pb;
864  AVStream *st = NULL;
865  uint64_t interval; // index entry time interval in 100 ns units, usually it's 1s
866  uint32_t pkt_num, nb_entries;
867  int32_t prev_pkt_num = -1;
868  int i;
869  int64_t offset;
870  uint64_t size = avio_rl64(pb);
871 
872  // simple index objects should be ordered by stream number, this loop tries to find
873  // the first not indexed video stream
874  for (i = 0; i < asf->nb_streams; i++) {
875  if ((asf->asf_st[i]->type == AVMEDIA_TYPE_VIDEO) && !asf->asf_st[i]->indexed) {
876  asf->asf_st[i]->indexed = 1;
877  st = s->streams[asf->asf_st[i]->index];
878  break;
879  }
880  }
881  if (!st) {
882  avio_skip(pb, size - 24); // if there's no video stream, skip index object
883  return 0;
884  }
885  avio_skip(pb, 16); // skip File ID
886  interval = avio_rl64(pb);
887  avio_skip(pb, 4);
888  nb_entries = avio_rl32(pb);
889  for (i = 0; i < nb_entries; i++) {
890  pkt_num = avio_rl32(pb);
891  offset = avio_skip(pb, 2);
892  if (offset < 0) {
893  av_log(s, AV_LOG_ERROR, "Skipping failed in asf_read_simple_index.\n");
894  return offset;
895  }
896  if (prev_pkt_num != pkt_num) {
898  pkt_num, av_rescale(interval, i, 10000),
899  asf->packet_size, 0, AVINDEX_KEYFRAME);
900  prev_pkt_num = pkt_num;
901  }
902  }
903  asf->is_simple_index = 1;
904  align_position(pb, asf->offset, size);
905 
906  return 0;
907 }
908 
909 static const GUIDParseTable gdef[] = {
910  { "Data", { 0x75, 0xB2, 0x26, 0x36, 0x66, 0x8E, 0x11, 0xCF, 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C }, asf_read_data, 1 },
911  { "Simple Index", { 0x33, 0x00, 0x08, 0x90, 0xE5, 0xB1, 0x11, 0xCF, 0x89, 0xF4, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xCB }, asf_read_simple_index, 1 },
912  { "Content Description", { 0x75, 0xB2, 0x26, 0x33, 0x66 ,0x8E, 0x11, 0xCF, 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C }, asf_read_content_desc, 1 },
913  { "Extended Content Description", { 0xD2, 0xD0, 0xA4, 0x40, 0xE3, 0x07, 0x11, 0xD2, 0x97, 0xF0, 0x00, 0xA0, 0xC9, 0x5e, 0xA8, 0x50 }, asf_read_ext_content, 1 },
914  { "Stream Bitrate Properties", { 0x7B, 0xF8, 0x75, 0xCE, 0x46, 0x8D, 0x11, 0xD1, 0x8D, 0x82, 0x00, 0x60, 0x97, 0xC9, 0xA2, 0xB2 }, asf_read_unknown, 1 },
915  { "File Properties", { 0x8C, 0xAB, 0xDC, 0xA1, 0xA9, 0x47, 0x11, 0xCF, 0x8E, 0xE4, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 }, asf_read_properties, 1 },
916  { "Header Extension", { 0x5F, 0xBF, 0x03, 0xB5, 0xA9, 0x2E, 0x11, 0xCF, 0x8E, 0xE3, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 }, asf_read_unknown, 0 },
917  { "Stream Properties", { 0xB7, 0xDC, 0x07, 0x91, 0xA9, 0xB7, 0x11, 0xCF, 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 }, asf_read_stream_properties, 1 },
918  { "Codec List", { 0x86, 0xD1, 0x52, 0x40, 0x31, 0x1D, 0x11, 0xD0, 0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6 }, asf_read_unknown, 1 },
919  { "Marker", { 0xF4, 0x87, 0xCD, 0x01, 0xA9, 0x51, 0x11, 0xCF, 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 }, asf_read_marker, 1 },
920  { "Script Command", { 0x1E, 0xFB, 0x1A, 0x30, 0x0B, 0x62, 0x11, 0xD0, 0xA3, 0x9B, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6 }, asf_read_unknown, 1 },
921  { "Language List", { 0x7C, 0x43, 0x46, 0xa9, 0xef, 0xe0, 0x4B, 0xFC, 0xB2, 0x29, 0x39, 0x3e, 0xde, 0x41, 0x5c, 0x85 }, asf_read_language_list, 1},
922  { "Padding", { 0x18, 0x06, 0xD4, 0x74, 0xCA, 0xDF, 0x45, 0x09, 0xA4, 0xBA, 0x9A, 0xAB, 0xCB, 0x96, 0xAA, 0xE8 }, asf_read_unknown, 1 },
923  { "DRMv1 Header", { 0x22, 0x11, 0xB3, 0xFB, 0xBD, 0x23, 0x11, 0xD2, 0xB4, 0xB7, 0x00, 0xA0, 0xC9, 0x55, 0xFC, 0x6E }, asf_read_unknown, 1 },
924  { "DRMv2 Header", { 0x29, 0x8A, 0xE6, 0x14, 0x26, 0x22, 0x4C, 0x17, 0xB9, 0x35, 0xDA, 0xE0, 0x7E, 0xE9, 0x28, 0x9c }, asf_read_unknown, 1 },
925  { "Index", { 0xD6, 0xE2, 0x29, 0xD3, 0x35, 0xDA, 0x11, 0xD1, 0x90, 0x34, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xBE }, asf_read_unknown, 1 },
926  { "Media Object Index", { 0xFE, 0xB1, 0x03, 0xF8, 0x12, 0xAD, 0x4C, 0x64, 0x84, 0x0F, 0x2A, 0x1D, 0x2F, 0x7A, 0xD4, 0x8C }, asf_read_unknown, 1 },
927  { "Timecode Index", { 0x3C, 0xB7, 0x3F, 0xD0, 0x0C, 0x4A, 0x48, 0x03, 0x95, 0x3D, 0xED, 0xF7, 0xB6, 0x22, 0x8F, 0x0C }, asf_read_unknown, 0 },
928  { "Bitrate_Mutual_Exclusion", { 0xD6, 0xE2, 0x29, 0xDC, 0x35, 0xDA, 0x11, 0xD1, 0x90, 0x34, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xBE }, asf_read_unknown, 1 },
929  { "Error Correction", { 0x75, 0xB2, 0x26, 0x35, 0x66, 0x8E, 0x11, 0xCF, 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C }, asf_read_unknown, 1 },
930  { "Content Branding", { 0x22, 0x11, 0xB3, 0xFA, 0xBD, 0x23, 0x11, 0xD2, 0xB4, 0xB7, 0x00, 0xA0, 0xC9, 0x55, 0xFC, 0x6E }, asf_read_unknown, 1 },
931  { "Content Encryption", { 0x22, 0x11, 0xB3, 0xFB, 0xBD, 0x23, 0x11, 0xD2, 0xB4, 0xB7, 0x00, 0xA0, 0xC9, 0x55, 0xFC, 0x6E }, asf_read_unknown, 1 },
932  { "Extended Content Encryption", { 0x29, 0x8A, 0xE6, 0x14, 0x26, 0x22, 0x4C, 0x17, 0xB9, 0x35, 0xDA, 0xE0, 0x7E, 0xE9, 0x28, 0x9C }, asf_read_unknown, 1 },
933  { "Digital Signature", { 0x22, 0x11, 0xB3, 0xFC, 0xBD, 0x23, 0x11, 0xD2, 0xB4, 0xB7, 0x00, 0xA0, 0xC9, 0x55, 0xFC, 0x6E }, asf_read_unknown, 1 },
934  { "Extended Stream Properties", { 0x14, 0xE6, 0xA5, 0xCB, 0xC6, 0x72, 0x43, 0x32, 0x83, 0x99, 0xA9, 0x69, 0x52, 0x06, 0x5B, 0x5A }, asf_read_ext_stream_properties, 1 },
935  { "Advanced Mutual Exclusion", { 0xA0, 0x86, 0x49, 0xCF, 0x47, 0x75, 0x46, 0x70, 0x8A, 0x16, 0x6E, 0x35, 0x35, 0x75, 0x66, 0xCD }, asf_read_unknown, 1 },
936  { "Group Mutual Exclusion", { 0xD1, 0x46, 0x5A, 0x40, 0x5A, 0x79, 0x43, 0x38, 0xB7, 0x1B, 0xE3, 0x6B, 0x8F, 0xD6, 0xC2, 0x49 }, asf_read_unknown, 1},
937  { "Stream Prioritization", { 0xD4, 0xFE, 0xD1, 0x5B, 0x88, 0xD3, 0x45, 0x4F, 0x81, 0xF0, 0xED, 0x5C, 0x45, 0x99, 0x9E, 0x24 }, asf_read_unknown, 1 },
938  { "Bandwidth Sharing Object", { 0xA6, 0x96, 0x09, 0xE6, 0x51, 0x7B, 0x11, 0xD2, 0xB6, 0xAF, 0x00, 0xC0, 0x4F, 0xD9, 0x08, 0xE9 }, asf_read_unknown, 1 },
939  { "Metadata", { 0xC5, 0xF8, 0xCB, 0xEA, 0x5B, 0xAF, 0x48, 0x77, 0x84, 0x67, 0xAA, 0x8C, 0x44, 0xFA, 0x4C, 0xCA }, asf_read_metadata_obj, 1 },
940  { "Metadata Library", { 0x44, 0x23, 0x1C, 0x94, 0x94, 0x98, 0x49, 0xD1, 0xA1, 0x41, 0x1D, 0x13, 0x4E, 0x45, 0x70, 0x54 }, asf_read_metadata_obj, 1 },
941  { "Audio Spread", { 0xBF, 0xC3, 0xCD, 0x50, 0x61, 0x8F, 0x11, 0xCF, 0x8B, 0xB2, 0x00, 0xAA, 0x00, 0xB4, 0xE2, 0x20 }, asf_read_unknown, 1 },
942  { "Index Parameters", { 0xD6, 0xE2, 0x29, 0xDF, 0x35, 0xDA, 0x11, 0xD1, 0x90, 0x34, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xBE }, asf_read_unknown, 1 },
943  { "Content Encryption System Windows Media DRM Network Devices",
944  { 0x7A, 0x07, 0x9B, 0xB6, 0xDA, 0XA4, 0x4e, 0x12, 0xA5, 0xCA, 0x91, 0xD3, 0x8D, 0xC1, 0x1A, 0x8D }, asf_read_unknown, 1 },
945  { "Mutex Language", { 0xD6, 0xE2, 0x2A, 0x00, 0x25, 0xDA, 0x11, 0xD1, 0x90, 0x34, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xBE }, asf_read_unknown, 1 },
946  { "Mutex Bitrate", { 0xD6, 0xE2, 0x2A, 0x01, 0x25, 0xDA, 0x11, 0xD1, 0x90, 0x34, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xBE }, asf_read_unknown, 1 },
947  { "Mutex Unknown", { 0xD6, 0xE2, 0x2A, 0x02, 0x25, 0xDA, 0x11, 0xD1, 0x90, 0x34, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xBE }, asf_read_unknown, 1 },
948  { "Bandwidth Sharing Exclusive", { 0xAF, 0x60, 0x60, 0xAA, 0x51, 0x97, 0x11, 0xD2, 0xB6, 0xAF, 0x00, 0xC0, 0x4F, 0xD9, 0x08, 0xE9 }, asf_read_unknown, 1 },
949  { "Bandwidth Sharing Partial", { 0xAF, 0x60, 0x60, 0xAB, 0x51, 0x97, 0x11, 0xD2, 0xB6, 0xAF, 0x00, 0xC0, 0x4F, 0xD9, 0x08, 0xE9 }, asf_read_unknown, 1 },
950  { "Payload Extension System Timecode", { 0x39, 0x95, 0x95, 0xEC, 0x86, 0x67, 0x4E, 0x2D, 0x8F, 0xDB, 0x98, 0x81, 0x4C, 0xE7, 0x6C, 0x1E }, asf_read_unknown, 1 },
951  { "Payload Extension System File Name", { 0xE1, 0x65, 0xEC, 0x0E, 0x19, 0xED, 0x45, 0xD7, 0xB4, 0xA7, 0x25, 0xCB, 0xD1, 0xE2, 0x8E, 0x9B }, asf_read_unknown, 1 },
952  { "Payload Extension System Content Type", { 0xD5, 0x90, 0xDC, 0x20, 0x07, 0xBC, 0x43, 0x6C, 0x9C, 0xF7, 0xF3, 0xBB, 0xFB, 0xF1, 0xA4, 0xDC }, asf_read_unknown, 1 },
953  { "Payload Extension System Pixel Aspect Ratio", { 0x1, 0x1E, 0xE5, 0x54, 0xF9, 0xEA, 0x4B, 0xC8, 0x82, 0x1A, 0x37, 0x6B, 0x74, 0xE4, 0xC4, 0xB8 }, asf_read_unknown, 1 },
954  { "Payload Extension System Sample Duration", { 0xC6, 0xBD, 0x94, 0x50, 0x86, 0x7F, 0x49, 0x07, 0x83, 0xA3, 0xC7, 0x79, 0x21, 0xB7, 0x33, 0xAD }, asf_read_unknown, 1 },
955  { "Payload Extension System Encryption Sample ID", { 0x66, 0x98, 0xB8, 0x4E, 0x0A, 0xFA, 0x43, 0x30, 0xAE, 0xB2, 0x1C, 0x0A, 0x98, 0xD7, 0xA4, 0x4D }, asf_read_unknown, 1 },
956  { "Payload Extension System Degradable JPEG", { 0x00, 0xE1, 0xAF, 0x06, 0x7B, 0xEC, 0x11, 0xD1, 0xA5, 0x82, 0x00, 0xC0, 0x4F, 0xC2, 0x9C, 0xFB }, asf_read_unknown, 1 },
957 };
958 
959 #define READ_LEN(flag, name, len) \
960  do { \
961  if ((flag) == name ## IS_BYTE) \
962  len = avio_r8(pb); \
963  else if ((flag) == name ## IS_WORD) \
964  len = avio_rl16(pb); \
965  else if ((flag) == name ## IS_DWORD) \
966  len = avio_rl32(pb); \
967  else \
968  len = 0; \
969  } while(0)
970 
971 static int asf_read_subpayload(AVFormatContext *s, AVPacket *pkt, int is_header)
972 {
973  ASFContext *asf = s->priv_data;
974  AVIOContext *pb = s->pb;
975  uint8_t sub_len;
976  int ret, i;
977 
978  if (is_header) {
979  asf->dts_delta = avio_r8(pb);
980  if (asf->nb_mult_left) {
981  asf->mult_sub_len = avio_rl16(pb); // total
982  }
983  asf->sub_header_offset = avio_tell(pb);
984  asf->nb_sub = 0;
985  asf->sub_left = 1;
986  }
987  sub_len = avio_r8(pb);
988  if ((ret = av_get_packet(pb, pkt, sub_len)) < 0) // each subpayload is entire frame
989  return ret;
990  for (i = 0; i < asf->nb_streams; i++) {
991  if (asf->stream_index == asf->asf_st[i]->stream_index) {
992  pkt->stream_index = asf->asf_st[i]->index;
993  break;
994  }
995  }
996  asf->return_subpayload = 1;
997  if (!sub_len)
998  asf->return_subpayload = 0;
999 
1000  if (sub_len)
1001  asf->nb_sub++;
1002  pkt->dts = asf->sub_dts + (asf->nb_sub - 1) * asf->dts_delta - asf->preroll;
1003  if (asf->nb_mult_left && (avio_tell(pb) >=
1004  (asf->sub_header_offset + asf->mult_sub_len))) {
1005  asf->sub_left = 0;
1006  asf->nb_mult_left--;
1007  }
1008  if (avio_tell(pb) >= asf->packet_offset + asf->packet_size - asf->pad_len) {
1009  asf->sub_left = 0;
1010  if (!asf->nb_mult_left) {
1011  avio_skip(pb, asf->pad_len);
1012  if (avio_tell(pb) != asf->packet_offset + asf->packet_size) {
1013  if (!asf->packet_size)
1014  return AVERROR_INVALIDDATA;
1016  "Position %"PRId64" wrong, should be %"PRId64"\n",
1017  avio_tell(pb), asf->packet_offset + asf->packet_size);
1018  avio_seek(pb, asf->packet_offset + asf->packet_size, SEEK_SET);
1019  }
1020  }
1021  }
1022 
1023  return 0;
1024 }
1025 
1026 static void reset_packet(ASFPacket *asf_pkt)
1027 {
1028  asf_pkt->size_left = 0;
1029  asf_pkt->data_size = 0;
1030  asf_pkt->duration = 0;
1031  asf_pkt->flags = 0;
1032  asf_pkt->dts = 0;
1033  av_packet_unref(asf_pkt->avpkt);
1034 }
1035 
1037 {
1038  ASFContext *asf = s->priv_data;
1039  AVIOContext *pb = s->pb;
1040  int ret, data_size;
1041 
1042  if (!asf_pkt->data_size) {
1043  data_size = avio_rl32(pb); // read media object size
1044  if (data_size <= 0)
1045  return AVERROR_INVALIDDATA;
1046  if ((ret = av_new_packet(asf_pkt->avpkt, data_size)) < 0)
1047  return ret;
1048  asf_pkt->data_size = asf_pkt->size_left = data_size;
1049  } else
1050  avio_skip(pb, 4); // reading of media object size is already done
1051  asf_pkt->dts = avio_rl32(pb); // read presentation time
1052  if (asf->rep_data_len >= 8)
1053  avio_skip(pb, asf->rep_data_len - 8); // skip replicated data
1054 
1055  return 0;
1056 }
1057 
1059  ASFPacket *asf_pkt)
1060 {
1061  ASFContext *asf = s->priv_data;
1062  AVIOContext *pb = s->pb;
1063  uint16_t pay_len;
1064  unsigned char *p;
1065  int ret;
1066  int skip = 0;
1067 
1068  // if replicated length is 1, subpayloads are present
1069  if (asf->rep_data_len == 1) {
1070  asf->sub_left = 1;
1071  asf->state = READ_MULTI_SUB;
1072  pkt->flags = asf_pkt->flags;
1073  if ((ret = asf_read_subpayload(s, pkt, 1)) < 0)
1074  return ret;
1075  } else {
1076  if (asf->rep_data_len)
1077  if ((ret = asf_read_replicated_data(s, asf_pkt)) < 0)
1078  return ret;
1079  pay_len = avio_rl16(pb); // payload length should be WORD
1080  if (pay_len > asf->packet_size) {
1082  "Error: invalid data packet size, pay_len %"PRIu16", "
1083  "asf->packet_size %"PRIu32", offset %"PRId64".\n",
1084  pay_len, asf->packet_size, avio_tell(pb));
1085  return AVERROR_INVALIDDATA;
1086  }
1087  p = asf_pkt->avpkt->data + asf_pkt->data_size - asf_pkt->size_left;
1088  if (pay_len > asf_pkt->size_left) {
1090  "Error: invalid buffer size, pay_len %d, data size left %d.\n",
1091  pay_len, asf_pkt->size_left);
1092  skip = pay_len - asf_pkt->size_left;
1093  pay_len = asf_pkt->size_left;
1094  }
1095  if (asf_pkt->size_left <= 0)
1096  return AVERROR_INVALIDDATA;
1097  if ((ret = avio_read(pb, p, pay_len)) < 0)
1098  return ret;
1099  if (s->key && s->keylen == 20)
1100  ff_asfcrypt_dec(s->key, p, ret);
1101  avio_skip(pb, skip);
1102  asf_pkt->size_left -= pay_len;
1103  asf->nb_mult_left--;
1104  }
1105 
1106  return 0;
1107 }
1108 
1110 {
1111  ASFContext *asf = s->priv_data;
1112  AVIOContext *pb = s->pb;
1113  int64_t offset;
1114  uint64_t size;
1115  unsigned char *p;
1116  int ret, data_size;
1117 
1118  if (!asf_pkt->data_size) {
1119  data_size = avio_rl32(pb); // read media object size
1120  if (data_size <= 0)
1121  return AVERROR_EOF;
1122  if ((ret = av_new_packet(asf_pkt->avpkt, data_size)) < 0)
1123  return ret;
1124  asf_pkt->data_size = asf_pkt->size_left = data_size;
1125  } else
1126  avio_skip(pb, 4); // skip media object size
1127  asf_pkt->dts = avio_rl32(pb); // read presentation time
1128  if (asf->rep_data_len >= 8)
1129  avio_skip(pb, asf->rep_data_len - 8); // skip replicated data
1130  offset = avio_tell(pb);
1131 
1132  // size of the payload - size of the packet without header and padding
1133  if (asf->packet_size_internal)
1134  size = asf->packet_size_internal - offset + asf->packet_offset - asf->pad_len;
1135  else
1136  size = asf->packet_size - offset + asf->packet_offset - asf->pad_len;
1137  if (size > asf->packet_size) {
1139  "Error: invalid data packet size, offset %"PRId64".\n",
1140  avio_tell(pb));
1141  return AVERROR_INVALIDDATA;
1142  }
1143  p = asf_pkt->avpkt->data + asf_pkt->data_size - asf_pkt->size_left;
1144  if (size > asf_pkt->size_left || asf_pkt->size_left <= 0)
1145  return AVERROR_INVALIDDATA;
1146  if (asf_pkt->size_left > size)
1147  asf_pkt->size_left -= size;
1148  else
1149  asf_pkt->size_left = 0;
1150  if ((ret = avio_read(pb, p, size)) < 0)
1151  return ret;
1152  if (s->key && s->keylen == 20)
1153  ff_asfcrypt_dec(s->key, p, ret);
1154  if (asf->packet_size_internal)
1155  avio_skip(pb, asf->packet_size - asf->packet_size_internal);
1156  avio_skip(pb, asf->pad_len); // skip padding
1157 
1158  return 0;
1159 }
1160 
1162 {
1163  ASFContext *asf = s->priv_data;
1164  AVIOContext *pb = s->pb;
1165  int ret, i;
1166  ASFPacket *asf_pkt = NULL;
1167 
1168  if (!asf->sub_left) {
1169  uint32_t off_len, media_len;
1170  uint8_t stream_num;
1171 
1172  stream_num = avio_r8(pb);
1173  asf->stream_index = stream_num & ASF_STREAM_NUM;
1174  for (i = 0; i < asf->nb_streams; i++) {
1175  if (asf->stream_index == asf->asf_st[i]->stream_index) {
1176  asf_pkt = &asf->asf_st[i]->pkt;
1177  asf_pkt->stream_index = asf->asf_st[i]->index;
1178  break;
1179  }
1180  }
1181  if (!asf_pkt) {
1182  if (asf->packet_offset + asf->packet_size <= asf->data_offset + asf->data_size) {
1183  if (!asf->packet_size) {
1184  av_log(s, AV_LOG_ERROR, "Invalid packet size 0.\n");
1185  return AVERROR_INVALIDDATA;
1186  }
1187  avio_seek(pb, asf->packet_offset + asf->packet_size, SEEK_SET);
1188  av_log(s, AV_LOG_WARNING, "Skipping the stream with the invalid stream index %d.\n",
1189  asf->stream_index);
1190  return AVERROR(EAGAIN);
1191  } else
1192  return AVERROR_INVALIDDATA;
1193  }
1194 
1195  if (stream_num >> 7)
1196  asf_pkt->flags |= AV_PKT_FLAG_KEY;
1198  ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_, media_len);
1200  ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_, off_len);
1202  ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_, asf->rep_data_len);
1203  if (asf_pkt->size_left && (asf_pkt->frame_num != media_len)) {
1204  av_log(s, AV_LOG_WARNING, "Unfinished frame will be ignored\n");
1205  reset_packet(asf_pkt);
1206  }
1207  asf_pkt->frame_num = media_len;
1208  asf->sub_dts = off_len;
1209  if (asf->nb_mult_left) {
1210  if ((ret = asf_read_multiple_payload(s, pkt, asf_pkt)) < 0)
1211  return ret;
1212  } else if (asf->rep_data_len == 1) {
1213  asf->sub_left = 1;
1214  asf->state = READ_SINGLE;
1215  pkt->flags = asf_pkt->flags;
1216  if ((ret = asf_read_subpayload(s, pkt, 1)) < 0)
1217  return ret;
1218  } else {
1219  if ((ret = asf_read_single_payload(s, asf_pkt)) < 0)
1220  return ret;
1221  }
1222  } else {
1223  for (i = 0; i <= asf->nb_streams; i++) {
1224  if (asf->stream_index == asf->asf_st[i]->stream_index) {
1225  asf_pkt = &asf->asf_st[i]->pkt;
1226  break;
1227  }
1228  }
1229  if (!asf_pkt)
1230  return AVERROR_INVALIDDATA;
1231  pkt->flags = asf_pkt->flags;
1232  pkt->dts = asf_pkt->dts;
1233  pkt->stream_index = asf->asf_st[i]->index;
1234  if ((ret = asf_read_subpayload(s, pkt, 0)) < 0) // read subpayload without its header
1235  return ret;
1236  }
1237 
1238  return 0;
1239 }
1240 
1242 {
1243  ASFContext *asf = s->priv_data;
1244  AVIOContext *pb = s->pb;
1245  uint64_t size;
1246  uint32_t av_unused seq;
1247  unsigned char error_flags, len_flags, pay_flags;
1248 
1249  asf->packet_offset = avio_tell(pb);
1250  error_flags = avio_r8(pb); // read Error Correction Flags
1251  if (error_flags & ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT) {
1252  if (!(error_flags & ASF_ERROR_CORRECTION_LENGTH_TYPE)) {
1254  avio_skip(pb, size);
1255  }
1256  len_flags = avio_r8(pb);
1257  } else
1258  len_flags = error_flags;
1259  asf->prop_flags = avio_r8(pb);
1261  ASF_PPI_FLAG_PACKET_LENGTH_FIELD_, asf->packet_size_internal);
1263  ASF_PPI_FLAG_SEQUENCE_FIELD_, seq);
1265  ASF_PPI_FLAG_PADDING_LENGTH_FIELD_, asf->pad_len );
1266  asf->send_time = avio_rl32(pb); // send time
1267  avio_skip(pb, 2); // skip duration
1268  if (len_flags & ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT) { // Multiple Payloads present
1269  pay_flags = avio_r8(pb);
1270  asf->nb_mult_left = (pay_flags & ASF_NUM_OF_PAYLOADS);
1271  }
1272 
1273  return 0;
1274 }
1275 
1276 static int asf_deinterleave(AVFormatContext *s, ASFPacket *asf_pkt, int st_num)
1277 {
1278  ASFContext *asf = s->priv_data;
1279  ASFStream *asf_st = asf->asf_st[st_num];
1280  unsigned char *p = asf_pkt->avpkt->data;
1281  uint16_t pkt_len = asf->asf_st[st_num]->virtual_pkt_len;
1282  uint16_t chunk_len = asf->asf_st[st_num]->virtual_chunk_len;
1283  int nchunks = pkt_len / chunk_len;
1284  uint8_t *data;
1285  int pos = 0, j, l, ret;
1286 
1287 
1289  if (!data)
1290  return AVERROR(ENOMEM);
1291  memset(data + asf_pkt->data_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
1292 
1293  while (asf_pkt->data_size >= asf_st->span * pkt_len + pos) {
1294  if (pos >= asf_pkt->data_size) {
1295  break;
1296  }
1297  for (l = 0; l < pkt_len; l++) {
1298  if (pos >= asf_pkt->data_size) {
1299  break;
1300  }
1301  for (j = 0; j < asf_st->span; j++) {
1302  if ((pos + chunk_len) >= asf_pkt->data_size)
1303  break;
1304  memcpy(data + pos,
1305  p + (j * nchunks + l) * chunk_len,
1306  chunk_len);
1307  pos += chunk_len;
1308  }
1309  }
1310  p += asf_st->span * pkt_len;
1311  if (p > asf_pkt->avpkt->data + asf_pkt->data_size)
1312  break;
1313  }
1314  av_packet_unref(asf_pkt->avpkt);
1315  ret = av_packet_from_data(asf_pkt->avpkt, data, asf_pkt->data_size);
1316  if (ret < 0)
1317  av_free(data);
1318 
1319  return ret;
1320 }
1321 
1323 {
1324  ASFContext *asf = s->priv_data;
1325  AVIOContext *pb = s->pb;
1326  int ret, i;
1327 
1328  if ((avio_tell(pb) >= asf->data_offset + asf->data_size) &&
1329  !(asf->b_flags & ASF_FLAG_BROADCAST))
1330  return AVERROR_EOF;
1331  while (!pb->eof_reached) {
1332  if (asf->state == PARSE_PACKET_HEADER) {
1334  if (pb->eof_reached)
1335  break;
1336  if (!asf->nb_mult_left)
1337  asf->state = READ_SINGLE;
1338  else
1339  asf->state = READ_MULTI;
1340  }
1341  ret = asf_read_payload(s, pkt);
1342  if (ret == AVERROR(EAGAIN)) {
1343  asf->state = PARSE_PACKET_HEADER;
1344  continue;
1345  }
1346  else if (ret < 0)
1347  return ret;
1348 
1349  switch (asf->state) {
1350  case READ_SINGLE:
1351  if (!asf->sub_left)
1352  asf->state = PARSE_PACKET_HEADER;
1353  break;
1354  case READ_MULTI_SUB:
1355  if (!asf->sub_left && !asf->nb_mult_left) {
1356  asf->state = PARSE_PACKET_HEADER;
1357  if (!asf->return_subpayload &&
1358  (avio_tell(pb) <= asf->packet_offset +
1359  asf->packet_size - asf->pad_len))
1360  avio_skip(pb, asf->pad_len); // skip padding
1361  if (asf->packet_offset + asf->packet_size > avio_tell(pb))
1362  avio_seek(pb, asf->packet_offset + asf->packet_size, SEEK_SET);
1363  } else if (!asf->sub_left)
1364  asf->state = READ_MULTI;
1365  break;
1366  case READ_MULTI:
1367  if (!asf->nb_mult_left) {
1368  asf->state = PARSE_PACKET_HEADER;
1369  if (!asf->return_subpayload &&
1370  (avio_tell(pb) <= asf->packet_offset +
1371  asf->packet_size - asf->pad_len))
1372  avio_skip(pb, asf->pad_len); // skip padding
1373  if (asf->packet_offset + asf->packet_size > avio_tell(pb))
1374  avio_seek(pb, asf->packet_offset + asf->packet_size, SEEK_SET);
1375  }
1376  break;
1377  }
1378  if (asf->return_subpayload) {
1379  asf->return_subpayload = 0;
1380  return 0;
1381  }
1382  for (i = 0; i < asf->nb_streams; i++) {
1383  ASFPacket *asf_pkt = &asf->asf_st[i]->pkt;
1384  if (asf_pkt && !asf_pkt->size_left && asf_pkt->data_size) {
1385  if (asf->asf_st[i]->span > 1 &&
1386  asf->asf_st[i]->type == AVMEDIA_TYPE_AUDIO)
1387  if ((ret = asf_deinterleave(s, asf_pkt, i)) < 0)
1388  return ret;
1389  av_packet_move_ref(pkt, asf_pkt->avpkt);
1390  pkt->stream_index = asf->asf_st[i]->index;
1391  pkt->flags = asf_pkt->flags;
1392  pkt->dts = asf_pkt->dts - asf->preroll;
1393  asf_pkt->data_size = 0;
1394  asf_pkt->frame_num = 0;
1395  return 0;
1396  }
1397  }
1398  }
1399 
1400  if (pb->eof_reached)
1401  return AVERROR_EOF;
1402 
1403  return 0;
1404 }
1405 
1407 {
1408  ASFContext *asf = s->priv_data;
1409  int i;
1410 
1411  for (i = 0; i < ASF_MAX_STREAMS; i++) {
1412  av_dict_free(&asf->asf_sd[i].asf_met);
1413  if (i < asf->nb_streams) {
1414  av_packet_free(&asf->asf_st[i]->pkt.avpkt);
1415  av_freep(&asf->asf_st[i]);
1416  }
1417  }
1418 
1419  asf->nb_streams = 0;
1420  return 0;
1421 }
1422 
1424 {
1425  ASFContext *asf = s->priv_data;
1426  int i;
1427 
1428  asf->state = PARSE_PACKET_HEADER;
1429  asf->offset = 0;
1430  asf->return_subpayload = 0;
1431  asf->sub_left = 0;
1432  asf->sub_header_offset = 0;
1433  asf->packet_offset = asf->first_packet_offset;
1434  asf->pad_len = 0;
1435  asf->rep_data_len = 0;
1436  asf->dts_delta = 0;
1437  asf->mult_sub_len = 0;
1438  asf->nb_mult_left = 0;
1439  asf->nb_sub = 0;
1440  asf->prop_flags = 0;
1441  asf->sub_dts = 0;
1442  for (i = 0; i < asf->nb_streams; i++) {
1443  ASFPacket *pkt = &asf->asf_st[i]->pkt;
1444  reset_packet(pkt);
1445  }
1446 }
1447 
1448 /*
1449  * Find a timestamp for the requested position within the payload
1450  * where the pos (position) is the offset inside the Data Object.
1451  * When position is not on the packet boundary, asf_read_timestamp tries
1452  * to find the closest packet offset after this position. If this packet
1453  * is a key frame, this packet timestamp is read and an index entry is created
1454  * for the packet. If this packet belongs to the requested stream,
1455  * asf_read_timestamp upgrades pos to the packet beginning offset and
1456  * returns this packet's dts. So returned dts is the dts of the first key frame with
1457  * matching stream number after given position.
1458  */
1459 static int64_t asf_read_timestamp(AVFormatContext *s, int stream_index,
1460  int64_t *pos, int64_t pos_limit)
1461 {
1462  ASFContext *asf = s->priv_data;
1463  int64_t pkt_pos = *pos, pkt_offset, dts = AV_NOPTS_VALUE, data_end;
1465  int n;
1466 
1467  if (!pkt)
1468  return AVERROR(ENOMEM);
1469 
1470  data_end = asf->data_offset + asf->data_size;
1471 
1472  n = (pkt_pos - asf->first_packet_offset + asf->packet_size - 1) /
1473  asf->packet_size;
1474  n = av_clip(n, 0, ((data_end - asf->first_packet_offset) / asf->packet_size - 1));
1475  pkt_pos = asf->first_packet_offset + n * asf->packet_size;
1476 
1477  avio_seek(s->pb, pkt_pos, SEEK_SET);
1478  pkt_offset = pkt_pos;
1479 
1481  while (avio_tell(s->pb) < data_end) {
1482 
1483  int i, ret, st_found;
1484 
1485  pkt_offset = avio_tell(s->pb);
1486  if ((ret = asf_read_packet(s, pkt)) < 0) {
1487  av_packet_free(&pkt);
1488  dts = AV_NOPTS_VALUE;
1489  return ret;
1490  }
1491  // ASFPacket may contain fragments of packets belonging to different streams,
1492  // pkt_offset is the offset of the first fragment within it.
1493  if ((pkt_offset >= (pkt_pos + asf->packet_size)))
1494  pkt_pos += asf->packet_size;
1495  for (i = 0; i < asf->nb_streams; i++) {
1496  ASFStream *st = asf->asf_st[i];
1497 
1498  st_found = 0;
1499  if (pkt->flags & AV_PKT_FLAG_KEY) {
1500  dts = pkt->dts;
1501  if (dts) {
1502  av_add_index_entry(s->streams[pkt->stream_index], pkt_pos,
1503  dts, pkt->size, 0, AVINDEX_KEYFRAME);
1504  if (stream_index == st->index) {
1505  st_found = 1;
1506  break;
1507  }
1508  }
1509  }
1510  }
1511  if (st_found)
1512  break;
1514  }
1515  *pos = pkt_pos;
1516 
1517  av_packet_free(&pkt);
1518  return dts;
1519 }
1520 
1521 static int asf_read_seek(AVFormatContext *s, int stream_index,
1522  int64_t timestamp, int flags)
1523 {
1524  ASFContext *asf = s->priv_data;
1525  int idx, ret;
1526 
1527  if (s->streams[stream_index]->internal->nb_index_entries && asf->is_simple_index) {
1528  idx = av_index_search_timestamp(s->streams[stream_index], timestamp, flags);
1529  if (idx < 0 || idx >= s->streams[stream_index]->internal->nb_index_entries)
1530  return AVERROR_INVALIDDATA;
1531  avio_seek(s->pb, s->streams[stream_index]->internal->index_entries[idx].pos, SEEK_SET);
1532  } else {
1533  if ((ret = ff_seek_frame_binary(s, stream_index, timestamp, flags)) < 0)
1534  return ret;
1535  }
1536 
1538 
1539  return 0;
1540 }
1541 
1543 {
1544  int j, ret;
1545  const GUIDParseTable *g;
1546 
1547  swap_guid(guid);
1548  g = gdef;
1549  for (j = 0; j < FF_ARRAY_ELEMS(gdef); j++) {
1550  if (!(ret = memcmp(guid, g->guid, sizeof(g->guid))))
1551  return g;
1552  g++;
1553  }
1554 
1555  return NULL;
1556 }
1557 
1558 static int detect_unknown_subobject(AVFormatContext *s, int64_t offset, int64_t size)
1559 {
1560  ASFContext *asf = s->priv_data;
1561  AVIOContext *pb = s->pb;
1562  const GUIDParseTable *g = NULL;
1563  ff_asf_guid guid;
1564  int ret;
1565 
1566  if (offset > INT64_MAX - size)
1567  return AVERROR_INVALIDDATA;
1568 
1569  while (avio_tell(pb) <= offset + size) {
1570  if (avio_tell(pb) == asf->offset)
1571  break;
1572  asf->offset = avio_tell(pb);
1573  if ((ret = ff_get_guid(pb, &guid)) < 0)
1574  return ret;
1575  g = find_guid(guid);
1576  if (g) {
1577  if ((ret = g->read_object(s, g)) < 0)
1578  return ret;
1579  } else {
1580  GUIDParseTable g2;
1581 
1582  g2.name = "Unknown";
1583  g2.is_subobject = 1;
1584  asf_read_unknown(s, &g2);
1585  }
1586  }
1587 
1588  return 0;
1589 }
1590 
1592 {
1593  ASFContext *asf = s->priv_data;
1594  AVIOContext *pb = s->pb;
1595  const GUIDParseTable *g = NULL;
1596  ff_asf_guid guid;
1597  int i, ret;
1598  uint64_t size;
1599 
1600  asf->preroll = 0;
1601  asf->is_simple_index = 0;
1602  ff_get_guid(pb, &guid);
1603  if (ff_guidcmp(&guid, &ff_asf_header))
1604  return AVERROR_INVALIDDATA;
1605  avio_skip(pb, 8); // skip header object size
1606  avio_skip(pb, 6); // skip number of header objects and 2 reserved bytes
1607  asf->data_reached = 0;
1608 
1609  /* 1 is here instead of pb->eof_reached because (when not streaming), Data are skipped
1610  * for the first time,
1611  * Index object is processed and got eof and then seeking back to the Data is performed.
1612  */
1613  while (1) {
1614  // for the cases when object size is invalid
1615  if (avio_tell(pb) == asf->offset)
1616  break;
1617  asf->offset = avio_tell(pb);
1618  if ((ret = ff_get_guid(pb, &guid)) < 0) {
1619  if (ret == AVERROR_EOF && asf->data_reached)
1620  break;
1621  else
1622  goto failed;
1623  }
1624  g = find_guid(guid);
1625  if (g) {
1626  asf->unknown_offset = asf->offset;
1627  asf->is_header = 1;
1628  if ((ret = g->read_object(s, g)) < 0)
1629  goto failed;
1630  } else {
1631  size = avio_rl64(pb);
1632  align_position(pb, asf->offset, size);
1633  }
1634  if (asf->data_reached &&
1635  (!(pb->seekable & AVIO_SEEKABLE_NORMAL) ||
1636  (asf->b_flags & ASF_FLAG_BROADCAST)))
1637  break;
1638  }
1639 
1640  if (!asf->data_reached) {
1641  av_log(s, AV_LOG_ERROR, "Data Object was not found.\n");
1643  goto failed;
1644  }
1645  if (pb->seekable & AVIO_SEEKABLE_NORMAL)
1646  avio_seek(pb, asf->first_packet_offset, SEEK_SET);
1647 
1648  for (i = 0; i < asf->nb_streams; i++) {
1649  const char *rfc1766 = asf->asf_sd[asf->asf_st[i]->lang_idx].langs;
1650  AVStream *st = s->streams[asf->asf_st[i]->index];
1651  set_language(s, rfc1766, &st->metadata);
1652  }
1653 
1654  for (i = 0; i < ASF_MAX_STREAMS; i++) {
1655  AVStream *st = NULL;
1656 
1657  st = find_stream(s, i);
1658  if (st) {
1660  if (asf->asf_sd[i].aspect_ratio.num > 0 && asf->asf_sd[i].aspect_ratio.den > 0) {
1663  }
1664  }
1665  }
1666 
1667  return 0;
1668 
1669 failed:
1670  asf_read_close(s);
1671  return ret;
1672 }
1673 
1675  .name = "asf_o",
1676  .long_name = NULL_IF_CONFIG_SMALL("ASF (Advanced / Active Streaming Format)"),
1677  .priv_data_size = sizeof(ASFContext),
1678  .read_probe = asf_probe,
1682  .read_timestamp = asf_read_timestamp,
1685 };
reset_packet
static void reset_packet(ASFPacket *asf_pkt)
Definition: asfdec_o.c:1026
ff_asf_ext_stream_embed_stream_header
const ff_asf_guid ff_asf_ext_stream_embed_stream_header
Definition: asf.c:96
ff_asf_jfif_media
const ff_asf_guid ff_asf_jfif_media
Definition: asf.c:53
ASFContext::sub_header_offset
uint64_t sub_header_offset
Definition: asfdec_o.c:121
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:634
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
PUT_UTF8
#define PUT_UTF8(val, tmp, PUT_BYTE)
Definition: common.h:552
asf_read_replicated_data
static int asf_read_replicated_data(AVFormatContext *s, ASFPacket *asf_pkt)
Definition: asfdec_o.c:1036
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:74
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
av_clip
#define av_clip
Definition: common.h:122
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
ff_get_guid
int ff_get_guid(AVIOContext *s, ff_asf_guid *g)
Definition: riffdec.c:32
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4547
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
ASFStreamData::langs
char langs[32]
Definition: asfdec_o.c:85
FFSWAP
#define FFSWAP(type, a, b)
Definition: common.h:108
asf_read_subpayload
static int asf_read_subpayload(AVFormatContext *s, AVPacket *pkt, int is_header)
Definition: asfdec_o.c:971
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:55
parse_video_info
static int parse_video_info(AVIOContext *pb, AVStream *st)
Definition: asfdec_o.c:576
ASFContext::data_offset
int64_t data_offset
Definition: asfdec_o.c:109
align_position
static void align_position(AVIOContext *pb, int64_t offset, uint64_t size)
Definition: asfdec_o.c:163
avlanguage.h
av_unused
#define av_unused
Definition: attributes.h:131
ASFContext::packet_offset
int64_t packet_offset
Definition: asfdec_o.c:125
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:27
AVPacket::data
uint8_t * data
Definition: packet.h:369
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:946
data
const char data[16]
Definition: mxf.c:142
ASFStream::type
int type
Definition: asfdec_o.c:75
AV_DICT_IGNORE_SUFFIX
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
Definition: dict.h:70
asfcrypt.h
asf_read_header
static int asf_read_header(AVFormatContext *s)
Definition: asfdec_o.c:1591
detect_unknown_subobject
static int detect_unknown_subobject(AVFormatContext *s, int64_t offset, int64_t size)
Definition: asfdec_o.c:1558
ff_asf_video_stream
const ff_asf_guid ff_asf_video_stream
Definition: asf.c:49
swap_guid
static void swap_guid(ff_asf_guid guid)
Definition: asfdec_o.c:155
ASF_GUID
#define ASF_GUID
Definition: asfdec_o.c:39
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:64
mathematics.h
AVDictionary
Definition: dict.c:30
AVFMT_NOBINSEARCH
#define AVFMT_NOBINSEARCH
Format does not allow to fall back on binary search via read_timestamp.
Definition: avformat.h:468
process_metadata
static int process_metadata(AVFormatContext *s, const uint8_t *name, uint16_t name_len, uint16_t val_len, uint16_t type, AVDictionary **met)
Definition: asfdec_o.c:355
asf_read_ext_content
static int asf_read_ext_content(AVFormatContext *s, const GUIDParseTable *g)
Definition: asfdec_o.c:383
ASFContext::data_offset
uint64_t data_offset
beginning of the first data packet
Definition: asfdec_f.c:84
asf_read_properties
static int asf_read_properties(AVFormatContext *s, const GUIDParseTable *g)
Definition: asfdec_o.c:533
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:410
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:75
BMP_HEADER_SIZE
#define BMP_HEADER_SIZE
Definition: asfdec_o.c:49
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
ff_seek_frame_binary
int ff_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags)
Perform a binary search using av_index_search_timestamp() and AVInputFormat.read_timestamp().
Definition: utils.c:2203
AVINDEX_KEYFRAME
#define AVINDEX_KEYFRAME
Definition: avformat.h:811
ASFContext::dts_delta
uint8_t dts_delta
Definition: asfdec_o.c:123
ff_guidcmp
static av_always_inline int ff_guidcmp(const void *g1, const void *g2)
Definition: riff.h:122
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:453
ASFPacket::size_left
int size_left
Definition: asfdec_o.c:68
ASFContext::stream_index
int stream_index
Definition: asfdec_f.c:109
ASFPacket::duration
int duration
Definition: asfdec_o.c:67
asf_read_data
static int asf_read_data(AVFormatContext *s, const GUIDParseTable *g)
Definition: asfdec_o.c:824
ASF_FLAG_BROADCAST
#define ASF_FLAG_BROADCAST
Definition: asfdec_o.c:43
ASFContext::offset
int64_t offset
Definition: asfdec_o.c:107
ff_get_bmp_header
int ff_get_bmp_header(AVIOContext *pb, AVStream *st, uint32_t *size)
Read BITMAPINFOHEADER structure and set AVStream codec width, height and bits_per_encoded_sample fiel...
Definition: riffdec.c:209
asf_read_marker
static int asf_read_marker(AVFormatContext *s, const GUIDParseTable *g)
Definition: asfdec_o.c:216
GUIDParseTable::read_object
int(* read_object)(AVFormatContext *, const struct GUIDParseTable *)
Definition: asfdec_o.c:57
ASFStreamData::asf_met
AVDictionary * asf_met
Definition: asfdec_o.c:86
read_seek
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
av_add_index_entry
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
Definition: utils.c:2044
ASFContext::sub_left
uint64_t sub_left
Definition: asfdec_o.c:130
asf_read_simple_index
static int asf_read_simple_index(AVFormatContext *s, const GUIDParseTable *g)
Definition: asfdec_o.c:860
asf_read_value
static int asf_read_value(AVFormatContext *s, const uint8_t *name, uint16_t val_len, int type, AVDictionary **met)
Definition: asfdec_o.c:272
gmtime_r
#define gmtime_r
Definition: time_internal.h:34
read_close
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:557
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
pts
static int64_t pts
Definition: transcode_aac.c:652
ASF_NUM_OF_PAYLOADS
#define ASF_NUM_OF_PAYLOADS
Definition: asfdec_o.c:50
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:922
ff_asf_o_demuxer
AVInputFormat ff_asf_o_demuxer
Definition: asfdec_o.c:1674
avio_rl16
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:734
AVRational::num
int num
Numerator.
Definition: rational.h:59
asf_read_metadata_obj
static int asf_read_metadata_obj(AVFormatContext *s, const GUIDParseTable *g)
Definition: asfdec_o.c:456
ASF_WORD
#define ASF_WORD
Definition: asfdec_o.c:38
ASFContext::READ_MULTI
@ READ_MULTI
Definition: asfdec_o.c:138
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
asf_deinterleave
static int asf_deinterleave(AVFormatContext *s, ASFPacket *asf_pkt, int st_num)
Definition: asfdec_o.c:1276
AVInputFormat
Definition: avformat.h:640
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
ASFStream::virtual_chunk_len
uint16_t virtual_chunk_len
Definition: asfdec_o.c:79
ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE
#define ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE
Definition: asf.h:157
ASFContext::asf_st
ASFStream * asf_st
currently decoded stream
Definition: asfdec_f.c:111
find_stream
static AVStream * find_stream(AVFormatContext *s, uint16_t st_num)
Definition: asfdec_o.c:420
avio_get_str16le
int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a UTF-16 string from pb and convert it to UTF-8.
ASFStream::index
int index
Definition: asfdec_o.c:74
GUIDParseTable::is_subobject
int is_subobject
Definition: asfdec_o.c:58
ASFContext::asf_sd
ASFStreamData asf_sd[ASF_MAX_STREAMS]
Definition: asfdec_o.c:115
s
#define s(width, name)
Definition: cbs_vp9.c:257
av_new_packet
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:99
ASFStream::indexed
int indexed
Definition: asfdec_o.c:76
ASFContext::b_flags
uint32_t b_flags
Definition: asfdec_o.c:101
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:645
g
const char * g
Definition: vf_curves.c:117
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:443
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
ASF_BYTE_ARRAY
#define ASF_BYTE_ARRAY
Definition: asfdec_o.c:44
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:126
ASFContext::mult_sub_len
uint16_t mult_sub_len
Definition: asfdec_o.c:132
ASF_STREAM_NUM
#define ASF_STREAM_NUM
Definition: asfdec_o.c:47
ASF_ERROR_CORRECTION_LENGTH_TYPE
#define ASF_ERROR_CORRECTION_LENGTH_TYPE
Definition: asfdec_o.c:51
nb_streams
static int nb_streams
Definition: ffprobe.c:283
ASFContext::nb_sub
unsigned int nb_sub
Definition: asfdec_o.c:131
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
int32_t
int32_t
Definition: audio_convert.c:194
time_internal.h
if
if(ret)
Definition: filter_design.txt:179
AVFormatContext
Format I/O context.
Definition: avformat.h:1231
ASFContext::preroll
uint64_t preroll
Definition: asfdec_o.c:95
asf_read_seek
static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: asfdec_o.c:1521
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1038
AV_LANG_ISO639_2_BIBL
@ AV_LANG_ISO639_2_BIBL
Definition: avlanguage.h:28
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:527
NULL
#define NULL
Definition: coverity.c:32
ff_asf_guid
uint8_t ff_asf_guid[16]
Definition: riff.h:96
read_probe
static int read_probe(const AVProbeData *pd)
Definition: jvdec.c:55
ff_asf_header
const ff_asf_guid ff_asf_header
Definition: asf.c:25
ASF_PPI_MASK_SEQUENCE_FIELD_SIZE
#define ASF_PPI_MASK_SEQUENCE_FIELD_SIZE
Definition: asf.h:141
ASF_QWORD
#define ASF_QWORD
Definition: asfdec_o.c:41
ASFContext::is_simple_index
int is_simple_index
Definition: asfdec_o.c:92
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
ASFPacket::avpkt
AVPacket * avpkt
Definition: asfdec_o.c:62
asf_read_metadata
static int asf_read_metadata(AVFormatContext *s, const char *title, uint16_t len, unsigned char *ch, uint16_t buflen)
Definition: asfdec_o.c:258
ASFContext::data_reached
int data_reached
Definition: asfdec_o.c:91
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:441
ASFPacket
Definition: asfdec_o.c:61
READ_LEN
#define READ_LEN(flag, name, len)
Definition: asfdec_o.c:959
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:937
ASFContext::nb_packets
uint64_t nb_packets
how many packets are there in the file, invalid if broadcasting
Definition: asfdec_o.c:96
ASFContext::unknown_size
uint64_t unknown_size
Definition: asfdec_o.c:105
av_packet_move_ref
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: avpacket.c:690
ff_asf_handle_byte_array
int ff_asf_handle_byte_array(AVFormatContext *s, const char *name, int val_len)
Handles both attached pictures as well as id3 tags.
Definition: asf.c:269
ASFContext::pad_len
uint32_t pad_len
Definition: asfdec_o.c:126
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:78
ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE
#define ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE
Definition: asf.h:162
asf_read_multiple_payload
static int asf_read_multiple_payload(AVFormatContext *s, AVPacket *pkt, ASFPacket *asf_pkt)
Definition: asfdec_o.c:1058
avio_rl32
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:750
av_packet_from_data
int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size)
Initialize a reference-counted packet from av_malloc()ed data.
Definition: avpacket.c:166
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
AVMediaType
AVMediaType
Definition: avutil.h:199
AVPacket::size
int size
Definition: packet.h:370
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
ff_codec_get_id
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:3185
AVIOContext::seekable
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:260
asf_read_generic_value
static int asf_read_generic_value(AVIOContext *pb, int type, uint64_t *value)
Definition: asfdec_o.c:313
ASFContext::prop_flags
uint32_t prop_flags
Definition: asfdec_o.c:102
ff_convert_lang_to
const char * ff_convert_lang_to(const char *lang, enum AVLangCodespace target_codespace)
Convert a language code to a target codespace.
Definition: avlanguage.c:736
start_time
static int64_t start_time
Definition: ffplay.c:332
FFMAX
#define FFMAX(a, b)
Definition: common.h:103
ASFContext::packet_size
uint32_t packet_size
Definition: asfdec_o.c:97
avpriv_set_pts_info
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:4993
asf_store_aspect_ratio
static int asf_store_aspect_ratio(AVFormatContext *s, uint8_t st_num, uint8_t *name, int type)
Definition: asfdec_o.c:436
size
int size
Definition: twinvq_data.h:10344
ASFStreamData
Definition: asfdec_o.c:84
ASFContext::is_header
int is_header
Definition: asfdec_o.c:93
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
ASFContext::sub_dts
int64_t sub_dts
Definition: asfdec_o.c:122
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:935
ASFContext::PARSE_PACKET_HEADER
@ PARSE_PACKET_HEADER
Definition: asfdec_o.c:136
ASFStreamData::aspect_ratio
AVRational aspect_ratio
Definition: asfdec_o.c:87
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:368
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:624
ASFStream::lang_idx
int16_t lang_idx
Definition: asfdec_o.c:80
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
GUIDParseTable::name
const char * name
Definition: asfdec_o.c:55
attributes.h
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:375
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:64
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:203
asf_read_single_payload
static int asf_read_single_payload(AVFormatContext *s, ASFPacket *asf_pkt)
Definition: asfdec_o.c:1109
bitrate
int64_t bitrate
Definition: h264_levels.c:131
asf_read_payload
static int asf_read_payload(AVFormatContext *s, AVPacket *pkt)
Definition: asfdec_o.c:1161
gdef
static const GUIDParseTable gdef[]
Definition: asfdec_o.c:909
ASFContext::READ_SINGLE
@ READ_SINGLE
Definition: asfdec_o.c:137
ASFStream::pkt
AVPacket pkt
Definition: asfdec_f.c:50
ff_asf_command_stream
const ff_asf_guid ff_asf_command_stream
Definition: asf.c:61
ASF_DWORD
#define ASF_DWORD
Definition: asfdec_o.c:40
ASFPacket::frame_num
uint32_t frame_num
Definition: asfdec_o.c:64
i
int i
Definition: input.c:407
asf_read_content_desc
static int asf_read_content_desc(AVFormatContext *s, const GUIDParseTable *g)
Definition: asfdec_o.c:504
ASFPacket::dts
int64_t dts
Definition: asfdec_o.c:63
avio_internal.h
internal.h
AVCodecParameters::height
int height
Definition: codec_par.h:127
set_language
static void set_language(AVFormatContext *s, const char *rfc1766, AVDictionary **met)
Definition: asfdec_o.c:715
common.h
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
uint8_t
uint8_t
Definition: audio_convert.c:194
GET_UTF16
#define GET_UTF16(val, GET_16BIT, ERROR)
Convert a UTF-16 character (2 or 4 bytes) to its 32-bit UCS-4 encoded form.
Definition: common.h:524
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
asf_read_timestamp
static int64_t asf_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos, int64_t pos_limit)
Definition: asfdec_o.c:1459
len
int len
Definition: vorbis_enc_data.h:452
ff_get_wav_header
int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int size, int big_endian)
Definition: riffdec.c:91
avpriv_new_chapter
AVChapter * avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base, int64_t start, int64_t end, const char *title)
Add a new chapter.
Definition: utils.c:4680
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
ASFContext::state
enum ASFContext::@243 state
ASFContext::unknown_offset
int64_t unknown_offset
Definition: asfdec_o.c:111
ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE
#define ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE
Definition: asf.h:167
av_get_packet
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition: utils.c:310
tag
uint32_t tag
Definition: movenc.c:1611
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:880
ret
ret
Definition: filter_design.txt:187
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVStream
Stream structure.
Definition: avformat.h:873
ASFContext::data_size
uint64_t data_size
Definition: asfdec_o.c:104
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:253
ASF_PACKET_ERROR_CORRECTION_DATA_SIZE
#define ASF_PACKET_ERROR_CORRECTION_DATA_SIZE
Definition: asfdec_o.c:52
ff_asf_audio_stream
const ff_asf_guid ff_asf_audio_stream
Definition: asf.c:41
ASFStream::stream_index
uint8_t stream_index
Definition: asfdec_o.c:73
ASFStream::virtual_pkt_len
uint16_t virtual_pkt_len
Definition: asfdec_o.c:78
ASFContext::first_packet_offset
int64_t first_packet_offset
Definition: asfdec_o.c:110
pos
unsigned int pos
Definition: spdifenc.c:412
avformat.h
dict.h
ASFPacket::stream_index
uint8_t stream_index
Definition: asfdec_o.c:69
get_asf_string
static int get_asf_string(AVIOContext *pb, int maxlen, char *buf, int buflen)
Definition: asfdec_o.c:199
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: avcodec.h:215
asf.h
ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE
#define ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE
Definition: asf.h:146
ASFStream::pkt
ASFPacket pkt
Definition: asfdec_o.c:81
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:874
ff_codec_bmp_tags
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:33
ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT
#define ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT
Definition: asf.h:136
GUIDParseTable
Definition: asfdec_o.c:54
asf_read_unknown
static int asf_read_unknown(AVFormatContext *s, const GUIDParseTable *g)
Definition: asfdec_o.c:169
GUIDParseTable::guid
ff_asf_guid guid
Definition: asfdec_o.c:56
ASFContext::rep_data_len
uint32_t rep_data_len
Definition: asfdec_o.c:127
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
AVRational::den
int den
Denominator.
Definition: rational.h:60
ASF_UNICODE
#define ASF_UNICODE
Definition: asfdec_o.c:42
ASFContext::duration
int duration
Definition: asfdec_o.c:99
AVFMT_NOGENSEARCH
#define AVFMT_NOGENSEARCH
Format does not allow to fall back on generic search.
Definition: avformat.h:469
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:633
asf_probe
static int asf_probe(const AVProbeData *pd)
Definition: asfdec_o.c:146
ASFContext::packet_size_internal
uint32_t packet_size_internal
Definition: asfdec_o.c:124
ASFStream::span
int8_t span
Definition: asfdec_o.c:77
asf_read_packet
static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: asfdec_o.c:1322
AVIOContext::eof_reached
int eof_reached
true if was unable to read due to error or eof
Definition: avio.h:239
AVPacket::stream_index
int stream_index
Definition: packet.h:371
ASF_BOOL
#define ASF_BOOL
Definition: asfdec_o.c:37
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:337
ASF_MAX_STREAMS
#define ASF_MAX_STREAMS
Definition: asfdec_o.c:48
ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE
#define ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE
Definition: asf.h:151
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
asf_read_close
static int asf_read_close(AVFormatContext *s)
Definition: asfdec_o.c:1406
ASFContext
Definition: asfdec_f.c:73
reset_packet_state
static void reset_packet_state(AVFormatContext *s)
Definition: asfdec_o.c:1423
ASFContext::return_subpayload
int return_subpayload
Definition: asfdec_o.c:134
find_guid
static const GUIDParseTable * find_guid(ff_asf_guid guid)
Definition: asfdec_o.c:1542
asf_read_ext_stream_properties
static int asf_read_ext_stream_properties(AVFormatContext *s, const GUIDParseTable *g)
Definition: asfdec_o.c:728
ASFContext::READ_MULTI_SUB
@ READ_MULTI_SUB
Definition: asfdec_o.c:139
ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT
#define ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT
Definition: asf.h:117
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
AVPacket
This structure stores compressed data.
Definition: packet.h:346
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:70
riff.h
av_dict_copy
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:217
avio_rl64
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:758
ASFStream
Definition: asfdec_f.c:46
asf_read_stream_properties
static int asf_read_stream_properties(AVFormatContext *s, const GUIDParseTable *g)
Definition: asfdec_o.c:609
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: codec_par.h:89
ASFContext::send_time
int64_t send_time
Definition: asfdec_o.c:98
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
asf_read_language_list
static int asf_read_language_list(AVFormatContext *s, const GUIDParseTable *g)
Definition: asfdec_o.c:798
asf_set_metadata
static int asf_set_metadata(AVFormatContext *s, const uint8_t *name, int type, AVDictionary **met)
Definition: asfdec_o.c:336
ASFPacket::flags
int flags
Definition: asfdec_o.c:65
AVStream::start_time
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Definition: avformat.h:912
int
int
Definition: ffmpeg_filter.c:158
snprintf
#define snprintf
Definition: snprintf.h:34
ASFContext::nb_mult_left
uint64_t nb_mult_left
Definition: asfdec_o.c:133
ASFContext::nb_streams
int nb_streams
Definition: asfdec_o.c:116
asf_read_packet_header
static int asf_read_packet_header(AVFormatContext *s)
Definition: asfdec_o.c:1241
ff_asfcrypt_dec
void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len)
Definition: asfcrypt.c:147
ASFPacket::data_size
int data_size
Definition: asfdec_o.c:66
av_index_search_timestamp
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
Definition: utils.c:2161
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:364