annotate psxstr.c @ 996:2177aea28f4f libavformat

generic crc calculation code
author michael
date Mon, 06 Mar 2006 14:13:01 +0000
parents edbe5c3717f9
children d89d7ef290da
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
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 885
diff changeset
17 * 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
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
683
095009fc2f35 kill warnings patch by (Mns Rullgrd <mru inprovide com>)
michael
parents: 482
diff changeset
110 #if 0
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
111 static void dump(unsigned char *buf,size_t len)
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
112 {
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
113 int i;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
114 for(i=0;i<len;i++) {
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 281
diff changeset
115 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
116 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
117 if ((i&15)==15) av_log(NULL, AV_LOG_DEBUG, "\n");
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
118 }
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 281
diff changeset
119 av_log(NULL, AV_LOG_DEBUG, "\n");
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
120 }
683
095009fc2f35 kill warnings patch by (Mns Rullgrd <mru inprovide com>)
michael
parents: 482
diff changeset
121 #endif
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
122
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
123 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
124 AVFormatParameters *ap)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
125 {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
126 ByteIOContext *pb = &s->pb;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
127 StrDemuxContext *str = (StrDemuxContext *)s->priv_data;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
128 AVStream *st;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
129 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
130 int start;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
131 int i;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
132 int channel;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
133
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
134 /* initialize context members */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
135 str->pts = 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
136 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
137 str->video_channel = -1;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
138 str->video_chunk = NULL;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
139
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 /* skip over any RIFF header */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
142 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
143 return AVERROR_IO;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
144 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
145 start = RIFF_HEADER_SIZE;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
146 else
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
147 start = 0;
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 url_fseek(pb, start, SEEK_SET);
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
150
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
151 /* 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
152 for (i = 0; i < 32; i++) {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
153 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
154 return AVERROR_IO;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
155
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
156 //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
157
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
158 channel = sector[0x11];
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
159 if (channel >= 32)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
160 return AVERROR_INVALIDDATA;
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 switch (sector[0x12] & CDXA_TYPE_MASK) {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
163
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
164 case CDXA_TYPE_DATA:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
165 case CDXA_TYPE_VIDEO:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
166 /* 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
167 if (str->video_channel == -1) {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
168 /* qualify the magic number */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
169 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
170 break;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
171 str->video_channel = channel;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
172 str->channels[channel].type = STR_VIDEO;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
173 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
174 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
175
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
176 /* allocate a new AVStream */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
177 st = av_new_stream(s, 0);
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
178 if (!st)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
179 return AVERROR_NOMEM;
837
4cf524326a1a set timebase correctly? this thing is always 15fps?
michael
parents: 820
diff changeset
180 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
181
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
182 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
183
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
184 st->codec->codec_type = CODEC_TYPE_VIDEO;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 837
diff changeset
185 st->codec->codec_id = CODEC_ID_MDEC;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
186 st->codec->codec_tag = 0; /* no fourcc */
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
187 st->codec->width = str->channels[channel].width;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
188 st->codec->height = str->channels[channel].height;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
189 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
190 break;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
191
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
192 case CDXA_TYPE_AUDIO:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
193 /* 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
194 if (str->audio_channel == -1) {
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
195 int fmt;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
196 str->audio_channel = channel;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
197 str->channels[channel].type = STR_AUDIO;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 837
diff changeset
198 str->channels[channel].channels =
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
199 (sector[0x13] & 0x01) ? 2 : 1;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 837
diff changeset
200 str->channels[channel].sample_rate =
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
201 (sector[0x13] & 0x04) ? 18900 : 37800;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 837
diff changeset
202 str->channels[channel].bits =
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
203 (sector[0x13] & 0x10) ? 8 : 4;
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
204
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
205 /* allocate a new AVStream */
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
206 st = av_new_stream(s, 0);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
207 if (!st)
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
208 return AVERROR_NOMEM;
837
4cf524326a1a set timebase correctly? this thing is always 15fps?
michael
parents: 820
diff changeset
209 av_set_pts_info(st, 64, 128, str->channels[channel].sample_rate);
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
210
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
211 str->channels[channel].audio_stream_index = st->index;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
212
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
213 fmt = sector[0x13];
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
214 st->codec->codec_type = CODEC_TYPE_AUDIO;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 837
diff changeset
215 st->codec->codec_id = CODEC_ID_ADPCM_XA;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
216 st->codec->codec_tag = 0; /* no fourcc */
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
217 st->codec->channels = (fmt&1)?2:1;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
218 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
219 // 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
220 st->codec->block_align = 128;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
221 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
222 break;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
223
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
224 default:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
225 /* ignore */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
226 break;
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
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
230 if (str->video_channel != -1)
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 281
diff changeset
231 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
232 str->channels[str->video_channel].width,
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
233 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
234 if (str->audio_channel != -1)
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 837
diff changeset
235 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
236 str->audio_channel,
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
237 str->channels[str->audio_channel].sample_rate,
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
238 str->channels[str->audio_channel].channels,
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
239 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
240
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
241 /* back to the start */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
242 url_fseek(pb, start, SEEK_SET);
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
243
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
244 return 0;
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
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
247 static int str_read_packet(AVFormatContext *s,
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
248 AVPacket *ret_pkt)
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
249 {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
250 ByteIOContext *pb = &s->pb;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
251 StrDemuxContext *str = (StrDemuxContext *)s->priv_data;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
252 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
253 int channel;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
254 int packet_read = 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
255 int ret = 0;
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
256 AVPacket *pkt;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
257
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
258 while (!packet_read) {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
259
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
260 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
261 return AVERROR_IO;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
262
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
263 channel = sector[0x11];
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
264 if (channel >= 32)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
265 return AVERROR_INVALIDDATA;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
266
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
267 switch (sector[0x12] & CDXA_TYPE_MASK) {
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 case CDXA_TYPE_DATA:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
270 case CDXA_TYPE_VIDEO:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
271 /* 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
272 if (channel == str->video_channel) {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
273
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
274 int current_sector = LE_16(&sector[0x1C]);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
275 int sector_count = LE_16(&sector[0x1E]);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
276 int frame_size = LE_32(&sector[0x24]);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
277 int bytes_to_copy;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
278 // 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
279 /* 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
280 pkt = &str->tmp_pkt;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
281 if (current_sector == 0) {
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
282 if (av_new_packet(pkt, frame_size))
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 462
diff changeset
283 return AVERROR_IO;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
284
775
c5077fdab490 AVPacket.pos
michael
parents: 683
diff changeset
285 pkt->pos= url_ftell(pb) - RAW_CD_SECTOR_SIZE;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 837
diff changeset
286 pkt->stream_index =
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
287 str->channels[channel].video_stream_index;
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
288 // pkt->pts = str->pts;
209
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 /* 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
291 * frame; assume 15 fps */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
292 if (str->audio_channel != -1)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
293 str->pts += (90000 / 15);
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
294 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
295
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
296 /* load all the constituent chunks in the video packet */
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
297 bytes_to_copy = frame_size - current_sector*VIDEO_DATA_CHUNK_SIZE;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
298 if (bytes_to_copy>0) {
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
299 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
300 memcpy(pkt->data + current_sector*VIDEO_DATA_CHUNK_SIZE,
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
301 sector + VIDEO_DATA_HEADER_SIZE, bytes_to_copy);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
302 }
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
303 if (current_sector == sector_count-1) {
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
304 *ret_pkt = *pkt;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
305 return 0;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
306 }
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
307
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 break;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
310
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
311 case CDXA_TYPE_AUDIO:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
312 #ifdef PRINTSTUFF
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
313 printf (" dropping audio sector\n");
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
314 #endif
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
315 #if 1
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
316 /* check if this the video channel we care about */
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
317 if (channel == str->audio_channel) {
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
318 pkt = ret_pkt;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
319 if (av_new_packet(pkt, 2304))
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 462
diff changeset
320 return AVERROR_IO;
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
321 memcpy(pkt->data,sector+24,2304);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
322
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 837
diff changeset
323 pkt->stream_index =
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
324 str->channels[channel].audio_stream_index;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
325 //pkt->pts = str->pts;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
326 return 0;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
327 }
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
328 #endif
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
329 break;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
330 default:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
331 /* drop the sector and move on */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
332 #ifdef PRINTSTUFF
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
333 printf (" dropping other sector\n");
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
334 #endif
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
335 break;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
336 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
337
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
338 if (url_feof(pb))
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 462
diff changeset
339 return AVERROR_IO;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
340 }
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 return ret;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
343 }
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 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
346 {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
347 StrDemuxContext *str = (StrDemuxContext *)s->priv_data;
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 av_free(str->video_chunk);
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 return 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
352 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
353
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
354 static AVInputFormat str_iformat = {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
355 "psxstr",
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
356 "Sony Playstation STR format",
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
357 sizeof(StrDemuxContext),
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
358 str_probe,
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
359 str_read_header,
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
360 str_read_packet,
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
361 str_read_close,
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
362 };
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 int str_init(void)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
365 {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
366 av_register_input_format(&str_iformat);
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
367 return 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
368 }