Statistics
| Branch: | Revision:

ffmpeg / libavformat / asf-enc.c @ 0ab1ebea

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