[MPlayer-dev-eng] [PATCH] win32 codec path

Joey Parrish joey at nicewarrior.org
Wed Aug 6 21:41:37 CEST 2003


On Wed, Aug 06, 2003 at 12:58:35PM -0500, Joey Parrish wrote:
> On Wed, Aug 06, 2003 at 10:54:18AM -0500, Joey Parrish wrote:
> > Here is a quick patch that attempts to set the PATH environment variable
> > before loading codecs in native win32.  This is untested at the moment.
> > But via ssh I can see that it compiles, and from MSDN I can see that it
> > is logically sound.  So I expect it to work.  Please test and report
> > your results.  If this works, then IMHO it is fairly clean and should be
> > applied to main.
> > 
> > I apologize for sending untested code, but I don't have enough free time
> > right now to install/test binary codecs while I'm away from my computer.
> 
> Say, I found the first problem!  :)
> I was still thinking in terms of the way I've been packaging things.  In
> cygwin environment, most people will have unix style codec paths, so I
> probably shouldn't pass those to the windows environment "as is."
>     SetEnvironmentVariableA("PATH", WIN32_PATH);

Here's a better patch!

For real codecs, REALCODEC_PATH was used over and over and sanity
checked and such, plus I have to convert it to a win32 path on cygwin...
So now I have moved some of that stuff to a function called
sanitize_path(), and that is called once on REALCODEC_PATH.  That will
convert to win32 path under cygwin, make sure a / or \ is appended to
the path.  Then the full path is used to LoadLibrary for both windows
and linux.  Thus, no need to set environment variables.

For qt codecs, WIN32_PATH is set as the PATH just before LoadLibrary.

For dmo, dshow, etc, it acts just like qt codecs.

This should take into consideration the differences between cygwin,
mingw, and *nix systems.  Please test.  :)

--Joey
-------------- next part --------------
diff -ur main.sofar/libmpcodecs/ad_qtaudio.c main.dev/libmpcodecs/ad_qtaudio.c
--- main.sofar/libmpcodecs/ad_qtaudio.c	2003-08-06 13:02:27.000000000 -0500
+++ main.dev/libmpcodecs/ad_qtaudio.c	2003-08-06 13:55:12.000000000 -0500
@@ -82,12 +82,20 @@
 HMODULE   WINAPI LoadLibraryA(LPCSTR);
 FARPROC   WINAPI GetProcAddress(HMODULE,LPCSTR);
 int       WINAPI FreeLibrary(HMODULE);
+int       WINAPI SetEnvironmentVariableA(LPCSTR,LPCSTR);
 
 static int loader_init()
 {
 
 #ifdef WIN32_LOADER
     Setup_LDT_Keeper();
+#else // native windows loader, supply the dll path
+# ifdef __CYGWIN__
+    { char winpath[MAX_PATH]; cygwin_conv_to_full_win32_path(WIN32_PATH, winpath);
+    SetEnvironmentVariableA("PATH", winpath); }
+# else
+    SetEnvironmentVariableA("PATH", WIN32_PATH);
+# endif
 #endif
     qtml_dll = LoadLibraryA("qtmlClient.dll");
     if( qtml_dll == NULL )
diff -ur main.sofar/libmpcodecs/ad_realaud.c main.dev/libmpcodecs/ad_realaud.c
--- main.sofar/libmpcodecs/ad_realaud.c	2003-08-06 13:02:27.000000000 -0500
+++ main.dev/libmpcodecs/ad_realaud.c	2003-08-06 13:54:01.000000000 -0500
@@ -161,8 +161,9 @@
 void* WINAPI LoadLibraryA(char* name);
 void* WINAPI GetProcAddress(void* handle,char *func);
 int WINAPI FreeLibrary(void *handle);
+int WINAPI SetEnvironmentVariableA(LPCSTR,LPCSTR);
 
-static int load_sysm_windows(char *path)
+static int load_syms_windows(char *path)
 {
     void *handle;
     
@@ -205,6 +206,23 @@
 }
 #endif
 
+static char sane_path[MAX_PATH];
+
+// sane should be MAX_PATH long on cygwin, strlen(path)+1 everywhere else
+static void sanitize_path(const char *path, char *sane)
+{
+#ifdef __CYGWIN__
+    cygwin_conv_to_full_win32_path(path, sane);
+#else
+    strcpy(sane, path);
+#endif
+    if(sane[strlen(sane)-1]!='/' && sane[strlen(sane)-1]!='\\'){
+      sane[strlen(sane)+1]=0;
+      sane[strlen(sane)]='/';
+    }
+    sane[strlen(sane)+1]=0;
+}
+
 static int preinit(sh_audio_t *sh){
   // let's check if the driver is available, return 0 if not.
   // (you should do that if you use external lib(s) which is optional)
@@ -213,9 +231,11 @@
   void* prop;
   char *path;
 
-  path = malloc(strlen(REALCODEC_PATH)+strlen(sh->codec->dll)+2);
+  sanitize_path(REALCODEC_PATH, sane_path);
+
+  path = malloc(strlen(sane_path)+strlen(sh->codec->dll)+1);
   if (!path) return 0;
-  sprintf(path, REALCODEC_PATH "/%s", sh->codec->dll);
+  sprintf(path, "%s%s", sane_path, sh->codec->dll);
 
     /* first try to load linux dlls, if failed and we're supporting win32 dlls,
        then try to load the windows ones */
@@ -223,7 +243,7 @@
     if (strstr(sh->codec->dll,".dll") || !load_syms_linux(path))
 #endif
 #ifdef USE_WIN32DLL
-	if (!load_sysm_windows(sh->codec->dll))
+	if (!load_syms_windows(path))
 #endif
     {
 	mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MissingDLLcodec, sh->codec->dll);
@@ -239,13 +259,8 @@
 #endif
       int i;
       // used by 'SIPR'
-      path = realloc(path, strlen(REALCODEC_PATH) + 12);
-      sprintf(path, "DT_Codecs=" REALCODEC_PATH);
-      if(path[strlen(path)-1]!='/'){
-        path[strlen(path)+1]=0;
-        path[strlen(path)]='/';
-      }
-      path[strlen(path)+1]=0;
+      path = realloc(path, strlen(sane_path) + 11);
+      sprintf(path, "DT_Codecs=%s", sane_path);
 #ifdef USE_WIN32DLL
     if (dll_type == 1)
     {
@@ -261,13 +276,13 @@
 #ifdef USE_WIN32DLL
     if (dll_type == 1){
       if(wraOpenCodec2)
-	result=wraOpenCodec2(&sh->context,REALCODEC_PATH "\\");
+	result=wraOpenCodec2(&sh->context,sane_path);
       else
 	result=wraOpenCodec(&sh->context);
     } else
 #endif
     if(raOpenCodec2)
-      result=raOpenCodec2(&sh->context,REALCODEC_PATH "/");
+      result=raOpenCodec2(&sh->context,sane_path);
     else
       result=raOpenCodec(&sh->context);
     if(result){
diff -ur main.sofar/libmpcodecs/vd_qtvideo.c main.dev/libmpcodecs/vd_qtvideo.c
--- main.sofar/libmpcodecs/vd_qtvideo.c	2003-08-06 13:02:27.000000000 -0500
+++ main.dev/libmpcodecs/vd_qtvideo.c	2003-08-06 13:55:01.000000000 -0500
@@ -113,6 +113,13 @@
 
 #ifdef WIN32_LOADER
     Setup_LDT_Keeper();
+#else // native windows loader, supply the dll path
+# ifdef __CYGWIN__
+    { char winpath[MAX_PATH]; cygwin_conv_to_full_win32_path(WIN32_PATH, winpath);
+    SetEnvironmentVariableA("PATH", winpath); }
+# else
+    SetEnvironmentVariableA("PATH", WIN32_PATH);
+# endif
 #endif
 
     handler = LoadLibraryA("qtmlClient.dll");
diff -ur main.sofar/libmpcodecs/vd_realvid.c main.dev/libmpcodecs/vd_realvid.c
--- main.sofar/libmpcodecs/vd_realvid.c	2003-08-06 13:02:27.000000000 -0500
+++ main.dev/libmpcodecs/vd_realvid.c	2003-08-06 13:54:08.000000000 -0500
@@ -188,6 +188,23 @@
 	int format;
 } rv_init_t;
 
+static char sane_path[MAX_PATH];
+
+// sane should be MAX_PATH long on cygwin, strlen(path)+1 everywhere else
+static void sanitize_path(const char *path, char *sane)
+{
+#ifdef __CYGWIN__
+    cygwin_conv_to_full_win32_path(path, sane);
+#else
+    strcpy(sane, path);
+#endif
+    if(sane[strlen(sane)-1]!='/' && sane[strlen(sane)-1]!='\\'){
+      sane[strlen(sane)+1]=0;
+      sane[strlen(sane)]='/';
+    }
+    sane[strlen(sane)+1]=0;
+}
+
 // init driver
 static int init(sh_video_t *sh){
 	//unsigned int out_fmt;
@@ -199,11 +217,13 @@
 		11, sh->disp_w, sh->disp_h,0,0,extrahdr[0],
 		1,extrahdr[1]}; // rv30
 
+        sanitize_path(REALCODEC_PATH, sane_path);
+
 	mp_msg(MSGT_DECVIDEO,MSGL_V,"realvideo codec id: 0x%08X  sub-id: 0x%08X\n",extrahdr[1],extrahdr[0]);
 
-	path = malloc(strlen(REALCODEC_PATH)+strlen(sh->codec->dll)+2);
+	path = malloc(strlen(sane_path)+strlen(sh->codec->dll)+1);
 	if (!path) return 0;
-	sprintf(path, REALCODEC_PATH "/%s", sh->codec->dll);
+	sprintf(path, "%s%s", sane_path, sh->codec->dll);
 
 	/* first try to load linux dlls, if failed and we're supporting win32 dlls,
 	   then try to load the windows ones */
@@ -211,7 +231,7 @@
 	if(strstr(sh->codec->dll,".dll") || !load_syms_linux(path))
 #endif
 #ifdef USE_WIN32DLL
-	    if (!load_syms_windows(sh->codec->dll))
+	    if (!load_syms_windows(path))
 #endif
 	{
 		mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingDLLcodec,sh->codec->dll);
diff -ur main.sofar/libmpcodecs/ve_qtvideo.c main.dev/libmpcodecs/ve_qtvideo.c
--- main.sofar/libmpcodecs/ve_qtvideo.c	2003-08-06 13:02:27.000000000 -0500
+++ main.dev/libmpcodecs/ve_qtvideo.c	2003-08-06 13:55:06.000000000 -0500
@@ -34,6 +34,7 @@
 HMODULE   WINAPI LoadLibraryA(LPCSTR);
 FARPROC   WINAPI GetProcAddress(HMODULE,LPCSTR);
 int       WINAPI FreeLibrary(HMODULE);
+int       WINAPI SetEnvironmentVariableA(LPCSTR,LPCSTR);
 static HMODULE handler;
 
 static OSErr        (*FindCodec)(CodecType              cType,
@@ -294,6 +295,13 @@
 
 #ifdef WIN32_LOADER
     Setup_LDT_Keeper();
+#else // native windows loader, supply the dll path
+# ifdef __CYGWIN__
+    { char winpath[MAX_PATH]; cygwin_conv_to_full_win32_path(WIN32_PATH, winpath);
+    SetEnvironmentVariableA("PATH", winpath); }
+# else
+    SetEnvironmentVariableA("PATH", WIN32_PATH);
+# endif
 #endif
     handler = LoadLibraryA("qtmlClient.dll");
     InitializeQTML = (OSErr (*)(long))GetProcAddress(handler, "InitializeQTML");
diff -ur main.sofar/loader/dmo/dmo.c main.dev/loader/dmo/dmo.c
--- main.sofar/loader/dmo/dmo.c	2003-08-06 13:02:27.000000000 -0500
+++ main.dev/loader/dmo/dmo.c	2003-08-06 12:38:54.000000000 -0500
@@ -38,6 +38,13 @@
     memset(This, 0, sizeof(DMO_Filter));
 #ifdef WIN32_LOADER
     CodecAlloc();
+#else // native windows loader, supply the dll path
+# ifdef __CYGWIN__
+    { char winpath[MAX_PATH]; cygwin_conv_to_full_win32_path(WIN32_PATH, winpath);
+    SetEnvironmentVariableA("PATH", winpath); }
+# else
+    SetEnvironmentVariableA("PATH", WIN32_PATH);
+# endif
 #endif
 
     //This->Start = DS_Filter_Start;
diff -ur main.sofar/loader/driver.c main.dev/loader/driver.c
--- main.sofar/loader/driver.c	2003-08-06 13:02:27.000000000 -0500
+++ main.dev/loader/driver.c	2003-08-06 12:38:54.000000000 -0500
@@ -161,6 +161,13 @@
 #ifdef WIN32_LOADER
     CodecAlloc();
     Setup_FS_Segment();
+#else // native windows loader, supply the dll path
+# ifdef __CYGWIN__
+    { char winpath[MAX_PATH]; cygwin_conv_to_full_win32_path(WIN32_PATH, winpath);
+    SetEnvironmentVariableA("PATH", winpath); }
+# else
+    SetEnvironmentVariableA("PATH", WIN32_PATH);
+# endif
 #endif
 
     hDriver->hDriverModule = LoadLibraryA(filename);
diff -ur main.sofar/loader/dshow/DS_Filter.c main.dev/loader/dshow/DS_Filter.c
--- main.sofar/loader/dshow/DS_Filter.c	2003-08-06 13:02:27.000000000 -0500
+++ main.dev/loader/dshow/DS_Filter.c	2003-08-06 12:38:54.000000000 -0500
@@ -117,6 +117,13 @@
     CodecAlloc();
 #else
     CoInitialize(0L);
+    // native windows loader, supply the dll path
+# ifdef __CYGWIN__
+    { char winpath[MAX_PATH]; cygwin_conv_to_full_win32_path(WIN32_PATH, winpath);
+    SetEnvironmentVariableA("PATH", winpath); }
+# else
+    SetEnvironmentVariableA("PATH", WIN32_PATH);
+# endif
 #endif
 
     This->m_pFilter = NULL;


More information about the MPlayer-dev-eng mailing list