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
38
39 #define RIFF_TAG MKTAG('R', 'I', 'F', 'F')
40 #define CDXA_TAG MKTAG('C', 'D', 'X', 'A')
41
42 #define RAW_CD_SECTOR_SIZE 2352
43 #define RAW_CD_SECTOR_DATA_SIZE 2304
44 #define VIDEO_DATA_CHUNK_SIZE 0x7E0
45 #define VIDEO_DATA_HEADER_SIZE 0x38
46 #define RIFF_HEADER_SIZE 0x2C
47
48 #define CDXA_TYPE_MASK 0x0E
49 #define CDXA_TYPE_DATA 0x08
50 #define CDXA_TYPE_AUDIO 0x04
51 #define CDXA_TYPE_VIDEO 0x02
52 #define CDXA_TYPE_EMPTY 0x00
53
54 #define STR_MAGIC (0x80010160)
55
57 /* video parameters */
60
61 /* audio parameters */
64
66
67 /* a STR file can contain up to 32 channels of data */
70
71 static const uint8_t
sync_header[12] = {0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00};
72
74 {
75 const uint8_t *sector= p->
buf;
76 const uint8_t *end= sector + p->
buf_size;
78
80 return 0;
81
84
85 /* RIFF header seen; skip 0x2C bytes */
87 }
88
90 /* look for CD sync header (00, 0xFF x 10, 00) */
92 return 0;
93
94 if (sector[0x11] >= 32)
95 return 0;
96
100 int current_sector =
AV_RL16(§or[0x1C]);
101 int sector_count =
AV_RL16(§or[0x1E]);
103
105 && current_sector < sector_count
107 return 0;
108 }
109 vid++;
110
111 }
112 break;
114 if(sector[0x13]&0x2A)
115 return 0;
117 break;
118 default:
120 return 0;
121 }
123 }
124 /* MPEG files (like those ripped from VCDs) can also look like this;
125 * only return half certainty */
127 else if(vid+
aud)
return 1;
128 else return 0;
129 }
130
132 {
136 int start;
138
139 /* skip over any RIFF header */
144 else
145 start = 0;
146
148
152 }
153
155
156 return 0;
157 }
158
161 {
168
169 while (1) {
171
174
177
181
183
186 {
187
188 int current_sector =
AV_RL16(§or[0x1C]);
189 int sector_count =
AV_RL16(§or[0x1E]);
191
193 && current_sector < sector_count
196 break;
197 }
198
200 /* allocate a new AVStream */
202 if (!st)
205
207
213 }
214
215 /* if this is the first sector of the frame, allocate a pkt */
217
226
230 }
231
235
236 if (current_sector == sector_count-1) {
242 return 0;
243 }
244
245 }
246 break;
247
250 int fmt = sector[0x13];
251 /* allocate a new AVStream */
253 if (!st)
255
257
263 // st->codecpar->bit_rate = 0; //FIXME;
265
269 }
273 memcpy(
pkt->
data,sector+24,2304);
274
278 return 0;
280 /* NOTE this also catches 0x80 (EOF bit) because of CDXA_TYPE_MASK */
281 /* TODO consider refactoring so as to explicitly handle each case? */
282 break;
283 default:
285 /* drop the sector and move on */
286 break;
287 }
288
291 }
292 }
293
295 {
301 }
302
303 return 0;
304 }
305
315 };