annotate libfaad.c @ 8649:470a3af1bf4f libavcodec

flacdec: remove some unused code
author jbr
date Sat, 24 Jan 2009 15:46:19 +0000
parents 04423b2f6e0b
children 5b7d5a33a3e2
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
8629
04423b2f6e0b cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 8590
diff changeset
3 * Copyright (c) 2003 Zdenek Kabelac
04423b2f6e0b cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 8590
diff changeset
4 * Copyright (c) 2004 Thomas Raivio
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
5 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3164
diff changeset
6 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3164
diff changeset
7 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3164
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3164
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
12 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3164
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
16 * Lesser General Public License for more details.
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
17 *
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3164
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2979
diff changeset
20 * 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
21 */
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
22
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 * @file faad.c
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
25 * AAC decoder.
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 * still a bit unfinished - but it plays something
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
28 */
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 #include "avcodec.h"
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
31 #include "faad.h"
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
32
2061
c28b03fea50f Building with faad2-cvs fix by ("Steven M. Schultz" <sms at 2bsd dot com>)
michael
parents: 2059
diff changeset
33 #ifndef FAADAPI
c28b03fea50f Building with faad2-cvs fix by ("Steven M. Schultz" <sms at 2bsd dot com>)
michael
parents: 2059
diff changeset
34 #define FAADAPI
c28b03fea50f Building with faad2-cvs fix by ("Steven M. Schultz" <sms at 2bsd dot com>)
michael
parents: 2059
diff changeset
35 #endif
c28b03fea50f Building with faad2-cvs fix by ("Steven M. Schultz" <sms at 2bsd dot com>)
michael
parents: 2059
diff changeset
36
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
37 /*
8590
7a463923ecd1 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 7978
diff changeset
38 * when CONFIG_LIBFAADBIN is true libfaad will be opened at runtime
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
39 */
4336
b7caa9237018 Rename variables: faad --> libfaad, faac --> libfaac, faadbin --> libfaadbin
diego
parents: 4163
diff changeset
40 //#undef CONFIG_LIBFAADBIN
8590
7a463923ecd1 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 7978
diff changeset
41 //#define CONFIG_LIBFAADBIN 0
7a463923ecd1 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 7978
diff changeset
42 //#define CONFIG_LIBFAADBIN 1
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
43
8590
7a463923ecd1 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 7978
diff changeset
44 #if CONFIG_LIBFAADBIN
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
45 #include <dlfcn.h>
7978
dc1a7a6ec58d Add (additional) const to many global tables.
reimar
parents: 7824
diff changeset
46 static const char* const libfaadname = "libfaad.so";
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
47 #else
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
48 #define dlopen(a)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
49 #define dlclose(a)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
50 #endif
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
51
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
52 typedef struct {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
53 void* handle; /* dlopen handle */
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
54 void* faac_handle; /* FAAD library handle */
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
55 int sample_size;
3097
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
56 int init;
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
57
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
58 /* faad calls */
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
59 faacDecHandle FAADAPI (*faacDecOpen)(void);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
60 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
61 #ifndef FAAD2_VERSION
6175
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
62 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
63 faacDecConfigurationPtr config);
6175
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
64 int FAADAPI (*faacDecInit)(faacDecHandle hDecoder,
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
65 unsigned char *buffer,
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
66 unsigned long *samplerate,
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
67 unsigned long *channels);
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
68 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
69 unsigned long SizeOfDecoderSpecificInfo,
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
70 unsigned long *samplerate, unsigned long *channels);
6175
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
71 int FAADAPI (*faacDecDecode)(faacDecHandle hDecoder,
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
72 unsigned char *buffer,
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
73 unsigned long *bytesconsumed,
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
74 short *sample_buffer,
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
75 unsigned long *samples);
1929
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
76 #else
6175
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
77 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
78 faacDecConfigurationPtr config);
6175
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
79 long FAADAPI (*faacDecInit)(faacDecHandle hDecoder,
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
80 unsigned char *buffer,
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
81 unsigned long buffer_size,
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
82 unsigned long *samplerate,
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
83 unsigned char *channels);
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
84 char FAADAPI (*faacDecInit2)(faacDecHandle hDecoder, unsigned char *pBuffer,
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
85 unsigned long SizeOfDecoderSpecificInfo,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
86 unsigned long *samplerate, unsigned char *channels);
6175
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
87 void *FAADAPI (*faacDecDecode)(faacDecHandle hDecoder,
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
88 faacDecFrameInfo *hInfo,
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
89 unsigned char *buffer,
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
90 unsigned long buffer_size);
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
91 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
92 #endif
2967
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 void FAADAPI (*faacDecClose)(faacDecHandle hDecoder);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
95
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
96
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
97 } FAACContext;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
98
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
99 static const unsigned long faac_srates[] =
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 96000, 88200, 64000, 48000, 44100, 32000,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
102 24000, 22050, 16000, 12000, 11025, 8000
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
6119
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
105 static void channel_setup(AVCodecContext *avctx)
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
106 {
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
107 #ifdef FAAD2_VERSION
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
108 FAACContext *s = avctx->priv_data;
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
109 if (avctx->request_channels > 0 && avctx->request_channels == 2 &&
6175
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
110 avctx->request_channels < avctx->channels) {
6119
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
111 faacDecConfigurationPtr faac_cfg;
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
112 avctx->channels = 2;
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
113 faac_cfg = s->faacDecGetCurrentConfiguration(s->faac_handle);
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
114 faac_cfg->downMatrix = 1;
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
115 s->faacDecSetConfiguration(s->faac_handle, faac_cfg);
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
116 }
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
117 #endif
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
118 }
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
119
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
120 static int faac_init_mp4(AVCodecContext *avctx)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
121 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4753
diff changeset
122 FAACContext *s = avctx->priv_data;
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
123 unsigned long samplerate;
1929
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
124 #ifndef FAAD2_VERSION
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
125 unsigned long channels;
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
126 #else
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
127 unsigned char channels;
1929
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
128 #endif
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
129 int r = 0;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
130
3097
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
131 if (avctx->extradata){
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
132 r = s->faacDecInit2(s->faac_handle, (uint8_t*) avctx->extradata,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
133 avctx->extradata_size,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
134 &samplerate, &channels);
3097
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
135 if (r < 0){
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
136 av_log(avctx, AV_LOG_ERROR,
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
137 "faacDecInit2 failed r:%d sr:%ld ch:%ld s:%d\n",
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
138 r, samplerate, (long)channels, avctx->extradata_size);
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
139 } else {
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
140 avctx->sample_rate = samplerate;
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
141 avctx->channels = channels;
6119
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
142 channel_setup(avctx);
3097
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
143 s->init = 1;
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
144 }
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
145 }
2059
ad972ab280bc sample_rate and channels in aac audio patch by (Luca Abeni <lucabe72 at email dot it>)
michael
parents: 1929
diff changeset
146
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
147 return r;
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
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
150 static int faac_decode_frame(AVCodecContext *avctx,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
151 void *data, int *data_size,
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
152 uint8_t *buf, int buf_size)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
153 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4753
diff changeset
154 FAACContext *s = avctx->priv_data;
1929
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
155 #ifndef FAAD2_VERSION
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
156 unsigned long bytesconsumed;
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
157 short *sample_buffer = NULL;
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
158 unsigned long samples;
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
159 int out;
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
160 #else
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
161 faacDecFrameInfo frame_info;
1929
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
162 void *out;
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
163 #endif
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
164 if(buf_size == 0)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
165 return 0;
1929
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
166 #ifndef FAAD2_VERSION
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
167 out = s->faacDecDecode(s->faac_handle,
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
168 (unsigned char*)buf,
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
169 &bytesconsumed,
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
170 data,
1929
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
171 &samples);
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
172 samples *= s->sample_size;
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
173 if (data_size)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
174 *data_size = samples;
1929
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
175 return (buf_size < (int)bytesconsumed)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
176 ? buf_size : (int)bytesconsumed;
1929
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
177 #else
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
178
3097
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
179 if(!s->init){
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
180 unsigned long srate;
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
181 unsigned char channels;
3155
c7d2c122a718 * bugfixing call reference
kabi
parents: 3097
diff changeset
182 int r = s->faacDecInit(s->faac_handle, buf, buf_size, &srate, &channels);
3097
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
183 if(r < 0){
6790
86ce080ea1e3 Do not use variable frame_info before its value is set.
cehoyos
parents: 6517
diff changeset
184 av_log(avctx, AV_LOG_ERROR, "faac: codec init failed.\n");
3164
d771383fbcb8 Make faac_decode_frame return -1 on error and not 0 which avoids
mru
parents: 3155
diff changeset
185 return -1;
3097
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
186 }
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
187 avctx->sample_rate = srate;
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
188 avctx->channels = channels;
6119
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
189 channel_setup(avctx);
3097
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
190 s->init = 1;
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
191 }
41fb9bda307d decode adts aac streams
mru
parents: 3036
diff changeset
192
1929
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
193 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
194
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
195 if (frame_info.error > 0) {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
196 av_log(avctx, AV_LOG_ERROR, "faac: frame decoding failed: %s\n",
6175
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
197 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
198 return -1;
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
199 }
7158
bfbb2df9963a set frame_size in libfaad decoder
bcoudurier
parents: 7040
diff changeset
200 if (!avctx->frame_size)
bfbb2df9963a set frame_size in libfaad decoder
bcoudurier
parents: 7040
diff changeset
201 avctx->frame_size = frame_info.samples/avctx->channels;
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
202 frame_info.samples *= s->sample_size;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
203 memcpy(data, out, frame_info.samples); // CHECKME - can we cheat this one
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
204
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
205 if (data_size)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
206 *data_size = frame_info.samples;
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
207
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
208 return (buf_size < (int)frame_info.bytesconsumed)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
209 ? 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
210 #endif
1245
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
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6177
diff changeset
213 static av_cold int faac_decode_end(AVCodecContext *avctx)
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
214 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4753
diff changeset
215 FAACContext *s = avctx->priv_data;
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
216
4753
7115a2f0854d call faacDecClose() with all libfaad versions
mru
parents: 4336
diff changeset
217 s->faacDecClose(s->faac_handle);
1245
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 dlclose(s->handle);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
220 return 0;
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
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6177
diff changeset
223 static av_cold int faac_decode_init(AVCodecContext *avctx)
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
224 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4753
diff changeset
225 FAACContext *s = avctx->priv_data;
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
226 faacDecConfigurationPtr faac_cfg;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
227
8590
7a463923ecd1 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 7978
diff changeset
228 #if CONFIG_LIBFAADBIN
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
229 const char* err = 0;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
230
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
231 s->handle = dlopen(libfaadname, RTLD_LAZY);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
232 if (!s->handle)
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
233 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
234 av_log(avctx, AV_LOG_ERROR, "FAAD library: %s could not be opened! \n%s\n",
6175
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
235 libfaadname, dlerror());
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
236 return -1;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
237 }
6177
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
238
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
239 #define dfaac(a) do { \
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
240 const char* n = AV_STRINGIFY(faacDec ## a); \
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
241 if (!err && !(s->faacDec ## a = dlsym(s->handle, n))) { \
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
242 err = n; \
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
243 } \
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
244 } while(0)
4336
b7caa9237018 Rename variables: faad --> libfaad, faac --> libfaac, faadbin --> libfaadbin
diego
parents: 4163
diff changeset
245 #else /* !CONFIG_LIBFAADBIN */
6177
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
246 #define dfaac(a) s->faacDec ## a = faacDec ## a
4336
b7caa9237018 Rename variables: faad --> libfaad, faac --> libfaac, faadbin --> libfaadbin
diego
parents: 4163
diff changeset
247 #endif /* CONFIG_LIBFAADBIN */
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
248
6177
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
249 // resolve all needed function calls
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
250 dfaac(Open);
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
251 dfaac(Close);
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
252 dfaac(GetCurrentConfiguration);
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
253 dfaac(SetConfiguration);
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
254 dfaac(Init);
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
255 dfaac(Init2);
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
256 dfaac(Decode);
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
257 #ifdef FAAD2_VERSION
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
258 dfaac(GetErrorMessage);
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
259 #endif
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
260
6177
5195f1ffba43 clean up dynamic loading of libfaad
mru
parents: 6175
diff changeset
261 #undef dfaac
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
262
8590
7a463923ecd1 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 7978
diff changeset
263 #if CONFIG_LIBFAADBIN
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
264 if (err) {
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
265 dlclose(s->handle);
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
266 av_log(avctx, AV_LOG_ERROR, "FAAD library: cannot resolve %s in %s!\n",
6175
843555383499 cosmetic: libfaad.c indentation
mru
parents: 6174
diff changeset
267 err, libfaadname);
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
268 return -1;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
269 }
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
270 #endif
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
271
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
272 s->faac_handle = s->faacDecOpen();
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
273 if (!s->faac_handle) {
1602
fdb8244da1e5 av_log patch(2 of ?) by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 1245
diff changeset
274 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
275 faac_decode_end(avctx);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
276 return -1;
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
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
279
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
280 faac_cfg = s->faacDecGetCurrentConfiguration(s->faac_handle);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
281
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
282 if (faac_cfg) {
7823
4525dcd81357 Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 7451
diff changeset
283 switch (avctx->bits_per_coded_sample) {
4525dcd81357 Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 7451
diff changeset
284 case 8: av_log(avctx, AV_LOG_ERROR, "FAADlib unsupported bps %d\n", avctx->bits_per_coded_sample); break;
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
285 default:
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
286 case 16:
1929
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
287 #ifdef FAAD2_VERSION
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
288 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
289 #endif
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
290 s->sample_size = 2;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
291 break;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
292 case 24:
1929
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
293 #ifdef FAAD2_VERSION
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
294 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
295 #endif
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
296 s->sample_size = 3;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
297 break;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
298 case 32:
1929
d4525c3065d0 aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents: 1602
diff changeset
299 #ifdef FAAD2_VERSION
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
300 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
301 #endif
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
302 s->sample_size = 4;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
303 break;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
304 }
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
305
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
306 faac_cfg->defSampleRate = (!avctx->sample_rate) ? 44100 : avctx->sample_rate;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
307 faac_cfg->defObjectType = LC;
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
308 }
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 s->faacDecSetConfiguration(s->faac_handle, faac_cfg);
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 faac_init_mp4(avctx);
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
313
6119
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
314 if(!s->init && avctx->channels > 0)
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
315 channel_setup(avctx);
49d225414a3f add downmixing support to libfaad decoder
jbr
parents: 5101
diff changeset
316
7451
85ab7655ad4d Modify all codecs to report their supported input and output sample format(s).
pross
parents: 7158
diff changeset
317 avctx->sample_fmt = SAMPLE_FMT_S16;
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
318 return 0;
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
319 }
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
320
6819
43bede126ef6 missing codec long names by Stefano Sabatini, stefano.sabatini-lala poste it
diego
parents: 6790
diff changeset
321 #define AAC_CODEC(id, name, long_name_) \
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
322 AVCodec name ## _decoder = { \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
323 #name, \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
324 CODEC_TYPE_AUDIO, \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
325 id, \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
326 sizeof(FAACContext), \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
327 faac_decode_init, \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
328 NULL, \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
329 faac_decode_end, \
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
330 faac_decode_frame, \
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6819
diff changeset
331 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
332 }
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
333
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
334 // FIXME - raw AAC files - maybe just one entry will be enough
6819
43bede126ef6 missing codec long names by Stefano Sabatini, stefano.sabatini-lala poste it
diego
parents: 6790
diff changeset
335 AAC_CODEC(CODEC_ID_AAC, libfaad, "libfaad AAC (Advanced Audio Codec)");
1245
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
336
cd88870c4560 * support for AAC audio streams via libfaad
kabi
parents:
diff changeset
337 #undef AAC_CODEC