annotate sol.c @ 2909:840ade0be043 libavformat

cosmetics
author ivo
date Mon, 07 Jan 2008 23:40:04 +0000
parents d52c718e83f9
children 6f61c3b36632
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
1 /*
1415
3b00fb8ef8e4 replace coder/decoder file description in libavformat by muxer/demuxer
aurel
parents: 1358
diff changeset
2 * Sierra SOL demuxer
533
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 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
8 * 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
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
13 * 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
14 * 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
15 * Lesser General Public License for more details.
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
16 *
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 885
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
533
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
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
22 /*
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
23 * 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
24 */
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
25
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
26 #include "avformat.h"
2545
213268d7594e move unrelated functions declarations out of allformats.h
aurel
parents: 2001
diff changeset
27 #include "raw.h"
1172
6a5e58d2114b move common stuff from avienc.c and wav.c to new file riff.c
mru
parents: 1169
diff changeset
28 #include "riff.h"
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
29 #include "bswap.h"
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 /* if we don't know the size in advance */
1885
3ffb9763dfc2 Fix UNKOWN --> UNKNOWN typo
diego
parents: 1787
diff changeset
32 #define AU_UNKNOWN_SIZE ((uint32_t)(~0))
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
33
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
34 static int sol_probe(AVProbeData *p)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
35 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
36 /* check file header */
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
37 uint16_t magic;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
38 magic=le2me_16(*((uint16_t*)p->buf));
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
39 if ((magic == 0x0B8D || magic == 0x0C0D || magic == 0x0C8D) &&
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
40 p->buf[2] == 'S' && p->buf[3] == 'O' &&
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
41 p->buf[4] == 'L' && p->buf[5] == 0)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
42 return AVPROBE_SCORE_MAX;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
43 else
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
44 return 0;
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
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
47 #define SOL_DPCM 1
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
48 #define SOL_16BIT 4
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
49 #define SOL_STEREO 16
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
50
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
51 static int sol_codec_id(int magic, int type)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
52 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
53 if (magic == 0x0B8D)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
54 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
55 if (type & SOL_DPCM) return CODEC_ID_SOL_DPCM;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
56 else return CODEC_ID_PCM_U8;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
57 }
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
58 if (type & SOL_DPCM)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
59 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
60 if (type & SOL_16BIT) return CODEC_ID_SOL_DPCM;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
61 else if (magic == 0x0C8D) return CODEC_ID_SOL_DPCM;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
62 else return CODEC_ID_SOL_DPCM;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
63 }
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
64 if (type & SOL_16BIT) return CODEC_ID_PCM_S16LE;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
65 return CODEC_ID_PCM_U8;
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
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
68 static int sol_codec_type(int magic, int type)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
69 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
70 if (magic == 0x0B8D) return 1;//SOL_DPCM_OLD;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
71 if (type & SOL_DPCM)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
72 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
73 if (type & SOL_16BIT) return 3;//SOL_DPCM_NEW16;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
74 else if (magic == 0x0C8D) return 1;//SOL_DPCM_OLD;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
75 else return 2;//SOL_DPCM_NEW8;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
76 }
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
77 return -1;
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
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
80 static int sol_channels(int magic, int type)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
81 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
82 if (magic == 0x0B8D || !(type & SOL_STEREO)) return 1;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
83 return 2;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
84 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
85
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
86 static int sol_read_header(AVFormatContext *s,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
87 AVFormatParameters *ap)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
88 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
89 int size;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
90 unsigned int magic,tag;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
91 ByteIOContext *pb = s->pb;
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
92 unsigned int id, codec, channels, rate, type;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
93 AVStream *st;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
94
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
95 /* check ".snd" header */
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
96 magic = get_le16(pb);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
97 tag = get_le32(pb);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
98 if (tag != MKTAG('S', 'O', 'L', 0))
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
99 return -1;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
100 rate = get_le16(pb);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
101 type = get_byte(pb);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
102 size = get_le32(pb);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
103 if (magic != 0x0B8D)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
104 get_byte(pb); /* newer SOLs contain padding byte */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
105
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
106 codec = sol_codec_id(magic, type);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
107 channels = sol_channels(magic, type);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
108
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
109 if (codec == CODEC_ID_SOL_DPCM)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
110 id = sol_codec_type(magic, type);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
111 else id = 0;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
112
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
113 /* now we are ready: build format streams */
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
114 st = av_new_stream(s, 0);
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
115 if (!st)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
116 return -1;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
117 st->codec->codec_type = CODEC_TYPE_AUDIO;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
118 st->codec->codec_tag = id;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
119 st->codec->codec_id = codec;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
120 st->codec->channels = channels;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
121 st->codec->sample_rate = rate;
567
23b915bb10f5 set correct timebase
michael
parents: 533
diff changeset
122 av_set_pts_info(st, 64, 1, rate);
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
123 return 0;
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
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
126 #define MAX_SIZE 4096
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
127
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
128 static int sol_read_packet(AVFormatContext *s,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
129 AVPacket *pkt)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
130 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
131 int ret;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
132
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
133 if (url_feof(s->pb))
1787
eb16c64144ee This fixes error handling for BeOS, removing the need for some ifdefs.
mmu_man
parents: 1415
diff changeset
134 return AVERROR(EIO);
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
135 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
136 pkt->stream_index = 0;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
137
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
138 /* 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
139 packet */
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
140 pkt->size = ret;
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
141 return 0;
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
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
144 static int sol_read_close(AVFormatContext *s)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
145 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
146 return 0;
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
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
149 AVInputFormat sol_demuxer = {
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
150 "sol",
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
151 "Sierra SOL Format",
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
152 0,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
153 sol_probe,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
154 sol_read_header,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
155 sol_read_packet,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
156 sol_read_close,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
157 pcm_read_seek,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
158 };