Mercurial > libavformat.hg
annotate psxstr.c @ 3514:616ffabfbb5b libavformat
vertical align
| author | michael |
|---|---|
| date | Thu, 26 Jun 2008 22:30:14 +0000 |
| parents | cfd3815774ad |
| children | 4f78b4688afc |
| rev | line source |
|---|---|
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
1 /* |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
2 * Sony Playstation (PSX) STR File Demuxer |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
3 * Copyright (c) 2003 The ffmpeg Project |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
4 * |
|
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1242
diff
changeset
|
5 * This file is part of FFmpeg. |
|
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1242
diff
changeset
|
6 * |
|
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1242
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
|
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1242
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
11 * |
|
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1242
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
16 * |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
|
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1242
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
|
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
885
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
20 */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
21 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
22 /** |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
23 * @file psxstr.c |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
24 * PSX STR file demuxer |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
25 * by Mike Melanson (melanson@pcisys.net) |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
26 * This module handles streams that have been ripped from Sony Playstation |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
27 * CD games. This demuxer can handle either raw STR files (which are just |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
28 * concatenations of raw compact disc sectors) or STR files with 0x2C-byte |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
29 * RIFF headers, followed by CD sectors. |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
30 */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
31 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
32 #include "avformat.h" |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
33 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
34 //#define PRINTSTUFF |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
35 |
|
386
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
370
diff
changeset
|
36 #define RIFF_TAG MKTAG('R', 'I', 'F', 'F') |
|
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
370
diff
changeset
|
37 #define CDXA_TAG MKTAG('C', 'D', 'X', 'A') |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
38 |
| 3514 | 39 #define RAW_CD_SECTOR_SIZE 2352 |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
40 #define RAW_CD_SECTOR_DATA_SIZE 2304 |
| 3514 | 41 #define VIDEO_DATA_CHUNK_SIZE 0x7E0 |
| 42 #define VIDEO_DATA_HEADER_SIZE 0x38 | |
| 43 #define RIFF_HEADER_SIZE 0x2C | |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
44 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
45 #define CDXA_TYPE_MASK 0x0E |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
46 #define CDXA_TYPE_DATA 0x08 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
47 #define CDXA_TYPE_AUDIO 0x04 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
48 #define CDXA_TYPE_VIDEO 0x02 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
49 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
50 #define STR_MAGIC (0x80010160) |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
51 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
52 typedef struct StrChannel { |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
53 /* video parameters */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
54 int video_stream_index; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
55 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
56 /* audio parameters */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
57 int audio_stream_index; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
58 } StrChannel; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
59 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
60 typedef struct StrDemuxContext { |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
61 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
62 /* a STR file can contain up to 32 channels of data */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
63 StrChannel channels[32]; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
64 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
65 /* only decode the first audio and video channels encountered */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
66 int video_channel; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
67 int audio_channel; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
68 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
69 int64_t pts; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
70 |
| 281 | 71 AVPacket tmp_pkt; |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
72 } StrDemuxContext; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
73 |
|
1242
996ce2a68147
Fix some "'static' is not at beginning of declaration" warnings.
diego
parents:
1169
diff
changeset
|
74 static const char sync_header[12] = {0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00}; |
| 281 | 75 |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
76 static int str_probe(AVProbeData *p) |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
77 { |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
78 int start; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
79 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
80 /* need at least 0x38 bytes to validate */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
81 if (p->buf_size < 0x38) |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
82 return 0; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
83 |
| 1673 | 84 if ((AV_RL32(&p->buf[0]) == RIFF_TAG) && |
| 85 (AV_RL32(&p->buf[8]) == CDXA_TAG)) { | |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
86 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
87 /* RIFF header seen; skip 0x2C bytes */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
88 start = RIFF_HEADER_SIZE; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
89 } else |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
90 start = 0; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
91 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
92 /* look for CD sync header (00, 0xFF x 10, 00) */ |
| 281 | 93 if (memcmp(p->buf+start,sync_header,sizeof(sync_header))) |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
94 return 0; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
95 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
96 /* MPEG files (like those ripped from VCDs) can also look like this; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
97 * only return half certainty */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
98 return 50; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
99 } |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
100 |
|
683
095009fc2f35
kill warnings patch by (M?ns Rullg?rd <mru inprovide com>)
michael
parents:
482
diff
changeset
|
101 #if 0 |
| 281 | 102 static void dump(unsigned char *buf,size_t len) |
| 103 { | |
| 104 int i; | |
| 105 for(i=0;i<len;i++) { | |
|
370
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
281
diff
changeset
|
106 if ((i&15)==0) av_log(NULL, AV_LOG_DEBUG, "%04x ",i); |
|
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
281
diff
changeset
|
107 av_log(NULL, AV_LOG_DEBUG, "%02x ",buf[i]); |
|
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
281
diff
changeset
|
108 if ((i&15)==15) av_log(NULL, AV_LOG_DEBUG, "\n"); |
| 281 | 109 } |
|
370
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
281
diff
changeset
|
110 av_log(NULL, AV_LOG_DEBUG, "\n"); |
| 281 | 111 } |
|
683
095009fc2f35
kill warnings patch by (M?ns Rullg?rd <mru inprovide com>)
michael
parents:
482
diff
changeset
|
112 #endif |
| 281 | 113 |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
114 static int str_read_header(AVFormatContext *s, |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
115 AVFormatParameters *ap) |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
116 { |
|
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
117 ByteIOContext *pb = s->pb; |
| 2006 | 118 StrDemuxContext *str = s->priv_data; |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
119 AVStream *st; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
120 unsigned char sector[RAW_CD_SECTOR_SIZE]; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
121 int start; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
122 int i; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
123 int channel; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
124 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
125 /* initialize context members */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
126 str->pts = 0; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
127 str->audio_channel = -1; /* assume to audio or video */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
128 str->video_channel = -1; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
129 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
130 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
131 /* skip over any RIFF header */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
132 if (get_buffer(pb, sector, RIFF_HEADER_SIZE) != RIFF_HEADER_SIZE) |
|
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
133 return AVERROR(EIO); |
| 1673 | 134 if (AV_RL32(§or[0]) == RIFF_TAG) |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
135 start = RIFF_HEADER_SIZE; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
136 else |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
137 start = 0; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
138 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
139 url_fseek(pb, start, SEEK_SET); |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
140 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
141 /* check through the first 32 sectors for individual channels */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
142 for (i = 0; i < 32; i++) { |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
143 if (get_buffer(pb, sector, RAW_CD_SECTOR_SIZE) != RAW_CD_SECTOR_SIZE) |
|
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
144 return AVERROR(EIO); |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
145 |
| 281 | 146 //printf("%02x %02x %02x %02x\n",sector[0x10],sector[0x11],sector[0x12],sector[0x13]); |
| 147 | |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
148 channel = sector[0x11]; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
149 if (channel >= 32) |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
150 return AVERROR_INVALIDDATA; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
151 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
152 switch (sector[0x12] & CDXA_TYPE_MASK) { |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
153 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
154 case CDXA_TYPE_DATA: |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
155 case CDXA_TYPE_VIDEO: |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
156 /* check if this channel gets to be the dominant video channel */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
157 if (str->video_channel == -1) { |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
158 /* qualify the magic number */ |
| 1673 | 159 if (AV_RL32(§or[0x18]) != STR_MAGIC) |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
160 break; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
161 str->video_channel = channel; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
162 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
163 /* allocate a new AVStream */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
164 st = av_new_stream(s, 0); |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
165 if (!st) |
|
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2006
diff
changeset
|
166 return AVERROR(ENOMEM); |
|
837
4cf524326a1a
set timebase correctly? this thing is always 15fps?
michael
parents:
820
diff
changeset
|
167 av_set_pts_info(st, 64, 1, 15); |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
168 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
169 str->channels[channel].video_stream_index = st->index; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
170 |
|
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
171 st->codec->codec_type = CODEC_TYPE_VIDEO; |
| 3514 | 172 st->codec->codec_id = CODEC_ID_MDEC; |
| 173 st->codec->codec_tag = 0; /* no fourcc */ | |
| 3513 | 174 st->codec->width = AV_RL16(§or[0x28]); |
| 175 st->codec->height = AV_RL16(§or[0x2A]); | |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
176 } |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
177 break; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
178 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
179 case CDXA_TYPE_AUDIO: |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
180 /* check if this channel gets to be the dominant audio channel */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
181 if (str->audio_channel == -1) { |
| 281 | 182 int fmt; |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
183 str->audio_channel = channel; |
| 281 | 184 |
| 185 /* allocate a new AVStream */ | |
| 186 st = av_new_stream(s, 0); | |
| 187 if (!st) | |
|
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2006
diff
changeset
|
188 return AVERROR(ENOMEM); |
| 281 | 189 |
| 190 str->channels[channel].audio_stream_index = st->index; | |
| 191 | |
| 192 fmt = sector[0x13]; | |
| 3514 | 193 st->codec->codec_type = CODEC_TYPE_AUDIO; |
| 194 st->codec->codec_id = CODEC_ID_ADPCM_XA; | |
| 195 st->codec->codec_tag = 0; /* no fourcc */ | |
| 196 st->codec->channels = (fmt&1)?2:1; | |
|
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
197 st->codec->sample_rate = (fmt&4)?18900:37800; |
|
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
198 // st->codec->bit_rate = 0; //FIXME; |
|
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
199 st->codec->block_align = 128; |
| 3513 | 200 |
| 201 av_set_pts_info(st, 64, 128, st->codec->sample_rate); | |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
202 } |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
203 break; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
204 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
205 default: |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
206 /* ignore */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
207 break; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
208 } |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
209 } |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
210 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
211 /* back to the start */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
212 url_fseek(pb, start, SEEK_SET); |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
213 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
214 return 0; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
215 } |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
216 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
217 static int str_read_packet(AVFormatContext *s, |
| 281 | 218 AVPacket *ret_pkt) |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
219 { |
|
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
220 ByteIOContext *pb = s->pb; |
| 2006 | 221 StrDemuxContext *str = s->priv_data; |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
222 unsigned char sector[RAW_CD_SECTOR_SIZE]; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
223 int channel; |
| 281 | 224 AVPacket *pkt; |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
225 |
| 3390 | 226 while (1) { |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
227 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
228 if (get_buffer(pb, sector, RAW_CD_SECTOR_SIZE) != RAW_CD_SECTOR_SIZE) |
|
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
229 return AVERROR(EIO); |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
230 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
231 channel = sector[0x11]; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
232 if (channel >= 32) |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
233 return AVERROR_INVALIDDATA; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
234 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
235 switch (sector[0x12] & CDXA_TYPE_MASK) { |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
236 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
237 case CDXA_TYPE_DATA: |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
238 case CDXA_TYPE_VIDEO: |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
239 /* check if this the video channel we care about */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
240 if (channel == str->video_channel) { |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
241 |
| 1673 | 242 int current_sector = AV_RL16(§or[0x1C]); |
| 243 int sector_count = AV_RL16(§or[0x1E]); | |
| 244 int frame_size = AV_RL32(§or[0x24]); | |
| 3511 | 245 |
| 246 if(!( frame_size>=0 | |
| 247 && current_sector < sector_count | |
| 248 && sector_count*VIDEO_DATA_CHUNK_SIZE >=frame_size)){ | |
| 249 av_log(s, AV_LOG_ERROR, "Invalid parameters %d %d %d\n", current_sector, sector_count, frame_size); | |
| 250 return AVERROR_INVALIDDATA; | |
| 251 } | |
| 252 | |
| 281 | 253 // printf("%d %d %d\n",current_sector,sector_count,frame_size); |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
254 /* if this is the first sector of the frame, allocate a pkt */ |
| 281 | 255 pkt = &str->tmp_pkt; |
| 3511 | 256 |
| 257 if(pkt->size != sector_count*VIDEO_DATA_CHUNK_SIZE){ | |
| 258 if(pkt->data) | |
| 259 av_log(s, AV_LOG_ERROR, "missmatching sector_count\n"); | |
| 260 av_free_packet(pkt); | |
| 261 if (av_new_packet(pkt, sector_count*VIDEO_DATA_CHUNK_SIZE)) | |
|
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
262 return AVERROR(EIO); |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
263 |
| 775 | 264 pkt->pos= url_ftell(pb) - RAW_CD_SECTOR_SIZE; |
| 885 | 265 pkt->stream_index = |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
266 str->channels[channel].video_stream_index; |
| 281 | 267 // pkt->pts = str->pts; |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
268 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
269 /* if there is no audio, adjust the pts after every video |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
270 * frame; assume 15 fps */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
271 if (str->audio_channel != -1) |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
272 str->pts += (90000 / 15); |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
273 } |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
274 |
| 3511 | 275 memcpy(pkt->data + current_sector*VIDEO_DATA_CHUNK_SIZE, |
| 276 sector + VIDEO_DATA_HEADER_SIZE, | |
| 277 VIDEO_DATA_CHUNK_SIZE); | |
| 278 | |
| 281 | 279 if (current_sector == sector_count-1) { |
| 3511 | 280 pkt->size= frame_size; |
| 281 | 281 *ret_pkt = *pkt; |
| 3511 | 282 pkt->data= NULL; |
| 283 pkt->size= -1; | |
| 281 | 284 return 0; |
| 285 } | |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
286 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
287 } |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
288 break; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
289 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
290 case CDXA_TYPE_AUDIO: |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
291 #ifdef PRINTSTUFF |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
292 printf (" dropping audio sector\n"); |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
293 #endif |
| 281 | 294 #if 1 |
| 295 /* check if this the video channel we care about */ | |
| 296 if (channel == str->audio_channel) { | |
| 297 pkt = ret_pkt; | |
| 298 if (av_new_packet(pkt, 2304)) | |
|
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
299 return AVERROR(EIO); |
| 281 | 300 memcpy(pkt->data,sector+24,2304); |
| 301 | |
| 885 | 302 pkt->stream_index = |
| 281 | 303 str->channels[channel].audio_stream_index; |
| 304 //pkt->pts = str->pts; | |
| 305 return 0; | |
| 306 } | |
| 307 #endif | |
| 308 break; | |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
309 default: |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
310 /* drop the sector and move on */ |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
311 #ifdef PRINTSTUFF |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
312 printf (" dropping other sector\n"); |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
313 #endif |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
314 break; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
315 } |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
316 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
317 if (url_feof(pb)) |
|
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
318 return AVERROR(EIO); |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
319 } |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
320 } |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
321 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
322 static int str_read_close(AVFormatContext *s) |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
323 { |
| 2006 | 324 StrDemuxContext *str = s->priv_data; |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
325 |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
326 return 0; |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
327 } |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
328 |
| 1169 | 329 AVInputFormat str_demuxer = { |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
330 "psxstr", |
|
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3390
diff
changeset
|
331 NULL_IF_CONFIG_SMALL("Sony Playstation STR format"), |
|
209
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
332 sizeof(StrDemuxContext), |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
333 str_probe, |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
334 str_read_header, |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
335 str_read_packet, |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
336 str_read_close, |
|
7414bbf64011
first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff
changeset
|
337 }; |
