annotate faad.c @ 3250:fec9bc8d63fc libavcodec

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