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

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


the patches removes unneeded wine cruft,
but windows.h must be included before internal
headers otherwise BITMAPINFOHEADER declaration in libmpdemux/ms_hdr.h
will conflict with mingw headers
---
 Makefile               |  2 +-
 libmpdemux/demux_avs.c | 62 ++++++++++++++++++++++++--------------------------
 libmpdemux/demuxer.c   |  2 --
 3 files changed, 31 insertions(+), 35 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 d01c1b7..2a0af46 100644
--- a/libmpdemux/demux_avs.c
+++ b/libmpdemux/demux_avs.c
@@ -24,6 +24,25 @@
 #include <unistd.h>
 #include <limits.h>
 
+#ifdef WIN32
+  #include <windows.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"
+
 #include "config.h"
 #include "mp_msg.h"
 #include "help_mp.h"
@@ -33,14 +52,6 @@
 #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"
-#endif
-
-#include "avisynth_c.h"
 
 #define MAX_AVS_SIZE    16 * 1024 /* 16k should be enough */
 
@@ -55,7 +66,7 @@ typedef AVSC_CC int (*imp_avs_get_audio)(AVS_Clip *, void * buf, INT64 start, IN
 
 #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 +75,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 sampleno;
     int init;
@@ -88,18 +96,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 +138,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 +387,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 +461,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