Statistics
| Branch: | Revision:

ffmpeg / libavformat / rmenc.c @ acaceca2

History | View | Annotate | Download (15.2 KB)

1 7b2a2ce5 Aurelien Jacobs
/*
2
 * "Real" compatible muxer.
3 406792e7 Diego Biurrun
 * Copyright (c) 2000, 2001 Fabrice Bellard
4 7b2a2ce5 Aurelien Jacobs
 *
5 2912e87a Mans Rullgard
 * This file is part of Libav.
6 7b2a2ce5 Aurelien Jacobs
 *
7 2912e87a Mans Rullgard
 * Libav is free software; you can redistribute it and/or
8 7b2a2ce5 Aurelien Jacobs
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12 2912e87a Mans Rullgard
 * Libav is distributed in the hope that it will be useful,
13 7b2a2ce5 Aurelien Jacobs
 * 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 2912e87a Mans Rullgard
 * License along with Libav; if not, write to the Free Software
19 7b2a2ce5 Aurelien Jacobs
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21
#include "avformat.h"
22 0abdb293 Anton Khirnov
#include "avio_internal.h"
23 7b2a2ce5 Aurelien Jacobs
#include "rm.h"
24
25 1edddc99 Ronald S. Bultje
typedef struct {
26
    int nb_packets;
27
    int packet_total_size;
28
    int packet_max_size;
29
    /* codec related output */
30
    int bit_rate;
31
    float frame_rate;
32
    int nb_frames;    /* current frame number */
33
    int total_frames; /* total number of frames */
34
    int num;
35
    AVCodecContext *enc;
36
} StreamInfo;
37
38
typedef struct {
39
    StreamInfo streams[2];
40
    StreamInfo *audio_stream, *video_stream;
41
    int data_pos; /* position of the data after the header */
42
} RMMuxContext;
43
44 7b2a2ce5 Aurelien Jacobs
/* in ms */
45
#define BUFFER_DURATION 0
46
47
48 ae628ec1 Anton Khirnov
static void put_str(AVIOContext *s, const char *tag)
49 7b2a2ce5 Aurelien Jacobs
{
50 77eb5504 Anton Khirnov
    avio_wb16(s,strlen(tag));
51 7b2a2ce5 Aurelien Jacobs
    while (*tag) {
52 77eb5504 Anton Khirnov
        avio_w8(s, *tag++);
53 7b2a2ce5 Aurelien Jacobs
    }
54
}
55
56 ae628ec1 Anton Khirnov
static void put_str8(AVIOContext *s, const char *tag)
57 7b2a2ce5 Aurelien Jacobs
{
58 77eb5504 Anton Khirnov
    avio_w8(s, strlen(tag));
59 7b2a2ce5 Aurelien Jacobs
    while (*tag) {
60 77eb5504 Anton Khirnov
        avio_w8(s, *tag++);
61 7b2a2ce5 Aurelien Jacobs
    }
62
}
63
64 cff87f04 Francesco Lavra
static int rv10_write_header(AVFormatContext *ctx,
65 22a25584 Francesco Lavra
                             int data_size, int index_pos)
66 7b2a2ce5 Aurelien Jacobs
{
67 1edddc99 Ronald S. Bultje
    RMMuxContext *rm = ctx->priv_data;
68 ae628ec1 Anton Khirnov
    AVIOContext *s = ctx->pb;
69 7b2a2ce5 Aurelien Jacobs
    StreamInfo *stream;
70
    unsigned char *data_offset_ptr, *start_ptr;
71
    const char *desc, *mimetype;
72
    int nb_packets, packet_total_size, packet_max_size, size, packet_avg_size, i;
73
    int bit_rate, v, duration, flags, data_pos;
74 7379d5bc Aurelien Jacobs
    AVMetadataTag *tag;
75 7b2a2ce5 Aurelien Jacobs
76
    start_ptr = s->buf_ptr;
77
78 0abdb293 Anton Khirnov
    ffio_wfourcc(s, ".RMF");
79 77eb5504 Anton Khirnov
    avio_wb32(s,18); /* header size */
80
    avio_wb16(s,0);
81
    avio_wb32(s,0);
82
    avio_wb32(s,4 + ctx->nb_streams); /* num headers */
83 7b2a2ce5 Aurelien Jacobs
84 0abdb293 Anton Khirnov
    ffio_wfourcc(s,"PROP");
85 77eb5504 Anton Khirnov
    avio_wb32(s, 50);
86
    avio_wb16(s, 0);
87 7b2a2ce5 Aurelien Jacobs
    packet_max_size = 0;
88
    packet_total_size = 0;
89
    nb_packets = 0;
90
    bit_rate = 0;
91
    duration = 0;
92
    for(i=0;i<ctx->nb_streams;i++) {
93
        StreamInfo *stream = &rm->streams[i];
94
        bit_rate += stream->bit_rate;
95
        if (stream->packet_max_size > packet_max_size)
96
            packet_max_size = stream->packet_max_size;
97
        nb_packets += stream->nb_packets;
98
        packet_total_size += stream->packet_total_size;
99
        /* select maximum duration */
100
        v = (int) (1000.0 * (float)stream->total_frames / stream->frame_rate);
101
        if (v > duration)
102
            duration = v;
103
    }
104 77eb5504 Anton Khirnov
    avio_wb32(s, bit_rate); /* max bit rate */
105
    avio_wb32(s, bit_rate); /* avg bit rate */
106
    avio_wb32(s, packet_max_size);        /* max packet size */
107 7b2a2ce5 Aurelien Jacobs
    if (nb_packets > 0)
108
        packet_avg_size = packet_total_size / nb_packets;
109
    else
110
        packet_avg_size = 0;
111 77eb5504 Anton Khirnov
    avio_wb32(s, packet_avg_size);        /* avg packet size */
112
    avio_wb32(s, nb_packets);  /* num packets */
113
    avio_wb32(s, duration); /* duration */
114
    avio_wb32(s, BUFFER_DURATION);           /* preroll */
115
    avio_wb32(s, index_pos);           /* index offset */
116 7b2a2ce5 Aurelien Jacobs
    /* computation of data the data offset */
117
    data_offset_ptr = s->buf_ptr;
118 77eb5504 Anton Khirnov
    avio_wb32(s, 0);           /* data offset : will be patched after */
119
    avio_wb16(s, ctx->nb_streams);    /* num streams */
120 7b2a2ce5 Aurelien Jacobs
    flags = 1 | 2; /* save allowed & perfect play */
121 8978feda Anton Khirnov
    if (!s->seekable)
122 7b2a2ce5 Aurelien Jacobs
        flags |= 4; /* live broadcast */
123 77eb5504 Anton Khirnov
    avio_wb16(s, flags);
124 7b2a2ce5 Aurelien Jacobs
125
    /* comments */
126
127 0abdb293 Anton Khirnov
    ffio_wfourcc(s,"CONT");
128 7379d5bc Aurelien Jacobs
    size =  4 * 2 + 10;
129
    for(i=0; i<FF_ARRAY_ELEMS(ff_rm_metadata); i++) {
130
        tag = av_metadata_get(ctx->metadata, ff_rm_metadata[i], NULL, 0);
131
        if(tag) size += strlen(tag->value);
132
    }
133 77eb5504 Anton Khirnov
    avio_wb32(s,size);
134
    avio_wb16(s,0);
135 7379d5bc Aurelien Jacobs
    for(i=0; i<FF_ARRAY_ELEMS(ff_rm_metadata); i++) {
136
        tag = av_metadata_get(ctx->metadata, ff_rm_metadata[i], NULL, 0);
137
        put_str(s, tag ? tag->value : "");
138
    }
139 7b2a2ce5 Aurelien Jacobs
140
    for(i=0;i<ctx->nb_streams;i++) {
141
        int codec_data_size;
142
143
        stream = &rm->streams[i];
144
145 72415b2a Stefano Sabatini
        if (stream->enc->codec_type == AVMEDIA_TYPE_AUDIO) {
146 7b2a2ce5 Aurelien Jacobs
            desc = "The Audio Stream";
147
            mimetype = "audio/x-pn-realaudio";
148
            codec_data_size = 73;
149
        } else {
150
            desc = "The Video Stream";
151
            mimetype = "video/x-pn-realvideo";
152
            codec_data_size = 34;
153
        }
154
155 0abdb293 Anton Khirnov
        ffio_wfourcc(s,"MDPR");
156 7b2a2ce5 Aurelien Jacobs
        size = 10 + 9 * 4 + strlen(desc) + strlen(mimetype) + codec_data_size;
157 77eb5504 Anton Khirnov
        avio_wb32(s, size);
158
        avio_wb16(s, 0);
159 7b2a2ce5 Aurelien Jacobs
160 77eb5504 Anton Khirnov
        avio_wb16(s, i); /* stream number */
161
        avio_wb32(s, stream->bit_rate); /* max bit rate */
162
        avio_wb32(s, stream->bit_rate); /* avg bit rate */
163
        avio_wb32(s, stream->packet_max_size);        /* max packet size */
164 7b2a2ce5 Aurelien Jacobs
        if (stream->nb_packets > 0)
165
            packet_avg_size = stream->packet_total_size /
166
                stream->nb_packets;
167
        else
168
            packet_avg_size = 0;
169 77eb5504 Anton Khirnov
        avio_wb32(s, packet_avg_size);        /* avg packet size */
170
        avio_wb32(s, 0);           /* start time */
171
        avio_wb32(s, BUFFER_DURATION);           /* preroll */
172 7b2a2ce5 Aurelien Jacobs
        /* duration */
173 8978feda Anton Khirnov
        if (!s->seekable || !stream->total_frames)
174 77eb5504 Anton Khirnov
            avio_wb32(s, (int)(3600 * 1000));
175 7b2a2ce5 Aurelien Jacobs
        else
176 77eb5504 Anton Khirnov
            avio_wb32(s, (int)(stream->total_frames * 1000 / stream->frame_rate));
177 7b2a2ce5 Aurelien Jacobs
        put_str8(s, desc);
178
        put_str8(s, mimetype);
179 77eb5504 Anton Khirnov
        avio_wb32(s, codec_data_size);
180 7b2a2ce5 Aurelien Jacobs
181 72415b2a Stefano Sabatini
        if (stream->enc->codec_type == AVMEDIA_TYPE_AUDIO) {
182 7b2a2ce5 Aurelien Jacobs
            int coded_frame_size, fscode, sample_rate;
183
            sample_rate = stream->enc->sample_rate;
184
            coded_frame_size = (stream->enc->bit_rate *
185
                                stream->enc->frame_size) / (8 * sample_rate);
186
            /* audio codec info */
187 bbc413f9 Anton Khirnov
            avio_write(s, ".ra", 3);
188 77eb5504 Anton Khirnov
            avio_w8(s, 0xfd);
189
            avio_wb32(s, 0x00040000); /* version */
190 0abdb293 Anton Khirnov
            ffio_wfourcc(s, ".ra4");
191 77eb5504 Anton Khirnov
            avio_wb32(s, 0x01b53530); /* stream length */
192
            avio_wb16(s, 4); /* unknown */
193
            avio_wb32(s, 0x39); /* header size */
194 7b2a2ce5 Aurelien Jacobs
195
            switch(sample_rate) {
196
            case 48000:
197
            case 24000:
198
            case 12000:
199
                fscode = 1;
200
                break;
201
            default:
202
            case 44100:
203
            case 22050:
204
            case 11025:
205
                fscode = 2;
206
                break;
207
            case 32000:
208
            case 16000:
209
            case 8000:
210
                fscode = 3;
211
            }
212 77eb5504 Anton Khirnov
            avio_wb16(s, fscode); /* codec additional info, for AC-3, seems
213 7b2a2ce5 Aurelien Jacobs
                                     to be a frequency code */
214
            /* special hack to compensate rounding errors... */
215
            if (coded_frame_size == 557)
216
                coded_frame_size--;
217 77eb5504 Anton Khirnov
            avio_wb32(s, coded_frame_size); /* frame length */
218
            avio_wb32(s, 0x51540); /* unknown */
219
            avio_wb32(s, 0x249f0); /* unknown */
220
            avio_wb32(s, 0x249f0); /* unknown */
221
            avio_wb16(s, 0x01);
222 7b2a2ce5 Aurelien Jacobs
            /* frame length : seems to be very important */
223 77eb5504 Anton Khirnov
            avio_wb16(s, coded_frame_size);
224
            avio_wb32(s, 0); /* unknown */
225
            avio_wb16(s, stream->enc->sample_rate); /* sample rate */
226
            avio_wb32(s, 0x10); /* unknown */
227
            avio_wb16(s, stream->enc->channels);
228 7b2a2ce5 Aurelien Jacobs
            put_str8(s, "Int0"); /* codec name */
229 cff87f04 Francesco Lavra
            if (stream->enc->codec_tag) {
230 77eb5504 Anton Khirnov
                avio_w8(s, 4); /* tag length */
231
                avio_wl32(s, stream->enc->codec_tag);
232 cff87f04 Francesco Lavra
            } else {
233
                av_log(ctx, AV_LOG_ERROR, "Invalid codec tag\n");
234
                return -1;
235
            }
236 77eb5504 Anton Khirnov
            avio_wb16(s, 0); /* title length */
237
            avio_wb16(s, 0); /* author length */
238
            avio_wb16(s, 0); /* copyright length */
239
            avio_w8(s, 0); /* end of header */
240 7b2a2ce5 Aurelien Jacobs
        } else {
241
            /* video codec info */
242 77eb5504 Anton Khirnov
            avio_wb32(s,34); /* size */
243 0abdb293 Anton Khirnov
            ffio_wfourcc(s, "VIDO");
244 7b2a2ce5 Aurelien Jacobs
            if(stream->enc->codec_id == CODEC_ID_RV10)
245 0abdb293 Anton Khirnov
                ffio_wfourcc(s,"RV10");
246 7b2a2ce5 Aurelien Jacobs
            else
247 0abdb293 Anton Khirnov
                ffio_wfourcc(s,"RV20");
248 77eb5504 Anton Khirnov
            avio_wb16(s, stream->enc->width);
249
            avio_wb16(s, stream->enc->height);
250
            avio_wb16(s, (int) stream->frame_rate); /* frames per seconds ? */
251
            avio_wb32(s,0);     /* unknown meaning */
252
            avio_wb16(s, (int) stream->frame_rate);  /* unknown meaning */
253
            avio_wb32(s,0);     /* unknown meaning */
254
            avio_wb16(s, 8);    /* unknown meaning */
255 7b2a2ce5 Aurelien Jacobs
            /* Seems to be the codec version: only use basic H263. The next
256
               versions seems to add a diffential DC coding as in
257
               MPEG... nothing new under the sun */
258
            if(stream->enc->codec_id == CODEC_ID_RV10)
259 77eb5504 Anton Khirnov
                avio_wb32(s,0x10000000);
260 7b2a2ce5 Aurelien Jacobs
            else
261 77eb5504 Anton Khirnov
                avio_wb32(s,0x20103001);
262
            //avio_wb32(s,0x10003000);
263 7b2a2ce5 Aurelien Jacobs
        }
264
    }
265
266
    /* patch data offset field */
267
    data_pos = s->buf_ptr - start_ptr;
268
    rm->data_pos = data_pos;
269
    data_offset_ptr[0] = data_pos >> 24;
270
    data_offset_ptr[1] = data_pos >> 16;
271
    data_offset_ptr[2] = data_pos >> 8;
272
    data_offset_ptr[3] = data_pos;
273
274
    /* data stream */
275 0abdb293 Anton Khirnov
    ffio_wfourcc(s, "DATA");
276 77eb5504 Anton Khirnov
    avio_wb32(s,data_size + 10 + 8);
277
    avio_wb16(s,0);
278 7b2a2ce5 Aurelien Jacobs
279 77eb5504 Anton Khirnov
    avio_wb32(s, nb_packets); /* number of packets */
280
    avio_wb32(s,0); /* next data header */
281 cff87f04 Francesco Lavra
    return 0;
282 7b2a2ce5 Aurelien Jacobs
}
283
284
static void write_packet_header(AVFormatContext *ctx, StreamInfo *stream,
285
                                int length, int key_frame)
286
{
287
    int timestamp;
288 ae628ec1 Anton Khirnov
    AVIOContext *s = ctx->pb;
289 7b2a2ce5 Aurelien Jacobs
290
    stream->nb_packets++;
291
    stream->packet_total_size += length;
292
    if (length > stream->packet_max_size)
293
        stream->packet_max_size =  length;
294
295 77eb5504 Anton Khirnov
    avio_wb16(s,0); /* version */
296
    avio_wb16(s,length + 12);
297
    avio_wb16(s, stream->num); /* stream number */
298 7b2a2ce5 Aurelien Jacobs
    timestamp = (1000 * (float)stream->nb_frames) / stream->frame_rate;
299 77eb5504 Anton Khirnov
    avio_wb32(s, timestamp); /* timestamp */
300
    avio_w8(s, 0); /* reserved */
301
    avio_w8(s, key_frame ? 2 : 0); /* flags */
302 7b2a2ce5 Aurelien Jacobs
}
303
304
static int rm_write_header(AVFormatContext *s)
305
{
306 1edddc99 Ronald S. Bultje
    RMMuxContext *rm = s->priv_data;
307 7b2a2ce5 Aurelien Jacobs
    StreamInfo *stream;
308
    int n;
309
    AVCodecContext *codec;
310
311
    for(n=0;n<s->nb_streams;n++) {
312
        s->streams[n]->id = n;
313
        codec = s->streams[n]->codec;
314
        stream = &rm->streams[n];
315
        memset(stream, 0, sizeof(StreamInfo));
316
        stream->num = n;
317
        stream->bit_rate = codec->bit_rate;
318
        stream->enc = codec;
319
320
        switch(codec->codec_type) {
321 72415b2a Stefano Sabatini
        case AVMEDIA_TYPE_AUDIO:
322 7b2a2ce5 Aurelien Jacobs
            rm->audio_stream = stream;
323
            stream->frame_rate = (float)codec->sample_rate / (float)codec->frame_size;
324
            /* XXX: dummy values */
325
            stream->packet_max_size = 1024;
326
            stream->nb_packets = 0;
327
            stream->total_frames = stream->nb_packets;
328
            break;
329 72415b2a Stefano Sabatini
        case AVMEDIA_TYPE_VIDEO:
330 7b2a2ce5 Aurelien Jacobs
            rm->video_stream = stream;
331
            stream->frame_rate = (float)codec->time_base.den / (float)codec->time_base.num;
332
            /* XXX: dummy values */
333
            stream->packet_max_size = 4096;
334
            stream->nb_packets = 0;
335
            stream->total_frames = stream->nb_packets;
336
            break;
337
        default:
338
            return -1;
339
        }
340
    }
341
342 cff87f04 Francesco Lavra
    if (rv10_write_header(s, 0, 0))
343
        return AVERROR_INVALIDDATA;
344 b7f2fdde Anton Khirnov
    avio_flush(s->pb);
345 7b2a2ce5 Aurelien Jacobs
    return 0;
346
}
347
348
static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size, int flags)
349
{
350
    uint8_t *buf1;
351 1edddc99 Ronald S. Bultje
    RMMuxContext *rm = s->priv_data;
352 ae628ec1 Anton Khirnov
    AVIOContext *pb = s->pb;
353 7b2a2ce5 Aurelien Jacobs
    StreamInfo *stream = rm->audio_stream;
354
    int i;
355
356
    /* XXX: suppress this malloc */
357
    buf1= (uint8_t*) av_malloc( size * sizeof(uint8_t) );
358
359 cc947f04 Jean-Daniel Dupas
    write_packet_header(s, stream, size, !!(flags & AV_PKT_FLAG_KEY));
360 7b2a2ce5 Aurelien Jacobs
361 cff87f04 Francesco Lavra
    if (stream->enc->codec_id == CODEC_ID_AC3) {
362 22a25584 Francesco Lavra
        /* for AC-3, the words seem to be reversed */
363
        for(i=0;i<size;i+=2) {
364
            buf1[i] = buf[i+1];
365
            buf1[i+1] = buf[i];
366
        }
367 77eb5504 Anton Khirnov
        avio_write(pb, buf1, size);
368 cff87f04 Francesco Lavra
    } else {
369 77eb5504 Anton Khirnov
        avio_write(pb, buf, size);
370 cff87f04 Francesco Lavra
    }
371 b7f2fdde Anton Khirnov
    avio_flush(pb);
372 7b2a2ce5 Aurelien Jacobs
    stream->nb_frames++;
373
    av_free(buf1);
374
    return 0;
375
}
376
377
static int rm_write_video(AVFormatContext *s, const uint8_t *buf, int size, int flags)
378
{
379 1edddc99 Ronald S. Bultje
    RMMuxContext *rm = s->priv_data;
380 ae628ec1 Anton Khirnov
    AVIOContext *pb = s->pb;
381 7b2a2ce5 Aurelien Jacobs
    StreamInfo *stream = rm->video_stream;
382 cc947f04 Jean-Daniel Dupas
    int key_frame = !!(flags & AV_PKT_FLAG_KEY);
383 7b2a2ce5 Aurelien Jacobs
384
    /* XXX: this is incorrect: should be a parameter */
385
386
    /* Well, I spent some time finding the meaning of these bits. I am
387
       not sure I understood everything, but it works !! */
388
#if 1
389 47ac2b0d Kostya Shishkov
    write_packet_header(s, stream, size + 7 + (size >= 0x4000)*4, key_frame);
390 7b2a2ce5 Aurelien Jacobs
    /* bit 7: '1' if final packet of a frame converted in several packets */
391 77eb5504 Anton Khirnov
    avio_w8(pb, 0x81);
392 7b2a2ce5 Aurelien Jacobs
    /* bit 7: '1' if I frame. bits 6..0 : sequence number in current
393
       frame starting from 1 */
394
    if (key_frame) {
395 77eb5504 Anton Khirnov
        avio_w8(pb, 0x81);
396 7b2a2ce5 Aurelien Jacobs
    } else {
397 77eb5504 Anton Khirnov
        avio_w8(pb, 0x01);
398 7b2a2ce5 Aurelien Jacobs
    }
399 47ac2b0d Kostya Shishkov
    if(size >= 0x4000){
400 77eb5504 Anton Khirnov
        avio_wb32(pb, size); /* total frame size */
401
        avio_wb32(pb, size); /* offset from the start or the end */
402 47ac2b0d Kostya Shishkov
    }else{
403 77eb5504 Anton Khirnov
        avio_wb16(pb, 0x4000 | size); /* total frame size */
404
        avio_wb16(pb, 0x4000 | size); /* offset from the start or the end */
405 47ac2b0d Kostya Shishkov
    }
406 7b2a2ce5 Aurelien Jacobs
#else
407
    /* full frame */
408
    write_packet_header(s, size + 6);
409 77eb5504 Anton Khirnov
    avio_w8(pb, 0xc0);
410
    avio_wb16(pb, 0x4000 + size); /* total frame size */
411
    avio_wb16(pb, 0x4000 + packet_number * 126); /* position in stream */
412 7b2a2ce5 Aurelien Jacobs
#endif
413 77eb5504 Anton Khirnov
    avio_w8(pb, stream->nb_frames & 0xff);
414 7b2a2ce5 Aurelien Jacobs
415 77eb5504 Anton Khirnov
    avio_write(pb, buf, size);
416 b7f2fdde Anton Khirnov
    avio_flush(pb);
417 7b2a2ce5 Aurelien Jacobs
418
    stream->nb_frames++;
419
    return 0;
420
}
421
422
static int rm_write_packet(AVFormatContext *s, AVPacket *pkt)
423
{
424
    if (s->streams[pkt->stream_index]->codec->codec_type ==
425 72415b2a Stefano Sabatini
        AVMEDIA_TYPE_AUDIO)
426 7b2a2ce5 Aurelien Jacobs
        return rm_write_audio(s, pkt->data, pkt->size, pkt->flags);
427
    else
428
        return rm_write_video(s, pkt->data, pkt->size, pkt->flags);
429
}
430
431
static int rm_write_trailer(AVFormatContext *s)
432
{
433 1edddc99 Ronald S. Bultje
    RMMuxContext *rm = s->priv_data;
434 7b2a2ce5 Aurelien Jacobs
    int data_size, index_pos, i;
435 ae628ec1 Anton Khirnov
    AVIOContext *pb = s->pb;
436 7b2a2ce5 Aurelien Jacobs
437 8978feda Anton Khirnov
    if (s->pb->seekable) {
438 7b2a2ce5 Aurelien Jacobs
        /* end of file: finish to write header */
439 447fe336 Anton Khirnov
        index_pos = avio_tell(pb);
440 7b2a2ce5 Aurelien Jacobs
        data_size = index_pos - rm->data_pos;
441
442 8b9794e5 Ronald S. Bultje
        /* FIXME: write index */
443
444 7b2a2ce5 Aurelien Jacobs
        /* undocumented end header */
445 77eb5504 Anton Khirnov
        avio_wb32(pb, 0);
446
        avio_wb32(pb, 0);
447 7b2a2ce5 Aurelien Jacobs
448 6b4aa5da Anton Khirnov
        avio_seek(pb, 0, SEEK_SET);
449 7b2a2ce5 Aurelien Jacobs
        for(i=0;i<s->nb_streams;i++)
450
            rm->streams[i].total_frames = rm->streams[i].nb_frames;
451 8b9794e5 Ronald S. Bultje
        rv10_write_header(s, data_size, 0);
452 7b2a2ce5 Aurelien Jacobs
    } else {
453
        /* undocumented end header */
454 77eb5504 Anton Khirnov
        avio_wb32(pb, 0);
455
        avio_wb32(pb, 0);
456 7b2a2ce5 Aurelien Jacobs
    }
457 b7f2fdde Anton Khirnov
    avio_flush(pb);
458 7b2a2ce5 Aurelien Jacobs
    return 0;
459
}
460
461
462 c6610a21 Diego Elio Pettenò
AVOutputFormat ff_rm_muxer = {
463 7b2a2ce5 Aurelien Jacobs
    "rm",
464 517ac243 Diego Biurrun
    NULL_IF_CONFIG_SMALL("RealMedia format"),
465 7b2a2ce5 Aurelien Jacobs
    "application/vnd.rn-realmedia",
466
    "rm,ra",
467 1edddc99 Ronald S. Bultje
    sizeof(RMMuxContext),
468 7b2a2ce5 Aurelien Jacobs
    CODEC_ID_AC3,
469
    CODEC_ID_RV10,
470
    rm_write_header,
471
    rm_write_packet,
472
    rm_write_trailer,
473 cff87f04 Francesco Lavra
    .codec_tag= (const AVCodecTag* const []){ff_rm_codec_tags, 0},
474 7b2a2ce5 Aurelien Jacobs
};