annotate rm.c @ 648:340f1911cd54 libavformat

add luma only support to yuv4mpeg patch by (Roine Gustafsson <roine users.sourceforge net>)
author michael
date Wed, 19 Jan 2005 12:27:48 +0000
parents 5188094c6ec4
children b47948262721
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;
194
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
42 int old_format;
609
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
43 int current_stream;
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
44 int remaining_len;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 } RMContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
47 #ifdef CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 static void put_str(ByteIOContext *s, const char *tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 put_be16(s,strlen(tag));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 while (*tag) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 put_byte(s, *tag++);
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 static void put_str8(ByteIOContext *s, const char *tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 put_byte(s, strlen(tag));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 while (*tag) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 put_byte(s, *tag++);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 static void rv10_write_header(AVFormatContext *ctx,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 int data_size, int index_pos)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 RMContext *rm = ctx->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 ByteIOContext *s = &ctx->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 StreamInfo *stream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 unsigned char *data_offset_ptr, *start_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 const char *desc, *mimetype;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 int nb_packets, packet_total_size, packet_max_size, size, packet_avg_size, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 int bit_rate, v, duration, flags, data_pos;
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);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123
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");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 size = strlen(ctx->title) + strlen(ctx->author) + strlen(ctx->copyright) +
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 strlen(ctx->comment) + 4 * 2 + 10;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 put_be32(s,size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 put_be16(s,0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 put_str(s, ctx->title);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 put_str(s, ctx->author);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 put_str(s, ctx->copyright);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 put_str(s, ctx->comment);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 for(i=0;i<ctx->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 int codec_data_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 stream = &rm->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 if (stream->enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 desc = "The Audio Stream";
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 mimetype = "audio/x-pn-realaudio";
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 codec_data_size = 73;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 desc = "The Video Stream";
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 mimetype = "video/x-pn-realvideo";
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 codec_data_size = 34;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151 put_tag(s,"MDPR");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152 size = 10 + 9 * 4 + strlen(desc) + strlen(mimetype) + codec_data_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 put_be32(s, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 put_be16(s, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 put_be16(s, i); /* stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157 put_be32(s, stream->bit_rate); /* max bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 put_be32(s, stream->bit_rate); /* avg bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 put_be32(s, stream->packet_max_size); /* max packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 if (stream->nb_packets > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 packet_avg_size = stream->packet_total_size /
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 stream->nb_packets;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 packet_avg_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 put_be32(s, packet_avg_size); /* avg packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166 put_be32(s, 0); /* start time */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 put_be32(s, BUFFER_DURATION); /* preroll */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 /* duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 if (url_is_streamed(s) || !stream->total_frames)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 put_be32(s, (int)(3600 * 1000));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 put_be32(s, (int)(stream->total_frames * 1000 / stream->frame_rate));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 put_str8(s, desc);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 put_str8(s, mimetype);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 put_be32(s, codec_data_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 if (stream->enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 int coded_frame_size, fscode, sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 sample_rate = stream->enc->sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180 coded_frame_size = (stream->enc->bit_rate *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181 stream->enc->frame_size) / (8 * sample_rate);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 /* audio codec info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 put_tag(s, ".ra");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 put_byte(s, 0xfd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 put_be32(s, 0x00040000); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 put_tag(s, ".ra4");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 put_be32(s, 0x01b53530); /* stream length */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 put_be16(s, 4); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 put_be32(s, 0x39); /* header size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 switch(sample_rate) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 case 48000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 case 24000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 case 12000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 fscode = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 case 44100:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199 case 22050:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 case 11025:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 fscode = 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 case 32000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 case 16000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 case 8000:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 fscode = 3;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 put_be16(s, fscode); /* codec additional info, for AC3, seems
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 to be a frequency code */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 /* special hack to compensate rounding errors... */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 if (coded_frame_size == 557)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 coded_frame_size--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 put_be32(s, coded_frame_size); /* frame length */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 put_be32(s, 0x51540); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 put_be32(s, 0x249f0); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 put_be32(s, 0x249f0); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 put_be16(s, 0x01);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 /* frame length : seems to be very important */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 put_be16(s, coded_frame_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 put_be32(s, 0); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 put_be16(s, stream->enc->sample_rate); /* sample rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 put_be32(s, 0x10); /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 put_be16(s, stream->enc->channels);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 put_str8(s, "Int0"); /* codec name */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 put_str8(s, "dnet"); /* codec name */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 put_be16(s, 0); /* title length */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 put_be16(s, 0); /* author length */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 put_be16(s, 0); /* copyright length */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 put_byte(s, 0); /* end of header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 /* video codec info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 put_be32(s,34); /* size */
614
cbcb3ae970c8 rv20 encoding
michael
parents: 613
diff changeset
233 if(stream->enc->codec_id == CODEC_ID_RV10)
cbcb3ae970c8 rv20 encoding
michael
parents: 613
diff changeset
234 put_tag(s,"VIDORV10");
cbcb3ae970c8 rv20 encoding
michael
parents: 613
diff changeset
235 else
cbcb3ae970c8 rv20 encoding
michael
parents: 613
diff changeset
236 put_tag(s,"VIDORV20");
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 put_be16(s, stream->enc->width);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 put_be16(s, stream->enc->height);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 put_be16(s, (int) stream->frame_rate); /* frames per seconds ? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 put_be32(s,0); /* unknown meaning */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 put_be16(s, (int) stream->frame_rate); /* unknown meaning */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 put_be32(s,0); /* unknown meaning */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 put_be16(s, 8); /* unknown meaning */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 /* Seems to be the codec version: only use basic H263. The next
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 versions seems to add a diffential DC coding as in
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 MPEG... nothing new under the sun */
614
cbcb3ae970c8 rv20 encoding
michael
parents: 613
diff changeset
247 if(stream->enc->codec_id == CODEC_ID_RV10)
cbcb3ae970c8 rv20 encoding
michael
parents: 613
diff changeset
248 put_be32(s,0x10000000);
cbcb3ae970c8 rv20 encoding
michael
parents: 613
diff changeset
249 else
cbcb3ae970c8 rv20 encoding
michael
parents: 613
diff changeset
250 put_be32(s,0x20103001);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 //put_be32(s,0x10003000);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 /* patch data offset field */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 data_pos = s->buf_ptr - start_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257 rm->data_pos = data_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 data_offset_ptr[0] = data_pos >> 24;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 data_offset_ptr[1] = data_pos >> 16;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 data_offset_ptr[2] = data_pos >> 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 data_offset_ptr[3] = data_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 /* data stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 put_tag(s,"DATA");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 put_be32(s,data_size + 10 + 8);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 put_be16(s,0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
268 put_be32(s, nb_packets); /* number of packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 put_be32(s,0); /* next data header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
270 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272 static void write_packet_header(AVFormatContext *ctx, StreamInfo *stream,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273 int length, int key_frame)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275 int timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276 ByteIOContext *s = &ctx->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 stream->nb_packets++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279 stream->packet_total_size += length;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 if (length > stream->packet_max_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281 stream->packet_max_size = length;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283 put_be16(s,0); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 put_be16(s,length + 12);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285 put_be16(s, stream->num); /* stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 timestamp = (1000 * (float)stream->nb_frames) / stream->frame_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287 put_be32(s, timestamp); /* timestamp */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288 put_byte(s, 0); /* reserved */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289 put_byte(s, key_frame ? 2 : 0); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292 static int rm_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 RMContext *rm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295 StreamInfo *stream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
296 int n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
297 AVCodecContext *codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
298
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
299 for(n=0;n<s->nb_streams;n++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300 s->streams[n]->id = n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301 codec = &s->streams[n]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
302 stream = &rm->streams[n];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303 memset(stream, 0, sizeof(StreamInfo));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
304 stream->num = n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
305 stream->bit_rate = codec->bit_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306 stream->enc = codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
308 switch(codec->codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310 rm->audio_stream = stream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
311 stream->frame_rate = (float)codec->sample_rate / (float)codec->frame_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
312 /* XXX: dummy values */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
313 stream->packet_max_size = 1024;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
314 stream->nb_packets = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315 stream->total_frames = stream->nb_packets;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
317 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318 rm->video_stream = stream;
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
319 stream->frame_rate = (float)codec->frame_rate / (float)codec->frame_rate_base;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
320 /* XXX: dummy values */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
321 stream->packet_max_size = 4096;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
322 stream->nb_packets = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
323 stream->total_frames = stream->nb_packets;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
324 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
325 default:
537
558a093b04db do not call (av_)abort()
michael
parents: 509
diff changeset
326 return -1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
329
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330 rv10_write_header(s, 0, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
335 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
336 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 33
diff changeset
337 uint8_t *buf1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 RMContext *rm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
340 StreamInfo *stream = rm->audio_stream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
341 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343 /* XXX: suppress this malloc */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 33
diff changeset
344 buf1= (uint8_t*) av_malloc( size * sizeof(uint8_t) );
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
345
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
346 write_packet_header(s, stream, size, !!(flags & PKT_FLAG_KEY));
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348 /* for AC3, the words seems to be reversed */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349 for(i=0;i<size;i+=2) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350 buf1[i] = buf[i+1];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351 buf1[i+1] = buf[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
353 put_buffer(pb, buf1, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
354 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
355 stream->nb_frames++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356 av_free(buf1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
358 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
360 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
361 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
362 RMContext *rm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364 StreamInfo *stream = rm->video_stream;
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
365 int key_frame = !!(flags & PKT_FLAG_KEY);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
366
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
367 /* XXX: this is incorrect: should be a parameter */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
368
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
369 /* Well, I spent some time finding the meaning of these bits. I am
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
370 not sure I understood everything, but it works !! */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
371 #if 1
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
372 write_packet_header(s, stream, size + 7, key_frame);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
373 /* bit 7: '1' if final packet of a frame converted in several packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
374 put_byte(pb, 0x81);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375 /* bit 7: '1' if I frame. bits 6..0 : sequence number in current
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 frame starting from 1 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
377 if (key_frame) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
378 put_byte(pb, 0x81);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
379 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
380 put_byte(pb, 0x01);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
381 }
611
8fcecf36e64c rm encoding fix
michael
parents: 610
diff changeset
382 put_be16(pb, 0x4000 + (size)); /* total frame size */
8fcecf36e64c rm encoding fix
michael
parents: 610
diff changeset
383 put_be16(pb, 0x4000 + (size)); /* offset from the start or the end */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
384 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
385 /* full frame */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
386 write_packet_header(s, size + 6);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
387 put_byte(pb, 0xc0);
611
8fcecf36e64c rm encoding fix
michael
parents: 610
diff changeset
388 put_be16(pb, 0x4000 + size); /* total frame size */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
389 put_be16(pb, 0x4000 + packet_number * 126); /* position in stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
390 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
391 put_byte(pb, stream->nb_frames & 0xff);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
393 put_buffer(pb, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396 stream->nb_frames++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
397 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
398 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 370
diff changeset
400 static int rm_write_packet(AVFormatContext *s, AVPacket *pkt)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
401 {
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 370
diff changeset
402 if (s->streams[pkt->stream_index]->codec.codec_type ==
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403 CODEC_TYPE_AUDIO)
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
404 return rm_write_audio(s, pkt->data, pkt->size, pkt->flags);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405 else
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
406 return rm_write_video(s, pkt->data, pkt->size, pkt->flags);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
407 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
408
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
409 static int rm_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
411 RMContext *rm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412 int data_size, index_pos, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415 if (!url_is_streamed(&s->pb)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 /* end of file: finish to write header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 index_pos = url_fseek(pb, 0, SEEK_CUR);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 data_size = index_pos - rm->data_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420 /* index */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
421 put_tag(pb, "INDX");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
422 put_be32(pb, 10 + 10 * s->nb_streams);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 put_be16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
425 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
426 put_be32(pb, 0); /* zero indices */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427 put_be16(pb, i); /* stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
428 put_be32(pb, 0); /* next index */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429 }
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 url_fseek(pb, 0, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435 for(i=0;i<s->nb_streams;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 rm->streams[i].total_frames = rm->streams[i].nb_frames;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 rv10_write_header(s, data_size, index_pos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439 /* undocumented end header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 put_be32(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441 put_be32(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445 }
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
446 #endif //CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 /***************************************************/
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450 static void get_str(ByteIOContext *pb, char *buf, int buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452 int len, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453 char *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
454
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455 len = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
456 q = buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
457 for(i=0;i<len;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
458 if (i < buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459 *q++ = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
460 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
462 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
464 static void get_str8(ByteIOContext *pb, char *buf, int buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
465 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
466 int len, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467 char *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469 len = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470 q = buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
471 for(i=0;i<len;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472 if (i < buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
473 *q++ = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
474 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
475 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
476 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
477
194
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
478 static void rm_read_audio_stream_info(AVFormatContext *s, AVStream *st,
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
479 int read_all)
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
480 {
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
481 ByteIOContext *pb = &s->pb;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
482 char buf[128];
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
483 uint32_t version;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
484 int i;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
485
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
486 /* ra type header */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
487 version = get_be32(pb); /* version */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
488 if (((version >> 16) & 0xff) == 3) {
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
489 /* very old version */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
490 for(i = 0; i < 14; i++)
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
491 get_byte(pb);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
492 get_str8(pb, s->title, sizeof(s->title));
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
493 get_str8(pb, s->author, sizeof(s->author));
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
494 get_str8(pb, s->copyright, sizeof(s->copyright));
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
495 get_str8(pb, s->comment, sizeof(s->comment));
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
496 get_byte(pb);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
497 get_str8(pb, buf, sizeof(buf));
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
498 st->codec.sample_rate = 8000;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
499 st->codec.channels = 1;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
500 st->codec.codec_type = CODEC_TYPE_AUDIO;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
501 st->codec.codec_id = CODEC_ID_RA_144;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
502 } else {
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
503 /* old version (4) */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
504 get_be32(pb); /* .ra4 */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
505 get_be32(pb);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
506 get_be16(pb);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
507 get_be32(pb); /* header size */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
508 get_be16(pb); /* add codec info */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
509 get_be32(pb); /* coded frame size */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
510 get_be32(pb); /* ??? */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
511 get_be32(pb); /* ??? */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
512 get_be32(pb); /* ??? */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
513 get_be16(pb); /* 1 */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
514 get_be16(pb); /* coded frame size */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
515 get_be32(pb);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
516 st->codec.sample_rate = get_be16(pb);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
517 get_be32(pb);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
518 st->codec.channels = get_be16(pb);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
519 get_str8(pb, buf, sizeof(buf)); /* desc */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
520 get_str8(pb, buf, sizeof(buf)); /* desc */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
521 st->codec.codec_type = CODEC_TYPE_AUDIO;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
522 if (!strcmp(buf, "dnet")) {
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
523 st->codec.codec_id = CODEC_ID_AC3;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
524 } else {
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
525 st->codec.codec_id = CODEC_ID_NONE;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
526 pstrcpy(st->codec.codec_name, sizeof(st->codec.codec_name),
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
527 buf);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
528 }
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
529 if (read_all) {
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
530 get_byte(pb);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
531 get_byte(pb);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
532 get_byte(pb);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
533
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
534 get_str8(pb, s->title, sizeof(s->title));
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
535 get_str8(pb, s->author, sizeof(s->author));
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
536 get_str8(pb, s->copyright, sizeof(s->copyright));
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
537 get_str8(pb, s->comment, sizeof(s->comment));
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
538 }
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
539 }
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
540 }
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
541
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
542 static int rm_read_header_old(AVFormatContext *s, AVFormatParameters *ap)
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
543 {
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
544 RMContext *rm = s->priv_data;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
545 AVStream *st;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
546
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
547 rm->old_format = 1;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
548 st = av_new_stream(s, 0);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
549 if (!st)
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
550 goto fail;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
551 rm_read_audio_stream_info(s, st, 1);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
552 return 0;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
553 fail:
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
554 return -1;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
555 }
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
556
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
557 static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
558 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
559 RMContext *rm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
560 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
561 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
562 unsigned int tag, v;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
563 int tag_size, size, codec_data_size, i;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 33
diff changeset
564 int64_t codec_pos;
188
6c9d6422a2f6 update duration and start_time - add av_new_stream() usage
bellard
parents: 85
diff changeset
565 unsigned int h263_hack_version, start_time, duration;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
566 char buf[128];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
567 int flags = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
568
194
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
569 tag = get_le32(pb);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
570 if (tag == MKTAG('.', 'r', 'a', 0xfd)) {
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
571 /* very old .ra format */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
572 return rm_read_header_old(s, ap);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
573 } else if (tag != MKTAG('.', 'R', 'M', 'F')) {
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 470
diff changeset
574 return AVERROR_IO;
194
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
575 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
576
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
577 get_be32(pb); /* header size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
578 get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
579 get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
580 get_be32(pb); /* number of headers */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
581
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
582 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
583 if (url_feof(pb))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
584 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
585 tag = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
586 tag_size = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
587 get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
588 #if 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
589 printf("tag=%c%c%c%c (%08x) size=%d\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
590 (tag) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
591 (tag >> 8) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
592 (tag >> 16) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
593 (tag >> 24) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
594 tag,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
595 tag_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
596 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
597 if (tag_size < 10)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
598 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
599 switch(tag) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
600 case MKTAG('P', 'R', 'O', 'P'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
601 /* file header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
602 get_be32(pb); /* max bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
603 get_be32(pb); /* avg bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
604 get_be32(pb); /* max packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
605 get_be32(pb); /* avg packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
606 get_be32(pb); /* nb packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
607 get_be32(pb); /* duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
608 get_be32(pb); /* preroll */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
609 get_be32(pb); /* index offset */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
610 get_be32(pb); /* data offset */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
611 get_be16(pb); /* nb streams */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
612 flags = get_be16(pb); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
613 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
614 case MKTAG('C', 'O', 'N', 'T'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
615 get_str(pb, s->title, sizeof(s->title));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
616 get_str(pb, s->author, sizeof(s->author));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
617 get_str(pb, s->copyright, sizeof(s->copyright));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
618 get_str(pb, s->comment, sizeof(s->comment));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
619 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
620 case MKTAG('M', 'D', 'P', 'R'):
188
6c9d6422a2f6 update duration and start_time - add av_new_stream() usage
bellard
parents: 85
diff changeset
621 st = av_new_stream(s, 0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
622 if (!st)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
623 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
624 st->id = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
625 get_be32(pb); /* max bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
626 st->codec.bit_rate = get_be32(pb); /* bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
627 get_be32(pb); /* max packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
628 get_be32(pb); /* avg packet size */
188
6c9d6422a2f6 update duration and start_time - add av_new_stream() usage
bellard
parents: 85
diff changeset
629 start_time = get_be32(pb); /* start time */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
630 get_be32(pb); /* preroll */
188
6c9d6422a2f6 update duration and start_time - add av_new_stream() usage
bellard
parents: 85
diff changeset
631 duration = get_be32(pb); /* duration */
6c9d6422a2f6 update duration and start_time - add av_new_stream() usage
bellard
parents: 85
diff changeset
632 st->start_time = start_time * (AV_TIME_BASE / 1000);
6c9d6422a2f6 update duration and start_time - add av_new_stream() usage
bellard
parents: 85
diff changeset
633 st->duration = duration * (AV_TIME_BASE / 1000);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
634 get_str8(pb, buf, sizeof(buf)); /* desc */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
635 get_str8(pb, buf, sizeof(buf)); /* mimetype */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
636 codec_data_size = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
637 codec_pos = url_ftell(pb);
593
a1f354e84965 skip unknown streams instead of failing
michael
parents: 592
diff changeset
638 st->codec.codec_type = CODEC_TYPE_DATA;
607
fce9fc3a0f17 timestamp fix
michael
parents: 604
diff changeset
639 av_set_pts_info(st, 64, 1, 1000);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
640
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
641 v = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
642 if (v == MKTAG(0xfd, 'a', 'r', '.')) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
643 /* ra type header */
194
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
644 rm_read_audio_stream_info(s, st, 0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
645 } else {
604
ed2709c1f49c next try at fixing rv20 decoding
michael
parents: 593
diff changeset
646 int fps, fps2;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
647 if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
648 fail1:
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 277
diff changeset
649 av_log(&st->codec, AV_LOG_ERROR, "Unsupported video codec\n");
593
a1f354e84965 skip unknown streams instead of failing
michael
parents: 592
diff changeset
650 goto skip;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
651 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
652 st->codec.codec_tag = get_le32(pb);
593
a1f354e84965 skip unknown streams instead of failing
michael
parents: 592
diff changeset
653 // av_log(NULL, AV_LOG_DEBUG, "%X %X\n", st->codec.codec_tag, MKTAG('R', 'V', '2', '0'));
509
45abb3409125 dont be so picky
michael
parents: 482
diff changeset
654 if ( st->codec.codec_tag != MKTAG('R', 'V', '1', '0')
638
5188094c6ec4 RV30/RV40 demuxing (untested)
michael
parents: 632
diff changeset
655 && st->codec.codec_tag != MKTAG('R', 'V', '2', '0')
5188094c6ec4 RV30/RV40 demuxing (untested)
michael
parents: 632
diff changeset
656 && st->codec.codec_tag != MKTAG('R', 'V', '3', '0')
5188094c6ec4 RV30/RV40 demuxing (untested)
michael
parents: 632
diff changeset
657 && st->codec.codec_tag != MKTAG('R', 'V', '4', '0'))
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
658 goto fail1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
659 st->codec.width = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
660 st->codec.height = get_be16(pb);
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
661 st->codec.frame_rate_base= 1;
604
ed2709c1f49c next try at fixing rv20 decoding
michael
parents: 593
diff changeset
662 fps= get_be16(pb);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
663 st->codec.codec_type = CODEC_TYPE_VIDEO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
664 get_be32(pb);
604
ed2709c1f49c next try at fixing rv20 decoding
michael
parents: 593
diff changeset
665 fps2= get_be16(pb);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
666 get_be16(pb);
604
ed2709c1f49c next try at fixing rv20 decoding
michael
parents: 593
diff changeset
667
ed2709c1f49c next try at fixing rv20 decoding
michael
parents: 593
diff changeset
668 st->codec.extradata_size= codec_data_size - (url_ftell(pb) - codec_pos);
ed2709c1f49c next try at fixing rv20 decoding
michael
parents: 593
diff changeset
669 st->codec.extradata= av_malloc(st->codec.extradata_size);
ed2709c1f49c next try at fixing rv20 decoding
michael
parents: 593
diff changeset
670 get_buffer(pb, st->codec.extradata, st->codec.extradata_size);
ed2709c1f49c next try at fixing rv20 decoding
michael
parents: 593
diff changeset
671
ed2709c1f49c next try at fixing rv20 decoding
michael
parents: 593
diff changeset
672 // av_log(NULL, AV_LOG_DEBUG, "fps= %d fps2= %d\n", fps, fps2);
ed2709c1f49c next try at fixing rv20 decoding
michael
parents: 593
diff changeset
673 st->codec.frame_rate = fps * st->codec.frame_rate_base;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
674 /* modification of h263 codec version (!) */
604
ed2709c1f49c next try at fixing rv20 decoding
michael
parents: 593
diff changeset
675 #ifdef WORDS_BIGENDIAN
ed2709c1f49c next try at fixing rv20 decoding
michael
parents: 593
diff changeset
676 h263_hack_version = ((uint32_t*)st->codec.extradata)[1];
ed2709c1f49c next try at fixing rv20 decoding
michael
parents: 593
diff changeset
677 #else
ed2709c1f49c next try at fixing rv20 decoding
michael
parents: 593
diff changeset
678 h263_hack_version = bswap_32(((uint32_t*)st->codec.extradata)[1]);
ed2709c1f49c next try at fixing rv20 decoding
michael
parents: 593
diff changeset
679 #endif
592
f28e99a6ac99 rv20 demuxing fix
michael
parents: 537
diff changeset
680 st->codec.sub_id = h263_hack_version;
638
5188094c6ec4 RV30/RV40 demuxing (untested)
michael
parents: 632
diff changeset
681 switch((h263_hack_version>>28)){
5188094c6ec4 RV30/RV40 demuxing (untested)
michael
parents: 632
diff changeset
682 case 1: st->codec.codec_id = CODEC_ID_RV10; break;
5188094c6ec4 RV30/RV40 demuxing (untested)
michael
parents: 632
diff changeset
683 case 2: st->codec.codec_id = CODEC_ID_RV20; break;
5188094c6ec4 RV30/RV40 demuxing (untested)
michael
parents: 632
diff changeset
684 case 3: st->codec.codec_id = CODEC_ID_RV30; break;
5188094c6ec4 RV30/RV40 demuxing (untested)
michael
parents: 632
diff changeset
685 case 4: st->codec.codec_id = CODEC_ID_RV40; break;
5188094c6ec4 RV30/RV40 demuxing (untested)
michael
parents: 632
diff changeset
686 default: goto fail1;
5188094c6ec4 RV30/RV40 demuxing (untested)
michael
parents: 632
diff changeset
687 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
688 }
593
a1f354e84965 skip unknown streams instead of failing
michael
parents: 592
diff changeset
689 skip:
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
690 /* skip codec info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
691 size = url_ftell(pb) - codec_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
692 url_fskip(pb, codec_data_size - size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
693 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
694 case MKTAG('D', 'A', 'T', 'A'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
695 goto header_end;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
696 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
697 /* unknown tag: skip it */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
698 url_fskip(pb, tag_size - 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
699 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
700 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
701 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
702 header_end:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
703 rm->nb_packets = get_be32(pb); /* number of packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
704 if (!rm->nb_packets && (flags & 4))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
705 rm->nb_packets = 3600 * 25;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
706 get_be32(pb); /* next data header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
707 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
708
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
709 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
710 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
711 av_free(s->streams[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
712 }
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 470
diff changeset
713 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
714 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
715
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
716 static int get_num(ByteIOContext *pb, int *len)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
717 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
718 int n, n1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
719
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
720 n = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
721 (*len)-=2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
722 if (n >= 0x4000) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
723 return n - 0x4000;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
724 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
725 n1 = get_be16(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
726 (*len)-=2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
727 return (n << 16) | n1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
728 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
729 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
730
194
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
731 /* multiple of 20 bytes for ra144 (ugly) */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
732 #define RAW_PACKET_SIZE 1000
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
733
613
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
734 static int sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_index, int64_t *pos){
612
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
735 RMContext *rm = s->priv_data;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
736 ByteIOContext *pb = &s->pb;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
737 int len, num, res, i;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
738 AVStream *st;
632
9f8fa2f4edfd skip INDX chunks
michael
parents: 614
diff changeset
739 uint32_t state=0xFFFFFFFF;
612
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
740
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
741 while(!url_feof(pb)){
613
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
742 *pos= url_ftell(pb);
612
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
743 if(rm->remaining_len > 0){
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
744 num= rm->current_stream;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
745 len= rm->remaining_len;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
746 *timestamp = AV_NOPTS_VALUE;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
747 *flags= 0;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
748 }else{
632
9f8fa2f4edfd skip INDX chunks
michael
parents: 614
diff changeset
749 state= (state<<8) + get_byte(pb);
9f8fa2f4edfd skip INDX chunks
michael
parents: 614
diff changeset
750
9f8fa2f4edfd skip INDX chunks
michael
parents: 614
diff changeset
751 if(state == MKBETAG('I', 'N', 'D', 'X')){
9f8fa2f4edfd skip INDX chunks
michael
parents: 614
diff changeset
752 len = get_be16(pb) - 6;
9f8fa2f4edfd skip INDX chunks
michael
parents: 614
diff changeset
753 if(len<0)
9f8fa2f4edfd skip INDX chunks
michael
parents: 614
diff changeset
754 continue;
9f8fa2f4edfd skip INDX chunks
michael
parents: 614
diff changeset
755 goto skip;
9f8fa2f4edfd skip INDX chunks
michael
parents: 614
diff changeset
756 }
9f8fa2f4edfd skip INDX chunks
michael
parents: 614
diff changeset
757
9f8fa2f4edfd skip INDX chunks
michael
parents: 614
diff changeset
758 if(state > (unsigned)0xFFFF || state < 12)
612
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
759 continue;
632
9f8fa2f4edfd skip INDX chunks
michael
parents: 614
diff changeset
760 len=state;
9f8fa2f4edfd skip INDX chunks
michael
parents: 614
diff changeset
761 state= 0xFFFFFFFF;
9f8fa2f4edfd skip INDX chunks
michael
parents: 614
diff changeset
762
612
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
763 num = get_be16(pb);
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
764 *timestamp = get_be32(pb);
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
765 res= get_byte(pb); /* reserved */
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
766 *flags = get_byte(pb); /* flags */
613
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
767
612
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
768
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
769 len -= 12;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
770 }
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
771 for(i=0;i<s->nb_streams;i++) {
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
772 st = s->streams[i];
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
773 if (num == st->id)
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
774 break;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
775 }
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
776 if (i == s->nb_streams) {
632
9f8fa2f4edfd skip INDX chunks
michael
parents: 614
diff changeset
777 skip:
612
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
778 /* skip packet if unknown number */
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
779 url_fskip(pb, len);
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
780 rm->remaining_len -= len;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
781 continue;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
782 }
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
783 *stream_index= i;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
784
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
785 return len;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
786 }
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
787 return -1;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
788 }
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
789
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
790 static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
791 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
792 RMContext *rm = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
793 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
794 AVStream *st;
612
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
795 int i, len, tmp, j;
613
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
796 int64_t timestamp, pos;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 33
diff changeset
797 uint8_t *ptr;
612
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
798 int flags;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
799
194
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
800 if (rm->old_format) {
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
801 /* just read raw bytes */
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
802 len = RAW_PACKET_SIZE;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
803 av_new_packet(pkt, len);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
804 pkt->stream_index = 0;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
805 len = get_buffer(pb, pkt->data, len);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
806 if (len <= 0) {
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
807 av_free_packet(pkt);
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 470
diff changeset
808 return AVERROR_IO;
194
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
809 }
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
810 pkt->size = len;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
811 st = s->streams[0];
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
812 } else {
613
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
813 int seq=1;
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
814
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
815 len=sync(s, &timestamp, &flags, &i, &pos);
612
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
816 if(len<0)
610
1ab7b989f475 try to recover from errors instead of failing fataly
michael
parents: 609
diff changeset
817 return AVERROR_IO;
612
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
818 st = s->streams[i];
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
819
194
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
820 if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
609
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
821 int h, pic_num, len2, pos;
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
822
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
823 h= get_byte(pb); len--;
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
824 if(!(h & 0x40)){
613
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
825 seq = get_byte(pb); len--;
609
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
826 }
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
827
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
828 if((h & 0xc0) == 0x40){
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
829 len2= pos= 0;
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
830 }else{
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
831 len2 = get_num(pb, &len);
194
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
832 pos = get_num(pb, &len);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
833 }
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
834 /* picture number */
609
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
835 pic_num= get_byte(pb); len--;
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
836 rm->remaining_len= len;
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
837 rm->current_stream= st->id;
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
838
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
839 // av_log(NULL, AV_LOG_DEBUG, "%X len:%d pos:%d len2:%d pic_num:%d\n",h, len, pos, len2, pic_num);
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
840 if(len2 && len2<len)
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
841 len=len2;
2f0de265bc5e various demuxer fixes
michael
parents: 608
diff changeset
842 rm->remaining_len-= len;
194
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
843 }
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
844
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
845 av_new_packet(pkt, len);
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
846 pkt->stream_index = i;
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
847 get_buffer(pb, pkt->data, len);
607
fce9fc3a0f17 timestamp fix
michael
parents: 604
diff changeset
848
fce9fc3a0f17 timestamp fix
michael
parents: 604
diff changeset
849 #if 0
fce9fc3a0f17 timestamp fix
michael
parents: 604
diff changeset
850 if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
fce9fc3a0f17 timestamp fix
michael
parents: 604
diff changeset
851 if(st->codec.codec_id == CODEC_ID_RV20){
fce9fc3a0f17 timestamp fix
michael
parents: 604
diff changeset
852 int seq= 128*(pkt->data[2]&0x7F) + (pkt->data[3]>>1);
fce9fc3a0f17 timestamp fix
michael
parents: 604
diff changeset
853 av_log(NULL, AV_LOG_DEBUG, "%d %Ld %d\n", timestamp, timestamp*512LL/25, seq);
fce9fc3a0f17 timestamp fix
michael
parents: 604
diff changeset
854
fce9fc3a0f17 timestamp fix
michael
parents: 604
diff changeset
855 seq |= (timestamp&~0x3FFF);
fce9fc3a0f17 timestamp fix
michael
parents: 604
diff changeset
856 if(seq - timestamp > 0x2000) seq -= 0x4000;
fce9fc3a0f17 timestamp fix
michael
parents: 604
diff changeset
857 if(seq - timestamp < -0x2000) seq += 0x4000;
fce9fc3a0f17 timestamp fix
michael
parents: 604
diff changeset
858 }
fce9fc3a0f17 timestamp fix
michael
parents: 604
diff changeset
859 }
fce9fc3a0f17 timestamp fix
michael
parents: 604
diff changeset
860 #endif
fce9fc3a0f17 timestamp fix
michael
parents: 604
diff changeset
861 pkt->pts= timestamp;
613
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
862 if(flags&2){
607
fce9fc3a0f17 timestamp fix
michael
parents: 604
diff changeset
863 pkt->flags |= PKT_FLAG_KEY;
613
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
864 if((seq&0x7F) == 1)
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
865 av_add_index_entry(st, pos, timestamp, 0, AVINDEX_KEYFRAME);
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
866 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
867 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
868
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
869 /* for AC3, needs to swap bytes */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
870 if (st->codec.codec_id == CODEC_ID_AC3) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
871 ptr = pkt->data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
872 for(j=0;j<len;j+=2) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
873 tmp = ptr[0];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
874 ptr[0] = ptr[1];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
875 ptr[1] = tmp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
876 ptr += 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
877 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
878 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
879 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
880 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
881
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
882 static int rm_read_close(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
883 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
884 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
885 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
886
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
887 static int rm_probe(AVProbeData *p)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
888 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
889 /* check file header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
890 if (p->buf_size <= 32)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
891 return 0;
194
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
892 if ((p->buf[0] == '.' && p->buf[1] == 'R' &&
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
893 p->buf[2] == 'M' && p->buf[3] == 'F' &&
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
894 p->buf[4] == 0 && p->buf[5] == 0) ||
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
895 (p->buf[0] == '.' && p->buf[1] == 'r' &&
37e7cd3d544d support for older real audio files (<= version 3)
bellard
parents: 188
diff changeset
896 p->buf[2] == 'a' && p->buf[3] == 0xfd))
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
897 return AVPROBE_SCORE_MAX;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
898 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
899 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
900 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
901
612
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
902 static int64_t rm_read_dts(AVFormatContext *s, int stream_index,
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
903 int64_t *ppos, int64_t pos_limit)
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
904 {
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
905 RMContext *rm = s->priv_data;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
906 int64_t pos, dts;
613
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
907 int stream_index2, flags, len, h;
612
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
908
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
909 pos = *ppos;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
910
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
911 if(rm->old_format)
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
912 return AV_NOPTS_VALUE;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
913
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
914 url_fseek(&s->pb, pos, SEEK_SET);
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
915 rm->remaining_len=0;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
916 for(;;){
613
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
917 int seq=1;
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
918 AVStream *st;
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
919
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
920 len=sync(s, &dts, &flags, &stream_index2, &pos);
612
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
921 if(len<0)
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
922 return AV_NOPTS_VALUE;
613
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
923
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
924 st = s->streams[stream_index2];
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
925 if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
926 h= get_byte(&s->pb); len--;
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
927 if(!(h & 0x40)){
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
928 seq = get_byte(&s->pb); len--;
612
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
929 }
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
930 }
613
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
931
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
932 if((flags&2) && (seq&0x7F) == 1){
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
933 // av_log(s, AV_LOG_DEBUG, "%d %d-%d %Ld %d\n", flags, stream_index2, stream_index, dts, seq);
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
934 av_add_index_entry(st, pos, dts, 0, AVINDEX_KEYFRAME);
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
935 if(stream_index2 == stream_index)
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
936 break;
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
937 }
2e70d3938f50 seeking in rm 2nd try
michael
parents: 612
diff changeset
938
612
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
939 url_fskip(&s->pb, len);
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
940 }
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
941 *ppos = pos;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
942 return dts;
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
943 }
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
944
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
945 static AVInputFormat rm_iformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
946 "rm",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
947 "rm format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
948 sizeof(RMContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
949 rm_probe,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
950 rm_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
951 rm_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
952 rm_read_close,
612
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
953 NULL,
fc167cb3b54c seeking in rm
michael
parents: 611
diff changeset
954 rm_read_dts,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
955 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
956
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
957 #ifdef CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
958 static AVOutputFormat rm_oformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
959 "rm",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
960 "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
961 "application/vnd.rn-realmedia",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
962 "rm,ra",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
963 sizeof(RMContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
964 CODEC_ID_AC3,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
965 CODEC_ID_RV10,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
966 rm_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
967 rm_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
968 rm_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
969 };
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
970 #endif //CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
971
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
972 int rm_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
973 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
974 av_register_input_format(&rm_iformat);
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
975 #ifdef CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
976 av_register_output_format(&rm_oformat);
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
977 #endif //CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
978 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
979 }