[MPlayer-dev-eng] [PATCH 3/3] demux_avs: unix port using avxsynth

Gianluigi Tiesi mplayer at netfarm.it
Mon Nov 4 07:13:18 CET 2013


---
 Makefile               |  2 +-
 libmpdemux/demux_avs.c | 57 +++++++++++++++++++++++++-------------------------
 libmpdemux/demuxer.c   |  2 --
 3 files changed, 29 insertions(+), 32 deletions(-)

diff --git a/Makefile b/Makefile
index 2119cda..c959a13 100644
--- a/Makefile
+++ b/Makefile
@@ -246,7 +246,6 @@ SRCS_COMMON-$(WIN32DLL)              += libmpcodecs/ad_acm.c            \
                                         libmpcodecs/vd_dsnative.c       \
                                         libmpcodecs/vd_vfw.c            \
                                         libmpcodecs/vd_vfwex.c          \
-                                        libmpdemux/demux_avs.c          \
                                         loader/afl.c                    \
                                         loader/drv.c                    \
                                         loader/vfl.c                    \
@@ -415,6 +414,7 @@ SRCS_COMMON = asxparser.c                       \
               libmpdemux/demux_asf.c            \
               libmpdemux/demux_audio.c          \
               libmpdemux/demux_avi.c            \
+              libmpdemux/demux_avs.c            \
               libmpdemux/demux_demuxers.c       \
               libmpdemux/demux_film.c           \
               libmpdemux/demux_fli.c            \
diff --git a/libmpdemux/demux_avs.c b/libmpdemux/demux_avs.c
index 2753635..816be27 100644
--- a/libmpdemux/demux_avs.c
+++ b/libmpdemux/demux_avs.c
@@ -33,11 +33,23 @@
 #include "stheader.h"
 #include "libvo/fastmemcpy.h"
 
-#include "loader/wine/winbase.h"
-#include "loader/wine/windef.h"
-
-#ifdef WIN32_LOADER
-#include "loader/ldt_keeper.h"
+#ifdef WIN32
+  #include "loader/wine/winbase.h"
+  #include "loader/wine/windef.h"
+  #define AVISYNTH_LIB "avisynth"
+#else
+  #include <dlfcn.h>
+  #if defined (__APPLE__)
+    #define AVISYNTH_LIB "libavxsynth.dylib"
+  #else
+   #define AVISYNTH_LIB "libavxsynth.so"
+  #endif
+
+  #define LoadLibraryA(x) dlopen(x, RTLD_NOW | RTLD_GLOBAL)
+  #define GetProcAddress dlsym
+  #define FreeLibrary dlclose
+  #define HMODULE void *
+  #define WINAPI
 #endif
 
 #include "avisynth_c.h"
@@ -55,7 +67,7 @@ typedef WINAPI int (*imp_avs_get_audio)(AVS_Clip *, void * buf, uint64_t start,
 
 #define Q(string) # string
 #define IMPORT_FUNC(x) \
-    AVS->x = ( imp_##x ) GetProcAddress(AVS->dll, Q(x)); \
+    AVS->x = ( imp_##x ) GetProcAddress(AVS->library, Q(x)); \
     if (!AVS->x) { mp_msg(MSGT_DEMUX,MSGL_V,"AVS: failed to load "Q(x)"()\n"); return 0; }
 
 typedef struct tagAVS
@@ -64,10 +76,7 @@ typedef struct tagAVS
     AVS_Value handler;
     AVS_Clip *clip;
     const AVS_VideoInfo *video_info;
-#ifdef WIN32_LOADER
-    ldt_fs_t* ldt_fs;
-#endif
-    HMODULE dll;
+    HMODULE library;
     int frameno;
     int64_t sampleno;
     int init;
@@ -88,18 +97,14 @@ static AVS_T *initAVS(const char *filename)
     AVS_Value arg0 = avs_new_value_string(filename);
     AVS_Value args = avs_new_value_array(&arg0, 1);
 
-#ifdef WIN32_LOADER
-    AVS->ldt_fs = Setup_LDT_Keeper();
-#endif
-
-    AVS->dll = LoadLibraryA("avisynth.dll");
-    if(!AVS->dll)
+    AVS->library = LoadLibraryA(AVISYNTH_LIB);
+    if(!AVS->library)
     {
-        mp_msg(MSGT_DEMUX ,MSGL_V, "AVS: failed to load avisynth.dll\n");
+        mp_msg(MSGT_DEMUX, MSGL_V, "AVS: failed to load " AVISYNTH_LIB "\n");
         goto avs_err;
     }
 
-    /* Dynamic import of needed stuff from avisynth.dll */
+    /* Dynamic import of needed stuff from avisynth library */
     IMPORT_FUNC(avs_create_script_environment);
     IMPORT_FUNC(avs_invoke);
     IMPORT_FUNC(avs_get_video_info);
@@ -134,10 +139,7 @@ static AVS_T *initAVS(const char *filename)
     return AVS;
 
 avs_err:
-    if (AVS->dll) FreeLibrary(AVS->dll);
-#ifdef WIN32_LOADER
-    Restore_LDT_Keeper(AVS->ldt_fs);
-#endif
+    if (AVS->library) FreeLibrary(AVS->library);
     free(AVS);
     return NULL;
 }
@@ -386,16 +388,13 @@ static void demux_close_avs(demuxer_t* demuxer)
 
     if (AVS)
     {
-        if (AVS->dll)
+        if (AVS->library)
         {
             if (AVS->clip)
                 AVS->avs_release_clip(AVS->clip);
-            mp_msg(MSGT_DEMUX, MSGL_V, "AVS: Unloading avisynth.dll\n");
-            FreeLibrary(AVS->dll);
+            mp_msg(MSGT_DEMUX, MSGL_V, "AVS: Unloading " AVISYNTH_LIB "\n");
+            FreeLibrary(AVS->library);
         }
-#ifdef WIN32_LOADER
-        Restore_LDT_Keeper(AVS->ldt_fs);
-#endif
         free(AVS);
     }
 }
@@ -463,7 +462,7 @@ const demuxer_desc_t demuxer_desc_avs = {
   "avs",
   "AVS",
   "Gianluigi Tiesi",
-  "Requires binary dll",
+  "Requires binary library",
   DEMUXER_TYPE_AVS,
   0, // unsafe autodetect
   avs_check_file,
diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c
index 153cd45..65afc54 100644
--- a/libmpdemux/demuxer.c
+++ b/libmpdemux/demuxer.c
@@ -152,9 +152,7 @@ const demuxer_desc_t *const demuxer_list[] = {
 #ifdef CONFIG_OGGVORBIS
     &demuxer_desc_ogg,
 #endif
-#ifdef CONFIG_WIN32DLL
     &demuxer_desc_avs,
-#endif
     &demuxer_desc_pva,
     &demuxer_desc_mpeg_ts,
     &demuxer_desc_lmlm4,
-- 
1.8.4.2


-- 
Gianluigi Tiesi <sherpya at netfarm.it>
EDP Project Leader
Netfarm S.r.l. - http://www.netfarm.it/
Free Software: http://oss.netfarm.it/


More information about the MPlayer-dev-eng mailing list