1 /*
2 * Sony Playstation (PSX) STR File Demuxer
3 * Copyright (c) 2003 The ffmpeg Project
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 * @file
24 * PSX STR file demuxer
25 * by Mike Melanson (melanson@pcisys.net)
26 * This module handles streams that have been ripped from Sony Playstation
27 * CD games. This demuxer can handle either raw STR files (which are just
28 * concatenations of raw compact disc sectors) or STR files with 0x2C-byte
29 * RIFF headers, followed by CD sectors.
30 */
31
36
37 #define RIFF_TAG MKTAG('R', 'I', 'F', 'F')
38 #define CDXA_TAG MKTAG('C', 'D', 'X', 'A')
39
40 #define RAW_CD_SECTOR_SIZE 2352
41 #define RAW_CD_SECTOR_DATA_SIZE 2304
42 #define VIDEO_DATA_CHUNK_SIZE 0x7E0
43 #define VIDEO_DATA_HEADER_SIZE 0x38
44 #define RIFF_HEADER_SIZE 0x2C
45
46 #define CDXA_TYPE_MASK 0x0E
47 #define CDXA_TYPE_DATA 0x08
48 #define CDXA_TYPE_AUDIO 0x04
49 #define CDXA_TYPE_VIDEO 0x02
50
51 #define STR_MAGIC (0x80010160)
52
54 /* video parameters */
57
58 /* audio parameters */
61
63
64 /* a STR file can contain up to 32 channels of data */
67
68 static const uint8_t sync_header[12] = {0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00};
69
71 {
74 int aud=0, vid=0;
75
77 return 0;
78
81
82 /* RIFF header seen; skip 0x2C bytes */
84 }
85
87 /* look for CD sync header (00, 0xFF x 10, 00) */
89 return 0;
90
91 if (sector[0x11] >= 32)
92 return 0;
93
97 int current_sector =
AV_RL16(§or[0x1C]);
98 int sector_count =
AV_RL16(§or[0x1E]);
100
101 if(!( frame_size>=0
102 && current_sector < sector_count
104 return 0;
105 }
106
107 /*st->codec->width = AV_RL16(§or[0x28]);
108 st->codec->height = AV_RL16(§or[0x2A]);*/
109
110 // if (current_sector == sector_count-1) {
111 vid++;
112 // }
113
114 }
115 break;
117 if(sector[0x13]&0x2A)
118 return 0;
119 aud++;
120 break;
121 default:
122 if(sector[0x12] & CDXA_TYPE_MASK)
123 return 0;
124 }
126 }
127 /* MPEG files (like those ripped from VCDs) can also look like this;
128 * only return half certainty */
130 else if(vid+aud) return 1;
131 else return 0;
132 }
133
135 {
140 int i;
141
142 /* skip over any RIFF header */
147 else
148 start = 0;
149
151
152 for(i=0; i<32; i++){
155 }
156
158
159 return 0;
160 }
161
164 {
168 int channel;
171
172 while (1) {
173
176
177 channel = sector[0x11];
178 if (channel >= 32)
180
182
185 {
186
187 int current_sector =
AV_RL16(§or[0x1C]);
188 int sector_count =
AV_RL16(§or[0x1E]);
190
191 if(!( frame_size>=0
192 && current_sector < sector_count
194 av_log(s,
AV_LOG_ERROR,
"Invalid parameters %d %d %d\n", current_sector, sector_count, frame_size);
195 break;
196 }
197
199 /* allocate a new AVStream */
201 if (!st)
204
206
212 }
213
214 /* if this is the first sector of the frame, allocate a pkt */
216
223
227 }
228
229 memcpy(pkt->
data + current_sector*VIDEO_DATA_CHUNK_SIZE,
231 VIDEO_DATA_CHUNK_SIZE);
232
233 if (current_sector == sector_count-1) {
239 #if FF_API_DESTRUCT_PACKET
240 pkt->destruct = NULL;
241 #endif
242 return 0;
243 }
244
245 }
246 break;
247
250 int fmt = sector[0x13];
251 /* allocate a new AVStream */
253 if (!st)
255
257
261 if (fmt & 1) {
264 } else {
267 }
269 // st->codec->bit_rate = 0; //FIXME;
271
275 }
276 pkt = ret_pkt;
279 memcpy(pkt->
data,sector+24,2304);
280
284 return 0;
285 default:
287 /* drop the sector and move on */
288 break;
289 }
290
293 }
294 }
295
297 {
299 int i;
300 for(i=0; i<32; i++){
303 }
304
305 return 0;
306 }
307
317 };