annotate sol.c @ 807:2b09fa58db70 libavformat

10l
author alex
date Sat, 02 Jul 2005 22:00:36 +0000
parents c5077fdab490
children feca73904e67
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
1 /*
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
2 * Sierra SOL decoder
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
3 * Copyright Konstantin Shishkov.
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
4 *
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
9 *
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
13 * Lesser General Public License for more details.
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
14 *
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
18 */
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
19
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
20 /*
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
21 * Based on documents from Game Audio Player and own research
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
22 */
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
23
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
24 #include "avformat.h"
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
25 #include "avi.h"
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
26 #include "bswap.h"
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
27
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
28 /* if we don't know the size in advance */
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
29 #define AU_UNKOWN_SIZE ((uint32_t)(~0))
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
30
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
31 static int sol_probe(AVProbeData *p)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
32 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
33 /* check file header */
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
34 uint16_t magic;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
35 if (p->buf_size <= 14)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
36 return 0;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
37 magic=le2me_16(*((uint16_t*)p->buf));
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
38 if ((magic == 0x0B8D || magic == 0x0C0D || magic == 0x0C8D) &&
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
39 p->buf[2] == 'S' && p->buf[3] == 'O' &&
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
40 p->buf[4] == 'L' && p->buf[5] == 0)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
41 return AVPROBE_SCORE_MAX;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
42 else
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
43 return 0;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
44 }
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
45
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
46 #define SOL_DPCM 1
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
47 #define SOL_16BIT 4
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
48 #define SOL_STEREO 16
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
49
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
50 static int sol_codec_id(int magic, int type)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
51 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
52 if (magic == 0x0B8D)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
53 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
54 if (type & SOL_DPCM) return CODEC_ID_SOL_DPCM;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
55 else return CODEC_ID_PCM_U8;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
56 }
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
57 if (type & SOL_DPCM)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
58 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
59 if (type & SOL_16BIT) return CODEC_ID_SOL_DPCM;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
60 else if (magic == 0x0C8D) return CODEC_ID_SOL_DPCM;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
61 else return CODEC_ID_SOL_DPCM;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
62 }
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
63 if (type & SOL_16BIT) return CODEC_ID_PCM_S16LE;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
64 return CODEC_ID_PCM_U8;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
65 }
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
66
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
67 static int sol_codec_type(int magic, int type)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
68 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
69 if (magic == 0x0B8D) return 1;//SOL_DPCM_OLD;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
70 if (type & SOL_DPCM)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
71 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
72 if (type & SOL_16BIT) return 3;//SOL_DPCM_NEW16;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
73 else if (magic == 0x0C8D) return 1;//SOL_DPCM_OLD;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
74 else return 2;//SOL_DPCM_NEW8;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
75 }
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
76 return -1;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
77 }
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
78
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
79 static int sol_channels(int magic, int type)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
80 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
81 if (magic == 0x0B8D || !(type & SOL_STEREO)) return 1;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
82 return 2;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
83 }
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
84
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
85 static int sol_read_header(AVFormatContext *s,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
86 AVFormatParameters *ap)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
87 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
88 int size;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
89 unsigned int magic,tag;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
90 ByteIOContext *pb = &s->pb;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
91 unsigned int id, codec, channels, rate, type;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
92 AVStream *st;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
93
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
94 /* check ".snd" header */
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
95 magic = get_le16(pb);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
96 tag = get_le32(pb);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
97 if (tag != MKTAG('S', 'O', 'L', 0))
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
98 return -1;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
99 rate = get_le16(pb);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
100 type = get_byte(pb);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
101 size = get_le32(pb);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
102 if (magic != 0x0B8D)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
103 get_byte(pb); /* newer SOLs contain padding byte */
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
104
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
105 codec = sol_codec_id(magic, type);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
106 channels = sol_channels(magic, type);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
107
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
108 if (codec == CODEC_ID_SOL_DPCM)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
109 id = sol_codec_type(magic, type);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
110 else id = 0;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
111
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
112 /* now we are ready: build format streams */
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
113 st = av_new_stream(s, 0);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
114 if (!st)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
115 return -1;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
116 st->codec.codec_type = CODEC_TYPE_AUDIO;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
117 st->codec.codec_tag = id;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
118 st->codec.codec_id = codec;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
119 st->codec.channels = channels;
567
23b915bb10f5 set correct timebase
michael
parents: 533
diff changeset
120 st->codec.sample_rate = rate;
23b915bb10f5 set correct timebase
michael
parents: 533
diff changeset
121 av_set_pts_info(st, 64, 1, rate);
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
122 return 0;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
123 }
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
124
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
125 #define MAX_SIZE 4096
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
126
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
127 static int sol_read_packet(AVFormatContext *s,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
128 AVPacket *pkt)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
129 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
130 int ret;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
131
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
132 if (url_feof(&s->pb))
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
133 return -EIO;
775
c5077fdab490 AVPacket.pos
michael
parents: 567
diff changeset
134 ret= av_get_packet(&s->pb, pkt, MAX_SIZE);
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
135 pkt->stream_index = 0;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
136
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
137 /* note: we need to modify the packet size here to handle the last
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
138 packet */
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
139 pkt->size = ret;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
140 return 0;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
141 }
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
142
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
143 static int sol_read_close(AVFormatContext *s)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
144 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
145 return 0;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
146 }
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
147
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
148 static AVInputFormat sol_iformat = {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
149 "sol",
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
150 "Sierra SOL Format",
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
151 0,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
152 sol_probe,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
153 sol_read_header,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
154 sol_read_packet,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
155 sol_read_close,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
156 pcm_read_seek,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
157 };
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
158
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
159 int sol_init(void)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
160 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
161 av_register_input_format(&sol_iformat);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
162 return 0;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
163 }