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