1 #pragma once
2 
3 #include "ADM_dynamicLoading.h"
4 
5 #if !defined(__APPLE__) && !defined(_WIN32)
6  #include <dlfcn.h>
7 #endif
8 
9 
10 
11 
12 #ifdef __APPLE__
13         #define  DLL_TO_LOAD "libvapoursynth-script.dylib"
14         #define  PYTHONLIB ""
15 #else
16     #ifdef _WIN32
17         #define  DLL_TO_LOAD "vsscript.dll"
18         #define  PYTHONLIB ""
19     #else
20         #define  DLL_TO_LOAD "libvapoursynth-script.so"
21         #define  PYTHONLIB VAPOURSYNTH_PYTHONLIB
22     #endif
23 #endif
24 
25 
26 /**
27  *
28  */
29 class vsDynaLoader:public ADM_LibWrapper
30 {
31 public:
32 
vsDynaLoader()33     vsDynaLoader()
34     {
35       init=NULL;
36       getVSApi=NULL;
37       freeScript=NULL;
38       finalize=NULL;
39       getError=NULL;
40       getOutput=NULL;
41       evaluateFile=NULL;
42       operational=false;
43     }
vsInit(const char * dllName,const char * pythonLib)44     bool vsInit(const char *dllName,const char *pythonLib)
45     {
46 #if !defined(__APPLE__) && !defined(_WIN32)
47       ADM_info("Trying to dlopen %s\n",VAPOURSYNTH_PYTHONLIB);
48       dlopen(VAPOURSYNTH_PYTHONLIB, RTLD_LAZY|RTLD_GLOBAL);
49 #endif
50       bool loaded= loadLibrary(dllName);
51       if(!loaded)
52       {
53           ADM_warning("Cannot load the vapoursynth-script library\n");
54           return false;
55       }
56       if(!     ADM_LibWrapper::getSymbols(7,
57 				&init,          "vsscript_init",
58                                 &getVSApi,      "vsscript_getVSApi",
59                                 &freeScript,    "vsscript_freeScript",
60                                 &finalize,      "vsscript_finalize",
61                                 &getError,      "vsscript_getError",
62                                 &getOutput,     "vsscript_getOutput",
63                                 &evaluateFile,  "vsscript_evaluateFile"))
64         {
65             ADM_warning("Cannot get symbols from vapoursynthlibrary\n");
66             return false;
67         }
68       operational=true;
69       return true;
70     }
isOperational()71     bool isOperational()
72     {
73       return operational;
74     }
75 public:
76     int             (*init)(void);
77     const VSAPI     *(*getVSApi)(void);
78     void            (*freeScript)(VSScript *handle);
79     int             (*finalize)(void);
80     const char      *(*getError)(VSScript *handle);
81     VSNodeRef *      (*getOutput)(VSScript *handle, int index);
82     int              (*evaluateFile)(VSScript **handle, const char *scriptFilename, int flags);
83 protected:
84     bool             operational;
85 };