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