Mercurial > libavformat.hg
annotate sol.c @ 5218:ebbaf1c20a84 libavformat
print at debug level the score at which codec probing succedeed
author | bcoudurier |
---|---|
date | Thu, 17 Sep 2009 18:46:50 +0000 |
parents | 77e0c7511d41 |
children | 536e5527c1e0 |
rev | line source |
---|---|
885 | 1 /* |
1415
3b00fb8ef8e4
replace coder/decoder file description in libavformat by muxer/demuxer
aurel
parents:
1358
diff
changeset
|
2 * Sierra SOL demuxer |
4251
77e0c7511d41
cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents:
3967
diff
changeset
|
3 * Copyright Konstantin Shishkov |
533
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 | 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 | 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 | 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 |
3967 | 50 static enum CodecID sol_codec_id(int magic, int type) |
533
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 | 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; |
3967 | 91 unsigned int id, channels, rate, type; |
92 enum CodecID codec; | |
533
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 | 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 | 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 | 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 | 121 st->codec->sample_rate = rate; |
567 | 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 |
1169 | 144 AVInputFormat sol_demuxer = { |
533
59da52e5f5a5
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
145 "sol", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3399
diff
changeset
|
146 NULL_IF_CONFIG_SMALL("Sierra SOL format"), |
533
59da52e5f5a5
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
147 0, |
59da52e5f5a5
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
148 sol_probe, |
59da52e5f5a5
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
149 sol_read_header, |
59da52e5f5a5
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
150 sol_read_packet, |
3484 | 151 NULL, |
533
59da52e5f5a5
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
152 pcm_read_seek, |
59da52e5f5a5
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
153 }; |