-
Notifications
You must be signed in to change notification settings - Fork 3
/
libfdkaac.patch
249 lines (237 loc) · 9.55 KB
/
libfdkaac.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
diff --git a/configure b/configure
index b6616f00b6..d02f5099fe 100755
--- a/configure
+++ b/configure
@@ -1774,7 +1774,6 @@ EXTERNAL_LIBRARY_GPL_LIST="
EXTERNAL_LIBRARY_NONFREE_LIST="
decklink
- libfdk_aac
libtls
"
@@ -1873,6 +1872,7 @@ EXTERNAL_LIBRARY_LIST="
openssl
pocketsphinx
vapoursynth
+ libfdk_aac
"
HWACCEL_AUTODETECT_LIBRARY_LIST="
@@ -6581,9 +6581,7 @@ enabled libdav1d && require_pkg_config libdav1d "dav1d >= 0.5.0" "dav1d
enabled libdavs2 && require_pkg_config libdavs2 "davs2 >= 1.6.0" davs2.h davs2_decoder_open
enabled libdc1394 && require_pkg_config libdc1394 libdc1394-2 dc1394/dc1394.h dc1394_new
enabled libdrm && require_pkg_config libdrm libdrm xf86drm.h drmGetVersion
-enabled libfdk_aac && { check_pkg_config libfdk_aac fdk-aac "fdk-aac/aacenc_lib.h" aacEncOpen ||
- { require libfdk_aac fdk-aac/aacenc_lib.h aacEncOpen -lfdk-aac &&
- warn "using libfdk without pkg-config"; } }
+enabled libfdk_aac && require_headers fdk-aac/aacenc_lib.h
flite_extralibs="-lflite_cmu_time_awb -lflite_cmu_us_awb -lflite_cmu_us_kal -lflite_cmu_us_kal16 -lflite_cmu_us_rms -lflite_cmu_us_slt -lflite_usenglish -lflite_cmulex -lflite"
enabled libflite && require libflite "flite/flite.h" flite_init $flite_extralibs
enabled fontconfig && enable libfontconfig
diff --git a/libavcodec/libfdk-aac_internal.h b/libavcodec/libfdk-aac_internal.h
new file mode 100644
index 0000000000..9bcfdb9aba
--- /dev/null
+++ b/libavcodec/libfdk-aac_internal.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2018 Gianluigi Tiesi
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_LIBFDK_AAC_INTERNAL_H
+#define AVCODEC_LIBFDK_AAC_INTERNAL_H
+
+#ifdef _WIN32
+#include <windows.h>
+#define LIBNAME "libfdk-aac-2.dll"
+#define dlopen(fname, f) ((void *) LoadLibraryA(fname))
+#define dlclose(handle) FreeLibrary((HMODULE) handle)
+#define dlsym(handle, name) GetProcAddress((HMODULE) handle, name)
+#else
+#include <dlfcn.h>
+#define LIBNAME "libfdk-aac.so.2"
+#endif
+
+#define DLSYM(x) \
+ do \
+ { \
+ s->pfn.x = ( imp_##x ) dlsym(s->hLib, AV_STRINGIFY(x)); \
+ if (!s->pfn.x ) \
+ { \
+ av_log(avctx, AV_LOG_ERROR, "Unable to find symbol " AV_STRINGIFY(x) " in dynamic " LIBNAME "\n"); \
+ return -1; \
+ } \
+ } while (0)
+
+
+#include <fdk-aac/aacenc_lib.h>
+#include <fdk-aac/aacdecoder_lib.h>
+
+typedef AACENC_ERROR (*imp_aacEncOpen)(HANDLE_AACENCODER *phAacEncoder, const UINT encModules, const UINT maxChannels);
+typedef AACENC_ERROR (*imp_aacEncClose)(HANDLE_AACENCODER *phAacEncoder);
+typedef AACENC_ERROR (*imp_aacEncEncode)(const HANDLE_AACENCODER hAacEncoder, const AACENC_BufDesc *inBufDesc, const AACENC_BufDesc *outBufDesc, const AACENC_InArgs *inargs, AACENC_OutArgs *outargs);
+typedef AACENC_ERROR (*imp_aacEncInfo)(const HANDLE_AACENCODER hAacEncoder, AACENC_InfoStruct *pInfo);
+typedef AACENC_ERROR (*imp_aacEncoder_SetParam)(const HANDLE_AACENCODER hAacEncoder, const AACENC_PARAM param, const UINT value);
+
+typedef struct _aacEncLib {
+ imp_aacEncOpen aacEncOpen;
+ imp_aacEncClose aacEncClose;
+ imp_aacEncEncode aacEncEncode;
+ imp_aacEncInfo aacEncInfo;
+ imp_aacEncoder_SetParam aacEncoder_SetParam;
+} aacEncLib;
+
+typedef LINKSPEC_H HANDLE_AACDECODER (*imp_aacDecoder_Open)(TRANSPORT_TYPE transportFmt, UINT nrOfLayers);
+typedef LINKSPEC_H void (*imp_aacDecoder_Close)(HANDLE_AACDECODER self);
+typedef LINKSPEC_H AAC_DECODER_ERROR (*imp_aacDecoder_Fill)(HANDLE_AACDECODER self, UCHAR *pBuffer[], const UINT bufferSize[], UINT *bytesValid);
+typedef LINKSPEC_H AAC_DECODER_ERROR (*imp_aacDecoder_DecodeFrame)(HANDLE_AACDECODER self, INT_PCM *pTimeData, const INT timeDataSize, const UINT flags);
+typedef LINKSPEC_H CStreamInfo* (*imp_aacDecoder_GetStreamInfo)(HANDLE_AACDECODER self);
+typedef LINKSPEC_H AAC_DECODER_ERROR (*imp_aacDecoder_ConfigRaw)(HANDLE_AACDECODER self, UCHAR *conf[], const UINT length[]);
+typedef LINKSPEC_H AAC_DECODER_ERROR (*imp_aacDecoder_SetParam)(const HANDLE_AACDECODER self, const AACDEC_PARAM param, const INT value);
+typedef LINKSPEC_H AAC_DECODER_ERROR (*imp_aacDecoder_AncDataInit)(HANDLE_AACDECODER self, UCHAR *buffer, int size);
+
+typedef struct _aacDecLib {
+ imp_aacDecoder_Open aacDecoder_Open;
+ imp_aacDecoder_Close aacDecoder_Close;
+ imp_aacDecoder_Fill aacDecoder_Fill;
+ imp_aacDecoder_DecodeFrame aacDecoder_DecodeFrame;
+ imp_aacDecoder_ConfigRaw aacDecoder_ConfigRaw;
+ imp_aacDecoder_GetStreamInfo aacDecoder_GetStreamInfo;
+ imp_aacDecoder_SetParam aacDecoder_SetParam;
+ imp_aacDecoder_AncDataInit aacDecoder_AncDataInit;
+} aacDecLib;
+
+#endif /* AVCODEC_LIBFDK_AAC_INTERNAL_H */
\ No newline at end of file
diff --git a/libavcodec/libfdk-aacdec.c b/libavcodec/libfdk-aacdec.c
index 8c1586e25e..25f68cdd10 100644
--- a/libavcodec/libfdk-aacdec.c
+++ b/libavcodec/libfdk-aacdec.c
@@ -25,6 +25,7 @@
#include "avcodec.h"
#include "codec_internal.h"
#include "decode.h"
+#include "libfdk-aac_internal.h"
#ifdef AACDECODER_LIB_VL0
#define FDKDEC_VER_AT_LEAST(vl0, vl1) \
@@ -48,6 +49,8 @@ enum ConcealMethod {
typedef struct FDKAACDecContext {
const AVClass *class;
HANDLE_AACDECODER handle;
+ void *hLib;
+ aacDecLib pfn;
uint8_t *decoder_buffer;
int decoder_buffer_size;
uint8_t *anc_buffer;
@@ -113,7 +116,7 @@ static const AVClass fdk_aac_dec_class = {
static int get_stream_info(AVCodecContext *avctx)
{
FDKAACDecContext *s = avctx->priv_data;
- CStreamInfo *info = aacDecoder_GetStreamInfo(s->handle);
+ CStreamInfo *info = s->pfn.aacDecoder_GetStreamInfo(s->handle);
int channel_counts[0x24] = { 0 };
int i, ch_error = 0;
uint64_t ch_layout = 0;
@@ -231,8 +234,10 @@ static av_cold int fdk_aac_decode_close(AVCodecContext *avctx)
{
FDKAACDecContext *s = avctx->priv_data;
- if (s->handle)
- aacDecoder_Close(s->handle);
+ if (s->hLib && s->handle) {
+ s->pfn.aacDecoder_Close(s->handle);
+ dlclose(s->hLib);
+ }
av_freep(&s->decoder_buffer);
av_freep(&s->anc_buffer);
@@ -244,6 +249,27 @@ static av_cold int fdk_aac_decode_init(AVCodecContext *avctx)
FDKAACDecContext *s = avctx->priv_data;
AAC_DECODER_ERROR err;
+ if (!(s->hLib = dlopen(LIBNAME, RTLD_NOW))) {
+ av_log(avctx, AV_LOG_ERROR, "Unable to load " LIBNAME "\n");
+ return -1;
+ }
+
+ DLSYM(aacDecoder_Open);
+#define aacDecoder_Open s->pfn.aacDecoder_Open
+ DLSYM(aacDecoder_Close);
+ DLSYM(aacDecoder_Fill);
+#define aacDecoder_Fill s->pfn.aacDecoder_Fill
+ DLSYM(aacDecoder_DecodeFrame);
+#define aacDecoder_DecodeFrame s->pfn.aacDecoder_DecodeFrame
+ DLSYM(aacDecoder_GetStreamInfo);
+#define aacDecoder_GetStreamInfo s->pfn.aacDecoder_GetStreamInfo
+ DLSYM(aacDecoder_ConfigRaw);
+#define aacDecoder_ConfigRaw s->pfn.aacDecoder_ConfigRaw
+ DLSYM(aacDecoder_SetParam);
+#define aacDecoder_SetParam s->pfn.aacDecoder_SetParam
+ DLSYM(aacDecoder_AncDataInit);
+#define aacDecoder_AncDataInit s->pfn.aacDecoder_AncDataInit
+
s->handle = aacDecoder_Open(avctx->extradata_size ? TT_MP4_RAW : TT_MP4_ADTS, 1);
if (!s->handle) {
av_log(avctx, AV_LOG_ERROR, "Error opening decoder\n");
diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c
index 54549de473..9e93ce092c 100644
--- a/libavcodec/libfdk-aacenc.c
+++ b/libavcodec/libfdk-aacenc.c
@@ -27,6 +27,7 @@
#include "codec_internal.h"
#include "encode.h"
#include "profiles.h"
+#include "libfdk-aac_internal.h"
#ifdef AACENCODER_LIB_VL0
#define FDKENC_VER_AT_LEAST(vl0, vl1) \
@@ -46,6 +47,8 @@ typedef struct AACContext {
int latm;
int header_period;
int vbr;
+ void *hLib;
+ aacEncLib pfn;
AudioFrameQueue afq;
} AACContext;
@@ -111,8 +114,10 @@ static int aac_encode_close(AVCodecContext *avctx)
{
AACContext *s = avctx->priv_data;
- if (s->handle)
- aacEncClose(&s->handle);
+ if (s->hLib && s->handle) {
+ s->pfn.aacEncClose(&s->handle);
+ dlclose(s->hLib);
+ }
ff_af_queue_close(&s->afq);
return 0;
@@ -128,6 +133,21 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
int aot = FF_PROFILE_AAC_LOW + 1;
int sce = 0, cpe = 0;
+ if (!(s->hLib = dlopen(LIBNAME, RTLD_NOW))) {
+ av_log(avctx, AV_LOG_ERROR, "Unable to load " LIBNAME "\n");
+ return -1;
+ }
+
+ DLSYM(aacEncOpen);
+#define aacEncOpen s->pfn.aacEncOpen
+ DLSYM(aacEncClose);
+ DLSYM(aacEncEncode);
+#define aacEncEncode s->pfn.aacEncEncode
+ DLSYM(aacEncInfo);
+#define aacEncInfo s->pfn.aacEncInfo
+ DLSYM(aacEncoder_SetParam);
+#define aacEncoder_SetParam s->pfn.aacEncoder_SetParam
+
if ((err = aacEncOpen(&s->handle, 0, avctx->ch_layout.nb_channels)) != AACENC_OK) {
av_log(avctx, AV_LOG_ERROR, "Unable to open the encoder: %s\n",
aac_get_error(err));