Mercurial > libavcodec.hg
annotate faad.c @ 2193:ea7715935e55 libavcodec
5% faster decode_subband()
a little cleanup
author | michael |
---|---|
date | Fri, 27 Aug 2004 20:15:32 +0000 |
parents | c28b03fea50f |
children | e25782262d7d |
rev | line source |
---|---|
1245 | 1 /* |
2 * Faad decoder | |
3 * Copyright (c) 2003 Zdenek Kabelac. | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
4 * Copyright (c) 2004 Thomas Raivio. |
1245 | 5 * |
6 * This library is free software; you can redistribute it and/or | |
7 * modify it under the terms of the GNU Lesser General Public | |
8 * License as published by the Free Software Foundation; either | |
9 * version 2 of the License, or (at your option) any later version. | |
10 * | |
11 * This library is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * Lesser General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Lesser General Public | |
17 * License along with this library; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 */ | |
20 | |
21 /** | |
22 * @file faad.c | |
23 * AAC decoder. | |
24 * | |
25 * still a bit unfinished - but it plays something | |
26 */ | |
27 | |
28 #include "avcodec.h" | |
29 #include "faad.h" | |
30 | |
2061
c28b03fea50f
Building with faad2-cvs fix by ("Steven M. Schultz" <sms at 2bsd dot com>)
michael
parents:
2059
diff
changeset
|
31 #ifndef FAADAPI |
c28b03fea50f
Building with faad2-cvs fix by ("Steven M. Schultz" <sms at 2bsd dot com>)
michael
parents:
2059
diff
changeset
|
32 #define FAADAPI |
c28b03fea50f
Building with faad2-cvs fix by ("Steven M. Schultz" <sms at 2bsd dot com>)
michael
parents:
2059
diff
changeset
|
33 #endif |
c28b03fea50f
Building with faad2-cvs fix by ("Steven M. Schultz" <sms at 2bsd dot com>)
michael
parents:
2059
diff
changeset
|
34 |
1245 | 35 /* |
36 * when CONFIG_FAADBIN is defined the libfaad will be opened at runtime | |
37 */ | |
38 //#undef CONFIG_FAADBIN | |
39 //#define CONFIG_FAADBIN | |
40 | |
41 #ifdef CONFIG_FAADBIN | |
42 #include <dlfcn.h> | |
43 static const char* libfaadname = "libfaad.so.0"; | |
44 #else | |
45 #define dlopen(a) | |
46 #define dlclose(a) | |
47 #endif | |
48 | |
49 typedef struct { | |
50 void* handle; /* dlopen handle */ | |
51 void* faac_handle; /* FAAD library handle */ | |
52 int frame_size; | |
53 int sample_size; | |
54 int flags; | |
55 | |
56 /* faad calls */ | |
57 faacDecHandle FAADAPI (*faacDecOpen)(void); | |
58 faacDecConfigurationPtr FAADAPI (*faacDecGetCurrentConfiguration)(faacDecHandle hDecoder); | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
59 #ifndef FAAD2_VERSION |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
60 int FAADAPI (*faacDecSetConfiguration)(faacDecHandle hDecoder, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
61 faacDecConfigurationPtr config); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
62 int FAADAPI (*faacDecInit)(faacDecHandle hDecoder, |
1245 | 63 unsigned char *buffer, |
64 unsigned long *samplerate, | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
65 unsigned long *channels); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
66 int FAADAPI (*faacDecInit2)(faacDecHandle hDecoder, unsigned char *pBuffer, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
67 unsigned long SizeOfDecoderSpecificInfo, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
68 unsigned long *samplerate, unsigned long *channels); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
69 int FAADAPI (*faacDecDecode)(faacDecHandle hDecoder, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
70 unsigned char *buffer, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
71 unsigned long *bytesconsumed, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
72 short *sample_buffer, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
73 unsigned long *samples); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
74 #else |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
75 unsigned char FAADAPI (*faacDecSetConfiguration)(faacDecHandle hDecoder, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
76 faacDecConfigurationPtr config); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
77 long FAADAPI (*faacDecInit)(faacDecHandle hDecoder, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
78 unsigned char *buffer, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
79 unsigned long buffer_size, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
80 unsigned long *samplerate, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
81 unsigned char *channels); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
82 char FAADAPI (*faacDecInit2)(faacDecHandle hDecoder, unsigned char *pBuffer, |
1245 | 83 unsigned long SizeOfDecoderSpecificInfo, |
84 unsigned long *samplerate, unsigned char *channels); | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
85 void *FAADAPI (*faacDecDecode)(faacDecHandle hDecoder, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
86 faacDecFrameInfo *hInfo, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
87 unsigned char *buffer, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
88 unsigned long buffer_size); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
89 unsigned char* FAADAPI (*faacDecGetErrorMessage)(unsigned char errcode); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
90 #endif |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
91 |
1245 | 92 void FAADAPI (*faacDecClose)(faacDecHandle hDecoder); |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
93 |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
94 |
1245 | 95 } FAACContext; |
96 | |
97 static const unsigned long faac_srates[] = | |
98 { | |
99 96000, 88200, 64000, 48000, 44100, 32000, | |
100 24000, 22050, 16000, 12000, 11025, 8000 | |
101 }; | |
102 | |
103 static int faac_init_mp4(AVCodecContext *avctx) | |
104 { | |
105 FAACContext *s = (FAACContext *) avctx->priv_data; | |
106 unsigned long samplerate; | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
107 #ifndef FAAD2_VERSION |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
108 unsigned long channels; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
109 #else |
1245 | 110 unsigned char channels; |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
111 #endif |
1245 | 112 int r = 0; |
113 | |
114 if (avctx->extradata) | |
115 r = s->faacDecInit2(s->faac_handle, (uint8_t*) avctx->extradata, | |
116 avctx->extradata_size, | |
117 &samplerate, &channels); | |
118 // else r = s->faacDecInit(s->faac_handle ... ); | |
119 | |
120 if (r < 0) | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
121 av_log(avctx, AV_LOG_ERROR, "faacDecInit2 failed r:%d sr:%ld ch:%ld s:%d\n", |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
122 r, samplerate, (long)channels, avctx->extradata_size); |
2059
ad972ab280bc
sample_rate and channels in aac audio patch by (Luca Abeni <lucabe72 at email dot it>)
michael
parents:
1929
diff
changeset
|
123 avctx->sample_rate = samplerate; |
ad972ab280bc
sample_rate and channels in aac audio patch by (Luca Abeni <lucabe72 at email dot it>)
michael
parents:
1929
diff
changeset
|
124 avctx->channels = channels; |
ad972ab280bc
sample_rate and channels in aac audio patch by (Luca Abeni <lucabe72 at email dot it>)
michael
parents:
1929
diff
changeset
|
125 |
1245 | 126 return r; |
127 } | |
128 | |
129 static int faac_init_aac(AVCodecContext *avctx) | |
130 { | |
131 return 0; | |
132 } | |
133 | |
134 static int faac_decode_frame(AVCodecContext *avctx, | |
135 void *data, int *data_size, | |
136 uint8_t *buf, int buf_size) | |
137 { | |
138 FAACContext *s = (FAACContext *) avctx->priv_data; | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
139 #ifndef FAAD2_VERSION |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
140 unsigned long bytesconsumed; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
141 short *sample_buffer = NULL; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
142 unsigned long samples; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
143 int out; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
144 #else |
1245 | 145 faacDecFrameInfo frame_info; |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
146 void *out; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
147 #endif |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
148 if(buf_size == 0) |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
149 return 0; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
150 #ifndef FAAD2_VERSION |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
151 out = s->faacDecDecode(s->faac_handle, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
152 (unsigned char*)buf, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
153 &bytesconsumed, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
154 data, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
155 &samples); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
156 samples *= s->sample_size; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
157 if (data_size) |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
158 *data_size = samples; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
159 return (buf_size < (int)bytesconsumed) |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
160 ? buf_size : (int)bytesconsumed; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
161 #else |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
162 |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
163 out = s->faacDecDecode(s->faac_handle, &frame_info, (unsigned char*)buf, (unsigned long)buf_size); |
1245 | 164 |
165 if (frame_info.error > 0) { | |
1602
fdb8244da1e5
av_log patch(2 of ?) by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1245
diff
changeset
|
166 av_log(avctx, AV_LOG_ERROR, "faac: frame decodinf failed: %s\n", |
1245 | 167 s->faacDecGetErrorMessage(frame_info.error)); |
168 return 0; | |
169 } | |
170 | |
171 frame_info.samples *= s->sample_size; | |
172 memcpy(data, out, frame_info.samples); // CHECKME - can we cheat this one | |
173 | |
174 if (data_size) | |
175 *data_size = frame_info.samples; | |
176 | |
177 return (buf_size < (int)frame_info.bytesconsumed) | |
178 ? buf_size : (int)frame_info.bytesconsumed; | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
179 #endif |
1245 | 180 } |
181 | |
182 static int faac_decode_end(AVCodecContext *avctx) | |
183 { | |
184 FAACContext *s = (FAACContext *) avctx->priv_data; | |
185 | |
186 if (s->faacDecClose) | |
187 s->faacDecClose(s->faac_handle); | |
188 | |
189 dlclose(s->handle); | |
190 return 0; | |
191 } | |
192 | |
193 static int faac_decode_init(AVCodecContext *avctx) | |
194 { | |
195 FAACContext *s = (FAACContext *) avctx->priv_data; | |
196 faacDecConfigurationPtr faac_cfg; | |
197 | |
198 #ifdef CONFIG_FAADBIN | |
199 const char* err = 0; | |
200 | |
201 s->handle = dlopen(libfaadname, RTLD_LAZY); | |
202 if (!s->handle) | |
203 { | |
1602
fdb8244da1e5
av_log patch(2 of ?) by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1245
diff
changeset
|
204 av_log(avctx, AV_LOG_ERROR, "FAAD library: %s could not be opened! \n%s\n", |
1245 | 205 libfaadname, dlerror()); |
206 return -1; | |
207 } | |
208 #define dfaac(a, b) \ | |
209 do { static const char* n = "faacDec" #a; \ | |
210 if ((s->faacDec ## a = b dlsym( s->handle, n )) == NULL) { err = n; break; } } while(0) | |
211 for(;;) { | |
212 #else /* !CONFIG_FAADBIN */ | |
213 #define dfaac(a, b) s->faacDec ## a = faacDec ## a | |
214 #endif /* CONFIG_FAADBIN */ | |
215 | |
216 // resolve all needed function calls | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
217 dfaac(Open, (faacDecHandle FAADAPI (*)(void))); |
1245 | 218 dfaac(GetCurrentConfiguration, (faacDecConfigurationPtr |
219 FAADAPI (*)(faacDecHandle))); | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
220 #ifndef FAAD2_VERSION |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
221 dfaac(SetConfiguration, (int FAADAPI (*)(faacDecHandle, |
1245 | 222 faacDecConfigurationPtr))); |
223 | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
224 dfaac(Init, (int FAADAPI (*)(faacDecHandle, unsigned char*, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
225 unsigned long*, unsigned long*))); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
226 dfaac(Init2, (int FAADAPI (*)(faacDecHandle, unsigned char*, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
227 unsigned long, unsigned long*, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
228 unsigned long*))); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
229 dfaac(Close, (void FAADAPI (*)(faacDecHandle hDecoder))); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
230 dfaac(Decode, (int FAADAPI (*)(faacDecHandle, unsigned char*, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
231 unsigned long*, short*, unsigned long*))); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
232 #else |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
233 dfaac(SetConfiguration, (unsigned char FAADAPI (*)(faacDecHandle, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
234 faacDecConfigurationPtr))); |
1245 | 235 dfaac(Init, (long FAADAPI (*)(faacDecHandle, unsigned char*, |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
236 unsigned long, unsigned long*, unsigned char*))); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
237 dfaac(Init2, (char FAADAPI (*)(faacDecHandle, unsigned char*, |
1245 | 238 unsigned long, unsigned long*, |
239 unsigned char*))); | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
240 dfaac(Decode, (void *FAADAPI (*)(faacDecHandle, faacDecFrameInfo*, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
241 unsigned char*, unsigned long))); |
1245 | 242 dfaac(GetErrorMessage, (unsigned char* FAADAPI (*)(unsigned char))); |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
243 #endif |
1245 | 244 #undef dfacc |
245 | |
246 #ifdef CONFIG_FAADBIN | |
247 break; | |
248 } | |
249 if (err) { | |
250 dlclose(s->handle); | |
1602
fdb8244da1e5
av_log patch(2 of ?) by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1245
diff
changeset
|
251 av_log(avctx, AV_LOG_ERROR, "FAAD library: cannot resolve %s in %s!\n", |
1245 | 252 err, libfaadname); |
253 return -1; | |
254 } | |
255 #endif | |
256 | |
257 s->faac_handle = s->faacDecOpen(); | |
258 if (!s->faac_handle) { | |
1602
fdb8244da1e5
av_log patch(2 of ?) by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1245
diff
changeset
|
259 av_log(avctx, AV_LOG_ERROR, "FAAD library: cannot create handler!\n"); |
1245 | 260 faac_decode_end(avctx); |
261 return -1; | |
262 } | |
263 | |
264 | |
265 faac_cfg = s->faacDecGetCurrentConfiguration(s->faac_handle); | |
266 | |
267 if (faac_cfg) { | |
268 switch (avctx->bits_per_sample) { | |
1602
fdb8244da1e5
av_log patch(2 of ?) by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1245
diff
changeset
|
269 case 8: av_log(avctx, AV_LOG_ERROR, "FAADlib unsupported bps %d\n", avctx->bits_per_sample); break; |
1245 | 270 default: |
271 case 16: | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
272 #ifdef FAAD2_VERSION |
1245 | 273 faac_cfg->outputFormat = FAAD_FMT_16BIT; |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
274 #endif |
1245 | 275 s->sample_size = 2; |
276 break; | |
277 case 24: | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
278 #ifdef FAAD2_VERSION |
1245 | 279 faac_cfg->outputFormat = FAAD_FMT_24BIT; |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
280 #endif |
1245 | 281 s->sample_size = 3; |
282 break; | |
283 case 32: | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
284 #ifdef FAAD2_VERSION |
1245 | 285 faac_cfg->outputFormat = FAAD_FMT_32BIT; |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
286 #endif |
1245 | 287 s->sample_size = 4; |
288 break; | |
289 } | |
290 | |
291 faac_cfg->defSampleRate = (!avctx->sample_rate) ? 44100 : avctx->sample_rate; | |
292 faac_cfg->defObjectType = LC; | |
293 } | |
294 | |
295 s->faacDecSetConfiguration(s->faac_handle, faac_cfg); | |
296 | |
297 faac_init_mp4(avctx); | |
298 | |
299 return 0; | |
300 } | |
301 | |
302 #define AAC_CODEC(id, name) \ | |
303 AVCodec name ## _decoder = { \ | |
304 #name, \ | |
305 CODEC_TYPE_AUDIO, \ | |
306 id, \ | |
307 sizeof(FAACContext), \ | |
308 faac_decode_init, \ | |
309 NULL, \ | |
310 faac_decode_end, \ | |
311 faac_decode_frame, \ | |
312 } | |
313 | |
314 // FIXME - raw AAC files - maybe just one entry will be enough | |
315 AAC_CODEC(CODEC_ID_AAC, aac); | |
316 // If it's mp4 file - usually embeded into Qt Mov | |
317 AAC_CODEC(CODEC_ID_MPEG4AAC, mpeg4aac); | |
318 | |
319 #undef AAC_CODEC |