annotate src/ffmpeg/libavformat/rm.c @ 841:9b50e71f7307 trunk

[svn] - implement shorten support more correctly.
author nenolod
date Mon, 12 Mar 2007 17:37:02 -0700
parents e8776388b02a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1 /*
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
2 * "Real" compatible mux and demux.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
3 * Copyright (c) 2000, 2001 Fabrice Bellard.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
4 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
5 * This file is part of FFmpeg.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
6 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
11 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
15 * Lesser General Public License for more details.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
16 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
20 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
21 #include "avformat.h"
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
22
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
23 /* in ms */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
24 #define BUFFER_DURATION 0
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
25
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
26 typedef struct {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
27 int nb_packets;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
28 int packet_total_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
29 int packet_max_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
30 /* codec related output */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
31 int bit_rate;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
32 float frame_rate;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
33 int nb_frames; /* current frame number */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
34 int total_frames; /* total number of frames */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
35 int num;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
36 AVCodecContext *enc;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
37 } StreamInfo;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
38
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
39 typedef struct {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
40 StreamInfo streams[2];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
41 StreamInfo *audio_stream, *video_stream;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
42 int data_pos; /* position of the data after the header */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
43 int nb_packets;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
44 int old_format;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
45 int current_stream;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
46 int remaining_len;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
47 /// Audio descrambling matrix parameters
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
48 uint8_t *audiobuf; ///< place to store reordered audio data
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
49 int64_t audiotimestamp; ///< Audio packet timestamp
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
50 int sub_packet_cnt; // Subpacket counter, used while reading
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
51 int sub_packet_size, sub_packet_h, coded_framesize; ///< Descrambling parameters from container
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
52 int audio_stream_num; ///< Stream number for audio packets
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
53 int audio_pkt_cnt; ///< Output packet counter
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
54 int audio_framesize; /// Audio frame size from container
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
55 int sub_packet_lengths[16]; /// Length of each aac subpacket
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
56 } RMContext;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
57
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
58 #ifdef CONFIG_MUXERS
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
59 static void put_str(ByteIOContext *s, const char *tag)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
60 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
61 put_be16(s,strlen(tag));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
62 while (*tag) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
63 put_byte(s, *tag++);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
64 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
65 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
66
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
67 static void put_str8(ByteIOContext *s, const char *tag)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
68 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
69 put_byte(s, strlen(tag));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
70 while (*tag) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
71 put_byte(s, *tag++);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
72 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
73 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
74
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
75 static void rv10_write_header(AVFormatContext *ctx,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
76 int data_size, int index_pos)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
77 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
78 RMContext *rm = ctx->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
79 ByteIOContext *s = &ctx->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
80 StreamInfo *stream;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
81 unsigned char *data_offset_ptr, *start_ptr;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
82 const char *desc, *mimetype;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
83 int nb_packets, packet_total_size, packet_max_size, size, packet_avg_size, i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
84 int bit_rate, v, duration, flags, data_pos;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
85
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
86 start_ptr = s->buf_ptr;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
87
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
88 put_tag(s, ".RMF");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
89 put_be32(s,18); /* header size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
90 put_be16(s,0);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
91 put_be32(s,0);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
92 put_be32(s,4 + ctx->nb_streams); /* num headers */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
93
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
94 put_tag(s,"PROP");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
95 put_be32(s, 50);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
96 put_be16(s, 0);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
97 packet_max_size = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
98 packet_total_size = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
99 nb_packets = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
100 bit_rate = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
101 duration = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
102 for(i=0;i<ctx->nb_streams;i++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
103 StreamInfo *stream = &rm->streams[i];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
104 bit_rate += stream->bit_rate;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
105 if (stream->packet_max_size > packet_max_size)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
106 packet_max_size = stream->packet_max_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
107 nb_packets += stream->nb_packets;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
108 packet_total_size += stream->packet_total_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
109 /* select maximum duration */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
110 v = (int) (1000.0 * (float)stream->total_frames / stream->frame_rate);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
111 if (v > duration)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
112 duration = v;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
113 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
114 put_be32(s, bit_rate); /* max bit rate */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
115 put_be32(s, bit_rate); /* avg bit rate */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
116 put_be32(s, packet_max_size); /* max packet size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
117 if (nb_packets > 0)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
118 packet_avg_size = packet_total_size / nb_packets;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
119 else
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
120 packet_avg_size = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
121 put_be32(s, packet_avg_size); /* avg packet size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
122 put_be32(s, nb_packets); /* num packets */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
123 put_be32(s, duration); /* duration */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
124 put_be32(s, BUFFER_DURATION); /* preroll */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
125 put_be32(s, index_pos); /* index offset */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
126 /* computation of data the data offset */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
127 data_offset_ptr = s->buf_ptr;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
128 put_be32(s, 0); /* data offset : will be patched after */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
129 put_be16(s, ctx->nb_streams); /* num streams */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
130 flags = 1 | 2; /* save allowed & perfect play */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
131 if (url_is_streamed(s))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
132 flags |= 4; /* live broadcast */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
133 put_be16(s, flags);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
134
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
135 /* comments */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
136
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
137 put_tag(s,"CONT");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
138 size = strlen(ctx->title) + strlen(ctx->author) + strlen(ctx->copyright) +
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
139 strlen(ctx->comment) + 4 * 2 + 10;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
140 put_be32(s,size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
141 put_be16(s,0);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
142 put_str(s, ctx->title);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
143 put_str(s, ctx->author);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
144 put_str(s, ctx->copyright);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
145 put_str(s, ctx->comment);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
146
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
147 for(i=0;i<ctx->nb_streams;i++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
148 int codec_data_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
149
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
150 stream = &rm->streams[i];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
151
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
152 if (stream->enc->codec_type == CODEC_TYPE_AUDIO) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
153 desc = "The Audio Stream";
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
154 mimetype = "audio/x-pn-realaudio";
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
155 codec_data_size = 73;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
156 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
157 desc = "The Video Stream";
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
158 mimetype = "video/x-pn-realvideo";
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
159 codec_data_size = 34;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
160 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
161
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
162 put_tag(s,"MDPR");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
163 size = 10 + 9 * 4 + strlen(desc) + strlen(mimetype) + codec_data_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
164 put_be32(s, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
165 put_be16(s, 0);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
166
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
167 put_be16(s, i); /* stream number */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
168 put_be32(s, stream->bit_rate); /* max bit rate */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
169 put_be32(s, stream->bit_rate); /* avg bit rate */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
170 put_be32(s, stream->packet_max_size); /* max packet size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
171 if (stream->nb_packets > 0)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
172 packet_avg_size = stream->packet_total_size /
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
173 stream->nb_packets;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
174 else
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
175 packet_avg_size = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
176 put_be32(s, packet_avg_size); /* avg packet size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
177 put_be32(s, 0); /* start time */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
178 put_be32(s, BUFFER_DURATION); /* preroll */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
179 /* duration */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
180 if (url_is_streamed(s) || !stream->total_frames)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
181 put_be32(s, (int)(3600 * 1000));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
182 else
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
183 put_be32(s, (int)(stream->total_frames * 1000 / stream->frame_rate));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
184 put_str8(s, desc);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
185 put_str8(s, mimetype);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
186 put_be32(s, codec_data_size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
187
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
188 if (stream->enc->codec_type == CODEC_TYPE_AUDIO) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
189 int coded_frame_size, fscode, sample_rate;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
190 sample_rate = stream->enc->sample_rate;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
191 coded_frame_size = (stream->enc->bit_rate *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
192 stream->enc->frame_size) / (8 * sample_rate);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
193 /* audio codec info */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
194 put_tag(s, ".ra");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
195 put_byte(s, 0xfd);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
196 put_be32(s, 0x00040000); /* version */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
197 put_tag(s, ".ra4");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
198 put_be32(s, 0x01b53530); /* stream length */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
199 put_be16(s, 4); /* unknown */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
200 put_be32(s, 0x39); /* header size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
201
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
202 switch(sample_rate) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
203 case 48000:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
204 case 24000:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
205 case 12000:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
206 fscode = 1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
207 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
208 default:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
209 case 44100:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
210 case 22050:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
211 case 11025:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
212 fscode = 2;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
213 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
214 case 32000:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
215 case 16000:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
216 case 8000:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
217 fscode = 3;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
218 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
219 put_be16(s, fscode); /* codec additional info, for AC3, seems
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
220 to be a frequency code */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
221 /* special hack to compensate rounding errors... */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
222 if (coded_frame_size == 557)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
223 coded_frame_size--;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
224 put_be32(s, coded_frame_size); /* frame length */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
225 put_be32(s, 0x51540); /* unknown */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
226 put_be32(s, 0x249f0); /* unknown */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
227 put_be32(s, 0x249f0); /* unknown */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
228 put_be16(s, 0x01);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
229 /* frame length : seems to be very important */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
230 put_be16(s, coded_frame_size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
231 put_be32(s, 0); /* unknown */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
232 put_be16(s, stream->enc->sample_rate); /* sample rate */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
233 put_be32(s, 0x10); /* unknown */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
234 put_be16(s, stream->enc->channels);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
235 put_str8(s, "Int0"); /* codec name */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
236 put_str8(s, "dnet"); /* codec name */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
237 put_be16(s, 0); /* title length */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
238 put_be16(s, 0); /* author length */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
239 put_be16(s, 0); /* copyright length */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
240 put_byte(s, 0); /* end of header */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
241 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
242 /* video codec info */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
243 put_be32(s,34); /* size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
244 if(stream->enc->codec_id == CODEC_ID_RV10)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
245 put_tag(s,"VIDORV10");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
246 else
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
247 put_tag(s,"VIDORV20");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
248 put_be16(s, stream->enc->width);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
249 put_be16(s, stream->enc->height);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
250 put_be16(s, (int) stream->frame_rate); /* frames per seconds ? */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
251 put_be32(s,0); /* unknown meaning */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
252 put_be16(s, (int) stream->frame_rate); /* unknown meaning */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
253 put_be32(s,0); /* unknown meaning */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
254 put_be16(s, 8); /* unknown meaning */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
255 /* Seems to be the codec version: only use basic H263. The next
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
256 versions seems to add a diffential DC coding as in
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
257 MPEG... nothing new under the sun */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
258 if(stream->enc->codec_id == CODEC_ID_RV10)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
259 put_be32(s,0x10000000);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
260 else
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
261 put_be32(s,0x20103001);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
262 //put_be32(s,0x10003000);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
263 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
264 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
265
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
266 /* patch data offset field */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
267 data_pos = s->buf_ptr - start_ptr;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
268 rm->data_pos = data_pos;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
269 data_offset_ptr[0] = data_pos >> 24;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
270 data_offset_ptr[1] = data_pos >> 16;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
271 data_offset_ptr[2] = data_pos >> 8;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
272 data_offset_ptr[3] = data_pos;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
273
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
274 /* data stream */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
275 put_tag(s,"DATA");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
276 put_be32(s,data_size + 10 + 8);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
277 put_be16(s,0);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
278
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
279 put_be32(s, nb_packets); /* number of packets */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
280 put_be32(s,0); /* next data header */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
281 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
282
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
283 static void write_packet_header(AVFormatContext *ctx, StreamInfo *stream,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
284 int length, int key_frame)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
285 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
286 int timestamp;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
287 ByteIOContext *s = &ctx->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
288
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
289 stream->nb_packets++;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
290 stream->packet_total_size += length;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
291 if (length > stream->packet_max_size)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
292 stream->packet_max_size = length;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
293
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
294 put_be16(s,0); /* version */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
295 put_be16(s,length + 12);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
296 put_be16(s, stream->num); /* stream number */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
297 timestamp = (1000 * (float)stream->nb_frames) / stream->frame_rate;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
298 put_be32(s, timestamp); /* timestamp */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
299 put_byte(s, 0); /* reserved */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
300 put_byte(s, key_frame ? 2 : 0); /* flags */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
301 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
302
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
303 static int rm_write_header(AVFormatContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
304 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
305 RMContext *rm = s->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
306 StreamInfo *stream;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
307 int n;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
308 AVCodecContext *codec;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
309
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
310 for(n=0;n<s->nb_streams;n++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
311 s->streams[n]->id = n;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
312 codec = s->streams[n]->codec;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
313 stream = &rm->streams[n];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
314 memset(stream, 0, sizeof(StreamInfo));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
315 stream->num = n;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
316 stream->bit_rate = codec->bit_rate;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
317 stream->enc = codec;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
318
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
319 switch(codec->codec_type) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
320 case CODEC_TYPE_AUDIO:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
321 rm->audio_stream = stream;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
322 stream->frame_rate = (float)codec->sample_rate / (float)codec->frame_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
323 /* XXX: dummy values */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
324 stream->packet_max_size = 1024;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
325 stream->nb_packets = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
326 stream->total_frames = stream->nb_packets;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
327 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
328 case CODEC_TYPE_VIDEO:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
329 rm->video_stream = stream;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
330 stream->frame_rate = (float)codec->time_base.den / (float)codec->time_base.num;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
331 /* XXX: dummy values */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
332 stream->packet_max_size = 4096;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
333 stream->nb_packets = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
334 stream->total_frames = stream->nb_packets;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
335 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
336 default:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
337 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
338 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
339 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
340
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
341 rv10_write_header(s, 0, 0);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
342 put_flush_packet(&s->pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
343 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
344 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
345
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
346 static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size, int flags)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
347 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
348 uint8_t *buf1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
349 RMContext *rm = s->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
350 ByteIOContext *pb = &s->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
351 StreamInfo *stream = rm->audio_stream;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
352 int i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
353
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
354 /* XXX: suppress this malloc */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
355 buf1= (uint8_t*) av_malloc( size * sizeof(uint8_t) );
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
356
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
357 write_packet_header(s, stream, size, !!(flags & PKT_FLAG_KEY));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
358
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
359 /* for AC3, the words seems to be reversed */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
360 for(i=0;i<size;i+=2) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
361 buf1[i] = buf[i+1];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
362 buf1[i+1] = buf[i];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
363 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
364 put_buffer(pb, buf1, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
365 put_flush_packet(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
366 stream->nb_frames++;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
367 av_free(buf1);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
368 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
369 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
370
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
371 static int rm_write_video(AVFormatContext *s, const uint8_t *buf, int size, int flags)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
372 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
373 RMContext *rm = s->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
374 ByteIOContext *pb = &s->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
375 StreamInfo *stream = rm->video_stream;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
376 int key_frame = !!(flags & PKT_FLAG_KEY);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
377
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
378 /* XXX: this is incorrect: should be a parameter */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
379
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
380 /* Well, I spent some time finding the meaning of these bits. I am
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
381 not sure I understood everything, but it works !! */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
382 #if 1
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
383 write_packet_header(s, stream, size + 7, key_frame);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
384 /* bit 7: '1' if final packet of a frame converted in several packets */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
385 put_byte(pb, 0x81);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
386 /* bit 7: '1' if I frame. bits 6..0 : sequence number in current
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
387 frame starting from 1 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
388 if (key_frame) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
389 put_byte(pb, 0x81);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
390 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
391 put_byte(pb, 0x01);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
392 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
393 put_be16(pb, 0x4000 + (size)); /* total frame size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
394 put_be16(pb, 0x4000 + (size)); /* offset from the start or the end */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
395 #else
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
396 /* full frame */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
397 write_packet_header(s, size + 6);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
398 put_byte(pb, 0xc0);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
399 put_be16(pb, 0x4000 + size); /* total frame size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
400 put_be16(pb, 0x4000 + packet_number * 126); /* position in stream */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
401 #endif
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
402 put_byte(pb, stream->nb_frames & 0xff);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
403
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
404 put_buffer(pb, buf, size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
405 put_flush_packet(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
406
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
407 stream->nb_frames++;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
408 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
409 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
410
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
411 static int rm_write_packet(AVFormatContext *s, AVPacket *pkt)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
412 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
413 if (s->streams[pkt->stream_index]->codec->codec_type ==
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
414 CODEC_TYPE_AUDIO)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
415 return rm_write_audio(s, pkt->data, pkt->size, pkt->flags);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
416 else
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
417 return rm_write_video(s, pkt->data, pkt->size, pkt->flags);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
418 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
419
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
420 static int rm_write_trailer(AVFormatContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
421 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
422 RMContext *rm = s->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
423 int data_size, index_pos, i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
424 ByteIOContext *pb = &s->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
425
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
426 if (!url_is_streamed(&s->pb)) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
427 /* end of file: finish to write header */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
428 index_pos = url_fseek(pb, 0, SEEK_CUR);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
429 data_size = index_pos - rm->data_pos;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
430
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
431 /* index */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
432 put_tag(pb, "INDX");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
433 put_be32(pb, 10 + 10 * s->nb_streams);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
434 put_be16(pb, 0);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
435
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
436 for(i=0;i<s->nb_streams;i++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
437 put_be32(pb, 0); /* zero indices */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
438 put_be16(pb, i); /* stream number */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
439 put_be32(pb, 0); /* next index */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
440 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
441 /* undocumented end header */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
442 put_be32(pb, 0);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
443 put_be32(pb, 0);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
444
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
445 url_fseek(pb, 0, SEEK_SET);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
446 for(i=0;i<s->nb_streams;i++)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
447 rm->streams[i].total_frames = rm->streams[i].nb_frames;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
448 rv10_write_header(s, data_size, index_pos);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
449 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
450 /* undocumented end header */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
451 put_be32(pb, 0);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
452 put_be32(pb, 0);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
453 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
454 put_flush_packet(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
455 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
456 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
457 #endif //CONFIG_MUXERS
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
458
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
459 /***************************************************/
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
460
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
461 static void get_str(ByteIOContext *pb, char *buf, int buf_size)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
462 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
463 int len, i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
464 char *q;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
465
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
466 len = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
467 q = buf;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
468 for(i=0;i<len;i++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
469 if (i < buf_size - 1)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
470 *q++ = get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
471 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
472 *q = '\0';
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
473 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
474
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
475 static void get_str8(ByteIOContext *pb, char *buf, int buf_size)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
476 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
477 int len, i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
478 char *q;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
479
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
480 len = get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
481 q = buf;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
482 for(i=0;i<len;i++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
483 if (i < buf_size - 1)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
484 *q++ = get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
485 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
486 *q = '\0';
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
487 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
488
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
489 static int rm_read_audio_stream_info(AVFormatContext *s, AVStream *st,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
490 int read_all)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
491 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
492 RMContext *rm = s->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
493 ByteIOContext *pb = &s->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
494 char buf[256];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
495 uint32_t version;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
496 int i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
497
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
498 /* ra type header */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
499 version = get_be32(pb); /* version */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
500 if (((version >> 16) & 0xff) == 3) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
501 int64_t startpos = url_ftell(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
502 /* very old version */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
503 for(i = 0; i < 14; i++)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
504 get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
505 get_str8(pb, s->title, sizeof(s->title));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
506 get_str8(pb, s->author, sizeof(s->author));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
507 get_str8(pb, s->copyright, sizeof(s->copyright));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
508 get_str8(pb, s->comment, sizeof(s->comment));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
509 if ((startpos + (version & 0xffff)) >= url_ftell(pb) + 2) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
510 // fourcc (should always be "lpcJ")
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
511 get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
512 get_str8(pb, buf, sizeof(buf));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
513 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
514 // Skip extra header crap (this should never happen)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
515 if ((startpos + (version & 0xffff)) > url_ftell(pb))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
516 url_fskip(pb, (version & 0xffff) + startpos - url_ftell(pb));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
517 st->codec->sample_rate = 8000;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
518 st->codec->channels = 1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
519 st->codec->codec_type = CODEC_TYPE_AUDIO;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
520 st->codec->codec_id = CODEC_ID_RA_144;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
521 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
522 int flavor, sub_packet_h, coded_framesize, sub_packet_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
523 /* old version (4) */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
524 get_be32(pb); /* .ra4 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
525 get_be32(pb); /* data size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
526 get_be16(pb); /* version2 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
527 get_be32(pb); /* header size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
528 flavor= get_be16(pb); /* add codec info / flavor */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
529 rm->coded_framesize = coded_framesize = get_be32(pb); /* coded frame size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
530 get_be32(pb); /* ??? */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
531 get_be32(pb); /* ??? */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
532 get_be32(pb); /* ??? */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
533 rm->sub_packet_h = sub_packet_h = get_be16(pb); /* 1 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
534 st->codec->block_align= get_be16(pb); /* frame size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
535 rm->sub_packet_size = sub_packet_size = get_be16(pb); /* sub packet size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
536 get_be16(pb); /* ??? */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
537 if (((version >> 16) & 0xff) == 5) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
538 get_be16(pb); get_be16(pb); get_be16(pb); }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
539 st->codec->sample_rate = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
540 get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
541 st->codec->channels = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
542 if (((version >> 16) & 0xff) == 5) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
543 get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
544 buf[0] = get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
545 buf[1] = get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
546 buf[2] = get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
547 buf[3] = get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
548 buf[4] = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
549 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
550 get_str8(pb, buf, sizeof(buf)); /* desc */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
551 get_str8(pb, buf, sizeof(buf)); /* desc */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
552 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
553 st->codec->codec_type = CODEC_TYPE_AUDIO;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
554 if (!strcmp(buf, "dnet")) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
555 st->codec->codec_id = CODEC_ID_AC3;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
556 } else if (!strcmp(buf, "28_8")) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
557 st->codec->codec_id = CODEC_ID_RA_288;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
558 st->codec->extradata_size= 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
559 rm->audio_framesize = st->codec->block_align;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
560 st->codec->block_align = coded_framesize;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
561
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
562 if(rm->audio_framesize >= UINT_MAX / sub_packet_h){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
563 av_log(s, AV_LOG_ERROR, "rm->audio_framesize * sub_packet_h too large\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
564 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
565 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
566
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
567 rm->audiobuf = av_malloc(rm->audio_framesize * sub_packet_h);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
568 } else if (!strcmp(buf, "cook")) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
569 int codecdata_length, i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
570 get_be16(pb); get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
571 if (((version >> 16) & 0xff) == 5)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
572 get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
573 codecdata_length = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
574 if(codecdata_length + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
575 av_log(s, AV_LOG_ERROR, "codecdata_length too large\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
576 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
577 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
578
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
579 st->codec->codec_id = CODEC_ID_COOK;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
580 st->codec->extradata_size= codecdata_length;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
581 st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
582 for(i = 0; i < codecdata_length; i++)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
583 ((uint8_t*)st->codec->extradata)[i] = get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
584 rm->audio_framesize = st->codec->block_align;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
585 st->codec->block_align = rm->sub_packet_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
586
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
587 if(rm->audio_framesize >= UINT_MAX / sub_packet_h){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
588 av_log(s, AV_LOG_ERROR, "rm->audio_framesize * sub_packet_h too large\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
589 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
590 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
591
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
592 rm->audiobuf = av_malloc(rm->audio_framesize * sub_packet_h);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
593 } else if (!strcmp(buf, "raac") || !strcmp(buf, "racp")) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
594 int codecdata_length, i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
595 get_be16(pb); get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
596 if (((version >> 16) & 0xff) == 5)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
597 get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
598 st->codec->codec_id = CODEC_ID_AAC;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
599 codecdata_length = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
600 if(codecdata_length + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
601 av_log(s, AV_LOG_ERROR, "codecdata_length too large\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
602 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
603 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
604 if (codecdata_length >= 1) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
605 st->codec->extradata_size = codecdata_length - 1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
606 st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
607 get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
608 for(i = 0; i < st->codec->extradata_size; i++)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
609 ((uint8_t*)st->codec->extradata)[i] = get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
610 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
611 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
612 st->codec->codec_id = CODEC_ID_NONE;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
613 pstrcpy(st->codec->codec_name, sizeof(st->codec->codec_name),
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
614 buf);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
615 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
616 if (read_all) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
617 get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
618 get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
619 get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
620
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
621 get_str8(pb, s->title, sizeof(s->title));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
622 get_str8(pb, s->author, sizeof(s->author));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
623 get_str8(pb, s->copyright, sizeof(s->copyright));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
624 get_str8(pb, s->comment, sizeof(s->comment));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
625 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
626 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
627 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
628 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
629
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
630 static int rm_read_header_old(AVFormatContext *s, AVFormatParameters *ap)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
631 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
632 RMContext *rm = s->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
633 AVStream *st;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
634
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
635 rm->old_format = 1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
636 st = av_new_stream(s, 0);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
637 if (!st)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
638 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
639 return rm_read_audio_stream_info(s, st, 1);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
640 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
641
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
642 static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
643 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
644 RMContext *rm = s->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
645 AVStream *st;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
646 ByteIOContext *pb = &s->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
647 unsigned int tag, v;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
648 int tag_size, size, codec_data_size, i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
649 int64_t codec_pos;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
650 unsigned int start_time, duration;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
651 char buf[128];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
652 int flags = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
653
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
654 tag = get_le32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
655 if (tag == MKTAG('.', 'r', 'a', 0xfd)) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
656 /* very old .ra format */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
657 return rm_read_header_old(s, ap);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
658 } else if (tag != MKTAG('.', 'R', 'M', 'F')) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
659 return AVERROR_IO;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
660 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
661
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
662 get_be32(pb); /* header size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
663 get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
664 get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
665 get_be32(pb); /* number of headers */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
666
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
667 for(;;) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
668 if (url_feof(pb))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
669 goto fail;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
670 tag = get_le32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
671 tag_size = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
672 get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
673 #if 0
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
674 printf("tag=%c%c%c%c (%08x) size=%d\n",
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
675 (tag) & 0xff,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
676 (tag >> 8) & 0xff,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
677 (tag >> 16) & 0xff,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
678 (tag >> 24) & 0xff,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
679 tag,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
680 tag_size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
681 #endif
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
682 if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A'))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
683 goto fail;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
684 switch(tag) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
685 case MKTAG('P', 'R', 'O', 'P'):
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
686 /* file header */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
687 get_be32(pb); /* max bit rate */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
688 get_be32(pb); /* avg bit rate */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
689 get_be32(pb); /* max packet size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
690 get_be32(pb); /* avg packet size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
691 get_be32(pb); /* nb packets */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
692 get_be32(pb); /* duration */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
693 get_be32(pb); /* preroll */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
694 get_be32(pb); /* index offset */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
695 get_be32(pb); /* data offset */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
696 get_be16(pb); /* nb streams */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
697 flags = get_be16(pb); /* flags */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
698 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
699 case MKTAG('C', 'O', 'N', 'T'):
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
700 get_str(pb, s->title, sizeof(s->title));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
701 get_str(pb, s->author, sizeof(s->author));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
702 get_str(pb, s->copyright, sizeof(s->copyright));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
703 get_str(pb, s->comment, sizeof(s->comment));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
704 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
705 case MKTAG('M', 'D', 'P', 'R'):
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
706 st = av_new_stream(s, 0);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
707 if (!st)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
708 goto fail;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
709 st->id = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
710 get_be32(pb); /* max bit rate */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
711 st->codec->bit_rate = get_be32(pb); /* bit rate */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
712 get_be32(pb); /* max packet size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
713 get_be32(pb); /* avg packet size */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
714 start_time = get_be32(pb); /* start time */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
715 get_be32(pb); /* preroll */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
716 duration = get_be32(pb); /* duration */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
717 st->start_time = start_time;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
718 st->duration = duration;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
719 get_str8(pb, buf, sizeof(buf)); /* desc */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
720 get_str8(pb, buf, sizeof(buf)); /* mimetype */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
721 codec_data_size = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
722 codec_pos = url_ftell(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
723 st->codec->codec_type = CODEC_TYPE_DATA;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
724 av_set_pts_info(st, 64, 1, 1000);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
725
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
726 v = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
727 if (v == MKTAG(0xfd, 'a', 'r', '.')) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
728 /* ra type header */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
729 if (rm_read_audio_stream_info(s, st, 0))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
730 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
731 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
732 int fps, fps2;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
733 if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
734 fail1:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
735 av_log(st->codec, AV_LOG_ERROR, "Unsupported video codec\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
736 goto skip;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
737 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
738 st->codec->codec_tag = get_le32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
739 // av_log(NULL, AV_LOG_DEBUG, "%X %X\n", st->codec->codec_tag, MKTAG('R', 'V', '2', '0'));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
740 if ( st->codec->codec_tag != MKTAG('R', 'V', '1', '0')
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
741 && st->codec->codec_tag != MKTAG('R', 'V', '2', '0')
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
742 && st->codec->codec_tag != MKTAG('R', 'V', '3', '0')
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
743 && st->codec->codec_tag != MKTAG('R', 'V', '4', '0'))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
744 goto fail1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
745 st->codec->width = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
746 st->codec->height = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
747 st->codec->time_base.num= 1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
748 fps= get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
749 st->codec->codec_type = CODEC_TYPE_VIDEO;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
750 get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
751 fps2= get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
752 get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
753
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
754 st->codec->extradata_size= codec_data_size - (url_ftell(pb) - codec_pos);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
755
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
756 if(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codec->extradata_size){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
757 //check is redundant as get_buffer() will catch this
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
758 av_log(s, AV_LOG_ERROR, "st->codec->extradata_size too large\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
759 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
760 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
761 st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
762 get_buffer(pb, st->codec->extradata, st->codec->extradata_size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
763
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
764 // av_log(NULL, AV_LOG_DEBUG, "fps= %d fps2= %d\n", fps, fps2);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
765 st->codec->time_base.den = fps * st->codec->time_base.num;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
766 switch(((uint8_t*)st->codec->extradata)[4]>>4){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
767 case 1: st->codec->codec_id = CODEC_ID_RV10; break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
768 case 2: st->codec->codec_id = CODEC_ID_RV20; break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
769 case 3: st->codec->codec_id = CODEC_ID_RV30; break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
770 case 4: st->codec->codec_id = CODEC_ID_RV40; break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
771 default: goto fail1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
772 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
773 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
774 skip:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
775 /* skip codec info */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
776 size = url_ftell(pb) - codec_pos;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
777 url_fskip(pb, codec_data_size - size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
778 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
779 case MKTAG('D', 'A', 'T', 'A'):
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
780 goto header_end;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
781 default:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
782 /* unknown tag: skip it */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
783 url_fskip(pb, tag_size - 10);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
784 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
785 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
786 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
787 header_end:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
788 rm->nb_packets = get_be32(pb); /* number of packets */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
789 if (!rm->nb_packets && (flags & 4))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
790 rm->nb_packets = 3600 * 25;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
791 get_be32(pb); /* next data header */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
792 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
793
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
794 fail:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
795 for(i=0;i<s->nb_streams;i++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
796 av_free(s->streams[i]);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
797 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
798 return AVERROR_IO;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
799 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
800
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
801 static int get_num(ByteIOContext *pb, int *len)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
802 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
803 int n, n1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
804
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
805 n = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
806 (*len)-=2;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
807 if (n >= 0x4000) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
808 return n - 0x4000;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
809 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
810 n1 = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
811 (*len)-=2;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
812 return (n << 16) | n1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
813 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
814 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
815
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
816 /* multiple of 20 bytes for ra144 (ugly) */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
817 #define RAW_PACKET_SIZE 1000
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
818
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
819 static int sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_index, int64_t *pos){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
820 RMContext *rm = s->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
821 ByteIOContext *pb = &s->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
822 int len, num, res, i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
823 AVStream *st;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
824 uint32_t state=0xFFFFFFFF;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
825
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
826 while(!url_feof(pb)){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
827 *pos= url_ftell(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
828 if(rm->remaining_len > 0){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
829 num= rm->current_stream;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
830 len= rm->remaining_len;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
831 *timestamp = AV_NOPTS_VALUE;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
832 *flags= 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
833 }else{
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
834 state= (state<<8) + get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
835
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
836 if(state == MKBETAG('I', 'N', 'D', 'X')){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
837 len = get_be16(pb) - 6;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
838 if(len<0)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
839 continue;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
840 goto skip;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
841 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
842
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
843 if(state > (unsigned)0xFFFF || state < 12)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
844 continue;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
845 len=state;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
846 state= 0xFFFFFFFF;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
847
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
848 num = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
849 *timestamp = get_be32(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
850 res= get_byte(pb); /* reserved */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
851 *flags = get_byte(pb); /* flags */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
852
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
853
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
854 len -= 12;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
855 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
856 for(i=0;i<s->nb_streams;i++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
857 st = s->streams[i];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
858 if (num == st->id)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
859 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
860 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
861 if (i == s->nb_streams) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
862 skip:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
863 /* skip packet if unknown number */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
864 url_fskip(pb, len);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
865 rm->remaining_len -= len;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
866 continue;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
867 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
868 *stream_index= i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
869
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
870 return len;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
871 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
872 return -1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
873 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
874
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
875 static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
876 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
877 RMContext *rm = s->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
878 ByteIOContext *pb = &s->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
879 AVStream *st;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
880 int i, len, tmp, j;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
881 int64_t timestamp, pos;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
882 uint8_t *ptr;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
883 int flags;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
884
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
885 if (rm->audio_pkt_cnt) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
886 // If there are queued audio packet return them first
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
887 st = s->streams[rm->audio_stream_num];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
888 if (st->codec->codec_id == CODEC_ID_AAC)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
889 av_get_packet(pb, pkt, rm->sub_packet_lengths[rm->sub_packet_cnt - rm->audio_pkt_cnt]);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
890 else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
891 av_new_packet(pkt, st->codec->block_align);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
892 memcpy(pkt->data, rm->audiobuf + st->codec->block_align *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
893 (rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - rm->audio_pkt_cnt),
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
894 st->codec->block_align);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
895 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
896 rm->audio_pkt_cnt--;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
897 pkt->flags = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
898 pkt->stream_index = rm->audio_stream_num;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
899 } else if (rm->old_format) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
900 st = s->streams[0];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
901 if (st->codec->codec_id == CODEC_ID_RA_288) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
902 int x, y;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
903
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
904 for (y = 0; y < rm->sub_packet_h; y++)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
905 for (x = 0; x < rm->sub_packet_h/2; x++)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
906 if (get_buffer(pb, rm->audiobuf+x*2*rm->audio_framesize+y*rm->coded_framesize, rm->coded_framesize) <= 0)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
907 return AVERROR_IO;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
908 rm->audio_stream_num = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
909 rm->audio_pkt_cnt = rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - 1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
910 // Release first audio packet
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
911 av_new_packet(pkt, st->codec->block_align);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
912 memcpy(pkt->data, rm->audiobuf, st->codec->block_align);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
913 pkt->flags |= PKT_FLAG_KEY; // Mark first packet as keyframe
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
914 pkt->stream_index = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
915 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
916 /* just read raw bytes */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
917 len = RAW_PACKET_SIZE;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
918 len= av_get_packet(pb, pkt, len);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
919 pkt->stream_index = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
920 if (len <= 0) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
921 return AVERROR_IO;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
922 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
923 pkt->size = len;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
924 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
925 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
926 int seq=1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
927 resync:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
928 len=sync(s, &timestamp, &flags, &i, &pos);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
929 if(len<0)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
930 return AVERROR_IO;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
931 st = s->streams[i];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
932
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
933 if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
934 int h, pic_num, len2, pos;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
935
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
936 h= get_byte(pb); len--;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
937 if(!(h & 0x40)){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
938 seq = get_byte(pb); len--;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
939 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
940
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
941 if((h & 0xc0) == 0x40){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
942 len2= pos= 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
943 }else{
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
944 len2 = get_num(pb, &len);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
945 pos = get_num(pb, &len);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
946 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
947 /* picture number */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
948 pic_num= get_byte(pb); len--;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
949 rm->remaining_len= len;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
950 rm->current_stream= st->id;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
951
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
952 // av_log(NULL, AV_LOG_DEBUG, "%X len:%d pos:%d len2:%d pic_num:%d\n",h, len, pos, len2, pic_num);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
953 if(len2 && len2<len)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
954 len=len2;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
955 rm->remaining_len-= len;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
956 av_get_packet(pb, pkt, len);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
957 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
958
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
959 if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
960 if ((st->codec->codec_id == CODEC_ID_RA_288) ||
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
961 (st->codec->codec_id == CODEC_ID_COOK)) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
962 int x;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
963 int sps = rm->sub_packet_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
964 int cfs = rm->coded_framesize;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
965 int h = rm->sub_packet_h;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
966 int y = rm->sub_packet_cnt;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
967 int w = rm->audio_framesize;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
968
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
969 if (flags & 2)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
970 y = rm->sub_packet_cnt = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
971 if (!y)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
972 rm->audiotimestamp = timestamp;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
973
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
974 switch(st->codec->codec_id) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
975 case CODEC_ID_RA_288:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
976 for (x = 0; x < h/2; x++)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
977 get_buffer(pb, rm->audiobuf+x*2*w+y*cfs, cfs);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
978 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
979 case CODEC_ID_COOK:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
980 for (x = 0; x < w/sps; x++)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
981 get_buffer(pb, rm->audiobuf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
982 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
983 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
984
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
985 if (++(rm->sub_packet_cnt) < h)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
986 goto resync;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
987 else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
988 rm->sub_packet_cnt = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
989 rm->audio_stream_num = i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
990 rm->audio_pkt_cnt = h * w / st->codec->block_align - 1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
991 // Release first audio packet
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
992 av_new_packet(pkt, st->codec->block_align);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
993 memcpy(pkt->data, rm->audiobuf, st->codec->block_align);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
994 timestamp = rm->audiotimestamp;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
995 flags = 2; // Mark first packet as keyframe
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
996 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
997 } else if (st->codec->codec_id == CODEC_ID_AAC) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
998 int x;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
999 rm->audio_stream_num = i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1000 rm->sub_packet_cnt = (get_be16(pb) & 0xf0) >> 4;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1001 if (rm->sub_packet_cnt) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1002 for (x = 0; x < rm->sub_packet_cnt; x++)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1003 rm->sub_packet_lengths[x] = get_be16(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1004 // Release first audio packet
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1005 rm->audio_pkt_cnt = rm->sub_packet_cnt - 1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1006 av_get_packet(pb, pkt, rm->sub_packet_lengths[0]);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1007 flags = 2; // Mark first packet as keyframe
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1008 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1009 } else
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1010 av_get_packet(pb, pkt, len);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1011 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1012
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1013 if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1014 || st->discard >= AVDISCARD_ALL){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1015 av_free_packet(pkt);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1016 goto resync;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1017 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1018
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1019 pkt->stream_index = i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1020
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1021 #if 0
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1022 if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1023 if(st->codec->codec_id == CODEC_ID_RV20){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1024 int seq= 128*(pkt->data[2]&0x7F) + (pkt->data[3]>>1);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1025 av_log(NULL, AV_LOG_DEBUG, "%d %Ld %d\n", timestamp, timestamp*512LL/25, seq);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1026
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1027 seq |= (timestamp&~0x3FFF);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1028 if(seq - timestamp > 0x2000) seq -= 0x4000;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1029 if(seq - timestamp < -0x2000) seq += 0x4000;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1030 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1031 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1032 #endif
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1033 pkt->pts= timestamp;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1034 if(flags&2){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1035 pkt->flags |= PKT_FLAG_KEY;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1036 if((seq&0x7F) == 1)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1037 av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1038 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1039 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1040
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1041 /* for AC3, needs to swap bytes */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1042 if (st->codec->codec_id == CODEC_ID_AC3) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1043 ptr = pkt->data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1044 for(j=0;j<len;j+=2) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1045 tmp = ptr[0];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1046 ptr[0] = ptr[1];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1047 ptr[1] = tmp;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1048 ptr += 2;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1049 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1050 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1051 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1052 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1053
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1054 static int rm_read_close(AVFormatContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1055 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1056 RMContext *rm = s->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1057
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1058 av_free(rm->audiobuf);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1059 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1060 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1061
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1062 static int rm_probe(AVProbeData *p)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1063 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1064 /* check file header */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1065 if (p->buf_size <= 32)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1066 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1067 if ((p->buf[0] == '.' && p->buf[1] == 'R' &&
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1068 p->buf[2] == 'M' && p->buf[3] == 'F' &&
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1069 p->buf[4] == 0 && p->buf[5] == 0) ||
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1070 (p->buf[0] == '.' && p->buf[1] == 'r' &&
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1071 p->buf[2] == 'a' && p->buf[3] == 0xfd))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1072 return AVPROBE_SCORE_MAX;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1073 else
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1074 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1075 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1076
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1077 static int64_t rm_read_dts(AVFormatContext *s, int stream_index,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1078 int64_t *ppos, int64_t pos_limit)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1079 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1080 RMContext *rm = s->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1081 int64_t pos, dts;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1082 int stream_index2, flags, len, h;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1083
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1084 pos = *ppos;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1085
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1086 if(rm->old_format)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1087 return AV_NOPTS_VALUE;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1088
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1089 url_fseek(&s->pb, pos, SEEK_SET);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1090 rm->remaining_len=0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1091 for(;;){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1092 int seq=1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1093 AVStream *st;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1094
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1095 len=sync(s, &dts, &flags, &stream_index2, &pos);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1096 if(len<0)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1097 return AV_NOPTS_VALUE;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1098
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1099 st = s->streams[stream_index2];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1100 if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1101 h= get_byte(&s->pb); len--;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1102 if(!(h & 0x40)){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1103 seq = get_byte(&s->pb); len--;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1104 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1105 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1106
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1107 if((flags&2) && (seq&0x7F) == 1){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1108 // av_log(s, AV_LOG_DEBUG, "%d %d-%d %Ld %d\n", flags, stream_index2, stream_index, dts, seq);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1109 av_add_index_entry(st, pos, dts, 0, 0, AVINDEX_KEYFRAME);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1110 if(stream_index2 == stream_index)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1111 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1112 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1113
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1114 url_fskip(&s->pb, len);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1115 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1116 *ppos = pos;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1117 return dts;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1118 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1119
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1120 #ifdef CONFIG_RM_DEMUXER
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1121 AVInputFormat rm_demuxer = {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1122 "rm",
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1123 "rm format",
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1124 sizeof(RMContext),
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1125 rm_probe,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1126 rm_read_header,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1127 rm_read_packet,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1128 rm_read_close,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1129 NULL,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1130 rm_read_dts,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1131 };
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1132 #endif
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1133 #ifdef CONFIG_RM_MUXER
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1134 AVOutputFormat rm_muxer = {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1135 "rm",
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1136 "rm format",
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1137 "application/vnd.rn-realmedia",
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1138 "rm,ra",
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1139 sizeof(RMContext),
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1140 CODEC_ID_AC3,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1141 CODEC_ID_RV10,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1142 rm_write_header,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1143 rm_write_packet,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1144 rm_write_trailer,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1145 };
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1146 #endif