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