Libav
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 Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/dict.h"
23 #include "libavutil/mathematics.h"
24 #include "avformat.h"
25 #include "avio_internal.h"
26 #include "internal.h"
27 #include "riff.h"
28 #include "asf.h"
29 
30 #undef NDEBUG
31 #include <assert.h>
32 
33 
34 #define ASF_INDEXED_INTERVAL 10000000
35 #define ASF_INDEX_BLOCK 600
36 
37 #define ASF_PACKET_ERROR_CORRECTION_DATA_SIZE 0x2
38 #define ASF_PACKET_ERROR_CORRECTION_FLAGS \
39  (ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT | \
40  ASF_PACKET_ERROR_CORRECTION_DATA_SIZE)
41 
42 #if (ASF_PACKET_ERROR_CORRECTION_FLAGS != 0)
43 # define ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE 1
44 #else
45 # define ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE 0
46 #endif
47 
48 #define ASF_PPI_PROPERTY_FLAGS \
49  (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_BYTE | \
50  ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_DWORD | \
51  ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_BYTE | \
52  ASF_PL_FLAG_STREAM_NUMBER_LENGTH_FIELD_IS_BYTE)
53 
54 #define ASF_PPI_LENGTH_TYPE_FLAGS 0
55 
56 #define ASF_PAYLOAD_FLAGS ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_WORD
57 
58 #if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
59 # define ASF_PPI_SEQUENCE_FIELD_SIZE 1
60 #endif
61 #if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
62 # define ASF_PPI_SEQUENCE_FIELD_SIZE 2
63 #endif
64 #if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
65 # define ASF_PPI_SEQUENCE_FIELD_SIZE 4
66 #endif
67 #ifndef ASF_PPI_SEQUENCE_FIELD_SIZE
68 # define ASF_PPI_SEQUENCE_FIELD_SIZE 0
69 #endif
70 
71 #if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
72 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 1
73 #endif
74 #if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
75 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 2
76 #endif
77 #if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
78 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 4
79 #endif
80 #ifndef ASF_PPI_PACKET_LENGTH_FIELD_SIZE
81 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 0
82 #endif
83 
84 #if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
85 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 1
86 #endif
87 #if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
88 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 2
89 #endif
90 #if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
91 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 4
92 #endif
93 #ifndef ASF_PPI_PADDING_LENGTH_FIELD_SIZE
94 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 0
95 #endif
96 
97 #if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_BYTE == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
98 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 1
99 #endif
100 #if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_WORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
101 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 2
102 #endif
103 #if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_DWORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
104 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 4
105 #endif
106 #ifndef ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE
107 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 0
108 #endif
109 
110 #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))
111 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 1
112 #endif
113 #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))
114 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 2
115 #endif
116 #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))
117 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 4
118 #endif
119 #ifndef ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE
120 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 0
121 #endif
122 
123 #if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_BYTE == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
124 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 1
125 #endif
126 #if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_WORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
127 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 2
128 #endif
129 #if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_DWORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
130 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 4
131 #endif
132 #ifndef ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE
133 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 0
134 #endif
135 
136 #if (ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_BYTE == (ASF_PAYLOAD_FLAGS & ASF_PL_MASK_PAYLOAD_LENGTH_FIELD_SIZE))
137 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 1
138 #endif
139 #if (ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_WORD == (ASF_PAYLOAD_FLAGS & ASF_PL_MASK_PAYLOAD_LENGTH_FIELD_SIZE))
140 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 2
141 #endif
142 #ifndef ASF_PAYLOAD_LENGTH_FIELD_SIZE
143 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 0
144 #endif
145 
146 #define PACKET_HEADER_MIN_SIZE \
147  (ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE + \
148  ASF_PACKET_ERROR_CORRECTION_DATA_SIZE + \
149  1 + /* Length Type Flags */ \
150  1 + /* Property Flags */ \
151  ASF_PPI_PACKET_LENGTH_FIELD_SIZE + \
152  ASF_PPI_SEQUENCE_FIELD_SIZE + \
153  ASF_PPI_PADDING_LENGTH_FIELD_SIZE + \
154  4 + /* Send Time Field */ \
155  2) /* Duration Field */
156 
157 // Replicated Data shall be at least 8 bytes long.
158 #define ASF_PAYLOAD_REPLICATED_DATA_LENGTH 0x08
159 
160 #define PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD \
161  (1 + /* Stream Number */ \
162  ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \
163  ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \
164  ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \
165  ASF_PAYLOAD_REPLICATED_DATA_LENGTH)
166 
167 #define PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS \
168  (1 + /* Stream Number */ \
169  ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \
170  ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \
171  ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \
172  ASF_PAYLOAD_REPLICATED_DATA_LENGTH + \
173  ASF_PAYLOAD_LENGTH_FIELD_SIZE)
174 
175 #define SINGLE_PAYLOAD_DATA_LENGTH \
176  (PACKET_SIZE - \
177  PACKET_HEADER_MIN_SIZE - \
178  PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD)
179 
180 #define MULTI_PAYLOAD_CONSTANT \
181  (PACKET_SIZE - \
182  PACKET_HEADER_MIN_SIZE - \
183  1 - /* Payload Flags */ \
184  2 * PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS)
185 
186 #define DATA_HEADER_SIZE 50
187 
188 typedef struct ASFStream {
189  int num;
190  unsigned char seq;
191  /* use for reading */
195 
196  int ds_span; /* descrambling */
199 
200  int64_t packet_pos;
201 
203 
205  uint32_t palette[256];
206 } ASFStream;
207 
208 typedef struct ASFContext {
209  uint32_t seqno;
211  ASFStream streams[128];
212  /* non-streamed additional info */
213  uint64_t nb_packets;
214  uint64_t duration;
215  /* packet filling */
216  unsigned char multi_payloads_present;
220  unsigned int packet_nb_payloads;
221  uint8_t packet_buf[PACKET_SIZE];
223  /* only for reading */
224  uint64_t data_offset;
225 
228  uint32_t nb_index_count;
230  uint16_t maximum_packet;
231 } ASFContext;
232 
233 static const AVCodecTag codec_asf_bmp_tags[] = {
234  { AV_CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
235  { AV_CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
236  { AV_CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
237  { AV_CODEC_ID_NONE, 0 },
238 };
239 
240 #define PREROLL_TIME 3100
241 
242 static void put_guid(AVIOContext *s, const ff_asf_guid *g)
243 {
244  assert(sizeof(*g) == 16);
245  avio_write(s, *g, sizeof(*g));
246 }
247 
248 static void put_str16(AVIOContext *s, const char *tag)
249 {
250  int len;
251  uint8_t *pb;
252  AVIOContext *dyn_buf;
253  if (avio_open_dyn_buf(&dyn_buf) < 0)
254  return;
255 
256  avio_put_str16le(dyn_buf, tag);
257  len = avio_close_dyn_buf(dyn_buf, &pb);
258  avio_wl16(s, len);
259  avio_write(s, pb, len);
260  av_freep(&pb);
261 }
262 
263 static int64_t put_header(AVIOContext *pb, const ff_asf_guid *g)
264 {
265  int64_t pos;
266 
267  pos = avio_tell(pb);
268  put_guid(pb, g);
269  avio_wl64(pb, 24);
270  return pos;
271 }
272 
273 /* update header size */
274 static void end_header(AVIOContext *pb, int64_t pos)
275 {
276  int64_t pos1;
277 
278  pos1 = avio_tell(pb);
279  avio_seek(pb, pos + 16, SEEK_SET);
280  avio_wl64(pb, pos1 - pos);
281  avio_seek(pb, pos1, SEEK_SET);
282 }
283 
284 /* write an asf chunk (only used in streaming case) */
285 static void put_chunk(AVFormatContext *s, int type,
286  int payload_length, int flags)
287 {
288  ASFContext *asf = s->priv_data;
289  AVIOContext *pb = s->pb;
290  int length;
291 
292  length = payload_length + 8;
293  avio_wl16(pb, type);
294  avio_wl16(pb, length); // size
295  avio_wl32(pb, asf->seqno); // sequence number
296  avio_wl16(pb, flags); // unknown bytes
297  avio_wl16(pb, length); // size_confirm
298  asf->seqno++;
299 }
300 
301 /* convert from unix to windows time */
302 static int64_t unix_to_file_time(int ti)
303 {
304  int64_t t;
305 
306  t = ti * INT64_C(10000000);
307  t += INT64_C(116444736000000000);
308  return t;
309 }
310 
311 static int32_t get_send_time(ASFContext *asf, int64_t pres_time, uint64_t *offset)
312 {
313  int i;
314  int32_t send_time = 0;
315  *offset = asf->data_offset + DATA_HEADER_SIZE;
316  for (i = 0; i < asf->nb_index_count; i++) {
317  if (pres_time <= asf->index_ptr[i].send_time)
318  break;
319  send_time = asf->index_ptr[i].send_time;
320  *offset = asf->index_ptr[i].offset;
321  }
322 
323  return send_time / 10000;
324 }
325 
327 {
328  ASFContext *asf = s->priv_data;
329  AVIOContext *pb = s->pb;
330  int i;
331  AVRational scale = {1, 10000000};
332  int64_t hpos = put_header(pb, &ff_asf_marker_header);
333 
334  put_guid(pb, &ff_asf_reserved_4); // ASF spec mandates this reserved value
335  avio_wl32(pb, s->nb_chapters); // markers count
336  avio_wl16(pb, 0); // ASF spec mandates 0 for this
337  avio_wl16(pb, 0); // name length 0, no name given
338 
339  for (i = 0; i < s->nb_chapters; i++) {
340  AVChapter *c = s->chapters[i];
341  AVDictionaryEntry *t = av_dict_get(c->metadata, "title", NULL, 0);
342  int64_t pres_time = av_rescale_q(c->start, c->time_base, scale);
343  uint64_t offset;
344  int32_t send_time = get_send_time(asf, pres_time, &offset);
345  int len = 0;
346  uint8_t *buf;
347  AVIOContext *dyn_buf;
348  if (t) {
349  if (avio_open_dyn_buf(&dyn_buf) < 0)
350  return AVERROR(ENOMEM);
351  avio_put_str16le(dyn_buf, t->value);
352  len = avio_close_dyn_buf(dyn_buf, &buf);
353  }
354  avio_wl64(pb, offset); // offset of the packet with send_time
355  avio_wl64(pb, pres_time + PREROLL_TIME * 10000); // presentation time
356  avio_wl16(pb, 12 + len); // entry length
357  avio_wl32(pb, send_time); // send time
358  avio_wl32(pb, 0); // flags, should be 0
359  avio_wl32(pb, len / 2); // marker desc length in WCHARS!
360  if (t) {
361  avio_write(pb, buf, len); // marker desc
362  av_freep(&buf);
363  }
364  }
365  end_header(pb, hpos);
366  return 0;
367 }
368 
369 /* write the header (used two times if non streamed) */
370 static int asf_write_header1(AVFormatContext *s, int64_t file_size,
371  int64_t data_chunk_size)
372 {
373  ASFContext *asf = s->priv_data;
374  AVIOContext *pb = s->pb;
375  AVDictionaryEntry *tags[5];
376  int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
377  int has_title;
378  int metadata_count;
379  AVCodecParameters *par;
380  int64_t header_offset, cur_pos, hpos;
381  int bit_rate;
382  uint64_t play_duration, send_duration;
383 
385 
386  tags[0] = av_dict_get(s->metadata, "title", NULL, 0);
387  tags[1] = av_dict_get(s->metadata, "author", NULL, 0);
388  tags[2] = av_dict_get(s->metadata, "copyright", NULL, 0);
389  tags[3] = av_dict_get(s->metadata, "comment", NULL, 0);
390  tags[4] = av_dict_get(s->metadata, "rating", NULL, 0);
391 
392  if (asf->duration > UINT64_MAX / 10000 - PREROLL_TIME) {
393  av_log(s, AV_LOG_WARNING, "Duration %"PRIu64" too large\n", asf->duration);
395  return AVERROR(ERANGE);
396  send_duration = 0;
397  play_duration = 0;
398  } else {
399  send_duration = asf->duration * 10000;
400  play_duration = (asf->duration + PREROLL_TIME) * 10000;
401  }
402 
403  has_title = tags[0] || tags[1] || tags[2] || tags[3] || tags[4];
404  metadata_count = av_dict_count(s->metadata);
405 
406  bit_rate = 0;
407  for (n = 0; n < s->nb_streams; n++) {
408  par = s->streams[n]->codecpar;
409 
410  avpriv_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */
411 
412  bit_rate += par->bit_rate;
413  }
414 
415  if (asf->is_streamed) {
416  put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */
417  }
418 
419  put_guid(pb, &ff_asf_header);
420  avio_wl64(pb, -1); /* header length, will be patched after */
421  avio_wl32(pb, 3 + has_title + !!metadata_count + s->nb_streams); /* number of chunks in header */
422  avio_w8(pb, 1); /* ??? */
423  avio_w8(pb, 2); /* ??? */
424 
425  /* file header */
426  header_offset = avio_tell(pb);
427  hpos = put_header(pb, &ff_asf_file_header);
428  put_guid(pb, &ff_asf_my_guid);
429  avio_wl64(pb, file_size);
430  file_time = 0;
431  avio_wl64(pb, unix_to_file_time(file_time));
432  avio_wl64(pb, asf->nb_packets); /* number of packets */
433  avio_wl64(pb, play_duration); /* end time stamp (in 100ns units) */
434  avio_wl64(pb, send_duration); /* duration (in 100ns units) */
435  avio_wl64(pb, PREROLL_TIME); /* start time stamp */
436  avio_wl32(pb, (asf->is_streamed || !pb->seekable) ? 3 : 2); /* ??? */
437  avio_wl32(pb, s->packet_size); /* packet size */
438  avio_wl32(pb, s->packet_size); /* packet size */
439  avio_wl32(pb, bit_rate); /* Nominal data rate in bps */
440  end_header(pb, hpos);
441 
442  /* unknown headers */
443  hpos = put_header(pb, &ff_asf_head1_guid);
445  avio_wl32(pb, 6);
446  avio_wl16(pb, 0);
447  end_header(pb, hpos);
448 
449  /* title and other info */
450  if (has_title) {
451  int len;
452  uint8_t *buf;
453  AVIOContext *dyn_buf;
454 
455  if (avio_open_dyn_buf(&dyn_buf) < 0)
456  return AVERROR(ENOMEM);
457 
458  hpos = put_header(pb, &ff_asf_comment_header);
459 
460  for (n = 0; n < FF_ARRAY_ELEMS(tags); n++) {
461  len = tags[n] ? avio_put_str16le(dyn_buf, tags[n]->value) : 0;
462  avio_wl16(pb, len);
463  }
464  len = avio_close_dyn_buf(dyn_buf, &buf);
465  avio_write(pb, buf, len);
466  av_freep(&buf);
467  end_header(pb, hpos);
468  }
469  if (metadata_count) {
472  avio_wl16(pb, metadata_count);
473  while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
474  put_str16(pb, tag->key);
475  avio_wl16(pb, 0);
476  put_str16(pb, tag->value);
477  }
478  end_header(pb, hpos);
479  }
480  /* chapters using ASF markers */
481  if (!asf->is_streamed && s->nb_chapters) {
482  int ret;
483  if (ret = asf_write_markers(s))
484  return ret;
485  }
486  /* stream headers */
487  for (n = 0; n < s->nb_streams; n++) {
488  int64_t es_pos;
489  // ASFStream *stream = &asf->streams[n];
490 
491  par = s->streams[n]->codecpar;
492  asf->streams[n].num = n + 1;
493  asf->streams[n].seq = 0;
494 
495  switch (par->codec_type) {
496  case AVMEDIA_TYPE_AUDIO:
497  wav_extra_size = 0;
498  extra_size = 18 + wav_extra_size;
499  extra_size2 = 8;
500  break;
501  default:
502  case AVMEDIA_TYPE_VIDEO:
503  wav_extra_size = par->extradata_size;
504  extra_size = 0x33 + wav_extra_size;
505  extra_size2 = 0;
506  break;
507  }
508 
509  hpos = put_header(pb, &ff_asf_stream_header);
510  if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
513  } else {
516  }
517  avio_wl64(pb, 0); /* ??? */
518  es_pos = avio_tell(pb);
519  avio_wl32(pb, extra_size); /* wav header len */
520  avio_wl32(pb, extra_size2); /* additional data len */
521  avio_wl16(pb, n + 1); /* stream number */
522  avio_wl32(pb, 0); /* ??? */
523 
524  if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
525  /* WAVEFORMATEX header */
526  int wavsize = ff_put_wav_header(s, pb, par);
527 
528  if (wavsize < 0)
529  return -1;
530  if (wavsize != extra_size) {
531  cur_pos = avio_tell(pb);
532  avio_seek(pb, es_pos, SEEK_SET);
533  avio_wl32(pb, wavsize); /* wav header len */
534  avio_seek(pb, cur_pos, SEEK_SET);
535  }
536  /* ERROR Correction */
537  avio_w8(pb, 0x01);
538  if (par->codec_id == AV_CODEC_ID_ADPCM_G726 || !par->block_align) {
539  avio_wl16(pb, 0x0190);
540  avio_wl16(pb, 0x0190);
541  } else {
542  avio_wl16(pb, par->block_align);
543  avio_wl16(pb, par->block_align);
544  }
545  avio_wl16(pb, 0x01);
546  avio_w8(pb, 0x00);
547  } else {
548  avio_wl32(pb, par->width);
549  avio_wl32(pb, par->height);
550  avio_w8(pb, 2); /* ??? */
551  avio_wl16(pb, 40 + par->extradata_size); /* size */
552 
553  /* BITMAPINFOHEADER header */
555  }
556  end_header(pb, hpos);
557  }
558 
559  /* media comments */
560 
563  avio_wl32(pb, s->nb_streams);
564  for (n = 0; n < s->nb_streams; n++) {
565  const AVCodecDescriptor *codec_desc;
566  const char *desc;
567 
568  par = s->streams[n]->codecpar;
569  codec_desc = avcodec_descriptor_get(par->codec_id);
570 
571  if (par->codec_type == AVMEDIA_TYPE_AUDIO)
572  avio_wl16(pb, 2);
573  else if (par->codec_type == AVMEDIA_TYPE_VIDEO)
574  avio_wl16(pb, 1);
575  else
576  avio_wl16(pb, -1);
577 
578  if (par->codec_id == AV_CODEC_ID_WMAV2)
579  desc = "Windows Media Audio V8";
580  else
581  desc = codec_desc ? codec_desc->name : NULL;
582 
583  if (desc) {
584  AVIOContext *dyn_buf;
585  uint8_t *buf;
586  int len;
587 
588  if (avio_open_dyn_buf(&dyn_buf) < 0)
589  return AVERROR(ENOMEM);
590 
591  avio_put_str16le(dyn_buf, desc);
592  len = avio_close_dyn_buf(dyn_buf, &buf);
593  avio_wl16(pb, len / 2); // "number of characters" = length in bytes / 2
594 
595  avio_write(pb, buf, len);
596  av_freep(&buf);
597  } else
598  avio_wl16(pb, 0);
599 
600  avio_wl16(pb, 0); /* no parameters */
601 
602  /* id */
603  if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
604  avio_wl16(pb, 2);
605  avio_wl16(pb, par->codec_tag);
606  } else {
607  avio_wl16(pb, 4);
608  avio_wl32(pb, par->codec_tag);
609  }
610  if (!par->codec_tag)
611  return -1;
612  }
613  end_header(pb, hpos);
614 
615  /* patch the header size fields */
616 
617  cur_pos = avio_tell(pb);
618  header_size = cur_pos - header_offset;
619  if (asf->is_streamed) {
620  header_size += 8 + 30 + DATA_HEADER_SIZE;
621 
622  avio_seek(pb, header_offset - 10 - 30, SEEK_SET);
623  avio_wl16(pb, header_size);
624  avio_seek(pb, header_offset - 2 - 30, SEEK_SET);
625  avio_wl16(pb, header_size);
626 
627  header_size -= 8 + 30 + DATA_HEADER_SIZE;
628  }
629  header_size += 24 + 6;
630  avio_seek(pb, header_offset - 14, SEEK_SET);
631  avio_wl64(pb, header_size);
632  avio_seek(pb, cur_pos, SEEK_SET);
633 
634  /* movie chunk, followed by packets of packet_size */
635  asf->data_offset = cur_pos;
637  avio_wl64(pb, data_chunk_size);
638  put_guid(pb, &ff_asf_my_guid);
639  avio_wl64(pb, asf->nb_packets); /* nb packets */
640  avio_w8(pb, 1); /* ??? */
641  avio_w8(pb, 1); /* ??? */
642  return 0;
643 }
644 
646 {
647  ASFContext *asf = s->priv_data;
648 
650  asf->nb_packets = 0;
651 
652  asf->last_indexed_pts = 0;
653  asf->index_ptr = av_malloc(sizeof(ASFIndex) * ASF_INDEX_BLOCK);
655  asf->nb_index_count = 0;
656  asf->maximum_packet = 0;
657 
658  /* the data-chunk-size has to be 50 (DATA_HEADER_SIZE), which is
659  * data_size - asf->data_offset at the moment this function is done.
660  * It is needed to use asf as a streamable format. */
661  if (asf_write_header1(s, 0, DATA_HEADER_SIZE) < 0) {
662  //av_free(asf);
663  av_freep(&asf->index_ptr);
664  return -1;
665  }
666 
667  avio_flush(s->pb);
668 
669  asf->packet_nb_payloads = 0;
670  asf->packet_timestamp_start = -1;
671  asf->packet_timestamp_end = -1;
672  ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
673  NULL, NULL, NULL, NULL);
674 
675  return 0;
676 }
677 
679 {
680  ASFContext *asf = s->priv_data;
681 
682  asf->is_streamed = 1;
683 
684  return asf_write_header(s);
685 }
686 
688  unsigned sendtime, unsigned duration,
689  int nb_payloads, int padsize)
690 {
691  ASFContext *asf = s->priv_data;
692  AVIOContext *pb = s->pb;
693  int ppi_size, i;
694  int64_t start = avio_tell(pb);
695 
696  int iLengthTypeFlags = ASF_PPI_LENGTH_TYPE_FLAGS;
697 
698  padsize -= PACKET_HEADER_MIN_SIZE;
699  if (asf->multi_payloads_present)
700  padsize--;
701  assert(padsize >= 0);
702 
704  for (i = 0; i < ASF_PACKET_ERROR_CORRECTION_DATA_SIZE; i++)
705  avio_w8(pb, 0x0);
706 
707  if (asf->multi_payloads_present)
708  iLengthTypeFlags |= ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT;
709 
710  if (padsize > 0) {
711  if (padsize < 256)
712  iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE;
713  else
714  iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD;
715  }
716  avio_w8(pb, iLengthTypeFlags);
717 
719 
720  if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD)
721  avio_wl16(pb, padsize - 2);
722  if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE)
723  avio_w8(pb, padsize - 1);
724 
725  avio_wl32(pb, sendtime);
726  avio_wl16(pb, duration);
727  if (asf->multi_payloads_present)
728  avio_w8(pb, nb_payloads | ASF_PAYLOAD_FLAGS);
729 
730  ppi_size = avio_tell(pb) - start;
731 
732  return ppi_size;
733 }
734 
736 {
737  ASFContext *asf = s->priv_data;
738  int packet_hdr_size, packet_filled_size;
739 
740  assert(asf->packet_timestamp_end >= asf->packet_timestamp_start);
741 
742  if (asf->is_streamed)
743  put_chunk(s, 0x4424, s->packet_size, 0);
744 
745  packet_hdr_size = put_payload_parsing_info(s,
747  asf->packet_timestamp_end -
749  asf->packet_nb_payloads,
750  asf->packet_size_left);
751 
752  packet_filled_size = PACKET_SIZE - asf->packet_size_left;
753  assert(packet_hdr_size <= asf->packet_size_left);
754  memset(asf->packet_buf + packet_filled_size, 0, asf->packet_size_left);
755 
756  avio_write(s->pb, asf->packet_buf, s->packet_size - packet_hdr_size);
757 
758  avio_flush(s->pb);
759  asf->nb_packets++;
760  asf->packet_nb_payloads = 0;
761  asf->packet_timestamp_start = -1;
762  asf->packet_timestamp_end = -1;
763  ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
764  NULL, NULL, NULL, NULL);
765 }
766 
768  int presentation_time, int m_obj_size,
769  int m_obj_offset, int payload_len, int flags)
770 {
771  ASFContext *asf = s->priv_data;
772  AVIOContext *pb = &asf->pb;
773  int val;
774 
775  val = stream->num;
776  if (flags & AV_PKT_FLAG_KEY)
777  val |= ASF_PL_FLAG_KEY_FRAME;
778  avio_w8(pb, val);
779 
780  avio_w8(pb, stream->seq); // Media object number
781  avio_wl32(pb, m_obj_offset); // Offset Into Media Object
782 
783  // Replicated Data shall be at least 8 bytes long.
784  // The first 4 bytes of data shall contain the
785  // Size of the Media Object that the payload belongs to.
786  // The next 4 bytes of data shall contain the
787  // Presentation Time for the media object that the payload belongs to.
789 
790  avio_wl32(pb, m_obj_size); // Replicated Data - Media Object Size
791  avio_wl32(pb, presentation_time); // Replicated Data - Presentation Time
792 
793  if (asf->multi_payloads_present) {
794  avio_wl16(pb, payload_len); // payload length
795  }
796 }
797 
798 static void put_frame(AVFormatContext *s, ASFStream *stream, AVStream *avst,
799  int timestamp, const uint8_t *buf,
800  int m_obj_size, int flags)
801 {
802  ASFContext *asf = s->priv_data;
803  int m_obj_offset, payload_len, frag_len1;
804 
805  m_obj_offset = 0;
806  while (m_obj_offset < m_obj_size) {
807  payload_len = m_obj_size - m_obj_offset;
808  if (asf->packet_timestamp_start == -1) {
809  asf->multi_payloads_present = (payload_len < MULTI_PAYLOAD_CONSTANT);
810 
812  if (asf->multi_payloads_present) {
813  frag_len1 = MULTI_PAYLOAD_CONSTANT - 1;
814  } else {
815  frag_len1 = SINGLE_PAYLOAD_DATA_LENGTH;
816  }
818  } else {
819  // multi payloads
820  frag_len1 = asf->packet_size_left -
823 
824  if (frag_len1 < payload_len &&
826  flush_packet(s);
827  continue;
828  }
829  }
830  if (frag_len1 > 0) {
831  if (payload_len > frag_len1)
832  payload_len = frag_len1;
833  else if (payload_len == (frag_len1 - 1))
834  payload_len = frag_len1 - 2; // additional byte need to put padding length
835 
836  put_payload_header(s, stream, timestamp + PREROLL_TIME,
837  m_obj_size, m_obj_offset, payload_len, flags);
838  avio_write(&asf->pb, buf, payload_len);
839 
840  if (asf->multi_payloads_present)
842  else
845 
846  asf->packet_nb_payloads++;
847  } else {
848  payload_len = 0;
849  }
850  m_obj_offset += payload_len;
851  buf += payload_len;
852 
853  if (!asf->multi_payloads_present)
854  flush_packet(s);
856  flush_packet(s);
857  }
858  stream->seq++;
859 }
860 
862 {
863  ASFContext *asf = s->priv_data;
864  AVIOContext *pb = s->pb;
865  ASFStream *stream;
866  AVCodecParameters *par;
867  int64_t packet_st, pts;
868  int start_sec, i;
869  int flags = pkt->flags;
870  uint64_t offset = avio_tell(pb);
871 
872  par = s->streams[pkt->stream_index]->codecpar;
873  stream = &asf->streams[pkt->stream_index];
874 
875  if (par->codec_type == AVMEDIA_TYPE_AUDIO)
876  flags &= ~AV_PKT_FLAG_KEY;
877 
878  pts = (pkt->pts != AV_NOPTS_VALUE) ? pkt->pts : pkt->dts;
879  assert(pts != AV_NOPTS_VALUE);
880 
881  if (pts > UINT64_MAX - pkt->duration)
882  return AVERROR(ERANGE);
883  asf->duration = FFMAX(asf->duration, pts + pkt->duration);
884 
885  packet_st = asf->nb_packets;
886  put_frame(s, stream, s->streams[pkt->stream_index],
887  pkt->dts, pkt->data, pkt->size, flags);
888 
889  /* check index */
890  if ((!asf->is_streamed) && (flags & AV_PKT_FLAG_KEY)) {
891  if (pts / 1000LL > INT_MAX)
892  return AVERROR(ERANGE);
893 
894  start_sec = pts / 1000;
895  if (start_sec != asf->last_indexed_pts / 1000) {
896  for (i = asf->nb_index_count; i < start_sec; i++) {
897  if (i >= asf->nb_index_memory_alloc) {
898  int err;
900  if ((err = av_reallocp_array(&asf->index_ptr,
902  sizeof(*asf->index_ptr))) < 0) {
903  asf->nb_index_memory_alloc = 0;
904  return err;
905  }
906  }
907  // store
908  asf->index_ptr[i].packet_number = (uint32_t)packet_st;
909  asf->index_ptr[i].packet_count = (uint16_t)(asf->nb_packets - packet_st);
910  asf->index_ptr[i].send_time = start_sec * INT64_C(10000000);
911  asf->index_ptr[i].offset = offset;
912  asf->maximum_packet = FFMAX(asf->maximum_packet,
913  (uint16_t)(asf->nb_packets - packet_st));
914  }
915  asf->nb_index_count = start_sec;
916  asf->last_indexed_pts = pts;
917  }
918  }
919  return 0;
920 }
921 
923  uint16_t max, uint32_t count)
924 {
925  AVIOContext *pb = s->pb;
926  int i;
927 
929  avio_wl64(pb, 24 + 16 + 8 + 4 + 4 + (4 + 2) * count);
930  put_guid(pb, &ff_asf_my_guid);
932  avio_wl32(pb, max);
933  avio_wl32(pb, count);
934  for (i = 0; i < count; i++) {
935  avio_wl32(pb, index[i].packet_number);
936  avio_wl16(pb, index[i].packet_count);
937  }
938 
939  return 0;
940 }
941 
943 {
944  ASFContext *asf = s->priv_data;
945  int64_t file_size, data_size;
946 
947  /* flush the current packet */
948  if (asf->pb.buf_ptr > asf->pb.buffer)
949  flush_packet(s);
950 
951  /* write index */
952  data_size = avio_tell(s->pb);
953  if ((!asf->is_streamed) && (asf->nb_index_count != 0))
955  avio_flush(s->pb);
956 
957  if (asf->is_streamed || !s->pb->seekable) {
958  put_chunk(s, 0x4524, 0, 0); /* end of stream */
959  } else {
960  /* rewrite an updated header */
961  file_size = avio_tell(s->pb);
962  avio_seek(s->pb, 0, SEEK_SET);
963  asf_write_header1(s, file_size, data_size - asf->data_offset);
964  }
965 
966  av_free(asf->index_ptr);
967  return 0;
968 }
969 
970 #if CONFIG_ASF_MUXER
971 AVOutputFormat ff_asf_muxer = {
972  .name = "asf",
973  .long_name = NULL_IF_CONFIG_SMALL("ASF (Advanced / Active Streaming Format)"),
974  .mime_type = "video/x-ms-asf",
975  .extensions = "asf,wmv,wma",
976  .priv_data_size = sizeof(ASFContext),
978  .video_codec = AV_CODEC_ID_MSMPEG4V3,
983  .codec_tag = (const AVCodecTag * const []) {
985  },
986 };
987 #endif /* CONFIG_ASF_MUXER */
988 
989 #if CONFIG_ASF_STREAM_MUXER
990 AVOutputFormat ff_asf_stream_muxer = {
991  .name = "asf_stream",
992  .long_name = NULL_IF_CONFIG_SMALL("ASF (Advanced / Active Streaming Format)"),
993  .mime_type = "video/x-ms-asf",
994  .extensions = "asf,wmv,wma",
995  .priv_data_size = sizeof(ASFContext),
997  .video_codec = AV_CODEC_ID_MSMPEG4V3,
1002  .codec_tag = (const AVCodecTag * const []) {
1004  },
1005 };
1006 #endif /* CONFIG_ASF_STREAM_MUXER */
unsigned int nb_chapters
Number of chapters in AVChapter array.
Definition: avformat.h:1137
const ff_asf_guid ff_asf_header
Definition: asf.c:23
ASFStream streams[128]
it&#39;s max number and it&#39;s not that big
Definition: asfenc.c:211
unsigned int packet_size
Definition: avformat.h:1044
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:398
static int asf_write_markers(AVFormatContext *s)
Definition: asfenc.c:326
#define CONFIG_LIBMP3LAME
Definition: config.h:368
Bytestream IO Context.
Definition: avio.h:104
#define ASF_PAYLOAD_FLAGS
Definition: asfenc.c:56
int64_t data_offset
Definition: asfdec.c:113
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1155
const ff_asf_guid ff_asf_codec_comment_header
Definition: asf.c:73
#define PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD
Definition: asfenc.c:160
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:130
unsigned char * buf_ptr
Current position in the buffer.
Definition: avio.h:120
unsigned int packet_nb_payloads
Definition: asfenc.c:220
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:2986
static int64_t unix_to_file_time(int ti)
Definition: asfenc.c:302
const char * desc
Definition: nvenc.c:101
int is_streamed
Definition: asfenc.c:210
#define PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS
Definition: asfenc.c:167
int num
Definition: asfenc.c:189
Definition: asf.h:57
static int asf_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: asfenc.c:861
uint64_t data_offset
beginning of the first data packet
Definition: asfenc.c:224
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3483
int size
Definition: avcodec.h:1347
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
Definition: dict.c:33
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:242
int palette_changed
Definition: asfenc.c:204
unsigned char * buffer
Start of the buffer.
Definition: avio.h:118
static int put_payload_parsing_info(AVFormatContext *s, unsigned sendtime, unsigned duration, int nb_payloads, int padsize)
Definition: asfenc.c:687
int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par)
Definition: riffenc.c:50
uint16_t maximum_packet
Definition: asfenc.c:230
#define FF_ARRAY_ELEMS(a)
static int asf_write_trailer(AVFormatContext *s)
Definition: asfenc.c:942
uint64_t offset
Definition: asf.h:61
AVDictionary * metadata
Definition: avformat.h:927
uint32_t packet_number
Definition: asf.h:58
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1143
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3475
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:202
const ff_asf_guid ff_asf_reserved_4
Definition: asf.c:120
Format I/O context.
Definition: avformat.h:940
const ff_asf_guid ff_asf_data_header
Definition: asf.c:80
Public dictionary API.
#define ASF_INDEX_BLOCK
Definition: asfenc.c:35
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:316
AVIOContext pb
Definition: asfenc.c:222
uint8_t
int width
Video only.
Definition: avcodec.h:3525
const ff_asf_guid ff_asf_audio_stream
Definition: asf.c:39
static void put_payload_header(AVFormatContext *s, ASFStream *stream, int presentation_time, int m_obj_size, int m_obj_offset, int payload_len, int flags)
Definition: asfenc.c:767
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1364
static int asf_write_header(AVFormatContext *s)
Definition: asfenc.c:645
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1008
int64_t duration
Definition: movenc.c:63
uint32_t nb_index_count
Definition: asfenc.c:228
int packet_size_left
Definition: asfenc.c:217
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:38
uint8_t * data
Definition: avcodec.h:1346
static int flags
Definition: log.c:50
uint32_t tag
Definition: movenc.c:854
AVPacket pkt
Definition: asfenc.c:192
#define ASF_PPI_LENGTH_TYPE_FLAGS
Definition: asfenc.c:54
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:295
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:221
static int write_trailer(AVFormatContext *s)
Definition: assenc.c:64
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1378
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:386
int64_t last_indexed_pts
Definition: asfenc.c:226
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:99
uint32_t seqno
Definition: asfenc.c:209
static int asf_write_index(AVFormatContext *s, ASFIndex *index, uint16_t max, uint32_t count)
Definition: asfenc.c:922
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:168
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1148
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:190
#define PREROLL_TIME
Definition: asfenc.c:240
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
#define DATA_HEADER_SIZE
Definition: asfenc.c:186
int type
Definition: asfdec.c:79
#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:148
g
Definition: yuv2rgb.c:546
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: avcodec.h:479
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3479
const ff_asf_guid ff_asf_video_conceal_none
Definition: asf.c:61
int ds_chunk_size
Definition: asfenc.c:198
AVChapter ** chapters
Definition: avformat.h:1138
#define ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD
Definition: asf.h:124
int frag_offset
Definition: asfenc.c:193
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:374
#define FFMAX(a, b)
Definition: common.h:64
int index
Definition: asfdec.c:78
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1352
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:2462
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3501
int bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: avcodec.h:3512
static void put_guid(AVIOContext *s, const ff_asf_guid *g)
Definition: asfenc.c:242
#define ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT
Definition: asf.h:116
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:996
int packet_timestamp_start
Definition: asfenc.c:218
int block_align
Audio only.
Definition: avcodec.h:3571
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:153
uint32_t palette[256]
Definition: asfenc.c:205
int void avio_flush(AVIOContext *s)
Definition: aviobuf.c:236
uint64_t duration
in ms
Definition: asfenc.c:214
uint64_t send_time
Definition: asf.h:60
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:29
static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
Definition: asfenc.c:285
#define ASF_PACKET_ERROR_CORRECTION_FLAGS
Definition: asfenc.c:38
const ff_asf_guid ff_asf_extended_content_header
Definition: asf.c:92
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:419
static int32_t get_send_time(ASFContext *asf, int64_t pres_time, uint64_t *offset)
Definition: asfenc.c:311
const char * name
Definition: avformat.h:450
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
int timestamp
Definition: asfenc.c:194
int32_t
#define ASF_PAYLOAD_REPLICATED_DATA_LENGTH
Definition: asfenc.c:158
#define AV_EF_EXPLODE
Definition: avcodec.h:2681
const ff_asf_guid ff_asf_my_guid
Definition: asf.c:126
#define ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE
Definition: asf.h:123
uint8_t ff_asf_guid[16]
Definition: riff.h:71
Stream structure.
Definition: avformat.h:705
NULL
Definition: eval.c:55
#define ASF_PACKET_ERROR_CORRECTION_DATA_SIZE
Definition: asfenc.c:37
uint8_t packet_buf[PACKET_SIZE]
Definition: asfenc.c:221
#define ASF_PPI_PROPERTY_FLAGS
Definition: asfenc.c:48
int packet_timestamp_end
Definition: asfenc.c:219
int ds_span
Definition: asfenc.c:196
const ff_asf_guid ff_asf_file_header
Definition: asf.c:27
#define SINGLE_PAYLOAD_DATA_LENGTH
Definition: asfenc.c:175
AVIOContext * pb
I/O context.
Definition: avformat.h:982
const ff_asf_guid ff_asf_video_stream
Definition: asf.c:53
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:200
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
Definition: avconv.c:278
uint16_t stream_language_index
Definition: asfenc.c:202
static void flush_packet(AVFormatContext *s)
Definition: asfenc.c:735
rational number numerator/denominator
Definition: rational.h:43
int ds_packet_size
Definition: asfenc.c:197
const ff_asf_guid ff_asf_stream_header
Definition: asf.c:31
static const AVCodecTag codec_asf_bmp_tags[]
Definition: asfenc.c:233
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
void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par, const AVCodecTag *tags, int for_asf)
Definition: riffenc.c:183
const char * name
Name of the codec described by this descriptor.
Definition: avcodec.h:588
static int64_t put_header(AVIOContext *pb, const ff_asf_guid *g)
Definition: asfenc.c:263
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:580
#define ASF_INDEXED_INTERVAL
Definition: asfenc.c:34
const ff_asf_guid ff_asf_comment_header
Definition: asf.c:69
ASFPacket pkt
Definition: asfdec.c:85
static int64_t pts
Global timestamp for the audio frames.
ASFIndex * index_ptr
Definition: asfenc.c:227
int64_t start
Definition: avformat.h:926
int64_t packet_pos
Definition: asfenc.c:200
#define MULTI_PAYLOAD_CONSTANT
Definition: asfenc.c:180
Main libavformat public API header.
static void end_header(AVIOContext *pb, int64_t pos)
Definition: asfenc.c:274
#define ASF_PL_FLAG_KEY_FRAME
Definition: asf.h:156
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:109
uint64_t nb_packets
how many packets are there in the file, invalid if broadcasting
Definition: asfdec.c:100
int error_recognition
Error recognition; higher values will detect more errors but may misdetect some more or less valid pa...
Definition: avformat.h:1170
unsigned char seq
Definition: asfenc.c:190
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:925
char * key
Definition: dict.h:73
void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition: metadata.c:26
static void put_frame(AVFormatContext *s, ASFStream *stream, AVStream *avst, int timestamp, const uint8_t *buf, int m_obj_size, int flags)
Definition: asfenc.c:798
static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size)
Definition: asfenc.c:370
char * value
Definition: dict.h:74
int len
void * priv_data
Format private data.
Definition: avformat.h:968
uint32_t nb_index_memory_alloc
Definition: asfenc.c:229
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:373
#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:1345
int duration
Definition: asfdec.c:103
static int asf_write_stream_header(AVFormatContext *s)
Definition: asfenc.c:678
static void put_str16(AVIOContext *s, const char *tag)
Definition: asfenc.c:248
#define AV_DICT_IGNORE_SUFFIX
Definition: dict.h:60
uint16_t packet_count
Definition: asf.h:59
AVCodecParameters * codecpar
Definition: avformat.h:831
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: avcodec.h:3487
#define PACKET_HEADER_MIN_SIZE
Definition: asfenc.c:146
const ff_asf_guid ff_asf_marker_header
Definition: asf.c:116
int stream_index
Definition: avcodec.h:1348
unsigned char multi_payloads_present
Definition: asfenc.c:216
#define MKTAG(a, b, c, d)
Definition: common.h:256
This structure stores compressed data.
Definition: avcodec.h:1323
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1339
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:235