FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
asfenc.c
Go to the documentation of this file.
1 /*
2  * ASF muxer
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 "libavutil/avassert.h"
23 #include "libavutil/dict.h"
24 #include "libavutil/mathematics.h"
25 #include "avformat.h"
26 #include "avio_internal.h"
27 #include "internal.h"
28 #include "riff.h"
29 #include "asf.h"
30 
31 #define ASF_INDEXED_INTERVAL 10000000
32 #define ASF_INDEX_BLOCK (1<<9)
33 #define ASF_PAYLOADS_PER_PACKET 63
34 
35 #define ASF_PACKET_ERROR_CORRECTION_DATA_SIZE 0x2
36 #define ASF_PACKET_ERROR_CORRECTION_FLAGS \
37  (ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT | \
38  ASF_PACKET_ERROR_CORRECTION_DATA_SIZE)
39 
40 #if (ASF_PACKET_ERROR_CORRECTION_FLAGS != 0)
41 # define ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE 1
42 #else
43 # define ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE 0
44 #endif
45 
46 #define ASF_PPI_PROPERTY_FLAGS \
47  (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_BYTE | \
48  ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_DWORD | \
49  ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_BYTE | \
50  ASF_PL_FLAG_STREAM_NUMBER_LENGTH_FIELD_IS_BYTE)
51 
52 #define ASF_PPI_LENGTH_TYPE_FLAGS 0
53 
54 #define ASF_PAYLOAD_FLAGS ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_WORD
55 
56 #if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
57 # define ASF_PPI_SEQUENCE_FIELD_SIZE 1
58 #endif
59 #if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
60 # define ASF_PPI_SEQUENCE_FIELD_SIZE 2
61 #endif
62 #if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
63 # define ASF_PPI_SEQUENCE_FIELD_SIZE 4
64 #endif
65 #ifndef ASF_PPI_SEQUENCE_FIELD_SIZE
66 # define ASF_PPI_SEQUENCE_FIELD_SIZE 0
67 #endif
68 
69 #if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
70 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 1
71 #endif
72 #if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
73 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 2
74 #endif
75 #if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
76 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 4
77 #endif
78 #ifndef ASF_PPI_PACKET_LENGTH_FIELD_SIZE
79 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 0
80 #endif
81 
82 #if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
83 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 1
84 #endif
85 #if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
86 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 2
87 #endif
88 #if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
89 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 4
90 #endif
91 #ifndef ASF_PPI_PADDING_LENGTH_FIELD_SIZE
92 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 0
93 #endif
94 
95 #if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_BYTE == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
96 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 1
97 #endif
98 #if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_WORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
99 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 2
100 #endif
101 #if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_DWORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
102 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 4
103 #endif
104 #ifndef ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE
105 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 0
106 #endif
107 
108 #if (ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_BYTE == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE))
109 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 1
110 #endif
111 #if (ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_WORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE))
112 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 2
113 #endif
114 #if (ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_DWORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE))
115 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 4
116 #endif
117 #ifndef ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE
118 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 0
119 #endif
120 
121 #if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_BYTE == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
122 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 1
123 #endif
124 #if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_WORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
125 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 2
126 #endif
127 #if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_DWORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
128 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 4
129 #endif
130 #ifndef ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE
131 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 0
132 #endif
133 
134 #if (ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_BYTE == (ASF_PAYLOAD_FLAGS & ASF_PL_MASK_PAYLOAD_LENGTH_FIELD_SIZE))
135 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 1
136 #endif
137 #if (ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_WORD == (ASF_PAYLOAD_FLAGS & ASF_PL_MASK_PAYLOAD_LENGTH_FIELD_SIZE))
138 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 2
139 #endif
140 #ifndef ASF_PAYLOAD_LENGTH_FIELD_SIZE
141 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 0
142 #endif
143 
144 #define PACKET_HEADER_MIN_SIZE \
145  (ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE + \
146  ASF_PACKET_ERROR_CORRECTION_DATA_SIZE + \
147  1 + /* Length Type Flags */ \
148  1 + /* Property Flags */ \
149  ASF_PPI_PACKET_LENGTH_FIELD_SIZE + \
150  ASF_PPI_SEQUENCE_FIELD_SIZE + \
151  ASF_PPI_PADDING_LENGTH_FIELD_SIZE + \
152  4 + /* Send Time Field */ \
153  2) /* Duration Field */
154 
155 // Replicated Data shall be at least 8 bytes long.
156 #define ASF_PAYLOAD_REPLICATED_DATA_LENGTH 0x08
157 
158 #define PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD \
159  (1 + /* Stream Number */ \
160  ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \
161  ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \
162  ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \
163  ASF_PAYLOAD_REPLICATED_DATA_LENGTH)
164 
165 #define PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS \
166  (1 + /* Stream Number */ \
167  ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \
168  ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \
169  ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \
170  ASF_PAYLOAD_REPLICATED_DATA_LENGTH + \
171  ASF_PAYLOAD_LENGTH_FIELD_SIZE)
172 
173 #define SINGLE_PAYLOAD_DATA_LENGTH \
174  (PACKET_SIZE - \
175  PACKET_HEADER_MIN_SIZE - \
176  PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD)
177 
178 #define MULTI_PAYLOAD_CONSTANT \
179  (PACKET_SIZE - \
180  PACKET_HEADER_MIN_SIZE - \
181  1 - /* Payload Flags */ \
182  2 * PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS)
183 
184 #define DATA_HEADER_SIZE 50
185 
186 typedef struct ASFContext {
187  uint32_t seqno;
189  ASFStream streams[128]; ///< it's max number and it's not that big
190  /* non streamed additonnal info */
191  uint64_t nb_packets; ///< how many packets are there in the file, invalid if broadcasting
192  int64_t duration; ///< in 100ns units
193  /* packet filling */
194  unsigned char multi_payloads_present;
195  int packet_size_left;
198  unsigned int packet_nb_payloads;
201  /* only for reading */
202  uint64_t data_offset; ///< beginning of the first data packet
203 
206  uint16_t maximum_packet;
211  int end_sec;
212 } ASFContext;
213 
214 static const AVCodecTag codec_asf_bmp_tags[] = {
215  { AV_CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
216  { AV_CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
217  { AV_CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
218  { AV_CODEC_ID_NONE, 0 },
219 };
220 
221 #define PREROLL_TIME 3100
222 
223 static void put_str16(AVIOContext *s, const char *tag)
224 {
225  int len;
226  uint8_t *pb;
227  AVIOContext *dyn_buf;
228  if (avio_open_dyn_buf(&dyn_buf) < 0)
229  return;
230 
231  avio_put_str16le(dyn_buf, tag);
232  len = avio_close_dyn_buf(dyn_buf, &pb);
233  avio_wl16(s, len);
234  avio_write(s, pb, len);
235  av_freep(&pb);
236 }
237 
238 static int64_t put_header(AVIOContext *pb, const ff_asf_guid *g)
239 {
240  int64_t pos;
241 
242  pos = avio_tell(pb);
243  ff_put_guid(pb, g);
244  avio_wl64(pb, 24);
245  return pos;
246 }
247 
248 /* update header size */
249 static void end_header(AVIOContext *pb, int64_t pos)
250 {
251  int64_t pos1;
252 
253  pos1 = avio_tell(pb);
254  avio_seek(pb, pos + 16, SEEK_SET);
255  avio_wl64(pb, pos1 - pos);
256  avio_seek(pb, pos1, SEEK_SET);
257 }
258 
259 /* write an asf chunk (only used in streaming case) */
260 static void put_chunk(AVFormatContext *s, int type,
261  int payload_length, int flags)
262 {
263  ASFContext *asf = s->priv_data;
264  AVIOContext *pb = s->pb;
265  int length;
266 
267  length = payload_length + 8;
268  avio_wl16(pb, type);
269  avio_wl16(pb, length); // size
270  avio_wl32(pb, asf->seqno); // sequence number
271  avio_wl16(pb, flags); // unknown bytes
272  avio_wl16(pb, length); // size_confirm
273  asf->seqno++;
274 }
275 
276 /* convert from unix to windows time */
277 static int64_t unix_to_file_time(int ti)
278 {
279  int64_t t;
280 
281  t = ti * INT64_C(10000000);
282  t += INT64_C(116444736000000000);
283  return t;
284 }
285 
286 static int32_t get_send_time(ASFContext *asf, int64_t pres_time, uint64_t *offset)
287 {
288  int i;
289  int32_t send_time = 0;
290  *offset = asf->data_offset + DATA_HEADER_SIZE;
291  for (i = 0; i < asf->next_start_sec; i++) {
292  if (pres_time <= asf->index_ptr[i].send_time)
293  break;
294  send_time = asf->index_ptr[i].send_time;
295  *offset = asf->index_ptr[i].offset;
296  }
297 
298  return send_time / 10000;
299 }
300 
302 {
303  ASFContext *asf = s->priv_data;
304  AVIOContext *pb = s->pb;
305  int i;
306  AVRational scale = {1, 10000000};
307  int64_t hpos = put_header(pb, &ff_asf_marker_header);
308 
309  ff_put_guid(pb, &ff_asf_reserved_4);// ASF spec mandates this reserved value
310  avio_wl32(pb, s->nb_chapters); // markers count
311  avio_wl16(pb, 0); // ASF spec mandates 0 for this
312  avio_wl16(pb, 0); // name length 0, no name given
313 
314  for (i = 0; i < s->nb_chapters; i++) {
315  AVChapter *c = s->chapters[i];
316  AVDictionaryEntry *t = av_dict_get(c->metadata, "title", NULL, 0);
317  int64_t pres_time = av_rescale_q(c->start, c->time_base, scale);
318  uint64_t offset;
319  int32_t send_time = get_send_time(asf, pres_time, &offset);
320  int len = 0;
321  uint8_t *buf;
322  AVIOContext *dyn_buf;
323  if (t) {
324  if (avio_open_dyn_buf(&dyn_buf) < 0)
325  return AVERROR(ENOMEM);
326  avio_put_str16le(dyn_buf, t->value);
327  len = avio_close_dyn_buf(dyn_buf, &buf);
328  }
329  avio_wl64(pb, offset); // offset of the packet with send_time
330  avio_wl64(pb, pres_time + PREROLL_TIME * 10000); // presentation time
331  avio_wl16(pb, 12 + len); // entry length
332  avio_wl32(pb, send_time); // send time
333  avio_wl32(pb, 0); // flags, should be 0
334  avio_wl32(pb, len / 2); // marker desc length in WCHARS!
335  if (t) {
336  avio_write(pb, buf, len); // marker desc
337  av_freep(&buf);
338  }
339  }
340  end_header(pb, hpos);
341  return 0;
342 }
343 
344 /* write the header (used two times if non streamed) */
345 static int asf_write_header1(AVFormatContext *s, int64_t file_size,
346  int64_t data_chunk_size)
347 {
348  ASFContext *asf = s->priv_data;
349  AVIOContext *pb = s->pb;
350  AVDictionaryEntry *tags[5];
351  int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
352  int has_title, has_aspect_ratio = 0;
353  int metadata_count;
354  AVCodecContext *enc;
355  int64_t header_offset, cur_pos, hpos;
356  int bit_rate;
357  int64_t duration;
358 
360 
361  tags[0] = av_dict_get(s->metadata, "title", NULL, 0);
362  tags[1] = av_dict_get(s->metadata, "author", NULL, 0);
363  tags[2] = av_dict_get(s->metadata, "copyright", NULL, 0);
364  tags[3] = av_dict_get(s->metadata, "comment", NULL, 0);
365  tags[4] = av_dict_get(s->metadata, "rating", NULL, 0);
366 
367  duration = asf->duration + PREROLL_TIME * 10000;
368  has_title = tags[0] || tags[1] || tags[2] || tags[3] || tags[4];
369  metadata_count = av_dict_count(s->metadata);
370 
371  bit_rate = 0;
372  for (n = 0; n < s->nb_streams; n++) {
373  enc = s->streams[n]->codec;
374 
375  avpriv_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */
376 
377  bit_rate += enc->bit_rate;
378  if ( enc->codec_type == AVMEDIA_TYPE_VIDEO
379  && enc->sample_aspect_ratio.num > 0
380  && enc->sample_aspect_ratio.den > 0)
381  has_aspect_ratio++;
382  }
383 
384  if (asf->is_streamed) {
385  put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */
386  }
387 
389  avio_wl64(pb, -1); /* header length, will be patched after */
390  avio_wl32(pb, 3 + has_title + !!metadata_count + s->nb_streams); /* number of chunks in header */
391  avio_w8(pb, 1); /* ??? */
392  avio_w8(pb, 2); /* ??? */
393 
394  /* file header */
395  header_offset = avio_tell(pb);
396  hpos = put_header(pb, &ff_asf_file_header);
398  avio_wl64(pb, file_size);
399  file_time = 0;
400  avio_wl64(pb, unix_to_file_time(file_time));
401  avio_wl64(pb, asf->nb_packets); /* number of packets */
402  avio_wl64(pb, duration); /* end time stamp (in 100ns units) */
403  avio_wl64(pb, asf->duration); /* duration (in 100ns units) */
404  avio_wl64(pb, PREROLL_TIME); /* start time stamp */
405  avio_wl32(pb, (asf->is_streamed || !pb->seekable) ? 3 : 2); /* ??? */
406  avio_wl32(pb, s->packet_size); /* packet size */
407  avio_wl32(pb, s->packet_size); /* packet size */
408  avio_wl32(pb, bit_rate ? bit_rate : -1); /* Maximum data rate in bps */
409  end_header(pb, hpos);
410 
411  /* unknown headers */
412  hpos = put_header(pb, &ff_asf_head1_guid);
414  avio_wl16(pb, 6);
415  if (has_aspect_ratio) {
416  int64_t hpos2;
417  avio_wl32(pb, 26 + has_aspect_ratio * 84);
418  hpos2 = put_header(pb, &ff_asf_metadata_header);
419  avio_wl16(pb, 2 * has_aspect_ratio);
420  for (n = 0; n < s->nb_streams; n++) {
421  enc = s->streams[n]->codec;
422  if ( enc->codec_type == AVMEDIA_TYPE_VIDEO
423  && enc->sample_aspect_ratio.num > 0
424  && enc->sample_aspect_ratio.den > 0) {
425  AVRational sar = enc->sample_aspect_ratio;
426  avio_wl16(pb, 0);
427  // the stream number is set like this below
428  avio_wl16(pb, n + 1);
429  avio_wl16(pb, 26); // name_len
430  avio_wl16(pb, 3); // value_type
431  avio_wl32(pb, 4); // value_len
432  avio_put_str16le(pb, "AspectRatioX");
433  avio_wl32(pb, sar.num);
434  avio_wl16(pb, 0);
435  // the stream number is set like this below
436  avio_wl16(pb, n + 1);
437  avio_wl16(pb, 26); // name_len
438  avio_wl16(pb, 3); // value_type
439  avio_wl32(pb, 4); // value_len
440  avio_put_str16le(pb, "AspectRatioY");
441  avio_wl32(pb, sar.den);
442  }
443  }
444  end_header(pb, hpos2);
445  } else {
446  avio_wl32(pb, 0);
447  }
448  end_header(pb, hpos);
449 
450  /* title and other infos */
451  if (has_title) {
452  int len;
453  uint8_t *buf;
454  AVIOContext *dyn_buf;
455 
456  if (avio_open_dyn_buf(&dyn_buf) < 0)
457  return AVERROR(ENOMEM);
458 
459  hpos = put_header(pb, &ff_asf_comment_header);
460 
461  for (n = 0; n < FF_ARRAY_ELEMS(tags); n++) {
462  len = tags[n] ? avio_put_str16le(dyn_buf, tags[n]->value) : 0;
463  avio_wl16(pb, len);
464  }
465  len = avio_close_dyn_buf(dyn_buf, &buf);
466  avio_write(pb, buf, len);
467  av_freep(&buf);
468  end_header(pb, hpos);
469  }
470  if (metadata_count) {
473  avio_wl16(pb, metadata_count);
474  while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
475  put_str16(pb, tag->key);
476  avio_wl16(pb, 0);
477  put_str16(pb, tag->value);
478  }
479  end_header(pb, hpos);
480  }
481  /* chapters using ASF markers */
482  if (!asf->is_streamed && s->nb_chapters) {
483  int ret;
484  if ((ret = asf_write_markers(s)) < 0)
485  return ret;
486  }
487  /* stream headers */
488  for (n = 0; n < s->nb_streams; n++) {
489  int64_t es_pos;
490  // ASFStream *stream = &asf->streams[n];
491 
492  enc = s->streams[n]->codec;
493  asf->streams[n].num = n + 1;
494  asf->streams[n].seq = 1;
495 
496  switch (enc->codec_type) {
497  case AVMEDIA_TYPE_AUDIO:
498  wav_extra_size = 0;
499  extra_size = 18 + wav_extra_size;
500  extra_size2 = 8;
501  break;
502  default:
503  case AVMEDIA_TYPE_VIDEO:
504  wav_extra_size = enc->extradata_size;
505  extra_size = 0x33 + wav_extra_size;
506  extra_size2 = 0;
507  break;
508  }
509 
510  hpos = put_header(pb, &ff_asf_stream_header);
511  if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
514  } else {
517  }
518  avio_wl64(pb, 0); /* ??? */
519  es_pos = avio_tell(pb);
520  avio_wl32(pb, extra_size); /* wav header len */
521  avio_wl32(pb, extra_size2); /* additional data len */
522  avio_wl16(pb, n + 1); /* stream number */
523  avio_wl32(pb, 0); /* ??? */
524 
525  if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
526  /* WAVEFORMATEX header */
528 
529  if (wavsize < 0)
530  return -1;
531  if (wavsize != extra_size) {
532  cur_pos = avio_tell(pb);
533  avio_seek(pb, es_pos, SEEK_SET);
534  avio_wl32(pb, wavsize); /* wav header len */
535  avio_seek(pb, cur_pos, SEEK_SET);
536  }
537  /* ERROR Correction */
538  avio_w8(pb, 0x01);
539  if (enc->codec_id == AV_CODEC_ID_ADPCM_G726 || !enc->block_align) {
540  avio_wl16(pb, 0x0190);
541  avio_wl16(pb, 0x0190);
542  } else {
543  avio_wl16(pb, enc->block_align);
544  avio_wl16(pb, enc->block_align);
545  }
546  avio_wl16(pb, 0x01);
547  avio_w8(pb, 0x00);
548  } else {
549  avio_wl32(pb, enc->width);
550  avio_wl32(pb, enc->height);
551  avio_w8(pb, 2); /* ??? */
552  avio_wl16(pb, 40 + enc->extradata_size); /* size */
553 
554  /* BITMAPINFOHEADER header */
555  ff_put_bmp_header(pb, enc, ff_codec_bmp_tags, 1, 0);
556  }
557  end_header(pb, hpos);
558  }
559 
560  /* media comments */
561 
564  avio_wl32(pb, s->nb_streams);
565  for (n = 0; n < s->nb_streams; n++) {
566  const AVCodecDescriptor *codec_desc;
567  const char *desc;
568 
569  enc = s->streams[n]->codec;
570  codec_desc = avcodec_descriptor_get(enc->codec_id);
571 
572  if (enc->codec_type == AVMEDIA_TYPE_AUDIO)
573  avio_wl16(pb, 2);
574  else if (enc->codec_type == AVMEDIA_TYPE_VIDEO)
575  avio_wl16(pb, 1);
576  else
577  avio_wl16(pb, -1);
578 
579  if (enc->codec_id == AV_CODEC_ID_WMAV2)
580  desc = "Windows Media Audio V8";
581  else
582  desc = codec_desc ? codec_desc->name : NULL;
583 
584  if (desc) {
585  AVIOContext *dyn_buf;
586  uint8_t *buf;
587  int len;
588 
589  if (avio_open_dyn_buf(&dyn_buf) < 0)
590  return AVERROR(ENOMEM);
591 
592  avio_put_str16le(dyn_buf, desc);
593  len = avio_close_dyn_buf(dyn_buf, &buf);
594  avio_wl16(pb, len / 2); // "number of characters" = length in bytes / 2
595 
596  avio_write(pb, buf, len);
597  av_freep(&buf);
598  } else
599  avio_wl16(pb, 0);
600 
601  avio_wl16(pb, 0); /* no parameters */
602 
603  /* id */
604  if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
605  avio_wl16(pb, 2);
606  avio_wl16(pb, enc->codec_tag);
607  } else {
608  avio_wl16(pb, 4);
609  avio_wl32(pb, enc->codec_tag);
610  }
611  if (!enc->codec_tag)
612  return -1;
613  }
614  end_header(pb, hpos);
615 
616  /* patch the header size fields */
617 
618  cur_pos = avio_tell(pb);
619  header_size = cur_pos - header_offset;
620  if (asf->is_streamed) {
621  header_size += 8 + 30 + DATA_HEADER_SIZE;
622 
623  avio_seek(pb, header_offset - 10 - 30, SEEK_SET);
624  avio_wl16(pb, header_size);
625  avio_seek(pb, header_offset - 2 - 30, SEEK_SET);
626  avio_wl16(pb, header_size);
627 
628  header_size -= 8 + 30 + DATA_HEADER_SIZE;
629  }
630  header_size += 24 + 6;
631  avio_seek(pb, header_offset - 14, SEEK_SET);
632  avio_wl64(pb, header_size);
633  avio_seek(pb, cur_pos, SEEK_SET);
634 
635  /* movie chunk, followed by packets of packet_size */
636  asf->data_offset = cur_pos;
638  avio_wl64(pb, data_chunk_size);
640  avio_wl64(pb, asf->nb_packets); /* nb packets */
641  avio_w8(pb, 1); /* ??? */
642  avio_w8(pb, 1); /* ??? */
643  return 0;
644 }
645 
647 {
648  ASFContext *asf = s->priv_data;
649 
651  s->max_interleave_delta = 0;
652  asf->nb_packets = 0;
653 
654  asf->index_ptr = av_malloc(sizeof(ASFIndex) * ASF_INDEX_BLOCK);
655  if (!asf->index_ptr)
656  return AVERROR(ENOMEM);
658  asf->maximum_packet = 0;
659 
660  /* the data-chunk-size has to be 50 (DATA_HEADER_SIZE), which is
661  * data_size - asf->data_offset at the moment this function is done.
662  * It is needed to use asf as a streamable format. */
663  if (asf_write_header1(s, 0, DATA_HEADER_SIZE) < 0) {
664  //av_free(asf);
665  av_freep(&asf->index_ptr);
666  return -1;
667  }
668 
669  avio_flush(s->pb);
670 
671  asf->packet_nb_payloads = 0;
672  asf->packet_timestamp_start = -1;
673  asf->packet_timestamp_end = -1;
674  ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
675  NULL, NULL, NULL, NULL);
676 
677  if (s->avoid_negative_ts < 0)
678  s->avoid_negative_ts = 1;
679 
680  return 0;
681 }
682 
684 {
685  ASFContext *asf = s->priv_data;
686 
687  asf->is_streamed = 1;
688 
689  return asf_write_header(s);
690 }
691 
693  unsigned sendtime, unsigned duration,
694  int nb_payloads, int padsize)
695 {
696  ASFContext *asf = s->priv_data;
697  AVIOContext *pb = s->pb;
698  int ppi_size, i;
699  int64_t start = avio_tell(pb);
700 
701  int iLengthTypeFlags = ASF_PPI_LENGTH_TYPE_FLAGS;
702 
703  padsize -= PACKET_HEADER_MIN_SIZE;
704  if (asf->multi_payloads_present)
705  padsize--;
706  av_assert0(padsize >= 0);
707 
709  for (i = 0; i < ASF_PACKET_ERROR_CORRECTION_DATA_SIZE; i++)
710  avio_w8(pb, 0x0);
711 
712  if (asf->multi_payloads_present)
713  iLengthTypeFlags |= ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT;
714 
715  if (padsize > 0) {
716  if (padsize < 256)
717  iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE;
718  else
719  iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD;
720  }
721  avio_w8(pb, iLengthTypeFlags);
722 
724 
725  if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD)
726  avio_wl16(pb, padsize - 2);
727  if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE)
728  avio_w8(pb, padsize - 1);
729 
730  avio_wl32(pb, sendtime);
731  avio_wl16(pb, duration);
732  if (asf->multi_payloads_present)
733  avio_w8(pb, nb_payloads | ASF_PAYLOAD_FLAGS);
734 
735  ppi_size = avio_tell(pb) - start;
736 
737  return ppi_size;
738 }
739 
741 {
742  ASFContext *asf = s->priv_data;
743  int packet_hdr_size, packet_filled_size;
744 
746 
747  if (asf->is_streamed)
748  put_chunk(s, 0x4424, s->packet_size, 0);
749 
750  packet_hdr_size = put_payload_parsing_info(s,
753  asf->packet_nb_payloads,
754  asf->packet_size_left);
755 
756  packet_filled_size = PACKET_SIZE - asf->packet_size_left;
757  av_assert0(packet_hdr_size <= asf->packet_size_left);
758  memset(asf->packet_buf + packet_filled_size, 0, asf->packet_size_left);
759 
760  avio_write(s->pb, asf->packet_buf, s->packet_size - packet_hdr_size);
761 
762  avio_flush(s->pb);
763  asf->nb_packets++;
764  asf->packet_nb_payloads = 0;
765  asf->packet_timestamp_start = -1;
766  asf->packet_timestamp_end = -1;
767  ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
768  NULL, NULL, NULL, NULL);
769 }
770 
772  int64_t presentation_time, int m_obj_size,
773  int m_obj_offset, int payload_len, int flags)
774 {
775  ASFContext *asf = s->priv_data;
776  AVIOContext *pb = &asf->pb;
777  int val;
778 
779  val = stream->num;
780  if (flags & AV_PKT_FLAG_KEY)
781  val |= ASF_PL_FLAG_KEY_FRAME;
782  avio_w8(pb, val);
783 
784  avio_w8(pb, stream->seq); // Media object number
785  avio_wl32(pb, m_obj_offset); // Offset Into Media Object
786 
787  // Replicated Data shall be at least 8 bytes long.
788  // The first 4 bytes of data shall contain the
789  // Size of the Media Object that the payload belongs to.
790  // The next 4 bytes of data shall contain the
791  // Presentation Time for the media object that the payload belongs to.
793 
794  avio_wl32(pb, m_obj_size); // Replicated Data - Media Object Size
795  avio_wl32(pb, (uint32_t) presentation_time); // Replicated Data - Presentation Time
796 
797  if (asf->multi_payloads_present) {
798  avio_wl16(pb, payload_len); // payload length
799  }
800 }
801 
802 static void put_frame(AVFormatContext *s, ASFStream *stream, AVStream *avst,
803  int64_t timestamp, const uint8_t *buf,
804  int m_obj_size, int flags)
805 {
806  ASFContext *asf = s->priv_data;
807  int m_obj_offset, payload_len, frag_len1;
808 
809  m_obj_offset = 0;
810  while (m_obj_offset < m_obj_size) {
811  payload_len = m_obj_size - m_obj_offset;
812  if (asf->packet_timestamp_start == -1) {
813  asf->multi_payloads_present = (payload_len < MULTI_PAYLOAD_CONSTANT);
814 
816  if (asf->multi_payloads_present) {
817  frag_len1 = MULTI_PAYLOAD_CONSTANT - 1;
818  } else {
819  frag_len1 = SINGLE_PAYLOAD_DATA_LENGTH;
820  }
821  asf->packet_timestamp_start = timestamp;
822  } else {
823  // multi payloads
824  frag_len1 = asf->packet_size_left -
827 
828  if (frag_len1 < payload_len &&
829  avst->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
830  flush_packet(s);
831  continue;
832  }
833  }
834  if (frag_len1 > 0) {
835  if (payload_len > frag_len1)
836  payload_len = frag_len1;
837  else if (payload_len == (frag_len1 - 1))
838  payload_len = frag_len1 - 2; // additional byte need to put padding length
839 
840  put_payload_header(s, stream, timestamp + PREROLL_TIME,
841  m_obj_size, m_obj_offset, payload_len, flags);
842  avio_write(&asf->pb, buf, payload_len);
843 
844  if (asf->multi_payloads_present)
846  else
848  asf->packet_timestamp_end = timestamp;
849 
850  asf->packet_nb_payloads++;
851  } else {
852  payload_len = 0;
853  }
854  m_obj_offset += payload_len;
855  buf += payload_len;
856 
857  if (!asf->multi_payloads_present)
858  flush_packet(s);
860  flush_packet(s);
862  flush_packet(s);
863  }
864  stream->seq++;
865 }
866 
867 static int update_index(AVFormatContext *s, int start_sec,
868  uint32_t packet_number, uint16_t packet_count,
869  uint64_t packet_offset)
870 {
871  ASFContext *asf = s->priv_data;
872 
873  if (start_sec > asf->next_start_sec) {
874  int i;
875 
876  if (!asf->next_start_sec) {
877  asf->next_packet_number = packet_number;
878  asf->next_packet_count = packet_count;
879  asf->next_packet_offset = packet_offset;
880  }
881 
882  if (start_sec > asf->nb_index_memory_alloc) {
883  int err;
884  asf->nb_index_memory_alloc = (start_sec + ASF_INDEX_BLOCK) & ~(ASF_INDEX_BLOCK - 1);
885  if ((err = av_reallocp_array(&asf->index_ptr,
887  sizeof(*asf->index_ptr))) < 0) {
888  asf->nb_index_memory_alloc = 0;
889  return err;
890  }
891  }
892  for (i = asf->next_start_sec; i < start_sec; i++) {
895  asf->index_ptr[i].send_time = asf->next_start_sec * INT64_C(10000000);
896  asf->index_ptr[i].offset = asf->next_packet_offset;
897 
898  }
899  }
900  asf->maximum_packet = FFMAX(asf->maximum_packet, packet_count);
901  asf->next_packet_number = packet_number;
902  asf->next_packet_count = packet_count;
903  asf->next_packet_offset = packet_offset;
904  asf->next_start_sec = start_sec;
905 
906  return 0;
907 }
908 
910 {
911  ASFContext *asf = s->priv_data;
912  AVIOContext *pb = s->pb;
913  ASFStream *stream;
914  AVCodecContext *codec;
915  uint32_t packet_number;
916  int64_t pts;
917  int start_sec;
918  int flags = pkt->flags;
919  int ret;
920  uint64_t offset = avio_tell(pb);
921 
922  codec = s->streams[pkt->stream_index]->codec;
923  stream = &asf->streams[pkt->stream_index];
924 
925  if (codec->codec_type == AVMEDIA_TYPE_AUDIO)
926  flags &= ~AV_PKT_FLAG_KEY;
927 
928  pts = (pkt->pts != AV_NOPTS_VALUE) ? pkt->pts : pkt->dts;
929  av_assert0(pts != AV_NOPTS_VALUE);
930  pts *= 10000;
931  asf->duration = FFMAX(asf->duration, pts + pkt->duration * 10000);
932 
933  packet_number = asf->nb_packets;
934  put_frame(s, stream, s->streams[pkt->stream_index],
935  pkt->dts, pkt->data, pkt->size, flags);
936 
937  start_sec = (int)((PREROLL_TIME * 10000 + pts + ASF_INDEXED_INTERVAL - 1)
939 
940  /* check index */
941  if ((!asf->is_streamed) && (flags & AV_PKT_FLAG_KEY)) {
942  uint16_t packet_count = asf->nb_packets - packet_number;
943  ret = update_index(s, start_sec, packet_number, packet_count, offset);
944  if (ret < 0)
945  return ret;
946  }
947  asf->end_sec = start_sec;
948 
949  return 0;
950 }
951 
953  uint16_t max, uint32_t count)
954 {
955  AVIOContext *pb = s->pb;
956  int i;
957 
959  avio_wl64(pb, 24 + 16 + 8 + 4 + 4 + (4 + 2) * count);
962  avio_wl32(pb, max);
963  avio_wl32(pb, count);
964  for (i = 0; i < count; i++) {
965  avio_wl32(pb, index[i].packet_number);
966  avio_wl16(pb, index[i].packet_count);
967  }
968 
969  return 0;
970 }
971 
973 {
974  ASFContext *asf = s->priv_data;
975  int64_t file_size, data_size;
976  int ret;
977 
978  /* flush the current packet */
979  if (asf->pb.buf_ptr > asf->pb.buffer)
980  flush_packet(s);
981 
982  /* write index */
983  data_size = avio_tell(s->pb);
984  if (!asf->is_streamed && asf->next_start_sec) {
985  if ((ret = update_index(s, asf->end_sec + 1, 0, 0, 0)) < 0)
986  return ret;
988  }
989  avio_flush(s->pb);
990 
991  if (asf->is_streamed || !s->pb->seekable) {
992  put_chunk(s, 0x4524, 0, 0); /* end of stream */
993  } else {
994  /* rewrite an updated header */
995  file_size = avio_tell(s->pb);
996  avio_seek(s->pb, 0, SEEK_SET);
997  asf_write_header1(s, file_size, data_size - asf->data_offset);
998  }
999 
1000  av_freep(&asf->index_ptr);
1001  return 0;
1002 }
1003 
1004 #if CONFIG_ASF_MUXER
1005 AVOutputFormat ff_asf_muxer = {
1006  .name = "asf",
1007  .long_name = NULL_IF_CONFIG_SMALL("ASF (Advanced / Active Streaming Format)"),
1008  .mime_type = "video/x-ms-asf",
1009  .extensions = "asf,wmv,wma",
1010  .priv_data_size = sizeof(ASFContext),
1011  .audio_codec = AV_CODEC_ID_WMAV2,
1012  .video_codec = AV_CODEC_ID_MSMPEG4V3,
1017  .codec_tag = (const AVCodecTag * const []) {
1019  },
1020 };
1021 #endif /* CONFIG_ASF_MUXER */
1022 
1023 #if CONFIG_ASF_STREAM_MUXER
1024 AVOutputFormat ff_asf_stream_muxer = {
1025  .name = "asf_stream",
1026  .long_name = NULL_IF_CONFIG_SMALL("ASF (Advanced / Active Streaming Format)"),
1027  .mime_type = "video/x-ms-asf",
1028  .extensions = "asf,wmv,wma",
1029  .priv_data_size = sizeof(ASFContext),
1030  .audio_codec = AV_CODEC_ID_WMAV2,
1031  .video_codec = AV_CODEC_ID_MSMPEG4V3,
1036  .codec_tag = (const AVCodecTag * const []) {
1038  },
1039 };
1040 #endif /* CONFIG_ASF_STREAM_MUXER */
unsigned int nb_chapters
Number of chapters in AVChapter array.
Definition: avformat.h:1471
const ff_asf_guid ff_asf_header
Definition: asf.c:23
unsigned int packet_size
Definition: avformat.h:1376
#define NULL
Definition: coverity.c:32
const char const char void * val
Definition: avisynth_c.h:634
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:416
static int asf_write_markers(AVFormatContext *s)
Definition: asfenc.c:301
const char * s
Definition: avisynth_c.h:631
Bytestream IO Context.
Definition: avio.h:111
#define ASF_PAYLOAD_FLAGS
Definition: asfenc.c:54
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1125
const ff_asf_guid ff_asf_codec_comment_header
Definition: asf.c:73
const ff_asf_guid ff_asf_metadata_header
Definition: asf.c:108
#define PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD
Definition: asfenc.c:158
void ff_put_guid(AVIOContext *s, const ff_asf_guid *g)
Definition: riffenc.c:323
unsigned char * buf_ptr
Current position in the buffer.
Definition: avio.h:127
unsigned int packet_nb_payloads
Definition: asfenc.c:198
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:4006
const char * g
Definition: vf_curves.c:108
static int64_t unix_to_file_time(int ti)
Definition: asfenc.c:277
int is_streamed
Definition: asfenc.c:188
#define PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS
Definition: asfenc.c:165
int num
Definition: asf.h:37
Definition: asf.h:89
static int asf_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: asfenc.c:909
uint64_t data_offset
beginning of the first data packet
Definition: asfdec.c:53
int num
numerator
Definition: rational.h:44
static int asf_write_index(AVFormatContext *s, const ASFIndex *index, uint16_t max, uint32_t count)
Definition: asfenc.c:952
int size
Definition: avcodec.h:1163
uint32_t next_packet_number
Definition: asfenc.c:207
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
Definition: dict.c:34
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:203
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:1623
unsigned char * buffer
Start of the buffer.
Definition: avio.h:125
static int put_payload_parsing_info(AVFormatContext *s, unsigned sendtime, unsigned duration, int nb_payloads, int padsize)
Definition: asfenc.c:692
uint16_t maximum_packet
Definition: asfenc.c:206
#define FF_ARRAY_ELEMS(a)
static AVPacket pkt
static int asf_write_trailer(AVFormatContext *s)
Definition: asfenc.c:972
uint64_t offset
Definition: asf.h:93
AVDictionary * metadata
Definition: avformat.h:1239
uint16_t next_packet_count
Definition: asfenc.c:208
uint32_t packet_number
Definition: asf.h:90
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1113
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:2022
const ff_asf_guid ff_asf_reserved_4
Definition: asf.c:120
Format I/O context.
Definition: avformat.h:1272
const ff_asf_guid ff_asf_data_header
Definition: asf.c:80
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
Public dictionary API.
#define ASF_INDEX_BLOCK
Definition: asfenc.c:32
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:318
AVIOContext pb
Definition: asfenc.c:200
uint8_t
#define av_malloc(s)
const ff_asf_guid ff_asf_audio_stream
Definition: asf.c:39
static int asf_write_header(AVFormatContext *s)
Definition: asfenc.c:646
ASFStream streams[128]
it's max number and it's not that big
Definition: asfdec.c:45
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1340
int packet_size_left
Definition: asfdec.c:51
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:39
uint8_t * data
Definition: avcodec.h:1162
int64_t max_interleave_delta
Maximum buffering duration for interleaving.
Definition: avformat.h:1544
uint32_t tag
Definition: movenc.c:1333
#define ASF_PPI_LENGTH_TYPE_FLAGS
Definition: asfenc.c:52
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:365
static int64_t duration
Definition: ffplay.c:321
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:177
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1180
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1208
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:404
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:140
uint32_t seqno
Definition: asfenc.c:187
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:213
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1482
#define PREROLL_TIME
Definition: asfenc.c:221
const ff_asf_guid ff_asf_head1_guid
Definition: asf.c:84
const ff_asf_guid ff_asf_simple_index_header
Definition: asf.c:96
const ff_asf_guid ff_asf_head2_guid
Definition: asf.c:88
static void put_payload_header(AVFormatContext *s, ASFStream *stream, int64_t presentation_time, int m_obj_size, int m_obj_offset, int payload_len, int flags)
Definition: asfenc.c:771
#define DATA_HEADER_SIZE
Definition: asfenc.c:184
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
int64_t packet_timestamp_start
Definition: asfenc.c:196
const ff_asf_guid ff_asf_video_conceal_none
Definition: asf.c:61
AVChapter ** chapters
Definition: avformat.h:1472
simple assert() macros that are a bit more flexible than ISO C assert().
GLsizei GLsizei * length
Definition: opengl_enc.c:115
#define ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD
Definition: asf.h:156
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
GLsizei count
Definition: opengl_enc.c:109
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:376
#define FFMAX(a, b)
Definition: common.h:64
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1168
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:2891
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:861
#define ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT
Definition: asf.h:148
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1328
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:160
int bit_rate
the average bitrate
Definition: avcodec.h:1305
int void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition: aviobuf.c:197
uint64_t send_time
Definition: asf.h:92
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:32
ret
Definition: avfilter.c:974
int width
picture width / height.
Definition: avcodec.h:1414
static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
Definition: asfenc.c:260
#define ASF_PACKET_ERROR_CORRECTION_FLAGS
Definition: asfenc.c:36
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
const ff_asf_guid ff_asf_extended_content_header
Definition: asf.c:92
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:94
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:471
static int32_t get_send_time(ASFContext *asf, int64_t pres_time, uint64_t *offset)
Definition: asfenc.c:286
#define ASF_PAYLOADS_PER_PACKET
Definition: asfenc.c:33
const char * name
Definition: avformat.h:513
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
int32_t
#define ASF_PAYLOAD_REPLICATED_DATA_LENGTH
Definition: asfenc.c:156
int next_start_sec
Definition: asfenc.c:210
int avoid_negative_ts
Avoid negative timestamps during muxing.
Definition: avformat.h:1573
int n
Definition: avisynth_c.h:547
const ff_asf_guid ff_asf_my_guid
Definition: asf.c:126
#define ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE
Definition: asf.h:155
uint8_t ff_asf_guid[16]
Definition: riff.h:84
Stream structure.
Definition: avformat.h:842
#define ASF_PACKET_ERROR_CORRECTION_DATA_SIZE
Definition: asfenc.c:35
uint8_t packet_buf[PACKET_SIZE]
Definition: asfenc.c:199
#define ASF_PPI_PROPERTY_FLAGS
Definition: asfenc.c:46
enum AVMediaType codec_type
Definition: avcodec.h:1249
const ff_asf_guid ff_asf_file_header
Definition: asf.c:27
#define SINGLE_PAYLOAD_DATA_LENGTH
Definition: asfenc.c:173
enum AVCodecID codec_id
Definition: avcodec.h:1258
AVIOContext * pb
I/O context.
Definition: avformat.h:1314
const ff_asf_guid ff_asf_video_stream
Definition: asf.c:53
Definition: asf.h:36
int64_t packet_timestamp_end
Definition: asfenc.c:197
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:155
main external API structure.
Definition: avcodec.h:1241
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1273
void * buf
Definition: avisynth_c.h:553
static void flush_packet(AVFormatContext *s)
Definition: asfenc.c:740
GLint GLenum type
Definition: opengl_enc.c:105
int extradata_size
Definition: avcodec.h:1356
int index
Definition: gxfenc.c:89
rational number numerator/denominator
Definition: rational.h:43
void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf, int ignore_extradata)
Definition: riffenc.c:205
const ff_asf_guid ff_asf_stream_header
Definition: asf.c:31
static const AVCodecTag codec_asf_bmp_tags[]
Definition: asfenc.c:214
int avio_put_str16le(AVIOContext *s, const char *str)
Convert an UTF-8 string to UTF-16LE and write it.
const AVMetadataConv ff_asf_metadata_conv[]
Definition: asf.c:147
const char * name
Name of the codec described by this descriptor.
Definition: avcodec.h:568
static int64_t put_header(AVIOContext *pb, const ff_asf_guid *g)
Definition: asfenc.c:238
int64_t duration
in 100ns units
Definition: asfenc.c:192
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:560
#define ASF_INDEXED_INTERVAL
Definition: asfenc.c:31
const ff_asf_guid ff_asf_comment_header
Definition: asf.c:69
static void put_frame(AVFormatContext *s, ASFStream *stream, AVStream *avst, int64_t timestamp, const uint8_t *buf, int m_obj_size, int flags)
Definition: asfenc.c:802
static int64_t pts
Global timestamp for the audio frames.
static int flags
Definition: cpu.c:47
ASFIndex * index_ptr
Definition: asfenc.c:204
int64_t start
Definition: avformat.h:1238
#define MULTI_PAYLOAD_CONSTANT
Definition: asfenc.c:178
Main libavformat public API header.
static void end_header(AVIOContext *pb, int64_t pos)
Definition: asfenc.c:249
#define ASF_PL_FLAG_KEY_FRAME
Definition: asf.h:188
int ffio_init_context(AVIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Definition: aviobuf.c:72
uint64_t nb_packets
how many packets are there in the file, invalid if broadcasting
Definition: asfenc.c:191
static double c[64]
unsigned char seq
Definition: asf.h:38
const ff_asf_guid ff_asf_audio_conceal_spread
Definition: asf.c:49
const ff_asf_guid ff_asf_codec_comment1_header
Definition: asf.c:76
AVRational time_base
time base in which the start/end timestamps are specified
Definition: avformat.h:1237
char * key
Definition: dict.h:87
int den
denominator
Definition: rational.h:45
void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition: metadata.c:26
static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size)
Definition: asfenc.c:345
char * value
Definition: dict.h:88
int len
int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc, int flags)
Write WAVEFORMAT header structure.
Definition: riffenc.c:54
void * priv_data
Format private data.
Definition: avformat.h:1300
uint32_t nb_index_memory_alloc
Definition: asfenc.c:205
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:493
#define PACKET_SIZE
Definition: asf.h:29
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1161
static int asf_write_stream_header(AVFormatContext *s)
Definition: asfenc.c:683
#define av_freep(p)
static void put_str16(AVIOContext *s, const char *tag)
Definition: asfenc.c:223
void INT64 start
Definition: avisynth_c.h:553
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
Definition: dict.h:72
uint16_t packet_count
Definition: asf.h:91
#define PACKET_HEADER_MIN_SIZE
Definition: asfenc.c:144
const ff_asf_guid ff_asf_marker_header
Definition: asf.c:116
int stream_index
Definition: avcodec.h:1164
int end_sec
Definition: asfenc.c:211
static int update_index(AVFormatContext *s, int start_sec, uint32_t packet_number, uint16_t packet_count, uint64_t packet_offset)
Definition: asfenc.c:867
unsigned char multi_payloads_present
Definition: asfenc.c:194
#define MKTAG(a, b, c, d)
Definition: common.h:315
This structure stores compressed data.
Definition: avcodec.h:1139
static int write_packet(AVFormatContext *s1, AVPacket *pkt)
Definition: v4l2enc.c:86
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1155
uint64_t next_packet_offset
Definition: asfenc.c:209
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:241
#define FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX
Tell ff_put_wav_header() to use WAVEFORMATEX even for PCM codecs.
Definition: riff.h:53