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