[droid] Do not show any ui if pre-checks are OK
[vuplus_xbmc] / lib / DllAvFilter.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2011 Team XBMC
4  *      http://www.xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, write to
18  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19  *  http://www.gnu.org/copyleft/gpl.html
20  *
21  */
22
23 #if (defined HAVE_CONFIG_H) && (!defined WIN32)
24   #include "config.h"
25 #endif
26 #include "DynamicDll.h"
27 #include "DllAvCodec.h"
28 #include "DllAvFormat.h"
29 #include "DllSwResample.h"
30 #include "utils/log.h"
31
32 extern "C" {
33 #ifndef HAVE_MMX
34 #define HAVE_MMX
35 #endif
36 #ifndef __STDC_CONSTANT_MACROS
37 #define __STDC_CONSTANT_MACROS
38 #endif
39
40 #ifndef __GNUC__
41 #pragma warning(disable:4244)
42 #endif
43
44 #if (defined USE_EXTERNAL_FFMPEG)
45   #if (defined HAVE_LIBAVFILTER_AVFILTER_H)
46     #include <libavfilter/avfiltergraph.h>
47     #include <libavfilter/buffersink.h>
48     #include <libavfilter/avcodec.h>
49   #elif (defined HAVE_FFMPEG_AVFILTER_H)
50     #include <ffmpeg/avfiltergraph.h>
51     #include <ffmpeg/buffersink.h>
52     #include <ffmpeg/avcodec.h>
53   #endif
54 #else
55   #include "libavfilter/avfiltergraph.h"
56   #include "libavfilter/buffersink.h"
57   #include "libavfilter/avcodec.h"
58 #endif
59 }
60
61 #include "threads/SingleLock.h"
62
63 class DllAvFilterInterface
64 {
65 public:
66   virtual ~DllAvFilterInterface() {}
67   virtual int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name)=0;
68   virtual void avfilter_free(AVFilterContext *filter)=0;
69   virtual void avfilter_graph_free(AVFilterGraph **graph)=0;
70   virtual int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt, const char *name, const char *args, void *opaque, AVFilterGraph *graph_ctx)=0;
71   virtual AVFilter *avfilter_get_by_name(const char *name)=0;
72   virtual AVFilterGraph *avfilter_graph_alloc(void)=0;
73   virtual AVFilterInOut *avfilter_inout_alloc()=0;
74   virtual void avfilter_inout_free(AVFilterInOut **inout)=0;
75   virtual int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs, void *log_ctx)=0;
76   virtual int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)=0;
77 #if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(3,0,0)
78   virtual int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, int flags)=0;
79 #else
80   virtual int av_buffersrc_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, int flags)=0;
81 #endif
82   virtual void avfilter_unref_buffer(AVFilterBufferRef *ref)=0;
83   virtual int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)=0;
84   virtual int av_buffersink_get_buffer_ref(AVFilterContext *buffer_sink, AVFilterBufferRef **bufref, int flags)=0;
85   virtual AVBufferSinkParams *av_buffersink_params_alloc()=0;
86   virtual int av_buffersink_poll_frame(AVFilterContext *ctx)=0;
87 };
88
89 #if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN)
90 // Use direct mapping
91 class DllAvFilter : public DllDynamic, DllAvFilterInterface
92 {
93 public:
94   virtual ~DllAvFilter() {}
95   virtual int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name)
96   {
97     CSingleLock lock(DllAvCodec::m_critSection);
98     return ::avfilter_open(filter_ctx, filter, inst_name);
99   }
100   virtual void avfilter_free(AVFilterContext *filter)
101   {
102     CSingleLock lock(DllAvCodec::m_critSection);
103     ::avfilter_free(filter);
104   }
105   virtual void avfilter_graph_free(AVFilterGraph **graph)
106   {
107     CSingleLock lock(DllAvCodec::m_critSection);
108     ::avfilter_graph_free(graph);
109   }
110   void avfilter_register_all()
111   {
112     CSingleLock lock(DllAvCodec::m_critSection);
113     ::avfilter_register_all();
114   }
115   virtual int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt, const char *name, const char *args, void *opaque, AVFilterGraph *graph_ctx) { return ::avfilter_graph_create_filter(filt_ctx, filt, name, args, opaque, graph_ctx); }
116   virtual AVFilter *avfilter_get_by_name(const char *name) { return ::avfilter_get_by_name(name); }
117   virtual AVFilterGraph *avfilter_graph_alloc() { return ::avfilter_graph_alloc(); }
118   virtual AVFilterInOut *avfilter_inout_alloc()
119   {
120     CSingleLock lock(DllAvCodec::m_critSection);
121     return ::avfilter_inout_alloc();
122   }
123   virtual void avfilter_inout_free(AVFilterInOut **inout)
124   {
125     CSingleLock lock(DllAvCodec::m_critSection);
126     ::avfilter_inout_free(inout);
127   }
128   virtual int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs, void *log_ctx)
129   {
130     CSingleLock lock(DllAvCodec::m_critSection);
131     return ::avfilter_graph_parse(graph, filters, inputs, outputs, log_ctx);
132   }
133   virtual int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
134   {
135     return ::avfilter_graph_config(graphctx, log_ctx);
136   }
137 #if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(3,0,0)
138   virtual int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, int flags) { return ::av_vsrc_buffer_add_frame(buffer_filter, frame, flags); }
139 #else
140   virtual int av_buffersrc_add_frame(AVFilterContext *buffer_filter, AVFrame* frame, int flags) { return ::av_buffersrc_add_frame(buffer_filter, frame, flags); }
141 #endif
142   virtual void avfilter_unref_buffer(AVFilterBufferRef *ref) { ::avfilter_unref_buffer(ref); }
143   virtual int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad) { return ::avfilter_link(src, srcpad, dst, dstpad); }
144   virtual int av_buffersink_get_buffer_ref(AVFilterContext *buffer_sink, AVFilterBufferRef **bufref, int flags) { return ::av_buffersink_get_buffer_ref(buffer_sink, bufref, flags); }
145   virtual AVBufferSinkParams *av_buffersink_params_alloc() { return ::av_buffersink_params_alloc(); }
146   virtual int av_buffersink_poll_frame(AVFilterContext *ctx) { return ::av_buffersink_poll_frame(ctx); }
147   // DLL faking.
148   virtual bool ResolveExports() { return true; }
149   virtual bool Load() {
150 #if !defined(TARGET_DARWIN)
151     CLog::Log(LOGDEBUG, "DllAvFilter: Using libavfilter system library");
152 #endif
153     return true;
154   }
155   virtual void Unload() {}
156 };
157 #else
158 class DllAvFilter : public DllDynamic, DllAvFilterInterface
159 {
160   DECLARE_DLL_WRAPPER(DllAvFilter, DLL_PATH_LIBAVFILTER)
161
162   LOAD_SYMBOLS()
163
164   DEFINE_METHOD3(int, avfilter_open_dont_call, (AVFilterContext **p1, AVFilter *p2, const char *p3))
165   DEFINE_METHOD1(void, avfilter_free_dont_call, (AVFilterContext *p1))
166   DEFINE_METHOD1(void, avfilter_graph_free_dont_call, (AVFilterGraph **p1))
167   DEFINE_METHOD0(void, avfilter_register_all_dont_call)
168   DEFINE_METHOD6(int, avfilter_graph_create_filter, (AVFilterContext **p1, AVFilter *p2, const char *p3, const char *p4, void *p5, AVFilterGraph *p6))
169   DEFINE_METHOD1(AVFilter*, avfilter_get_by_name, (const char *p1))
170   DEFINE_METHOD0(AVFilterGraph*, avfilter_graph_alloc)
171   DEFINE_METHOD0(AVFilterInOut*, avfilter_inout_alloc_dont_call)
172   DEFINE_METHOD1(void, avfilter_inout_free_dont_call, (AVFilterInOut **p1))
173   DEFINE_FUNC_ALIGNED5(int, __cdecl, avfilter_graph_parse_dont_call, AVFilterGraph *, const char *, AVFilterInOut **, AVFilterInOut **, void *)
174   DEFINE_FUNC_ALIGNED2(int, __cdecl, avfilter_graph_config_dont_call, AVFilterGraph *, void *)
175 #if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(3,0,0)
176   DEFINE_METHOD3(int, av_vsrc_buffer_add_frame, (AVFilterContext *p1, AVFrame *p2, int p3))
177 #else
178   DEFINE_METHOD3(int, av_buffersrc_add_frame, (AVFilterContext *p1, AVFrame *p2, int p3))
179 #endif
180   DEFINE_METHOD1(void, avfilter_unref_buffer, (AVFilterBufferRef *p1))
181   DEFINE_METHOD4(int, avfilter_link, (AVFilterContext *p1, unsigned p2, AVFilterContext *p3, unsigned p4))
182   DEFINE_FUNC_ALIGNED3(int                , __cdecl, av_buffersink_get_buffer_ref, AVFilterContext *, AVFilterBufferRef **, int);
183   DEFINE_FUNC_ALIGNED0(AVBufferSinkParams*, __cdecl, av_buffersink_params_alloc);
184   DEFINE_FUNC_ALIGNED1(int                , __cdecl, av_buffersink_poll_frame, AVFilterContext *);
185
186   BEGIN_METHOD_RESOLVE()
187     RESOLVE_METHOD_RENAME(avfilter_open, avfilter_open_dont_call)
188     RESOLVE_METHOD_RENAME(avfilter_free, avfilter_free_dont_call)
189     RESOLVE_METHOD_RENAME(avfilter_graph_free, avfilter_graph_free_dont_call)
190     RESOLVE_METHOD_RENAME(avfilter_register_all, avfilter_register_all_dont_call)
191     RESOLVE_METHOD(avfilter_graph_create_filter)
192     RESOLVE_METHOD(avfilter_get_by_name)
193     RESOLVE_METHOD(avfilter_graph_alloc)
194     RESOLVE_METHOD_RENAME(avfilter_inout_alloc, avfilter_inout_alloc_dont_call)
195     RESOLVE_METHOD_RENAME(avfilter_inout_free, avfilter_inout_free_dont_call)
196     RESOLVE_METHOD_RENAME(avfilter_graph_parse, avfilter_graph_parse_dont_call)
197     RESOLVE_METHOD_RENAME(avfilter_graph_config, avfilter_graph_config_dont_call)
198 #if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(3,0,0)
199     RESOLVE_METHOD(av_vsrc_buffer_add_frame)
200 #else
201     RESOLVE_METHOD(av_buffersrc_add_frame)
202 #endif
203     RESOLVE_METHOD(avfilter_unref_buffer)
204     RESOLVE_METHOD(avfilter_link)
205     RESOLVE_METHOD(av_buffersink_get_buffer_ref)
206     RESOLVE_METHOD(av_buffersink_params_alloc)
207     RESOLVE_METHOD(av_buffersink_poll_frame)
208   END_METHOD_RESOLVE()
209
210   /* dependencies of libavfilter */
211   DllAvUtil m_dllAvUtil;
212   DllSwResample m_dllSwResample;
213   DllAvFormat m_dllAvFormat;
214
215 public:
216   int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name)
217   {
218     CSingleLock lock(DllAvCodec::m_critSection);
219     return avfilter_open_dont_call(filter_ctx, filter, inst_name);
220   }
221   void avfilter_free(AVFilterContext *filter)
222   {
223     CSingleLock lock(DllAvCodec::m_critSection);
224     avfilter_free_dont_call(filter);
225   }
226   void avfilter_graph_free(AVFilterGraph **graph)
227   {
228     CSingleLock lock(DllAvCodec::m_critSection);
229     avfilter_graph_free_dont_call(graph);
230   }
231   void avfilter_register_all()
232   {
233     CSingleLock lock(DllAvCodec::m_critSection);
234     avfilter_register_all_dont_call();
235   }
236   AVFilterInOut* avfilter_inout_alloc()
237   {
238     CSingleLock lock(DllAvCodec::m_critSection);
239     return avfilter_inout_alloc_dont_call();
240   }
241   int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs, void *log_ctx)
242   {
243     CSingleLock lock(DllAvCodec::m_critSection);
244     return avfilter_graph_parse_dont_call(graph, filters, inputs, outputs, log_ctx);
245   }
246   void avfilter_inout_free(AVFilterInOut **inout)
247   {
248     CSingleLock lock(DllAvCodec::m_critSection);
249     avfilter_inout_free_dont_call(inout);
250   }
251   int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
252   {
253     CSingleLock lock(DllAvCodec::m_critSection);
254     return avfilter_graph_config_dont_call(graphctx, log_ctx);
255   }
256   virtual bool Load()
257   {
258     if (!m_dllAvUtil.Load())
259       return false;
260     if (!m_dllSwResample.Load())
261       return false;
262     if (!m_dllAvFormat.Load())
263       return false;
264     return DllDynamic::Load();
265   }
266 };
267 #endif