Mercurial > libavcodec.hg
annotate ws-snd1.c @ 11358:a1376a6f9af1 libavcodec
AAC: Mark predictor functions av_always_inline.
This results in a 50% speedup on main profile with no increase in binary size.
author | alexc |
---|---|
date | Thu, 04 Mar 2010 04:58:43 +0000 |
parents | 54bc8a2727b0 |
children | 8a4984c5cacc |
rev | line source |
---|---|
2585 | 1 /* |
2 * Westwood SNDx codecs | |
3 * Copyright (c) 2005 Konstantin Shishkov | |
4 * | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
2585 | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
2585 | 11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
2585 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2967
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2585 | 20 */ |
8573
2acf0ae7b041
Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents:
7451
diff
changeset
|
21 |
2acf0ae7b041
Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents:
7451
diff
changeset
|
22 #include "libavutil/intreadwrite.h" |
2585 | 23 #include "avcodec.h" |
24 | |
25 /** | |
8718
e9d9d946f213
Use full internal pathname in doxygen @file directives.
diego
parents:
8673
diff
changeset
|
26 * @file libavcodec/ws-snd1.c |
2585 | 27 * Westwood SNDx codecs. |
28 * | |
29 * Reference documents about VQA format and its audio codecs | |
30 * can be found here: | |
31 * http://www.multimedia.cx | |
32 */ | |
33 | |
34 static const char ws_adpcm_2bit[] = { -2, -1, 0, 1}; | |
35 static const char ws_adpcm_4bit[] = { | |
36 -9, -8, -6, -5, -4, -3, -2, -1, | |
37 0, 1, 2, 3, 4, 5, 6, 8 }; | |
38 | |
39 #define CLIP8(a) if(a>127)a=127;if(a<-128)a=-128; | |
40 | |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6299
diff
changeset
|
41 static av_cold int ws_snd_decode_init(AVCodecContext * avctx) |
2585 | 42 { |
43 // WSSNDContext *c = avctx->priv_data; | |
2967 | 44 |
7451
85ab7655ad4d
Modify all codecs to report their supported input and output sample format(s).
pross
parents:
7040
diff
changeset
|
45 avctx->sample_fmt = SAMPLE_FMT_S16; |
2585 | 46 return 0; |
47 } | |
48 | |
49 static int ws_snd_decode_frame(AVCodecContext *avctx, | |
50 void *data, int *data_size, | |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
51 AVPacket *avpkt) |
2585 | 52 { |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
53 const uint8_t *buf = avpkt->data; |
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
54 int buf_size = avpkt->size; |
2585 | 55 // WSSNDContext *c = avctx->priv_data; |
2967 | 56 |
2585 | 57 int in_size, out_size; |
58 int sample = 0; | |
59 int i; | |
60 short *samples = data; | |
2967 | 61 |
2585 | 62 if (!buf_size) |
63 return 0; | |
64 | |
4364 | 65 out_size = AV_RL16(&buf[0]); |
2585 | 66 *data_size = out_size * 2; |
4364 | 67 in_size = AV_RL16(&buf[2]); |
2585 | 68 buf += 4; |
2967 | 69 |
5674
ca944f1db2b3
Add checks on input/output buffers size for some audio decoders
kostya
parents:
4364
diff
changeset
|
70 if (out_size > *data_size) { |
ca944f1db2b3
Add checks on input/output buffers size for some audio decoders
kostya
parents:
4364
diff
changeset
|
71 av_log(avctx, AV_LOG_ERROR, "Frame is too large to fit in buffer\n"); |
ca944f1db2b3
Add checks on input/output buffers size for some audio decoders
kostya
parents:
4364
diff
changeset
|
72 return -1; |
ca944f1db2b3
Add checks on input/output buffers size for some audio decoders
kostya
parents:
4364
diff
changeset
|
73 } |
ca944f1db2b3
Add checks on input/output buffers size for some audio decoders
kostya
parents:
4364
diff
changeset
|
74 if (in_size > buf_size) { |
ca944f1db2b3
Add checks on input/output buffers size for some audio decoders
kostya
parents:
4364
diff
changeset
|
75 av_log(avctx, AV_LOG_ERROR, "Frame data is larger than input buffer\n"); |
ca944f1db2b3
Add checks on input/output buffers size for some audio decoders
kostya
parents:
4364
diff
changeset
|
76 return -1; |
ca944f1db2b3
Add checks on input/output buffers size for some audio decoders
kostya
parents:
4364
diff
changeset
|
77 } |
2585 | 78 if (in_size == out_size) { |
79 for (i = 0; i < out_size; i++) | |
80 *samples++ = (*buf++ - 0x80) << 8; | |
81 return buf_size; | |
82 } | |
2967 | 83 |
2585 | 84 while (out_size > 0) { |
85 int code; | |
86 uint8_t count; | |
87 code = (*buf) >> 6; | |
88 count = (*buf) & 0x3F; | |
89 buf++; | |
90 switch(code) { | |
91 case 0: /* ADPCM 2-bit */ | |
92 for (count++; count > 0; count--) { | |
93 code = *buf++; | |
94 sample += ws_adpcm_2bit[code & 0x3]; | |
95 CLIP8(sample); | |
96 *samples++ = sample << 8; | |
97 sample += ws_adpcm_2bit[(code >> 2) & 0x3]; | |
98 CLIP8(sample); | |
99 *samples++ = sample << 8; | |
100 sample += ws_adpcm_2bit[(code >> 4) & 0x3]; | |
101 CLIP8(sample); | |
102 *samples++ = sample << 8; | |
103 sample += ws_adpcm_2bit[(code >> 6) & 0x3]; | |
104 CLIP8(sample); | |
105 *samples++ = sample << 8; | |
106 out_size -= 4; | |
107 } | |
108 break; | |
109 case 1: /* ADPCM 4-bit */ | |
110 for (count++; count > 0; count--) { | |
111 code = *buf++; | |
112 sample += ws_adpcm_4bit[code & 0xF]; | |
113 CLIP8(sample); | |
114 *samples++ = sample << 8; | |
115 sample += ws_adpcm_4bit[code >> 4]; | |
116 CLIP8(sample); | |
117 *samples++ = sample << 8; | |
118 out_size -= 2; | |
119 } | |
120 break; | |
121 case 2: /* no compression */ | |
122 if (count & 0x20) { /* big delta */ | |
123 char t; | |
124 t = count; | |
125 t <<= 3; | |
126 sample += t >> 3; | |
127 *samples++ = sample << 8; | |
128 out_size--; | |
129 } else { /* copy */ | |
130 for (count++; count > 0; count--) { | |
131 *samples++ = (*buf++ - 0x80) << 8; | |
132 out_size--; | |
133 } | |
134 sample = buf[-1] - 0x80; | |
135 } | |
136 break; | |
137 default: /* run */ | |
138 for(count++; count > 0; count--) { | |
139 *samples++ = sample << 8; | |
140 out_size--; | |
141 } | |
142 } | |
143 } | |
2967 | 144 |
2585 | 145 return buf_size; |
146 } | |
147 | |
148 AVCodec ws_snd1_decoder = { | |
149 "ws_snd1", | |
150 CODEC_TYPE_AUDIO, | |
151 CODEC_ID_WESTWOOD_SND1, | |
4019 | 152 0, |
2585 | 153 ws_snd_decode_init, |
154 NULL, | |
155 NULL, | |
156 ws_snd_decode_frame, | |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6717
diff
changeset
|
157 .long_name = NULL_IF_CONFIG_SMALL("Westwood Audio (SND1)"), |
2585 | 158 }; |