Mercurial > libavcodec.hg
annotate faad.c @ 1964:2b16a3c32318 libavcodec
cygwin patch by ("Sascha Sommer" <saschasommer at freenet dot de>)
author | michael |
---|---|
date | Sat, 24 Apr 2004 11:51:38 +0000 |
parents | d4525c3065d0 |
children | ad972ab280bc |
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 | |
31 /* | |
32 * when CONFIG_FAADBIN is defined the libfaad will be opened at runtime | |
33 */ | |
34 //#undef CONFIG_FAADBIN | |
35 //#define CONFIG_FAADBIN | |
36 | |
37 #ifdef CONFIG_FAADBIN | |
38 #include <dlfcn.h> | |
39 static const char* libfaadname = "libfaad.so.0"; | |
40 #else | |
41 #define dlopen(a) | |
42 #define dlclose(a) | |
43 #endif | |
44 | |
45 typedef struct { | |
46 void* handle; /* dlopen handle */ | |
47 void* faac_handle; /* FAAD library handle */ | |
48 int frame_size; | |
49 int sample_size; | |
50 int flags; | |
51 | |
52 /* faad calls */ | |
53 faacDecHandle FAADAPI (*faacDecOpen)(void); | |
54 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
|
55 #ifndef FAAD2_VERSION |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
56 int FAADAPI (*faacDecSetConfiguration)(faacDecHandle hDecoder, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
57 faacDecConfigurationPtr config); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
58 int FAADAPI (*faacDecInit)(faacDecHandle hDecoder, |
1245 | 59 unsigned char *buffer, |
60 unsigned long *samplerate, | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
61 unsigned long *channels); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
62 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
|
63 unsigned long SizeOfDecoderSpecificInfo, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
64 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
|
65 int FAADAPI (*faacDecDecode)(faacDecHandle hDecoder, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
66 unsigned char *buffer, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
67 unsigned long *bytesconsumed, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
68 short *sample_buffer, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
69 unsigned long *samples); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
70 #else |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
71 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
|
72 faacDecConfigurationPtr config); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
73 long FAADAPI (*faacDecInit)(faacDecHandle hDecoder, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
74 unsigned char *buffer, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
75 unsigned long buffer_size, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
76 unsigned long *samplerate, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
77 unsigned char *channels); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
78 char FAADAPI (*faacDecInit2)(faacDecHandle hDecoder, unsigned char *pBuffer, |
1245 | 79 unsigned long SizeOfDecoderSpecificInfo, |
80 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
|
81 void *FAADAPI (*faacDecDecode)(faacDecHandle hDecoder, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
82 faacDecFrameInfo *hInfo, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
83 unsigned char *buffer, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
84 unsigned long buffer_size); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
85 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
|
86 #endif |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
87 |
1245 | 88 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
|
89 |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
90 |
1245 | 91 } FAACContext; |
92 | |
93 static const unsigned long faac_srates[] = | |
94 { | |
95 96000, 88200, 64000, 48000, 44100, 32000, | |
96 24000, 22050, 16000, 12000, 11025, 8000 | |
97 }; | |
98 | |
99 static int faac_init_mp4(AVCodecContext *avctx) | |
100 { | |
101 FAACContext *s = (FAACContext *) avctx->priv_data; | |
102 unsigned long samplerate; | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
103 #ifndef FAAD2_VERSION |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
104 unsigned long channels; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
105 #else |
1245 | 106 unsigned char channels; |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
107 #endif |
1245 | 108 int r = 0; |
109 | |
110 if (avctx->extradata) | |
111 r = s->faacDecInit2(s->faac_handle, (uint8_t*) avctx->extradata, | |
112 avctx->extradata_size, | |
113 &samplerate, &channels); | |
114 // else r = s->faacDecInit(s->faac_handle ... ); | |
115 | |
116 if (r < 0) | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
117 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
|
118 r, samplerate, (long)channels, avctx->extradata_size); |
1245 | 119 return r; |
120 } | |
121 | |
122 static int faac_init_aac(AVCodecContext *avctx) | |
123 { | |
124 return 0; | |
125 } | |
126 | |
127 static int faac_decode_frame(AVCodecContext *avctx, | |
128 void *data, int *data_size, | |
129 uint8_t *buf, int buf_size) | |
130 { | |
131 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
|
132 #ifndef FAAD2_VERSION |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
133 unsigned long bytesconsumed; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
134 short *sample_buffer = NULL; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
135 unsigned long samples; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
136 int out; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
137 #else |
1245 | 138 faacDecFrameInfo frame_info; |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
139 void *out; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
140 #endif |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
141 if(buf_size == 0) |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
142 return 0; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
143 #ifndef FAAD2_VERSION |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
144 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
|
145 (unsigned char*)buf, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
146 &bytesconsumed, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
147 data, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
148 &samples); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
149 samples *= s->sample_size; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
150 if (data_size) |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
151 *data_size = samples; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
152 return (buf_size < (int)bytesconsumed) |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
153 ? buf_size : (int)bytesconsumed; |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
154 #else |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
155 |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
156 out = s->faacDecDecode(s->faac_handle, &frame_info, (unsigned char*)buf, (unsigned long)buf_size); |
1245 | 157 |
158 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
|
159 av_log(avctx, AV_LOG_ERROR, "faac: frame decodinf failed: %s\n", |
1245 | 160 s->faacDecGetErrorMessage(frame_info.error)); |
161 return 0; | |
162 } | |
163 | |
164 frame_info.samples *= s->sample_size; | |
165 memcpy(data, out, frame_info.samples); // CHECKME - can we cheat this one | |
166 | |
167 if (data_size) | |
168 *data_size = frame_info.samples; | |
169 | |
170 return (buf_size < (int)frame_info.bytesconsumed) | |
171 ? 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
|
172 #endif |
1245 | 173 } |
174 | |
175 static int faac_decode_end(AVCodecContext *avctx) | |
176 { | |
177 FAACContext *s = (FAACContext *) avctx->priv_data; | |
178 | |
179 if (s->faacDecClose) | |
180 s->faacDecClose(s->faac_handle); | |
181 | |
182 dlclose(s->handle); | |
183 return 0; | |
184 } | |
185 | |
186 static int faac_decode_init(AVCodecContext *avctx) | |
187 { | |
188 FAACContext *s = (FAACContext *) avctx->priv_data; | |
189 faacDecConfigurationPtr faac_cfg; | |
190 | |
191 #ifdef CONFIG_FAADBIN | |
192 const char* err = 0; | |
193 | |
194 s->handle = dlopen(libfaadname, RTLD_LAZY); | |
195 if (!s->handle) | |
196 { | |
1602
fdb8244da1e5
av_log patch(2 of ?) by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1245
diff
changeset
|
197 av_log(avctx, AV_LOG_ERROR, "FAAD library: %s could not be opened! \n%s\n", |
1245 | 198 libfaadname, dlerror()); |
199 return -1; | |
200 } | |
201 #define dfaac(a, b) \ | |
202 do { static const char* n = "faacDec" #a; \ | |
203 if ((s->faacDec ## a = b dlsym( s->handle, n )) == NULL) { err = n; break; } } while(0) | |
204 for(;;) { | |
205 #else /* !CONFIG_FAADBIN */ | |
206 #define dfaac(a, b) s->faacDec ## a = faacDec ## a | |
207 #endif /* CONFIG_FAADBIN */ | |
208 | |
209 // 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
|
210 dfaac(Open, (faacDecHandle FAADAPI (*)(void))); |
1245 | 211 dfaac(GetCurrentConfiguration, (faacDecConfigurationPtr |
212 FAADAPI (*)(faacDecHandle))); | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
213 #ifndef FAAD2_VERSION |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
214 dfaac(SetConfiguration, (int FAADAPI (*)(faacDecHandle, |
1245 | 215 faacDecConfigurationPtr))); |
216 | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
217 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
|
218 unsigned long*, unsigned long*))); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
219 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
|
220 unsigned long, unsigned long*, |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
221 unsigned long*))); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
222 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
|
223 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
|
224 unsigned long*, short*, unsigned long*))); |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
225 #else |
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
226 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
|
227 faacDecConfigurationPtr))); |
1245 | 228 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
|
229 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
|
230 dfaac(Init2, (char FAADAPI (*)(faacDecHandle, unsigned char*, |
1245 | 231 unsigned long, unsigned long*, |
232 unsigned char*))); | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
233 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
|
234 unsigned char*, unsigned long))); |
1245 | 235 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
|
236 #endif |
1245 | 237 #undef dfacc |
238 | |
239 #ifdef CONFIG_FAADBIN | |
240 break; | |
241 } | |
242 if (err) { | |
243 dlclose(s->handle); | |
1602
fdb8244da1e5
av_log patch(2 of ?) by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1245
diff
changeset
|
244 av_log(avctx, AV_LOG_ERROR, "FAAD library: cannot resolve %s in %s!\n", |
1245 | 245 err, libfaadname); |
246 return -1; | |
247 } | |
248 #endif | |
249 | |
250 s->faac_handle = s->faacDecOpen(); | |
251 if (!s->faac_handle) { | |
1602
fdb8244da1e5
av_log patch(2 of ?) by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1245
diff
changeset
|
252 av_log(avctx, AV_LOG_ERROR, "FAAD library: cannot create handler!\n"); |
1245 | 253 faac_decode_end(avctx); |
254 return -1; | |
255 } | |
256 | |
257 | |
258 faac_cfg = s->faacDecGetCurrentConfiguration(s->faac_handle); | |
259 | |
260 if (faac_cfg) { | |
261 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
|
262 case 8: av_log(avctx, AV_LOG_ERROR, "FAADlib unsupported bps %d\n", avctx->bits_per_sample); break; |
1245 | 263 default: |
264 case 16: | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
265 #ifdef FAAD2_VERSION |
1245 | 266 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
|
267 #endif |
1245 | 268 s->sample_size = 2; |
269 break; | |
270 case 24: | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
271 #ifdef FAAD2_VERSION |
1245 | 272 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
|
273 #endif |
1245 | 274 s->sample_size = 3; |
275 break; | |
276 case 32: | |
1929
d4525c3065d0
aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
1602
diff
changeset
|
277 #ifdef FAAD2_VERSION |
1245 | 278 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
|
279 #endif |
1245 | 280 s->sample_size = 4; |
281 break; | |
282 } | |
283 | |
284 faac_cfg->defSampleRate = (!avctx->sample_rate) ? 44100 : avctx->sample_rate; | |
285 faac_cfg->defObjectType = LC; | |
286 } | |
287 | |
288 s->faacDecSetConfiguration(s->faac_handle, faac_cfg); | |
289 | |
290 faac_init_mp4(avctx); | |
291 | |
292 return 0; | |
293 } | |
294 | |
295 #define AAC_CODEC(id, name) \ | |
296 AVCodec name ## _decoder = { \ | |
297 #name, \ | |
298 CODEC_TYPE_AUDIO, \ | |
299 id, \ | |
300 sizeof(FAACContext), \ | |
301 faac_decode_init, \ | |
302 NULL, \ | |
303 faac_decode_end, \ | |
304 faac_decode_frame, \ | |
305 } | |
306 | |
307 // FIXME - raw AAC files - maybe just one entry will be enough | |
308 AAC_CODEC(CODEC_ID_AAC, aac); | |
309 // If it's mp4 file - usually embeded into Qt Mov | |
310 AAC_CODEC(CODEC_ID_MPEG4AAC, mpeg4aac); | |
311 | |
312 #undef AAC_CODEC |