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 {
189  uint32_t seqno;
191  ASFStream streams[128];
192  /* non streamed additonnal info */
193  uint64_t nb_packets;
194  uint64_t duration;
195  /* packet filling */
196  unsigned char multi_payloads_present;
197  int packet_size_left;
200  unsigned int packet_nb_payloads;
201  uint8_t packet_buf[PACKET_SIZE];
203  /* only for reading */
204  uint64_t data_offset;
205 
208  uint32_t nb_index_count;
210  uint16_t maximum_packet;
211 } ASFContext;
212 
213 static const AVCodecTag codec_asf_bmp_tags[] = {
214  { AV_CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
215  { AV_CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
216  { AV_CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
217  { AV_CODEC_ID_NONE, 0 },
218 };
219 
220 #define PREROLL_TIME 3100
221 
222 static void put_guid(AVIOContext *s, const ff_asf_guid *g)
223 {
224  assert(sizeof(*g) == 16);
225  avio_write(s, *g, sizeof(*g));
226 }
227 
228 static void put_str16(AVIOContext *s, const char *tag)
229 {
230  int len;
231  uint8_t *pb;
232  AVIOContext *dyn_buf;
233  if (avio_open_dyn_buf(&dyn_buf) < 0)
234  return;
235 
236  avio_put_str16le(dyn_buf, tag);
237  len = avio_close_dyn_buf(dyn_buf, &pb);
238  avio_wl16(s, len);
239  avio_write(s, pb, len);
240  av_freep(&pb);
241 }
242 
243 static int64_t put_header(AVIOContext *pb, const ff_asf_guid *g)
244 {
245  int64_t pos;
246 
247  pos = avio_tell(pb);
248  put_guid(pb, g);
249  avio_wl64(pb, 24);
250  return pos;
251 }
252 
253 /* update header size */
254 static void end_header(AVIOContext *pb, int64_t pos)
255 {
256  int64_t pos1;
257 
258  pos1 = avio_tell(pb);
259  avio_seek(pb, pos + 16, SEEK_SET);
260  avio_wl64(pb, pos1 - pos);
261  avio_seek(pb, pos1, SEEK_SET);
262 }
263 
264 /* write an asf chunk (only used in streaming case) */
265 static void put_chunk(AVFormatContext *s, int type,
266  int payload_length, int flags)
267 {
268  ASFContext *asf = s->priv_data;
269  AVIOContext *pb = s->pb;
270  int length;
271 
272  length = payload_length + 8;
273  avio_wl16(pb, type);
274  avio_wl16(pb, length); // size
275  avio_wl32(pb, asf->seqno); // sequence number
276  avio_wl16(pb, flags); // unknown bytes
277  avio_wl16(pb, length); // size_confirm
278  asf->seqno++;
279 }
280 
281 /* convert from unix to windows time */
282 static int64_t unix_to_file_time(int ti)
283 {
284  int64_t t;
285 
286  t = ti * INT64_C(10000000);
287  t += INT64_C(116444736000000000);
288  return t;
289 }
290 
291 static int32_t get_send_time(ASFContext *asf, int64_t pres_time, uint64_t *offset)
292 {
293  int i;
294  int32_t send_time = 0;
295  *offset = asf->data_offset + DATA_HEADER_SIZE;
296  for (i = 0; i < asf->nb_index_count; i++) {
297  if (pres_time <= asf->index_ptr[i].send_time)
298  break;
299  send_time = asf->index_ptr[i].send_time;
300  *offset = asf->index_ptr[i].offset;
301  }
302 
303  return send_time / 10000;
304 }
305 
307 {
308  ASFContext *asf = s->priv_data;
309  AVIOContext *pb = s->pb;
310  int i;
311  AVRational scale = {1, 10000000};
312  int64_t hpos = put_header(pb, &ff_asf_marker_header);
313 
314  put_guid(pb, &ff_asf_reserved_4); // ASF spec mandates this reserved value
315  avio_wl32(pb, s->nb_chapters); // markers count
316  avio_wl16(pb, 0); // ASF spec mandates 0 for this
317  avio_wl16(pb, 0); // name length 0, no name given
318 
319  for (i = 0; i < s->nb_chapters; i++) {
320  AVChapter *c = s->chapters[i];
321  AVDictionaryEntry *t = av_dict_get(c->metadata, "title", NULL, 0);
322  int64_t pres_time = av_rescale_q(c->start, c->time_base, scale);
323  uint64_t offset;
324  int32_t send_time = get_send_time(asf, pres_time, &offset);
325  int len = 0;
326  uint8_t *buf;
327  AVIOContext *dyn_buf;
328  if (t) {
329  if (avio_open_dyn_buf(&dyn_buf) < 0)
330  return AVERROR(ENOMEM);
331  avio_put_str16le(dyn_buf, t->value);
332  len = avio_close_dyn_buf(dyn_buf, &buf);
333  }
334  avio_wl64(pb, offset); // offset of the packet with send_time
335  avio_wl64(pb, pres_time + PREROLL_TIME * 10000); // presentation time
336  avio_wl16(pb, 12 + len); // entry length
337  avio_wl32(pb, send_time); // send time
338  avio_wl32(pb, 0); // flags, should be 0
339  avio_wl32(pb, len / 2); // marker desc length in WCHARS!
340  if (t) {
341  avio_write(pb, buf, len); // marker desc
342  av_freep(&buf);
343  }
344  }
345  end_header(pb, hpos);
346  return 0;
347 }
348 
349 /* write the header (used two times if non streamed) */
350 static int asf_write_header1(AVFormatContext *s, int64_t file_size,
351  int64_t data_chunk_size)
352 {
353  ASFContext *asf = s->priv_data;
354  AVIOContext *pb = s->pb;
355  AVDictionaryEntry *tags[5];
356  int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
357  int has_title;
358  int metadata_count;
359  AVCodecContext *enc;
360  int64_t header_offset, cur_pos, hpos;
361  int bit_rate;
362  uint64_t play_duration, send_duration;
363 
365 
366  tags[0] = av_dict_get(s->metadata, "title", NULL, 0);
367  tags[1] = av_dict_get(s->metadata, "author", NULL, 0);
368  tags[2] = av_dict_get(s->metadata, "copyright", NULL, 0);
369  tags[3] = av_dict_get(s->metadata, "comment", NULL, 0);
370  tags[4] = av_dict_get(s->metadata, "rating", NULL, 0);
371 
372  if (asf->duration > UINT64_MAX / 10000 - PREROLL_TIME) {
373  av_log(s, AV_LOG_WARNING, "Duration %"PRIu64" too large\n", asf->duration);
375  return AVERROR(ERANGE);
376  send_duration = 0;
377  play_duration = 0;
378  } else {
379  send_duration = asf->duration * 10000;
380  play_duration = (asf->duration + PREROLL_TIME) * 10000;
381  }
382 
383  has_title = tags[0] || tags[1] || tags[2] || tags[3] || tags[4];
384  metadata_count = av_dict_count(s->metadata);
385 
386  bit_rate = 0;
387  for (n = 0; n < s->nb_streams; n++) {
388  enc = s->streams[n]->codec;
389 
390  avpriv_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */
391 
392  bit_rate += enc->bit_rate;
393  }
394 
395  if (asf->is_streamed) {
396  put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */
397  }
398 
399  put_guid(pb, &ff_asf_header);
400  avio_wl64(pb, -1); /* header length, will be patched after */
401  avio_wl32(pb, 3 + has_title + !!metadata_count + s->nb_streams); /* number of chunks in header */
402  avio_w8(pb, 1); /* ??? */
403  avio_w8(pb, 2); /* ??? */
404 
405  /* file header */
406  header_offset = avio_tell(pb);
407  hpos = put_header(pb, &ff_asf_file_header);
408  put_guid(pb, &ff_asf_my_guid);
409  avio_wl64(pb, file_size);
410  file_time = 0;
411  avio_wl64(pb, unix_to_file_time(file_time));
412  avio_wl64(pb, asf->nb_packets); /* number of packets */
413  avio_wl64(pb, play_duration); /* end time stamp (in 100ns units) */
414  avio_wl64(pb, send_duration); /* duration (in 100ns units) */
415  avio_wl64(pb, PREROLL_TIME); /* start time stamp */
416  avio_wl32(pb, (asf->is_streamed || !pb->seekable) ? 3 : 2); /* ??? */
417  avio_wl32(pb, s->packet_size); /* packet size */
418  avio_wl32(pb, s->packet_size); /* packet size */
419  avio_wl32(pb, bit_rate); /* Nominal data rate in bps */
420  end_header(pb, hpos);
421 
422  /* unknown headers */
423  hpos = put_header(pb, &ff_asf_head1_guid);
425  avio_wl32(pb, 6);
426  avio_wl16(pb, 0);
427  end_header(pb, hpos);
428 
429  /* title and other infos */
430  if (has_title) {
431  int len;
432  uint8_t *buf;
433  AVIOContext *dyn_buf;
434 
435  if (avio_open_dyn_buf(&dyn_buf) < 0)
436  return AVERROR(ENOMEM);
437 
438  hpos = put_header(pb, &ff_asf_comment_header);
439 
440  for (n = 0; n < FF_ARRAY_ELEMS(tags); n++) {
441  len = tags[n] ? avio_put_str16le(dyn_buf, tags[n]->value) : 0;
442  avio_wl16(pb, len);
443  }
444  len = avio_close_dyn_buf(dyn_buf, &buf);
445  avio_write(pb, buf, len);
446  av_freep(&buf);
447  end_header(pb, hpos);
448  }
449  if (metadata_count) {
452  avio_wl16(pb, metadata_count);
453  while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
454  put_str16(pb, tag->key);
455  avio_wl16(pb, 0);
456  put_str16(pb, tag->value);
457  }
458  end_header(pb, hpos);
459  }
460  /* chapters using ASF markers */
461  if (!asf->is_streamed && s->nb_chapters) {
462  int ret;
463  if (ret = asf_write_markers(s))
464  return ret;
465  }
466  /* stream headers */
467  for (n = 0; n < s->nb_streams; n++) {
468  int64_t es_pos;
469  // ASFStream *stream = &asf->streams[n];
470 
471  enc = s->streams[n]->codec;
472  asf->streams[n].num = n + 1;
473  asf->streams[n].seq = 0;
474 
475  switch (enc->codec_type) {
476  case AVMEDIA_TYPE_AUDIO:
477  wav_extra_size = 0;
478  extra_size = 18 + wav_extra_size;
479  extra_size2 = 8;
480  break;
481  default:
482  case AVMEDIA_TYPE_VIDEO:
483  wav_extra_size = enc->extradata_size;
484  extra_size = 0x33 + wav_extra_size;
485  extra_size2 = 0;
486  break;
487  }
488 
489  hpos = put_header(pb, &ff_asf_stream_header);
490  if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
493  } else {
496  }
497  avio_wl64(pb, 0); /* ??? */
498  es_pos = avio_tell(pb);
499  avio_wl32(pb, extra_size); /* wav header len */
500  avio_wl32(pb, extra_size2); /* additional data len */
501  avio_wl16(pb, n + 1); /* stream number */
502  avio_wl32(pb, 0); /* ??? */
503 
504  if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
505  /* WAVEFORMATEX header */
506  int wavsize = ff_put_wav_header(pb, enc);
507 
508  if (wavsize < 0)
509  return -1;
510  if (wavsize != extra_size) {
511  cur_pos = avio_tell(pb);
512  avio_seek(pb, es_pos, SEEK_SET);
513  avio_wl32(pb, wavsize); /* wav header len */
514  avio_seek(pb, cur_pos, SEEK_SET);
515  }
516  /* ERROR Correction */
517  avio_w8(pb, 0x01);
518  if (enc->codec_id == AV_CODEC_ID_ADPCM_G726 || !enc->block_align) {
519  avio_wl16(pb, 0x0190);
520  avio_wl16(pb, 0x0190);
521  } else {
522  avio_wl16(pb, enc->block_align);
523  avio_wl16(pb, enc->block_align);
524  }
525  avio_wl16(pb, 0x01);
526  avio_w8(pb, 0x00);
527  } else {
528  avio_wl32(pb, enc->width);
529  avio_wl32(pb, enc->height);
530  avio_w8(pb, 2); /* ??? */
531  avio_wl16(pb, 40 + enc->extradata_size); /* size */
532 
533  /* BITMAPINFOHEADER header */
535  }
536  end_header(pb, hpos);
537  }
538 
539  /* media comments */
540 
543  avio_wl32(pb, s->nb_streams);
544  for (n = 0; n < s->nb_streams; n++) {
545  const AVCodecDescriptor *codec_desc;
546  const char *desc;
547 
548  enc = s->streams[n]->codec;
549  codec_desc = avcodec_descriptor_get(enc->codec_id);
550 
551  if (enc->codec_type == AVMEDIA_TYPE_AUDIO)
552  avio_wl16(pb, 2);
553  else if (enc->codec_type == AVMEDIA_TYPE_VIDEO)
554  avio_wl16(pb, 1);
555  else
556  avio_wl16(pb, -1);
557 
558  if (enc->codec_id == AV_CODEC_ID_WMAV2)
559  desc = "Windows Media Audio V8";
560  else
561  desc = codec_desc ? codec_desc->name : NULL;
562 
563  if (desc) {
564  AVIOContext *dyn_buf;
565  uint8_t *buf;
566  int len;
567 
568  if (avio_open_dyn_buf(&dyn_buf) < 0)
569  return AVERROR(ENOMEM);
570 
571  avio_put_str16le(dyn_buf, desc);
572  len = avio_close_dyn_buf(dyn_buf, &buf);
573  avio_wl16(pb, len / 2); // "number of characters" = length in bytes / 2
574 
575  avio_write(pb, buf, len);
576  av_freep(&buf);
577  } else
578  avio_wl16(pb, 0);
579 
580  avio_wl16(pb, 0); /* no parameters */
581 
582  /* id */
583  if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
584  avio_wl16(pb, 2);
585  avio_wl16(pb, enc->codec_tag);
586  } else {
587  avio_wl16(pb, 4);
588  avio_wl32(pb, enc->codec_tag);
589  }
590  if (!enc->codec_tag)
591  return -1;
592  }
593  end_header(pb, hpos);
594 
595  /* patch the header size fields */
596 
597  cur_pos = avio_tell(pb);
598  header_size = cur_pos - header_offset;
599  if (asf->is_streamed) {
600  header_size += 8 + 30 + DATA_HEADER_SIZE;
601 
602  avio_seek(pb, header_offset - 10 - 30, SEEK_SET);
603  avio_wl16(pb, header_size);
604  avio_seek(pb, header_offset - 2 - 30, SEEK_SET);
605  avio_wl16(pb, header_size);
606 
607  header_size -= 8 + 30 + DATA_HEADER_SIZE;
608  }
609  header_size += 24 + 6;
610  avio_seek(pb, header_offset - 14, SEEK_SET);
611  avio_wl64(pb, header_size);
612  avio_seek(pb, cur_pos, SEEK_SET);
613 
614  /* movie chunk, followed by packets of packet_size */
615  asf->data_offset = cur_pos;
617  avio_wl64(pb, data_chunk_size);
618  put_guid(pb, &ff_asf_my_guid);
619  avio_wl64(pb, asf->nb_packets); /* nb packets */
620  avio_w8(pb, 1); /* ??? */
621  avio_w8(pb, 1); /* ??? */
622  return 0;
623 }
624 
626 {
627  ASFContext *asf = s->priv_data;
628 
630  asf->nb_packets = 0;
631 
632  asf->last_indexed_pts = 0;
633  asf->index_ptr = av_malloc(sizeof(ASFIndex) * ASF_INDEX_BLOCK);
635  asf->nb_index_count = 0;
636  asf->maximum_packet = 0;
637 
638  /* the data-chunk-size has to be 50 (DATA_HEADER_SIZE), which is
639  * data_size - asf->data_offset at the moment this function is done.
640  * It is needed to use asf as a streamable format. */
641  if (asf_write_header1(s, 0, DATA_HEADER_SIZE) < 0) {
642  //av_free(asf);
643  return -1;
644  }
645 
646  avio_flush(s->pb);
647 
648  asf->packet_nb_payloads = 0;
649  asf->packet_timestamp_start = -1;
650  asf->packet_timestamp_end = -1;
651  ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
652  NULL, NULL, NULL, NULL);
653 
654  return 0;
655 }
656 
658 {
659  ASFContext *asf = s->priv_data;
660 
661  asf->is_streamed = 1;
662 
663  return asf_write_header(s);
664 }
665 
667  unsigned sendtime, unsigned duration,
668  int nb_payloads, int padsize)
669 {
670  ASFContext *asf = s->priv_data;
671  AVIOContext *pb = s->pb;
672  int ppi_size, i;
673  int64_t start = avio_tell(pb);
674 
675  int iLengthTypeFlags = ASF_PPI_LENGTH_TYPE_FLAGS;
676 
677  padsize -= PACKET_HEADER_MIN_SIZE;
678  if (asf->multi_payloads_present)
679  padsize--;
680  assert(padsize >= 0);
681 
683  for (i = 0; i < ASF_PACKET_ERROR_CORRECTION_DATA_SIZE; i++)
684  avio_w8(pb, 0x0);
685 
686  if (asf->multi_payloads_present)
687  iLengthTypeFlags |= ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT;
688 
689  if (padsize > 0) {
690  if (padsize < 256)
691  iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE;
692  else
693  iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD;
694  }
695  avio_w8(pb, iLengthTypeFlags);
696 
698 
699  if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD)
700  avio_wl16(pb, padsize - 2);
701  if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE)
702  avio_w8(pb, padsize - 1);
703 
704  avio_wl32(pb, sendtime);
705  avio_wl16(pb, duration);
706  if (asf->multi_payloads_present)
707  avio_w8(pb, nb_payloads | ASF_PAYLOAD_FLAGS);
708 
709  ppi_size = avio_tell(pb) - start;
710 
711  return ppi_size;
712 }
713 
715 {
716  ASFContext *asf = s->priv_data;
717  int packet_hdr_size, packet_filled_size;
718 
719  assert(asf->packet_timestamp_end >= asf->packet_timestamp_start);
720 
721  if (asf->is_streamed)
722  put_chunk(s, 0x4424, s->packet_size, 0);
723 
724  packet_hdr_size = put_payload_parsing_info(s,
726  asf->packet_timestamp_end -
728  asf->packet_nb_payloads,
729  asf->packet_size_left);
730 
731  packet_filled_size = PACKET_SIZE - asf->packet_size_left;
732  assert(packet_hdr_size <= asf->packet_size_left);
733  memset(asf->packet_buf + packet_filled_size, 0, asf->packet_size_left);
734 
735  avio_write(s->pb, asf->packet_buf, s->packet_size - packet_hdr_size);
736 
737  avio_flush(s->pb);
738  asf->nb_packets++;
739  asf->packet_nb_payloads = 0;
740  asf->packet_timestamp_start = -1;
741  asf->packet_timestamp_end = -1;
742  ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
743  NULL, NULL, NULL, NULL);
744 }
745 
747  int presentation_time, int m_obj_size,
748  int m_obj_offset, int payload_len, int flags)
749 {
750  ASFContext *asf = s->priv_data;
751  AVIOContext *pb = &asf->pb;
752  int val;
753 
754  val = stream->num;
755  if (flags & AV_PKT_FLAG_KEY)
756  val |= ASF_PL_FLAG_KEY_FRAME;
757  avio_w8(pb, val);
758 
759  avio_w8(pb, stream->seq); // Media object number
760  avio_wl32(pb, m_obj_offset); // Offset Into Media Object
761 
762  // Replicated Data shall be at least 8 bytes long.
763  // The first 4 bytes of data shall contain the
764  // Size of the Media Object that the payload belongs to.
765  // The next 4 bytes of data shall contain the
766  // Presentation Time for the media object that the payload belongs to.
768 
769  avio_wl32(pb, m_obj_size); // Replicated Data - Media Object Size
770  avio_wl32(pb, presentation_time); // Replicated Data - Presentation Time
771 
772  if (asf->multi_payloads_present) {
773  avio_wl16(pb, payload_len); // payload length
774  }
775 }
776 
777 static void put_frame(AVFormatContext *s, ASFStream *stream, AVStream *avst,
778  int timestamp, const uint8_t *buf,
779  int m_obj_size, int flags)
780 {
781  ASFContext *asf = s->priv_data;
782  int m_obj_offset, payload_len, frag_len1;
783 
784  m_obj_offset = 0;
785  while (m_obj_offset < m_obj_size) {
786  payload_len = m_obj_size - m_obj_offset;
787  if (asf->packet_timestamp_start == -1) {
788  asf->multi_payloads_present = (payload_len < MULTI_PAYLOAD_CONSTANT);
789 
791  if (asf->multi_payloads_present) {
792  frag_len1 = MULTI_PAYLOAD_CONSTANT - 1;
793  } else {
794  frag_len1 = SINGLE_PAYLOAD_DATA_LENGTH;
795  }
796  asf->packet_timestamp_start = timestamp;
797  } else {
798  // multi payloads
799  frag_len1 = asf->packet_size_left -
802 
803  if (frag_len1 < payload_len &&
804  avst->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
805  flush_packet(s);
806  continue;
807  }
808  }
809  if (frag_len1 > 0) {
810  if (payload_len > frag_len1)
811  payload_len = frag_len1;
812  else if (payload_len == (frag_len1 - 1))
813  payload_len = frag_len1 - 2; // additional byte need to put padding length
814 
815  put_payload_header(s, stream, timestamp + PREROLL_TIME,
816  m_obj_size, m_obj_offset, payload_len, flags);
817  avio_write(&asf->pb, buf, payload_len);
818 
819  if (asf->multi_payloads_present)
821  else
823  asf->packet_timestamp_end = timestamp;
824 
825  asf->packet_nb_payloads++;
826  } else {
827  payload_len = 0;
828  }
829  m_obj_offset += payload_len;
830  buf += payload_len;
831 
832  if (!asf->multi_payloads_present)
833  flush_packet(s);
835  flush_packet(s);
836  }
837  stream->seq++;
838 }
839 
841 {
842  ASFContext *asf = s->priv_data;
843  AVIOContext *pb = s->pb;
844  ASFStream *stream;
845  AVCodecContext *codec;
846  int64_t packet_st, pts;
847  int start_sec, i;
848  int flags = pkt->flags;
849  uint64_t offset = avio_tell(pb);
850 
851  codec = s->streams[pkt->stream_index]->codec;
852  stream = &asf->streams[pkt->stream_index];
853 
854  if (codec->codec_type == AVMEDIA_TYPE_AUDIO)
855  flags &= ~AV_PKT_FLAG_KEY;
856 
857  pts = (pkt->pts != AV_NOPTS_VALUE) ? pkt->pts : pkt->dts;
858  assert(pts != AV_NOPTS_VALUE);
859 
860  if (pts > UINT64_MAX - pkt->duration)
861  return AVERROR(ERANGE);
862  asf->duration = FFMAX(asf->duration, pts + pkt->duration);
863 
864  packet_st = asf->nb_packets;
865  put_frame(s, stream, s->streams[pkt->stream_index],
866  pkt->dts, pkt->data, pkt->size, flags);
867 
868  /* check index */
869  if ((!asf->is_streamed) && (flags & AV_PKT_FLAG_KEY)) {
870  if (pts / 1000LL > INT_MAX)
871  return AVERROR(ERANGE);
872 
873  start_sec = pts / 1000;
874  if (start_sec != asf->last_indexed_pts / 1000) {
875  for (i = asf->nb_index_count; i < start_sec; i++) {
876  if (i >= asf->nb_index_memory_alloc) {
877  int err;
879  if ((err = av_reallocp_array(&asf->index_ptr,
881  sizeof(*asf->index_ptr))) < 0) {
882  asf->nb_index_memory_alloc = 0;
883  return err;
884  }
885  }
886  // store
887  asf->index_ptr[i].packet_number = (uint32_t)packet_st;
888  asf->index_ptr[i].packet_count = (uint16_t)(asf->nb_packets - packet_st);
889  asf->index_ptr[i].send_time = start_sec * INT64_C(10000000);
890  asf->index_ptr[i].offset = offset;
891  asf->maximum_packet = FFMAX(asf->maximum_packet,
892  (uint16_t)(asf->nb_packets - packet_st));
893  }
894  asf->nb_index_count = start_sec;
895  asf->last_indexed_pts = pts;
896  }
897  }
898  return 0;
899 }
900 
902  uint16_t max, uint32_t count)
903 {
904  AVIOContext *pb = s->pb;
905  int i;
906 
908  avio_wl64(pb, 24 + 16 + 8 + 4 + 4 + (4 + 2) * count);
909  put_guid(pb, &ff_asf_my_guid);
911  avio_wl32(pb, max);
912  avio_wl32(pb, count);
913  for (i = 0; i < count; i++) {
914  avio_wl32(pb, index[i].packet_number);
915  avio_wl16(pb, index[i].packet_count);
916  }
917 
918  return 0;
919 }
920 
922 {
923  ASFContext *asf = s->priv_data;
924  int64_t file_size, data_size;
925 
926  /* flush the current packet */
927  if (asf->pb.buf_ptr > asf->pb.buffer)
928  flush_packet(s);
929 
930  /* write index */
931  data_size = avio_tell(s->pb);
932  if ((!asf->is_streamed) && (asf->nb_index_count != 0))
934  avio_flush(s->pb);
935 
936  if (asf->is_streamed || !s->pb->seekable) {
937  put_chunk(s, 0x4524, 0, 0); /* end of stream */
938  } else {
939  /* rewrite an updated header */
940  file_size = avio_tell(s->pb);
941  avio_seek(s->pb, 0, SEEK_SET);
942  asf_write_header1(s, file_size, data_size - asf->data_offset);
943  }
944 
945  av_free(asf->index_ptr);
946  return 0;
947 }
948 
949 #if CONFIG_ASF_MUXER
950 AVOutputFormat ff_asf_muxer = {
951  .name = "asf",
952  .long_name = NULL_IF_CONFIG_SMALL("ASF (Advanced / Active Streaming Format)"),
953  .mime_type = "video/x-ms-asf",
954  .extensions = "asf,wmv,wma",
955  .priv_data_size = sizeof(ASFContext),
957  .video_codec = AV_CODEC_ID_MSMPEG4V3,
962  .codec_tag = (const AVCodecTag * const []) {
964  },
965 };
966 #endif /* CONFIG_ASF_MUXER */
967 
968 #if CONFIG_ASF_STREAM_MUXER
969 AVOutputFormat ff_asf_stream_muxer = {
970  .name = "asf_stream",
971  .long_name = NULL_IF_CONFIG_SMALL("ASF (Advanced / Active Streaming Format)"),
972  .mime_type = "video/x-ms-asf",
973  .extensions = "asf,wmv,wma",
974  .priv_data_size = sizeof(ASFContext),
975  .audio_codec = CONFIG_LIBMP3LAME ? AV_CODEC_ID_MP3 : AV_CODEC_ID_MP2,
976  .video_codec = AV_CODEC_ID_MSMPEG4V3,
981  .codec_tag = (const AVCodecTag * const []) {
983  },
984 };
985 #endif /* CONFIG_ASF_STREAM_MUXER */
unsigned int nb_chapters
Number of chapters in AVChapter array.
Definition: avformat.h:1119
const ff_asf_guid ff_asf_header
Definition: asf.c:23
unsigned int packet_size
Definition: avformat.h:1026
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:347
static int asf_write_markers(AVFormatContext *s)
Definition: asfenc.c:306
Bytestream IO Context.
Definition: avio.h:68
#define ASF_PAYLOAD_FLAGS
Definition: asfenc.c:56
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:977
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:129
unsigned char * buf_ptr
Current position in the buffer.
Definition: avio.h:84
unsigned int packet_nb_payloads
Definition: asfenc.c:200
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:2829
static int64_t unix_to_file_time(int ti)
Definition: asfenc.c:282
int is_streamed
Definition: asfenc.c:190
#define PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS
Definition: asfenc.c:167
int num
Definition: asf.h:32
Definition: asf.h:78
static int write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: assenc.c:58
static int asf_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: asfenc.c:840
uint64_t data_offset
beginning of the first data packet
Definition: asfdec.c:53
int size
Definition: avcodec.h:974
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
Definition: dict.c:33
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:186
unsigned char * buffer
Start of the buffer.
Definition: avio.h:82
static int put_payload_parsing_info(AVFormatContext *s, unsigned sendtime, unsigned duration, int nb_payloads, int padsize)
Definition: asfenc.c:666
uint16_t maximum_packet
Definition: asfenc.c:210
#define FF_ARRAY_ELEMS(a)
static int asf_write_trailer(AVFormatContext *s)
Definition: asfenc.c:921
uint64_t offset
Definition: asf.h:82
AVDictionary * metadata
Definition: avformat.h:909
uint32_t packet_number
Definition: asf.h:79
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:965
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:1844
static int64_t duration
Definition: avplay.c:246
#define CONFIG_LIBMP3LAME
Definition: config.h:334
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
const ff_asf_guid ff_asf_reserved_4
Definition: asf.c:120
Format I/O context.
Definition: avformat.h:922
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:271
AVIOContext pb
Definition: asfenc.c:202
uint8_t
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:746
static int asf_write_header(AVFormatContext *s)
Definition: asfenc.c:625
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:990
uint32_t nb_index_count
Definition: asfenc.c:208
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:38
uint8_t * data
Definition: avcodec.h:973
static int flags
Definition: log.c:44
uint32_t tag
Definition: movenc.c:844
#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:219
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:165
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:991
static int write_trailer(AVFormatContext *s)
Definition: assenc.c:64
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1019
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:335
int64_t last_indexed_pts
Definition: asfenc.c:206
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:129
uint32_t seqno
Definition: asfenc.c:189
static int asf_write_index(AVFormatContext *s, ASFIndex *index, uint16_t max, uint32_t count)
Definition: asfenc.c:901
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:167
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1130
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:186
#define PREROLL_TIME
Definition: asfenc.c:220
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
#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:145
g
Definition: yuv2rgb.c:535
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: avcodec.h:379
const ff_asf_guid ff_asf_video_conceal_none
Definition: asf.c:61
AVChapter ** chapters
Definition: avformat.h:1120
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
#define ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD
Definition: asf.h:145
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:353
#define FFMAX(a, b)
Definition: common.h:55
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:979
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:2353
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:718
static void put_guid(AVIOContext *s, const ff_asf_guid *g)
Definition: asfenc.c:222
#define ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT
Definition: asf.h:137
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:978
int packet_timestamp_start
Definition: asfenc.c:198
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:117
int bit_rate
the average bitrate
Definition: avcodec.h:1114
int void avio_flush(AVIOContext *s)
Definition: aviobuf.c:180
uint64_t duration
in ms
Definition: asfenc.c:194
uint64_t send_time
Definition: asf.h:81
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:29
int width
picture width / height.
Definition: avcodec.h:1229
static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
Definition: asfenc.c:265
#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:415
static int32_t get_send_time(ASFContext *asf, int64_t pres_time, uint64_t *offset)
Definition: asfenc.c:291
const char * name
Definition: avformat.h:446
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:158
#define AV_EF_EXPLODE
Definition: avcodec.h:2433
const ff_asf_guid ff_asf_my_guid
Definition: asf.c:126
#define ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE
Definition: asf.h:144
uint8_t ff_asf_guid[16]
Definition: riff.h:70
Stream structure.
Definition: avformat.h:699
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:201
#define ASF_PPI_PROPERTY_FLAGS
Definition: asfenc.c:48
int packet_timestamp_end
Definition: asfenc.c:199
enum AVMediaType codec_type
Definition: avcodec.h:1058
const ff_asf_guid ff_asf_file_header
Definition: asf.c:27
#define SINGLE_PAYLOAD_DATA_LENGTH
Definition: asfenc.c:175
enum AVCodecID codec_id
Definition: avcodec.h:1067
AVIOContext * pb
I/O context.
Definition: avformat.h:964
const ff_asf_guid ff_asf_video_stream
Definition: asf.c:53
Definition: asf.h:31
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:144
main external API structure.
Definition: avcodec.h:1050
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1082
static void flush_packet(AVFormatContext *s)
Definition: asfenc.c:714
int extradata_size
Definition: avcodec.h:1165
int index
Definition: gxfenc.c:72
rational number numerator/denominator
Definition: rational.h:43
const ff_asf_guid ff_asf_stream_header
Definition: asf.c:31
static const AVCodecTag codec_asf_bmp_tags[]
Definition: asfenc.c:213
int avio_put_str16le(AVIOContext *s, const char *str)
Convert an UTF-8 string to UTF-16LE and write it.
Definition: aviobuf.c:298
const AVMetadataConv ff_asf_metadata_conv[]
Definition: asf.c:147
const char * name
Name of the codec described by this descriptor.
Definition: avcodec.h:486
static int64_t put_header(AVIOContext *pb, const ff_asf_guid *g)
Definition: asfenc.c:243
void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf)
Definition: riffenc.c:186
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:478
#define ASF_INDEXED_INTERVAL
Definition: asfenc.c:34
const ff_asf_guid ff_asf_comment_header
Definition: asf.c:69
ASFIndex * index_ptr
Definition: asfenc.c:207
int64_t start
Definition: avformat.h:908
#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:254
#define ASF_PL_FLAG_KEY_FRAME
Definition: asf.h:177
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:70
uint64_t nb_packets
how many packets are there in the file, invalid if broadcasting
Definition: asfenc.c:193
unsigned char seq
Definition: asf.h:33
int error_recognition
Error recognition; higher values will detect more errors but may misdetect some more or less valid pa...
Definition: avformat.h:1152
int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc)
Definition: riffenc.c:50
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:907
char * key
Definition: dict.h:75
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:777
static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size)
Definition: asfenc.c:350
char * value
Definition: dict.h:76
int len
void * priv_data
Format private data.
Definition: avformat.h:950
uint32_t nb_index_memory_alloc
Definition: asfenc.c:209
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:380
#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:972
static int asf_write_stream_header(AVFormatContext *s)
Definition: asfenc.c:657
static void put_str16(AVIOContext *s, const char *tag)
Definition: asfenc.c:228
#define AV_DICT_IGNORE_SUFFIX
Definition: dict.h:62
uint16_t packet_count
Definition: asf.h:80
#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:975
unsigned char multi_payloads_present
Definition: asfenc.c:196
#define MKTAG(a, b, c, d)
Definition: common.h:238
This structure stores compressed data.
Definition: avcodec.h:950
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:966
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:228