annotate sol.c @ 3783:db75e26da599 libavformat

remove useless assignment (st is never read after this line)
author aurel
date Tue, 26 Aug 2008 20:38:04 +0000
parents 31a0f3b99ef7
children 4fd67f05bad9
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
3286
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 2771
diff changeset
26 #include "libavutil/bswap.h"
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
27 #include "avformat.h"
2545
213268d7594e move unrelated functions declarations out of allformats.h
aurel
parents: 2001
diff changeset
28 #include "raw.h"
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
29
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
30 /* if we don't know the size in advance */
1885
3ffb9763dfc2 Fix UNKOWN --> UNKNOWN typo
diego
parents: 1787
diff changeset
31 #define AU_UNKNOWN_SIZE ((uint32_t)(~0))
533
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 static int sol_probe(AVProbeData *p)
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
34 {
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
35 /* check file header */
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
36 uint16_t magic;
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 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
84
533
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;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
90 ByteIOContext *pb = s->pb;
533
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 */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
104
533
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);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
107
533
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;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
111
533
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;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
116 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
117 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
118 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
119 st->codec->channels = channels;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
120 st->codec->sample_rate = rate;
567
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
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
132 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
133 return AVERROR(EIO);
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
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
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
143 AVInputFormat sol_demuxer = {
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
144 "sol",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3399
diff changeset
145 NULL_IF_CONFIG_SMALL("Sierra SOL format"),
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
146 0,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
147 sol_probe,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
148 sol_read_header,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
149 sol_read_packet,
3484
31a0f3b99ef7 remove useless close funcs
bcoudurier
parents: 3424
diff changeset
150 NULL,
533
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
151 pcm_read_seek,
59da52e5f5a5 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
152 };