1 /*
2 * RL2 Format Demuxer
3 * Copyright (c) 2008 Sascha Sommer (saschasommer@freenet.de)
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * RL2 file demuxer
24 * @file
25 * @author Sascha Sommer (saschasommer@freenet.de)
26 * @see http://wiki.multimedia.cx/index.php?title=RL2
27 *
28 * extradata:
29 * 2 byte le initial drawing offset within 320x200 viewport
30 * 4 byte le number of used colors
31 * 256 * 3 bytes rgb palette
32 * optional background_frame
33 */
34
35 #include <stdint.h>
36
42
43 #define EXTRADATA1_SIZE (6 + 256 * 3) ///< video base, clr, palette
44
45 #define FORM_TAG MKBETAG('F', 'O', 'R', 'M')
46 #define RLV2_TAG MKBETAG('R', 'L', 'V', '2')
47 #define RLV3_TAG MKBETAG('R', 'L', 'V', '3')
48
50 unsigned int index_pos[2];
///< indexes in the sample tables
52
53
54 /**
55 * check if the file is in rl2 format
56 * @param p probe buffer
57 * @return 0 when the probe buffer does not contain rl2 data, > 0 otherwise
58 */
60 {
61
63 return 0;
64
67 return 0;
68
70 }
71
72 /**
73 * read rl2 header data and setup the avstreams
74 * @param s demuxer context
75 * @return 0 on success, AVERROR otherwise
76 */
78 {
81 unsigned int frame_count;
82 unsigned int audio_frame_counter = 0;
83 unsigned int video_frame_counter = 0;
84 unsigned int back_size;
85 unsigned short sound_rate;
86 unsigned short rate;
88 unsigned short def_sound_size;
90 unsigned int pts_den = 11025; /* video only case */
91 unsigned int pts_num = 1103;
92 unsigned int* chunk_offset =
NULL;
93 int* chunk_size =
NULL;
94 int* audio_size =
NULL;
97
99 back_size =
avio_rl32(pb);
/**< get size of the background frame */
103
104 /* disallow back_sizes and frame_counts that may lead to overflows later */
105 if(back_size > INT_MAX/2 || frame_count > INT_MAX / sizeof(uint32_t))
107
113
114 /** setup video stream */
116 if(!st)
118
124
125 /** allocate and fill extradata */
127
130
134
135 /** setup audio stream if present */
136 if(sound_rate){
140 }
141
142 pts_num = def_sound_size;
143 pts_den = rate;
144
146 if (!st)
159 }
160
162
163 chunk_size =
av_malloc(frame_count *
sizeof(uint32_t));
164 audio_size =
av_malloc(frame_count *
sizeof(uint32_t));
165 chunk_offset =
av_malloc(frame_count *
sizeof(uint32_t));
166
167 if(!chunk_size || !audio_size || !chunk_offset){
172 }
173
174 /** read offset and size tables */
175 for(
i=0;
i < frame_count;
i++) {
178 goto end;
179 }
181 }
182 for(
i=0;
i < frame_count;
i++) {
185 goto end;
186 }
188 }
189 for(
i=0;
i < frame_count;
i++) {
192 goto end;
193 }
195 }
196
197 /** build the sample index */
198 for(
i=0;
i<frame_count;
i++){
199 if(chunk_size[
i] < 0 || audio_size[
i] > chunk_size[
i]){
201 break;
202 }
203
204 if(sound_rate && audio_size[
i]){
207 audio_frame_counter += audio_size[
i] /
channels;
208 }
211 ++video_frame_counter;
212 }
213
214 end:
218
220 }
221
222 /**
223 * read a single audio or video packet
224 * @param s demuxer context
225 * @param pkt the packet to be filled
226 * @return 0 on success, AVERROR otherwise
227 */
230 {
236 int stream_id = -1;
237 int64_t
pos = INT64_MAX;
238
239 /** check if there is a valid video or audio entry that can be used */
240 for(
i=0;
i<
s->nb_streams;
i++){
247 }
248 }
249
250 if(stream_id == -1)
252
254
255 /** position the stream (will probably be there anyway) */
257
258 /** fill the packet */
262 }
263
266
268 }
269
270 /**
271 * seek to a new timestamp
272 * @param s demuxer context
273 * @param stream_index index of the stream that should be seeked
274 * @param timestamp wanted timestamp
275 * @param flags direction and seeking mode
276 * @return 0 on success, -1 otherwise
277 */
279 {
285 return -1;
286
289
290 for(
i=0;
i <
s->nb_streams;
i++){
295
298
300 }
301
302 return 0;
303 }
304
313 };