annotate faad.c @ 1561:aa71c7981523 libavcodec

10l
author michael
date Thu, 23 Oct 2003 08:31:26 +0000
parents cd88870c4560
children fdb8244da1e5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
1 /*
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
2 * Faad decoder
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
3 * Copyright (c) 2003 Zdenek Kabelac.
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
4 *
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
9 *
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
13 * Lesser General Public License for more details.
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
14 *
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
18 */
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
19
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
20 /**
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
21 * @file faad.c
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
22 * AAC decoder.
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
23 *
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
24 * still a bit unfinished - but it plays something
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
25 */
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
26
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
27 #include "avcodec.h"
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
28 #include "faad.h"
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
29
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
30 /*
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
31 * when CONFIG_FAADBIN is defined the libfaad will be opened at runtime
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
32 */
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
33 //#undef CONFIG_FAADBIN
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
34 //#define CONFIG_FAADBIN
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
35
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
36 #ifdef CONFIG_FAADBIN
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
37 #include <dlfcn.h>
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
38 static const char* libfaadname = "libfaad.so.0";
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
39 #else
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
40 #define dlopen(a)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
41 #define dlclose(a)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
42 #endif
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
43
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
44 typedef struct {
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
45 void* handle; /* dlopen handle */
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
46 void* faac_handle; /* FAAD library handle */
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
47 int frame_size;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
48 int sample_size;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
49 int flags;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
50
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
51 /* faad calls */
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
52 faacDecHandle FAADAPI (*faacDecOpen)(void);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
53 faacDecConfigurationPtr FAADAPI (*faacDecGetCurrentConfiguration)(faacDecHandle hDecoder);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
54 unsigned char FAADAPI (*faacDecSetConfiguration)(faacDecHandle hDecoder,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
55 faacDecConfigurationPtr config);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
56 long FAADAPI (*faacDecInit)(faacDecHandle hDecoder,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
57 unsigned char *buffer,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
58 unsigned long *samplerate,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
59 unsigned char *channels);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
60 char FAADAPI (*faacDecInit2)(faacDecHandle hDecoder, unsigned char *pBuffer,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
61 unsigned long SizeOfDecoderSpecificInfo,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
62 unsigned long *samplerate, unsigned char *channels);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
63 void FAADAPI (*faacDecClose)(faacDecHandle hDecoder);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
64 void* FAADAPI (*faacDecDecode)(faacDecHandle hDecoder,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
65 faacDecFrameInfo *hInfo,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
66 unsigned char *buffer);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
67 unsigned char* FAADAPI (*faacDecGetErrorMessage)(unsigned char errcode);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
68 } FAACContext;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
69
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
70 static const unsigned long faac_srates[] =
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
71 {
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
72 96000, 88200, 64000, 48000, 44100, 32000,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
73 24000, 22050, 16000, 12000, 11025, 8000
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
74 };
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
75
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
76 static int faac_init_mp4(AVCodecContext *avctx)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
77 {
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
78 FAACContext *s = (FAACContext *) avctx->priv_data;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
79 unsigned long samplerate;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
80 unsigned char channels;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
81 int r = 0;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
82
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
83 if (avctx->extradata)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
84 r = s->faacDecInit2(s->faac_handle, (uint8_t*) avctx->extradata,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
85 avctx->extradata_size,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
86 &samplerate, &channels);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
87 // else r = s->faacDecInit(s->faac_handle ... );
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
88
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
89 if (r < 0)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
90 fprintf(stderr, "faacDecInit2 failed r:%d sr:%ld ch:%d s:%d\n",
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
91 r, samplerate, channels, avctx->extradata_size);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
92
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
93 return r;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
94 }
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
95
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
96 static int faac_init_aac(AVCodecContext *avctx)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
97 {
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
98 FAACContext *s = (FAACContext *) avctx->priv_data;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
99 return 0;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
100 }
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
101
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
102 static int faac_decode_frame(AVCodecContext *avctx,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
103 void *data, int *data_size,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
104 uint8_t *buf, int buf_size)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
105 {
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
106 FAACContext *s = (FAACContext *) avctx->priv_data;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
107 faacDecFrameInfo frame_info;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
108 void* out = s->faacDecDecode(s->faac_handle, &frame_info, (unsigned char*)buf);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
109 //printf("DECODE FRAME %d, %d, %d - %p\n", buf_size, frame_info.samples, frame_info.bytesconsumed, out);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
110
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
111 if (frame_info.error > 0) {
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
112 fprintf(stderr, "faac: frame decodinf failed: %s\n",
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
113 s->faacDecGetErrorMessage(frame_info.error));
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
114 return 0;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
115 }
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
116
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
117 frame_info.samples *= s->sample_size;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
118 memcpy(data, out, frame_info.samples); // CHECKME - can we cheat this one
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
119
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
120 if (data_size)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
121 *data_size = frame_info.samples;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
122
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
123 return (buf_size < (int)frame_info.bytesconsumed)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
124 ? buf_size : (int)frame_info.bytesconsumed;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
125 }
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
126
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
127 static int faac_decode_end(AVCodecContext *avctx)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
128 {
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
129 FAACContext *s = (FAACContext *) avctx->priv_data;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
130
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
131 if (s->faacDecClose)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
132 s->faacDecClose(s->faac_handle);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
133
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
134 dlclose(s->handle);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
135 return 0;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
136 }
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
137
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
138 static int faac_decode_init(AVCodecContext *avctx)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
139 {
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
140 FAACContext *s = (FAACContext *) avctx->priv_data;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
141 faacDecConfigurationPtr faac_cfg;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
142
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
143 #ifdef CONFIG_FAADBIN
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
144 const char* err = 0;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
145
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
146 s->handle = dlopen(libfaadname, RTLD_LAZY);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
147 if (!s->handle)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
148 {
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
149 fprintf(stderr, "FAAD library: %s could not be opened! \n%s\n",
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
150 libfaadname, dlerror());
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
151 return -1;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
152 }
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
153 #define dfaac(a, b) \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
154 do { static const char* n = "faacDec" #a; \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
155 if ((s->faacDec ## a = b dlsym( s->handle, n )) == NULL) { err = n; break; } } while(0)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
156 for(;;) {
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
157 #else /* !CONFIG_FAADBIN */
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
158 #define dfaac(a, b) s->faacDec ## a = faacDec ## a
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
159 #endif /* CONFIG_FAADBIN */
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
160
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
161 // resolve all needed function calls
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
162 dfaac(Open, (faacDecHandle FAADAPI (*)(void)));
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
163 dfaac(GetCurrentConfiguration, (faacDecConfigurationPtr
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
164 FAADAPI (*)(faacDecHandle)));
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
165 dfaac(SetConfiguration, (unsigned char FAADAPI (*)(faacDecHandle,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
166 faacDecConfigurationPtr)));
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
167
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
168 dfaac(Init, (long FAADAPI (*)(faacDecHandle, unsigned char*,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
169 unsigned long*, unsigned char*)));
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
170 dfaac(Init2, (char FAADAPI (*)(faacDecHandle, unsigned char*,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
171 unsigned long, unsigned long*,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
172 unsigned char*)));
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
173 dfaac(Close, (void FAADAPI (*)(faacDecHandle hDecoder)));
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
174 dfaac(Decode, (void* FAADAPI (*)(faacDecHandle, faacDecFrameInfo*,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
175 unsigned char*)));
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
176
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
177 dfaac(GetErrorMessage, (unsigned char* FAADAPI (*)(unsigned char)));
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
178 #undef dfacc
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
179
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
180 #ifdef CONFIG_FAADBIN
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
181 break;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
182 }
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
183 if (err) {
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
184 dlclose(s->handle);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
185 fprintf(stderr, "FAAD library: cannot resolve %s in %s!\n",
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
186 err, libfaadname);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
187 return -1;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
188 }
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
189 #endif
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
190
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
191 s->faac_handle = s->faacDecOpen();
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
192 if (!s->faac_handle) {
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
193 fprintf(stderr, "FAAD library: cannot create handler!\n");
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
194 faac_decode_end(avctx);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
195 return -1;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
196 }
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
197
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
198
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
199 faac_cfg = s->faacDecGetCurrentConfiguration(s->faac_handle);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
200
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
201 if (faac_cfg) {
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
202 switch (avctx->bits_per_sample) {
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
203 case 8: fprintf(stderr, "FAADlib unsupported bps %d\n", avctx->bits_per_sample); break;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
204 default:
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
205 case 16:
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
206 faac_cfg->outputFormat = FAAD_FMT_16BIT;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
207 s->sample_size = 2;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
208 break;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
209 case 24:
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
210 faac_cfg->outputFormat = FAAD_FMT_24BIT;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
211 s->sample_size = 3;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
212 break;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
213 case 32:
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
214 faac_cfg->outputFormat = FAAD_FMT_32BIT;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
215 s->sample_size = 4;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
216 break;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
217 }
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
218
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
219 faac_cfg->defSampleRate = (!avctx->sample_rate) ? 44100 : avctx->sample_rate;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
220 faac_cfg->defObjectType = LC;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
221 }
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
222
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
223 s->faacDecSetConfiguration(s->faac_handle, faac_cfg);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
224
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
225 faac_init_mp4(avctx);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
226
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
227 return 0;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
228 }
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
229
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
230 #define AAC_CODEC(id, name) \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
231 AVCodec name ## _decoder = { \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
232 #name, \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
233 CODEC_TYPE_AUDIO, \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
234 id, \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
235 sizeof(FAACContext), \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
236 faac_decode_init, \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
237 NULL, \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
238 faac_decode_end, \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
239 faac_decode_frame, \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
240 }
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
241
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
242 // FIXME - raw AAC files - maybe just one entry will be enough
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
243 AAC_CODEC(CODEC_ID_AAC, aac);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
244 // If it's mp4 file - usually embeded into Qt Mov
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
245 AAC_CODEC(CODEC_ID_MPEG4AAC, mpeg4aac);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
246
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
247 #undef AAC_CODEC