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  int64_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  int64_t 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  duration = asf->duration + PREROLL_TIME * 10000;
373  has_title = tags[0] || tags[1] || tags[2] || tags[3] || tags[4];
374  metadata_count = av_dict_count(s->metadata);
375 
376  bit_rate = 0;
377  for (n = 0; n < s->nb_streams; n++) {
378  enc = s->streams[n]->codec;
379 
380  avpriv_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */
381 
382  bit_rate += enc->bit_rate;
383  }
384 
385  if (asf->is_streamed) {
386  put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */
387  }
388 
389  put_guid(pb, &ff_asf_header);
390  avio_wl64(pb, -1); /* header length, will be patched after */
391  avio_wl32(pb, 3 + has_title + !!metadata_count + s->nb_streams); /* number of chunks in header */
392  avio_w8(pb, 1); /* ??? */
393  avio_w8(pb, 2); /* ??? */
394 
395  /* file header */
396  header_offset = avio_tell(pb);
397  hpos = put_header(pb, &ff_asf_file_header);
398  put_guid(pb, &ff_asf_my_guid);
399  avio_wl64(pb, file_size);
400  file_time = 0;
401  avio_wl64(pb, unix_to_file_time(file_time));
402  avio_wl64(pb, asf->nb_packets); /* number of packets */
403  avio_wl64(pb, duration); /* end time stamp (in 100ns units) */
404  avio_wl64(pb, asf->duration); /* duration (in 100ns units) */
405  avio_wl64(pb, PREROLL_TIME); /* start time stamp */
406  avio_wl32(pb, (asf->is_streamed || !pb->seekable) ? 3 : 2); /* ??? */
407  avio_wl32(pb, s->packet_size); /* packet size */
408  avio_wl32(pb, s->packet_size); /* packet size */
409  avio_wl32(pb, bit_rate); /* Nominal data rate in bps */
410  end_header(pb, hpos);
411 
412  /* unknown headers */
413  hpos = put_header(pb, &ff_asf_head1_guid);
415  avio_wl32(pb, 6);
416  avio_wl16(pb, 0);
417  end_header(pb, hpos);
418 
419  /* title and other infos */
420  if (has_title) {
421  int len;
422  uint8_t *buf;
423  AVIOContext *dyn_buf;
424 
425  if (avio_open_dyn_buf(&dyn_buf) < 0)
426  return AVERROR(ENOMEM);
427 
428  hpos = put_header(pb, &ff_asf_comment_header);
429 
430  for (n = 0; n < FF_ARRAY_ELEMS(tags); n++) {
431  len = tags[n] ? avio_put_str16le(dyn_buf, tags[n]->value) : 0;
432  avio_wl16(pb, len);
433  }
434  len = avio_close_dyn_buf(dyn_buf, &buf);
435  avio_write(pb, buf, len);
436  av_freep(&buf);
437  end_header(pb, hpos);
438  }
439  if (metadata_count) {
442  avio_wl16(pb, metadata_count);
443  while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
444  put_str16(pb, tag->key);
445  avio_wl16(pb, 0);
446  put_str16(pb, tag->value);
447  }
448  end_header(pb, hpos);
449  }
450  /* chapters using ASF markers */
451  if (!asf->is_streamed && s->nb_chapters) {
452  int ret;
453  if (ret = asf_write_markers(s))
454  return ret;
455  }
456  /* stream headers */
457  for (n = 0; n < s->nb_streams; n++) {
458  int64_t es_pos;
459  // ASFStream *stream = &asf->streams[n];
460 
461  enc = s->streams[n]->codec;
462  asf->streams[n].num = n + 1;
463  asf->streams[n].seq = 0;
464 
465  switch (enc->codec_type) {
466  case AVMEDIA_TYPE_AUDIO:
467  wav_extra_size = 0;
468  extra_size = 18 + wav_extra_size;
469  extra_size2 = 8;
470  break;
471  default:
472  case AVMEDIA_TYPE_VIDEO:
473  wav_extra_size = enc->extradata_size;
474  extra_size = 0x33 + wav_extra_size;
475  extra_size2 = 0;
476  break;
477  }
478 
479  hpos = put_header(pb, &ff_asf_stream_header);
480  if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
483  } else {
486  }
487  avio_wl64(pb, 0); /* ??? */
488  es_pos = avio_tell(pb);
489  avio_wl32(pb, extra_size); /* wav header len */
490  avio_wl32(pb, extra_size2); /* additional data len */
491  avio_wl16(pb, n + 1); /* stream number */
492  avio_wl32(pb, 0); /* ??? */
493 
494  if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
495  /* WAVEFORMATEX header */
496  int wavsize = ff_put_wav_header(pb, enc);
497 
498  if (wavsize < 0)
499  return -1;
500  if (wavsize != extra_size) {
501  cur_pos = avio_tell(pb);
502  avio_seek(pb, es_pos, SEEK_SET);
503  avio_wl32(pb, wavsize); /* wav header len */
504  avio_seek(pb, cur_pos, SEEK_SET);
505  }
506  /* ERROR Correction */
507  avio_w8(pb, 0x01);
508  if (enc->codec_id == AV_CODEC_ID_ADPCM_G726 || !enc->block_align) {
509  avio_wl16(pb, 0x0190);
510  avio_wl16(pb, 0x0190);
511  } else {
512  avio_wl16(pb, enc->block_align);
513  avio_wl16(pb, enc->block_align);
514  }
515  avio_wl16(pb, 0x01);
516  avio_w8(pb, 0x00);
517  } else {
518  avio_wl32(pb, enc->width);
519  avio_wl32(pb, enc->height);
520  avio_w8(pb, 2); /* ??? */
521  avio_wl16(pb, 40 + enc->extradata_size); /* size */
522 
523  /* BITMAPINFOHEADER header */
525  }
526  end_header(pb, hpos);
527  }
528 
529  /* media comments */
530 
533  avio_wl32(pb, s->nb_streams);
534  for (n = 0; n < s->nb_streams; n++) {
535  const AVCodecDescriptor *codec_desc;
536  const char *desc;
537 
538  enc = s->streams[n]->codec;
539  codec_desc = avcodec_descriptor_get(enc->codec_id);
540 
541  if (enc->codec_type == AVMEDIA_TYPE_AUDIO)
542  avio_wl16(pb, 2);
543  else if (enc->codec_type == AVMEDIA_TYPE_VIDEO)
544  avio_wl16(pb, 1);
545  else
546  avio_wl16(pb, -1);
547 
548  if (enc->codec_id == AV_CODEC_ID_WMAV2)
549  desc = "Windows Media Audio V8";
550  else
551  desc = codec_desc ? codec_desc->name : NULL;
552 
553  if (desc) {
554  AVIOContext *dyn_buf;
555  uint8_t *buf;
556  int len;
557 
558  if (avio_open_dyn_buf(&dyn_buf) < 0)
559  return AVERROR(ENOMEM);
560 
561  avio_put_str16le(dyn_buf, desc);
562  len = avio_close_dyn_buf(dyn_buf, &buf);
563  avio_wl16(pb, len / 2); // "number of characters" = length in bytes / 2
564 
565  avio_write(pb, buf, len);
566  av_freep(&buf);
567  } else
568  avio_wl16(pb, 0);
569 
570  avio_wl16(pb, 0); /* no parameters */
571 
572  /* id */
573  if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
574  avio_wl16(pb, 2);
575  avio_wl16(pb, enc->codec_tag);
576  } else {
577  avio_wl16(pb, 4);
578  avio_wl32(pb, enc->codec_tag);
579  }
580  if (!enc->codec_tag)
581  return -1;
582  }
583  end_header(pb, hpos);
584 
585  /* patch the header size fields */
586 
587  cur_pos = avio_tell(pb);
588  header_size = cur_pos - header_offset;
589  if (asf->is_streamed) {
590  header_size += 8 + 30 + DATA_HEADER_SIZE;
591 
592  avio_seek(pb, header_offset - 10 - 30, SEEK_SET);
593  avio_wl16(pb, header_size);
594  avio_seek(pb, header_offset - 2 - 30, SEEK_SET);
595  avio_wl16(pb, header_size);
596 
597  header_size -= 8 + 30 + DATA_HEADER_SIZE;
598  }
599  header_size += 24 + 6;
600  avio_seek(pb, header_offset - 14, SEEK_SET);
601  avio_wl64(pb, header_size);
602  avio_seek(pb, cur_pos, SEEK_SET);
603 
604  /* movie chunk, followed by packets of packet_size */
605  asf->data_offset = cur_pos;
607  avio_wl64(pb, data_chunk_size);
608  put_guid(pb, &ff_asf_my_guid);
609  avio_wl64(pb, asf->nb_packets); /* nb packets */
610  avio_w8(pb, 1); /* ??? */
611  avio_w8(pb, 1); /* ??? */
612  return 0;
613 }
614 
616 {
617  ASFContext *asf = s->priv_data;
618 
620  asf->nb_packets = 0;
621 
622  asf->last_indexed_pts = 0;
623  asf->index_ptr = av_malloc(sizeof(ASFIndex) * ASF_INDEX_BLOCK);
625  asf->nb_index_count = 0;
626  asf->maximum_packet = 0;
627 
628  /* the data-chunk-size has to be 50 (DATA_HEADER_SIZE), which is
629  * data_size - asf->data_offset at the moment this function is done.
630  * It is needed to use asf as a streamable format. */
631  if (asf_write_header1(s, 0, DATA_HEADER_SIZE) < 0) {
632  //av_free(asf);
633  return -1;
634  }
635 
636  avio_flush(s->pb);
637 
638  asf->packet_nb_payloads = 0;
639  asf->packet_timestamp_start = -1;
640  asf->packet_timestamp_end = -1;
641  ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
642  NULL, NULL, NULL, NULL);
643 
644  return 0;
645 }
646 
648 {
649  ASFContext *asf = s->priv_data;
650 
651  asf->is_streamed = 1;
652 
653  return asf_write_header(s);
654 }
655 
657  unsigned sendtime, unsigned duration,
658  int nb_payloads, int padsize)
659 {
660  ASFContext *asf = s->priv_data;
661  AVIOContext *pb = s->pb;
662  int ppi_size, i;
663  int64_t start = avio_tell(pb);
664 
665  int iLengthTypeFlags = ASF_PPI_LENGTH_TYPE_FLAGS;
666 
667  padsize -= PACKET_HEADER_MIN_SIZE;
668  if (asf->multi_payloads_present)
669  padsize--;
670  assert(padsize >= 0);
671 
673  for (i = 0; i < ASF_PACKET_ERROR_CORRECTION_DATA_SIZE; i++)
674  avio_w8(pb, 0x0);
675 
676  if (asf->multi_payloads_present)
677  iLengthTypeFlags |= ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT;
678 
679  if (padsize > 0) {
680  if (padsize < 256)
681  iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE;
682  else
683  iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD;
684  }
685  avio_w8(pb, iLengthTypeFlags);
686 
688 
689  if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD)
690  avio_wl16(pb, padsize - 2);
691  if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE)
692  avio_w8(pb, padsize - 1);
693 
694  avio_wl32(pb, sendtime);
695  avio_wl16(pb, duration);
696  if (asf->multi_payloads_present)
697  avio_w8(pb, nb_payloads | ASF_PAYLOAD_FLAGS);
698 
699  ppi_size = avio_tell(pb) - start;
700 
701  return ppi_size;
702 }
703 
705 {
706  ASFContext *asf = s->priv_data;
707  int packet_hdr_size, packet_filled_size;
708 
709  assert(asf->packet_timestamp_end >= asf->packet_timestamp_start);
710 
711  if (asf->is_streamed)
712  put_chunk(s, 0x4424, s->packet_size, 0);
713 
714  packet_hdr_size = put_payload_parsing_info(s,
716  asf->packet_timestamp_end -
718  asf->packet_nb_payloads,
719  asf->packet_size_left);
720 
721  packet_filled_size = PACKET_SIZE - asf->packet_size_left;
722  assert(packet_hdr_size <= asf->packet_size_left);
723  memset(asf->packet_buf + packet_filled_size, 0, asf->packet_size_left);
724 
725  avio_write(s->pb, asf->packet_buf, s->packet_size - packet_hdr_size);
726 
727  avio_flush(s->pb);
728  asf->nb_packets++;
729  asf->packet_nb_payloads = 0;
730  asf->packet_timestamp_start = -1;
731  asf->packet_timestamp_end = -1;
732  ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
733  NULL, NULL, NULL, NULL);
734 }
735 
737  int presentation_time, int m_obj_size,
738  int m_obj_offset, int payload_len, int flags)
739 {
740  ASFContext *asf = s->priv_data;
741  AVIOContext *pb = &asf->pb;
742  int val;
743 
744  val = stream->num;
745  if (flags & AV_PKT_FLAG_KEY)
746  val |= ASF_PL_FLAG_KEY_FRAME;
747  avio_w8(pb, val);
748 
749  avio_w8(pb, stream->seq); // Media object number
750  avio_wl32(pb, m_obj_offset); // Offset Into Media Object
751 
752  // Replicated Data shall be at least 8 bytes long.
753  // The first 4 bytes of data shall contain the
754  // Size of the Media Object that the payload belongs to.
755  // The next 4 bytes of data shall contain the
756  // Presentation Time for the media object that the payload belongs to.
758 
759  avio_wl32(pb, m_obj_size); // Replicated Data - Media Object Size
760  avio_wl32(pb, presentation_time); // Replicated Data - Presentation Time
761 
762  if (asf->multi_payloads_present) {
763  avio_wl16(pb, payload_len); // payload length
764  }
765 }
766 
767 static void put_frame(AVFormatContext *s, ASFStream *stream, AVStream *avst,
768  int timestamp, const uint8_t *buf,
769  int m_obj_size, int flags)
770 {
771  ASFContext *asf = s->priv_data;
772  int m_obj_offset, payload_len, frag_len1;
773 
774  m_obj_offset = 0;
775  while (m_obj_offset < m_obj_size) {
776  payload_len = m_obj_size - m_obj_offset;
777  if (asf->packet_timestamp_start == -1) {
778  asf->multi_payloads_present = (payload_len < MULTI_PAYLOAD_CONSTANT);
779 
781  if (asf->multi_payloads_present) {
782  frag_len1 = MULTI_PAYLOAD_CONSTANT - 1;
783  } else {
784  frag_len1 = SINGLE_PAYLOAD_DATA_LENGTH;
785  }
786  asf->packet_timestamp_start = timestamp;
787  } else {
788  // multi payloads
789  frag_len1 = asf->packet_size_left -
792 
793  if (frag_len1 < payload_len &&
794  avst->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
795  flush_packet(s);
796  continue;
797  }
798  }
799  if (frag_len1 > 0) {
800  if (payload_len > frag_len1)
801  payload_len = frag_len1;
802  else if (payload_len == (frag_len1 - 1))
803  payload_len = frag_len1 - 2; // additional byte need to put padding length
804 
805  put_payload_header(s, stream, timestamp + PREROLL_TIME,
806  m_obj_size, m_obj_offset, payload_len, flags);
807  avio_write(&asf->pb, buf, payload_len);
808 
809  if (asf->multi_payloads_present)
811  else
813  asf->packet_timestamp_end = timestamp;
814 
815  asf->packet_nb_payloads++;
816  } else {
817  payload_len = 0;
818  }
819  m_obj_offset += payload_len;
820  buf += payload_len;
821 
822  if (!asf->multi_payloads_present)
823  flush_packet(s);
825  flush_packet(s);
826  }
827  stream->seq++;
828 }
829 
831 {
832  ASFContext *asf = s->priv_data;
833  AVIOContext *pb = s->pb;
834  ASFStream *stream;
835  int64_t duration;
836  AVCodecContext *codec;
837  int64_t packet_st, pts;
838  int start_sec, i;
839  int flags = pkt->flags;
840  uint64_t offset = avio_tell(pb);
841 
842  codec = s->streams[pkt->stream_index]->codec;
843  stream = &asf->streams[pkt->stream_index];
844 
845  if (codec->codec_type == AVMEDIA_TYPE_AUDIO)
846  flags &= ~AV_PKT_FLAG_KEY;
847 
848  pts = (pkt->pts != AV_NOPTS_VALUE) ? pkt->pts : pkt->dts;
849  assert(pts != AV_NOPTS_VALUE);
850  if ( pts < - PREROLL_TIME
851  || pts > (INT_MAX-3)/10000LL * ASF_INDEXED_INTERVAL - PREROLL_TIME) {
852  av_log(s, AV_LOG_ERROR, "input pts %"PRId64" is invalid\n", pts);
853  return AVERROR(EINVAL);
854  }
855  duration = pts * 10000;
856  asf->duration = FFMAX(asf->duration, duration + pkt->duration * 10000);
857 
858  packet_st = asf->nb_packets;
859  put_frame(s, stream, s->streams[pkt->stream_index],
860  pkt->dts, pkt->data, pkt->size, flags);
861 
862  /* check index */
863  if ((!asf->is_streamed) && (flags & AV_PKT_FLAG_KEY)) {
864  start_sec = (int)(duration / INT64_C(10000000));
865  if (start_sec != (int)(asf->last_indexed_pts / INT64_C(10000000))) {
866  for (i = asf->nb_index_count; i < start_sec; i++) {
867  if (i >= asf->nb_index_memory_alloc) {
868  int err;
870  if ((err = av_reallocp_array(&asf->index_ptr,
872  sizeof(*asf->index_ptr))) < 0) {
873  asf->nb_index_memory_alloc = 0;
874  return err;
875  }
876  }
877  // store
878  asf->index_ptr[i].packet_number = (uint32_t)packet_st;
879  asf->index_ptr[i].packet_count = (uint16_t)(asf->nb_packets - packet_st);
880  asf->index_ptr[i].send_time = start_sec * INT64_C(10000000);
881  asf->index_ptr[i].offset = offset;
882  asf->maximum_packet = FFMAX(asf->maximum_packet,
883  (uint16_t)(asf->nb_packets - packet_st));
884  }
885  asf->nb_index_count = start_sec;
886  asf->last_indexed_pts = duration;
887  }
888  }
889  return 0;
890 }
891 
893  uint16_t max, uint32_t count)
894 {
895  AVIOContext *pb = s->pb;
896  int i;
897 
899  avio_wl64(pb, 24 + 16 + 8 + 4 + 4 + (4 + 2) * count);
900  put_guid(pb, &ff_asf_my_guid);
902  avio_wl32(pb, max);
903  avio_wl32(pb, count);
904  for (i = 0; i < count; i++) {
905  avio_wl32(pb, index[i].packet_number);
906  avio_wl16(pb, index[i].packet_count);
907  }
908 
909  return 0;
910 }
911 
913 {
914  ASFContext *asf = s->priv_data;
915  int64_t file_size, data_size;
916 
917  /* flush the current packet */
918  if (asf->pb.buf_ptr > asf->pb.buffer)
919  flush_packet(s);
920 
921  /* write index */
922  data_size = avio_tell(s->pb);
923  if ((!asf->is_streamed) && (asf->nb_index_count != 0))
925  avio_flush(s->pb);
926 
927  if (asf->is_streamed || !s->pb->seekable) {
928  put_chunk(s, 0x4524, 0, 0); /* end of stream */
929  } else {
930  /* rewrite an updated header */
931  file_size = avio_tell(s->pb);
932  avio_seek(s->pb, 0, SEEK_SET);
933  asf_write_header1(s, file_size, data_size - asf->data_offset);
934  }
935 
936  av_free(asf->index_ptr);
937  return 0;
938 }
939 
940 #if CONFIG_ASF_MUXER
941 AVOutputFormat ff_asf_muxer = {
942  .name = "asf",
943  .long_name = NULL_IF_CONFIG_SMALL("ASF (Advanced / Active Streaming Format)"),
944  .mime_type = "video/x-ms-asf",
945  .extensions = "asf,wmv,wma",
946  .priv_data_size = sizeof(ASFContext),
948  .video_codec = AV_CODEC_ID_MSMPEG4V3,
953  .codec_tag = (const AVCodecTag * const []) {
955  },
956 };
957 #endif /* CONFIG_ASF_MUXER */
958 
959 #if CONFIG_ASF_STREAM_MUXER
960 AVOutputFormat ff_asf_stream_muxer = {
961  .name = "asf_stream",
962  .long_name = NULL_IF_CONFIG_SMALL("ASF (Advanced / Active Streaming Format)"),
963  .mime_type = "video/x-ms-asf",
964  .extensions = "asf,wmv,wma",
965  .priv_data_size = sizeof(ASFContext),
966  .audio_codec = CONFIG_LIBMP3LAME ? AV_CODEC_ID_MP3 : AV_CODEC_ID_MP2,
967  .video_codec = AV_CODEC_ID_MSMPEG4V3,
972  .codec_tag = (const AVCodecTag * const []) {
974  },
975 };
976 #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:336
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:966
const ff_asf_guid ff_asf_codec_comment_header
Definition: asf.c:73
#define PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD
Definition: asfenc.c:160
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:830
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:656
uint16_t maximum_packet
Definition: asfenc.c:210
#define FF_ARRAY_ELEMS(a)
static int asf_write_trailer(AVFormatContext *s)
Definition: asfenc.c:912
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:954
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:260
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:736
static int asf_write_header(AVFormatContext *s)
Definition: asfenc.c:615
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:324
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:892
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:167
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
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 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
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:704
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:287
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
int64_t duration
in 100ns units
Definition: asfenc.c:194
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 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:767
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:647
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