annotate rmenc.c @ 6333:f5fec1ab4925 libavformat

Skip short padding in id3v2. Patch by Alexander Kojevnikov, alexander kojevnikov com
author cehoyos
date Wed, 28 Jul 2010 08:06:52 +0000
parents 490c440a53e7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
2103
95139f2053a9 split rm muxer and demuxer in their own files
aurel
parents: 2024
diff changeset
2 * "Real" compatible muxer.
4251
77e0c7511d41 cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 4097
diff changeset
3 * Copyright (c) 2000, 2001 Fabrice Bellard
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1350
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1350
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1350
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1350
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1350
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1350
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 888
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 #include "avformat.h"
2103
95139f2053a9 split rm muxer and demuxer in their own files
aurel
parents: 2024
diff changeset
22 #include "rm.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23
4097
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
24 typedef struct {
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
25 int nb_packets;
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
26 int packet_total_size;
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
27 int packet_max_size;
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
28 /* codec related output */
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
29 int bit_rate;
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
30 float frame_rate;
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
31 int nb_frames; /* current frame number */
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
32 int total_frames; /* total number of frames */
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
33 int num;
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
34 AVCodecContext *enc;
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
35 } StreamInfo;
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
36
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
37 typedef struct {
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
38 StreamInfo streams[2];
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
39 StreamInfo *audio_stream, *video_stream;
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
40 int data_pos; /* position of the data after the header */
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
41 } RMMuxContext;
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
42
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 /* in ms */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
44 #define BUFFER_DURATION 0
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 static void put_str(ByteIOContext *s, const char *tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 put_be16(s,strlen(tag));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 while (*tag) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 put_byte(s, *tag++);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 static void put_str8(ByteIOContext *s, const char *tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 put_byte(s, strlen(tag));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 while (*tag) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 put_byte(s, *tag++);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62
6065
441608273a5c Use ff_rm_codec_tags[] in RM muxer. This, incidentally, also allows muxing
rbultje
parents: 5913
diff changeset
63 static int rv10_write_header(AVFormatContext *ctx,
6066
490c440a53e7 Reindent after r23361.
rbultje
parents: 6065
diff changeset
64 int data_size, int index_pos)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 {
4097
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
66 RMMuxContext *rm = ctx->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2103
diff changeset
67 ByteIOContext *s = ctx->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 StreamInfo *stream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 unsigned char *data_offset_ptr, *start_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 const char *desc, *mimetype;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 int nb_packets, packet_total_size, packet_max_size, size, packet_avg_size, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 int bit_rate, v, duration, flags, data_pos;
4522
aaf07b2acb3c use new metadata API in rm (de)muxer
aurel
parents: 4465
diff changeset
73 AVMetadataTag *tag;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 start_ptr = s->buf_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 put_tag(s, ".RMF");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 put_be32(s,18); /* header size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 put_be16(s,0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 put_be32(s,0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 put_be32(s,4 + ctx->nb_streams); /* num headers */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 put_tag(s,"PROP");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 put_be32(s, 50);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 put_be16(s, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 packet_max_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 packet_total_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 nb_packets = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 bit_rate = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 duration = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 for(i=0;i<ctx->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 StreamInfo *stream = &rm->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 bit_rate += stream->bit_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 if (stream->packet_max_size > packet_max_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 packet_max_size = stream->packet_max_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 nb_packets += stream->nb_packets;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 packet_total_size += stream->packet_total_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 /* select maximum duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 v = (int) (1000.0 * (float)stream->total_frames / stream->frame_rate);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 if (v > duration)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 duration = v;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 put_be32(s, bit_rate); /* max bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 put_be32(s, bit_rate); /* avg bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 put_be32(s, packet_max_size); /* max packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 if (nb_packets > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 packet_avg_size = packet_total_size / nb_packets;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 packet_avg_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 put_be32(s, packet_avg_size); /* avg packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 put_be32(s, nb_packets); /* num packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 put_be32(s, duration); /* duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 put_be32(s, BUFFER_DURATION); /* preroll */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 put_be32(s, index_pos); /* index offset */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 /* computation of data the data offset */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 data_offset_ptr = s->buf_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 put_be32(s, 0); /* data offset : will be patched after */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 put_be16(s, ctx->nb_streams); /* num streams */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 flags = 1 | 2; /* save allowed & perfect play */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 if (url_is_streamed(s))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 flags |= 4; /* live broadcast */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 put_be16(s, flags);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
123
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 /* comments */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 put_tag(s,"CONT");
4522
aaf07b2acb3c use new metadata API in rm (de)muxer
aurel
parents: 4465
diff changeset
127 size = 4 * 2 + 10;
aaf07b2acb3c use new metadata API in rm (de)muxer
aurel
parents: 4465
diff changeset
128 for(i=0; i<FF_ARRAY_ELEMS(ff_rm_metadata); i++) {
aaf07b2acb3c use new metadata API in rm (de)muxer
aurel
parents: 4465
diff changeset
129 tag = av_metadata_get(ctx->metadata, ff_rm_metadata[i], NULL, 0);
aaf07b2acb3c use new metadata API in rm (de)muxer
aurel
parents: 4465
diff changeset
130 if(tag) size += strlen(tag->value);
aaf07b2acb3c use new metadata API in rm (de)muxer
aurel
parents: 4465
diff changeset
131 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 put_be32(s,size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 put_be16(s,0);
4522
aaf07b2acb3c use new metadata API in rm (de)muxer
aurel
parents: 4465
diff changeset
134 for(i=0; i<FF_ARRAY_ELEMS(ff_rm_metadata); i++) {
aaf07b2acb3c use new metadata API in rm (de)muxer
aurel
parents: 4465
diff changeset
135 tag = av_metadata_get(ctx->metadata, ff_rm_metadata[i], NULL, 0);
aaf07b2acb3c use new metadata API in rm (de)muxer
aurel
parents: 4465
diff changeset
136 put_str(s, tag ? tag->value : "");
aaf07b2acb3c use new metadata API in rm (de)muxer
aurel
parents: 4465
diff changeset
137 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
138
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 for(i=0;i<ctx->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 int codec_data_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 stream = &rm->streams[i];
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
143
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 4770
diff changeset
144 if (stream->enc->codec_type == AVMEDIA_TYPE_AUDIO) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 desc = "The Audio Stream";
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 mimetype = "audio/x-pn-realaudio";
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 codec_data_size = 73;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 desc = "The Video Stream";
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150 mimetype = "video/x-pn-realvideo";
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151 codec_data_size = 34;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 put_tag(s,"MDPR");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155 size = 10 + 9 * 4 + strlen(desc) + strlen(mimetype) + codec_data_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 put_be32(s, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157 put_be16(s, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 put_be16(s, i); /* stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 put_be32(s, stream->bit_rate); /* max bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 put_be32(s, stream->bit_rate); /* avg bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 put_be32(s, stream->packet_max_size); /* max packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 if (stream->nb_packets > 0)
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
164 packet_avg_size = stream->packet_total_size /
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 stream->nb_packets;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 packet_avg_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 put_be32(s, packet_avg_size); /* avg packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 put_be32(s, 0); /* start time */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 put_be32(s, BUFFER_DURATION); /* preroll */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 /* duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 if (url_is_streamed(s) || !stream->total_frames)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 put_be32(s, (int)(3600 * 1000));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 put_be32(s, (int)(stream->total_frames * 1000 / stream->frame_rate));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 put_str8(s, desc);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 put_str8(s, mimetype);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 put_be32(s, codec_data_size);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
179
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 4770
diff changeset
180 if (stream->enc->codec_type == AVMEDIA_TYPE_AUDIO) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181 int coded_frame_size, fscode, sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 sample_rate = stream->enc->sample_rate;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
183 coded_frame_size = (stream->enc->bit_rate *
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 stream->enc->frame_size) / (8 * sample_rate);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 /* audio codec info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 put_tag(s, ".ra");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 put_byte(s, 0xfd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 put_be32(s, 0x00040000); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 put_tag(s, ".ra4");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 put_be32(s, 0x01b53530); /* stream length */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 put_be16(s, 4); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 put_be32(s, 0x39); /* header size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 switch(sample_rate) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 case 48000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 case 24000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 case 12000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 fscode = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 case 44100:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 case 22050:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 case 11025:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 fscode = 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 case 32000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 case 16000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 case 8000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 fscode = 3;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 }
3624
8b4be8aa2324 cosmetics: make all references to AC-3 capitalized and hyphenated
jbr
parents: 3424
diff changeset
211 put_be16(s, fscode); /* codec additional info, for AC-3, seems
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 to be a frequency code */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 /* special hack to compensate rounding errors... */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 if (coded_frame_size == 557)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 coded_frame_size--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 put_be32(s, coded_frame_size); /* frame length */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 put_be32(s, 0x51540); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 put_be32(s, 0x249f0); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 put_be32(s, 0x249f0); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 put_be16(s, 0x01);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 /* frame length : seems to be very important */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
222 put_be16(s, coded_frame_size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 put_be32(s, 0); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 put_be16(s, stream->enc->sample_rate); /* sample rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 put_be32(s, 0x10); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 put_be16(s, stream->enc->channels);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 put_str8(s, "Int0"); /* codec name */
6065
441608273a5c Use ff_rm_codec_tags[] in RM muxer. This, incidentally, also allows muxing
rbultje
parents: 5913
diff changeset
228 if (stream->enc->codec_tag) {
441608273a5c Use ff_rm_codec_tags[] in RM muxer. This, incidentally, also allows muxing
rbultje
parents: 5913
diff changeset
229 put_byte(s, 4); /* tag length */
441608273a5c Use ff_rm_codec_tags[] in RM muxer. This, incidentally, also allows muxing
rbultje
parents: 5913
diff changeset
230 put_le32(s, stream->enc->codec_tag);
441608273a5c Use ff_rm_codec_tags[] in RM muxer. This, incidentally, also allows muxing
rbultje
parents: 5913
diff changeset
231 } else {
441608273a5c Use ff_rm_codec_tags[] in RM muxer. This, incidentally, also allows muxing
rbultje
parents: 5913
diff changeset
232 av_log(ctx, AV_LOG_ERROR, "Invalid codec tag\n");
441608273a5c Use ff_rm_codec_tags[] in RM muxer. This, incidentally, also allows muxing
rbultje
parents: 5913
diff changeset
233 return -1;
441608273a5c Use ff_rm_codec_tags[] in RM muxer. This, incidentally, also allows muxing
rbultje
parents: 5913
diff changeset
234 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 put_be16(s, 0); /* title length */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 put_be16(s, 0); /* author length */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 put_be16(s, 0); /* copyright length */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 put_byte(s, 0); /* end of header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 /* video codec info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 put_be32(s,34); /* size */
614
cbcb3ae970c8 rv20 encoding
michael
parents: 613
diff changeset
242 if(stream->enc->codec_id == CODEC_ID_RV10)
cbcb3ae970c8 rv20 encoding
michael
parents: 613
diff changeset
243 put_tag(s,"VIDORV10");
cbcb3ae970c8 rv20 encoding
michael
parents: 613
diff changeset
244 else
cbcb3ae970c8 rv20 encoding
michael
parents: 613
diff changeset
245 put_tag(s,"VIDORV20");
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 put_be16(s, stream->enc->width);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 put_be16(s, stream->enc->height);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 put_be16(s, (int) stream->frame_rate); /* frames per seconds ? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 put_be32(s,0); /* unknown meaning */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 put_be16(s, (int) stream->frame_rate); /* unknown meaning */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 put_be32(s,0); /* unknown meaning */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 put_be16(s, 8); /* unknown meaning */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 /* Seems to be the codec version: only use basic H263. The next
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 versions seems to add a diffential DC coding as in
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 MPEG... nothing new under the sun */
614
cbcb3ae970c8 rv20 encoding
michael
parents: 613
diff changeset
256 if(stream->enc->codec_id == CODEC_ID_RV10)
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
257 put_be32(s,0x10000000);
614
cbcb3ae970c8 rv20 encoding
michael
parents: 613
diff changeset
258 else
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
259 put_be32(s,0x20103001);
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
260 //put_be32(s,0x10003000);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 /* patch data offset field */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 data_pos = s->buf_ptr - start_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 rm->data_pos = data_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267 data_offset_ptr[0] = data_pos >> 24;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
268 data_offset_ptr[1] = data_pos >> 16;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 data_offset_ptr[2] = data_pos >> 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
270 data_offset_ptr[3] = data_pos;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
271
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272 /* data stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273 put_tag(s,"DATA");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 put_be32(s,data_size + 10 + 8);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275 put_be16(s,0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 put_be32(s, nb_packets); /* number of packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 put_be32(s,0); /* next data header */
6065
441608273a5c Use ff_rm_codec_tags[] in RM muxer. This, incidentally, also allows muxing
rbultje
parents: 5913
diff changeset
279 return 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
282 static void write_packet_header(AVFormatContext *ctx, StreamInfo *stream,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283 int length, int key_frame)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285 int timestamp;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2103
diff changeset
286 ByteIOContext *s = ctx->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288 stream->nb_packets++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289 stream->packet_total_size += length;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 if (length > stream->packet_max_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291 stream->packet_max_size = length;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293 put_be16(s,0); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 put_be16(s,length + 12);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295 put_be16(s, stream->num); /* stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
296 timestamp = (1000 * (float)stream->nb_frames) / stream->frame_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
297 put_be32(s, timestamp); /* timestamp */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
298 put_byte(s, 0); /* reserved */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
299 put_byte(s, key_frame ? 2 : 0); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
302 static int rm_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303 {
4097
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
304 RMMuxContext *rm = s->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
305 StreamInfo *stream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306 int n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307 AVCodecContext *codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
308
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309 for(n=0;n<s->nb_streams;n++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310 s->streams[n]->id = n;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
311 codec = s->streams[n]->codec;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
312 stream = &rm->streams[n];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
313 memset(stream, 0, sizeof(StreamInfo));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
314 stream->num = n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315 stream->bit_rate = codec->bit_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316 stream->enc = codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
317
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318 switch(codec->codec_type) {
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 4770
diff changeset
319 case AVMEDIA_TYPE_AUDIO:
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
320 rm->audio_stream = stream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
321 stream->frame_rate = (float)codec->sample_rate / (float)codec->frame_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
322 /* XXX: dummy values */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
323 stream->packet_max_size = 1024;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
324 stream->nb_packets = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
325 stream->total_frames = stream->nb_packets;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326 break;
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 4770
diff changeset
327 case AVMEDIA_TYPE_VIDEO:
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328 rm->video_stream = stream;
743
af4e24d6310c switch to native time bases
michael
parents: 736
diff changeset
329 stream->frame_rate = (float)codec->time_base.den / (float)codec->time_base.num;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330 /* XXX: dummy values */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331 stream->packet_max_size = 4096;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332 stream->nb_packets = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333 stream->total_frames = stream->nb_packets;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335 default:
537
558a093b04db do not call (av_)abort()
michael
parents: 509
diff changeset
336 return -1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339
6065
441608273a5c Use ff_rm_codec_tags[] in RM muxer. This, incidentally, also allows muxing
rbultje
parents: 5913
diff changeset
340 if (rv10_write_header(s, 0, 0))
441608273a5c Use ff_rm_codec_tags[] in RM muxer. This, incidentally, also allows muxing
rbultje
parents: 5913
diff changeset
341 return AVERROR_INVALIDDATA;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2103
diff changeset
342 put_flush_packet(s->pb);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
344 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
345
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
346 static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size, int flags)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 33
diff changeset
348 uint8_t *buf1;
4097
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
349 RMMuxContext *rm = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2103
diff changeset
350 ByteIOContext *pb = s->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351 StreamInfo *stream = rm->audio_stream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
353
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
354 /* XXX: suppress this malloc */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 33
diff changeset
355 buf1= (uint8_t*) av_malloc( size * sizeof(uint8_t) );
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
356
5913
11bb10c37225 Replace all occurences of PKT_FLAG_KEY with AV_PKT_FLAG_KEY.
cehoyos
parents: 5910
diff changeset
357 write_packet_header(s, stream, size, !!(flags & AV_PKT_FLAG_KEY));
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
358
6065
441608273a5c Use ff_rm_codec_tags[] in RM muxer. This, incidentally, also allows muxing
rbultje
parents: 5913
diff changeset
359 if (stream->enc->codec_id == CODEC_ID_AC3) {
6066
490c440a53e7 Reindent after r23361.
rbultje
parents: 6065
diff changeset
360 /* for AC-3, the words seem to be reversed */
490c440a53e7 Reindent after r23361.
rbultje
parents: 6065
diff changeset
361 for(i=0;i<size;i+=2) {
490c440a53e7 Reindent after r23361.
rbultje
parents: 6065
diff changeset
362 buf1[i] = buf[i+1];
490c440a53e7 Reindent after r23361.
rbultje
parents: 6065
diff changeset
363 buf1[i+1] = buf[i];
490c440a53e7 Reindent after r23361.
rbultje
parents: 6065
diff changeset
364 }
490c440a53e7 Reindent after r23361.
rbultje
parents: 6065
diff changeset
365 put_buffer(pb, buf1, size);
6065
441608273a5c Use ff_rm_codec_tags[] in RM muxer. This, incidentally, also allows muxing
rbultje
parents: 5913
diff changeset
366 } else {
441608273a5c Use ff_rm_codec_tags[] in RM muxer. This, incidentally, also allows muxing
rbultje
parents: 5913
diff changeset
367 put_buffer(pb, buf, size);
441608273a5c Use ff_rm_codec_tags[] in RM muxer. This, incidentally, also allows muxing
rbultje
parents: 5913
diff changeset
368 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
369 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
370 stream->nb_frames++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
371 av_free(buf1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
372 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
373 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
374
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
375 static int rm_write_video(AVFormatContext *s, const uint8_t *buf, int size, int flags)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 {
4097
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
377 RMMuxContext *rm = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2103
diff changeset
378 ByteIOContext *pb = s->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
379 StreamInfo *stream = rm->video_stream;
5913
11bb10c37225 Replace all occurences of PKT_FLAG_KEY with AV_PKT_FLAG_KEY.
cehoyos
parents: 5910
diff changeset
380 int key_frame = !!(flags & AV_PKT_FLAG_KEY);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
381
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
382 /* XXX: this is incorrect: should be a parameter */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
383
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
384 /* Well, I spent some time finding the meaning of these bits. I am
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
385 not sure I understood everything, but it works !! */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
386 #if 1
2792
e0a046abae56 Fix muxer so that generated files are playable by realplayer, other open
rtogni
parents: 2771
diff changeset
387 write_packet_header(s, stream, size + 7 + (size >= 0x4000)*4, key_frame);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
388 /* bit 7: '1' if final packet of a frame converted in several packets */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
389 put_byte(pb, 0x81);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
390 /* bit 7: '1' if I frame. bits 6..0 : sequence number in current
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
391 frame starting from 1 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392 if (key_frame) {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
393 put_byte(pb, 0x81);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 } else {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
395 put_byte(pb, 0x01);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396 }
2792
e0a046abae56 Fix muxer so that generated files are playable by realplayer, other open
rtogni
parents: 2771
diff changeset
397 if(size >= 0x4000){
e0a046abae56 Fix muxer so that generated files are playable by realplayer, other open
rtogni
parents: 2771
diff changeset
398 put_be32(pb, size); /* total frame size */
e0a046abae56 Fix muxer so that generated files are playable by realplayer, other open
rtogni
parents: 2771
diff changeset
399 put_be32(pb, size); /* offset from the start or the end */
e0a046abae56 Fix muxer so that generated files are playable by realplayer, other open
rtogni
parents: 2771
diff changeset
400 }else{
e0a046abae56 Fix muxer so that generated files are playable by realplayer, other open
rtogni
parents: 2771
diff changeset
401 put_be16(pb, 0x4000 | size); /* total frame size */
e0a046abae56 Fix muxer so that generated files are playable by realplayer, other open
rtogni
parents: 2771
diff changeset
402 put_be16(pb, 0x4000 | size); /* offset from the start or the end */
e0a046abae56 Fix muxer so that generated files are playable by realplayer, other open
rtogni
parents: 2771
diff changeset
403 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405 /* full frame */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
406 write_packet_header(s, size + 6);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
407 put_byte(pb, 0xc0);
611
8fcecf36e64c rm encoding fix
michael
parents: 610
diff changeset
408 put_be16(pb, 0x4000 + size); /* total frame size */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
409 put_be16(pb, 0x4000 + packet_number * 126); /* position in stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410 #endif
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
411 put_byte(pb, stream->nb_frames & 0xff);
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
412
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 put_buffer(pb, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 stream->nb_frames++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 370
diff changeset
420 static int rm_write_packet(AVFormatContext *s, AVPacket *pkt)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
421 {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
422 if (s->streams[pkt->stream_index]->codec->codec_type ==
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 4770
diff changeset
423 AVMEDIA_TYPE_AUDIO)
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
424 return rm_write_audio(s, pkt->data, pkt->size, pkt->flags);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
425 else
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
426 return rm_write_video(s, pkt->data, pkt->size, pkt->flags);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
428
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429 static int rm_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
430 {
4097
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
431 RMMuxContext *rm = s->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432 int data_size, index_pos, i;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2103
diff changeset
433 ByteIOContext *pb = s->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
434
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2103
diff changeset
435 if (!url_is_streamed(s->pb)) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 /* end of file: finish to write header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 index_pos = url_fseek(pb, 0, SEEK_CUR);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 data_size = index_pos - rm->data_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439
4770
7875964b4a58 Remove index writing in RM muxer, since it is broken (multiple streams per
rbultje
parents: 4522
diff changeset
440 /* FIXME: write index */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
441
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 /* undocumented end header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 put_be32(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 put_be32(pb, 0);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
445
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446 url_fseek(pb, 0, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447 for(i=0;i<s->nb_streams;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 rm->streams[i].total_frames = rm->streams[i].nb_frames;
4770
7875964b4a58 Remove index writing in RM muxer, since it is broken (multiple streams per
rbultje
parents: 4522
diff changeset
449 rv10_write_header(s, data_size, 0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451 /* undocumented end header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452 put_be32(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453 put_be32(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
454 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
456 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
457 }
613
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
458
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
459
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
460 AVOutputFormat rm_muxer = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461 "rm",
4465
042e9a2fdda2 Use more descriptive format long_names.
diego
parents: 4251
diff changeset
462 NULL_IF_CONFIG_SMALL("RealMedia format"),
14
b167760cd0aa mimetype fixes patch by (Ryutaroh Matsumoto <ryutaroh at it dot ss dot titech dot ac dot jp>)
michaelni
parents: 7
diff changeset
463 "application/vnd.rn-realmedia",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
464 "rm,ra",
4097
f8a743bd2df8 Split RMContext into RMDemux/MuxContext and make them private in rmdec/enc.c.
rbultje
parents: 3624
diff changeset
465 sizeof(RMMuxContext),
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
466 CODEC_ID_AC3,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467 CODEC_ID_RV10,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468 rm_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469 rm_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470 rm_write_trailer,
6065
441608273a5c Use ff_rm_codec_tags[] in RM muxer. This, incidentally, also allows muxing
rbultje
parents: 5913
diff changeset
471 .codec_tag= (const AVCodecTag* const []){ff_rm_codec_tags, 0},
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472 };