annotate faad.c @ 1991:fa09319b80af libavcodec

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