Libav
asfdec.c
Go to the documentation of this file.
1 /*
2  * ASF compatible demuxer
3  * Copyright (c) 2000, 2001 Fabrice Bellard
4  *
5  * This file is part of Libav.
6  *
7  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <inttypes.h>
23 
24 #include "libavutil/attributes.h"
25 #include "libavutil/avassert.h"
26 #include "libavutil/avstring.h"
27 #include "libavutil/bswap.h"
28 #include "libavutil/common.h"
29 #include "libavutil/dict.h"
30 #include "libavutil/internal.h"
31 #include "libavutil/mathematics.h"
32 #include "libavutil/opt.h"
33 #include "avformat.h"
34 #include "avio_internal.h"
35 #include "avlanguage.h"
36 #include "id3v2.h"
37 #include "internal.h"
38 #include "riff.h"
39 #include "asf.h"
40 #include "asfcrypt.h"
41 
42 typedef struct {
43  const AVClass *class;
44  int asfid2avid[128];
45  ASFStream streams[128];
46  uint32_t stream_bitrates[128];
47  AVRational dar[128];
48  char stream_languages[128][6];
49  /* non streamed additonnal info */
50  /* packet filling */
52  /* only for reading */
53  uint64_t data_offset;
54  uint64_t data_object_offset;
55  uint64_t data_object_size;
57 
59 
69  unsigned int packet_frag_offset;
70  unsigned int packet_frag_size;
76  int64_t packet_pos;
77 
79 
81 
83 } ASFContext;
84 
85 static const AVOption options[] = {
86  { "no_resync_search", "Don't try to resynchronize by looking for a certain optional start code", offsetof(ASFContext, no_resync_search), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
87  { NULL },
88 };
89 
90 static const AVClass asf_class = {
91  .class_name = "asf demuxer",
92  .item_name = av_default_item_name,
93  .option = options,
94  .version = LIBAVUTIL_VERSION_INT,
95 };
96 
97 #undef NDEBUG
98 #include <assert.h>
99 
100 #define ASF_MAX_STREAMS 127
101 #define FRAME_HEADER_SIZE 17
102 // Fix Me! FRAME_HEADER_SIZE may be different.
103 
104 static const ff_asf_guid index_guid = {
105  0x90, 0x08, 0x00, 0x33, 0xb1, 0xe5, 0xcf, 0x11, 0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb
106 };
107 
108 #ifdef DEBUG
109 static const ff_asf_guid stream_bitrate_guid = { /* (http://get.to/sdp) */
110  0xce, 0x75, 0xf8, 0x7b, 0x8d, 0x46, 0xd1, 0x11, 0x8d, 0x82, 0x00, 0x60, 0x97, 0xc9, 0xa2, 0xb2
111 };
112 
113 #define PRINT_IF_GUID(g, cmp) \
114  if (!ff_guidcmp(g, &cmp)) \
115  av_dlog(NULL, "(GUID: %s) ", # cmp)
116 
117 static void print_guid(ff_asf_guid *g)
118 {
119  int i;
120  PRINT_IF_GUID(g, ff_asf_header);
121  else PRINT_IF_GUID(g, ff_asf_file_header);
122  else PRINT_IF_GUID(g, ff_asf_stream_header);
123  else PRINT_IF_GUID(g, ff_asf_audio_stream);
124  else PRINT_IF_GUID(g, ff_asf_audio_conceal_none);
125  else PRINT_IF_GUID(g, ff_asf_video_stream);
126  else PRINT_IF_GUID(g, ff_asf_video_conceal_none);
127  else PRINT_IF_GUID(g, ff_asf_command_stream);
128  else PRINT_IF_GUID(g, ff_asf_comment_header);
129  else PRINT_IF_GUID(g, ff_asf_codec_comment_header);
130  else PRINT_IF_GUID(g, ff_asf_codec_comment1_header);
131  else PRINT_IF_GUID(g, ff_asf_data_header);
132  else PRINT_IF_GUID(g, index_guid);
133  else PRINT_IF_GUID(g, ff_asf_head1_guid);
134  else PRINT_IF_GUID(g, ff_asf_head2_guid);
135  else PRINT_IF_GUID(g, ff_asf_my_guid);
136  else PRINT_IF_GUID(g, ff_asf_ext_stream_header);
137  else PRINT_IF_GUID(g, ff_asf_extended_content_header);
138  else PRINT_IF_GUID(g, ff_asf_ext_stream_embed_stream_header);
139  else PRINT_IF_GUID(g, ff_asf_ext_stream_audio_stream);
140  else PRINT_IF_GUID(g, ff_asf_metadata_header);
141  else PRINT_IF_GUID(g, ff_asf_metadata_library_header);
142  else PRINT_IF_GUID(g, ff_asf_marker_header);
143  else PRINT_IF_GUID(g, stream_bitrate_guid);
144  else PRINT_IF_GUID(g, ff_asf_language_guid);
145  else
146  av_dlog(NULL, "(GUID: unknown) ");
147  for (i = 0; i < 16; i++)
148  av_dlog(NULL, " 0x%02x,", (*g)[i]);
149  av_dlog(NULL, "}\n");
150 }
151 #undef PRINT_IF_GUID
152 #else
153 #define print_guid(g)
154 #endif
155 
156 static int asf_probe(AVProbeData *pd)
157 {
158  /* check file header */
159  if (!ff_guidcmp(pd->buf, &ff_asf_header))
160  return AVPROBE_SCORE_MAX;
161  else
162  return 0;
163 }
164 
165 /* size of type 2 (BOOL) is 32bit for "Extended Content Description Object"
166  * but 16 bit for "Metadata Object" and "Metadata Library Object" */
167 static int get_value(AVIOContext *pb, int type, int type2_size)
168 {
169  switch (type) {
170  case 2:
171  return (type2_size == 32) ? avio_rl32(pb) : avio_rl16(pb);
172  case 3:
173  return avio_rl32(pb);
174  case 4:
175  return avio_rl64(pb);
176  case 5:
177  return avio_rl16(pb);
178  default:
179  return INT_MIN;
180  }
181 }
182 
183 /* MSDN claims that this should be "compatible with the ID3 frame, APIC",
184  * but in reality this is only loosely similar */
186 {
187  AVPacket pkt = { 0 };
188  const CodecMime *mime = ff_id3v2_mime_tags;
189  enum AVCodecID id = AV_CODEC_ID_NONE;
190  char mimetype[64];
191  uint8_t *desc = NULL;
192  AVStream *st = NULL;
193  int ret, type, picsize, desc_len;
194 
195  /* type + picsize + mime + desc */
196  if (len < 1 + 4 + 2 + 2) {
197  av_log(s, AV_LOG_ERROR, "Invalid attached picture size: %d.\n", len);
198  return AVERROR_INVALIDDATA;
199  }
200 
201  /* picture type */
202  type = avio_r8(s->pb);
203  len--;
204  if (type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types) || type < 0) {
205  av_log(s, AV_LOG_WARNING, "Unknown attached picture type: %d.\n", type);
206  type = 0;
207  }
208 
209  /* picture data size */
210  picsize = avio_rl32(s->pb);
211  len -= 4;
212 
213  /* picture MIME type */
214  len -= avio_get_str16le(s->pb, len, mimetype, sizeof(mimetype));
215  while (mime->id != AV_CODEC_ID_NONE) {
216  if (!strncmp(mime->str, mimetype, sizeof(mimetype))) {
217  id = mime->id;
218  break;
219  }
220  mime++;
221  }
222  if (id == AV_CODEC_ID_NONE) {
223  av_log(s, AV_LOG_ERROR, "Unknown attached picture mimetype: %s.\n",
224  mimetype);
225  return 0;
226  }
227 
228  if (picsize >= len) {
229  av_log(s, AV_LOG_ERROR, "Invalid attached picture data size: %d >= %d.\n",
230  picsize, len);
231  return AVERROR_INVALIDDATA;
232  }
233 
234  /* picture description */
235  desc_len = (len - picsize) * 2 + 1;
236  desc = av_malloc(desc_len);
237  if (!desc)
238  return AVERROR(ENOMEM);
239  len -= avio_get_str16le(s->pb, len - picsize, desc, desc_len);
240 
241  ret = av_get_packet(s->pb, &pkt, picsize);
242  if (ret < 0)
243  goto fail;
244 
245  st = avformat_new_stream(s, NULL);
246  if (!st) {
247  ret = AVERROR(ENOMEM);
248  goto fail;
249  }
252  st->codec->codec_id = id;
253  st->attached_pic = pkt;
254  st->attached_pic.stream_index = st->index;
256 
257  if (*desc)
258  av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL);
259  else
260  av_freep(&desc);
261 
262  av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[type], 0);
263 
264  return 0;
265 
266 fail:
267  av_freep(&desc);
268  av_free_packet(&pkt);
269  return ret;
270 }
271 
272 static void get_id3_tag(AVFormatContext *s, int len)
273 {
274  ID3v2ExtraMeta *id3v2_extra_meta = NULL;
275 
276  ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta);
277  if (id3v2_extra_meta)
278  ff_id3v2_parse_apic(s, &id3v2_extra_meta);
279  ff_id3v2_free_extra_meta(&id3v2_extra_meta);
280 }
281 
282 static void get_tag(AVFormatContext *s, const char *key, int type, int len, int type2_size)
283 {
284  char *value;
285  int64_t off = avio_tell(s->pb);
286 
287  if ((unsigned)len >= (UINT_MAX - 1) / 2)
288  return;
289 
290  value = av_malloc(2 * len + 1);
291  if (!value)
292  goto finish;
293 
294  if (type == 0) { // UTF16-LE
295  avio_get_str16le(s->pb, len, value, 2 * len + 1);
296  } else if (type == 1) { // byte array
297  if (!strcmp(key, "WM/Picture")) { // handle cover art
298  asf_read_picture(s, len);
299  } else if (!strcmp(key, "ID3")) { // handle ID3 tag
300  get_id3_tag(s, len);
301  } else {
302  av_log(s, AV_LOG_VERBOSE, "Unsupported byte array in tag %s.\n", key);
303  }
304  goto finish;
305  } else if (type > 1 && type <= 5) { // boolean or DWORD or QWORD or WORD
306  uint64_t num = get_value(s->pb, type, type2_size);
307  snprintf(value, len, "%"PRIu64, num);
308  } else if (type == 6) { // (don't) handle GUID
309  av_log(s, AV_LOG_DEBUG, "Unsupported GUID value in tag %s.\n", key);
310  goto finish;
311  } else {
312  av_log(s, AV_LOG_DEBUG,
313  "Unsupported value type %d in tag %s.\n", type, key);
314  goto finish;
315  }
316  if (*value)
317  av_dict_set(&s->metadata, key, value, 0);
318 
319 finish:
320  av_freep(&value);
321  avio_seek(s->pb, off + len, SEEK_SET);
322 }
323 
325 {
326  ASFContext *asf = s->priv_data;
327  AVIOContext *pb = s->pb;
328 
329  ff_get_guid(pb, &asf->hdr.guid);
330  asf->hdr.file_size = avio_rl64(pb);
331  asf->hdr.create_time = avio_rl64(pb);
332  avio_rl64(pb); /* number of packets */
333  asf->hdr.play_time = avio_rl64(pb);
334  asf->hdr.send_time = avio_rl64(pb);
335  asf->hdr.preroll = avio_rl32(pb);
336  asf->hdr.ignore = avio_rl32(pb);
337  asf->hdr.flags = avio_rl32(pb);
338  asf->hdr.min_pktsize = avio_rl32(pb);
339  asf->hdr.max_pktsize = avio_rl32(pb);
340  if (asf->hdr.min_pktsize >= (1U << 29))
341  return AVERROR_INVALIDDATA;
342  asf->hdr.max_bitrate = avio_rl32(pb);
343  s->packet_size = asf->hdr.max_pktsize;
344 
345  return 0;
346 }
347 
349 {
350  ASFContext *asf = s->priv_data;
351  AVIOContext *pb = s->pb;
352  AVStream *st;
353  ASFStream *asf_st;
354  ff_asf_guid g;
355  enum AVMediaType type;
356  int type_specific_size, sizeX;
357  unsigned int tag1;
358  int64_t pos1, pos2, start_time;
359  int test_for_ext_stream_audio, is_dvr_ms_audio = 0;
360 
361  if (s->nb_streams == ASF_MAX_STREAMS) {
362  av_log(s, AV_LOG_ERROR, "too many streams\n");
363  return AVERROR(EINVAL);
364  }
365 
366  pos1 = avio_tell(pb);
367 
368  st = avformat_new_stream(s, NULL);
369  if (!st)
370  return AVERROR(ENOMEM);
371  avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
372  asf_st = av_mallocz(sizeof(ASFStream));
373  if (!asf_st)
374  return AVERROR(ENOMEM);
375  st->priv_data = asf_st;
376  st->start_time = 0;
377  start_time = asf->hdr.preroll;
378 
379  asf_st->stream_language_index = 128; // invalid stream index means no language info
380 
381  if (!(asf->hdr.flags & 0x01)) { // if we aren't streaming...
382  st->duration = asf->hdr.play_time /
383  (10000000 / 1000) - start_time;
384  }
385  ff_get_guid(pb, &g);
386 
387  test_for_ext_stream_audio = 0;
388  if (!ff_guidcmp(&g, &ff_asf_audio_stream)) {
389  type = AVMEDIA_TYPE_AUDIO;
390  } else if (!ff_guidcmp(&g, &ff_asf_video_stream)) {
391  type = AVMEDIA_TYPE_VIDEO;
392  } else if (!ff_guidcmp(&g, &ff_asf_jfif_media)) {
393  type = AVMEDIA_TYPE_VIDEO;
395  } else if (!ff_guidcmp(&g, &ff_asf_command_stream)) {
396  type = AVMEDIA_TYPE_DATA;
398  test_for_ext_stream_audio = 1;
399  type = AVMEDIA_TYPE_UNKNOWN;
400  } else {
401  return -1;
402  }
403  ff_get_guid(pb, &g);
404  avio_skip(pb, 8); /* total_size */
405  type_specific_size = avio_rl32(pb);
406  avio_rl32(pb);
407  st->id = avio_rl16(pb) & 0x7f; /* stream id */
408  // mapping of asf ID to AV stream ID;
409  asf->asfid2avid[st->id] = s->nb_streams - 1;
410 
411  avio_rl32(pb);
412 
413  if (test_for_ext_stream_audio) {
414  ff_get_guid(pb, &g);
416  type = AVMEDIA_TYPE_AUDIO;
417  is_dvr_ms_audio = 1;
418  ff_get_guid(pb, &g);
419  avio_rl32(pb);
420  avio_rl32(pb);
421  avio_rl32(pb);
422  ff_get_guid(pb, &g);
423  avio_rl32(pb);
424  }
425  }
426 
427  st->codec->codec_type = type;
428  if (type == AVMEDIA_TYPE_AUDIO) {
429  int ret = ff_get_wav_header(pb, st->codec, type_specific_size);
430  if (ret < 0)
431  return ret;
432  if (is_dvr_ms_audio) {
433  // codec_id and codec_tag are unreliable in dvr_ms
434  // files. Set them later by probing stream.
436  st->codec->codec_tag = 0;
437  }
438  if (st->codec->codec_id == AV_CODEC_ID_AAC)
440  else
442  /* We have to init the frame size at some point .... */
443  pos2 = avio_tell(pb);
444  if (size >= (pos2 + 8 - pos1 + 24)) {
445  asf_st->ds_span = avio_r8(pb);
446  asf_st->ds_packet_size = avio_rl16(pb);
447  asf_st->ds_chunk_size = avio_rl16(pb);
448  avio_rl16(pb); // ds_data_size
449  avio_r8(pb); // ds_silence_data
450  }
451  if (asf_st->ds_span > 1) {
452  if (!asf_st->ds_chunk_size ||
453  (asf_st->ds_packet_size / asf_st->ds_chunk_size <= 1) ||
454  asf_st->ds_packet_size % asf_st->ds_chunk_size)
455  asf_st->ds_span = 0; // disable descrambling
456  }
457  } else if (type == AVMEDIA_TYPE_VIDEO &&
458  size - (avio_tell(pb) - pos1 + 24) >= 51) {
459  avio_rl32(pb);
460  avio_rl32(pb);
461  avio_r8(pb);
462  avio_rl16(pb); /* size */
463  sizeX = avio_rl32(pb); /* size */
464  st->codec->width = avio_rl32(pb);
465  st->codec->height = avio_rl32(pb);
466  /* not available for asf */
467  avio_rl16(pb); /* panes */
468  st->codec->bits_per_coded_sample = avio_rl16(pb); /* depth */
469  tag1 = avio_rl32(pb);
470  avio_skip(pb, 20);
471  if (sizeX > 40) {
472  st->codec->extradata_size = sizeX - 40;
475  avio_read(pb, st->codec->extradata, st->codec->extradata_size);
476  }
477 
478  /* Extract palette from extradata if bpp <= 8 */
479  /* This code assumes that extradata contains only palette */
480  /* This is true for all paletted codecs implemented in libavcodec */
481  if (st->codec->extradata_size && (st->codec->bits_per_coded_sample <= 8)) {
482 #if HAVE_BIGENDIAN
483  int i;
484  for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE) / 4; i++)
485  asf_st->palette[i] = av_bswap32(((uint32_t *)st->codec->extradata)[i]);
486 #else
487  memcpy(asf_st->palette, st->codec->extradata,
489 #endif
490  asf_st->palette_changed = 1;
491  }
492 
493  st->codec->codec_tag = tag1;
495  if (tag1 == MKTAG('D', 'V', 'R', ' ')) {
497  /* issue658 contains wrong w/h and MS even puts a fake seq header
498  * with wrong w/h in extradata while a correct one is in the stream.
499  * maximum lameness */
500  st->codec->width =
501  st->codec->height = 0;
502  av_freep(&st->codec->extradata);
503  st->codec->extradata_size = 0;
504  }
505  if (st->codec->codec_id == AV_CODEC_ID_H264)
507  }
508  pos2 = avio_tell(pb);
509  avio_skip(pb, size - (pos2 - pos1 + 24));
510 
511  return 0;
512 }
513 
515 {
516  ASFContext *asf = s->priv_data;
517  AVIOContext *pb = s->pb;
518  ff_asf_guid g;
519  int ext_len, payload_ext_ct, stream_ct, i;
520  uint32_t leak_rate, stream_num;
521  unsigned int stream_languageid_index;
522 
523  avio_rl64(pb); // starttime
524  avio_rl64(pb); // endtime
525  leak_rate = avio_rl32(pb); // leak-datarate
526  avio_rl32(pb); // bucket-datasize
527  avio_rl32(pb); // init-bucket-fullness
528  avio_rl32(pb); // alt-leak-datarate
529  avio_rl32(pb); // alt-bucket-datasize
530  avio_rl32(pb); // alt-init-bucket-fullness
531  avio_rl32(pb); // max-object-size
532  avio_rl32(pb); // flags (reliable,seekable,no_cleanpoints?,resend-live-cleanpoints, rest of bits reserved)
533  stream_num = avio_rl16(pb); // stream-num
534 
535  stream_languageid_index = avio_rl16(pb); // stream-language-id-index
536  if (stream_num < 128)
537  asf->streams[stream_num].stream_language_index = stream_languageid_index;
538 
539  avio_rl64(pb); // avg frametime in 100ns units
540  stream_ct = avio_rl16(pb); // stream-name-count
541  payload_ext_ct = avio_rl16(pb); // payload-extension-system-count
542 
543  if (stream_num < 128)
544  asf->stream_bitrates[stream_num] = leak_rate;
545 
546  for (i = 0; i < stream_ct; i++) {
547  avio_rl16(pb);
548  ext_len = avio_rl16(pb);
549  avio_skip(pb, ext_len);
550  }
551 
552  for (i = 0; i < payload_ext_ct; i++) {
553  ff_get_guid(pb, &g);
554  avio_skip(pb, 2);
555  ext_len = avio_rl32(pb);
556  avio_skip(pb, ext_len);
557  }
558 
559  return 0;
560 }
561 
563 {
564  AVIOContext *pb = s->pb;
565  int len1, len2, len3, len4, len5;
566 
567  len1 = avio_rl16(pb);
568  len2 = avio_rl16(pb);
569  len3 = avio_rl16(pb);
570  len4 = avio_rl16(pb);
571  len5 = avio_rl16(pb);
572  get_tag(s, "title", 0, len1, 32);
573  get_tag(s, "author", 0, len2, 32);
574  get_tag(s, "copyright", 0, len3, 32);
575  get_tag(s, "comment", 0, len4, 32);
576  avio_skip(pb, len5);
577 
578  return 0;
579 }
580 
582 {
583  AVIOContext *pb = s->pb;
584  ASFContext *asf = s->priv_data;
585  int desc_count, i, ret;
586 
587  desc_count = avio_rl16(pb);
588  for (i = 0; i < desc_count; i++) {
589  int name_len, value_type, value_len;
590  char name[1024];
591 
592  name_len = avio_rl16(pb);
593  if (name_len % 2) // must be even, broken lavf versions wrote len-1
594  name_len += 1;
595  if ((ret = avio_get_str16le(pb, name_len, name, sizeof(name))) < name_len)
596  avio_skip(pb, name_len - ret);
597  value_type = avio_rl16(pb);
598  value_len = avio_rl16(pb);
599  if (!value_type && value_len % 2)
600  value_len += 1;
601  /* My sample has that stream set to 0 maybe that mean the container.
602  * ASF stream count starts at 1. I am using 0 to the container value
603  * since it's unused. */
604  if (!strcmp(name, "AspectRatioX"))
605  asf->dar[0].num = get_value(s->pb, value_type, 32);
606  else if (!strcmp(name, "AspectRatioY"))
607  asf->dar[0].den = get_value(s->pb, value_type, 32);
608  else
609  get_tag(s, name, value_type, value_len, 32);
610  }
611 
612  return 0;
613 }
614 
616 {
617  AVIOContext *pb = s->pb;
618  ASFContext *asf = s->priv_data;
619  int j, ret;
620  int stream_count = avio_rl16(pb);
621  for (j = 0; j < stream_count; j++) {
622  char lang[6];
623  unsigned int lang_len = avio_r8(pb);
624  if ((ret = avio_get_str16le(pb, lang_len, lang,
625  sizeof(lang))) < lang_len)
626  avio_skip(pb, lang_len - ret);
627  if (j < 128)
628  av_strlcpy(asf->stream_languages[j], lang,
629  sizeof(*asf->stream_languages));
630  }
631 
632  return 0;
633 }
634 
635 static int asf_read_metadata(AVFormatContext *s, int64_t size)
636 {
637  AVIOContext *pb = s->pb;
638  ASFContext *asf = s->priv_data;
639  int n, stream_num, name_len, value_len;
640  int ret, i;
641  n = avio_rl16(pb);
642 
643  for (i = 0; i < n; i++) {
644  char name[1024];
645  int value_type;
646 
647  avio_rl16(pb); // lang_list_index
648  stream_num = avio_rl16(pb);
649  name_len = avio_rl16(pb);
650  value_type = avio_rl16(pb); /* value_type */
651  value_len = avio_rl32(pb);
652 
653  if ((ret = avio_get_str16le(pb, name_len, name, sizeof(name))) < name_len)
654  avio_skip(pb, name_len - ret);
655  av_dlog(s, "%d stream %d name_len %2d type %d len %4d <%s>\n",
656  i, stream_num, name_len, value_type, value_len, name);
657 
658  if (!strcmp(name, "AspectRatioX")){
659  int aspect_x = get_value(s->pb, value_type, 16);
660  if(stream_num < 128)
661  asf->dar[stream_num].num = aspect_x;
662  } else if(!strcmp(name, "AspectRatioY")){
663  int aspect_y = get_value(s->pb, value_type, 16);
664  if(stream_num < 128)
665  asf->dar[stream_num].den = aspect_y;
666  } else {
667  get_tag(s, name, value_type, value_len, 16);
668  }
669  }
670 
671  return 0;
672 }
673 
674 static int asf_read_marker(AVFormatContext *s, int64_t size)
675 {
676  AVIOContext *pb = s->pb;
677  ASFContext *asf = s->priv_data;
678  int i, count, name_len, ret;
679  char name[1024];
680 
681  avio_rl64(pb); // reserved 16 bytes
682  avio_rl64(pb); // ...
683  count = avio_rl32(pb); // markers count
684  avio_rl16(pb); // reserved 2 bytes
685  name_len = avio_rl16(pb); // name length
686  avio_skip(pb, name_len);
687 
688  for (i = 0; i < count; i++) {
689  int64_t pres_time;
690  int name_len;
691 
692  if (avio_feof(pb))
693  return AVERROR_INVALIDDATA;
694 
695  avio_rl64(pb); // offset, 8 bytes
696  pres_time = avio_rl64(pb); // presentation time
697  pres_time -= asf->hdr.preroll * 10000;
698  avio_rl16(pb); // entry length
699  avio_rl32(pb); // send time
700  avio_rl32(pb); // flags
701  name_len = avio_rl32(pb); // name length
702  if ((ret = avio_get_str16le(pb, name_len * 2, name,
703  sizeof(name))) < name_len)
704  avio_skip(pb, name_len - ret);
705  avpriv_new_chapter(s, i, (AVRational) { 1, 10000000 }, pres_time,
707  }
708 
709  return 0;
710 }
711 
713 {
714  ASFContext *asf = s->priv_data;
715  ff_asf_guid g;
716  AVIOContext *pb = s->pb;
717  int i;
718  int64_t gsize;
719 
720  ff_get_guid(pb, &g);
721  if (ff_guidcmp(&g, &ff_asf_header))
722  return -1;
723  avio_rl64(pb);
724  avio_rl32(pb);
725  avio_r8(pb);
726  avio_r8(pb);
727  memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid));
728  for (;;) {
729  uint64_t gpos = avio_tell(pb);
730  ff_get_guid(pb, &g);
731  gsize = avio_rl64(pb);
732  print_guid(&g);
733  if (!ff_guidcmp(&g, &ff_asf_data_header)) {
734  asf->data_object_offset = avio_tell(pb);
735  /* If not streaming, gsize is not unlimited (how?),
736  * and there is enough space in the file.. */
737  if (!(asf->hdr.flags & 0x01) && gsize >= 100)
738  asf->data_object_size = gsize - 24;
739  else
740  asf->data_object_size = (uint64_t)-1;
741  break;
742  }
743  if (gsize < 24)
744  return -1;
745  if (!ff_guidcmp(&g, &ff_asf_file_header)) {
746  int ret = asf_read_file_properties(s, gsize);
747  if (ret < 0)
748  return ret;
749  } else if (!ff_guidcmp(&g, &ff_asf_stream_header)) {
750  int ret = asf_read_stream_properties(s, gsize);
751  if (ret < 0)
752  return ret;
753  } else if (!ff_guidcmp(&g, &ff_asf_comment_header)) {
754  asf_read_content_desc(s, gsize);
755  } else if (!ff_guidcmp(&g, &ff_asf_language_guid)) {
756  asf_read_language_list(s, gsize);
757  } else if (!ff_guidcmp(&g, &ff_asf_extended_content_header)) {
758  asf_read_ext_content_desc(s, gsize);
759  } else if (!ff_guidcmp(&g, &ff_asf_metadata_header)) {
760  asf_read_metadata(s, gsize);
761  } else if (!ff_guidcmp(&g, &ff_asf_metadata_library_header)) {
762  asf_read_metadata(s, gsize);
763  } else if (!ff_guidcmp(&g, &ff_asf_ext_stream_header)) {
765 
766  // there could be a optional stream properties object to follow
767  // if so the next iteration will pick it up
768  continue;
769  } else if (!ff_guidcmp(&g, &ff_asf_head1_guid)) {
770  ff_get_guid(pb, &g);
771  avio_skip(pb, 6);
772  continue;
773  } else if (!ff_guidcmp(&g, &ff_asf_marker_header)) {
774  asf_read_marker(s, gsize);
775  } else if (pb->eof_reached) {
776  return -1;
777  } else {
778  if (!s->keylen) {
781  "DRM protected stream detected, decoding will likely fail!\n");
782  } else if (!ff_guidcmp(&g, &ff_asf_ext_content_encryption)) {
784  "Ext DRM protected stream detected, decoding will likely fail!\n");
785  } else if (!ff_guidcmp(&g, &ff_asf_digital_signature)) {
787  "Digital signature detected, decoding will likely fail!\n");
788  }
789  }
790  }
791  if (avio_tell(pb) != gpos + gsize)
792  av_log(s, AV_LOG_DEBUG,
793  "gpos mismatch our pos=%"PRIu64", end=%"PRId64"\n",
794  avio_tell(pb) - gpos, gsize);
795  avio_seek(pb, gpos + gsize, SEEK_SET);
796  }
797  ff_get_guid(pb, &g);
798  avio_rl64(pb);
799  avio_r8(pb);
800  avio_r8(pb);
801  if (pb->eof_reached)
802  return -1;
803  asf->data_offset = avio_tell(pb);
804  asf->packet_size_left = 0;
805 
806  for (i = 0; i < 128; i++) {
807  int stream_num = asf->asfid2avid[i];
808  if (stream_num >= 0) {
809  AVStream *st = s->streams[stream_num];
810  if (!st->codec->bit_rate)
811  st->codec->bit_rate = asf->stream_bitrates[i];
812  if (asf->dar[i].num > 0 && asf->dar[i].den > 0) {
815  asf->dar[i].num, asf->dar[i].den, INT_MAX);
816  } else if ((asf->dar[0].num > 0) && (asf->dar[0].den > 0) &&
817  // Use ASF container value if the stream doesn't set AR.
821  asf->dar[0].num, asf->dar[0].den, INT_MAX);
822 
823  av_dlog(s, "i=%d, st->codec->codec_type:%d, asf->dar %d:%d sar=%d:%d\n",
824  i, st->codec->codec_type, asf->dar[i].num, asf->dar[i].den,
826 
827  // copy and convert language codes to the frontend
828  if (asf->streams[i].stream_language_index < 128) {
829  const char *rfc1766 = asf->stream_languages[asf->streams[i].stream_language_index];
830  if (rfc1766 && strlen(rfc1766) > 1) {
831  const char primary_tag[3] = { rfc1766[0], rfc1766[1], '\0' }; // ignore country code if any
832  const char *iso6392 = av_convert_lang_to(primary_tag,
834  if (iso6392)
835  av_dict_set(&st->metadata, "language", iso6392, 0);
836  }
837  }
838  }
839  }
840 
842 
843  return 0;
844 }
845 
846 #define DO_2BITS(bits, var, defval) \
847  switch (bits & 3) { \
848  case 3: \
849  var = avio_rl32(pb); \
850  rsize += 4; \
851  break; \
852  case 2: \
853  var = avio_rl16(pb); \
854  rsize += 2; \
855  break; \
856  case 1: \
857  var = avio_r8(pb); \
858  rsize++; \
859  break; \
860  default: \
861  var = defval; \
862  break; \
863  }
864 
872 {
873  ASFContext *asf = s->priv_data;
874  uint32_t packet_length, padsize;
875  int rsize = 8;
876  int c, d, e, off;
877 
878  // if we do not know packet size, allow skipping up to 32 kB
879  off = 32768;
880  if (asf->no_resync_search)
881  off = 3;
882  else if (s->packet_size > 0)
883  off = (avio_tell(pb) - s->data_offset) % s->packet_size + 3;
884 
885  c = d = e = -1;
886  while (off-- > 0) {
887  c = d;
888  d = e;
889  e = avio_r8(pb);
890  if (c == 0x82 && !d && !e)
891  break;
892  }
893 
894  if (c != 0x82) {
895  /* This code allows handling of -EAGAIN at packet boundaries (i.e.
896  * if the packet sync code above triggers -EAGAIN). This does not
897  * imply complete -EAGAIN handling support at random positions in
898  * the stream. */
899  if (pb->error == AVERROR(EAGAIN))
900  return AVERROR(EAGAIN);
901  if (!pb->eof_reached)
902  av_log(s, AV_LOG_ERROR,
903  "ff asf bad header %x at:%"PRId64"\n", c, avio_tell(pb));
904  }
905  if ((c & 0x8f) == 0x82) {
906  if (d || e) {
907  if (!pb->eof_reached)
908  av_log(s, AV_LOG_ERROR, "ff asf bad non zero\n");
909  return -1;
910  }
911  c = avio_r8(pb);
912  d = avio_r8(pb);
913  rsize += 3;
914  } else if (!pb->eof_reached) {
915  avio_seek(pb, -1, SEEK_CUR); // FIXME
916  }
917 
918  asf->packet_flags = c;
919  asf->packet_property = d;
920 
921  DO_2BITS(asf->packet_flags >> 5, packet_length, s->packet_size);
922  DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence ignored
923  DO_2BITS(asf->packet_flags >> 3, padsize, 0); // padding length
924 
925  // the following checks prevent overflows and infinite loops
926  if (!packet_length || packet_length >= (1U << 29)) {
927  av_log(s, AV_LOG_ERROR,
928  "invalid packet_length %"PRIu32" at:%"PRId64"\n",
929  packet_length, avio_tell(pb));
930  return -1;
931  }
932  if (padsize >= packet_length) {
933  av_log(s, AV_LOG_ERROR,
934  "invalid padsize %"PRIu32" at:%"PRId64"\n", padsize, avio_tell(pb));
935  return -1;
936  }
937 
938  asf->packet_timestamp = avio_rl32(pb);
939  avio_rl16(pb); /* duration */
940  // rsize has at least 11 bytes which have to be present
941 
942  if (asf->packet_flags & 0x01) {
943  asf->packet_segsizetype = avio_r8(pb);
944  rsize++;
945  asf->packet_segments = asf->packet_segsizetype & 0x3f;
946  } else {
947  asf->packet_segments = 1;
948  asf->packet_segsizetype = 0x80;
949  }
950  if (rsize > packet_length - padsize) {
951  asf->packet_size_left = 0;
952  av_log(s, AV_LOG_ERROR,
953  "invalid packet header length %d for pktlen %"PRIu32"-%"PRIu32" at %"PRId64"\n",
954  rsize, packet_length, padsize, avio_tell(pb));
955  return -1;
956  }
957  asf->packet_size_left = packet_length - padsize - rsize;
958  if (packet_length < asf->hdr.min_pktsize)
959  padsize += asf->hdr.min_pktsize - packet_length;
960  asf->packet_padsize = padsize;
961  av_dlog(s, "packet: size=%d padsize=%d left=%d\n",
963  return 0;
964 }
965 
971 {
972  ASFContext *asf = s->priv_data;
973  int rsize = 1;
974  int num = avio_r8(pb);
975  int64_t ts0;
976 
977  asf->packet_segments--;
978  asf->packet_key_frame = num >> 7;
979  asf->stream_index = asf->asfid2avid[num & 0x7f];
980  // sequence should be ignored!
981  DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
982  DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
984  av_dlog(asf, "key:%d stream:%d seq:%d offset:%d replic_size:%d\n",
985  asf->packet_key_frame, asf->stream_index, asf->packet_seq,
987  if (asf->packet_replic_size >= 8) {
988  asf->packet_obj_size = avio_rl32(pb);
989  if (asf->packet_obj_size >= (1 << 24) || asf->packet_obj_size <= 0) {
990  av_log(s, AV_LOG_ERROR, "packet_obj_size invalid\n");
991  return -1;
992  }
993  asf->packet_frag_timestamp = avio_rl32(pb); // timestamp
994  if (asf->packet_replic_size >= 8 + 38 + 4) {
995  avio_skip(pb, 10);
996  ts0 = avio_rl64(pb);
997  avio_skip(pb, 8);
998  avio_skip(pb, 12);
999  avio_rl32(pb);
1000  avio_skip(pb, asf->packet_replic_size - 8 - 38 - 4);
1001  if (ts0 != -1)
1002  asf->packet_frag_timestamp = ts0 / 10000;
1003  else
1005  } else
1006  avio_skip(pb, asf->packet_replic_size - 8);
1007  rsize += asf->packet_replic_size; // FIXME - check validity
1008  } else if (asf->packet_replic_size == 1) {
1009  // multipacket - frag_offset is beginning timestamp
1011  asf->packet_frag_offset = 0;
1013 
1014  asf->packet_time_delta = avio_r8(pb);
1015  rsize++;
1016  } else if (asf->packet_replic_size != 0) {
1017  av_log(s, AV_LOG_ERROR, "unexpected packet_replic_size of %d\n",
1018  asf->packet_replic_size);
1019  return -1;
1020  }
1021  if (asf->packet_flags & 0x01) {
1022  DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
1023  if (rsize > asf->packet_size_left) {
1024  av_log(s, AV_LOG_ERROR, "packet_replic_size is invalid\n");
1025  return -1;
1026  } else if (asf->packet_frag_size > asf->packet_size_left - rsize) {
1027  if (asf->packet_frag_size > asf->packet_size_left - rsize + asf->packet_padsize) {
1028  av_log(s, AV_LOG_ERROR, "packet_frag_size is invalid (%d-%d)\n",
1029  asf->packet_size_left, rsize);
1030  return -1;
1031  } else {
1032  int diff = asf->packet_frag_size - (asf->packet_size_left - rsize);
1033  asf->packet_size_left += diff;
1034  asf->packet_padsize -= diff;
1035  }
1036  }
1037  } else {
1038  if (rsize > asf->packet_size_left) {
1039  av_log(s, AV_LOG_ERROR, "packet_replic_size is invalid\n");
1040  return -1;
1041  }
1042  asf->packet_frag_size = asf->packet_size_left - rsize;
1043  }
1044  if (asf->packet_replic_size == 1) {
1045  asf->packet_multi_size = asf->packet_frag_size;
1046  if (asf->packet_multi_size > asf->packet_size_left)
1047  return -1;
1048  }
1049  asf->packet_size_left -= rsize;
1050 
1051  return 0;
1052 }
1053 
1064 {
1065  ASFContext *asf = s->priv_data;
1066  ASFStream *asf_st = 0;
1067  for (;;) {
1068  int ret;
1069 
1070  if (pb->eof_reached)
1071  return AVERROR_EOF;
1072 
1073  if (asf->packet_size_left < FRAME_HEADER_SIZE ||
1074  asf->packet_segments < 1) {
1075  int ret = asf->packet_size_left + asf->packet_padsize;
1076 
1077  assert(ret >= 0);
1078  /* fail safe */
1079  avio_skip(pb, ret);
1080 
1081  asf->packet_pos = avio_tell(pb);
1082  if (asf->data_object_size != (uint64_t)-1 &&
1083  (asf->packet_pos - asf->data_object_offset >= asf->data_object_size))
1084  return AVERROR_EOF; /* Do not exceed the size of the data object */
1085  return 1;
1086  }
1087  if (asf->packet_time_start == 0) {
1088  if (asf_read_frame_header(s, pb) < 0) {
1089  asf->packet_segments = 0;
1090  continue;
1091  }
1092  if (asf->stream_index < 0 ||
1093  s->streams[asf->stream_index]->discard >= AVDISCARD_ALL ||
1094  (!asf->packet_key_frame &&
1095  s->streams[asf->stream_index]->discard >= AVDISCARD_NONKEY)) {
1096  asf->packet_time_start = 0;
1097  /* unhandled packet (should not happen) */
1098  avio_skip(pb, asf->packet_frag_size);
1099  asf->packet_size_left -= asf->packet_frag_size;
1100  if (asf->stream_index < 0)
1101  av_log(s, AV_LOG_ERROR, "ff asf skip %d (unknown stream)\n",
1102  asf->packet_frag_size);
1103  continue;
1104  }
1105  asf->asf_st = s->streams[asf->stream_index]->priv_data;
1106  }
1107  asf_st = asf->asf_st;
1108  av_assert0(asf_st);
1109 
1110  if (!asf_st->frag_offset && asf->packet_frag_offset) {
1111  av_dlog(s, "skipping asf data pkt with fragment offset for "
1112  "stream:%d, expected:%d but got %d from pkt)\n",
1113  asf->stream_index, asf_st->frag_offset,
1114  asf->packet_frag_offset);
1115  avio_skip(pb, asf->packet_frag_size);
1116  asf->packet_size_left -= asf->packet_frag_size;
1117  continue;
1118  }
1119 
1120  if (asf->packet_replic_size == 1) {
1121  // frag_offset is here used as the beginning timestamp
1123  asf->packet_time_start += asf->packet_time_delta;
1124  asf->packet_obj_size = asf->packet_frag_size = avio_r8(pb);
1125  asf->packet_size_left--;
1126  asf->packet_multi_size--;
1127  if (asf->packet_multi_size < asf->packet_obj_size) {
1128  asf->packet_time_start = 0;
1129  avio_skip(pb, asf->packet_multi_size);
1130  asf->packet_size_left -= asf->packet_multi_size;
1131  continue;
1132  }
1133  asf->packet_multi_size -= asf->packet_obj_size;
1134  }
1135  if (asf_st->frag_offset + asf->packet_frag_size <= asf_st->pkt.size &&
1136  asf_st->frag_offset + asf->packet_frag_size > asf->packet_obj_size) {
1137  av_log(s, AV_LOG_INFO, "ignoring invalid packet_obj_size (%d %d %d %d)\n",
1138  asf_st->frag_offset, asf->packet_frag_size,
1139  asf->packet_obj_size, asf_st->pkt.size);
1140  asf->packet_obj_size = asf_st->pkt.size;
1141  }
1142 
1143  if (asf_st->pkt.size != asf->packet_obj_size ||
1144  // FIXME is this condition sufficient?
1145  asf_st->frag_offset + asf->packet_frag_size > asf_st->pkt.size) {
1146  if (asf_st->pkt.data) {
1147  av_log(s, AV_LOG_INFO,
1148  "freeing incomplete packet size %d, new %d\n",
1149  asf_st->pkt.size, asf->packet_obj_size);
1150  asf_st->frag_offset = 0;
1151  av_free_packet(&asf_st->pkt);
1152  }
1153  /* new packet */
1154  av_new_packet(&asf_st->pkt, asf->packet_obj_size);
1155  asf_st->seq = asf->packet_seq;
1156  asf_st->pkt.dts = asf->packet_frag_timestamp - asf->hdr.preroll;
1157  asf_st->pkt.stream_index = asf->stream_index;
1158  asf_st->pkt.pos = asf_st->packet_pos = asf->packet_pos;
1159 
1160  if (asf_st->pkt.data && asf_st->palette_changed) {
1161  uint8_t *pal;
1163  AVPALETTE_SIZE);
1164  if (!pal) {
1165  av_log(s, AV_LOG_ERROR, "Cannot append palette to packet\n");
1166  } else {
1167  memcpy(pal, asf_st->palette, AVPALETTE_SIZE);
1168  asf_st->palette_changed = 0;
1169  }
1170  }
1171  av_dlog(asf, "new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n",
1172  asf->stream_index, asf->packet_key_frame,
1173  asf_st->pkt.flags & AV_PKT_FLAG_KEY,
1175  asf->packet_obj_size);
1177  asf->packet_key_frame = 1;
1178  if (asf->packet_key_frame)
1179  asf_st->pkt.flags |= AV_PKT_FLAG_KEY;
1180  }
1181 
1182  /* read data */
1183  av_dlog(asf, "READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n",
1184  s->packet_size, asf_st->pkt.size, asf->packet_frag_offset,
1185  asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data);
1186  asf->packet_size_left -= asf->packet_frag_size;
1187  if (asf->packet_size_left < 0)
1188  continue;
1189 
1190  if (asf->packet_frag_offset >= asf_st->pkt.size ||
1191  asf->packet_frag_size > asf_st->pkt.size - asf->packet_frag_offset) {
1192  av_log(s, AV_LOG_ERROR,
1193  "packet fragment position invalid %u,%u not in %u\n",
1195  asf_st->pkt.size);
1196  continue;
1197  }
1198 
1199  ret = avio_read(pb, asf_st->pkt.data + asf->packet_frag_offset,
1200  asf->packet_frag_size);
1201  if (ret != asf->packet_frag_size) {
1202  if (ret < 0 || asf->packet_frag_offset + ret == 0)
1203  return ret < 0 ? ret : AVERROR_EOF;
1204 
1205  if (asf_st->ds_span > 1) {
1206  // scrambling, we can either drop it completely or fill the remainder
1207  // TODO: should we fill the whole packet instead of just the current
1208  // fragment?
1209  memset(asf_st->pkt.data + asf->packet_frag_offset + ret, 0,
1210  asf->packet_frag_size - ret);
1211  ret = asf->packet_frag_size;
1212  } else {
1213  // no scrambling, so we can return partial packets
1214  av_shrink_packet(&asf_st->pkt, asf->packet_frag_offset + ret);
1215  }
1216  }
1217  if (s->key && s->keylen == 20)
1218  ff_asfcrypt_dec(s->key, asf_st->pkt.data + asf->packet_frag_offset,
1219  ret);
1220  asf_st->frag_offset += ret;
1221  /* test if whole packet is read */
1222  if (asf_st->frag_offset == asf_st->pkt.size) {
1223  // workaround for macroshit radio DVR-MS files
1225  asf_st->pkt.size > 100) {
1226  int i;
1227  for (i = 0; i < asf_st->pkt.size && !asf_st->pkt.data[i]; i++)
1228  ;
1229  if (i == asf_st->pkt.size) {
1230  av_log(s, AV_LOG_DEBUG, "discarding ms fart\n");
1231  asf_st->frag_offset = 0;
1232  av_free_packet(&asf_st->pkt);
1233  continue;
1234  }
1235  }
1236 
1237  /* return packet */
1238  if (asf_st->ds_span > 1) {
1239  if (asf_st->pkt.size != asf_st->ds_packet_size * asf_st->ds_span) {
1240  av_log(s, AV_LOG_ERROR,
1241  "pkt.size != ds_packet_size * ds_span (%d %d %d)\n",
1242  asf_st->pkt.size, asf_st->ds_packet_size,
1243  asf_st->ds_span);
1244  } else {
1245  /* packet descrambling */
1246  AVBufferRef *buf = av_buffer_alloc(asf_st->pkt.size +
1248  if (buf) {
1249  uint8_t *newdata = buf->data;
1250  int offset = 0;
1251  memset(newdata + asf_st->pkt.size, 0,
1253  while (offset < asf_st->pkt.size) {
1254  int off = offset / asf_st->ds_chunk_size;
1255  int row = off / asf_st->ds_span;
1256  int col = off % asf_st->ds_span;
1257  int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size;
1258  assert(offset + asf_st->ds_chunk_size <= asf_st->pkt.size);
1259  assert(idx + 1 <= asf_st->pkt.size / asf_st->ds_chunk_size);
1260  memcpy(newdata + offset,
1261  asf_st->pkt.data + idx * asf_st->ds_chunk_size,
1262  asf_st->ds_chunk_size);
1263  offset += asf_st->ds_chunk_size;
1264  }
1265  av_buffer_unref(&asf_st->pkt.buf);
1266  asf_st->pkt.buf = buf;
1267  asf_st->pkt.data = buf->data;
1268  }
1269  }
1270  }
1271  asf_st->frag_offset = 0;
1272  *pkt = asf_st->pkt;
1273 #if FF_API_DESTRUCT_PACKET
1275  asf_st->pkt.destruct = NULL;
1277 #endif
1278  asf_st->pkt.buf = 0;
1279  asf_st->pkt.size = 0;
1280  asf_st->pkt.data = 0;
1281  asf_st->pkt.side_data_elems = 0;
1282  asf_st->pkt.side_data = NULL;
1283  break; // packet completed
1284  }
1285  }
1286  return 0;
1287 }
1288 
1290 {
1291  ASFContext *asf = s->priv_data;
1292 
1293  for (;;) {
1294  int ret;
1295 
1296  /* parse cached packets, if any */
1297  if ((ret = asf_parse_packet(s, s->pb, pkt)) <= 0)
1298  return ret;
1299  if ((ret = asf_get_packet(s, s->pb)) < 0)
1300  assert(asf->packet_size_left < FRAME_HEADER_SIZE ||
1301  asf->packet_segments < 1);
1302  asf->packet_time_start = 0;
1303  }
1304 }
1305 
1306 // Added to support seeking after packets have been read
1307 // If information is not reset, read_packet fails due to
1308 // leftover information from previous reads
1310 {
1311  ASFContext *asf = s->priv_data;
1312  ASFStream *asf_st;
1313  int i;
1314 
1315  asf->packet_size_left = 0;
1316  asf->packet_segments = 0;
1317  asf->packet_flags = 0;
1318  asf->packet_property = 0;
1319  asf->packet_timestamp = 0;
1320  asf->packet_segsizetype = 0;
1321  asf->packet_segments = 0;
1322  asf->packet_seq = 0;
1323  asf->packet_replic_size = 0;
1324  asf->packet_key_frame = 0;
1325  asf->packet_padsize = 0;
1326  asf->packet_frag_offset = 0;
1327  asf->packet_frag_size = 0;
1328  asf->packet_frag_timestamp = 0;
1329  asf->packet_multi_size = 0;
1330  asf->packet_obj_size = 0;
1331  asf->packet_time_delta = 0;
1332  asf->packet_time_start = 0;
1333 
1334  for (i = 0; i < s->nb_streams; i++) {
1335  asf_st = s->streams[i]->priv_data;
1336  if (!asf_st)
1337  continue;
1338  av_free_packet(&asf_st->pkt);
1339  asf_st->frag_offset = 0;
1340  asf_st->seq = 0;
1341  }
1342  asf->asf_st = NULL;
1343 }
1344 
1346 {
1347  asf_reset_header(s);
1348 
1349  return 0;
1350 }
1351 
1352 static int64_t asf_read_pts(AVFormatContext *s, int stream_index,
1353  int64_t *ppos, int64_t pos_limit)
1354 {
1355  AVPacket pkt1, *pkt = &pkt1;
1356  ASFStream *asf_st;
1357  int64_t pts;
1358  int64_t pos = *ppos;
1359  int i;
1360  int64_t start_pos[ASF_MAX_STREAMS];
1361 
1362  for (i = 0; i < s->nb_streams; i++)
1363  start_pos[i] = pos;
1364 
1365  if (s->packet_size > 0)
1366  pos = (pos + s->packet_size - 1 - s->data_offset) /
1367  s->packet_size * s->packet_size +
1368  s->data_offset;
1369  *ppos = pos;
1370  avio_seek(s->pb, pos, SEEK_SET);
1371 
1372  asf_reset_header(s);
1373  for (;;) {
1374  if (asf_read_packet(s, pkt) < 0) {
1375  av_log(s, AV_LOG_INFO, "asf_read_pts failed\n");
1376  return AV_NOPTS_VALUE;
1377  }
1378 
1379  pts = pkt->dts;
1380 
1381  av_free_packet(pkt);
1382  if (pkt->flags & AV_PKT_FLAG_KEY) {
1383  i = pkt->stream_index;
1384 
1385  asf_st = s->streams[i]->priv_data;
1386  av_assert0(asf_st);
1387 
1388 // assert((asf_st->packet_pos - s->data_offset) % s->packet_size == 0);
1389  pos = asf_st->packet_pos;
1390 
1391  av_add_index_entry(s->streams[i], pos, pts, pkt->size,
1392  pos - start_pos[i] + 1, AVINDEX_KEYFRAME);
1393  start_pos[i] = asf_st->packet_pos + 1;
1394 
1395  if (pkt->stream_index == stream_index)
1396  break;
1397  }
1398  }
1399 
1400  *ppos = pos;
1401  return pts;
1402 }
1403 
1404 static int asf_build_simple_index(AVFormatContext *s, int stream_index)
1405 {
1406  ff_asf_guid g;
1407  ASFContext *asf = s->priv_data;
1408  int64_t current_pos = avio_tell(s->pb);
1409  int i, ret = 0;
1410 
1411  avio_seek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET);
1412  if ((ret = ff_get_guid(s->pb, &g)) < 0)
1413  goto end;
1414 
1415  /* the data object can be followed by other top-level objects,
1416  * skip them until the simple index object is reached */
1417  while (ff_guidcmp(&g, &index_guid)) {
1418  int64_t gsize = avio_rl64(s->pb);
1419  if (gsize < 24 || s->pb->eof_reached) {
1420  goto end;
1421  }
1422  avio_skip(s->pb, gsize - 24);
1423  if ((ret = ff_get_guid(s->pb, &g)) < 0)
1424  goto end;
1425  }
1426 
1427  {
1428  int64_t itime, last_pos = -1;
1429  int pct, ict;
1430  int64_t av_unused gsize = avio_rl64(s->pb);
1431  if ((ret = ff_get_guid(s->pb, &g)) < 0)
1432  goto end;
1433  itime = avio_rl64(s->pb);
1434  pct = avio_rl32(s->pb);
1435  ict = avio_rl32(s->pb);
1436  av_log(s, AV_LOG_DEBUG,
1437  "itime:0x%"PRIx64", pct:%d, ict:%d\n", itime, pct, ict);
1438 
1439  for (i = 0; i < ict; i++) {
1440  int pktnum = avio_rl32(s->pb);
1441  int pktct = avio_rl16(s->pb);
1442  int64_t pos = s->data_offset + s->packet_size * (int64_t)pktnum;
1443  int64_t index_pts = FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);
1444 
1445  if (avio_feof(s->pb)) {
1446  ret = AVERROR_INVALIDDATA;
1447  goto end;
1448  }
1449 
1450  if (pos != last_pos) {
1451  av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d pts: %"PRId64"\n",
1452  pktnum, pktct, index_pts);
1453  av_add_index_entry(s->streams[stream_index], pos, index_pts,
1454  s->packet_size, 0, AVINDEX_KEYFRAME);
1455  last_pos = pos;
1456  }
1457  }
1458  asf->index_read = ict > 0;
1459  }
1460 end:
1461  if (s->pb->eof_reached)
1462  ret = 0;
1463  avio_seek(s->pb, current_pos, SEEK_SET);
1464  return ret;
1465 }
1466 
1467 static int asf_read_seek(AVFormatContext *s, int stream_index,
1468  int64_t pts, int flags)
1469 {
1470  ASFContext *asf = s->priv_data;
1471  AVStream *st = s->streams[stream_index];
1472  int64_t pos;
1473  int index, ret = 0;
1474 
1475  if (s->packet_size <= 0)
1476  return -1;
1477 
1478  /* Try using the protocol's read_seek if available */
1479  if (s->pb) {
1480  int ret = avio_seek_time(s->pb, stream_index, pts, flags);
1481  if (ret >= 0)
1482  asf_reset_header(s);
1483  if (ret != AVERROR(ENOSYS))
1484  return ret;
1485  }
1486 
1487  /* explicitly handle the case of seeking to 0 */
1488  if (!pts) {
1489  asf_reset_header(s);
1490  avio_seek(s->pb, s->data_offset, SEEK_SET);
1491  return 0;
1492  }
1493 
1494  if (!asf->index_read)
1495  ret = asf_build_simple_index(s, stream_index);
1496 
1497  if (!ret && asf->index_read && st->index_entries) {
1498  index = av_index_search_timestamp(st, pts, flags);
1499  if (index >= 0) {
1500  /* find the position */
1501  pos = st->index_entries[index].pos;
1502 
1503  /* do the seek */
1504  av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos);
1505  avio_seek(s->pb, pos, SEEK_SET);
1506  asf_reset_header(s);
1507  return 0;
1508  }
1509  }
1510  /* no index or seeking by index failed */
1511  if (ff_seek_frame_binary(s, stream_index, pts, flags) < 0)
1512  return -1;
1513  asf_reset_header(s);
1514  return 0;
1515 }
1516 
1518  .name = "asf",
1519  .long_name = NULL_IF_CONFIG_SMALL("ASF (Advanced / Active Streaming Format)"),
1520  .priv_data_size = sizeof(ASFContext),
1521  .read_probe = asf_probe,
1526  .read_timestamp = asf_read_pts,
1528  .priv_class = &asf_class,
1529 };
#define FRAME_HEADER_SIZE
Definition: asfdec.c:101
#define AVPALETTE_SIZE
Definition: avcodec.h:3051
codec_id is not known (like AV_CODEC_ID_NONE) but lavf should attempt to identify it ...
Definition: avcodec.h:464
const ff_asf_guid ff_asf_header
Definition: asf.c:23
unsigned int packet_size
Definition: avformat.h:1026
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
discard all frames except keyframes
Definition: avcodec.h:567
#define AVFMT_NOBINSEARCH
Format does not allow to fall back on binary search via read_timestamp.
Definition: avformat.h:422
Bytestream IO Context.
Definition: avio.h:68
static int asf_read_marker(AVFormatContext *s, int64_t size)
Definition: asfdec.c:674
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
int packet_timestamp
Definition: asfdec.c:62
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
Definition: buffer.c:106
int size
void av_free_packet(AVPacket *pkt)
Free a packet.
Definition: avpacket.c:243
const ff_asf_guid ff_asf_ext_stream_audio_stream
Definition: asf.c:104
const ff_asf_guid ff_asf_ext_content_encryption
Definition: asf.c:138
int packet_segments
Definition: asfdec.c:64
AVOption.
Definition: opt.h:234
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
Definition: utils.c:1181
const ff_asf_guid ff_asf_codec_comment_header
Definition: asf.c:73
enum AVCodecID id
Definition: mxfenc.c:84
const ff_asf_guid ff_asf_metadata_header
Definition: asf.c:108
static void get_id3_tag(AVFormatContext *s, int len)
Definition: asfdec.c:272
int packet_key_frame
Definition: asfdec.c:67
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:1943
static av_always_inline int ff_get_guid(AVIOContext *s, ff_asf_guid *g)
Definition: riff.h:94
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:129
AVInputFormat ff_asf_demuxer
Definition: asfdec.c:1517
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:998
static int asf_read_ext_stream_properties(AVFormatContext *s, int64_t size)
Definition: asfdec.c:514
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition: avpacket.c:101
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:2829
static const AVClass asf_class
Definition: asfdec.c:90
int64_t pos
Definition: avformat.h:660
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
uint64_t data_offset
beginning of the first data packet
Definition: asfdec.c:53
ASFMainHeader hdr
Definition: asfdec.c:58
Definition: vf_drawbox.c:37
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:769
static const AVOption options[]
Definition: asfdec.c:85
static int asf_read_metadata(AVFormatContext *s, int64_t size)
Definition: asfdec.c:635
int num
numerator
Definition: rational.h:44
int index
stream index in AVFormatContext
Definition: avformat.h:700
int size
Definition: avcodec.h:974
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
Definition: id3v2.h:35
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:186
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: avformat.h:878
int64_t packet_frag_timestamp
Definition: asfdec.c:71
int palette_changed
Definition: asf.h:48
const ff_asf_guid ff_asf_command_stream
Definition: asf.c:65
void * priv_data
Definition: avformat.h:719
#define FF_ARRAY_ELEMS(a)
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
const ff_asf_guid ff_asf_ext_stream_header
Definition: asf.c:35
int64_t data_offset
offset of the first packet
Definition: avformat.h:1220
discard all
Definition: avcodec.h:568
uint32_t min_pktsize
size of a data packet invalid if broadcasting
Definition: asf.h:68
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:738
int packet_time_start
Definition: asfdec.c:75
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.
#define print_guid(g)
Definition: asfdec.c:153
static int asf_read_file_properties(AVFormatContext *s, int64_t size)
Definition: asfdec.c:324
Macro definitions for various function/variable attributes.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
AVChapter * avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title)
Add a new chapter.
Definition: utils.c:2601
Format I/O context.
Definition: avformat.h:922
char str[32]
Definition: internal.h:41
const ff_asf_guid ff_asf_data_header
Definition: asf.c:80
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:38
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
Public dictionary API.
uint8_t
uint32_t flags
0x01 - broadcast 0x02 - seekable rest is reserved should be 0
Definition: asf.h:65
Opaque data information usually continuous.
Definition: avutil.h:189
const ff_asf_guid ff_asf_audio_stream
Definition: asf.c:39
AVOptions.
attribute_deprecated void(* destruct)(struct AVPacket *)
Definition: avcodec.h:994
int packet_time_delta
Definition: asfdec.c:74
enum AVStreamParseType need_parsing
Definition: avformat.h:867
int id
Format-specific stream ID.
Definition: avformat.h:706
ASFStream streams[128]
it's max number and it's not that big
Definition: asfdec.c:45
int packet_padsize
Definition: asfdec.c:68
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1164
const char * name
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:2521
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:990
int packet_size_left
Definition: asfdec.c:51
#define DO_2BITS(bits, var, defval)
Definition: asfdec.c:846
uint8_t * data
Definition: avcodec.h:973
ASFStream * asf_st
currently decoded stream
Definition: asfdec.c:80
static int flags
Definition: log.c:44
uint64_t send_time
time to send file, in 100-nanosecond units invalid if broadcasting (could be ignored) ...
Definition: asf.h:60
#define AVERROR_EOF
End of file.
Definition: error.h:51
enum AVCodecID id
Definition: internal.h:42
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:139
AVPacket pkt
Definition: asf.h:35
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:117
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:219
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2523
int asfid2avid[128]
conversion table from asf ID 2 AVStream ID
Definition: asfdec.c:44
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:463
uint64_t file_size
in bytes invalid if broadcasting
Definition: asf.h:54
ff_asf_guid guid
generated by client computer
Definition: asf.h:53
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1019
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:81
#define AVINDEX_KEYFRAME
Definition: avformat.h:662
const ff_asf_guid ff_asf_audio_conceal_none
Definition: asf.c:43
int packet_replic_size
Definition: asfdec.c:66
static int asf_read_picture(AVFormatContext *s, int len)
Definition: asfdec.c:185
static int64_t start_time
Definition: avplay.c:245
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:105
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1130
const ff_asf_guid ff_asf_head1_guid
Definition: asf.c:84
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
Definition: utils.c:1222
#define ASF_MAX_STREAMS
Definition: asfdec.c:100
const ff_asf_guid ff_asf_head2_guid
Definition: asf.c:88
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:575
#define AVERROR(e)
Definition: error.h:43
int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
Definition: riffdec.c:82
const char * av_convert_lang_to(const char *lang, enum AVLangCodespace target_codespace)
Convert a language code to a target codespace.
Definition: avlanguage.c:736
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:145
g
Definition: yuv2rgb.c:535
void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len)
Definition: asfcrypt.c:147
int packet_seq
Definition: asfdec.c:65
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: avcodec.h:956
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
Free memory allocated parsing special (non-text) metadata.
Definition: id3v2.c:724
const ff_asf_guid ff_asf_video_conceal_none
Definition: asf.c:61
int ds_chunk_size
Definition: asf.h:42
simple assert() macros that are a bit more flexible than ISO C assert().
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
int side_data_elems
Definition: avcodec.h:985
int frag_offset
Definition: asf.h:36
#define FFMAX(a, b)
Definition: common.h:55
uint64_t data_object_size
size of the data object
Definition: asfdec.c:55
static int asf_build_simple_index(AVFormatContext *s, int stream_index)
Definition: asfdec.c:1404
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:81
const char * ff_id3v2_picture_types[21]
Definition: id3v2.c:89
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:979
static int asf_get_packet(AVFormatContext *s, AVIOContext *pb)
Load a single ASF packet into the demuxer.
Definition: asfdec.c:871
static int asf_read_header(AVFormatContext *s)
Definition: asfdec.c:712
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:454
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:718
uint32_t max_pktsize
shall be the same as for min_pktsize invalid if broadcasting
Definition: asf.h:70
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:397
const CodecMime ff_id3v2_mime_tags[]
Definition: id3v2.c:113
common internal API header
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:531
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:978
uint32_t palette[256]
Definition: asf.h:49
int bit_rate
the average bitrate
Definition: avcodec.h:1114
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:116
#define FFMIN(a, b)
Definition: common.h:57
const ff_asf_guid ff_asf_digital_signature
Definition: asf.c:142
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:29
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() and chilren.
Definition: dict.h:66
static int read_probe(AVProbeData *pd)
Definition: jvdec.c:55
char stream_languages[128][6]
max number of streams, language for each (RFC1766, e.g. en-US)
Definition: asfdec.c:48
int width
picture width / height.
Definition: avcodec.h:1229
const ff_asf_guid ff_asf_extended_content_header
Definition: asf.c:92
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: avio.h:210
unsigned int packet_frag_size
Definition: asfdec.c:70
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
const ff_asf_guid ff_asf_ext_stream_embed_stream_header
Definition: asf.c:100
int packet_multi_size
Definition: asfdec.c:72
AVDictionary * metadata
Definition: avformat.h:771
const ff_asf_guid ff_asf_my_guid
Definition: asf.c:126
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:186
static int asf_probe(AVProbeData *pd)
Definition: asfdec.c:156
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:110
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
#define AV_DISPOSITION_ATTACHED_PIC
The stream is stored in the file as an attached picture/"cover art" (e.g.
Definition: avformat.h:690
void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta)
Read an ID3v2 tag, including supported extra metadata.
Definition: id3v2.c:692
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:544
static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
Definition: asfdec.c:348
uint8_t ff_asf_guid[16]
Definition: riff.h:70
Stream structure.
Definition: avformat.h:699
NULL
Definition: eval.c:55
uint32_t ignore
preroll is 64bit - but let's just ignore it
Definition: asf.h:64
#define AV_LOG_INFO
Standard information.
Definition: log.h:134
uint32_t stream_bitrates[128]
max number of streams, bitrate for each (for streaming)
Definition: asfdec.c:46
#define av_bswap32
Definition: bswap.h:33
int ds_span
Definition: asf.h:40
uint64_t create_time
time of creation, in 100-nanosecond units since 1.1.1601 invalid if broadcasting
Definition: asf.h:56
enum AVMediaType codec_type
Definition: avcodec.h:1058
const ff_asf_guid ff_asf_file_header
Definition: asf.c:27
uint64_t play_time
play time, in 100-nanosecond units invalid if broadcasting
Definition: asf.h:58
enum AVCodecID codec_id
Definition: avcodec.h:1067
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:66
AVIOContext * pb
I/O context.
Definition: avformat.h:964
static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
Definition: asfdec.c:1352
av_default_item_name
Definition: dnxhdenc.c:52
const ff_asf_guid ff_asf_video_stream
Definition: asf.c:53
Definition: asf.h:31
uint8_t * data
The data buffer.
Definition: buffer.h:89
static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
Definition: asfdec.c:1467
uint16_t stream_language_index
Definition: asf.h:46
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1082
#define AVFMT_NOGENSEARCH
Format does not allow to fall back on generic search.
Definition: avformat.h:423
int extradata_size
Definition: avcodec.h:1165
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:114
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:68
int index_read
Definition: asfdec.c:56
Describe the class of an AVClass context structure.
Definition: log.h:33
int index
Definition: gxfenc.c:72
rational number numerator/denominator
Definition: rational.h:43
int ds_packet_size
Definition: asf.h:41
const ff_asf_guid ff_asf_stream_header
Definition: asf.c:31
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:265
unsigned int packet_frag_offset
Definition: asfdec.c:69
byte swapping routines
static int asf_read_close(AVFormatContext *s)
Definition: asfdec.c:1345
AVMediaType
Definition: avutil.h:185
const AVMetadataConv ff_asf_metadata_conv[]
Definition: asf.c:147
uint64_t data_object_offset
data object offset (excl. GUID & size)
Definition: asfdec.c:54
int error
contains the error code or 0 if no error happened
Definition: avio.h:102
This structure contains the data a format has to probe a file.
Definition: avformat.h:395
static int asf_read_ext_content_desc(AVFormatContext *s, int64_t size)
Definition: asfdec.c:581
static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb)
Definition: asfdec.c:970
full parsing and repack of the first frame only, only implemented for H.264 currently ...
Definition: avformat.h:656
static int asf_read_content_desc(AVFormatContext *s, int64_t size)
Definition: asfdec.c:562
int packet_property
Definition: asfdec.c:61
const ff_asf_guid ff_asf_comment_header
Definition: asf.c:69
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:756
uint32_t preroll
timestamp of the first packet, in milliseconds if nonzero - subtract from time
Definition: asf.h:62
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:404
const uint8_t * key
Definition: avformat.h:1066
int64_t packet_pos
Definition: asf.h:44
A reference to a data buffer.
Definition: buffer.h:81
const ff_asf_guid ff_asf_language_guid
Definition: asf.c:130
full parsing and repack
Definition: avformat.h:653
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:559
Main libavformat public API header.
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
Definition: avcodec.h:984
const ff_asf_guid ff_asf_jfif_media
Definition: asf.c:57
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:76
common internal and external API header
int packet_obj_size
Definition: asfdec.c:73
static const ff_asf_guid index_guid
Definition: asfdec.c:104
int64_t start_time
Decoding: pts of the first frame of the stream, in stream time base.
Definition: avformat.h:749
int no_resync_search
Definition: asfdec.c:82
unsigned char seq
Definition: asf.h:33
int disposition
AV_DISPOSITION_* bit field.
Definition: avformat.h:760
const ff_asf_guid ff_asf_codec_comment1_header
Definition: asf.c:76
int den
denominator
Definition: rational.h:45
void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition: metadata.c:26
int64_t packet_pos
Definition: asfdec.c:76
int64_t avio_seek_time(AVIOContext *h, int stream_index, int64_t timestamp, int flags)
Seek to a given timestamp relative to some component stream.
Definition: aviobuf.c:852
const ff_asf_guid ff_asf_content_encryption
Definition: asf.c:134
int eof_reached
true if eof reached
Definition: avio.h:96
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:77
int len
AVRational dar[128]
Definition: asfdec.c:47
void * priv_data
Format private data.
Definition: avformat.h:950
static int asf_read_language_list(AVFormatContext *s, int64_t size)
Definition: asfdec.c:615
int packet_flags
Definition: asfdec.c:60
static int get_value(AVIOContext *pb, int type, int type2_size)
Definition: asfdec.c:167
int packet_segsizetype
Definition: asfdec.c:63
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:972
int stream_index
Definition: asfdec.c:78
static int asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt)
Parse data from individual ASF packets (which were previously loaded with asf_get_packet()).
Definition: asfdec.c:1063
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:525
int avio_feof(AVIOContext *s)
Definition: aviobuf.c:260
const ff_asf_guid ff_asf_marker_header
Definition: asf.c:116
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
Definition: avpacket.c:262
int stream_index
Definition: avcodec.h:975
static void get_tag(AVFormatContext *s, const char *key, int type, int len, int type2_size)
Definition: asfdec.c:282
#define MKTAG(a, b, c, d)
Definition: common.h:238
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:762
static av_always_inline int ff_guidcmp(const void *g1, const void *g2)
Definition: riff.h:89
static void asf_reset_header(AVFormatContext *s)
Definition: asfdec.c:1309
This structure stores compressed data.
Definition: avcodec.h:950
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:583
uint32_t max_bitrate
bandwidth of stream in bps should be the sum of bitrates of the individual media streams ...
Definition: asf.h:72
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
const ff_asf_guid ff_asf_metadata_library_header
Definition: asf.c:112
AVPacket attached_pic
For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet will contain the attached pictu...
Definition: avformat.h:789
static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: asfdec.c:1289
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:228
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:1228
#define av_unused
Definition: attributes.h:86