Statistics
| Branch: | Revision:

ffmpeg / libavformat / asf-enc.c @ 1ae7518d

History | View | Annotate | Download (28.7 KB)

1 542993b0 Konstantin Andreyev
/*
2 7fbde343 Aurelien Jacobs
 * Adaptive stream format muxer
3 542993b0 Konstantin Andreyev
 * Copyright (c) 2000, 2001 Fabrice Bellard.
4
 *
5 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8 542993b0 Konstantin Andreyev
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
11 542993b0 Konstantin Andreyev
 *
12 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
13 542993b0 Konstantin Andreyev
 * 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 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
19 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 542993b0 Konstantin Andreyev
 */
21
#include "avformat.h"
22 9d9f4119 Måns Rullgård
#include "riff.h"
23 542993b0 Konstantin Andreyev
#include "asf.h"
24
25
#undef NDEBUG
26
#include <assert.h>
27
28 982e53fe Calcium
29 bb270c08 Diego Biurrun
#define ASF_INDEXED_INTERVAL    10000000
30
#define ASF_INDEX_BLOCK         600
31 982e53fe Calcium
32 615b92fd Konstantin Andreyev
#define ASF_PACKET_ERROR_CORRECTION_DATA_SIZE 0x2
33
#define ASF_PACKET_ERROR_CORRECTION_FLAGS (\
34 bb270c08 Diego Biurrun
                ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT | \
35
                ASF_PACKET_ERROR_CORRECTION_DATA_SIZE\
36
                )
37 615b92fd Konstantin Andreyev
38
#if (ASF_PACKET_ERROR_CORRECTION_FLAGS != 0)
39
#   define ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE 1
40
#else
41
#   define ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE 0
42
#endif
43
44
#define ASF_PPI_PROPERTY_FLAGS (\
45 bb270c08 Diego Biurrun
                ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_BYTE | \
46
                ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_DWORD | \
47
                ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_BYTE | \
48
                ASF_PL_FLAG_STREAM_NUMBER_LENGTH_FIELD_IS_BYTE \
49
                )
50 615b92fd Konstantin Andreyev
51
#define ASF_PPI_LENGTH_TYPE_FLAGS 0
52
53
#define ASF_PAYLOAD_FLAGS ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_WORD
54
55
#if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
56
#   define ASF_PPI_SEQUENCE_FIELD_SIZE 1
57
#endif
58
#if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
59
#   define ASF_PPI_SEQUENCE_FIELD_SIZE 2
60
#endif
61
#if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
62
#   define ASF_PPI_SEQUENCE_FIELD_SIZE 4
63
#endif
64
#ifndef ASF_PPI_SEQUENCE_FIELD_SIZE
65
#   define ASF_PPI_SEQUENCE_FIELD_SIZE 0
66
#endif
67
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 bb270c08 Diego Biurrun
                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 615b92fd Konstantin Andreyev
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 bb270c08 Diego Biurrun
                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 115329f1 Diego Biurrun
168 615b92fd Konstantin Andreyev
#define PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS (\
169 bb270c08 Diego Biurrun
                1 + /*Stream Number*/ \
170
                ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \
171
                ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \
172
                ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \
173
                ASF_PAYLOAD_REPLICATED_DATA_LENGTH + \
174
                ASF_PAYLOAD_LENGTH_FIELD_SIZE \
175
                )
176 615b92fd Konstantin Andreyev
177
#define SINGLE_PAYLOAD_DATA_LENGTH (\
178 bb270c08 Diego Biurrun
                PACKET_SIZE - \
179
                PACKET_HEADER_MIN_SIZE - \
180
                PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD \
181
                )
182 615b92fd Konstantin Andreyev
183
#define MULTI_PAYLOAD_CONSTANT (\
184 bb270c08 Diego Biurrun
                PACKET_SIZE - \
185
                PACKET_HEADER_MIN_SIZE - \
186
                1 - /*Payload Flags*/ \
187
                2*PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS \
188
                )
189 615b92fd Konstantin Andreyev
190 7caf0cc6 Michael Niedermayer
static const AVCodecTag codec_asf_bmp_tags[] = {
191
    { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
192
    { CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
193
    { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
194
    { CODEC_ID_NONE, 0 },
195
};
196
197 615b92fd Konstantin Andreyev
static int preroll_time = 2000;
198
199 982e53fe Calcium
static const uint8_t error_spread_ADPCM_G726[] = { 0x01, 0x90, 0x01, 0x90, 0x01, 0x01, 0x00, 0x00 };
200
201 542993b0 Konstantin Andreyev
static void put_guid(ByteIOContext *s, const GUID *g)
202
{
203 24c14d6d Michael Niedermayer
    assert(sizeof(*g) == 16);
204
    put_buffer(s, g, sizeof(*g));
205 542993b0 Konstantin Andreyev
}
206
207 d65b8230 Michael Niedermayer
static void put_str16_nolen(ByteIOContext *s, const char *tag);
208 542993b0 Konstantin Andreyev
static void put_str16(ByteIOContext *s, const char *tag)
209
{
210
    put_le16(s,strlen(tag) + 1);
211 d65b8230 Michael Niedermayer
    put_str16_nolen(s, tag);
212 542993b0 Konstantin Andreyev
}
213
214
static void put_str16_nolen(ByteIOContext *s, const char *tag)
215
{
216
    int c;
217
218 d65b8230 Michael Niedermayer
    do{
219 542993b0 Konstantin Andreyev
        c = (uint8_t)*tag++;
220
        put_le16(s, c);
221 d65b8230 Michael Niedermayer
    }while(c);
222 542993b0 Konstantin Andreyev
}
223
224
static int64_t put_header(ByteIOContext *pb, const GUID *g)
225
{
226
    int64_t pos;
227
228
    pos = url_ftell(pb);
229
    put_guid(pb, g);
230
    put_le64(pb, 24);
231
    return pos;
232
}
233
234
/* update header size */
235
static void end_header(ByteIOContext *pb, int64_t pos)
236
{
237
    int64_t pos1;
238
239
    pos1 = url_ftell(pb);
240
    url_fseek(pb, pos + 16, SEEK_SET);
241
    put_le64(pb, pos1 - pos);
242
    url_fseek(pb, pos1, SEEK_SET);
243
}
244
245
/* write an asf chunk (only used in streaming case) */
246
static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
247
{
248
    ASFContext *asf = s->priv_data;
249
    ByteIOContext *pb = &s->pb;
250
    int length;
251
252
    length = payload_length + 8;
253
    put_le16(pb, type);
254 615b92fd Konstantin Andreyev
    put_le16(pb, length);    //size
255
    put_le32(pb, asf->seqno);//sequence number
256 542993b0 Konstantin Andreyev
    put_le16(pb, flags); /* unknown bytes */
257 615b92fd Konstantin Andreyev
    put_le16(pb, length);    //size_confirm
258 542993b0 Konstantin Andreyev
    asf->seqno++;
259
}
260
261
/* convert from unix to windows time */
262
static int64_t unix_to_file_time(int ti)
263
{
264
    int64_t t;
265
266 8da9266c Måns Rullgård
    t = ti * INT64_C(10000000);
267
    t += INT64_C(116444736000000000);
268 542993b0 Konstantin Andreyev
    return t;
269
}
270
271
/* write the header (used two times if non streamed) */
272
static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size)
273
{
274
    ASFContext *asf = s->priv_data;
275
    ByteIOContext *pb = &s->pb;
276
    int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
277
    int has_title;
278
    AVCodecContext *enc;
279
    int64_t header_offset, cur_pos, hpos;
280
    int bit_rate;
281 4336886c Brian Brice
    int64_t duration;
282 542993b0 Konstantin Andreyev
283 4336886c Brian Brice
    duration = asf->duration + preroll_time * 10000;
284 542993b0 Konstantin Andreyev
    has_title = (s->title[0] || s->author[0] || s->copyright[0] || s->comment[0]);
285
286
    bit_rate = 0;
287
    for(n=0;n<s->nb_streams;n++) {
288 01f4895c Michael Niedermayer
        enc = s->streams[n]->codec;
289 542993b0 Konstantin Andreyev
290 9ee91c2f Michael Niedermayer
        av_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */
291
292 542993b0 Konstantin Andreyev
        bit_rate += enc->bit_rate;
293
    }
294
295
    if (asf->is_streamed) {
296
        put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */
297
    }
298
299
    put_guid(pb, &asf_header);
300
    put_le64(pb, -1); /* header length, will be patched after */
301
    put_le32(pb, 3 + has_title + s->nb_streams); /* number of chunks in header */
302
    put_byte(pb, 1); /* ??? */
303
    put_byte(pb, 2); /* ??? */
304
305
    /* file header */
306
    header_offset = url_ftell(pb);
307
    hpos = put_header(pb, &file_header);
308
    put_guid(pb, &my_guid);
309
    put_le64(pb, file_size);
310
    file_time = 0;
311
    put_le64(pb, unix_to_file_time(file_time));
312
    put_le64(pb, asf->nb_packets); /* number of packets */
313 4336886c Brian Brice
    put_le64(pb, duration); /* end time stamp (in 100ns units) */
314
    put_le64(pb, duration); /* duration (in 100ns units) */
315 e928649b Michael Niedermayer
    put_le32(pb, preroll_time); /* start time stamp */
316 542993b0 Konstantin Andreyev
    put_le32(pb, 0); /* ??? */
317
    put_le32(pb, asf->is_streamed ? 1 : 0); /* ??? */
318
    put_le32(pb, asf->packet_size); /* packet size */
319
    put_le32(pb, asf->packet_size); /* packet size */
320
    put_le32(pb, bit_rate); /* Nominal data rate in bps */
321
    end_header(pb, hpos);
322
323
    /* unknown headers */
324
    hpos = put_header(pb, &head1_guid);
325
    put_guid(pb, &head2_guid);
326
    put_le32(pb, 6);
327
    put_le16(pb, 0);
328
    end_header(pb, hpos);
329
330
    /* title and other infos */
331
    if (has_title) {
332
        hpos = put_header(pb, &comment_header);
333 982e53fe Calcium
        if ( s->title[0]     ) { put_le16(pb, 2 * (strlen(s->title    ) + 1)); } else { put_le16(pb, 0); }
334
        if ( s->author[0]    ) { put_le16(pb, 2 * (strlen(s->author   ) + 1)); } else { put_le16(pb, 0); }
335
        if ( s->copyright[0] ) { put_le16(pb, 2 * (strlen(s->copyright) + 1)); } else { put_le16(pb, 0); }
336
        if ( s->comment[0]   ) { put_le16(pb, 2 * (strlen(s->comment  ) + 1)); } else { put_le16(pb, 0); }
337 542993b0 Konstantin Andreyev
        put_le16(pb, 0);
338 982e53fe Calcium
        if ( s->title[0]     ) put_str16_nolen(pb, s->title);
339
        if ( s->author[0]    ) put_str16_nolen(pb, s->author);
340
        if ( s->copyright[0] ) put_str16_nolen(pb, s->copyright);
341
        if ( s->comment[0]   ) put_str16_nolen(pb, s->comment);
342 542993b0 Konstantin Andreyev
        end_header(pb, hpos);
343
    }
344
345
    /* stream headers */
346
    for(n=0;n<s->nb_streams;n++) {
347
        int64_t es_pos;
348 a97c1e93 Stefan Huehner
        const uint8_t *er_spr = NULL;
349 982e53fe Calcium
        int er_spr_len = 0;
350 542993b0 Konstantin Andreyev
        //        ASFStream *stream = &asf->streams[n];
351
352 01f4895c Michael Niedermayer
        enc = s->streams[n]->codec;
353 542993b0 Konstantin Andreyev
        asf->streams[n].num = n + 1;
354
        asf->streams[n].seq = 0;
355
356 115329f1 Diego Biurrun
357 982e53fe Calcium
        if (enc->codec_type == CODEC_TYPE_AUDIO) {
358
            if (enc->codec_id == CODEC_ID_ADPCM_G726) {
359 a97c1e93 Stefan Huehner
                er_spr     = error_spread_ADPCM_G726;
360 982e53fe Calcium
                er_spr_len = sizeof(error_spread_ADPCM_G726);
361
            }
362
        }
363
364 542993b0 Konstantin Andreyev
        switch(enc->codec_type) {
365
        case CODEC_TYPE_AUDIO:
366
            wav_extra_size = 0;
367
            extra_size = 18 + wav_extra_size;
368 982e53fe Calcium
            extra_size2 = er_spr_len;
369 542993b0 Konstantin Andreyev
            break;
370
        default:
371
        case CODEC_TYPE_VIDEO:
372 982e53fe Calcium
            wav_extra_size = enc->extradata_size;
373
            extra_size = 0x33 + wav_extra_size;
374 542993b0 Konstantin Andreyev
            extra_size2 = 0;
375
            break;
376
        }
377
378
        hpos = put_header(pb, &stream_header);
379
        if (enc->codec_type == CODEC_TYPE_AUDIO) {
380
            put_guid(pb, &audio_stream);
381 982e53fe Calcium
            if ((er_spr != NULL) && (er_spr_len != 0)) {
382
                put_guid(pb, &audio_conceal_spread);
383
            } else {
384
                put_guid(pb, &video_conceal_none);
385
            }
386 542993b0 Konstantin Andreyev
        } else {
387
            put_guid(pb, &video_stream);
388
            put_guid(pb, &video_conceal_none);
389
        }
390
        put_le64(pb, 0); /* ??? */
391
        es_pos = url_ftell(pb);
392
        put_le32(pb, extra_size); /* wav header len */
393
        put_le32(pb, extra_size2); /* additional data len */
394
        put_le16(pb, n + 1); /* stream number */
395
        put_le32(pb, 0); /* ??? */
396
397
        if (enc->codec_type == CODEC_TYPE_AUDIO) {
398
            /* WAVEFORMATEX header */
399
            int wavsize = put_wav_header(pb, enc);
400 982e53fe Calcium
            if ((enc->codec_id != CODEC_ID_MP3) && (enc->codec_id != CODEC_ID_MP2) && (enc->codec_id != CODEC_ID_ADPCM_IMA_WAV) && (enc->extradata_size==0)) {
401
                wavsize += 2;
402
                put_le16(pb, 0);
403
            }
404 542993b0 Konstantin Andreyev
405
            if (wavsize < 0)
406
                return -1;
407
            if (wavsize != extra_size) {
408
                cur_pos = url_ftell(pb);
409
                url_fseek(pb, es_pos, SEEK_SET);
410
                put_le32(pb, wavsize); /* wav header len */
411
                url_fseek(pb, cur_pos, SEEK_SET);
412
            }
413 982e53fe Calcium
            /* ERROR Correction */
414
            if ((er_spr != NULL) && (er_spr_len != 0))
415
                put_buffer(pb, er_spr, er_spr_len);
416 542993b0 Konstantin Andreyev
        } else {
417
            put_le32(pb, enc->width);
418
            put_le32(pb, enc->height);
419
            put_byte(pb, 2); /* ??? */
420 982e53fe Calcium
            put_le16(pb, 40 + enc->extradata_size); /* size */
421 542993b0 Konstantin Andreyev
422
            /* BITMAPINFOHEADER header */
423
            put_bmp_header(pb, enc, codec_bmp_tags, 1);
424
        }
425
        end_header(pb, hpos);
426
    }
427
428
    /* media comments */
429
430
    hpos = put_header(pb, &codec_comment_header);
431
    put_guid(pb, &codec_comment1_header);
432
    put_le32(pb, s->nb_streams);
433
    for(n=0;n<s->nb_streams;n++) {
434
        AVCodec *p;
435
436 01f4895c Michael Niedermayer
        enc = s->streams[n]->codec;
437 542993b0 Konstantin Andreyev
        p = avcodec_find_encoder(enc->codec_id);
438
439
        put_le16(pb, asf->streams[n].num);
440
        put_str16(pb, p ? p->name : enc->codec_name);
441
        put_le16(pb, 0); /* no parameters */
442 115329f1 Diego Biurrun
443
444 542993b0 Konstantin Andreyev
        /* id */
445
        if (enc->codec_type == CODEC_TYPE_AUDIO) {
446
            put_le16(pb, 2);
447
            put_le16(pb, enc->codec_tag);
448
        } else {
449
            put_le16(pb, 4);
450
            put_le32(pb, enc->codec_tag);
451
        }
452 d65b8230 Michael Niedermayer
        if(!enc->codec_tag)
453
            return -1;
454 542993b0 Konstantin Andreyev
    }
455
    end_header(pb, hpos);
456
457
    /* patch the header size fields */
458
459
    cur_pos = url_ftell(pb);
460
    header_size = cur_pos - header_offset;
461
    if (asf->is_streamed) {
462
        header_size += 8 + 30 + 50;
463
464
        url_fseek(pb, header_offset - 10 - 30, SEEK_SET);
465
        put_le16(pb, header_size);
466
        url_fseek(pb, header_offset - 2 - 30, SEEK_SET);
467
        put_le16(pb, header_size);
468
469
        header_size -= 8 + 30 + 50;
470
    }
471
    header_size += 24 + 6;
472
    url_fseek(pb, header_offset - 14, SEEK_SET);
473
    put_le64(pb, header_size);
474
    url_fseek(pb, cur_pos, SEEK_SET);
475
476
    /* movie chunk, followed by packets of packet_size */
477
    asf->data_offset = cur_pos;
478
    put_guid(pb, &data_header);
479
    put_le64(pb, data_chunk_size);
480
    put_guid(pb, &my_guid);
481
    put_le64(pb, asf->nb_packets); /* nb packets */
482
    put_byte(pb, 1); /* ??? */
483
    put_byte(pb, 1); /* ??? */
484
    return 0;
485
}
486
487
static int asf_write_header(AVFormatContext *s)
488
{
489
    ASFContext *asf = s->priv_data;
490
491
    asf->packet_size = PACKET_SIZE;
492
    asf->nb_packets = 0;
493 115329f1 Diego Biurrun
494 982e53fe Calcium
    asf->last_indexed_pts = 0;
495
    asf->index_ptr = (ASFIndex*)av_malloc( sizeof(ASFIndex) * ASF_INDEX_BLOCK );
496
    asf->nb_index_memory_alloc = ASF_INDEX_BLOCK;
497
    asf->nb_index_count = 0;
498
    asf->maximum_packet = 0;
499 542993b0 Konstantin Andreyev
500
    if (asf_write_header1(s, 0, 50) < 0) {
501
        //av_free(asf);
502
        return -1;
503
    }
504
505
    put_flush_packet(&s->pb);
506
507 615b92fd Konstantin Andreyev
    asf->packet_nb_payloads = 0;
508
    asf->prev_packet_sent_time = 0;
509 542993b0 Konstantin Andreyev
    asf->packet_timestamp_start = -1;
510
    asf->packet_timestamp_end = -1;
511
    init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
512
                  NULL, NULL, NULL, NULL);
513
514
    return 0;
515
}
516
517
static int asf_write_stream_header(AVFormatContext *s)
518
{
519
    ASFContext *asf = s->priv_data;
520
521
    asf->is_streamed = 1;
522
523
    return asf_write_header(s);
524
}
525
526 615b92fd Konstantin Andreyev
static int put_payload_parsing_info(
527
                                AVFormatContext *s,
528 115329f1 Diego Biurrun
                                unsigned int    sendtime,
529 615b92fd Konstantin Andreyev
                                unsigned int    duration,
530 115329f1 Diego Biurrun
                                int             nb_payloads,
531 615b92fd Konstantin Andreyev
                                int             padsize
532
            )
533 542993b0 Konstantin Andreyev
{
534
    ASFContext *asf = s->priv_data;
535
    ByteIOContext *pb = &s->pb;
536 615b92fd Konstantin Andreyev
    int ppi_size, i;
537
    unsigned char *start_ppi_ptr = pb->buf_ptr;
538
539
    int iLengthTypeFlags = ASF_PPI_LENGTH_TYPE_FLAGS;
540 115329f1 Diego Biurrun
541 615b92fd Konstantin Andreyev
    put_byte(pb, ASF_PACKET_ERROR_CORRECTION_FLAGS);
542
    for (i = 0; i < ASF_PACKET_ERROR_CORRECTION_DATA_SIZE; i++){
543
        put_byte(pb, 0x0);
544 542993b0 Konstantin Andreyev
    }
545
546 615b92fd Konstantin Andreyev
    if (asf->multi_payloads_present)
547
        iLengthTypeFlags |= ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT;
548 542993b0 Konstantin Andreyev
549
    if (padsize > 0) {
550
        if (padsize < 256)
551 615b92fd Konstantin Andreyev
            iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE;
552 542993b0 Konstantin Andreyev
        else
553 615b92fd Konstantin Andreyev
            iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD;
554 542993b0 Konstantin Andreyev
    }
555 615b92fd Konstantin Andreyev
    put_byte(pb, iLengthTypeFlags);
556
557
    put_byte(pb, ASF_PPI_PROPERTY_FLAGS);
558
559
    if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD)
560 542993b0 Konstantin Andreyev
        put_le16(pb, padsize - 2);
561 615b92fd Konstantin Andreyev
    if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE)
562 542993b0 Konstantin Andreyev
        put_byte(pb, padsize - 1);
563 615b92fd Konstantin Andreyev
564
    put_le32(pb, sendtime);
565 542993b0 Konstantin Andreyev
    put_le16(pb, duration);
566 615b92fd Konstantin Andreyev
    if (asf->multi_payloads_present)
567
        put_byte(pb, nb_payloads | ASF_PAYLOAD_FLAGS);
568
569
    ppi_size = pb->buf_ptr - start_ppi_ptr;
570 542993b0 Konstantin Andreyev
571 615b92fd Konstantin Andreyev
    return ppi_size;
572 542993b0 Konstantin Andreyev
}
573
574
static void flush_packet(AVFormatContext *s)
575
{
576
    ASFContext *asf = s->priv_data;
577 615b92fd Konstantin Andreyev
    int packet_hdr_size, packet_filled_size;
578 542993b0 Konstantin Andreyev
579 615b92fd Konstantin Andreyev
    if (asf->is_streamed) {
580
        put_chunk(s, 0x4424, asf->packet_size, 0);
581
    }
582
583
    packet_hdr_size = put_payload_parsing_info(
584
                            s,
585
                            asf->packet_timestamp_start,
586
                            asf->packet_timestamp_end - asf->packet_timestamp_start,
587
                            asf->packet_nb_payloads,
588
                            asf->packet_size_left
589
                        );
590 542993b0 Konstantin Andreyev
591 615b92fd Konstantin Andreyev
    packet_filled_size = PACKET_SIZE - packet_hdr_size - asf->packet_size_left;
592
    memset(asf->packet_buf + packet_filled_size, 0, asf->packet_size_left);
593 542993b0 Konstantin Andreyev
594 615b92fd Konstantin Andreyev
    put_buffer(&s->pb, asf->packet_buf, asf->packet_size - packet_hdr_size);
595 542993b0 Konstantin Andreyev
596
    put_flush_packet(&s->pb);
597
    asf->nb_packets++;
598 615b92fd Konstantin Andreyev
    asf->packet_nb_payloads = 0;
599
    asf->prev_packet_sent_time = asf->packet_timestamp_start;
600 542993b0 Konstantin Andreyev
    asf->packet_timestamp_start = -1;
601
    asf->packet_timestamp_end = -1;
602
    init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
603
                  NULL, NULL, NULL, NULL);
604
}
605
606 615b92fd Konstantin Andreyev
static void put_payload_header(
607
                                AVFormatContext *s,
608
                                ASFStream       *stream,
609
                                int             presentation_time,
610
                                int             m_obj_size,
611
                                int             m_obj_offset,
612 3c895fc0 Michael Niedermayer
                                int             payload_len,
613
                                int             flags
614 615b92fd Konstantin Andreyev
            )
615 542993b0 Konstantin Andreyev
{
616
    ASFContext *asf = s->priv_data;
617
    ByteIOContext *pb = &asf->pb;
618
    int val;
619 115329f1 Diego Biurrun
620 542993b0 Konstantin Andreyev
    val = stream->num;
621 3c895fc0 Michael Niedermayer
    if (flags & PKT_FLAG_KEY)
622 615b92fd Konstantin Andreyev
        val |= ASF_PL_FLAG_KEY_FRAME;
623 542993b0 Konstantin Andreyev
    put_byte(pb, val);
624 115329f1 Diego Biurrun
625 615b92fd Konstantin Andreyev
    put_byte(pb, stream->seq);  //Media object number
626
    put_le32(pb, m_obj_offset); //Offset Into Media Object
627 115329f1 Diego Biurrun
628 615b92fd Konstantin Andreyev
    // Replicated Data shall be at least 8 bytes long.
629 115329f1 Diego Biurrun
    // The first 4 bytes of data shall contain the
630 615b92fd Konstantin Andreyev
    // Size of the Media Object that the payload belongs to.
631 115329f1 Diego Biurrun
    // The next 4 bytes of data shall contain the
632 615b92fd Konstantin Andreyev
    // Presentation Time for the media object that the payload belongs to.
633
    put_byte(pb, ASF_PAYLOAD_REPLICATED_DATA_LENGTH);
634
635
    put_le32(pb, m_obj_size);       //Replicated Data - Media Object Size
636
    put_le32(pb, presentation_time);//Replicated Data - Presentation Time
637 115329f1 Diego Biurrun
638 615b92fd Konstantin Andreyev
    if (asf->multi_payloads_present){
639
        put_le16(pb, payload_len);   //payload length
640
    }
641 542993b0 Konstantin Andreyev
}
642
643 615b92fd Konstantin Andreyev
static void put_frame(
644
                    AVFormatContext *s,
645
                    ASFStream       *stream,
646 bb270c08 Diego Biurrun
                    int             timestamp,
647 615b92fd Konstantin Andreyev
                    const uint8_t   *buf,
648 bb270c08 Diego Biurrun
                    int             m_obj_size,
649 3c895fc0 Michael Niedermayer
                    int             flags
650 bb270c08 Diego Biurrun
                )
651 542993b0 Konstantin Andreyev
{
652
    ASFContext *asf = s->priv_data;
653 615b92fd Konstantin Andreyev
    int m_obj_offset, payload_len, frag_len1;
654
655
    m_obj_offset = 0;
656
    while (m_obj_offset < m_obj_size) {
657
        payload_len = m_obj_size - m_obj_offset;
658
        if (asf->packet_timestamp_start == -1) {
659
            asf->multi_payloads_present = (payload_len < MULTI_PAYLOAD_CONSTANT);
660 115329f1 Diego Biurrun
661 615b92fd Konstantin Andreyev
            if (asf->multi_payloads_present){
662
                asf->packet_size_left = PACKET_SIZE; //For debug
663
                asf->packet_size_left = PACKET_SIZE - PACKET_HEADER_MIN_SIZE - 1;
664
                frag_len1 = MULTI_PAYLOAD_CONSTANT - 1;
665
            }
666
            else {
667
                asf->packet_size_left = PACKET_SIZE - PACKET_HEADER_MIN_SIZE;
668
                frag_len1 = SINGLE_PAYLOAD_DATA_LENGTH;
669
            }
670
            if (asf->prev_packet_sent_time > timestamp)
671
                asf->packet_timestamp_start = asf->prev_packet_sent_time;
672
            else
673
                asf->packet_timestamp_start = timestamp;
674
        }
675
        else {
676
            // multi payloads
677
            frag_len1 = asf->packet_size_left - PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS;
678 542993b0 Konstantin Andreyev
679 615b92fd Konstantin Andreyev
            if (asf->prev_packet_sent_time > timestamp)
680
                asf->packet_timestamp_start = asf->prev_packet_sent_time;
681
            else if (asf->packet_timestamp_start >= timestamp)
682
                asf->packet_timestamp_start = timestamp;
683
        }
684 542993b0 Konstantin Andreyev
        if (frag_len1 > 0) {
685 615b92fd Konstantin Andreyev
            if (payload_len > frag_len1)
686
                payload_len = frag_len1;
687
            else if (payload_len == (frag_len1 - 1))
688
                payload_len = frag_len1 - 2;  //additional byte need to put padding length
689 115329f1 Diego Biurrun
690 3c895fc0 Michael Niedermayer
            put_payload_header(s, stream, timestamp+preroll_time, m_obj_size, m_obj_offset, payload_len, flags);
691 615b92fd Konstantin Andreyev
            put_buffer(&asf->pb, buf, payload_len);
692
693
            if (asf->multi_payloads_present)
694
                asf->packet_size_left -= (payload_len + PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS);
695
            else
696
                asf->packet_size_left -= (payload_len + PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD);
697 542993b0 Konstantin Andreyev
            asf->packet_timestamp_end = timestamp;
698 115329f1 Diego Biurrun
699 615b92fd Konstantin Andreyev
            asf->packet_nb_payloads++;
700 542993b0 Konstantin Andreyev
        } else {
701 615b92fd Konstantin Andreyev
            payload_len = 0;
702 542993b0 Konstantin Andreyev
        }
703 615b92fd Konstantin Andreyev
        m_obj_offset += payload_len;
704
        buf += payload_len;
705
706
        if (!asf->multi_payloads_present)
707
            flush_packet(s);
708
        else if (asf->packet_size_left <= (PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS + 1))
709 542993b0 Konstantin Andreyev
            flush_packet(s);
710
    }
711
    stream->seq++;
712
}
713
714 e928649b Michael Niedermayer
static int asf_write_packet(AVFormatContext *s, AVPacket *pkt)
715 542993b0 Konstantin Andreyev
{
716
    ASFContext *asf = s->priv_data;
717
    ASFStream *stream;
718
    int64_t duration;
719
    AVCodecContext *codec;
720 115329f1 Diego Biurrun
    int64_t packet_st,pts;
721 982e53fe Calcium
    int start_sec,i;
722 542993b0 Konstantin Andreyev
723 01f4895c Michael Niedermayer
    codec = s->streams[pkt->stream_index]->codec;
724 e928649b Michael Niedermayer
    stream = &asf->streams[pkt->stream_index];
725 542993b0 Konstantin Andreyev
726 982e53fe Calcium
    //XXX /FIXME use duration from AVPacket (quick hack by)
727
    pts = (pkt->pts != AV_NOPTS_VALUE) ? pkt->pts : pkt->dts;
728
    if (pts == AV_NOPTS_VALUE) {
729
        if (codec->codec_type == CODEC_TYPE_AUDIO) {
730 8da9266c Måns Rullgård
            duration = (codec->frame_number * (int64_t)codec->frame_size * INT64_C(10000000)) /
731 982e53fe Calcium
                codec->sample_rate;
732
        } else {
733 c0df9d75 Michael Niedermayer
            duration = av_rescale(codec->frame_number * (int64_t)codec->time_base.num, 10000000, codec->time_base.den);
734 982e53fe Calcium
        }
735 542993b0 Konstantin Andreyev
    } else {
736 982e53fe Calcium
        duration = pts * 10000;
737 542993b0 Konstantin Andreyev
    }
738 d65b8230 Michael Niedermayer
    asf->duration= FFMAX(asf->duration, duration);
739 542993b0 Konstantin Andreyev
740 982e53fe Calcium
    packet_st = asf->nb_packets;
741 3c895fc0 Michael Niedermayer
    put_frame(s, stream, pkt->pts, pkt->data, pkt->size, pkt->flags);
742 982e53fe Calcium
743
    /* check index */
744
    if ((!asf->is_streamed) && (codec->codec_type == CODEC_TYPE_VIDEO) && (pkt->flags & PKT_FLAG_KEY)) {
745 8da9266c Måns Rullgård
        start_sec = (int)(duration / INT64_C(10000000));
746
        if (start_sec != (int)(asf->last_indexed_pts / INT64_C(10000000))) {
747 982e53fe Calcium
            for(i=asf->nb_index_count;i<start_sec;i++) {
748
                if (i>=asf->nb_index_memory_alloc) {
749
                    asf->nb_index_memory_alloc += ASF_INDEX_BLOCK;
750
                    asf->index_ptr = (ASFIndex*)av_realloc( asf->index_ptr, sizeof(ASFIndex) * asf->nb_index_memory_alloc );
751
                }
752
                // store
753
                asf->index_ptr[i].packet_number = (uint32_t)packet_st;
754
                asf->index_ptr[i].packet_count  = (uint16_t)(asf->nb_packets-packet_st);
755 d65b8230 Michael Niedermayer
                asf->maximum_packet = FFMAX(asf->maximum_packet, (uint16_t)(asf->nb_packets-packet_st));
756 982e53fe Calcium
            }
757
            asf->nb_index_count = start_sec;
758
            asf->last_indexed_pts = duration;
759
        }
760
    }
761
    return 0;
762
}
763
764
//
765
static int asf_write_index(AVFormatContext *s, ASFIndex *index, uint16_t max, uint32_t count)
766
{
767
    ByteIOContext *pb = &s->pb;
768
    int i;
769
770
    put_guid(pb, &simple_index_header);
771
    put_le64(pb, 24 + 16 + 8 + 4 + 4 + (4 + 2)*count);
772
    put_guid(pb, &my_guid);
773
    put_le64(pb, ASF_INDEXED_INTERVAL);
774
    put_le32(pb, max);
775
    put_le32(pb, count);
776
    for(i=0; i<count; i++) {
777
        put_le32(pb, index[i].packet_number);
778
        put_le16(pb, index[i].packet_count);
779
    }
780
781 542993b0 Konstantin Andreyev
    return 0;
782
}
783
784
static int asf_write_trailer(AVFormatContext *s)
785
{
786
    ASFContext *asf = s->priv_data;
787 982e53fe Calcium
    int64_t file_size,data_size;
788 542993b0 Konstantin Andreyev
789
    /* flush the current packet */
790
    if (asf->pb.buf_ptr > asf->pb.buffer)
791
        flush_packet(s);
792
793 982e53fe Calcium
    /* write index */
794
    data_size = url_ftell(&s->pb);
795
    if ((!asf->is_streamed) && (asf->nb_index_count != 0)) {
796
        asf_write_index(s, asf->index_ptr, asf->maximum_packet, asf->nb_index_count);
797
    }
798
    put_flush_packet(&s->pb);
799
800 542993b0 Konstantin Andreyev
    if (asf->is_streamed) {
801
        put_chunk(s, 0x4524, 0, 0); /* end of stream */
802
    } else {
803
        /* rewrite an updated header */
804
        file_size = url_ftell(&s->pb);
805
        url_fseek(&s->pb, 0, SEEK_SET);
806 982e53fe Calcium
        asf_write_header1(s, file_size, data_size - asf->data_offset);
807 542993b0 Konstantin Andreyev
    }
808
809
    put_flush_packet(&s->pb);
810 982e53fe Calcium
    av_free(asf->index_ptr);
811 542993b0 Konstantin Andreyev
    return 0;
812
}
813
814 ff70e601 Måns Rullgård
#ifdef CONFIG_ASF_MUXER
815 d2a067d1 Måns Rullgård
AVOutputFormat asf_muxer = {
816 542993b0 Konstantin Andreyev
    "asf",
817
    "asf format",
818
    "video/x-ms-asf",
819 87094371 Michael Niedermayer
    "asf,wmv,wma",
820 542993b0 Konstantin Andreyev
    sizeof(ASFContext),
821 6ebe07fb Diego Biurrun
#ifdef CONFIG_LIBMP3LAME
822 542993b0 Konstantin Andreyev
    CODEC_ID_MP3,
823
#else
824
    CODEC_ID_MP2,
825
#endif
826
    CODEC_ID_MSMPEG4V3,
827
    asf_write_header,
828
    asf_write_packet,
829
    asf_write_trailer,
830 982e53fe Calcium
    .flags = AVFMT_GLOBALHEADER,
831 6c77805f Michael Niedermayer
    .codec_tag= (const AVCodecTag*[]){codec_asf_bmp_tags, codec_bmp_tags, codec_wav_tags, 0},
832 542993b0 Konstantin Andreyev
};
833 ff70e601 Måns Rullgård
#endif
834 542993b0 Konstantin Andreyev
835 ff70e601 Måns Rullgård
#ifdef CONFIG_ASF_STREAM_MUXER
836 d2a067d1 Måns Rullgård
AVOutputFormat asf_stream_muxer = {
837 542993b0 Konstantin Andreyev
    "asf_stream",
838
    "asf format",
839
    "video/x-ms-asf",
840 87094371 Michael Niedermayer
    "asf,wmv,wma",
841 542993b0 Konstantin Andreyev
    sizeof(ASFContext),
842 6ebe07fb Diego Biurrun
#ifdef CONFIG_LIBMP3LAME
843 542993b0 Konstantin Andreyev
    CODEC_ID_MP3,
844
#else
845
    CODEC_ID_MP2,
846
#endif
847
    CODEC_ID_MSMPEG4V3,
848
    asf_write_stream_header,
849
    asf_write_packet,
850
    asf_write_trailer,
851 982e53fe Calcium
    .flags = AVFMT_GLOBALHEADER,
852 6c77805f Michael Niedermayer
    .codec_tag= (const AVCodecTag*[]){codec_asf_bmp_tags, codec_bmp_tags, codec_wav_tags, 0},
853 542993b0 Konstantin Andreyev
};
854 ff70e601 Måns Rullgård
#endif //CONFIG_ASF_STREAM_MUXER