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 FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 //#define DEBUG
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/mathematics.h"
31 #include "libavutil/opt.h"
32 #include "avformat.h"
33 #include "avio_internal.h"
34 #include "avlanguage.h"
35 #include "id3v2.h"
36 #include "internal.h"
37 #include "riff.h"
38 #include "asf.h"
39 #include "asfcrypt.h"
40 
41 typedef struct {
42  const AVClass *class;
43  int asfid2avid[128]; ///< conversion table from asf ID 2 AVStream ID
44  ASFStream streams[128]; ///< it's max number and it's not that big
45  uint32_t stream_bitrates[128]; ///< max number of streams, bitrate for each (for streaming)
46  AVRational dar[128];
47  char stream_languages[128][6]; ///< max number of streams, language for each (RFC1766, e.g. en-US)
48  /* non streamed additonnal info */
49  /* packet filling */
51  /* only for reading */
52  uint64_t data_offset; ///< beginning of the first data packet
53  uint64_t data_object_offset; ///< data object offset (excl. GUID & size)
54  uint64_t data_object_size; ///< size of the data object
56 
58 
68  unsigned int packet_frag_offset;
69  unsigned int packet_frag_size;
75  int64_t packet_pos;
76 
78 
79  ASFStream *asf_st; ///< currently decoded stream
80 
82 } ASFContext;
83 
84 static const AVOption options[] = {
85  { "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 },
86  { NULL },
87 };
88 
89 static const AVClass asf_class = {
90  .class_name = "asf demuxer",
91  .item_name = av_default_item_name,
92  .option = options,
93  .version = LIBAVUTIL_VERSION_INT,
94 };
95 
96 #undef NDEBUG
97 #include <assert.h>
98 
99 #define ASF_MAX_STREAMS 127
100 #define FRAME_HEADER_SIZE 16
101 // Fix Me! FRAME_HEADER_SIZE may be different. (17 is known to be too large)
102 
103 #ifdef DEBUG
104 static const ff_asf_guid stream_bitrate_guid = { /* (http://get.to/sdp) */
105  0xce, 0x75, 0xf8, 0x7b, 0x8d, 0x46, 0xd1, 0x11, 0x8d, 0x82, 0x00, 0x60, 0x97, 0xc9, 0xa2, 0xb2
106 };
107 
108 #define PRINT_IF_GUID(g, cmp) \
109  if (!ff_guidcmp(g, &cmp)) \
110  av_dlog(NULL, "(GUID: %s) ", # cmp)
111 
112 static void print_guid(ff_asf_guid *g)
113 {
114  int i;
115  PRINT_IF_GUID(g, ff_asf_header);
116  else PRINT_IF_GUID(g, ff_asf_file_header);
117  else PRINT_IF_GUID(g, ff_asf_stream_header);
118  else PRINT_IF_GUID(g, ff_asf_audio_stream);
119  else PRINT_IF_GUID(g, ff_asf_audio_conceal_none);
120  else PRINT_IF_GUID(g, ff_asf_video_stream);
121  else PRINT_IF_GUID(g, ff_asf_video_conceal_none);
122  else PRINT_IF_GUID(g, ff_asf_command_stream);
123  else PRINT_IF_GUID(g, ff_asf_comment_header);
124  else PRINT_IF_GUID(g, ff_asf_codec_comment_header);
125  else PRINT_IF_GUID(g, ff_asf_codec_comment1_header);
126  else PRINT_IF_GUID(g, ff_asf_data_header);
127  else PRINT_IF_GUID(g, ff_asf_simple_index_header);
128  else PRINT_IF_GUID(g, ff_asf_head1_guid);
129  else PRINT_IF_GUID(g, ff_asf_head2_guid);
130  else PRINT_IF_GUID(g, ff_asf_my_guid);
131  else PRINT_IF_GUID(g, ff_asf_ext_stream_header);
132  else PRINT_IF_GUID(g, ff_asf_extended_content_header);
133  else PRINT_IF_GUID(g, ff_asf_ext_stream_embed_stream_header);
134  else PRINT_IF_GUID(g, ff_asf_ext_stream_audio_stream);
135  else PRINT_IF_GUID(g, ff_asf_metadata_header);
136  else PRINT_IF_GUID(g, ff_asf_metadata_library_header);
137  else PRINT_IF_GUID(g, ff_asf_marker_header);
138  else PRINT_IF_GUID(g, stream_bitrate_guid);
139  else PRINT_IF_GUID(g, ff_asf_language_guid);
140  else
141  av_dlog(NULL, "(GUID: unknown) ");
142  for (i = 0; i < 16; i++)
143  av_dlog(NULL, " 0x%02x,", (*g)[i]);
144  av_dlog(NULL, "}\n");
145 }
146 #undef PRINT_IF_GUID
147 #else
148 #define print_guid(g)
149 #endif
150 
151 static int asf_probe(AVProbeData *pd)
152 {
153  /* check file header */
154  if (!ff_guidcmp(pd->buf, &ff_asf_header))
155  return AVPROBE_SCORE_MAX;
156  else
157  return 0;
158 }
159 
160 /* size of type 2 (BOOL) is 32bit for "Extended Content Description Object"
161  * but 16 bit for "Metadata Object" and "Metadata Library Object" */
162 static int get_value(AVIOContext *pb, int type, int type2_size)
163 {
164  switch (type) {
165  case 2:
166  return (type2_size == 32) ? avio_rl32(pb) : avio_rl16(pb);
167  case 3:
168  return avio_rl32(pb);
169  case 4:
170  return avio_rl64(pb);
171  case 5:
172  return avio_rl16(pb);
173  default:
174  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  AVStream *st = NULL;
188  int ret, type, picsize, desc_len;
189 
190  /* type + picsize + mime + desc */
191  if (len < 1 + 4 + 2 + 2) {
192  av_log(s, AV_LOG_ERROR, "Invalid attached picture size: %d.\n", len);
193  return AVERROR_INVALIDDATA;
194  }
195 
196  /* picture type */
197  type = avio_r8(s->pb);
198  len--;
199  if (type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types) || type < 0) {
200  av_log(s, AV_LOG_WARNING, "Unknown attached picture type: %d.\n", type);
201  type = 0;
202  }
203 
204  /* picture data size */
205  picsize = avio_rl32(s->pb);
206  len -= 4;
207 
208  /* picture MIME type */
209  len -= avio_get_str16le(s->pb, len, mimetype, sizeof(mimetype));
210  while (mime->id != AV_CODEC_ID_NONE) {
211  if (!strncmp(mime->str, mimetype, sizeof(mimetype))) {
212  id = mime->id;
213  break;
214  }
215  mime++;
216  }
217  if (id == AV_CODEC_ID_NONE) {
218  av_log(s, AV_LOG_ERROR, "Unknown attached picture mimetype: %s.\n",
219  mimetype);
220  return 0;
221  }
222 
223  if (picsize >= len) {
224  av_log(s, AV_LOG_ERROR, "Invalid attached picture data size: %d >= %d.\n",
225  picsize, len);
226  return AVERROR_INVALIDDATA;
227  }
228 
229  /* picture description */
230  desc_len = (len - picsize) * 2 + 1;
231  desc = av_malloc(desc_len);
232  if (!desc)
233  return AVERROR(ENOMEM);
234  len -= avio_get_str16le(s->pb, len - picsize, desc, desc_len);
235 
236  ret = av_get_packet(s->pb, &pkt, picsize);
237  if (ret < 0)
238  goto fail;
239 
240  st = avformat_new_stream(s, NULL);
241  if (!st) {
242  ret = AVERROR(ENOMEM);
243  goto fail;
244  }
247  st->codec->codec_id = id;
248  st->attached_pic = pkt;
249  st->attached_pic.stream_index = st->index;
251 
252  if (*desc)
253  av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL);
254  else
255  av_freep(&desc);
256 
257  av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[type], 0);
258 
259  return 0;
260 
261 fail:
262  av_freep(&desc);
263  av_free_packet(&pkt);
264  return ret;
265 }
266 
267 static void get_id3_tag(AVFormatContext *s, int len)
268 {
269  ID3v2ExtraMeta *id3v2_extra_meta = NULL;
270 
271  ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta);
272  if (id3v2_extra_meta)
273  ff_id3v2_parse_apic(s, &id3v2_extra_meta);
274  ff_id3v2_free_extra_meta(&id3v2_extra_meta);
275 }
276 
277 static void get_tag(AVFormatContext *s, const char *key, int type, int len, int type2_size)
278 {
279  char *value;
280  int64_t off = avio_tell(s->pb);
281 #define LEN 22
282 
283  if ((unsigned)len >= (UINT_MAX - LEN) / 2)
284  return;
285 
286  value = av_malloc(2 * len + LEN);
287  if (!value)
288  goto finish;
289 
290  if (type == 0) { // UTF16-LE
291  avio_get_str16le(s->pb, len, value, 2 * len + 1);
292  } else if (type == -1) { // ASCII
293  avio_read(s->pb, value, len);
294  value[len]=0;
295  } else if (type == 1) { // byte array
296  if (!strcmp(key, "WM/Picture")) { // handle cover art
297  asf_read_picture(s, len);
298  } else if (!strcmp(key, "ID3")) { // handle ID3 tag
299  get_id3_tag(s, len);
300  } else {
301  av_log(s, AV_LOG_VERBOSE, "Unsupported byte array in tag %s.\n", key);
302  }
303  goto finish;
304  } else if (type > 1 && type <= 5) { // boolean or DWORD or QWORD or WORD
305  uint64_t num = get_value(s->pb, type, type2_size);
306  snprintf(value, LEN, "%"PRIu64, num);
307  } else if (type == 6) { // (don't) handle GUID
308  av_log(s, AV_LOG_DEBUG, "Unsupported GUID value in tag %s.\n", key);
309  goto finish;
310  } else {
311  av_log(s, AV_LOG_DEBUG,
312  "Unsupported value type %d in tag %s.\n", type, key);
313  goto finish;
314  }
315  if (*value)
316  av_dict_set(&s->metadata, key, value, 0);
317 
318 finish:
319  av_freep(&value);
320  avio_seek(s->pb, off + len, SEEK_SET);
321 }
322 
324 {
325  ASFContext *asf = s->priv_data;
326  AVIOContext *pb = s->pb;
327 
328  ff_get_guid(pb, &asf->hdr.guid);
329  asf->hdr.file_size = avio_rl64(pb);
330  asf->hdr.create_time = avio_rl64(pb);
331  avio_rl64(pb); /* number of packets */
332  asf->hdr.play_time = avio_rl64(pb);
333  asf->hdr.send_time = avio_rl64(pb);
334  asf->hdr.preroll = avio_rl32(pb);
335  asf->hdr.ignore = avio_rl32(pb);
336  asf->hdr.flags = avio_rl32(pb);
337  asf->hdr.min_pktsize = avio_rl32(pb);
338  asf->hdr.max_pktsize = avio_rl32(pb);
339  if (asf->hdr.min_pktsize >= (1U << 29))
340  return AVERROR_INVALIDDATA;
341  asf->hdr.max_bitrate = avio_rl32(pb);
342  s->packet_size = asf->hdr.max_pktsize;
343 
344  return 0;
345 }
346 
348 {
349  ASFContext *asf = s->priv_data;
350  AVIOContext *pb = s->pb;
351  AVStream *st;
352  ASFStream *asf_st;
353  ff_asf_guid g;
354  enum AVMediaType type;
355  int type_specific_size, sizeX;
356  unsigned int tag1;
357  int64_t pos1, pos2, start_time;
358  int test_for_ext_stream_audio, is_dvr_ms_audio = 0;
359 
360  if (s->nb_streams == ASF_MAX_STREAMS) {
361  av_log(s, AV_LOG_ERROR, "too many streams\n");
362  return AVERROR(EINVAL);
363  }
364 
365  pos1 = avio_tell(pb);
366 
367  st = avformat_new_stream(s, NULL);
368  if (!st)
369  return AVERROR(ENOMEM);
370  avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
371  asf_st = av_mallocz(sizeof(ASFStream));
372  if (!asf_st)
373  return AVERROR(ENOMEM);
374  st->priv_data = asf_st;
375  start_time = asf->hdr.preroll;
376 
377  asf_st->stream_language_index = 128; // invalid stream index means no language info
378 
379  if (!(asf->hdr.flags & 0x01)) { // if we aren't streaming...
380  int64_t fsize = avio_size(pb);
381  if (fsize <= 0 || (int64_t)asf->hdr.file_size <= 0 || FFABS(fsize - (int64_t)asf->hdr.file_size) < 10000)
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.
435  st->request_probe = 1;
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 = ffio_limit(pb, 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  asf->streams[stream_num].payload_ext_ct = 0;
546  }
547 
548  for (i = 0; i < stream_ct; i++) {
549  avio_rl16(pb);
550  ext_len = avio_rl16(pb);
551  avio_skip(pb, ext_len);
552  }
553 
554  for (i = 0; i < payload_ext_ct; i++) {
555  int size;
556  ff_get_guid(pb, &g);
557  size = avio_rl16(pb);
558  ext_len = avio_rl32(pb);
559  avio_skip(pb, ext_len);
560  if (stream_num < 128 && i < FF_ARRAY_ELEMS(asf->streams[stream_num].payload)) {
561  ASFPayload *p = &asf->streams[stream_num].payload[i];
562  p->type = g[0];
563  p->size = size;
564  av_log(s, AV_LOG_DEBUG, "Payload extension %x %d\n", g[0], p->size );
565  asf->streams[stream_num].payload_ext_ct ++;
566  }
567  }
568 
569  return 0;
570 }
571 
573 {
574  AVIOContext *pb = s->pb;
575  int len1, len2, len3, len4, len5;
576 
577  len1 = avio_rl16(pb);
578  len2 = avio_rl16(pb);
579  len3 = avio_rl16(pb);
580  len4 = avio_rl16(pb);
581  len5 = avio_rl16(pb);
582  get_tag(s, "title", 0, len1, 32);
583  get_tag(s, "author", 0, len2, 32);
584  get_tag(s, "copyright", 0, len3, 32);
585  get_tag(s, "comment", 0, len4, 32);
586  avio_skip(pb, len5);
587 
588  return 0;
589 }
590 
592 {
593  AVIOContext *pb = s->pb;
594  ASFContext *asf = s->priv_data;
595  int desc_count, i, ret;
596 
597  desc_count = avio_rl16(pb);
598  for (i = 0; i < desc_count; i++) {
599  int name_len, value_type, value_len;
600  char name[1024];
601 
602  name_len = avio_rl16(pb);
603  if (name_len % 2) // must be even, broken lavf versions wrote len-1
604  name_len += 1;
605  if ((ret = avio_get_str16le(pb, name_len, name, sizeof(name))) < name_len)
606  avio_skip(pb, name_len - ret);
607  value_type = avio_rl16(pb);
608  value_len = avio_rl16(pb);
609  if (!value_type && value_len % 2)
610  value_len += 1;
611  /* My sample has that stream set to 0 maybe that mean the container.
612  * ASF stream count starts at 1. I am using 0 to the container value
613  * since it's unused. */
614  if (!strcmp(name, "AspectRatioX"))
615  asf->dar[0].num = get_value(s->pb, value_type, 32);
616  else if (!strcmp(name, "AspectRatioY"))
617  asf->dar[0].den = get_value(s->pb, value_type, 32);
618  else
619  get_tag(s, name, value_type, value_len, 32);
620  }
621 
622  return 0;
623 }
624 
626 {
627  AVIOContext *pb = s->pb;
628  ASFContext *asf = s->priv_data;
629  int j, ret;
630  int stream_count = avio_rl16(pb);
631  for (j = 0; j < stream_count; j++) {
632  char lang[6];
633  unsigned int lang_len = avio_r8(pb);
634  if ((ret = avio_get_str16le(pb, lang_len, lang,
635  sizeof(lang))) < lang_len)
636  avio_skip(pb, lang_len - ret);
637  if (j < 128)
638  av_strlcpy(asf->stream_languages[j], lang,
639  sizeof(*asf->stream_languages));
640  }
641 
642  return 0;
643 }
644 
646 {
647  AVIOContext *pb = s->pb;
648  ASFContext *asf = s->priv_data;
649  int n, stream_num, name_len, value_len;
650  int ret, i;
651  n = avio_rl16(pb);
652 
653  for (i = 0; i < n; i++) {
654  char name[1024];
655  int value_type;
656 
657  avio_rl16(pb); // lang_list_index
658  stream_num = avio_rl16(pb);
659  name_len = avio_rl16(pb);
660  value_type = avio_rl16(pb); /* value_type */
661  value_len = avio_rl32(pb);
662 
663  if ((ret = avio_get_str16le(pb, name_len, name, sizeof(name))) < name_len)
664  avio_skip(pb, name_len - ret);
665  av_dlog(s, "%d stream %d name_len %2d type %d len %4d <%s>\n",
666  i, stream_num, name_len, value_type, value_len, name);
667 
668  if (!strcmp(name, "AspectRatioX")){
669  int aspect_x = get_value(s->pb, value_type, 16);
670  if(stream_num < 128)
671  asf->dar[stream_num].num = aspect_x;
672  } else if(!strcmp(name, "AspectRatioY")){
673  int aspect_y = get_value(s->pb, value_type, 16);
674  if(stream_num < 128)
675  asf->dar[stream_num].den = aspect_y;
676  } else {
677  get_tag(s, name, value_type, value_len, 16);
678  }
679  }
680 
681  return 0;
682 }
683 
684 static int asf_read_marker(AVFormatContext *s, int64_t size)
685 {
686  AVIOContext *pb = s->pb;
687  int i, count, name_len, ret;
688  char name[1024];
689 
690  avio_rl64(pb); // reserved 16 bytes
691  avio_rl64(pb); // ...
692  count = avio_rl32(pb); // markers count
693  avio_rl16(pb); // reserved 2 bytes
694  name_len = avio_rl16(pb); // name length
695  for (i = 0; i < name_len; i++)
696  avio_r8(pb); // skip the name
697 
698  for (i = 0; i < count; i++) {
699  int64_t pres_time;
700  int name_len;
701 
702  avio_rl64(pb); // offset, 8 bytes
703  pres_time = avio_rl64(pb); // presentation time
704  avio_rl16(pb); // entry length
705  avio_rl32(pb); // send time
706  avio_rl32(pb); // flags
707  name_len = avio_rl32(pb); // name length
708  if ((ret = avio_get_str16le(pb, name_len * 2, name,
709  sizeof(name))) < name_len)
710  avio_skip(pb, name_len - ret);
711  avpriv_new_chapter(s, i, (AVRational) { 1, 10000000 }, pres_time,
713  }
714 
715  return 0;
716 }
717 
719 {
720  ASFContext *asf = s->priv_data;
721  ff_asf_guid g;
722  AVIOContext *pb = s->pb;
723  int i;
724  int64_t gsize;
725 
726  ff_get_guid(pb, &g);
727  if (ff_guidcmp(&g, &ff_asf_header))
728  return AVERROR_INVALIDDATA;
729  avio_rl64(pb);
730  avio_rl32(pb);
731  avio_r8(pb);
732  avio_r8(pb);
733  memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid));
734  for (;;) {
735  uint64_t gpos = avio_tell(pb);
736  ff_get_guid(pb, &g);
737  gsize = avio_rl64(pb);
738  print_guid(&g);
739  if (!ff_guidcmp(&g, &ff_asf_data_header)) {
740  asf->data_object_offset = avio_tell(pb);
741  /* If not streaming, gsize is not unlimited (how?),
742  * and there is enough space in the file.. */
743  if (!(asf->hdr.flags & 0x01) && gsize >= 100)
744  asf->data_object_size = gsize - 24;
745  else
746  asf->data_object_size = (uint64_t)-1;
747  break;
748  }
749  if (gsize < 24)
750  return AVERROR_INVALIDDATA;
751  if (!ff_guidcmp(&g, &ff_asf_file_header)) {
752  int ret = asf_read_file_properties(s, gsize);
753  if (ret < 0)
754  return ret;
755  } else if (!ff_guidcmp(&g, &ff_asf_stream_header)) {
756  asf_read_stream_properties(s, gsize);
757  } else if (!ff_guidcmp(&g, &ff_asf_comment_header)) {
758  asf_read_content_desc(s, gsize);
759  } else if (!ff_guidcmp(&g, &ff_asf_language_guid)) {
760  asf_read_language_list(s, gsize);
761  } else if (!ff_guidcmp(&g, &ff_asf_extended_content_header)) {
762  asf_read_ext_content_desc(s, gsize);
763  } else if (!ff_guidcmp(&g, &ff_asf_metadata_header)) {
764  asf_read_metadata(s, gsize);
765  } else if (!ff_guidcmp(&g, &ff_asf_metadata_library_header)) {
766  asf_read_metadata(s, gsize);
767  } else if (!ff_guidcmp(&g, &ff_asf_ext_stream_header)) {
769 
770  // there could be a optional stream properties object to follow
771  // if so the next iteration will pick it up
772  continue;
773  } else if (!ff_guidcmp(&g, &ff_asf_head1_guid)) {
774  ff_get_guid(pb, &g);
775  avio_skip(pb, 6);
776  continue;
777  } else if (!ff_guidcmp(&g, &ff_asf_marker_header)) {
778  asf_read_marker(s, gsize);
779  } else if (url_feof(pb)) {
780  return AVERROR_EOF;
781  } else {
782  if (!s->keylen) {
784  unsigned int len;
785  AVPacket pkt;
787  "DRM protected stream detected, decoding will likely fail!\n");
788  len= avio_rl32(pb);
789  av_log(s, AV_LOG_DEBUG, "Secret data:\n");
790  av_get_packet(pb, &pkt, len); av_hex_dump_log(s, AV_LOG_DEBUG, pkt.data, pkt.size); av_free_packet(&pkt);
791  len= avio_rl32(pb);
792  get_tag(s, "ASF_Protection_Type", -1, len, 32);
793  len= avio_rl32(pb);
794  get_tag(s, "ASF_Key_ID", -1, len, 32);
795  len= avio_rl32(pb);
796  get_tag(s, "ASF_License_URL", -1, len, 32);
797  } else if (!ff_guidcmp(&g, &ff_asf_ext_content_encryption)) {
799  "Ext DRM protected stream detected, decoding will likely fail!\n");
800  av_dict_set(&s->metadata, "encryption", "ASF Extended Content Encryption", 0);
801  } else if (!ff_guidcmp(&g, &ff_asf_digital_signature)) {
802  av_log(s, AV_LOG_INFO, "Digital signature detected!\n");
803  }
804  }
805  }
806  if (avio_tell(pb) != gpos + gsize)
807  av_log(s, AV_LOG_DEBUG,
808  "gpos mismatch our pos=%"PRIu64", end=%"PRId64"\n",
809  avio_tell(pb) - gpos, gsize);
810  avio_seek(pb, gpos + gsize, SEEK_SET);
811  }
812  ff_get_guid(pb, &g);
813  avio_rl64(pb);
814  avio_r8(pb);
815  avio_r8(pb);
816  if (url_feof(pb))
817  return AVERROR_EOF;
818  asf->data_offset = avio_tell(pb);
819  asf->packet_size_left = 0;
820 
821  for (i = 0; i < 128; i++) {
822  int stream_num = asf->asfid2avid[i];
823  if (stream_num >= 0) {
824  AVStream *st = s->streams[stream_num];
825  if (!st->codec->bit_rate)
826  st->codec->bit_rate = asf->stream_bitrates[i];
827  if (asf->dar[i].num > 0 && asf->dar[i].den > 0) {
830  asf->dar[i].num, asf->dar[i].den, INT_MAX);
831  } else if ((asf->dar[0].num > 0) && (asf->dar[0].den > 0) &&
832  // Use ASF container value if the stream doesn't set AR.
836  asf->dar[0].num, asf->dar[0].den, INT_MAX);
837 
838  av_dlog(s, "i=%d, st->codec->codec_type:%d, asf->dar %d:%d sar=%d:%d\n",
839  i, st->codec->codec_type, asf->dar[i].num, asf->dar[i].den,
841 
842  // copy and convert language codes to the frontend
843  if (asf->streams[i].stream_language_index < 128) {
844  const char *rfc1766 = asf->stream_languages[asf->streams[i].stream_language_index];
845  if (rfc1766 && strlen(rfc1766) > 1) {
846  const char primary_tag[3] = { rfc1766[0], rfc1766[1], '\0' }; // ignore country code if any
847  const char *iso6392 = av_convert_lang_to(primary_tag,
849  if (iso6392)
850  av_dict_set(&st->metadata, "language", iso6392, 0);
851  }
852  }
853  }
854  }
855 
857 
858  return 0;
859 }
860 
861 #define DO_2BITS(bits, var, defval) \
862  switch (bits & 3) { \
863  case 3: \
864  var = avio_rl32(pb); \
865  rsize += 4; \
866  break; \
867  case 2: \
868  var = avio_rl16(pb); \
869  rsize += 2; \
870  break; \
871  case 1: \
872  var = avio_r8(pb); \
873  rsize++; \
874  break; \
875  default: \
876  var = defval; \
877  break; \
878  }
879 
880 /**
881  * Load a single ASF packet into the demuxer.
882  * @param s demux context
883  * @param pb context to read data from
884  * @return 0 on success, <0 on error
885  */
887 {
888  ASFContext *asf = s->priv_data;
889  uint32_t packet_length, padsize;
890  int rsize = 8;
891  int c, d, e, off;
892 
893  // if we do not know packet size, allow skipping up to 32 kB
894  off = 32768;
895  if (asf->no_resync_search)
896  off = 3;
897  else if (s->packet_size > 0)
898  off = (avio_tell(pb) - s->data_offset) % s->packet_size + 3;
899 
900  c = d = e = -1;
901  while (off-- > 0) {
902  c = d;
903  d = e;
904  e = avio_r8(pb);
905  if (c == 0x82 && !d && !e)
906  break;
907  }
908 
909  if (c != 0x82) {
910  /* This code allows handling of -EAGAIN at packet boundaries (i.e.
911  * if the packet sync code above triggers -EAGAIN). This does not
912  * imply complete -EAGAIN handling support at random positions in
913  * the stream. */
914  if (pb->error == AVERROR(EAGAIN))
915  return AVERROR(EAGAIN);
916  if (!url_feof(pb))
917  av_log(s, AV_LOG_ERROR,
918  "ff asf bad header %x at:%"PRId64"\n", c, avio_tell(pb));
919  }
920  if ((c & 0x8f) == 0x82) {
921  if (d || e) {
922  if (!url_feof(pb))
923  av_log(s, AV_LOG_ERROR, "ff asf bad non zero\n");
924  return AVERROR_INVALIDDATA;
925  }
926  c = avio_r8(pb);
927  d = avio_r8(pb);
928  rsize += 3;
929  } else if(!url_feof(pb)) {
930  avio_seek(pb, -1, SEEK_CUR); // FIXME
931  }
932 
933  asf->packet_flags = c;
934  asf->packet_property = d;
935 
936  DO_2BITS(asf->packet_flags >> 5, packet_length, s->packet_size);
937  DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence ignored
938  DO_2BITS(asf->packet_flags >> 3, padsize, 0); // padding length
939 
940  // the following checks prevent overflows and infinite loops
941  if (!packet_length || packet_length >= (1U << 29)) {
942  av_log(s, AV_LOG_ERROR,
943  "invalid packet_length %d at:%"PRId64"\n",
944  packet_length, avio_tell(pb));
945  return AVERROR_INVALIDDATA;
946  }
947  if (padsize >= packet_length) {
948  av_log(s, AV_LOG_ERROR,
949  "invalid padsize %d at:%"PRId64"\n", padsize, avio_tell(pb));
950  return AVERROR_INVALIDDATA;
951  }
952 
953  asf->packet_timestamp = avio_rl32(pb);
954  avio_rl16(pb); /* duration */
955  // rsize has at least 11 bytes which have to be present
956 
957  if (asf->packet_flags & 0x01) {
958  asf->packet_segsizetype = avio_r8(pb);
959  rsize++;
960  asf->packet_segments = asf->packet_segsizetype & 0x3f;
961  } else {
962  asf->packet_segments = 1;
963  asf->packet_segsizetype = 0x80;
964  }
965  if (rsize > packet_length - padsize) {
966  asf->packet_size_left = 0;
967  av_log(s, AV_LOG_ERROR,
968  "invalid packet header length %d for pktlen %d-%d at %"PRId64"\n",
969  rsize, packet_length, padsize, avio_tell(pb));
970  return AVERROR_INVALIDDATA;
971  }
972  asf->packet_size_left = packet_length - padsize - rsize;
973  if (packet_length < asf->hdr.min_pktsize)
974  padsize += asf->hdr.min_pktsize - packet_length;
975  asf->packet_padsize = padsize;
976  av_dlog(s, "packet: size=%d padsize=%d left=%d\n",
978  return 0;
979 }
980 
981 /**
982  *
983  * @return <0 if error
984  */
986 {
987  ASFContext *asf = s->priv_data;
988  ASFStream *asfst;
989  int rsize = 1;
990  int num = avio_r8(pb);
991  int i;
992  int64_t ts0, ts1 av_unused;
993 
994  asf->packet_segments--;
995  asf->packet_key_frame = num >> 7;
996  asf->stream_index = asf->asfid2avid[num & 0x7f];
997  asfst = &asf->streams[num & 0x7f];
998  // sequence should be ignored!
999  DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
1000  DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
1002  av_dlog(asf, "key:%d stream:%d seq:%d offset:%d replic_size:%d\n",
1003  asf->packet_key_frame, asf->stream_index, asf->packet_seq,
1005  if (rsize+(int64_t)asf->packet_replic_size > asf->packet_size_left) {
1006  av_log(s, AV_LOG_ERROR, "packet_replic_size %d is invalid\n", asf->packet_replic_size);
1007  return AVERROR_INVALIDDATA;
1008  }
1009  if (asf->packet_replic_size >= 8) {
1010  int64_t end = avio_tell(pb) + asf->packet_replic_size;
1011  AVRational aspect;
1012  asf->packet_obj_size = avio_rl32(pb);
1013  if (asf->packet_obj_size >= (1 << 24) || asf->packet_obj_size <= 0) {
1014  av_log(s, AV_LOG_ERROR, "packet_obj_size invalid\n");
1015  asf->packet_obj_size = 0;
1016  return AVERROR_INVALIDDATA;
1017  }
1018  asf->packet_frag_timestamp = avio_rl32(pb); // timestamp
1019 
1020  for (i = 0; i < asfst->payload_ext_ct; i++) {
1021  ASFPayload *p = &asfst->payload[i];
1022  int size = p->size;
1023  int64_t payend;
1024  if (size == 0xFFFF)
1025  size = avio_rl16(pb);
1026  payend = avio_tell(pb) + size;
1027  if (payend > end) {
1028  av_log(s, AV_LOG_ERROR, "too long payload\n");
1029  break;
1030  }
1031  switch (p->type) {
1032  case 0x50:
1033 // duration = avio_rl16(pb);
1034  break;
1035  case 0x54:
1036  aspect.num = avio_r8(pb);
1037  aspect.den = avio_r8(pb);
1038  if (aspect.num > 0 && aspect.den > 0 && asf->stream_index >= 0) {
1039  s->streams[asf->stream_index]->sample_aspect_ratio = aspect;
1040  }
1041  break;
1042  case 0x2A:
1043  avio_skip(pb, 8);
1044  ts0 = avio_rl64(pb);
1045  ts1 = avio_rl64(pb);
1046  if (ts0!= -1) asf->packet_frag_timestamp = ts0/10000;
1048  break;
1049  case 0x5B:
1050  case 0xB7:
1051  case 0xCC:
1052  case 0xC0:
1053  case 0xA0:
1054  //unknown
1055  break;
1056  }
1057  avio_seek(pb, payend, SEEK_SET);
1058  }
1059 
1060  avio_seek(pb, end, SEEK_SET);
1061  rsize += asf->packet_replic_size; // FIXME - check validity
1062  } else if (asf->packet_replic_size == 1) {
1063  // multipacket - frag_offset is beginning timestamp
1065  asf->packet_frag_offset = 0;
1067 
1068  asf->packet_time_delta = avio_r8(pb);
1069  rsize++;
1070  } else if (asf->packet_replic_size != 0) {
1071  av_log(s, AV_LOG_ERROR, "unexpected packet_replic_size of %d\n",
1072  asf->packet_replic_size);
1073  return AVERROR_INVALIDDATA;
1074  }
1075  if (asf->packet_flags & 0x01) {
1076  DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
1077  if (rsize > asf->packet_size_left) {
1078  av_log(s, AV_LOG_ERROR, "packet_replic_size is invalid\n");
1079  return AVERROR_INVALIDDATA;
1080  } else if (asf->packet_frag_size > asf->packet_size_left - rsize) {
1081  if (asf->packet_frag_size > asf->packet_size_left - rsize + asf->packet_padsize) {
1082  av_log(s, AV_LOG_ERROR, "packet_frag_size is invalid (%d-%d)\n",
1083  asf->packet_size_left, rsize);
1084  return AVERROR_INVALIDDATA;
1085  } else {
1086  int diff = asf->packet_frag_size - (asf->packet_size_left - rsize);
1087  asf->packet_size_left += diff;
1088  asf->packet_padsize -= diff;
1089  }
1090  }
1091  } else {
1092  asf->packet_frag_size = asf->packet_size_left - rsize;
1093  }
1094  if (asf->packet_replic_size == 1) {
1095  asf->packet_multi_size = asf->packet_frag_size;
1096  if (asf->packet_multi_size > asf->packet_size_left)
1097  return AVERROR_INVALIDDATA;
1098  }
1099  asf->packet_size_left -= rsize;
1100 
1101  return 0;
1102 }
1103 
1104 /**
1105  * Parse data from individual ASF packets (which were previously loaded
1106  * with asf_get_packet()).
1107  * @param s demux context
1108  * @param pb context to read data from
1109  * @param pkt pointer to store packet data into
1110  * @return 0 if data was stored in pkt, <0 on error or 1 if more ASF
1111  * packets need to be loaded (through asf_get_packet())
1112  */
1114 {
1115  ASFContext *asf = s->priv_data;
1116  ASFStream *asf_st = 0;
1117  for (;;) {
1118  int ret;
1119  if (url_feof(pb))
1120  return AVERROR_EOF;
1121 
1122  if (asf->packet_size_left < FRAME_HEADER_SIZE ||
1123  asf->packet_segments < 1) {
1124  int ret = asf->packet_size_left + asf->packet_padsize;
1125 
1126  assert(ret >= 0);
1127  /* fail safe */
1128  avio_skip(pb, ret);
1129 
1130  asf->packet_pos = avio_tell(pb);
1131  if (asf->data_object_size != (uint64_t)-1 &&
1132  (asf->packet_pos - asf->data_object_offset >= asf->data_object_size))
1133  return AVERROR_EOF; /* Do not exceed the size of the data object */
1134  return 1;
1135  }
1136  if (asf->packet_time_start == 0) {
1137  if (asf_read_frame_header(s, pb) < 0) {
1138  asf->packet_segments = 0;
1139  continue;
1140  }
1141  if (asf->stream_index < 0 ||
1142  s->streams[asf->stream_index]->discard >= AVDISCARD_ALL ||
1143  (!asf->packet_key_frame &&
1144  s->streams[asf->stream_index]->discard >= AVDISCARD_NONKEY)) {
1145  asf->packet_time_start = 0;
1146  /* unhandled packet (should not happen) */
1147  avio_skip(pb, asf->packet_frag_size);
1148  asf->packet_size_left -= asf->packet_frag_size;
1149  if (asf->stream_index < 0)
1150  av_log(s, AV_LOG_ERROR, "ff asf skip %d (unknown stream)\n",
1151  asf->packet_frag_size);
1152  continue;
1153  }
1154  asf->asf_st = s->streams[asf->stream_index]->priv_data;
1155  }
1156  asf_st = asf->asf_st;
1157  av_assert0(asf_st);
1158 
1159  if (asf->packet_replic_size == 1) {
1160  // frag_offset is here used as the beginning timestamp
1162  asf->packet_time_start += asf->packet_time_delta;
1163  asf->packet_obj_size = asf->packet_frag_size = avio_r8(pb);
1164  asf->packet_size_left--;
1165  asf->packet_multi_size--;
1166  if (asf->packet_multi_size < asf->packet_obj_size) {
1167  asf->packet_time_start = 0;
1168  avio_skip(pb, asf->packet_multi_size);
1169  asf->packet_size_left -= asf->packet_multi_size;
1170  continue;
1171  }
1172  asf->packet_multi_size -= asf->packet_obj_size;
1173  }
1174  if (asf_st->frag_offset + asf->packet_frag_size <= asf_st->pkt.size &&
1175  asf_st->frag_offset + asf->packet_frag_size > asf->packet_obj_size) {
1176  av_log(s, AV_LOG_INFO, "ignoring invalid packet_obj_size (%d %d %d %d)\n",
1177  asf_st->frag_offset, asf->packet_frag_size,
1178  asf->packet_obj_size, asf_st->pkt.size);
1179  asf->packet_obj_size = asf_st->pkt.size;
1180  }
1181 
1182  if (asf_st->pkt.size != asf->packet_obj_size ||
1183  // FIXME is this condition sufficient?
1184  asf_st->frag_offset + asf->packet_frag_size > asf_st->pkt.size) {
1185  if (asf_st->pkt.data) {
1186  av_log(s, AV_LOG_INFO,
1187  "freeing incomplete packet size %d, new %d\n",
1188  asf_st->pkt.size, asf->packet_obj_size);
1189  asf_st->frag_offset = 0;
1190  av_free_packet(&asf_st->pkt);
1191  }
1192  /* new packet */
1193  av_new_packet(&asf_st->pkt, asf->packet_obj_size);
1194  asf_st->seq = asf->packet_seq;
1195  asf_st->pkt.dts = asf->packet_frag_timestamp - asf->hdr.preroll;
1196  asf_st->pkt.stream_index = asf->stream_index;
1197  asf_st->pkt.pos = asf_st->packet_pos = asf->packet_pos;
1198 
1199  if (asf_st->pkt.data && asf_st->palette_changed) {
1200  uint8_t *pal;
1202  AVPALETTE_SIZE);
1203  if (!pal) {
1204  av_log(s, AV_LOG_ERROR, "Cannot append palette to packet\n");
1205  } else {
1206  memcpy(pal, asf_st->palette, AVPALETTE_SIZE);
1207  asf_st->palette_changed = 0;
1208  }
1209  }
1210  av_dlog(asf, "new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n",
1211  asf->stream_index, asf->packet_key_frame,
1212  asf_st->pkt.flags & AV_PKT_FLAG_KEY,
1214  asf->packet_obj_size);
1216  asf->packet_key_frame = 1;
1217  if (asf->packet_key_frame)
1218  asf_st->pkt.flags |= AV_PKT_FLAG_KEY;
1219  }
1220 
1221  /* read data */
1222  av_dlog(asf, "READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n",
1223  s->packet_size, asf_st->pkt.size, asf->packet_frag_offset,
1224  asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data);
1225  asf->packet_size_left -= asf->packet_frag_size;
1226  if (asf->packet_size_left < 0)
1227  continue;
1228 
1229  if (asf->packet_frag_offset >= asf_st->pkt.size ||
1230  asf->packet_frag_size > asf_st->pkt.size - asf->packet_frag_offset) {
1231  av_log(s, AV_LOG_ERROR,
1232  "packet fragment position invalid %u,%u not in %u\n",
1234  asf_st->pkt.size);
1235  continue;
1236  }
1237 
1238  ret = avio_read(pb, asf_st->pkt.data + asf->packet_frag_offset,
1239  asf->packet_frag_size);
1240  if (ret != asf->packet_frag_size) {
1241  if (ret < 0 || asf->packet_frag_offset + ret == 0)
1242  return ret < 0 ? ret : AVERROR_EOF;
1243 
1244  if (asf_st->ds_span > 1) {
1245  // scrambling, we can either drop it completely or fill the remainder
1246  // TODO: should we fill the whole packet instead of just the current
1247  // fragment?
1248  memset(asf_st->pkt.data + asf->packet_frag_offset + ret, 0,
1249  asf->packet_frag_size - ret);
1250  ret = asf->packet_frag_size;
1251  } else {
1252  // no scrambling, so we can return partial packets
1253  av_shrink_packet(&asf_st->pkt, asf->packet_frag_offset + ret);
1254  }
1255  }
1256  if (s->key && s->keylen == 20)
1257  ff_asfcrypt_dec(s->key, asf_st->pkt.data + asf->packet_frag_offset,
1258  ret);
1259  asf_st->frag_offset += ret;
1260  /* test if whole packet is read */
1261  if (asf_st->frag_offset == asf_st->pkt.size) {
1262  // workaround for macroshit radio DVR-MS files
1264  asf_st->pkt.size > 100) {
1265  int i;
1266  for (i = 0; i < asf_st->pkt.size && !asf_st->pkt.data[i]; i++)
1267  ;
1268  if (i == asf_st->pkt.size) {
1269  av_log(s, AV_LOG_DEBUG, "discarding ms fart\n");
1270  asf_st->frag_offset = 0;
1271  av_free_packet(&asf_st->pkt);
1272  continue;
1273  }
1274  }
1275 
1276  /* return packet */
1277  if (asf_st->ds_span > 1) {
1278  if (asf_st->pkt.size != asf_st->ds_packet_size * asf_st->ds_span) {
1279  av_log(s, AV_LOG_ERROR,
1280  "pkt.size != ds_packet_size * ds_span (%d %d %d)\n",
1281  asf_st->pkt.size, asf_st->ds_packet_size,
1282  asf_st->ds_span);
1283  } else {
1284  /* packet descrambling */
1285  AVBufferRef *buf = av_buffer_alloc(asf_st->pkt.size +
1287  if (buf) {
1288  uint8_t *newdata = buf->data;
1289  int offset = 0;
1290  memset(newdata + asf_st->pkt.size, 0,
1292  while (offset < asf_st->pkt.size) {
1293  int off = offset / asf_st->ds_chunk_size;
1294  int row = off / asf_st->ds_span;
1295  int col = off % asf_st->ds_span;
1296  int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size;
1297  assert(offset + asf_st->ds_chunk_size <= asf_st->pkt.size);
1298  assert(idx + 1 <= asf_st->pkt.size / asf_st->ds_chunk_size);
1299  memcpy(newdata + offset,
1300  asf_st->pkt.data + idx * asf_st->ds_chunk_size,
1301  asf_st->ds_chunk_size);
1302  offset += asf_st->ds_chunk_size;
1303  }
1304  av_buffer_unref(&asf_st->pkt.buf);
1305  asf_st->pkt.buf = buf;
1306  asf_st->pkt.data = buf->data;
1307  }
1308  }
1309  }
1310  asf_st->frag_offset = 0;
1311  *pkt = asf_st->pkt;
1312 #if FF_API_DESTRUCT_PACKET
1313  asf_st->pkt.destruct = NULL;
1314 #endif
1315  asf_st->pkt.buf = 0;
1316  asf_st->pkt.size = 0;
1317  asf_st->pkt.data = 0;
1318  asf_st->pkt.side_data_elems = 0;
1319  asf_st->pkt.side_data = NULL;
1320  break; // packet completed
1321  }
1322  }
1323  return 0;
1324 }
1325 
1327 {
1328  ASFContext *asf = s->priv_data;
1329 
1330  for (;;) {
1331  int ret;
1332 
1333  /* parse cached packets, if any */
1334  if ((ret = ff_asf_parse_packet(s, s->pb, pkt)) <= 0)
1335  return ret;
1336  if ((ret = ff_asf_get_packet(s, s->pb)) < 0)
1337  assert(asf->packet_size_left < FRAME_HEADER_SIZE ||
1338  asf->packet_segments < 1);
1339  asf->packet_time_start = 0;
1340  }
1341 }
1342 
1343 // Added to support seeking after packets have been read
1344 // If information is not reset, read_packet fails due to
1345 // leftover information from previous reads
1347 {
1348  ASFContext *asf = s->priv_data;
1349  ASFStream *asf_st;
1350  int i;
1351 
1352  asf->packet_size_left = 0;
1353  asf->packet_segments = 0;
1354  asf->packet_flags = 0;
1355  asf->packet_property = 0;
1356  asf->packet_timestamp = 0;
1357  asf->packet_segsizetype = 0;
1358  asf->packet_segments = 0;
1359  asf->packet_seq = 0;
1360  asf->packet_replic_size = 0;
1361  asf->packet_key_frame = 0;
1362  asf->packet_padsize = 0;
1363  asf->packet_frag_offset = 0;
1364  asf->packet_frag_size = 0;
1365  asf->packet_frag_timestamp = 0;
1366  asf->packet_multi_size = 0;
1367  asf->packet_obj_size = 0;
1368  asf->packet_time_delta = 0;
1369  asf->packet_time_start = 0;
1370 
1371  for (i = 0; i < s->nb_streams; i++) {
1372  asf_st = s->streams[i]->priv_data;
1373  if (!asf_st)
1374  continue;
1375  av_free_packet(&asf_st->pkt);
1376  asf_st->frag_offset = 0;
1377  asf_st->seq = 0;
1378  }
1379  asf->asf_st = NULL;
1380 }
1381 
1383 {
1384  asf_reset_header(s);
1385 
1386  return 0;
1387 }
1388 
1389 static int64_t asf_read_pts(AVFormatContext *s, int stream_index,
1390  int64_t *ppos, int64_t pos_limit)
1391 {
1392  AVPacket pkt1, *pkt = &pkt1;
1393  ASFStream *asf_st;
1394  int64_t pts;
1395  int64_t pos = *ppos;
1396  int i;
1397  int64_t start_pos[ASF_MAX_STREAMS];
1398 
1399  for (i = 0; i < s->nb_streams; i++)
1400  start_pos[i] = pos;
1401 
1402  if (s->packet_size > 0)
1403  pos = (pos + s->packet_size - 1 - s->data_offset) /
1404  s->packet_size * s->packet_size +
1405  s->data_offset;
1406  *ppos = pos;
1407  if (avio_seek(s->pb, pos, SEEK_SET) < 0)
1408  return AV_NOPTS_VALUE;
1409 
1410  asf_reset_header(s);
1411  for (;;) {
1412  if (av_read_frame(s, pkt) < 0) {
1413  av_log(s, AV_LOG_INFO, "asf_read_pts failed\n");
1414  return AV_NOPTS_VALUE;
1415  }
1416 
1417  pts = pkt->dts;
1418 
1419  av_free_packet(pkt);
1420  if (pkt->flags & AV_PKT_FLAG_KEY) {
1421  i = pkt->stream_index;
1422 
1423  asf_st = s->streams[i]->priv_data;
1424  av_assert0(asf_st);
1425 
1426 // assert((asf_st->packet_pos - s->data_offset) % s->packet_size == 0);
1427  pos = asf_st->packet_pos;
1428 
1429  av_add_index_entry(s->streams[i], pos, pts, pkt->size,
1430  pos - start_pos[i] + 1, AVINDEX_KEYFRAME);
1431  start_pos[i] = asf_st->packet_pos + 1;
1432 
1433  if (pkt->stream_index == stream_index)
1434  break;
1435  }
1436  }
1437 
1438  *ppos = pos;
1439  return pts;
1440 }
1441 
1442 static void asf_build_simple_index(AVFormatContext *s, int stream_index)
1443 {
1444  ff_asf_guid g;
1445  ASFContext *asf = s->priv_data;
1446  int64_t current_pos = avio_tell(s->pb);
1447 
1448  if(avio_seek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET) < 0) {
1449  asf->index_read= -1;
1450  return;
1451  }
1452 
1453  ff_get_guid(s->pb, &g);
1454 
1455  /* the data object can be followed by other top-level objects,
1456  * skip them until the simple index object is reached */
1457  while (ff_guidcmp(&g, &ff_asf_simple_index_header)) {
1458  int64_t gsize = avio_rl64(s->pb);
1459  if (gsize < 24 || url_feof(s->pb)) {
1460  avio_seek(s->pb, current_pos, SEEK_SET);
1461  asf->index_read= -1;
1462  return;
1463  }
1464  avio_skip(s->pb, gsize - 24);
1465  ff_get_guid(s->pb, &g);
1466  }
1467 
1468  {
1469  int64_t itime, last_pos = -1;
1470  int pct, ict;
1471  int i;
1472  int64_t av_unused gsize = avio_rl64(s->pb);
1473  ff_get_guid(s->pb, &g);
1474  itime = avio_rl64(s->pb);
1475  pct = avio_rl32(s->pb);
1476  ict = avio_rl32(s->pb);
1477  av_log(s, AV_LOG_DEBUG,
1478  "itime:0x%"PRIx64", pct:%d, ict:%d\n", itime, pct, ict);
1479 
1480  for (i = 0; i < ict; i++) {
1481  int pktnum = avio_rl32(s->pb);
1482  int pktct = avio_rl16(s->pb);
1483  int64_t pos = s->data_offset + s->packet_size * (int64_t)pktnum;
1484  int64_t index_pts = FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);
1485 
1486  if (pos != last_pos) {
1487  av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d pts: %"PRId64"\n",
1488  pktnum, pktct, index_pts);
1489  av_add_index_entry(s->streams[stream_index], pos, index_pts,
1490  s->packet_size, 0, AVINDEX_KEYFRAME);
1491  last_pos = pos;
1492  }
1493  }
1494  asf->index_read = ict > 1;
1495  }
1496  avio_seek(s->pb, current_pos, SEEK_SET);
1497 }
1498 
1499 static int asf_read_seek(AVFormatContext *s, int stream_index,
1500  int64_t pts, int flags)
1501 {
1502  ASFContext *asf = s->priv_data;
1503  AVStream *st = s->streams[stream_index];
1504 
1505  if (s->packet_size <= 0)
1506  return -1;
1507 
1508  /* Try using the protocol's read_seek if available */
1509  if (s->pb) {
1510  int ret = avio_seek_time(s->pb, stream_index, pts, flags);
1511  if (ret >= 0)
1512  asf_reset_header(s);
1513  if (ret != AVERROR(ENOSYS))
1514  return ret;
1515  }
1516 
1517  if (!asf->index_read)
1518  asf_build_simple_index(s, stream_index);
1519 
1520  if ((asf->index_read > 0 && st->index_entries)) {
1521  int index = av_index_search_timestamp(st, pts, flags);
1522  if (index >= 0) {
1523  /* find the position */
1524  uint64_t pos = st->index_entries[index].pos;
1525 
1526  /* do the seek */
1527  av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos);
1528  if(avio_seek(s->pb, pos, SEEK_SET) < 0)
1529  return -1;
1530  asf_reset_header(s);
1531  return 0;
1532  }
1533  }
1534  /* no index or seeking by index failed */
1535  if (ff_seek_frame_binary(s, stream_index, pts, flags) < 0)
1536  return -1;
1537  asf_reset_header(s);
1538  return 0;
1539 }
1540 
1542  .name = "asf",
1543  .long_name = NULL_IF_CONFIG_SMALL("ASF (Advanced / Active Streaming Format)"),
1544  .priv_data_size = sizeof(ASFContext),
1545  .read_probe = asf_probe,
1550  .read_timestamp = asf_read_pts,
1552  .priv_class = &asf_class,
1553 };
const char * name
Definition: avisynth_c.h:675
#define FRAME_HEADER_SIZE
Definition: asfdec.c:100
const ff_asf_guid ff_asf_header
Definition: asf.c:23
unsigned int packet_size
Definition: avformat.h:1018
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
discard all frames except keyframes
#define AVFMT_NOBINSEARCH
Format does not allow to fallback to binary search via read_timestamp.
Definition: avformat.h:358
const char * s
Definition: avisynth_c.h:668
Bytestream IO Context.
Definition: avio.h:68
static int asf_read_marker(AVFormatContext *s, int64_t size)
Definition: asfdec.c:684
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:261
int packet_timestamp
Definition: asfdec.c:61
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
void av_free_packet(AVPacket *pkt)
Free a packet.
Definition: avpacket.c:242
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:134
int packet_segments
Definition: asfdec.c:63
AVOption.
Definition: opt.h:251
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.
const ff_asf_guid ff_asf_codec_comment_header
Definition: asf.c:73
enum AVCodecID id
Definition: mxfenc.c:89
const ff_asf_guid ff_asf_metadata_header
Definition: asf.c:108
static void get_id3_tag(AVFormatContext *s, int len)
Definition: asfdec.c:267
int packet_key_frame
Definition: asfdec.c:66
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
av_default_item_name
AVInputFormat ff_asf_demuxer
Definition: asfdec.c:1541
int64_t pos
byte position in stream, -1 if unknown
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:97
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.
static const AVClass asf_class
Definition: asfdec.c:89
int64_t pos
Definition: avformat.h:592
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:154
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:52
ASFMainHeader hdr
Definition: asfdec.c:57
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:709
static const AVOption options[]
Definition: asfdec.c:84
static int asf_read_metadata(AVFormatContext *s, int64_t size)
Definition: asfdec.c:645
int num
numerator
Definition: rational.h:44
int index
stream index in AVFormatContext
Definition: avformat.h:644
#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:199
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: avformat.h:822
int64_t packet_frag_timestamp
Definition: asfdec.c:70
int palette_changed
Definition: asf.h:53
const ff_asf_guid ff_asf_command_stream
Definition: asf.c:65
void * priv_data
Definition: avformat.h:663
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:256
#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:1242
uint32_t min_pktsize
size of a data packet invalid if broadcasting
Definition: asf.h:76
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:827
int packet_time_start
Definition: asfdec.c:74
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:148
static int asf_read_file_properties(AVFormatContext *s, int64_t size)
Definition: asfdec.c:323
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.
set threshold d
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
Format I/O context.
Definition: avformat.h:944
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:55
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
Public dictionary API.
int ffio_limit(AVIOContext *s, int size)
static int64_t start_time
Definition: ffplay.c:293
uint8_t
uint32_t flags
0x01 - broadcast 0x02 - seekable rest is reserved should be 0
Definition: asf.h:73
Opaque data information usually continuous.
Definition: avutil.h:145
const ff_asf_guid ff_asf_audio_stream
Definition: asf.c:39
AVOptions.
#define AVPALETTE_SIZE
Definition: pixfmt.h:33
static AVPacket pkt
Definition: demuxing.c:56
int packet_time_delta
Definition: asfdec.c:73
enum AVStreamParseType need_parsing
Definition: avformat.h:811
int id
Format-specific stream ID.
Definition: avformat.h:650
end end
ASFStream streams[128]
it&#39;s max number and it&#39;s not that big
Definition: asfdec.c:44
int packet_padsize
Definition: asfdec.c:67
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
Definition: avformat.h:992
int packet_size_left
Definition: asfdec.c:50
#define DO_2BITS(bits, var, defval)
Definition: asfdec.c:861
uint8_t * data
ASFStream * asf_st
currently decoded stream
Definition: asfdec.c:79
uint64_t send_time
time to send file, in 100-nanosecond units invalid if broadcasting (could be ignored) ...
Definition: asf.h:68
#define AVERROR_EOF
End of file.
Definition: error.h:55
enum AVCodecID id
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
AVPacket pkt
Definition: asf.h:40
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.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:248
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
int asfid2avid[128]
conversion table from asf ID 2 AVStream ID
Definition: asfdec.c:43
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:478
uint64_t file_size
in bytes invalid if broadcasting
Definition: asf.h:62
ff_asf_guid guid
generated by client computer
Definition: asf.h:61
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define U(x)
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:73
#define AVINDEX_KEYFRAME
Definition: avformat.h:599
const ff_asf_guid ff_asf_audio_conceal_none
Definition: asf.c:43
int packet_replic_size
Definition: asfdec.c:65
static int asf_read_picture(AVFormatContext *s, int len)
Definition: asfdec.c:180
AVCodecID
Identify the syntax and semantics of the bitstream.
AVDictionary * metadata
Definition: avformat.h:1092
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.
#define ASF_MAX_STREAMS
Definition: asfdec.c:99
const ff_asf_guid ff_asf_simple_index_header
Definition: asf.c:96
const ff_asf_guid ff_asf_head2_guid
Definition: asf.c:88
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:579
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: asf.h:31
void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len)
Definition: asfcrypt.c:147
int packet_seq
Definition: asfdec.c:64
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
Free memory allocated parsing special (non-text) metadata.
Definition: id3v2.c:813
const ff_asf_guid ff_asf_video_conceal_none
Definition: asf.c:61
int ds_chunk_size
Definition: asf.h:47
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:246
int frag_offset
Definition: asf.h:41
static const uint8_t offset[127][2]
Definition: vf_spp.c:70
#define FFMAX(a, b)
Definition: common.h:56
uint64_t data_object_size
size of the data object
Definition: asfdec.c:54
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:82
int size
const char * ff_id3v2_picture_types[21]
Definition: id3v2.c:103
int flags
A combination of AV_PKT_FLAG values.
static int asf_read_header(AVFormatContext *s)
Definition: asfdec.c:718
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:469
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
uint32_t max_pktsize
shall be the same as for min_pktsize invalid if broadcasting
Definition: asf.h:78
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:336
const CodecMime ff_id3v2_mime_tags[]
Definition: id3v2.c:127
uint16_t size
Definition: asf.h:33
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:991
#define AV_LOG_VERBOSE
Definition: log.h:157
uint32_t palette[256]
Definition: asf.h:54
FFT buffer for g
Definition: stft_peak.m:17
int bit_rate
the average bitrate
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:118
#define LEN
#define FFMIN(a, b)
Definition: common.h:58
const ff_asf_guid ff_asf_digital_signature
Definition: asf.c:138
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:35
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that&#39;s been allocated with av_malloc() and chilren.
Definition: dict.h:72
static int read_probe(AVProbeData *pd)
char stream_languages[128][6]
max number of streams, language for each (RFC1766, e.g. en-US)
Definition: asfdec.c:47
ret
Definition: avfilter.c:821
int width
picture width / height.
const ff_asf_guid ff_asf_extended_content_header
Definition: asf.c:92
unsigned int packet_frag_size
Definition: asfdec.c:69
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
#define FFABS(a)
Definition: common.h:53
const ff_asf_guid ff_asf_ext_stream_embed_stream_header
Definition: asf.c:100
int packet_multi_size
Definition: asfdec.c:71
AVDictionary * metadata
Definition: avformat.h:711
const ff_asf_guid ff_asf_my_guid
Definition: asf.c:122
#define diff(a, as, b, bs)
Definition: vf_phase.c:80
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:142
static int asf_probe(AVProbeData *pd)
Definition: asfdec.c:151
int url_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
Definition: aviobuf.c:280
preferred ID for MPEG-1/2 video decoding
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:627
void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta)
Read an ID3v2 tag, including supported extra metadata.
Definition: id3v2.c:780
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:517
static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
Definition: asfdec.c:347
uint8_t ff_asf_guid[16]
Definition: riff.h:59
Stream structure.
Definition: avformat.h:643
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:1113
NULL
Definition: eval.c:55
uint32_t ignore
preroll is 64bit - but let&#39;s just ignore it
Definition: asf.h:72
uint32_t stream_bitrates[128]
max number of streams, bitrate for each (for streaming)
Definition: asfdec.c:45
#define av_bswap32
Definition: bfin/bswap.h:33
int ds_span
Definition: asf.h:45
uint64_t create_time
time of creation, in 100-nanosecond units since 1.1.1601 invalid if broadcasting
Definition: asf.h:64
enum AVMediaType codec_type
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:66
enum AVCodecID codec_id
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
AVIOContext * pb
I/O context.
Definition: avformat.h:977
static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
Definition: asfdec.c:1389
const ff_asf_guid ff_asf_video_stream
Definition: asf.c:53
Definition: asf.h:36
uint8_t * data
The data buffer.
Definition: buffer.h:89
ASFPayload payload[8]
Definition: asf.h:57
static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
Definition: asfdec.c:1499
static int ff_asf_get_packet(AVFormatContext *s, AVIOContext *pb)
Load a single ASF packet into the demuxer.
Definition: asfdec.c:886
uint16_t stream_language_index
Definition: asf.h:51
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
#define AVFMT_NOGENSEARCH
Format does not allow to fallback to generic search.
Definition: avformat.h:359
void * buf
Definition: avisynth_c.h:594
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:62
int index_read
Definition: asfdec.c:55
double value
Definition: eval.c:82
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:73
Describe the class of an AVClass context structure.
Definition: log.h:50
int index
Definition: gxfenc.c:89
synthesis window for stochastic i
rational number numerator/denominator
Definition: rational.h:43
int ds_packet_size
Definition: asf.h:46
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:282
unsigned int packet_frag_offset
Definition: asfdec.c:68
static void asf_build_simple_index(AVFormatContext *s, int stream_index)
Definition: asfdec.c:1442
byte swapping routines
static int asf_read_close(AVFormatContext *s)
Definition: asfdec.c:1382
AVMediaType
Definition: avutil.h:141
const AVMetadataConv ff_asf_metadata_conv[]
Definition: asf.c:143
#define snprintf
Definition: snprintf.h:34
uint64_t data_object_offset
data object offset (excl. GUID & size)
Definition: asfdec.c:53
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:334
static int asf_read_ext_content_desc(AVFormatContext *s, int64_t size)
Definition: asfdec.c:591
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
#define type
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb)
Definition: asfdec.c:985
full parsing and repack of the first frame only, only implemented for H.264 currently ...
Definition: avformat.h:585
static int asf_read_content_desc(AVFormatContext *s, int64_t size)
Definition: asfdec.c:572
int packet_property
Definition: asfdec.c:60
const ff_asf_guid ff_asf_comment_header
Definition: asf.c:69
static int flags
Definition: cpu.c:23
uint8_t type
Definition: asf.h:32
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:696
Synth Windw Norm while(pin< pend)%Until the end...%---Analysis x_w
uint32_t preroll
timestamp of the first packet, in milliseconds if nonzero - subtract from time
Definition: asf.h:70
#define AVPROBE_SCORE_MAX
maximum score, half of that is used for file-extension-based detection
Definition: avformat.h:340
const uint8_t * key
Definition: avformat.h:1047
int64_t packet_pos
Definition: asf.h:49
A reference to a data buffer.
Definition: buffer.h:81
const ff_asf_guid ff_asf_language_guid
Definition: asf.c:126
full parsing and repack
Definition: avformat.h:582
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:563
Main libavformat public API header.
const ff_asf_guid ff_asf_jfif_media
Definition: asf.c:57
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:162
common internal and external API header
int packet_obj_size
Definition: asfdec.c:72
static double c[64]
int no_resync_search
Definition: asfdec.c:81
unsigned char seq
Definition: asf.h:38
int disposition
AV_DISPOSITION_* bit field.
Definition: avformat.h:700
const ff_asf_guid ff_asf_codec_comment1_header
Definition: asf.c:76
int den
denominator
Definition: rational.h:45
void ff_get_guid(AVIOContext *s, ff_asf_guid *g)
void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
int64_t packet_pos
Definition: asfdec.c:75
int payload_ext_ct
Definition: asf.h:56
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:866
const ff_asf_guid ff_asf_content_encryption
Definition: asf.c:130
int len
AVRational dar[128]
Definition: asfdec.c:46
void * priv_data
Format private data.
Definition: avformat.h:964
static int asf_read_language_list(AVFormatContext *s, int64_t size)
Definition: asfdec.c:625
int packet_flags
Definition: asfdec.c:59
static int get_value(AVIOContext *pb, int type, int type2_size)
Definition: asfdec.c:162
int packet_segsizetype
Definition: asfdec.c:62
struct AVPacket::@35 * side_data
Additional packet data that can be provided by the container.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int stream_index
Definition: asfdec.c:77
#define AV_LOG_INFO
Definition: log.h:156
void INT64 INT64 count
Definition: avisynth_c.h:594
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:461
const ff_asf_guid ff_asf_marker_header
Definition: asf.c:116
void av_hex_dump_log(void *avcl, int level, const uint8_t *buf, int size)
Send a nice hexadecimal dump of a buffer to the log.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
Definition: avpacket.c:264
static void get_tag(AVFormatContext *s, const char *key, int type, int len, int type2_size)
Definition: asfdec.c:277
#define MKTAG(a, b, c, d)
Definition: common.h:282
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:702
static av_always_inline int ff_guidcmp(const void *g1, const void *g2)
Definition: riff.h:68
int request_probe
stream probing state -1 -> probing finished 0 -> no probing requested rest -> perform probing with re...
Definition: avformat.h:834
static void asf_reset_header(AVFormatContext *s)
Definition: asfdec.c:1346
This structure stores compressed data.
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:587
uint32_t max_bitrate
bandwidth of stream in bps should be the sum of bitrates of the individual media streams ...
Definition: asf.h:80
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:725
static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: asfdec.c:1326
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:190
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().
#define av_unused
Definition: attributes.h:114