annotate psxstr.c @ 592:f28e99a6ac99 libavformat

rv20 demuxing fix
author michael
date Fri, 19 Nov 2004 16:36:30 +0000
parents 0fdc96c2f2fe
children 095009fc2f35
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 *
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
6 * 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
7 * License as published by the Free Software Foundation; either
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
9 *
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
11 * 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
12 * 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
13 * 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
14 *
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
18 */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
19
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 * @file psxstr.c
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
22 * PSX STR file demuxer
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
23 * by Mike Melanson (melanson@pcisys.net)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
24 * 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
25 * 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
26 * 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
27 * RIFF headers, followed by CD sectors.
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
28 */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
29
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
30 #include "avformat.h"
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 //#define PRINTSTUFF
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
33
386
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
34 #define RIFF_TAG MKTAG('R', 'I', 'F', 'F')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
35 #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
36
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
37 #define RAW_CD_SECTOR_SIZE 2352
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
38 #define RAW_CD_SECTOR_DATA_SIZE 2304
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
39 #define VIDEO_DATA_CHUNK_SIZE 0x7E0
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
40 #define VIDEO_DATA_HEADER_SIZE 0x38
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
41 #define RIFF_HEADER_SIZE 0x2C
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
42
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
43 #define CDXA_TYPE_MASK 0x0E
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
44 #define CDXA_TYPE_DATA 0x08
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
45 #define CDXA_TYPE_AUDIO 0x04
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
46 #define CDXA_TYPE_VIDEO 0x02
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
47
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
48 #define STR_MAGIC (0x80010160)
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 typedef struct StrChannel {
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 int type;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
53 #define STR_AUDIO 0
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
54 #define STR_VIDEO 1
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 /* video parameters */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
57 int width;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
58 int height;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
59 int video_stream_index;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
60
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
61 /* audio parameters */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
62 int sample_rate;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
63 int channels;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
64 int bits;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
65 int audio_stream_index;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
66 } StrChannel;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
67
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
68 typedef struct StrDemuxContext {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
69
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
70 /* 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
71 StrChannel channels[32];
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
72
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
73 /* 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
74 int video_channel;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
75 int audio_channel;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
76
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
77 int64_t pts;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
78
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
79 unsigned char *video_chunk;
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
80 AVPacket tmp_pkt;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
81 } StrDemuxContext;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
82
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
83 const static char sync_header[12] = {0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00};
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
84
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
85 static int str_probe(AVProbeData *p)
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 int start;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
88
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
89 /* 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
90 if (p->buf_size < 0x38)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
91 return 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
92
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
93 if ((LE_32(&p->buf[0]) == RIFF_TAG) &&
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
94 (LE_32(&p->buf[8]) == CDXA_TAG)) {
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 /* RIFF header seen; skip 0x2C bytes */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
97 start = RIFF_HEADER_SIZE;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
98 } else
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
99 start = 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
100
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
101 /* look for CD sync header (00, 0xFF x 10, 00) */
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
102 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
103 return 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
104
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
105 /* 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
106 * only return half certainty */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
107 return 50;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
108 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
109
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
110 static void dump(unsigned char *buf,size_t len)
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
111 {
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
112 int i;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
113 for(i=0;i<len;i++) {
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 281
diff changeset
114 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
115 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
116 if ((i&15)==15) av_log(NULL, AV_LOG_DEBUG, "\n");
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
117 }
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 281
diff changeset
118 av_log(NULL, AV_LOG_DEBUG, "\n");
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
119 }
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
120
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
121 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
122 AVFormatParameters *ap)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
123 {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
124 ByteIOContext *pb = &s->pb;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
125 StrDemuxContext *str = (StrDemuxContext *)s->priv_data;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
126 AVStream *st;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
127 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
128 int start;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
129 int i;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
130 int channel;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
131
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
132 /* initialize context members */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
133 str->pts = 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
134 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
135 str->video_channel = -1;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
136 str->video_chunk = NULL;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
137
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 /* skip over any RIFF header */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
140 if (get_buffer(pb, sector, RIFF_HEADER_SIZE) != RIFF_HEADER_SIZE)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
141 return AVERROR_IO;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
142 if (LE_32(&sector[0]) == RIFF_TAG)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
143 start = RIFF_HEADER_SIZE;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
144 else
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
145 start = 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
146
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
147 url_fseek(pb, start, SEEK_SET);
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
148
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
149 /* 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
150 for (i = 0; i < 32; i++) {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
151 if (get_buffer(pb, sector, RAW_CD_SECTOR_SIZE) != RAW_CD_SECTOR_SIZE)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
152 return AVERROR_IO;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
153
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
154 //printf("%02x %02x %02x %02x\n",sector[0x10],sector[0x11],sector[0x12],sector[0x13]);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
155
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
156 channel = sector[0x11];
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
157 if (channel >= 32)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
158 return AVERROR_INVALIDDATA;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
159
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
160 switch (sector[0x12] & CDXA_TYPE_MASK) {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
161
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
162 case CDXA_TYPE_DATA:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
163 case CDXA_TYPE_VIDEO:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
164 /* 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
165 if (str->video_channel == -1) {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
166 /* qualify the magic number */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
167 if (LE_32(&sector[0x18]) != STR_MAGIC)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
168 break;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
169 str->video_channel = channel;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
170 str->channels[channel].type = STR_VIDEO;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
171 str->channels[channel].width = LE_16(&sector[0x28]);
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
172 str->channels[channel].height = LE_16(&sector[0x2A]);
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
173
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
174 /* allocate a new AVStream */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
175 st = av_new_stream(s, 0);
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
176 if (!st)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
177 return AVERROR_NOMEM;
462
b69898ffc92a move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents: 386
diff changeset
178 /* set the pts reference (1 pts = 1/90000) */
b69898ffc92a move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents: 386
diff changeset
179 av_set_pts_info(st, 33, 1, 90000);
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
180
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
181 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
182
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
183 st->codec.codec_type = CODEC_TYPE_VIDEO;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
184 st->codec.codec_id = CODEC_ID_MDEC;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
185 st->codec.codec_tag = 0; /* no fourcc */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
186 st->codec.width = str->channels[channel].width;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
187 st->codec.height = str->channels[channel].height;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
188 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
189 break;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
190
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
191 case CDXA_TYPE_AUDIO:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
192 /* 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
193 if (str->audio_channel == -1) {
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
194 int fmt;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
195 str->audio_channel = channel;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
196 str->channels[channel].type = STR_AUDIO;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
197 str->channels[channel].channels =
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
198 (sector[0x13] & 0x01) ? 2 : 1;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
199 str->channels[channel].sample_rate =
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
200 (sector[0x13] & 0x04) ? 18900 : 37800;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
201 str->channels[channel].bits =
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
202 (sector[0x13] & 0x10) ? 8 : 4;
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
203
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
204 /* allocate a new AVStream */
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
205 st = av_new_stream(s, 0);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
206 if (!st)
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
207 return AVERROR_NOMEM;
462
b69898ffc92a move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents: 386
diff changeset
208 av_set_pts_info(st, 33, 1, 90000);
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
209
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
210 str->channels[channel].audio_stream_index = st->index;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
211
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
212 fmt = sector[0x13];
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
213 st->codec.codec_type = CODEC_TYPE_AUDIO;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
214 st->codec.codec_id = CODEC_ID_ADPCM_XA;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
215 st->codec.codec_tag = 0; /* no fourcc */
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
216 st->codec.channels = (fmt&1)?2:1;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
217 st->codec.sample_rate = (fmt&4)?18900:37800;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
218 // st->codec.bit_rate = 0; //FIXME;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
219 st->codec.block_align = 128;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
220 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
221 break;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
222
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
223 default:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
224 /* ignore */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
225 break;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
226 }
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
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
229 if (str->video_channel != -1)
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 281
diff changeset
230 av_log (s, AV_LOG_DEBUG, " video channel = %d, %d x %d %d\n", str->video_channel,
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
231 str->channels[str->video_channel].width,
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
232 str->channels[str->video_channel].height,str->channels[str->video_channel].video_stream_index);
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
233 if (str->audio_channel != -1)
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 281
diff changeset
234 av_log (s, AV_LOG_DEBUG, " audio channel = %d, %d Hz, %d channels, %d bits/sample %d\n",
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
235 str->audio_channel,
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
236 str->channels[str->audio_channel].sample_rate,
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
237 str->channels[str->audio_channel].channels,
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
238 str->channels[str->audio_channel].bits,str->channels[str->audio_channel].audio_stream_index);
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
239
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
240 /* back to the start */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
241 url_fseek(pb, start, SEEK_SET);
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
242
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
243 return 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
244 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
245
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
246 static int str_read_packet(AVFormatContext *s,
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
247 AVPacket *ret_pkt)
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
248 {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
249 ByteIOContext *pb = &s->pb;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
250 StrDemuxContext *str = (StrDemuxContext *)s->priv_data;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
251 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
252 int channel;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
253 int packet_read = 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
254 int ret = 0;
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
255 AVPacket *pkt;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
256
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
257 while (!packet_read) {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
258
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
259 if (get_buffer(pb, sector, RAW_CD_SECTOR_SIZE) != RAW_CD_SECTOR_SIZE)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 462
diff changeset
260 return AVERROR_IO;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
261
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
262 channel = sector[0x11];
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
263 if (channel >= 32)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
264 return AVERROR_INVALIDDATA;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
265
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
266 switch (sector[0x12] & CDXA_TYPE_MASK) {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
267
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
268 case CDXA_TYPE_DATA:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
269 case CDXA_TYPE_VIDEO:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
270 /* 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
271 if (channel == str->video_channel) {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
272
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
273 int current_sector = LE_16(&sector[0x1C]);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
274 int sector_count = LE_16(&sector[0x1E]);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
275 int frame_size = LE_32(&sector[0x24]);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
276 int bytes_to_copy;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
277 // 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
278 /* if this is the first sector of the frame, allocate a pkt */
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
279 pkt = &str->tmp_pkt;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
280 if (current_sector == 0) {
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
281 if (av_new_packet(pkt, frame_size))
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 462
diff changeset
282 return AVERROR_IO;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
283
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
284 pkt->stream_index =
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
285 str->channels[channel].video_stream_index;
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
286 // pkt->pts = str->pts;
209
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 /* 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
289 * frame; assume 15 fps */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
290 if (str->audio_channel != -1)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
291 str->pts += (90000 / 15);
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
292 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
293
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
294 /* load all the constituent chunks in the video packet */
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
295 bytes_to_copy = frame_size - current_sector*VIDEO_DATA_CHUNK_SIZE;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
296 if (bytes_to_copy>0) {
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
297 if (bytes_to_copy>VIDEO_DATA_CHUNK_SIZE) bytes_to_copy=VIDEO_DATA_CHUNK_SIZE;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
298 memcpy(pkt->data + current_sector*VIDEO_DATA_CHUNK_SIZE,
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
299 sector + VIDEO_DATA_HEADER_SIZE, bytes_to_copy);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
300 }
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
301 if (current_sector == sector_count-1) {
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
302 *ret_pkt = *pkt;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
303 return 0;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
304 }
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
305
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
306 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
307 break;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
308
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
309 case CDXA_TYPE_AUDIO:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
310 #ifdef PRINTSTUFF
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
311 printf (" dropping audio sector\n");
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
312 #endif
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
313 #if 1
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
314 /* check if this the video channel we care about */
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
315 if (channel == str->audio_channel) {
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
316 pkt = ret_pkt;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
317 if (av_new_packet(pkt, 2304))
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 462
diff changeset
318 return AVERROR_IO;
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
319 memcpy(pkt->data,sector+24,2304);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
320
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
321 pkt->stream_index =
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
322 str->channels[channel].audio_stream_index;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
323 //pkt->pts = str->pts;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
324 return 0;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
325 }
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
326 #endif
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
327 break;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
328 default:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
329 /* drop the sector and move on */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
330 #ifdef PRINTSTUFF
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
331 printf (" dropping other sector\n");
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
332 #endif
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
333 break;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
334 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
335
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
336 if (url_feof(pb))
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 462
diff changeset
337 return AVERROR_IO;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
338 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
339
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
340 return ret;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
341 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
342
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
343 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
344 {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
345 StrDemuxContext *str = (StrDemuxContext *)s->priv_data;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
346
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
347 av_free(str->video_chunk);
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
348
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
349 return 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
350 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
351
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
352 static AVInputFormat str_iformat = {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
353 "psxstr",
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
354 "Sony Playstation STR format",
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
355 sizeof(StrDemuxContext),
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
356 str_probe,
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
357 str_read_header,
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
358 str_read_packet,
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
359 str_read_close,
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
360 };
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
361
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
362 int str_init(void)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
363 {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
364 av_register_input_format(&str_iformat);
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
365 return 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
366 }