FFmpeg
asfdec_f.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 #include <inttypes.h>
23 
24 #include "libavutil/attributes.h"
25 #include "libavutil/avassert.h"
26 #include "libavutil/avstring.h"
27 #include "libavutil/bswap.h"
28 #include "libavutil/common.h"
29 #include "libavutil/dict.h"
30 #include "libavutil/internal.h"
31 #include "libavutil/mathematics.h"
32 #include "libavutil/opt.h"
33 #include "avformat.h"
34 #include "avio_internal.h"
35 #include "avlanguage.h"
36 #include "id3v2.h"
37 #include "internal.h"
38 #include "riff.h"
39 #include "asf.h"
40 #include "asfcrypt.h"
41 
42 typedef struct ASFPayload {
44  uint16_t size;
45 } ASFPayload;
46 
47 typedef struct ASFStream {
48  int num;
49  unsigned char seq;
50  /* use for reading */
54  int timestamp;
55  int64_t duration;
57  int pkt_clean;
58 
59  int ds_span; /* descrambling */
62 
63  int64_t packet_pos;
64 
66 
68  uint32_t palette[256];
69 
72 } ASFStream;
73 
74 typedef struct ASFContext {
75  const AVClass *class;
76  int asfid2avid[128]; ///< conversion table from asf ID 2 AVStream ID
77  ASFStream streams[128]; ///< it's max number and it's not that big
78  uint32_t stream_bitrates[128]; ///< max number of streams, bitrate for each (for streaming)
80  char stream_languages[128][6]; ///< max number of streams, language for each (RFC1766, e.g. en-US)
81  /* non streamed additonnal info */
82  /* packet filling */
84  /* only for reading */
85  uint64_t data_offset; ///< beginning of the first data packet
86  uint64_t data_object_offset; ///< data object offset (excl. GUID & size)
87  uint64_t data_object_size; ///< size of the data object
89 
91 
101  unsigned int packet_frag_offset;
102  unsigned int packet_frag_size;
108  int64_t packet_pos;
109 
111 
112  ASFStream *asf_st; ///< currently decoded stream
113 
116 
118 } ASFContext;
119 
120 static const AVOption options[] = {
121  { "no_resync_search", "Don't try to resynchronize by looking for a certain optional start code", offsetof(ASFContext, no_resync_search), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
122  { "export_xmp", "Export full XMP metadata", offsetof(ASFContext, export_xmp), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
123  { NULL },
124 };
125 
126 static const AVClass asf_class = {
127  .class_name = "asf demuxer",
128  .item_name = av_default_item_name,
129  .option = options,
130  .version = LIBAVUTIL_VERSION_INT,
131 };
132 
133 #undef NDEBUG
134 #include <assert.h>
135 
136 #define ASF_MAX_STREAMS 127
137 #define FRAME_HEADER_SIZE 6
138 // Fix Me! FRAME_HEADER_SIZE may be different.
139 // (7 is known to be too large for GipsyGuitar.wmv)
140 
141 #ifdef DEBUG
142 static const ff_asf_guid stream_bitrate_guid = { /* (http://get.to/sdp) */
143  0xce, 0x75, 0xf8, 0x7b, 0x8d, 0x46, 0xd1, 0x11, 0x8d, 0x82, 0x00, 0x60, 0x97, 0xc9, 0xa2, 0xb2
144 };
145 
146 #define PRINT_IF_GUID(g, cmp) \
147  if (!ff_guidcmp(g, &cmp)) \
148  av_log(NULL, AV_LOG_TRACE, "(GUID: %s) ", # cmp)
149 
150 static void print_guid(ff_asf_guid *g)
151 {
152  int i;
153  PRINT_IF_GUID(g, ff_asf_header);
154  else PRINT_IF_GUID(g, ff_asf_file_header);
155  else PRINT_IF_GUID(g, ff_asf_stream_header);
156  else PRINT_IF_GUID(g, ff_asf_audio_stream);
157  else PRINT_IF_GUID(g, ff_asf_audio_conceal_none);
158  else PRINT_IF_GUID(g, ff_asf_video_stream);
159  else PRINT_IF_GUID(g, ff_asf_video_conceal_none);
160  else PRINT_IF_GUID(g, ff_asf_command_stream);
161  else PRINT_IF_GUID(g, ff_asf_comment_header);
162  else PRINT_IF_GUID(g, ff_asf_codec_comment_header);
163  else PRINT_IF_GUID(g, ff_asf_codec_comment1_header);
164  else PRINT_IF_GUID(g, ff_asf_data_header);
165  else PRINT_IF_GUID(g, ff_asf_simple_index_header);
166  else PRINT_IF_GUID(g, ff_asf_head1_guid);
167  else PRINT_IF_GUID(g, ff_asf_head2_guid);
168  else PRINT_IF_GUID(g, ff_asf_my_guid);
169  else PRINT_IF_GUID(g, ff_asf_ext_stream_header);
170  else PRINT_IF_GUID(g, ff_asf_extended_content_header);
171  else PRINT_IF_GUID(g, ff_asf_ext_stream_embed_stream_header);
172  else PRINT_IF_GUID(g, ff_asf_ext_stream_audio_stream);
173  else PRINT_IF_GUID(g, ff_asf_metadata_header);
174  else PRINT_IF_GUID(g, ff_asf_metadata_library_header);
175  else PRINT_IF_GUID(g, ff_asf_marker_header);
176  else PRINT_IF_GUID(g, stream_bitrate_guid);
177  else PRINT_IF_GUID(g, ff_asf_language_guid);
178  else
179  av_log(NULL, AV_LOG_TRACE, "(GUID: unknown) ");
180  for (i = 0; i < 16; i++)
181  av_log(NULL, AV_LOG_TRACE, " 0x%02x,", (*g)[i]);
182  av_log(NULL, AV_LOG_TRACE, "}\n");
183 }
184 #undef PRINT_IF_GUID
185 #else
186 #define print_guid(g) while(0)
187 #endif
188 
189 static int asf_probe(const AVProbeData *pd)
190 {
191  /* check file header */
192  if (!ff_guidcmp(pd->buf, &ff_asf_header))
193  return AVPROBE_SCORE_MAX;
194  else
195  return 0;
196 }
197 
198 /* size of type 2 (BOOL) is 32bit for "Extended Content Description Object"
199  * but 16 bit for "Metadata Object" and "Metadata Library Object" */
200 static int get_value(AVIOContext *pb, int type, int type2_size)
201 {
202  switch (type) {
203  case 2:
204  return (type2_size == 32) ? avio_rl32(pb) : avio_rl16(pb);
205  case 3:
206  return avio_rl32(pb);
207  case 4:
208  return avio_rl64(pb);
209  case 5:
210  return avio_rl16(pb);
211  default:
212  return INT_MIN;
213  }
214 }
215 
216 /* MSDN claims that this should be "compatible with the ID3 frame, APIC",
217  * but in reality this is only loosely similar */
219 {
220  AVPacket pkt = { 0 };
221  const CodecMime *mime = ff_id3v2_mime_tags;
222  enum AVCodecID id = AV_CODEC_ID_NONE;
223  char mimetype[64];
224  uint8_t *desc = NULL;
225  AVStream *st = NULL;
226  int ret, type, picsize, desc_len;
227 
228  /* type + picsize + mime + desc */
229  if (len < 1 + 4 + 2 + 2) {
230  av_log(s, AV_LOG_ERROR, "Invalid attached picture size: %d.\n", len);
231  return AVERROR_INVALIDDATA;
232  }
233 
234  /* picture type */
235  type = avio_r8(s->pb);
236  len--;
238  av_log(s, AV_LOG_WARNING, "Unknown attached picture type: %d.\n", type);
239  type = 0;
240  }
241 
242  /* picture data size */
243  picsize = avio_rl32(s->pb);
244  len -= 4;
245 
246  /* picture MIME type */
247  len -= avio_get_str16le(s->pb, len, mimetype, sizeof(mimetype));
248  while (mime->id != AV_CODEC_ID_NONE) {
249  if (!strncmp(mime->str, mimetype, sizeof(mimetype))) {
250  id = mime->id;
251  break;
252  }
253  mime++;
254  }
255  if (id == AV_CODEC_ID_NONE) {
256  av_log(s, AV_LOG_ERROR, "Unknown attached picture mimetype: %s.\n",
257  mimetype);
258  return 0;
259  }
260 
261  if (picsize >= len) {
262  av_log(s, AV_LOG_ERROR, "Invalid attached picture data size: %d >= %d.\n",
263  picsize, len);
264  return AVERROR_INVALIDDATA;
265  }
266 
267  /* picture description */
268  desc_len = (len - picsize) * 2 + 1;
269  desc = av_malloc(desc_len);
270  if (!desc)
271  return AVERROR(ENOMEM);
272  len -= avio_get_str16le(s->pb, len - picsize, desc, desc_len);
273 
274  ret = av_get_packet(s->pb, &pkt, picsize);
275  if (ret < 0)
276  goto fail;
277 
278  st = avformat_new_stream(s, NULL);
279  if (!st) {
280  ret = AVERROR(ENOMEM);
281  goto fail;
282  }
285  st->codecpar->codec_id = id;
286  st->attached_pic = pkt;
287  st->attached_pic.stream_index = st->index;
289 
290  if (*desc)
292  else
293  av_freep(&desc);
294 
295  av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[type], 0);
296 
297  return 0;
298 
299 fail:
300  av_freep(&desc);
302  return ret;
303 }
304 
305 static void get_id3_tag(AVFormatContext *s, int len)
306 {
307  ID3v2ExtraMeta *id3v2_extra_meta = NULL;
308 
309  ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta, len);
310  if (id3v2_extra_meta) {
311  ff_id3v2_parse_apic(s, &id3v2_extra_meta);
312  ff_id3v2_parse_chapters(s, &id3v2_extra_meta);
313  }
314  ff_id3v2_free_extra_meta(&id3v2_extra_meta);
315 }
316 
317 static void get_tag(AVFormatContext *s, const char *key, int type, int len, int type2_size)
318 {
319  ASFContext *asf = s->priv_data;
320  char *value = NULL;
321  int64_t off = avio_tell(s->pb);
322 #define LEN 22
323 
324  av_assert0((unsigned)len < (INT_MAX - LEN) / 2);
325 
326  if (!asf->export_xmp && !strncmp(key, "xmp", 3))
327  goto finish;
328 
329  value = av_malloc(2 * len + LEN);
330  if (!value)
331  goto finish;
332 
333  switch (type) {
334  case ASF_UNICODE:
335  avio_get_str16le(s->pb, len, value, 2 * len + 1);
336  break;
337  case -1: // ASCI
338  avio_read(s->pb, value, len);
339  value[len]=0;
340  break;
341  case ASF_BYTE_ARRAY:
342  if (!strcmp(key, "WM/Picture")) { // handle cover art
344  } else if (!strcmp(key, "ID3")) { // handle ID3 tag
345  get_id3_tag(s, len);
346  } else {
347  av_log(s, AV_LOG_VERBOSE, "Unsupported byte array in tag %s.\n", key);
348  }
349  goto finish;
350  case ASF_BOOL:
351  case ASF_DWORD:
352  case ASF_QWORD:
353  case ASF_WORD: {
354  uint64_t num = get_value(s->pb, type, type2_size);
355  snprintf(value, LEN, "%"PRIu64, num);
356  break;
357  }
358  case ASF_GUID:
359  av_log(s, AV_LOG_DEBUG, "Unsupported GUID value in tag %s.\n", key);
360  goto finish;
361  default:
363  "Unsupported value type %d in tag %s.\n", type, key);
364  goto finish;
365  }
366  if (*value)
367  av_dict_set(&s->metadata, key, value, 0);
368 
369 finish:
370  av_freep(&value);
371  avio_seek(s->pb, off + len, SEEK_SET);
372 }
373 
375 {
376  ASFContext *asf = s->priv_data;
377  AVIOContext *pb = s->pb;
378 
379  ff_get_guid(pb, &asf->hdr.guid);
380  asf->hdr.file_size = avio_rl64(pb);
381  asf->hdr.create_time = avio_rl64(pb);
382  avio_rl64(pb); /* number of packets */
383  asf->hdr.play_time = avio_rl64(pb);
384  asf->hdr.send_time = avio_rl64(pb);
385  asf->hdr.preroll = avio_rl32(pb);
386  asf->hdr.ignore = avio_rl32(pb);
387  asf->hdr.flags = avio_rl32(pb);
388  asf->hdr.min_pktsize = avio_rl32(pb);
389  asf->hdr.max_pktsize = avio_rl32(pb);
390  if (asf->hdr.min_pktsize >= (1U << 29))
391  return AVERROR_INVALIDDATA;
392  asf->hdr.max_bitrate = avio_rl32(pb);
393  s->packet_size = asf->hdr.max_pktsize;
394 
395  return 0;
396 }
397 
399 {
400  ASFContext *asf = s->priv_data;
401  AVIOContext *pb = s->pb;
402  AVStream *st;
403  ASFStream *asf_st;
404  ff_asf_guid g;
405  enum AVMediaType type;
406  int type_specific_size, sizeX;
407  unsigned int tag1;
408  int64_t pos1, pos2, start_time;
409  int test_for_ext_stream_audio, is_dvr_ms_audio = 0;
410 
411  if (s->nb_streams == ASF_MAX_STREAMS) {
412  av_log(s, AV_LOG_ERROR, "too many streams\n");
413  return AVERROR(EINVAL);
414  }
415 
416  pos1 = avio_tell(pb);
417 
418  st = avformat_new_stream(s, NULL);
419  if (!st)
420  return AVERROR(ENOMEM);
421  avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
422  start_time = asf->hdr.preroll;
423 
424  if (!(asf->hdr.flags & 0x01)) { // if we aren't streaming...
425  int64_t fsize = avio_size(pb);
426  if (fsize <= 0 || (int64_t)asf->hdr.file_size <= 0 ||
427  FFABS(fsize - (int64_t)asf->hdr.file_size) < FFMIN(fsize, asf->hdr.file_size)/20)
428  st->duration = asf->hdr.play_time /
429  (10000000 / 1000) - start_time;
430  }
431  ff_get_guid(pb, &g);
432 
433  test_for_ext_stream_audio = 0;
434  if (!ff_guidcmp(&g, &ff_asf_audio_stream)) {
436  } else if (!ff_guidcmp(&g, &ff_asf_video_stream)) {
438  } else if (!ff_guidcmp(&g, &ff_asf_jfif_media)) {
441  } else if (!ff_guidcmp(&g, &ff_asf_command_stream)) {
444  test_for_ext_stream_audio = 1;
446  } else {
447  return -1;
448  }
449  ff_get_guid(pb, &g);
450  avio_skip(pb, 8); /* total_size */
451  type_specific_size = avio_rl32(pb);
452  avio_rl32(pb);
453  st->id = avio_rl16(pb) & 0x7f; /* stream id */
454  // mapping of asf ID to AV stream ID;
455  asf->asfid2avid[st->id] = s->nb_streams - 1;
456  asf_st = &asf->streams[st->id];
457 
458  avio_rl32(pb);
459 
460  if (test_for_ext_stream_audio) {
461  ff_get_guid(pb, &g);
464  is_dvr_ms_audio = 1;
465  ff_get_guid(pb, &g);
466  avio_rl32(pb);
467  avio_rl32(pb);
468  avio_rl32(pb);
469  ff_get_guid(pb, &g);
470  avio_rl32(pb);
471  }
472  }
473 
474  st->codecpar->codec_type = type;
475  if (type == AVMEDIA_TYPE_AUDIO) {
476  int ret = ff_get_wav_header(s, pb, st->codecpar, type_specific_size, 0);
477  if (ret < 0)
478  return ret;
479  if (is_dvr_ms_audio) {
480  // codec_id and codec_tag are unreliable in dvr_ms
481  // files. Set them later by probing stream.
482  st->request_probe = 1;
483  st->codecpar->codec_tag = 0;
484  }
485  if (st->codecpar->codec_id == AV_CODEC_ID_AAC)
487  else
489  /* We have to init the frame size at some point .... */
490  pos2 = avio_tell(pb);
491  if (size >= (pos2 + 8 - pos1 + 24)) {
492  asf_st->ds_span = avio_r8(pb);
493  asf_st->ds_packet_size = avio_rl16(pb);
494  asf_st->ds_chunk_size = avio_rl16(pb);
495  avio_rl16(pb); // ds_data_size
496  avio_r8(pb); // ds_silence_data
497  }
498  if (asf_st->ds_span > 1) {
499  if (!asf_st->ds_chunk_size ||
500  (asf_st->ds_packet_size / asf_st->ds_chunk_size <= 1) ||
501  asf_st->ds_packet_size % asf_st->ds_chunk_size)
502  asf_st->ds_span = 0; // disable descrambling
503  }
504  } else if (type == AVMEDIA_TYPE_VIDEO &&
505  size - (avio_tell(pb) - pos1 + 24) >= 51) {
506  avio_rl32(pb);
507  avio_rl32(pb);
508  avio_r8(pb);
509  avio_rl16(pb); /* size */
510  sizeX = avio_rl32(pb); /* size */
511  st->codecpar->width = avio_rl32(pb);
512  st->codecpar->height = avio_rl32(pb);
513  /* not available for asf */
514  avio_rl16(pb); /* panes */
515  st->codecpar->bits_per_coded_sample = avio_rl16(pb); /* depth */
516  tag1 = avio_rl32(pb);
517  avio_skip(pb, 20);
518  if (sizeX > 40) {
519  if (size < sizeX - 40 || sizeX - 40 > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
520  return AVERROR_INVALIDDATA;
521  st->codecpar->extradata_size = ffio_limit(pb, sizeX - 40);
524  if (!st->codecpar->extradata)
525  return AVERROR(ENOMEM);
527  }
528 
529  /* Extract palette from extradata if bpp <= 8 */
530  /* This code assumes that extradata contains only palette */
531  /* This is true for all paletted codecs implemented in libavcodec */
532  if (st->codecpar->extradata_size && (st->codecpar->bits_per_coded_sample <= 8)) {
533 #if HAVE_BIGENDIAN
534  int i;
535  for (i = 0; i < FFMIN(st->codecpar->extradata_size, AVPALETTE_SIZE) / 4; i++)
536  asf_st->palette[i] = av_bswap32(((uint32_t *)st->codecpar->extradata)[i]);
537 #else
538  memcpy(asf_st->palette, st->codecpar->extradata,
540 #endif
541  asf_st->palette_changed = 1;
542  }
543 
544  st->codecpar->codec_tag = tag1;
546  if (tag1 == MKTAG('D', 'V', 'R', ' ')) {
548  /* issue658 contains wrong w/h and MS even puts a fake seq header
549  * with wrong w/h in extradata while a correct one is in the stream.
550  * maximum lameness */
551  st->codecpar->width =
552  st->codecpar->height = 0;
553  av_freep(&st->codecpar->extradata);
554  st->codecpar->extradata_size = 0;
555  }
556  if (st->codecpar->codec_id == AV_CODEC_ID_H264)
558  if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4)
560  }
561  pos2 = avio_tell(pb);
562  avio_skip(pb, size - (pos2 - pos1 + 24));
563 
564  return 0;
565 }
566 
568 {
569  ASFContext *asf = s->priv_data;
570  AVIOContext *pb = s->pb;
571  ff_asf_guid g;
572  int ext_len, payload_ext_ct, stream_ct, i;
573  uint32_t leak_rate, stream_num;
574  unsigned int stream_languageid_index;
575 
576  avio_rl64(pb); // starttime
577  avio_rl64(pb); // endtime
578  leak_rate = avio_rl32(pb); // leak-datarate
579  avio_rl32(pb); // bucket-datasize
580  avio_rl32(pb); // init-bucket-fullness
581  avio_rl32(pb); // alt-leak-datarate
582  avio_rl32(pb); // alt-bucket-datasize
583  avio_rl32(pb); // alt-init-bucket-fullness
584  avio_rl32(pb); // max-object-size
585  avio_rl32(pb); // flags (reliable,seekable,no_cleanpoints?,resend-live-cleanpoints, rest of bits reserved)
586  stream_num = avio_rl16(pb); // stream-num
587 
588  stream_languageid_index = avio_rl16(pb); // stream-language-id-index
589  if (stream_num < 128)
590  asf->streams[stream_num].stream_language_index = stream_languageid_index;
591 
592  avio_rl64(pb); // avg frametime in 100ns units
593  stream_ct = avio_rl16(pb); // stream-name-count
594  payload_ext_ct = avio_rl16(pb); // payload-extension-system-count
595 
596  if (stream_num < 128) {
597  asf->stream_bitrates[stream_num] = leak_rate;
598  asf->streams[stream_num].payload_ext_ct = 0;
599  }
600 
601  for (i = 0; i < stream_ct; i++) {
602  avio_rl16(pb);
603  ext_len = avio_rl16(pb);
604  avio_skip(pb, ext_len);
605  }
606 
607  for (i = 0; i < payload_ext_ct; i++) {
608  int size;
609  ff_get_guid(pb, &g);
610  size = avio_rl16(pb);
611  ext_len = avio_rl32(pb);
612  if (ext_len < 0)
613  return AVERROR_INVALIDDATA;
614  avio_skip(pb, ext_len);
615  if (stream_num < 128 && i < FF_ARRAY_ELEMS(asf->streams[stream_num].payload)) {
616  ASFPayload *p = &asf->streams[stream_num].payload[i];
617  p->type = g[0];
618  p->size = size;
619  av_log(s, AV_LOG_DEBUG, "Payload extension %x %d\n", g[0], p->size );
620  asf->streams[stream_num].payload_ext_ct ++;
621  }
622  }
623 
624  return 0;
625 }
626 
628 {
629  AVIOContext *pb = s->pb;
630  int len1, len2, len3, len4, len5;
631 
632  len1 = avio_rl16(pb);
633  len2 = avio_rl16(pb);
634  len3 = avio_rl16(pb);
635  len4 = avio_rl16(pb);
636  len5 = avio_rl16(pb);
637  get_tag(s, "title", 0, len1, 32);
638  get_tag(s, "author", 0, len2, 32);
639  get_tag(s, "copyright", 0, len3, 32);
640  get_tag(s, "comment", 0, len4, 32);
641  avio_skip(pb, len5);
642 
643  return 0;
644 }
645 
647 {
648  AVIOContext *pb = s->pb;
649  ASFContext *asf = s->priv_data;
650  int desc_count, i, ret;
651 
652  desc_count = avio_rl16(pb);
653  for (i = 0; i < desc_count; i++) {
654  int name_len, value_type, value_len;
655  char name[1024];
656 
657  name_len = avio_rl16(pb);
658  if (name_len % 2) // must be even, broken lavf versions wrote len-1
659  name_len += 1;
660  if ((ret = avio_get_str16le(pb, name_len, name, sizeof(name))) < name_len)
661  avio_skip(pb, name_len - ret);
662  value_type = avio_rl16(pb);
663  value_len = avio_rl16(pb);
664  if (!value_type && value_len % 2)
665  value_len += 1;
666  /* My sample has that stream set to 0 maybe that mean the container.
667  * ASF stream count starts at 1. I am using 0 to the container value
668  * since it's unused. */
669  if (!strcmp(name, "AspectRatioX"))
670  asf->dar[0].num = get_value(s->pb, value_type, 32);
671  else if (!strcmp(name, "AspectRatioY"))
672  asf->dar[0].den = get_value(s->pb, value_type, 32);
673  else
674  get_tag(s, name, value_type, value_len, 32);
675  }
676 
677  return 0;
678 }
679 
681 {
682  AVIOContext *pb = s->pb;
683  ASFContext *asf = s->priv_data;
684  int j, ret;
685  int stream_count = avio_rl16(pb);
686  for (j = 0; j < stream_count; j++) {
687  char lang[6];
688  unsigned int lang_len = avio_r8(pb);
689  if ((ret = avio_get_str16le(pb, lang_len, lang,
690  sizeof(lang))) < lang_len)
691  avio_skip(pb, lang_len - ret);
692  if (j < 128)
693  av_strlcpy(asf->stream_languages[j], lang,
694  sizeof(*asf->stream_languages));
695  }
696 
697  return 0;
698 }
699 
701 {
702  AVIOContext *pb = s->pb;
703  ASFContext *asf = s->priv_data;
704  int n, stream_num, name_len_utf16, name_len_utf8, value_len;
705  int ret, i;
706  n = avio_rl16(pb);
707 
708  for (i = 0; i < n; i++) {
709  uint8_t *name;
710  int value_type;
711 
712  avio_rl16(pb); // lang_list_index
713  stream_num = avio_rl16(pb);
714  name_len_utf16 = avio_rl16(pb);
715  value_type = avio_rl16(pb); /* value_type */
716  value_len = avio_rl32(pb);
717 
718  if (value_len < 0 || value_len > UINT16_MAX)
719  return AVERROR_INVALIDDATA;
720 
721  name_len_utf8 = 2*name_len_utf16 + 1;
722  name = av_malloc(name_len_utf8);
723  if (!name)
724  return AVERROR(ENOMEM);
725 
726  if ((ret = avio_get_str16le(pb, name_len_utf16, name, name_len_utf8)) < name_len_utf16)
727  avio_skip(pb, name_len_utf16 - ret);
728  av_log(s, AV_LOG_TRACE, "%d stream %d name_len %2d type %d len %4d <%s>\n",
729  i, stream_num, name_len_utf16, value_type, value_len, name);
730 
731  if (!strcmp(name, "AspectRatioX")){
732  int aspect_x = get_value(s->pb, value_type, 16);
733  if(stream_num < 128)
734  asf->dar[stream_num].num = aspect_x;
735  } else if(!strcmp(name, "AspectRatioY")){
736  int aspect_y = get_value(s->pb, value_type, 16);
737  if(stream_num < 128)
738  asf->dar[stream_num].den = aspect_y;
739  } else {
740  get_tag(s, name, value_type, value_len, 16);
741  }
742  av_freep(&name);
743  }
744 
745  return 0;
746 }
747 
748 static int asf_read_marker(AVFormatContext *s, int64_t size)
749 {
750  AVIOContext *pb = s->pb;
751  ASFContext *asf = s->priv_data;
752  int i, count, name_len, ret;
753  char name[1024];
754 
755  avio_rl64(pb); // reserved 16 bytes
756  avio_rl64(pb); // ...
757  count = avio_rl32(pb); // markers count
758  avio_rl16(pb); // reserved 2 bytes
759  name_len = avio_rl16(pb); // name length
760  avio_skip(pb, name_len);
761 
762  for (i = 0; i < count; i++) {
763  int64_t pres_time;
764  int name_len;
765 
766  if (avio_feof(pb))
767  return AVERROR_INVALIDDATA;
768 
769  avio_rl64(pb); // offset, 8 bytes
770  pres_time = avio_rl64(pb); // presentation time
771  pres_time -= asf->hdr.preroll * 10000;
772  avio_rl16(pb); // entry length
773  avio_rl32(pb); // send time
774  avio_rl32(pb); // flags
775  name_len = avio_rl32(pb); // name length
776  if ((unsigned)name_len > INT_MAX / 2)
777  return AVERROR_INVALIDDATA;
778  if ((ret = avio_get_str16le(pb, name_len * 2, name,
779  sizeof(name))) < name_len)
780  avio_skip(pb, name_len - ret);
781  avpriv_new_chapter(s, i, (AVRational) { 1, 10000000 }, pres_time,
783  }
784 
785  return 0;
786 }
787 
789 {
790  ASFContext *asf = s->priv_data;
791  ff_asf_guid g;
792  AVIOContext *pb = s->pb;
793  int i;
794  int64_t gsize;
795 
796  ff_get_guid(pb, &g);
797  if (ff_guidcmp(&g, &ff_asf_header))
798  return AVERROR_INVALIDDATA;
799  avio_rl64(pb);
800  avio_rl32(pb);
801  avio_r8(pb);
802  avio_r8(pb);
803  memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid));
804 
805  for (i = 0; i<128; i++)
806  asf->streams[i].stream_language_index = 128; // invalid stream index means no language info
807 
808  for (;;) {
809  uint64_t gpos = avio_tell(pb);
810  int ret = 0;
811  ff_get_guid(pb, &g);
812  gsize = avio_rl64(pb);
813  print_guid(&g);
814  if (!ff_guidcmp(&g, &ff_asf_data_header)) {
815  asf->data_object_offset = avio_tell(pb);
816  /* If not streaming, gsize is not unlimited (how?),
817  * and there is enough space in the file.. */
818  if (!(asf->hdr.flags & 0x01) && gsize >= 100)
819  asf->data_object_size = gsize - 24;
820  else
821  asf->data_object_size = (uint64_t)-1;
822  break;
823  }
824  if (gsize < 24)
825  return AVERROR_INVALIDDATA;
826  if (!ff_guidcmp(&g, &ff_asf_file_header)) {
827  ret = asf_read_file_properties(s, gsize);
828  } else if (!ff_guidcmp(&g, &ff_asf_stream_header)) {
829  ret = asf_read_stream_properties(s, gsize);
830  } else if (!ff_guidcmp(&g, &ff_asf_comment_header)) {
831  asf_read_content_desc(s, gsize);
832  } else if (!ff_guidcmp(&g, &ff_asf_language_guid)) {
833  asf_read_language_list(s, gsize);
834  } else if (!ff_guidcmp(&g, &ff_asf_extended_content_header)) {
836  } else if (!ff_guidcmp(&g, &ff_asf_metadata_header)) {
837  asf_read_metadata(s, gsize);
838  } else if (!ff_guidcmp(&g, &ff_asf_metadata_library_header)) {
839  asf_read_metadata(s, gsize);
840  } else if (!ff_guidcmp(&g, &ff_asf_ext_stream_header)) {
842 
843  // there could be an optional stream properties object to follow
844  // if so the next iteration will pick it up
845  continue;
846  } else if (!ff_guidcmp(&g, &ff_asf_head1_guid)) {
847  ff_get_guid(pb, &g);
848  avio_skip(pb, 6);
849  continue;
850  } else if (!ff_guidcmp(&g, &ff_asf_marker_header)) {
851  asf_read_marker(s, gsize);
852  } else if (avio_feof(pb)) {
853  return AVERROR_EOF;
854  } else {
855  if (!s->keylen) {
857  unsigned int len;
858  AVPacket pkt;
860  "DRM protected stream detected, decoding will likely fail!\n");
861  len= avio_rl32(pb);
862  av_log(s, AV_LOG_DEBUG, "Secret data:\n");
863 
864  if ((ret = av_get_packet(pb, &pkt, len)) < 0)
865  return ret;
868 
869  len= avio_rl32(pb);
870  if (len > UINT16_MAX)
871  return AVERROR_INVALIDDATA;
872  get_tag(s, "ASF_Protection_Type", -1, len, 32);
873 
874  len= avio_rl32(pb);
875  if (len > UINT16_MAX)
876  return AVERROR_INVALIDDATA;
877  get_tag(s, "ASF_Key_ID", -1, len, 32);
878 
879  len= avio_rl32(pb);
880  if (len > UINT16_MAX)
881  return AVERROR_INVALIDDATA;
882  get_tag(s, "ASF_License_URL", -1, len, 32);
883  } else if (!ff_guidcmp(&g, &ff_asf_ext_content_encryption)) {
885  "Ext DRM protected stream detected, decoding will likely fail!\n");
886  av_dict_set(&s->metadata, "encryption", "ASF Extended Content Encryption", 0);
887  } else if (!ff_guidcmp(&g, &ff_asf_digital_signature)) {
888  av_log(s, AV_LOG_INFO, "Digital signature detected!\n");
889  }
890  }
891  }
892  if (ret < 0)
893  return ret;
894 
895  if (avio_tell(pb) != gpos + gsize)
897  "gpos mismatch our pos=%"PRIu64", end=%"PRId64"\n",
898  avio_tell(pb) - gpos, gsize);
899  avio_seek(pb, gpos + gsize, SEEK_SET);
900  }
901  ff_get_guid(pb, &g);
902  avio_rl64(pb);
903  avio_r8(pb);
904  avio_r8(pb);
905  if (avio_feof(pb))
906  return AVERROR_EOF;
907  asf->data_offset = avio_tell(pb);
908  asf->packet_size_left = 0;
909 
910  for (i = 0; i < 128; i++) {
911  int stream_num = asf->asfid2avid[i];
912  if (stream_num >= 0) {
913  AVStream *st = s->streams[stream_num];
914  if (!st->codecpar->bit_rate)
915  st->codecpar->bit_rate = asf->stream_bitrates[i];
916  if (asf->dar[i].num > 0 && asf->dar[i].den > 0) {
919  asf->dar[i].num, asf->dar[i].den, INT_MAX);
920  } else if ((asf->dar[0].num > 0) && (asf->dar[0].den > 0) &&
921  // Use ASF container value if the stream doesn't set AR.
925  asf->dar[0].num, asf->dar[0].den, INT_MAX);
926 
927  av_log(s, AV_LOG_TRACE, "i=%d, st->codecpar->codec_type:%d, asf->dar %d:%d sar=%d:%d\n",
928  i, st->codecpar->codec_type, asf->dar[i].num, asf->dar[i].den,
930 
931  // copy and convert language codes to the frontend
932  if (asf->streams[i].stream_language_index < 128) {
933  const char *rfc1766 = asf->stream_languages[asf->streams[i].stream_language_index];
934  if (rfc1766 && strlen(rfc1766) > 1) {
935  const char primary_tag[3] = { rfc1766[0], rfc1766[1], '\0' }; // ignore country code if any
936  const char *iso6392 = ff_convert_lang_to(primary_tag,
938  if (iso6392)
939  av_dict_set(&st->metadata, "language", iso6392, 0);
940  }
941  }
942  }
943  }
944 
946 
947  return 0;
948 }
949 
950 #define DO_2BITS(bits, var, defval) \
951  switch (bits & 3) { \
952  case 3: \
953  var = avio_rl32(pb); \
954  rsize += 4; \
955  break; \
956  case 2: \
957  var = avio_rl16(pb); \
958  rsize += 2; \
959  break; \
960  case 1: \
961  var = avio_r8(pb); \
962  rsize++; \
963  break; \
964  default: \
965  var = defval; \
966  break; \
967  }
968 
969 /**
970  * Load a single ASF packet into the demuxer.
971  * @param s demux context
972  * @param pb context to read data from
973  * @return 0 on success, <0 on error
974  */
976 {
977  ASFContext *asf = s->priv_data;
978  uint32_t packet_length, padsize;
979  int rsize = 8;
980  int c, d, e, off;
981 
982  if (asf->uses_std_ecc > 0) {
983  // if we do not know packet size, allow skipping up to 32 kB
984  off = 32768;
985  if (asf->no_resync_search)
986  off = 3;
987 // else if (s->packet_size > 0 && !asf->uses_std_ecc)
988 // off = (avio_tell(pb) - s->internal->data_offset) % s->packet_size + 3;
989 
990  c = d = e = -1;
991  while (off-- > 0) {
992  c = d;
993  d = e;
994  e = avio_r8(pb);
995  if (c == 0x82 && !d && !e)
996  break;
997  }
998 
999  if (c != 0x82) {
1000  /* This code allows handling of -EAGAIN at packet boundaries (i.e.
1001  * if the packet sync code above triggers -EAGAIN). This does not
1002  * imply complete -EAGAIN handling support at random positions in
1003  * the stream. */
1004  if (pb->error == AVERROR(EAGAIN))
1005  return AVERROR(EAGAIN);
1006  if (!avio_feof(pb))
1008  "ff asf bad header %x at:%"PRId64"\n", c, avio_tell(pb));
1009  }
1010  if ((c & 0x8f) == 0x82) {
1011  if (d || e) {
1012  if (!avio_feof(pb))
1013  av_log(s, AV_LOG_ERROR, "ff asf bad non zero\n");
1014  return AVERROR_INVALIDDATA;
1015  }
1016  c = avio_r8(pb);
1017  d = avio_r8(pb);
1018  rsize += 3;
1019  } else if(!avio_feof(pb)) {
1020  avio_seek(pb, -1, SEEK_CUR); // FIXME
1021  }
1022  } else {
1023  c = avio_r8(pb);
1024  if (c & 0x80) {
1025  rsize ++;
1026  if (!(c & 0x60)) {
1027  d = avio_r8(pb);
1028  e = avio_r8(pb);
1029  avio_seek(pb, (c & 0xF) - 2, SEEK_CUR);
1030  rsize += c & 0xF;
1031  }
1032 
1033  if (c != 0x82)
1034  avpriv_request_sample(s, "Invalid ECC byte");
1035 
1036  if (!asf->uses_std_ecc)
1037  asf->uses_std_ecc = (c == 0x82 && !d && !e) ? 1 : -1;
1038 
1039  c = avio_r8(pb);
1040  } else
1041  asf->uses_std_ecc = -1;
1042  d = avio_r8(pb);
1043  }
1044 
1045  asf->packet_flags = c;
1046  asf->packet_property = d;
1047 
1048  DO_2BITS(asf->packet_flags >> 5, packet_length, s->packet_size);
1049  DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence ignored
1050  DO_2BITS(asf->packet_flags >> 3, padsize, 0); // padding length
1051 
1052  // the following checks prevent overflows and infinite loops
1053  if (!packet_length || packet_length >= (1U << 29)) {
1055  "invalid packet_length %"PRIu32" at:%"PRId64"\n",
1056  packet_length, avio_tell(pb));
1057  return AVERROR_INVALIDDATA;
1058  }
1059  if (padsize >= packet_length) {
1061  "invalid padsize %"PRIu32" at:%"PRId64"\n", padsize, avio_tell(pb));
1062  return AVERROR_INVALIDDATA;
1063  }
1064 
1065  asf->packet_timestamp = avio_rl32(pb);
1066  avio_rl16(pb); /* duration */
1067  // rsize has at least 11 bytes which have to be present
1068 
1069  if (asf->packet_flags & 0x01) {
1070  asf->packet_segsizetype = avio_r8(pb);
1071  rsize++;
1072  asf->packet_segments = asf->packet_segsizetype & 0x3f;
1073  } else {
1074  asf->packet_segments = 1;
1075  asf->packet_segsizetype = 0x80;
1076  }
1077  if (rsize > packet_length - padsize) {
1078  asf->packet_size_left = 0;
1080  "invalid packet header length %d for pktlen %"PRIu32"-%"PRIu32" at %"PRId64"\n",
1081  rsize, packet_length, padsize, avio_tell(pb));
1082  return AVERROR_INVALIDDATA;
1083  }
1084  asf->packet_size_left = packet_length - padsize - rsize;
1085  if (packet_length < asf->hdr.min_pktsize)
1086  padsize += asf->hdr.min_pktsize - packet_length;
1087  asf->packet_padsize = padsize;
1088  av_log(s, AV_LOG_TRACE, "packet: size=%d padsize=%d left=%d\n",
1089  s->packet_size, asf->packet_padsize, asf->packet_size_left);
1090  return 0;
1091 }
1092 
1093 /**
1094  *
1095  * @return <0 if error
1096  */
1098 {
1099  ASFContext *asf = s->priv_data;
1100  ASFStream *asfst;
1101  int rsize = 1;
1102  int num = avio_r8(pb);
1103  int i;
1104  int64_t ts0, ts1 av_unused;
1105 
1106  asf->packet_segments--;
1107  asf->packet_key_frame = num >> 7;
1108  asf->stream_index = asf->asfid2avid[num & 0x7f];
1109  asfst = &asf->streams[num & 0x7f];
1110  // sequence should be ignored!
1111  DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
1112  DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
1114  av_log(asf, AV_LOG_TRACE, "key:%d stream:%d seq:%d offset:%d replic_size:%d num:%X packet_property %X\n",
1115  asf->packet_key_frame, asf->stream_index, asf->packet_seq,
1116  asf->packet_frag_offset, asf->packet_replic_size, num, asf->packet_property);
1117  if (rsize+(int64_t)asf->packet_replic_size > asf->packet_size_left) {
1118  av_log(s, AV_LOG_ERROR, "packet_replic_size %d is invalid\n", asf->packet_replic_size);
1119  return AVERROR_INVALIDDATA;
1120  }
1121  if (asf->packet_replic_size >= 8) {
1122  int64_t end = avio_tell(pb) + asf->packet_replic_size;
1123  AVRational aspect;
1124  asfst->packet_obj_size = avio_rl32(pb);
1125  if (asfst->packet_obj_size >= (1 << 24) || asfst->packet_obj_size < 0) {
1126  av_log(s, AV_LOG_ERROR, "packet_obj_size %d invalid\n", asfst->packet_obj_size);
1127  asfst->packet_obj_size = 0;
1128  return AVERROR_INVALIDDATA;
1129  }
1130  asf->packet_frag_timestamp = avio_rl32(pb); // timestamp
1131 
1132  for (i = 0; i < asfst->payload_ext_ct; i++) {
1133  ASFPayload *p = &asfst->payload[i];
1134  int size = p->size;
1135  int64_t payend;
1136  if (size == 0xFFFF)
1137  size = avio_rl16(pb);
1138  payend = avio_tell(pb) + size;
1139  if (payend > end) {
1140  av_log(s, AV_LOG_ERROR, "too long payload\n");
1141  break;
1142  }
1143  switch (p->type) {
1144  case 0x50:
1145 // duration = avio_rl16(pb);
1146  break;
1147  case 0x54:
1148  aspect.num = avio_r8(pb);
1149  aspect.den = avio_r8(pb);
1150  if (aspect.num > 0 && aspect.den > 0 && asf->stream_index >= 0) {
1151  s->streams[asf->stream_index]->sample_aspect_ratio = aspect;
1152  }
1153  break;
1154  case 0x2A:
1155  avio_skip(pb, 8);
1156  ts0 = avio_rl64(pb);
1157  ts1 = avio_rl64(pb);
1158  if (ts0!= -1) asf->packet_frag_timestamp = ts0/10000;
1160  asf->ts_is_pts = 1;
1161  break;
1162  case 0x5B:
1163  case 0xB7:
1164  case 0xCC:
1165  case 0xC0:
1166  case 0xA0:
1167  //unknown
1168  break;
1169  }
1170  avio_seek(pb, payend, SEEK_SET);
1171  }
1172 
1173  avio_seek(pb, end, SEEK_SET);
1174  rsize += asf->packet_replic_size; // FIXME - check validity
1175  } else if (asf->packet_replic_size == 1) {
1176  // multipacket - frag_offset is beginning timestamp
1178  asf->packet_frag_offset = 0;
1180 
1181  asf->packet_time_delta = avio_r8(pb);
1182  rsize++;
1183  } else if (asf->packet_replic_size != 0) {
1184  av_log(s, AV_LOG_ERROR, "unexpected packet_replic_size of %d\n",
1185  asf->packet_replic_size);
1186  return AVERROR_INVALIDDATA;
1187  }
1188  if (asf->packet_flags & 0x01) {
1189  DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
1190  if (rsize > asf->packet_size_left) {
1191  av_log(s, AV_LOG_ERROR, "packet_replic_size is invalid\n");
1192  return AVERROR_INVALIDDATA;
1193  } else if (asf->packet_frag_size > asf->packet_size_left - rsize) {
1194  if (asf->packet_frag_size > asf->packet_size_left - rsize + asf->packet_padsize) {
1195  av_log(s, AV_LOG_ERROR, "packet_frag_size is invalid (%d>%d-%d+%d)\n",
1196  asf->packet_frag_size, asf->packet_size_left, rsize, asf->packet_padsize);
1197  return AVERROR_INVALIDDATA;
1198  } else {
1199  int diff = asf->packet_frag_size - (asf->packet_size_left - rsize);
1200  asf->packet_size_left += diff;
1201  asf->packet_padsize -= diff;
1202  }
1203  }
1204  } else {
1205  asf->packet_frag_size = asf->packet_size_left - rsize;
1206  }
1207  if (asf->packet_replic_size == 1) {
1208  asf->packet_multi_size = asf->packet_frag_size;
1209  if (asf->packet_multi_size > asf->packet_size_left)
1210  return AVERROR_INVALIDDATA;
1211  }
1212  asf->packet_size_left -= rsize;
1213 
1214  return 0;
1215 }
1216 
1217 /**
1218  * Parse data from individual ASF packets (which were previously loaded
1219  * with asf_get_packet()).
1220  * @param s demux context
1221  * @param pb context to read data from
1222  * @param pkt pointer to store packet data into
1223  * @return 0 if data was stored in pkt, <0 on error or 1 if more ASF
1224  * packets need to be loaded (through asf_get_packet())
1225  */
1227 {
1228  ASFContext *asf = s->priv_data;
1229  ASFStream *asf_st = 0;
1230  for (;;) {
1231  int ret;
1232  if (avio_feof(pb))
1233  return AVERROR_EOF;
1234  if (asf->packet_size_left < FRAME_HEADER_SIZE ||
1235  asf->packet_segments < 1 && asf->packet_time_start == 0) {
1236  int ret = asf->packet_size_left + asf->packet_padsize;
1237 
1239  av_log(s, AV_LOG_WARNING, "Skip due to FRAME_HEADER_SIZE\n");
1240 
1241  assert(ret >= 0);
1242  /* fail safe */
1243  avio_skip(pb, ret);
1244 
1245  asf->packet_pos = avio_tell(pb);
1246  if (asf->data_object_size != (uint64_t)-1 &&
1247  (asf->packet_pos - asf->data_object_offset >= asf->data_object_size))
1248  return AVERROR_EOF; /* Do not exceed the size of the data object */
1249  return 1;
1250  }
1251  if (asf->packet_time_start == 0) {
1252  if (asf_read_frame_header(s, pb) < 0) {
1253  asf->packet_time_start = asf->packet_segments = 0;
1254  continue;
1255  }
1256  if (asf->stream_index < 0 ||
1257  s->streams[asf->stream_index]->discard >= AVDISCARD_ALL ||
1258  (!asf->packet_key_frame &&
1259  (s->streams[asf->stream_index]->discard >= AVDISCARD_NONKEY || asf->streams[s->streams[asf->stream_index]->id].skip_to_key))) {
1260  asf->packet_time_start = 0;
1261  /* unhandled packet (should not happen) */
1262  avio_skip(pb, asf->packet_frag_size);
1263  asf->packet_size_left -= asf->packet_frag_size;
1264  if (asf->stream_index < 0)
1265  av_log(s, AV_LOG_ERROR, "ff asf skip %d (unknown stream)\n",
1266  asf->packet_frag_size);
1267  continue;
1268  }
1269  asf->asf_st = &asf->streams[s->streams[asf->stream_index]->id];
1270  if (!asf->packet_frag_offset)
1271  asf->asf_st->skip_to_key = 0;
1272  }
1273  asf_st = asf->asf_st;
1274  av_assert0(asf_st);
1275 
1276  if (!asf_st->frag_offset && asf->packet_frag_offset) {
1277  av_log(s, AV_LOG_TRACE, "skipping asf data pkt with fragment offset for "
1278  "stream:%d, expected:%d but got %d from pkt)\n",
1279  asf->stream_index, asf_st->frag_offset,
1280  asf->packet_frag_offset);
1281  avio_skip(pb, asf->packet_frag_size);
1282  asf->packet_size_left -= asf->packet_frag_size;
1283  continue;
1284  }
1285 
1286  if (asf->packet_replic_size == 1) {
1287  // frag_offset is here used as the beginning timestamp
1289  asf->packet_time_start += asf->packet_time_delta;
1290  asf_st->packet_obj_size = asf->packet_frag_size = avio_r8(pb);
1291  asf->packet_size_left--;
1292  asf->packet_multi_size--;
1293  if (asf->packet_multi_size < asf_st->packet_obj_size) {
1294  asf->packet_time_start = 0;
1295  avio_skip(pb, asf->packet_multi_size);
1296  asf->packet_size_left -= asf->packet_multi_size;
1297  continue;
1298  }
1299  asf->packet_multi_size -= asf_st->packet_obj_size;
1300  }
1301 
1302  if (asf_st->pkt.size != asf_st->packet_obj_size ||
1303  // FIXME is this condition sufficient?
1304  asf_st->frag_offset + asf->packet_frag_size > asf_st->pkt.size) {
1305  int ret;
1306 
1307  if (asf_st->pkt.data) {
1308  av_log(s, AV_LOG_INFO,
1309  "freeing incomplete packet size %d, new %d\n",
1310  asf_st->pkt.size, asf_st->packet_obj_size);
1311  asf_st->frag_offset = 0;
1312  av_packet_unref(&asf_st->pkt);
1313  }
1314  /* new packet */
1315  if ((ret = av_new_packet(&asf_st->pkt, asf_st->packet_obj_size)) < 0)
1316  return ret;
1317  asf_st->seq = asf->packet_seq;
1318  if (asf->ts_is_pts) {
1319  asf_st->pkt.pts = asf->packet_frag_timestamp - asf->hdr.preroll;
1320  } else
1321  asf_st->pkt.dts = asf->packet_frag_timestamp - asf->hdr.preroll;
1322  asf_st->pkt.stream_index = asf->stream_index;
1323  asf_st->pkt.pos = asf_st->packet_pos = asf->packet_pos;
1324  asf_st->pkt_clean = 0;
1325 
1326  if (asf_st->pkt.data && asf_st->palette_changed) {
1327  uint8_t *pal;
1329  AVPALETTE_SIZE);
1330  if (!pal) {
1331  av_log(s, AV_LOG_ERROR, "Cannot append palette to packet\n");
1332  } else {
1333  memcpy(pal, asf_st->palette, AVPALETTE_SIZE);
1334  asf_st->palette_changed = 0;
1335  }
1336  }
1337  av_log(asf, AV_LOG_TRACE, "new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n",
1338  asf->stream_index, asf->packet_key_frame,
1339  asf_st->pkt.flags & AV_PKT_FLAG_KEY,
1340  s->streams[asf->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO,
1341  asf_st->packet_obj_size);
1342  if (s->streams[asf->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
1343  asf->packet_key_frame = 1;
1344  if (asf->packet_key_frame)
1345  asf_st->pkt.flags |= AV_PKT_FLAG_KEY;
1346  }
1347 
1348  /* read data */
1349  av_log(asf, AV_LOG_TRACE, "READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n",
1350  s->packet_size, asf_st->pkt.size, asf->packet_frag_offset,
1351  asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data);
1352  asf->packet_size_left -= asf->packet_frag_size;
1353  if (asf->packet_size_left < 0)
1354  continue;
1355 
1356  if (asf->packet_frag_offset >= asf_st->pkt.size ||
1357  asf->packet_frag_size > asf_st->pkt.size - asf->packet_frag_offset) {
1359  "packet fragment position invalid %u,%u not in %u\n",
1361  asf_st->pkt.size);
1362  continue;
1363  }
1364 
1365  if (asf->packet_frag_offset != asf_st->frag_offset && !asf_st->pkt_clean) {
1366  memset(asf_st->pkt.data + asf_st->frag_offset, 0, asf_st->pkt.size - asf_st->frag_offset);
1367  asf_st->pkt_clean = 1;
1368  }
1369 
1370  ret = avio_read(pb, asf_st->pkt.data + asf->packet_frag_offset,
1371  asf->packet_frag_size);
1372  if (ret != asf->packet_frag_size) {
1373  if (ret < 0 || asf->packet_frag_offset + ret == 0)
1374  return ret < 0 ? ret : AVERROR_EOF;
1375 
1376  if (asf_st->ds_span > 1) {
1377  // scrambling, we can either drop it completely or fill the remainder
1378  // TODO: should we fill the whole packet instead of just the current
1379  // fragment?
1380  memset(asf_st->pkt.data + asf->packet_frag_offset + ret, 0,
1381  asf->packet_frag_size - ret);
1382  ret = asf->packet_frag_size;
1383  } else {
1384  // no scrambling, so we can return partial packets
1385  av_shrink_packet(&asf_st->pkt, asf->packet_frag_offset + ret);
1386  }
1387  }
1388  if (s->key && s->keylen == 20)
1389  ff_asfcrypt_dec(s->key, asf_st->pkt.data + asf->packet_frag_offset,
1390  ret);
1391  asf_st->frag_offset += ret;
1392  /* test if whole packet is read */
1393  if (asf_st->frag_offset == asf_st->pkt.size) {
1394  // workaround for macroshit radio DVR-MS files
1395  if (s->streams[asf->stream_index]->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO &&
1396  asf_st->pkt.size > 100) {
1397  int i;
1398  for (i = 0; i < asf_st->pkt.size && !asf_st->pkt.data[i]; i++)
1399  ;
1400  if (i == asf_st->pkt.size) {
1401  av_log(s, AV_LOG_DEBUG, "discarding ms fart\n");
1402  asf_st->frag_offset = 0;
1403  av_packet_unref(&asf_st->pkt);
1404  continue;
1405  }
1406  }
1407 
1408  /* return packet */
1409  if (asf_st->ds_span > 1) {
1410  if (asf_st->pkt.size != asf_st->ds_packet_size * asf_st->ds_span) {
1412  "pkt.size != ds_packet_size * ds_span (%d %d %d)\n",
1413  asf_st->pkt.size, asf_st->ds_packet_size,
1414  asf_st->ds_span);
1415  } else {
1416  /* packet descrambling */
1417  AVBufferRef *buf = av_buffer_alloc(asf_st->pkt.size +
1419  if (buf) {
1420  uint8_t *newdata = buf->data;
1421  int offset = 0;
1422  memset(newdata + asf_st->pkt.size, 0,
1424  while (offset < asf_st->pkt.size) {
1425  int off = offset / asf_st->ds_chunk_size;
1426  int row = off / asf_st->ds_span;
1427  int col = off % asf_st->ds_span;
1428  int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size;
1429  assert(offset + asf_st->ds_chunk_size <= asf_st->pkt.size);
1430  assert(idx + 1 <= asf_st->pkt.size / asf_st->ds_chunk_size);
1431  memcpy(newdata + offset,
1432  asf_st->pkt.data + idx * asf_st->ds_chunk_size,
1433  asf_st->ds_chunk_size);
1434  offset += asf_st->ds_chunk_size;
1435  }
1436  av_buffer_unref(&asf_st->pkt.buf);
1437  asf_st->pkt.buf = buf;
1438  asf_st->pkt.data = buf->data;
1439  }
1440  }
1441  }
1442  asf_st->frag_offset = 0;
1443  *pkt = asf_st->pkt;
1444  asf_st->pkt.buf = 0;
1445  asf_st->pkt.size = 0;
1446  asf_st->pkt.data = 0;
1447  asf_st->pkt.side_data_elems = 0;
1448  asf_st->pkt.side_data = NULL;
1449  break; // packet completed
1450  }
1451  }
1452  return 0;
1453 }
1454 
1456 {
1457  ASFContext *asf = s->priv_data;
1458 
1459  for (;;) {
1460  int ret;
1461 
1462  /* parse cached packets, if any */
1463  if ((ret = asf_parse_packet(s, s->pb, pkt)) <= 0)
1464  return ret;
1465  if ((ret = asf_get_packet(s, s->pb)) < 0)
1466  assert(asf->packet_size_left < FRAME_HEADER_SIZE ||
1467  asf->packet_segments < 1);
1468  asf->packet_time_start = 0;
1469  }
1470 }
1471 
1472 // Added to support seeking after packets have been read
1473 // If information is not reset, read_packet fails due to
1474 // leftover information from previous reads
1476 {
1477  ASFContext *asf = s->priv_data;
1478  ASFStream *asf_st;
1479  int i;
1480 
1481  asf->packet_size_left = 0;
1482  asf->packet_flags = 0;
1483  asf->packet_property = 0;
1484  asf->packet_timestamp = 0;
1485  asf->packet_segsizetype = 0;
1486  asf->packet_segments = 0;
1487  asf->packet_seq = 0;
1488  asf->packet_replic_size = 0;
1489  asf->packet_key_frame = 0;
1490  asf->packet_padsize = 0;
1491  asf->packet_frag_offset = 0;
1492  asf->packet_frag_size = 0;
1493  asf->packet_frag_timestamp = 0;
1494  asf->packet_multi_size = 0;
1495  asf->packet_time_delta = 0;
1496  asf->packet_time_start = 0;
1497 
1498  for (i = 0; i < 128; i++) {
1499  asf_st = &asf->streams[i];
1500  av_packet_unref(&asf_st->pkt);
1501  asf_st->packet_obj_size = 0;
1502  asf_st->frag_offset = 0;
1503  asf_st->seq = 0;
1504  }
1505  asf->asf_st = NULL;
1506 }
1507 
1509 {
1510  ASFContext *asf = s->priv_data;
1511  int i;
1512 
1513  for (i = 0; i < 128; i++) {
1514  int j = asf->asfid2avid[i];
1515  ASFStream *asf_st = &asf->streams[i];
1516  if (j < 0 || s->streams[j]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO)
1517  continue;
1518 
1519  asf_st->skip_to_key = 1;
1520  }
1521 }
1522 
1524 {
1526 
1527  return 0;
1528 }
1529 
1530 static int64_t asf_read_pts(AVFormatContext *s, int stream_index,
1531  int64_t *ppos, int64_t pos_limit)
1532 {
1533  ASFContext *asf = s->priv_data;
1534  AVPacket pkt1, *pkt = &pkt1;
1535  ASFStream *asf_st;
1536  int64_t pts;
1537  int64_t pos = *ppos;
1538  int i;
1539  int64_t start_pos[ASF_MAX_STREAMS];
1540 
1541  for (i = 0; i < s->nb_streams; i++)
1542  start_pos[i] = pos;
1543 
1544  if (s->packet_size > 0)
1545  pos = (pos + s->packet_size - 1 - s->internal->data_offset) /
1546  s->packet_size * s->packet_size +
1547  s->internal->data_offset;
1548  *ppos = pos;
1549  if (avio_seek(s->pb, pos, SEEK_SET) < 0)
1550  return AV_NOPTS_VALUE;
1551 
1554  for (;;) {
1555  if (av_read_frame(s, pkt) < 0) {
1556  av_log(s, AV_LOG_INFO, "asf_read_pts failed\n");
1557  return AV_NOPTS_VALUE;
1558  }
1559 
1560  pts = pkt->dts;
1561 
1562  if (pkt->flags & AV_PKT_FLAG_KEY) {
1563  i = pkt->stream_index;
1564 
1565  asf_st = &asf->streams[s->streams[i]->id];
1566 
1567 // assert((asf_st->packet_pos - s->data_offset) % s->packet_size == 0);
1568  pos = asf_st->packet_pos;
1569  av_assert1(pkt->pos == asf_st->packet_pos);
1570 
1571  av_add_index_entry(s->streams[i], pos, pts, pkt->size,
1572  pos - start_pos[i] + 1, AVINDEX_KEYFRAME);
1573  start_pos[i] = asf_st->packet_pos + 1;
1574 
1575  if (pkt->stream_index == stream_index) {
1577  break;
1578  }
1579  }
1581  }
1582 
1583  *ppos = pos;
1584  return pts;
1585 }
1586 
1587 static int asf_build_simple_index(AVFormatContext *s, int stream_index)
1588 {
1589  ff_asf_guid g;
1590  ASFContext *asf = s->priv_data;
1591  int64_t current_pos = avio_tell(s->pb);
1592  int64_t ret;
1593 
1594  if((ret = avio_seek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET)) < 0) {
1595  return ret;
1596  }
1597 
1598  if ((ret = ff_get_guid(s->pb, &g)) < 0)
1599  goto end;
1600 
1601  /* the data object can be followed by other top-level objects,
1602  * skip them until the simple index object is reached */
1604  int64_t gsize = avio_rl64(s->pb);
1605  if (gsize < 24 || avio_feof(s->pb)) {
1606  goto end;
1607  }
1608  avio_skip(s->pb, gsize - 24);
1609  if ((ret = ff_get_guid(s->pb, &g)) < 0)
1610  goto end;
1611  }
1612 
1613  {
1614  int64_t itime, last_pos = -1;
1615  int pct, ict;
1616  int i;
1617  int64_t av_unused gsize = avio_rl64(s->pb);
1618  if ((ret = ff_get_guid(s->pb, &g)) < 0)
1619  goto end;
1620  itime = avio_rl64(s->pb);
1621  pct = avio_rl32(s->pb);
1622  ict = avio_rl32(s->pb);
1624  "itime:0x%"PRIx64", pct:%d, ict:%d\n", itime, pct, ict);
1625 
1626  for (i = 0; i < ict; i++) {
1627  int pktnum = avio_rl32(s->pb);
1628  int pktct = avio_rl16(s->pb);
1629  int64_t pos = s->internal->data_offset + s->packet_size * (int64_t)pktnum;
1630  int64_t index_pts = FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);
1631 
1632  if (avio_feof(s->pb)) {
1634  goto end;
1635  }
1636 
1637  if (pos != last_pos) {
1638  av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d pts: %"PRId64"\n",
1639  pktnum, pktct, index_pts);
1640  av_add_index_entry(s->streams[stream_index], pos, index_pts,
1641  s->packet_size, 0, AVINDEX_KEYFRAME);
1642  last_pos = pos;
1643  }
1644  }
1645  asf->index_read = ict > 1;
1646  }
1647 end:
1648 // if (avio_feof(s->pb)) {
1649 // ret = 0;
1650 // }
1651  avio_seek(s->pb, current_pos, SEEK_SET);
1652  return ret;
1653 }
1654 
1655 static int asf_read_seek(AVFormatContext *s, int stream_index,
1656  int64_t pts, int flags)
1657 {
1658  ASFContext *asf = s->priv_data;
1659  AVStream *st = s->streams[stream_index];
1660  int ret = 0;
1661 
1662  if (s->packet_size <= 0)
1663  return -1;
1664 
1665  /* Try using the protocol's read_seek if available */
1666  if (s->pb) {
1667  int64_t ret = avio_seek_time(s->pb, stream_index, pts, flags);
1668  if (ret >= 0)
1670  if (ret != AVERROR(ENOSYS))
1671  return ret;
1672  }
1673 
1674  /* explicitly handle the case of seeking to 0 */
1675  if (!pts) {
1677  avio_seek(s->pb, s->internal->data_offset, SEEK_SET);
1678  return 0;
1679  }
1680 
1681  if (!asf->index_read) {
1682  ret = asf_build_simple_index(s, stream_index);
1683  if (ret < 0)
1684  asf->index_read = -1;
1685  }
1686 
1687  if (asf->index_read > 0 && st->index_entries) {
1689  if (index >= 0) {
1690  /* find the position */
1691  uint64_t pos = st->index_entries[index].pos;
1692 
1693  /* do the seek */
1694  av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos);
1695  if(avio_seek(s->pb, pos, SEEK_SET) < 0)
1696  return -1;
1698  skip_to_key(s);
1699  return 0;
1700  }
1701  }
1702  /* no index or seeking by index failed */
1703  if (ff_seek_frame_binary(s, stream_index, pts, flags) < 0)
1704  return -1;
1706  skip_to_key(s);
1707  return 0;
1708 }
1709 
1711  .name = "asf",
1712  .long_name = NULL_IF_CONFIG_SMALL("ASF (Advanced / Active Streaming Format)"),
1713  .priv_data_size = sizeof(ASFContext),
1714  .read_probe = asf_probe,
1719  .read_timestamp = asf_read_pts,
1721  .priv_class = &asf_class,
1722 };
AVStream::index_entries
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: avformat.h:1099
ff_asf_ext_stream_embed_stream_header
const ff_asf_guid ff_asf_ext_stream_embed_stream_header
Definition: asf.c:100
asf_class
static const AVClass asf_class
Definition: asfdec_f.c:126
ff_asf_jfif_media
const ff_asf_guid ff_asf_jfif_media
Definition: asf.c:57
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:599
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3971
ASF_MAX_STREAMS
#define ASF_MAX_STREAMS
Definition: asfdec_f.c:136
av_buffer_alloc
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:67
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
ff_get_guid
int ff_get_guid(AVIOContext *s, ff_asf_guid *g)
Definition: riffdec.c:32
opt.h
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4480
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3953
n
int n
Definition: avisynth_c.h:760
ASF_WORD
@ ASF_WORD
Definition: asf.h:35
ASFMainHeader::send_time
uint64_t send_time
time to send file, in 100-nanosecond units invalid if broadcasting (could be ignored)
Definition: asf.h:47
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:55
MKTAG
#define MKTAG(a, b, c, d)
Definition: common.h:366
AV_DISPOSITION_ATTACHED_PIC
#define AV_DISPOSITION_ATTACHED_PIC
The stream is stored in the file as an attached picture/"cover art" (e.g.
Definition: avformat.h:838
avlanguage.h
ASFContext::packet_segsizetype
int packet_segsizetype
Definition: asfdec_f.c:95
asf_read_content_desc
static int asf_read_content_desc(AVFormatContext *s, int64_t size)
Definition: asfdec_f.c:627
skip_to_key
static void skip_to_key(AVFormatContext *s)
Definition: asfdec_f.c:1508
asf_parse_packet
static int asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt)
Parse data from individual ASF packets (which were previously loaded with asf_get_packet()).
Definition: asfdec_f.c:1226
ASFStream::palette_changed
int palette_changed
Definition: asfdec_f.c:67
count
void INT64 INT64 count
Definition: avisynth_c.h:767
av_unused
#define av_unused
Definition: attributes.h:125
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: avcodec.h:230
id3v2.h
end
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
ASFMainHeader::preroll
uint32_t preroll
timestamp of the first packet, in milliseconds if nonzero - subtract from time
Definition: asf.h:49
name
const char * name
Definition: avisynth_c.h:867
AVPacket::data
uint8_t * data
Definition: avcodec.h:1477
AVOption
AVOption.
Definition: opt.h:246
AV_PKT_DATA_PALETTE
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
Definition: avcodec.h:1190
asf_build_simple_index
static int asf_build_simple_index(AVFormatContext *s, int stream_index)
Definition: asfdec_f.c:1587
ASFStream::skip_to_key
int skip_to_key
Definition: asfdec_f.c:56
LEN
#define LEN
ASF_BOOL
@ ASF_BOOL
Definition: asf.h:32
AVIOContext::error
int error
contains the error code or 0 if no error happened
Definition: avio.h:245
ff_id3v2_read
void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta, unsigned int max_search_size)
Read an ID3v2 tag, including supported extra metadata.
Definition: id3v2.c:1131
asfcrypt.h
ff_asf_video_stream
const ff_asf_guid ff_asf_video_stream
Definition: asf.c:53
ff_asf_simple_index_header
const ff_asf_guid ff_asf_simple_index_header
Definition: asf.c:96
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: avcodec.h:3961
mathematics.h
ASF_UNICODE
@ ASF_UNICODE
Definition: asf.h:30
av_read_frame
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition: utils.c:1785
ff_asf_stream_header
const ff_asf_guid ff_asf_stream_header
Definition: asf.c:31
ASFContext::packet_padsize
int packet_padsize
Definition: asfdec_f.c:100
AVFMT_NOBINSEARCH
#define AVFMT_NOBINSEARCH
Format does not allow to fall back on binary search via read_timestamp.
Definition: avformat.h:473
ff_asf_codec_comment_header
const ff_asf_guid ff_asf_codec_comment_header
Definition: asf.c:73
ASFContext::data_offset
uint64_t data_offset
beginning of the first data packet
Definition: asfdec_f.c:85
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:336
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1509
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
ff_seek_frame_binary
int ff_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags)
Perform a binary search using av_index_search_timestamp() and AVInputFormat.read_timestamp().
Definition: utils.c:2182
AVINDEX_KEYFRAME
#define AVINDEX_KEYFRAME
Definition: avformat.h:808
asf_get_packet
static int asf_get_packet(AVFormatContext *s, AVIOContext *pb)
Load a single ASF packet into the demuxer.
Definition: asfdec_f.c:975
ff_guidcmp
static av_always_inline int ff_guidcmp(const void *g1, const void *g2)
Definition: riff.h:118
ASFContext::packet_frag_size
unsigned int packet_frag_size
Definition: asfdec_f.c:102
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:458
CodecMime
Definition: internal.h:49
ASFContext::stream_index
int stream_index
Definition: asfdec_f.c:110
ff_id3v2_parse_apic
int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta **extra_meta)
Create a stream for each APIC (attached picture) extracted from the ID3v2 header.
Definition: id3v2.c:1153
finish
static void finish(void)
Definition: movenc.c:345
ASFContext::hdr
ASFMainHeader hdr
Definition: asfdec_f.c:90
ASFMainHeader::flags
uint32_t flags
0x01 - broadcast 0x02 - seekable rest is reserved should be 0
Definition: asf.h:52
ASFContext::stream_bitrates
uint32_t stream_bitrates[128]
max number of streams, bitrate for each (for streaming)
Definition: asfdec_f.c:78
U
#define U(x)
Definition: vp56_arith.h:37
ASFContext::streams
ASFStream streams[128]
it's max number and it's not that big
Definition: asfdec_f.c:77
fail
#define fail()
Definition: checkasm.h:120
ASFContext::uses_std_ecc
int uses_std_ecc
Definition: asfdec_f.c:117
avio_seek_time
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:1237
read_seek
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
av_shrink_packet
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition: avpacket.c:101
av_add_index_entry
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
Definition: utils.c:2056
AVSTREAM_PARSE_FULL_ONCE
@ AVSTREAM_PARSE_FULL_ONCE
full parsing and repack of the first frame only, only implemented for H.264 currently
Definition: avformat.h:794
ASFContext::data_object_size
uint64_t data_object_size
size of the data object
Definition: asfdec_f.c:87
read_close
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:557
ASFContext::ts_is_pts
int ts_is_pts
Definition: asfdec_f.c:104
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
pts
static int64_t pts
Definition: transcode_aac.c:647
ASF_GUID
@ ASF_GUID
Definition: asf.h:36
asf_read_ext_content_desc
static int asf_read_ext_content_desc(AVFormatContext *s, int64_t size)
Definition: asfdec_f.c:646
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:919
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
avio_rl16
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:753
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVStream::attached_pic
AVPacket attached_pic
For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet will contain the attached pictu...
Definition: avformat.h:952
ASFMainHeader::create_time
uint64_t create_time
time of creation, in 100-nanosecond units since 1.1.1601 invalid if broadcasting
Definition: asf.h:43
AV_DICT_DONT_STRDUP_VAL
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
Definition: dict.h:74
av_bswap32
#define av_bswap32
Definition: bswap.h:33
asf_read_stream_properties
static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
Definition: asfdec_f.c:398
avassert.h
ASFStream::pkt_clean
int pkt_clean
Definition: asfdec_f.c:57
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:202
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
buf
void * buf
Definition: avisynth_c.h:766
get_value
static int get_value(AVIOContext *pb, int type, int type2_size)
Definition: asfdec_f.c:200
AVInputFormat
Definition: avformat.h:640
asf_read_close
static int asf_read_close(AVFormatContext *s)
Definition: asfdec_f.c:1523
ID3v2ExtraMeta
Definition: id3v2.h:57
ASFContext::asf_st
ASFStream * asf_st
currently decoded stream
Definition: asfdec_f.c:112
avio_get_str16le
int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a UTF-16 string from pb and convert it to UTF-8.
ASFContext::packet_frag_timestamp
int64_t packet_frag_timestamp
Definition: asfdec_f.c:103
ASFStream::duration
int64_t duration
Definition: asfdec_f.c:55
asf_read_seek
static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
Definition: asfdec_f.c:1655
s
#define s(width, name)
Definition: cbs_vp9.c:257
av_new_packet
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:86
ff_asf_data_header
const ff_asf_guid ff_asf_data_header
Definition: asf.c:80
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:645
g
const char * g
Definition: vf_curves.c:115
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:448
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: avcodec.h:4023
ASFContext::packet_pos
int64_t packet_pos
Definition: asfdec_f.c:108
get_id3_tag
static void get_id3_tag(AVFormatContext *s, int len)
Definition: asfdec_f.c:305
DO_2BITS
#define DO_2BITS(bits, var, defval)
Definition: asfdec_f.c:950
asf_read_marker
static int asf_read_marker(AVFormatContext *s, int64_t size)
Definition: asfdec_f.c:748
ASFContext::dar
AVRational dar[128]
Definition: asfdec_f.c:79
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
asf_probe
static int asf_probe(const AVProbeData *pd)
Definition: asfdec_f.c:189
ASFContext::packet_property
int packet_property
Definition: asfdec_f.c:93
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
AVStream::need_parsing
enum AVStreamParseType need_parsing
Definition: avformat.h:1088
ASFContext::packet_frag_offset
unsigned int packet_frag_offset
Definition: asfdec_f.c:101
asf_read_packet
static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: asfdec_f.c:1455
ASF_BYTE_ARRAY
@ ASF_BYTE_ARRAY
Definition: asf.h:31
key
const char * key
Definition: hwcontext_opencl.c:168
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
fsize
static int64_t fsize(FILE *f)
Definition: audiomatch.c:28
ASFStream::timestamp
int timestamp
Definition: asfdec_f.c:54
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: avcodec.h:245
av_packet_new_side_data
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
Definition: avpacket.c:329
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
if
if(ret)
Definition: filter_design.txt:179
ASFMainHeader
Definition: asf.h:39
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: avcodec.h:811
AVFormatContext
Format I/O context.
Definition: avformat.h:1342
ASF_QWORD
@ ASF_QWORD
Definition: asf.h:34
internal.h
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: avcodec.h:1460
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1017
AV_LANG_ISO639_2_BIBL
@ AV_LANG_ISO639_2_BIBL
Definition: avlanguage.h:31
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:530
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
ASFStream::ds_packet_size
int ds_packet_size
Definition: asfdec_f.c:60
ASFMainHeader::guid
ff_asf_guid guid
generated by client computer
Definition: asf.h:40
NULL
#define NULL
Definition: coverity.c:32
ff_asf_guid
uint8_t ff_asf_guid[16]
Definition: riff.h:92
ASFPayload::size
uint16_t size
Definition: asfdec_f.c:44
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:125
read_probe
static int read_probe(const AVProbeData *pd)
Definition: jvdec.c:55
ff_asf_header
const ff_asf_guid ff_asf_header
Definition: asf.c:23
ASFStream::seq
unsigned char seq
Definition: asfdec_f.c:49
ff_asf_metadata_conv
const AVMetadataConv ff_asf_metadata_conv[]
Definition: asf.c:159
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVPALETTE_SIZE
#define AVPALETTE_SIZE
Definition: pixfmt.h:32
AVSTREAM_PARSE_NONE
@ AVSTREAM_PARSE_NONE
Definition: avformat.h:790
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
ASFMainHeader::ignore
uint32_t ignore
preroll is 64 bits - but let's just ignore it
Definition: asf.h:51
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:446
ASFContext::stream_languages
char stream_languages[128][6]
max number of streams, language for each (RFC1766, e.g. en-US)
Definition: asfdec_f.c:80
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:934
ASFContext::index_read
int index_read
Definition: asfdec_f.c:88
ASFMainHeader::play_time
uint64_t play_time
play time, in 100-nanosecond units invalid if broadcasting
Definition: asf.h:45
ASFContext::packet_size_left
int packet_size_left
Definition: asfdec_f.c:83
ff_id3v2_picture_types
const char *const ff_id3v2_picture_types[21]
Definition: id3v2.c:107
ff_asf_head1_guid
const ff_asf_guid ff_asf_head1_guid
Definition: asf.c:84
ff_asf_digital_signature
const ff_asf_guid ff_asf_digital_signature
Definition: asf.c:142
index
int index
Definition: gxfenc.c:89
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ASFContext::packet_seq
int packet_seq
Definition: asfdec_f.c:97
ff_id3v2_mime_tags
const CodecMime ff_id3v2_mime_tags[]
Definition: id3v2.c:131
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:215
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3975
ASFStream::packet_pos
int64_t packet_pos
Definition: asfdec_f.c:63
ASFStream::ds_chunk_size
int ds_chunk_size
Definition: asfdec_f.c:61
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: avcodec.h:566
options
static const AVOption options[]
Definition: asfdec_f.c:120
ASFContext::packet_time_start
int packet_time_start
Definition: asfdec_f.c:107
avio_rl32
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:769
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: avcodec.h:810
desc
const char * desc
Definition: nvenc.c:68
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
AVMediaType
AVMediaType
Definition: avutil.h:199
AVPacket::size
int size
Definition: avcodec.h:1478
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
id
enum AVCodecID id
Definition: extract_extradata_bsf.c:329
ff_codec_get_id
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:3146
ASFContext::packet_time_delta
int packet_time_delta
Definition: asfdec_f.c:106
ff_convert_lang_to
const char * ff_convert_lang_to(const char *lang, enum AVLangCodespace target_codespace)
Convert a language code to a target codespace.
Definition: avlanguage.c:736
start_time
static int64_t start_time
Definition: ffplay.c:331
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:4910
size
int size
Definition: twinvq_data.h:11134
asf_read_metadata
static int asf_read_metadata(AVFormatContext *s, int64_t size)
Definition: asfdec_f.c:700
ID3v2_DEFAULT_MAGIC
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
Definition: id3v2.h:35
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
ASFPayload::type
uint8_t type
Definition: asfdec_f.c:43
ASFMainHeader::min_pktsize
uint32_t min_pktsize
size of a data packet invalid if broadcasting
Definition: asf.h:55
ASFStream::ds_span
int ds_span
Definition: asfdec_f.c:59
ASFMainHeader::max_pktsize
uint32_t max_pktsize
shall be the same as for min_pktsize invalid if broadcasting
Definition: asf.h:57
FRAME_HEADER_SIZE
#define FRAME_HEADER_SIZE
Definition: asfdec_f.c:137
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
ASF_DWORD
@ ASF_DWORD
Definition: asf.h:33
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:932
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: avcodec.h:1476
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:638
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
attributes.h
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1483
ASFContext::data_object_offset
uint64_t data_object_offset
data object offset (excl. GUID & size)
Definition: asfdec_f.c:86
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
asf_read_picture
static int asf_read_picture(AVFormatContext *s, int len)
Definition: asfdec_f.c:218
ASFStream::pkt
AVPacket pkt
Definition: asfdec_f.c:51
ff_asf_command_stream
const ff_asf_guid ff_asf_command_stream
Definition: asf.c:65
ffio_limit
int ffio_limit(AVIOContext *s, int size)
Definition: utils.c:247
AV_CODEC_ID_MJPEG
@ AV_CODEC_ID_MJPEG
Definition: avcodec.h:225
ASFContext::packet_flags
int packet_flags
Definition: asfdec_f.c:92
print_guid
#define print_guid(g)
Definition: asfdec_f.c:186
ff_asf_content_encryption
const ff_asf_guid ff_asf_content_encryption
Definition: asf.c:134
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: avcodec.h:216
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1470
avio_internal.h
internal.h
AVCodecParameters::height
int height
Definition: avcodec.h:4024
ASFStream::stream_language_index
uint16_t stream_language_index
Definition: asfdec_f.c:65
avpriv_new_chapter
AVChapter * avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title)
Add a new chapter.
Definition: utils.c:4608
ASFContext::packet_key_frame
int packet_key_frame
Definition: asfdec_f.c:99
ASFStream::frag_offset
int frag_offset
Definition: asfdec_f.c:52
ff_metadata_conv
void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition: metadata.c:26
common.h
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
ff_asf_ext_stream_header
const ff_asf_guid ff_asf_ext_stream_header
Definition: asf.c:35
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:277
asf_read_pts
static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
Definition: asfdec_f.c:1530
uint8_t
uint8_t
Definition: audio_convert.c:194
asf_read_frame_header
static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb)
Definition: asfdec_f.c:1097
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:236
ASFStream::payload
ASFPayload payload[8]
Definition: asfdec_f.c:71
len
int len
Definition: vorbis_enc_data.h:452
ff_get_wav_header
int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int size, int big_endian)
Definition: riffdec.c:91
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
ff_asf_extended_content_header
const ff_asf_guid ff_asf_extended_content_header
Definition: asf.c:92
av_get_packet
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition: utils.c:313
AVStream::disposition
int disposition
AV_DISPOSITION_* bit field.
Definition: avformat.h:923
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:877
ret
ret
Definition: filter_design.txt:187
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVStream
Stream structure.
Definition: avformat.h:870
bswap.h
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:246
AVClass::class_name
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:72
av_hex_dump_log
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.
Definition: dump.c:79
ff_asf_audio_stream
const ff_asf_guid ff_asf_audio_stream
Definition: asf.c:39
ff_asf_metadata_library_header
const ff_asf_guid ff_asf_metadata_library_header
Definition: asf.c:112
ASFStream::packet_obj_size
int packet_obj_size
Definition: asfdec_f.c:53
ASFMainHeader::file_size
uint64_t file_size
in bytes invalid if broadcasting
Definition: asf.h:41
asf_read_file_properties
static int asf_read_file_properties(AVFormatContext *s, int64_t size)
Definition: asfdec_f.c:374
avformat.h
dict.h
AVPacket::side_data
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
Definition: avcodec.h:1488
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: avcodec.h:790
asf.h
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen_template.c:38
ASFContext::asfid2avid
int asfid2avid[128]
conversion table from asf ID 2 AVStream ID
Definition: asfdec_f.c:76
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:871
ff_codec_bmp_tags
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:32
ff_asf_comment_header
const ff_asf_guid ff_asf_comment_header
Definition: asf.c:69
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
ASFContext::packet_timestamp
int packet_timestamp
Definition: asfdec_f.c:94
asf_read_language_list
static int asf_read_language_list(AVFormatContext *s, int64_t size)
Definition: asfdec_f.c:680
AVRational::den
int den
Denominator.
Definition: rational.h:60
AVFMT_NOGENSEARCH
#define AVFMT_NOGENSEARCH
Format does not allow to fall back on generic search.
Definition: avformat.h:474
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:647
ASFStream::num
int num
Definition: asfdec_f.c:48
AVIndexEntry::pos
int64_t pos
Definition: avformat.h:801
ff_asf_language_guid
const ff_asf_guid ff_asf_language_guid
Definition: asf.c:130
ff_asf_ext_content_encryption
const ff_asf_guid ff_asf_ext_content_encryption
Definition: asf.c:138
AVStream::request_probe
int request_probe
stream probing state -1 -> probing finished 0 -> no probing requested rest -> perform probing with re...
Definition: avformat.h:1128
asf_reset_header
static void asf_reset_header(AVFormatContext *s)
Definition: asfdec_f.c:1475
AVPacket::stream_index
int stream_index
Definition: avcodec.h:1479
ASFContext::packet_multi_size
int packet_multi_size
Definition: asfdec_f.c:105
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:331
ff_asf_file_header
const ff_asf_guid ff_asf_file_header
Definition: asf.c:27
CodecMime::str
char str[32]
Definition: internal.h:50
CodecMime::id
enum AVCodecID id
Definition: internal.h:51
ff_asf_metadata_header
const ff_asf_guid ff_asf_metadata_header
Definition: asf.c:108
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVCodecParameters::bits_per_coded_sample
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: avcodec.h:3999
ASFContext
Definition: asfdec_f.c:74
ff_asf_head2_guid
const ff_asf_guid ff_asf_head2_guid
Definition: asf.c:88
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:81
ASFMainHeader::max_bitrate
uint32_t max_bitrate
bandwidth of stream in bps should be the sum of bitrates of the individual media streams
Definition: asf.h:59
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:39
get_tag
static void get_tag(AVFormatContext *s, const char *key, int type, int len, int type2_size)
Definition: asfdec_f.c:317
ASFStream::palette
uint32_t palette[256]
Definition: asfdec_f.c:68
diff
static av_always_inline int diff(const uint32_t a, const uint32_t b)
Definition: vf_palettegen.c:136
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3957
AVPacket
This structure stores compressed data.
Definition: avcodec.h:1454
ff_read_frame_flush
void ff_read_frame_flush(AVFormatContext *s)
Flush the frame reader.
Definition: utils.c:1935
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:240
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:70
riff.h
ff_id3v2_free_extra_meta
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
Free memory allocated parsing special (non-text) metadata.
Definition: id3v2.c:1137
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1497
avio_rl64
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:777
ff_asf_my_guid
const ff_asf_guid ff_asf_my_guid
Definition: asf.c:126
ASFStream
Definition: asfdec_f.c:47
ASFContext::no_resync_search
int no_resync_search
Definition: asfdec_f.c:114
AVSTREAM_PARSE_FULL
@ AVSTREAM_PARSE_FULL
full parsing and repack
Definition: avformat.h:791
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
ff_asf_marker_header
const ff_asf_guid ff_asf_marker_header
Definition: asf.c:116
av_strlcpy
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:83
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: avcodec.h:3986
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
asf_read_ext_stream_properties
static int asf_read_ext_stream_properties(AVFormatContext *s, int64_t size)
Definition: asfdec_f.c:567
avstring.h
ff_id3v2_parse_chapters
int ff_id3v2_parse_chapters(AVFormatContext *s, ID3v2ExtraMeta **extra_meta)
Create chapters for all CHAP tags found in the ID3v2 header.
Definition: id3v2.c:1193
ff_asf_video_conceal_none
const ff_asf_guid ff_asf_video_conceal_none
Definition: asf.c:61
ff_asf_audio_conceal_none
const ff_asf_guid ff_asf_audio_conceal_none
Definition: asf.c:43
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:220
snprintf
#define snprintf
Definition: snprintf.h:34
ASFPayload
Definition: asfdec_f.c:42
ASFContext::packet_replic_size
int packet_replic_size
Definition: asfdec_f.c:98
ff_asfcrypt_dec
void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len)
Definition: asfcrypt.c:147
ASFContext::packet_segments
int packet_segments
Definition: asfdec_f.c:96
ff_asf_codec_comment1_header
const ff_asf_guid ff_asf_codec_comment1_header
Definition: asf.c:76
asf_read_header
static int asf_read_header(AVFormatContext *s)
Definition: asfdec_f.c:788
ff_asf_ext_stream_audio_stream
const ff_asf_guid ff_asf_ext_stream_audio_stream
Definition: asf.c:104
AVPacket::side_data_elems
int side_data_elems
Definition: avcodec.h:1489
ASFStream::payload_ext_ct
int payload_ext_ct
Definition: asfdec_f.c:70
av_index_search_timestamp
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
Definition: utils.c:2167
ff_asf_demuxer
AVInputFormat ff_asf_demuxer
Definition: asfdec_f.c:1710
ASFContext::export_xmp
int export_xmp
Definition: asfdec_f.c:115
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:358