Statistics
| Branch: | Revision:

ffmpeg / libavformat / asf-enc.c @ 5f8e0227

History | View | Annotate | Download (28.3 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 d7742a74 Baptiste Coudurier
    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 899681cd Björn Axelsson
    ByteIOContext *pb = s->pb;
248 542993b0 Konstantin Andreyev
    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 899681cd Björn Axelsson
    ByteIOContext *pb = s->pb;
274 542993b0 Konstantin Andreyev
    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 90901860 Michael Niedermayer
    asf->index_ptr = av_malloc( sizeof(ASFIndex) * ASF_INDEX_BLOCK );
497 982e53fe Calcium
    asf->nb_index_memory_alloc = ASF_INDEX_BLOCK;
498
    asf->nb_index_count = 0;
499
    asf->maximum_packet = 0;
500 542993b0 Konstantin Andreyev
501 ed7b48b2 Patric Stout
    /* the data-chunk-size has to be 50, which is data_size - asf->data_offset
502
     *  at the moment this function is done. It is needed to use asf as
503
     *  streamable format. */
504
    if (asf_write_header1(s, 0, 50) < 0) {
505 542993b0 Konstantin Andreyev
        //av_free(asf);
506
        return -1;
507
    }
508
509 899681cd Björn Axelsson
    put_flush_packet(s->pb);
510 542993b0 Konstantin Andreyev
511 615b92fd Konstantin Andreyev
    asf->packet_nb_payloads = 0;
512 542993b0 Konstantin Andreyev
    asf->packet_timestamp_start = -1;
513
    asf->packet_timestamp_end = -1;
514
    init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
515
                  NULL, NULL, NULL, NULL);
516
517
    return 0;
518
}
519
520
static int asf_write_stream_header(AVFormatContext *s)
521
{
522
    ASFContext *asf = s->priv_data;
523
524
    asf->is_streamed = 1;
525
526
    return asf_write_header(s);
527
}
528
529 615b92fd Konstantin Andreyev
static int put_payload_parsing_info(
530
                                AVFormatContext *s,
531 115329f1 Diego Biurrun
                                unsigned int    sendtime,
532 615b92fd Konstantin Andreyev
                                unsigned int    duration,
533 115329f1 Diego Biurrun
                                int             nb_payloads,
534 615b92fd Konstantin Andreyev
                                int             padsize
535
            )
536 542993b0 Konstantin Andreyev
{
537
    ASFContext *asf = s->priv_data;
538 899681cd Björn Axelsson
    ByteIOContext *pb = s->pb;
539 615b92fd Konstantin Andreyev
    int ppi_size, i;
540 ff5b8d83 Michael Niedermayer
    int64_t start= url_ftell(pb);
541 615b92fd Konstantin Andreyev
542
    int iLengthTypeFlags = ASF_PPI_LENGTH_TYPE_FLAGS;
543 115329f1 Diego Biurrun
544 2d241e66 Michael Niedermayer
    padsize -= PACKET_HEADER_MIN_SIZE;
545
    if(asf->multi_payloads_present)
546
        padsize--;
547
    assert(padsize>=0);
548
549 615b92fd Konstantin Andreyev
    put_byte(pb, ASF_PACKET_ERROR_CORRECTION_FLAGS);
550
    for (i = 0; i < ASF_PACKET_ERROR_CORRECTION_DATA_SIZE; i++){
551
        put_byte(pb, 0x0);
552 542993b0 Konstantin Andreyev
    }
553
554 615b92fd Konstantin Andreyev
    if (asf->multi_payloads_present)
555
        iLengthTypeFlags |= ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT;
556 542993b0 Konstantin Andreyev
557
    if (padsize > 0) {
558
        if (padsize < 256)
559 615b92fd Konstantin Andreyev
            iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE;
560 542993b0 Konstantin Andreyev
        else
561 615b92fd Konstantin Andreyev
            iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD;
562 542993b0 Konstantin Andreyev
    }
563 615b92fd Konstantin Andreyev
    put_byte(pb, iLengthTypeFlags);
564
565
    put_byte(pb, ASF_PPI_PROPERTY_FLAGS);
566
567
    if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD)
568 542993b0 Konstantin Andreyev
        put_le16(pb, padsize - 2);
569 615b92fd Konstantin Andreyev
    if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE)
570 542993b0 Konstantin Andreyev
        put_byte(pb, padsize - 1);
571 615b92fd Konstantin Andreyev
572
    put_le32(pb, sendtime);
573 542993b0 Konstantin Andreyev
    put_le16(pb, duration);
574 615b92fd Konstantin Andreyev
    if (asf->multi_payloads_present)
575
        put_byte(pb, nb_payloads | ASF_PAYLOAD_FLAGS);
576
577 ff5b8d83 Michael Niedermayer
    ppi_size = url_ftell(pb) - start;
578 542993b0 Konstantin Andreyev
579 615b92fd Konstantin Andreyev
    return ppi_size;
580 542993b0 Konstantin Andreyev
}
581
582
static void flush_packet(AVFormatContext *s)
583
{
584
    ASFContext *asf = s->priv_data;
585 615b92fd Konstantin Andreyev
    int packet_hdr_size, packet_filled_size;
586 542993b0 Konstantin Andreyev
587 a57c41b2 Michael Niedermayer
    assert(asf->packet_timestamp_end >= asf->packet_timestamp_start);
588
589 615b92fd Konstantin Andreyev
    if (asf->is_streamed) {
590
        put_chunk(s, 0x4424, asf->packet_size, 0);
591
    }
592
593
    packet_hdr_size = put_payload_parsing_info(
594
                            s,
595
                            asf->packet_timestamp_start,
596
                            asf->packet_timestamp_end - asf->packet_timestamp_start,
597
                            asf->packet_nb_payloads,
598
                            asf->packet_size_left
599
                        );
600 542993b0 Konstantin Andreyev
601 2d241e66 Michael Niedermayer
    packet_filled_size = PACKET_SIZE - asf->packet_size_left;
602
    assert(packet_hdr_size <= asf->packet_size_left);
603 615b92fd Konstantin Andreyev
    memset(asf->packet_buf + packet_filled_size, 0, asf->packet_size_left);
604 542993b0 Konstantin Andreyev
605 899681cd Björn Axelsson
    put_buffer(s->pb, asf->packet_buf, asf->packet_size - packet_hdr_size);
606 542993b0 Konstantin Andreyev
607 899681cd Björn Axelsson
    put_flush_packet(s->pb);
608 542993b0 Konstantin Andreyev
    asf->nb_packets++;
609 615b92fd Konstantin Andreyev
    asf->packet_nb_payloads = 0;
610 542993b0 Konstantin Andreyev
    asf->packet_timestamp_start = -1;
611
    asf->packet_timestamp_end = -1;
612
    init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
613
                  NULL, NULL, NULL, NULL);
614
}
615
616 615b92fd Konstantin Andreyev
static void put_payload_header(
617
                                AVFormatContext *s,
618
                                ASFStream       *stream,
619
                                int             presentation_time,
620
                                int             m_obj_size,
621
                                int             m_obj_offset,
622 3c895fc0 Michael Niedermayer
                                int             payload_len,
623
                                int             flags
624 615b92fd Konstantin Andreyev
            )
625 542993b0 Konstantin Andreyev
{
626
    ASFContext *asf = s->priv_data;
627
    ByteIOContext *pb = &asf->pb;
628
    int val;
629 115329f1 Diego Biurrun
630 542993b0 Konstantin Andreyev
    val = stream->num;
631 3c895fc0 Michael Niedermayer
    if (flags & PKT_FLAG_KEY)
632 615b92fd Konstantin Andreyev
        val |= ASF_PL_FLAG_KEY_FRAME;
633 542993b0 Konstantin Andreyev
    put_byte(pb, val);
634 115329f1 Diego Biurrun
635 615b92fd Konstantin Andreyev
    put_byte(pb, stream->seq);  //Media object number
636
    put_le32(pb, m_obj_offset); //Offset Into Media Object
637 115329f1 Diego Biurrun
638 615b92fd Konstantin Andreyev
    // Replicated Data shall be at least 8 bytes long.
639 115329f1 Diego Biurrun
    // The first 4 bytes of data shall contain the
640 615b92fd Konstantin Andreyev
    // Size of the Media Object that the payload belongs to.
641 115329f1 Diego Biurrun
    // The next 4 bytes of data shall contain the
642 615b92fd Konstantin Andreyev
    // Presentation Time for the media object that the payload belongs to.
643
    put_byte(pb, ASF_PAYLOAD_REPLICATED_DATA_LENGTH);
644
645
    put_le32(pb, m_obj_size);       //Replicated Data - Media Object Size
646
    put_le32(pb, presentation_time);//Replicated Data - Presentation Time
647 115329f1 Diego Biurrun
648 615b92fd Konstantin Andreyev
    if (asf->multi_payloads_present){
649
        put_le16(pb, payload_len);   //payload length
650
    }
651 542993b0 Konstantin Andreyev
}
652
653 615b92fd Konstantin Andreyev
static void put_frame(
654
                    AVFormatContext *s,
655
                    ASFStream       *stream,
656 75b213ed Michael Niedermayer
                    AVStream        *avst,
657 bb270c08 Diego Biurrun
                    int             timestamp,
658 615b92fd Konstantin Andreyev
                    const uint8_t   *buf,
659 bb270c08 Diego Biurrun
                    int             m_obj_size,
660 3c895fc0 Michael Niedermayer
                    int             flags
661 bb270c08 Diego Biurrun
                )
662 542993b0 Konstantin Andreyev
{
663
    ASFContext *asf = s->priv_data;
664 615b92fd Konstantin Andreyev
    int m_obj_offset, payload_len, frag_len1;
665
666
    m_obj_offset = 0;
667
    while (m_obj_offset < m_obj_size) {
668
        payload_len = m_obj_size - m_obj_offset;
669
        if (asf->packet_timestamp_start == -1) {
670
            asf->multi_payloads_present = (payload_len < MULTI_PAYLOAD_CONSTANT);
671 115329f1 Diego Biurrun
672 2d241e66 Michael Niedermayer
            asf->packet_size_left = PACKET_SIZE;
673 615b92fd Konstantin Andreyev
            if (asf->multi_payloads_present){
674
                frag_len1 = MULTI_PAYLOAD_CONSTANT - 1;
675
            }
676
            else {
677
                frag_len1 = SINGLE_PAYLOAD_DATA_LENGTH;
678
            }
679 190972a0 Michael Niedermayer
            asf->packet_timestamp_start = timestamp;
680 615b92fd Konstantin Andreyev
        }
681
        else {
682
            // multi payloads
683 2d241e66 Michael Niedermayer
            frag_len1 = asf->packet_size_left - PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS - PACKET_HEADER_MIN_SIZE - 1;
684 542993b0 Konstantin Andreyev
685 75b213ed Michael Niedermayer
            if(frag_len1 < payload_len && avst->codec->codec_type == CODEC_TYPE_AUDIO){
686
                flush_packet(s);
687
                continue;
688
            }
689 615b92fd Konstantin Andreyev
        }
690 542993b0 Konstantin Andreyev
        if (frag_len1 > 0) {
691 615b92fd Konstantin Andreyev
            if (payload_len > frag_len1)
692
                payload_len = frag_len1;
693
            else if (payload_len == (frag_len1 - 1))
694
                payload_len = frag_len1 - 2;  //additional byte need to put padding length
695 115329f1 Diego Biurrun
696 3caa0d93 Alex Beregszaszi
            put_payload_header(s, stream, timestamp+PREROLL_TIME, m_obj_size, m_obj_offset, payload_len, flags);
697 615b92fd Konstantin Andreyev
            put_buffer(&asf->pb, buf, payload_len);
698
699
            if (asf->multi_payloads_present)
700
                asf->packet_size_left -= (payload_len + PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS);
701
            else
702
                asf->packet_size_left -= (payload_len + PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD);
703 542993b0 Konstantin Andreyev
            asf->packet_timestamp_end = timestamp;
704 115329f1 Diego Biurrun
705 615b92fd Konstantin Andreyev
            asf->packet_nb_payloads++;
706 542993b0 Konstantin Andreyev
        } else {
707 615b92fd Konstantin Andreyev
            payload_len = 0;
708 542993b0 Konstantin Andreyev
        }
709 615b92fd Konstantin Andreyev
        m_obj_offset += payload_len;
710
        buf += payload_len;
711
712
        if (!asf->multi_payloads_present)
713
            flush_packet(s);
714 2d241e66 Michael Niedermayer
        else if (asf->packet_size_left <= (PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS + PACKET_HEADER_MIN_SIZE + 1))
715 542993b0 Konstantin Andreyev
            flush_packet(s);
716
    }
717
    stream->seq++;
718
}
719
720 e928649b Michael Niedermayer
static int asf_write_packet(AVFormatContext *s, AVPacket *pkt)
721 542993b0 Konstantin Andreyev
{
722
    ASFContext *asf = s->priv_data;
723
    ASFStream *stream;
724
    int64_t duration;
725
    AVCodecContext *codec;
726 115329f1 Diego Biurrun
    int64_t packet_st,pts;
727 982e53fe Calcium
    int start_sec,i;
728 0d9f8633 Michael Niedermayer
    int flags= pkt->flags;
729 542993b0 Konstantin Andreyev
730 01f4895c Michael Niedermayer
    codec = s->streams[pkt->stream_index]->codec;
731 e928649b Michael Niedermayer
    stream = &asf->streams[pkt->stream_index];
732 542993b0 Konstantin Andreyev
733 0d9f8633 Michael Niedermayer
    if(codec->codec_type == CODEC_TYPE_AUDIO)
734
        flags &= ~PKT_FLAG_KEY;
735
736 982e53fe Calcium
    pts = (pkt->pts != AV_NOPTS_VALUE) ? pkt->pts : pkt->dts;
737 9bc93229 Michael Niedermayer
    assert(pts != AV_NOPTS_VALUE);
738
    duration = pts * 10000;
739 4fa6eac5 Henrik Gulbrandsen
    asf->duration= FFMAX(asf->duration, duration + pkt->duration * 10000);
740 542993b0 Konstantin Andreyev
741 982e53fe Calcium
    packet_st = asf->nb_packets;
742 75b213ed Michael Niedermayer
    put_frame(s, stream, s->streams[pkt->stream_index], pkt->dts, pkt->data, pkt->size, flags);
743 982e53fe Calcium
744
    /* check index */
745 0d9f8633 Michael Niedermayer
    if ((!asf->is_streamed) && (flags & PKT_FLAG_KEY)) {
746 8da9266c Måns Rullgård
        start_sec = (int)(duration / INT64_C(10000000));
747
        if (start_sec != (int)(asf->last_indexed_pts / INT64_C(10000000))) {
748 982e53fe Calcium
            for(i=asf->nb_index_count;i<start_sec;i++) {
749
                if (i>=asf->nb_index_memory_alloc) {
750
                    asf->nb_index_memory_alloc += ASF_INDEX_BLOCK;
751
                    asf->index_ptr = (ASFIndex*)av_realloc( asf->index_ptr, sizeof(ASFIndex) * asf->nb_index_memory_alloc );
752
                }
753
                // store
754
                asf->index_ptr[i].packet_number = (uint32_t)packet_st;
755
                asf->index_ptr[i].packet_count  = (uint16_t)(asf->nb_packets-packet_st);
756 d65b8230 Michael Niedermayer
                asf->maximum_packet = FFMAX(asf->maximum_packet, (uint16_t)(asf->nb_packets-packet_st));
757 982e53fe Calcium
            }
758
            asf->nb_index_count = start_sec;
759
            asf->last_indexed_pts = duration;
760
        }
761
    }
762
    return 0;
763
}
764
765
//
766
static int asf_write_index(AVFormatContext *s, ASFIndex *index, uint16_t max, uint32_t count)
767
{
768 899681cd Björn Axelsson
    ByteIOContext *pb = s->pb;
769 982e53fe Calcium
    int i;
770
771
    put_guid(pb, &simple_index_header);
772
    put_le64(pb, 24 + 16 + 8 + 4 + 4 + (4 + 2)*count);
773
    put_guid(pb, &my_guid);
774
    put_le64(pb, ASF_INDEXED_INTERVAL);
775
    put_le32(pb, max);
776
    put_le32(pb, count);
777
    for(i=0; i<count; i++) {
778
        put_le32(pb, index[i].packet_number);
779
        put_le16(pb, index[i].packet_count);
780
    }
781
782 542993b0 Konstantin Andreyev
    return 0;
783
}
784
785
static int asf_write_trailer(AVFormatContext *s)
786
{
787
    ASFContext *asf = s->priv_data;
788 982e53fe Calcium
    int64_t file_size,data_size;
789 542993b0 Konstantin Andreyev
790
    /* flush the current packet */
791
    if (asf->pb.buf_ptr > asf->pb.buffer)
792
        flush_packet(s);
793
794 982e53fe Calcium
    /* write index */
795 899681cd Björn Axelsson
    data_size = url_ftell(s->pb);
796 982e53fe Calcium
    if ((!asf->is_streamed) && (asf->nb_index_count != 0)) {
797
        asf_write_index(s, asf->index_ptr, asf->maximum_packet, asf->nb_index_count);
798
    }
799 899681cd Björn Axelsson
    put_flush_packet(s->pb);
800 982e53fe Calcium
801 899681cd Björn Axelsson
    if (asf->is_streamed || url_is_streamed(s->pb)) {
802 542993b0 Konstantin Andreyev
        put_chunk(s, 0x4524, 0, 0); /* end of stream */
803
    } else {
804
        /* rewrite an updated header */
805 899681cd Björn Axelsson
        file_size = url_ftell(s->pb);
806
        url_fseek(s->pb, 0, SEEK_SET);
807 982e53fe Calcium
        asf_write_header1(s, file_size, data_size - asf->data_offset);
808 542993b0 Konstantin Andreyev
    }
809
810 899681cd Björn Axelsson
    put_flush_packet(s->pb);
811 982e53fe Calcium
    av_free(asf->index_ptr);
812 542993b0 Konstantin Andreyev
    return 0;
813
}
814
815 ff70e601 Måns Rullgård
#ifdef CONFIG_ASF_MUXER
816 d2a067d1 Måns Rullgård
AVOutputFormat asf_muxer = {
817 542993b0 Konstantin Andreyev
    "asf",
818 bde15e74 Stefano Sabatini
    NULL_IF_CONFIG_SMALL("ASF format"),
819 542993b0 Konstantin Andreyev
    "video/x-ms-asf",
820 87094371 Michael Niedermayer
    "asf,wmv,wma",
821 542993b0 Konstantin Andreyev
    sizeof(ASFContext),
822 6ebe07fb Diego Biurrun
#ifdef CONFIG_LIBMP3LAME
823 542993b0 Konstantin Andreyev
    CODEC_ID_MP3,
824
#else
825
    CODEC_ID_MP2,
826
#endif
827
    CODEC_ID_MSMPEG4V3,
828
    asf_write_header,
829
    asf_write_packet,
830
    asf_write_trailer,
831 982e53fe Calcium
    .flags = AVFMT_GLOBALHEADER,
832 6c77805f Michael Niedermayer
    .codec_tag= (const AVCodecTag*[]){codec_asf_bmp_tags, codec_bmp_tags, codec_wav_tags, 0},
833 542993b0 Konstantin Andreyev
};
834 ff70e601 Måns Rullgård
#endif
835 542993b0 Konstantin Andreyev
836 ff70e601 Måns Rullgård
#ifdef CONFIG_ASF_STREAM_MUXER
837 d2a067d1 Måns Rullgård
AVOutputFormat asf_stream_muxer = {
838 542993b0 Konstantin Andreyev
    "asf_stream",
839 bde15e74 Stefano Sabatini
    NULL_IF_CONFIG_SMALL("ASF format"),
840 542993b0 Konstantin Andreyev
    "video/x-ms-asf",
841 87094371 Michael Niedermayer
    "asf,wmv,wma",
842 542993b0 Konstantin Andreyev
    sizeof(ASFContext),
843 6ebe07fb Diego Biurrun
#ifdef CONFIG_LIBMP3LAME
844 542993b0 Konstantin Andreyev
    CODEC_ID_MP3,
845
#else
846
    CODEC_ID_MP2,
847
#endif
848
    CODEC_ID_MSMPEG4V3,
849
    asf_write_stream_header,
850
    asf_write_packet,
851
    asf_write_trailer,
852 982e53fe Calcium
    .flags = AVFMT_GLOBALHEADER,
853 6c77805f Michael Niedermayer
    .codec_tag= (const AVCodecTag*[]){codec_asf_bmp_tags, codec_bmp_tags, codec_wav_tags, 0},
854 542993b0 Konstantin Andreyev
};
855 ff70e601 Måns Rullgård
#endif //CONFIG_ASF_STREAM_MUXER