annotate psxstr.c @ 370:845f9de2c883 libavformat

av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
author michael
date Wed, 03 Mar 2004 15:41:21 +0000
parents ee009afcc2a1
children c152849ee643
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
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
34 #define LE_16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
35 #define LE_32(x) ((((uint8_t*)(x))[3] << 24) | \
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
36 (((uint8_t*)(x))[2] << 16) | \
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
37 (((uint8_t*)(x))[1] << 8) | \
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
38 ((uint8_t*)(x))[0])
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
39
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
40 #define FOURCC_TAG( ch0, ch1, ch2, ch3 ) \
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
41 ( (long)(unsigned char)(ch0) | \
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
42 ( (long)(unsigned char)(ch1) << 8 ) | \
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
43 ( (long)(unsigned char)(ch2) << 16 ) | \
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
44 ( (long)(unsigned char)(ch3) << 24 ) )
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
45
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
46 #define RIFF_TAG FOURCC_TAG('R', 'I', 'F', 'F')
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
47 #define CDXA_TAG FOURCC_TAG('C', 'D', 'X', 'A')
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
48
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
49 #define RAW_CD_SECTOR_SIZE 2352
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
50 #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
51 #define VIDEO_DATA_CHUNK_SIZE 0x7E0
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
52 #define VIDEO_DATA_HEADER_SIZE 0x38
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
53 #define RIFF_HEADER_SIZE 0x2C
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
54
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
55 #define CDXA_TYPE_MASK 0x0E
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
56 #define CDXA_TYPE_DATA 0x08
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
57 #define CDXA_TYPE_AUDIO 0x04
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
58 #define CDXA_TYPE_VIDEO 0x02
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
59
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
60 #define STR_MAGIC (0x80010160)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
61
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
62 typedef struct StrChannel {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
63
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
64 int type;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
65 #define STR_AUDIO 0
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
66 #define STR_VIDEO 1
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 /* video parameters */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
69 int width;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
70 int height;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
71 int video_stream_index;
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 /* audio parameters */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
74 int sample_rate;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
75 int channels;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
76 int bits;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
77 int audio_stream_index;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
78 } StrChannel;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
79
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
80 typedef struct StrDemuxContext {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
81
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
82 /* 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
83 StrChannel channels[32];
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
84
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
85 /* 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
86 int video_channel;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
87 int audio_channel;
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 int64_t pts;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
90
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
91 unsigned char *video_chunk;
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
92 AVPacket tmp_pkt;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
93 } StrDemuxContext;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
94
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
95 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
96
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
97 static int str_probe(AVProbeData *p)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
98 {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
99 int start;
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 /* 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
102 if (p->buf_size < 0x38)
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 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
106 (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
107
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
108 /* RIFF header seen; skip 0x2C bytes */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
109 start = RIFF_HEADER_SIZE;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
110 } else
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
111 start = 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
112
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
113 /* look for CD sync header (00, 0xFF x 10, 00) */
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
114 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
115 return 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
116
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
117 /* 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
118 * only return half certainty */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
119 return 50;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
120 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
121
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
122 static void dump(unsigned char *buf,size_t len)
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
123 {
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
124 int i;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
125 for(i=0;i<len;i++) {
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 281
diff changeset
126 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
127 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
128 if ((i&15)==15) av_log(NULL, AV_LOG_DEBUG, "\n");
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
129 }
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 281
diff changeset
130 av_log(NULL, AV_LOG_DEBUG, "\n");
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
131 }
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
132
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
133 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
134 AVFormatParameters *ap)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
135 {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
136 ByteIOContext *pb = &s->pb;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
137 StrDemuxContext *str = (StrDemuxContext *)s->priv_data;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
138 AVStream *st;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
139 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
140 int start;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
141 int i;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
142 int channel;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
143
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
144 /* initialize context members */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
145 str->pts = 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
146 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
147 str->video_channel = -1;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
148 str->video_chunk = NULL;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
149
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
150 /* set the pts reference (1 pts = 1/90000) */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
151 s->pts_num = 1;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
152 s->pts_den = 90000;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
153
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
154 /* skip over any RIFF header */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
155 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
156 return AVERROR_IO;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
157 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
158 start = RIFF_HEADER_SIZE;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
159 else
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
160 start = 0;
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 url_fseek(pb, start, SEEK_SET);
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 /* 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
165 for (i = 0; i < 32; i++) {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
166 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
167 return AVERROR_IO;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
168
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
169 //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
170
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
171 channel = sector[0x11];
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
172 if (channel >= 32)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
173 return AVERROR_INVALIDDATA;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
174
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
175 switch (sector[0x12] & CDXA_TYPE_MASK) {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
176
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
177 case CDXA_TYPE_DATA:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
178 case CDXA_TYPE_VIDEO:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
179 /* 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
180 if (str->video_channel == -1) {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
181 /* qualify the magic number */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
182 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
183 break;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
184 str->video_channel = channel;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
185 str->channels[channel].type = STR_VIDEO;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
186 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
187 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
188
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
189 /* allocate a new AVStream */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
190 st = av_new_stream(s, 0);
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
191 if (!st)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
192 return AVERROR_NOMEM;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
193
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
194 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
195
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
196 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
197 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
198 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
199 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
200 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
201 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
202 break;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
203
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
204 case CDXA_TYPE_AUDIO:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
205 /* 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
206 if (str->audio_channel == -1) {
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
207 int fmt;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
208 str->audio_channel = channel;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
209 str->channels[channel].type = STR_AUDIO;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
210 str->channels[channel].channels =
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
211 (sector[0x13] & 0x01) ? 2 : 1;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
212 str->channels[channel].sample_rate =
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
213 (sector[0x13] & 0x04) ? 18900 : 37800;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
214 str->channels[channel].bits =
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
215 (sector[0x13] & 0x10) ? 8 : 4;
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
216
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
217 /* allocate a new AVStream */
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
218 st = av_new_stream(s, 0);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
219 if (!st)
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
220 return AVERROR_NOMEM;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
221
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
222 str->channels[channel].audio_stream_index = st->index;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
223
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
224 fmt = sector[0x13];
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
225 st->codec.codec_type = CODEC_TYPE_AUDIO;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
226 st->codec.codec_id = CODEC_ID_ADPCM_XA;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
227 st->codec.codec_tag = 0; /* no fourcc */
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
228 st->codec.channels = (fmt&1)?2:1;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
229 st->codec.sample_rate = (fmt&4)?18900:37800;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
230 // st->codec.bit_rate = 0; //FIXME;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
231 st->codec.block_align = 128;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
232 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
233 break;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
234
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
235 default:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
236 /* ignore */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
237 break;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
238 }
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
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
241 if (str->video_channel != -1)
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 281
diff changeset
242 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
243 str->channels[str->video_channel].width,
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
244 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
245 if (str->audio_channel != -1)
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 281
diff changeset
246 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
247 str->audio_channel,
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
248 str->channels[str->audio_channel].sample_rate,
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
249 str->channels[str->audio_channel].channels,
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
250 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
251
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
252 /* back to the start */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
253 url_fseek(pb, start, SEEK_SET);
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
254
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
255 return 0;
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
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
258 static int str_read_packet(AVFormatContext *s,
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
259 AVPacket *ret_pkt)
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
260 {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
261 ByteIOContext *pb = &s->pb;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
262 StrDemuxContext *str = (StrDemuxContext *)s->priv_data;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
263 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
264 int channel;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
265 int packet_read = 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
266 int ret = 0;
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
267 AVPacket *pkt;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
268
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
269 while (!packet_read) {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
270
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
271 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
272 return -EIO;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
273
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
274 channel = sector[0x11];
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
275 if (channel >= 32)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
276 return AVERROR_INVALIDDATA;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
277
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
278 switch (sector[0x12] & CDXA_TYPE_MASK) {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
279
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
280 case CDXA_TYPE_DATA:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
281 case CDXA_TYPE_VIDEO:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
282 /* 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
283 if (channel == str->video_channel) {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
284
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
285 int current_sector = LE_16(&sector[0x1C]);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
286 int sector_count = LE_16(&sector[0x1E]);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
287 int frame_size = LE_32(&sector[0x24]);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
288 int bytes_to_copy;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
289 // 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
290 /* 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
291 pkt = &str->tmp_pkt;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
292 if (current_sector == 0) {
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
293 if (av_new_packet(pkt, frame_size))
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
294 return -EIO;
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 pkt->stream_index =
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
297 str->channels[channel].video_stream_index;
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
298 // pkt->pts = str->pts;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
299
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
300 /* 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
301 * frame; assume 15 fps */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
302 if (str->audio_channel != -1)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
303 str->pts += (90000 / 15);
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
304 }
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 /* load all the constituent chunks in the video packet */
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
307 bytes_to_copy = frame_size - current_sector*VIDEO_DATA_CHUNK_SIZE;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
308 if (bytes_to_copy>0) {
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
309 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
310 memcpy(pkt->data + current_sector*VIDEO_DATA_CHUNK_SIZE,
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
311 sector + VIDEO_DATA_HEADER_SIZE, bytes_to_copy);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
312 }
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
313 if (current_sector == sector_count-1) {
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
314 *ret_pkt = *pkt;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
315 return 0;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
316 }
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
317
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
318 }
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
319 break;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
320
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
321 case CDXA_TYPE_AUDIO:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
322 #ifdef PRINTSTUFF
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
323 printf (" dropping audio sector\n");
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
324 #endif
281
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
325 #if 1
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
326 /* check if this the video channel we care about */
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
327 if (channel == str->audio_channel) {
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
328 pkt = ret_pkt;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
329 if (av_new_packet(pkt, 2304))
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
330 return -EIO;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
331 memcpy(pkt->data,sector+24,2304);
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
332
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
333 pkt->stream_index =
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
334 str->channels[channel].audio_stream_index;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
335 //pkt->pts = str->pts;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
336 return 0;
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
337 }
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
338 #endif
ee009afcc2a1 hook up the XA ADPCM decoder
melanson
parents: 209
diff changeset
339 break;
209
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
340 default:
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
341 /* drop the sector and move on */
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
342 #ifdef PRINTSTUFF
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
343 printf (" dropping other sector\n");
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
344 #endif
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
345 break;
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
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
348 if (url_feof(pb))
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
349 return -EIO;
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 return ret;
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
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
355 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
356 {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
357 StrDemuxContext *str = (StrDemuxContext *)s->priv_data;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
358
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
359 av_free(str->video_chunk);
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 return 0;
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 static AVInputFormat str_iformat = {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
365 "psxstr",
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
366 "Sony Playstation STR format",
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
367 sizeof(StrDemuxContext),
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
368 str_probe,
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
369 str_read_header,
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
370 str_read_packet,
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
371 str_read_close,
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
372 };
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
373
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
374 int str_init(void)
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
375 {
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
376 av_register_input_format(&str_iformat);
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
377 return 0;
7414bbf64011 first pass at PSX STR demuxer; does not yet interact correctly with MDEC
tmmm
parents:
diff changeset
378 }