annotate rm.c @ 22:65433f1b2549 libavformat

os2 support patch by ("Slavik Gnatenko" <miracle9 at newmail dot ru>)
author michaelni
date Sat, 11 Jan 2003 20:34:38 +0000
parents b167760cd0aa
children 3eff1f2dcf71
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * "Real" compatible mux and demux.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2000, 2001 Fabrice Bellard.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
19 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 /* in ms */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 #define BUFFER_DURATION 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 typedef struct {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 int nb_packets;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 int packet_total_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 int packet_max_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 /* codec related output */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 int bit_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 float frame_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 int nb_frames; /* current frame number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 int total_frames; /* total number of frames */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 int num;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 AVCodecContext *enc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 } StreamInfo;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 typedef struct {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 StreamInfo streams[2];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 StreamInfo *audio_stream, *video_stream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 int data_pos; /* position of the data after the header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 int nb_packets;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 } RMContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 static void put_str(ByteIOContext *s, const char *tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 put_be16(s,strlen(tag));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 while (*tag) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 put_byte(s, *tag++);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 static void put_str8(ByteIOContext *s, const char *tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 put_byte(s, strlen(tag));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 while (*tag) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 put_byte(s, *tag++);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 static void rv10_write_header(AVFormatContext *ctx,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 int data_size, int index_pos)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 RMContext *rm = ctx->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 ByteIOContext *s = &ctx->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 StreamInfo *stream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 unsigned char *data_offset_ptr, *start_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 const char *desc, *mimetype;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 int nb_packets, packet_total_size, packet_max_size, size, packet_avg_size, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 int bit_rate, v, duration, flags, data_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 start_ptr = s->buf_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 put_tag(s, ".RMF");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 put_be32(s,18); /* header size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 put_be16(s,0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 put_be32(s,0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 put_be32(s,4 + ctx->nb_streams); /* num headers */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 put_tag(s,"PROP");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 put_be32(s, 50);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 put_be16(s, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 packet_max_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 packet_total_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 nb_packets = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 bit_rate = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 duration = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 for(i=0;i<ctx->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 StreamInfo *stream = &rm->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 bit_rate += stream->bit_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 if (stream->packet_max_size > packet_max_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 packet_max_size = stream->packet_max_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 nb_packets += stream->nb_packets;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 packet_total_size += stream->packet_total_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 /* select maximum duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 v = (int) (1000.0 * (float)stream->total_frames / stream->frame_rate);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 if (v > duration)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 duration = v;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 put_be32(s, bit_rate); /* max bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 put_be32(s, bit_rate); /* avg bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 put_be32(s, packet_max_size); /* max packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 if (nb_packets > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 packet_avg_size = packet_total_size / nb_packets;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 packet_avg_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 put_be32(s, packet_avg_size); /* avg packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 put_be32(s, nb_packets); /* num packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 put_be32(s, duration); /* duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 put_be32(s, BUFFER_DURATION); /* preroll */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 put_be32(s, index_pos); /* index offset */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 /* computation of data the data offset */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 data_offset_ptr = s->buf_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 put_be32(s, 0); /* data offset : will be patched after */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 put_be16(s, ctx->nb_streams); /* num streams */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 flags = 1 | 2; /* save allowed & perfect play */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 if (url_is_streamed(s))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 flags |= 4; /* live broadcast */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 put_be16(s, flags);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 /* comments */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 put_tag(s,"CONT");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 size = strlen(ctx->title) + strlen(ctx->author) + strlen(ctx->copyright) +
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 strlen(ctx->comment) + 4 * 2 + 10;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 put_be32(s,size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 put_be16(s,0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 put_str(s, ctx->title);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 put_str(s, ctx->author);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 put_str(s, ctx->copyright);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 put_str(s, ctx->comment);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 for(i=0;i<ctx->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 int codec_data_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 stream = &rm->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 if (stream->enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 desc = "The Audio Stream";
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 mimetype = "audio/x-pn-realaudio";
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 codec_data_size = 73;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 desc = "The Video Stream";
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 mimetype = "video/x-pn-realvideo";
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 codec_data_size = 34;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 put_tag(s,"MDPR");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 size = 10 + 9 * 4 + strlen(desc) + strlen(mimetype) + codec_data_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 put_be32(s, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150 put_be16(s, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152 put_be16(s, i); /* stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 put_be32(s, stream->bit_rate); /* max bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 put_be32(s, stream->bit_rate); /* avg bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155 put_be32(s, stream->packet_max_size); /* max packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 if (stream->nb_packets > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157 packet_avg_size = stream->packet_total_size /
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 stream->nb_packets;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 packet_avg_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 put_be32(s, packet_avg_size); /* avg packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 put_be32(s, 0); /* start time */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 put_be32(s, BUFFER_DURATION); /* preroll */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 /* duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 if (url_is_streamed(s) || !stream->total_frames)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166 put_be32(s, (int)(3600 * 1000));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 put_be32(s, (int)(stream->total_frames * 1000 / stream->frame_rate));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 put_str8(s, desc);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 put_str8(s, mimetype);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 put_be32(s, codec_data_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 if (stream->enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 int coded_frame_size, fscode, sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 sample_rate = stream->enc->sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 coded_frame_size = (stream->enc->bit_rate *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 stream->enc->frame_size) / (8 * sample_rate);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 /* audio codec info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 put_tag(s, ".ra");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180 put_byte(s, 0xfd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181 put_be32(s, 0x00040000); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 put_tag(s, ".ra4");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 put_be32(s, 0x01b53530); /* stream length */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 put_be16(s, 4); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 put_be32(s, 0x39); /* header size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 switch(sample_rate) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 case 48000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 case 24000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 case 12000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 fscode = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 case 44100:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 case 22050:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 case 11025:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 fscode = 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199 case 32000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 case 16000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 case 8000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 fscode = 3;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 put_be16(s, fscode); /* codec additional info, for AC3, seems
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 to be a frequency code */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 /* special hack to compensate rounding errors... */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 if (coded_frame_size == 557)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 coded_frame_size--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 put_be32(s, coded_frame_size); /* frame length */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 put_be32(s, 0x51540); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 put_be32(s, 0x249f0); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 put_be32(s, 0x249f0); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 put_be16(s, 0x01);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 /* frame length : seems to be very important */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 put_be16(s, coded_frame_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 put_be32(s, 0); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 put_be16(s, stream->enc->sample_rate); /* sample rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 put_be32(s, 0x10); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 put_be16(s, stream->enc->channels);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 put_str8(s, "Int0"); /* codec name */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 put_str8(s, "dnet"); /* codec name */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 put_be16(s, 0); /* title length */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 put_be16(s, 0); /* author length */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 put_be16(s, 0); /* copyright length */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 put_byte(s, 0); /* end of header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 /* video codec info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 put_be32(s,34); /* size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 put_tag(s,"VIDORV10");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 put_be16(s, stream->enc->width);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 put_be16(s, stream->enc->height);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 put_be16(s, (int) stream->frame_rate); /* frames per seconds ? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 put_be32(s,0); /* unknown meaning */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 put_be16(s, (int) stream->frame_rate); /* unknown meaning */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 put_be32(s,0); /* unknown meaning */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 put_be16(s, 8); /* unknown meaning */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 /* Seems to be the codec version: only use basic H263. The next
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 versions seems to add a diffential DC coding as in
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 MPEG... nothing new under the sun */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 put_be32(s,0x10000000);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 //put_be32(s,0x10003000);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 /* patch data offset field */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 data_pos = s->buf_ptr - start_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 rm->data_pos = data_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 data_offset_ptr[0] = data_pos >> 24;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 data_offset_ptr[1] = data_pos >> 16;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 data_offset_ptr[2] = data_pos >> 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 data_offset_ptr[3] = data_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 /* data stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 put_tag(s,"DATA");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 put_be32(s,data_size + 10 + 8);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 put_be16(s,0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 put_be32(s, nb_packets); /* number of packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 put_be32(s,0); /* next data header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 static void write_packet_header(AVFormatContext *ctx, StreamInfo *stream,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 int length, int key_frame)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 int timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 ByteIOContext *s = &ctx->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
268 stream->nb_packets++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 stream->packet_total_size += length;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
270 if (length > stream->packet_max_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271 stream->packet_max_size = length;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273 put_be16(s,0); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 put_be16(s,length + 12);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275 put_be16(s, stream->num); /* stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276 timestamp = (1000 * (float)stream->nb_frames) / stream->frame_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 put_be32(s, timestamp); /* timestamp */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 put_byte(s, 0); /* reserved */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279 put_byte(s, key_frame ? 2 : 0); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282 static int rm_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 RMContext *rm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285 StreamInfo *stream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 int n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287 AVCodecContext *codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289 for(n=0;n<s->nb_streams;n++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 s->streams[n]->id = n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291 codec = &s->streams[n]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292 stream = &rm->streams[n];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293 memset(stream, 0, sizeof(StreamInfo));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 stream->num = n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295 stream->bit_rate = codec->bit_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
296 stream->enc = codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
297
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
298 switch(codec->codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
299 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300 rm->audio_stream = stream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301 stream->frame_rate = (float)codec->sample_rate / (float)codec->frame_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
302 /* XXX: dummy values */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303 stream->packet_max_size = 1024;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
304 stream->nb_packets = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
305 stream->total_frames = stream->nb_packets;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
308 rm->video_stream = stream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309 stream->frame_rate = (float)codec->frame_rate / (float)FRAME_RATE_BASE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310 /* XXX: dummy values */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
311 stream->packet_max_size = 4096;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
312 stream->nb_packets = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
313 stream->total_frames = stream->nb_packets;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
314 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316 av_abort();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
317 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
319
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
320 rv10_write_header(s, 0, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
321 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
322 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
323 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
324
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
325 static int rm_write_audio(AVFormatContext *s, UINT8 *buf, int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 UINT8 *buf1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328 RMContext *rm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
329 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330 StreamInfo *stream = rm->audio_stream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333 /* XXX: suppress this malloc */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334 buf1= (UINT8*) av_malloc( size * sizeof(UINT8) );
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335
7
47e502ac6349 AVVideoFrame -> AVFrame
michaelni
parents: 5
diff changeset
336 write_packet_header(s, stream, size, stream->enc->coded_frame->key_frame);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 /* for AC3, the words seems to be reversed */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339 for(i=0;i<size;i+=2) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
340 buf1[i] = buf[i+1];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
341 buf1[i+1] = buf[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343 put_buffer(pb, buf1, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
344 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
345 stream->nb_frames++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
346 av_free(buf1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350 static int rm_write_video(AVFormatContext *s, UINT8 *buf, int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 RMContext *rm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
353 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
354 StreamInfo *stream = rm->video_stream;
7
47e502ac6349 AVVideoFrame -> AVFrame
michaelni
parents: 5
diff changeset
355 int key_frame = stream->enc->coded_frame->key_frame;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357 /* XXX: this is incorrect: should be a parameter */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
358
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359 /* Well, I spent some time finding the meaning of these bits. I am
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360 not sure I understood everything, but it works !! */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361 #if 1
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
362 write_packet_header(s, stream, size + 7, key_frame);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363 /* bit 7: '1' if final packet of a frame converted in several packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364 put_byte(pb, 0x81);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
365 /* bit 7: '1' if I frame. bits 6..0 : sequence number in current
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
366 frame starting from 1 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
367 if (key_frame) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
368 put_byte(pb, 0x81);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
369 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
370 put_byte(pb, 0x01);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
371 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
372 put_be16(pb, 0x4000 | (size)); /* total frame size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
373 put_be16(pb, 0x4000 | (size)); /* offset from the start or the end */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
374 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375 /* full frame */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 write_packet_header(s, size + 6);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
377 put_byte(pb, 0xc0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
378 put_be16(pb, 0x4000 | size); /* total frame size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
379 put_be16(pb, 0x4000 + packet_number * 126); /* position in stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
380 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
381 put_byte(pb, stream->nb_frames & 0xff);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
382
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
383 put_buffer(pb, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
384 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
385
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
386 stream->nb_frames++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
387 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
388 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
389
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
390 static int rm_write_packet(AVFormatContext *s, int stream_index,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
391 UINT8 *buf, int size, int force_pts)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
393 if (s->streams[stream_index]->codec.codec_type ==
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 CODEC_TYPE_AUDIO)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395 return rm_write_audio(s, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
397 return rm_write_video(s, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
398 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
400 static int rm_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
401 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
402 RMContext *rm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403 int data_size, index_pos, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
406 if (!url_is_streamed(&s->pb)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
407 /* end of file: finish to write header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
408 index_pos = url_fseek(pb, 0, SEEK_CUR);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
409 data_size = index_pos - rm->data_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
411 /* index */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412 put_tag(pb, "INDX");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 put_be32(pb, 10 + 10 * s->nb_streams);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 put_be16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 put_be32(pb, 0); /* zero indices */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 put_be16(pb, i); /* stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419 put_be32(pb, 0); /* next index */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
421 /* undocumented end header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
422 put_be32(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 put_be32(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
425 url_fseek(pb, 0, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
426 for(i=0;i<s->nb_streams;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427 rm->streams[i].total_frames = rm->streams[i].nb_frames;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
428 rv10_write_header(s, data_size, index_pos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
430 /* undocumented end header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
431 put_be32(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432 put_be32(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
433 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
434 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 /***************************************************/
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 static void get_str(ByteIOContext *pb, char *buf, int buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 int len, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 char *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445 len = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446 q = buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447 for(i=0;i<len;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 if (i < buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449 *q++ = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
454 static void get_str8(ByteIOContext *pb, char *buf, int buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
456 int len, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
457 char *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
458
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459 len = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
460 q = buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461 for(i=0;i<len;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
462 if (i < buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463 *q++ = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
464 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
465 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
466 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468 static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470 RMContext *rm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
471 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
473 unsigned int tag, v;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
474 int tag_size, size, codec_data_size, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
475 INT64 codec_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
476 unsigned int h263_hack_version;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
477 char buf[128];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
478 int flags = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
479
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
480 if (get_le32(pb) != MKTAG('.', 'R', 'M', 'F'))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
481 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
482
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
483 get_be32(pb); /* header size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
484 get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
485 get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
486 get_be32(pb); /* number of headers */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
487
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
488 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
489 if (url_feof(pb))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
490 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
491 tag = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
492 tag_size = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
493 get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
494 #if 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
495 printf("tag=%c%c%c%c (%08x) size=%d\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
496 (tag) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
497 (tag >> 8) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
498 (tag >> 16) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
499 (tag >> 24) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
500 tag,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
501 tag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
502 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
503 if (tag_size < 10)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
504 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
505 switch(tag) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
506 case MKTAG('P', 'R', 'O', 'P'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
507 /* file header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
508 get_be32(pb); /* max bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
509 get_be32(pb); /* avg bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
510 get_be32(pb); /* max packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
511 get_be32(pb); /* avg packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
512 get_be32(pb); /* nb packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
513 get_be32(pb); /* duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
514 get_be32(pb); /* preroll */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
515 get_be32(pb); /* index offset */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
516 get_be32(pb); /* data offset */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
517 get_be16(pb); /* nb streams */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
518 flags = get_be16(pb); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
519 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
520 case MKTAG('C', 'O', 'N', 'T'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
521 get_str(pb, s->title, sizeof(s->title));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
522 get_str(pb, s->author, sizeof(s->author));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
523 get_str(pb, s->copyright, sizeof(s->copyright));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
524 get_str(pb, s->comment, sizeof(s->comment));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
525 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
526 case MKTAG('M', 'D', 'P', 'R'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
527 st = av_mallocz(sizeof(AVStream));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
528 if (!st)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
529 goto fail;
5
39c4c4336486 cleanup
michaelni
parents: 0
diff changeset
530 avcodec_get_context_defaults(&st->codec);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
531 s->streams[s->nb_streams++] = st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
532 st->id = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
533 get_be32(pb); /* max bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
534 st->codec.bit_rate = get_be32(pb); /* bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
535 get_be32(pb); /* max packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
536 get_be32(pb); /* avg packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
537 get_be32(pb); /* start time */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
538 get_be32(pb); /* preroll */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
539 get_be32(pb); /* duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
540 get_str8(pb, buf, sizeof(buf)); /* desc */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
541 get_str8(pb, buf, sizeof(buf)); /* mimetype */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
542 codec_data_size = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
543 codec_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
544
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
545 v = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
546 if (v == MKTAG(0xfd, 'a', 'r', '.')) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
547 /* ra type header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
548 get_be32(pb); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
549 get_be32(pb); /* .ra4 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
550 get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
551 get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
552 get_be32(pb); /* header size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
553 get_be16(pb); /* add codec info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
554 get_be32(pb); /* coded frame size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
555 get_be32(pb); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
556 get_be32(pb); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
557 get_be32(pb); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
558 get_be16(pb); /* 1 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
559 get_be16(pb); /* coded frame size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
560 get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
561 st->codec.sample_rate = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
562 get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
563 st->codec.channels = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
564 get_str8(pb, buf, sizeof(buf)); /* desc */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
565 get_str8(pb, buf, sizeof(buf)); /* desc */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
566 st->codec.codec_type = CODEC_TYPE_AUDIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
567 if (!strcmp(buf, "dnet")) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
568 st->codec.codec_id = CODEC_ID_AC3;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
569 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
570 st->codec.codec_id = CODEC_ID_NONE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
571 pstrcpy(st->codec.codec_name, sizeof(st->codec.codec_name),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
572 buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
573 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
574 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
575 if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
576 fail1:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
577 fprintf(stderr, "Unsupported video codec\n");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
578 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
579 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
580 st->codec.codec_tag = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
581 if (st->codec.codec_tag != MKTAG('R', 'V', '1', '0'))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
582 goto fail1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
583 st->codec.width = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
584 st->codec.height = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
585 st->codec.frame_rate = get_be16(pb) * FRAME_RATE_BASE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
586 st->codec.codec_type = CODEC_TYPE_VIDEO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
587 get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
588 get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
589 get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
590 get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
591 /* modification of h263 codec version (!) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
592 h263_hack_version = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
593 switch(h263_hack_version) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
594 case 0x10000000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
595 case 0x10003000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
596 case 0x10003001:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
597 st->codec.sub_id = h263_hack_version;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
598 st->codec.codec_id = CODEC_ID_RV10;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
599 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
600 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
601 /* not handled */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
602 st->codec.codec_id = CODEC_ID_NONE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
603 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
604 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
605 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
606 /* skip codec info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
607 size = url_ftell(pb) - codec_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
608 url_fskip(pb, codec_data_size - size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
609 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
610 case MKTAG('D', 'A', 'T', 'A'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
611 goto header_end;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
612 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
613 /* unknown tag: skip it */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
614 url_fskip(pb, tag_size - 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
615 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
616 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
617 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
618 header_end:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
619 rm->nb_packets = get_be32(pb); /* number of packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
620 if (!rm->nb_packets && (flags & 4))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
621 rm->nb_packets = 3600 * 25;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
622 get_be32(pb); /* next data header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
623 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
624
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
625 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
626 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
627 av_free(s->streams[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
628 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
629 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
630 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
631
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
632 static int get_num(ByteIOContext *pb, int *len)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
633 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
634 int n, n1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
635
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
636 n = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
637 (*len)-=2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
638 if (n >= 0x4000) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
639 return n - 0x4000;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
640 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
641 n1 = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
642 (*len)-=2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
643 return (n << 16) | n1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
644 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
645 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
646
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
647 static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
648 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
649 RMContext *rm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
650 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
651 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
652 int len, num, timestamp, i, tmp, j;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
653 UINT8 *ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
654 int flags;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
655
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
656 redo:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
657 if (rm->nb_packets == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
658 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
659 get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
660 len = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
661 if (len < 12)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
662 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
663 num = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
664 timestamp = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
665 get_byte(pb); /* reserved */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
666 flags = get_byte(pb); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
667 rm->nb_packets--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
668 len -= 12;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
669
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
670 st = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
671 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
672 st = s->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
673 if (num == st->id)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
674 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
675 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
676 if (i == s->nb_streams) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
677 /* skip packet if unknown number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
678 url_fskip(pb, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
679 goto redo;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
680 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
681
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
682 if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
683 int full_frame, h, pic_num;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
684
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
685 h= get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
686 if ((h & 0xc0) == 0xc0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
687 int len2, pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
688 full_frame = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
689 len2= get_num(pb, &len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
690 pos = get_num(pb, &len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
691 //printf("pos:%d\n",len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
692 len -= 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
693 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
694 int seq, frame_size, pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
695 full_frame = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
696 seq = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
697 frame_size = get_num(pb, &len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
698 pos = get_num(pb, &len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
699 //printf("seq:%d, size:%d, pos:%d\n",seq,frame_size,pos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
700 len -= 3;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
701 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
702 /* picture number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
703 pic_num= get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
704
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
705 //XXX/FIXME/HACK, demuxer should be fixed to send complete frames ...
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
706 if(st->codec.slice_offset==NULL) st->codec.slice_offset= (int*)malloc(sizeof(int));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
707 st->codec.slice_count= full_frame;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
708 st->codec.slice_offset[0]= 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
709 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
710
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
711 av_new_packet(pkt, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
712 pkt->stream_index = i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
713 get_buffer(pb, pkt->data, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
714
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
715 /* for AC3, needs to swap bytes */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
716 if (st->codec.codec_id == CODEC_ID_AC3) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
717 ptr = pkt->data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
718 for(j=0;j<len;j+=2) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
719 tmp = ptr[0];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
720 ptr[0] = ptr[1];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
721 ptr[1] = tmp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
722 ptr += 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
723 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
724 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
725 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
726 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
727
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
728 static int rm_read_close(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
729 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
730 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
731 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
732
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
733 static int rm_probe(AVProbeData *p)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
734 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
735 /* check file header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
736 if (p->buf_size <= 32)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
737 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
738 if (p->buf[0] == '.' && p->buf[1] == 'R' &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
739 p->buf[2] == 'M' && p->buf[3] == 'F' &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
740 p->buf[4] == 0 && p->buf[5] == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
741 return AVPROBE_SCORE_MAX;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
742 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
743 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
744 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
745
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
746 static AVInputFormat rm_iformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
747 "rm",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
748 "rm format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
749 sizeof(RMContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
750 rm_probe,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
751 rm_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
752 rm_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
753 rm_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
754 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
755
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
756 static AVOutputFormat rm_oformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
757 "rm",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
758 "rm 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
759 "application/vnd.rn-realmedia",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
760 "rm,ra",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
761 sizeof(RMContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
762 CODEC_ID_AC3,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
763 CODEC_ID_RV10,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
764 rm_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
765 rm_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
766 rm_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
767 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
768
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
769 int rm_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
770 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
771 av_register_input_format(&rm_iformat);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
772 av_register_output_format(&rm_oformat);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
773 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
774 }