]> git.sesse.net Git - vlc/blobdiff - src/misc/win32_specific.c
* src/libvlc.h: disabled the encoders config options (encoders are not used anymore...
[vlc] / src / misc / win32_specific.c
index 513737bcc68de7cefacdc5d8a3e675eac9e7d27c..b26200dca8c2975c06efc1f6797881fff5e6fcb3 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
- * win32_specific.c: Win32 specific features 
+ * win32_specific.c: Win32 specific features
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: win32_specific.c,v 1.13 2002/07/29 19:05:47 gbazin Exp $
+ * $Id: win32_specific.c,v 1.23 2003/07/18 20:52:11 gbazin Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *          Gildas Bazin <gbazin@netcourrier.com>
@@ -11,7 +11,7 @@
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
-#include <errno.h>                                                 /* ENOMEM */
 #include <string.h>                                              /* strdup() */
 #include <stdlib.h>                                                /* free() */
-#include <fcntl.h>
-
-#include <winsock2.h>
 
 #include <vlc/vlc.h>
 
+#if !defined( UNDER_CE )
+#   include <fcntl.h>
+#   include <winsock2.h>
+#endif
+
 /*****************************************************************************
  * system_Init: initialize winsock and misc other things.
  *****************************************************************************/
 void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
 {
+#if !defined( UNDER_CE )
     WSADATA Data;
-    int i_err;
-    HINSTANCE hInstLib;
 
-    /* dynamically get the address of SignalObjectAndWait */
-    if( (GetVersion() < 0x80000000) )
+    /* Get our full path */
+    if( ppsz_argv[0] )
+    {
+        char psz_path[MAX_PATH];
+        char *psz_vlc;
+
+        GetFullPathName( ppsz_argv[0], MAX_PATH, psz_path, &psz_vlc );
+
+        if( psz_vlc > psz_path && psz_vlc[-1] == '\\' )
+        {
+            psz_vlc[-1] = '\0';
+            p_this->p_libvlc->psz_vlcpath = strdup( psz_path );
+        }
+        else
+        {
+            p_this->p_libvlc->psz_vlcpath = strdup( "" );
+        }
+    }
+    else
     {
-        /* We are running on NT/2K/XP, we can use SignalObjectAndWait */
-        hInstLib = LoadLibrary( "kernel32" );
-        if( hInstLib)
-            p_this->p_vlc->SignalObjectAndWait =
-                (SIGNALOBJECTANDWAIT)GetProcAddress( hInstLib,
-                                                     "SignalObjectAndWait" );
+        p_this->p_libvlc->psz_vlcpath = strdup( "" );
     }
-    else p_this->p_vlc->SignalObjectAndWait = NULL;
+
+    /* Set the default file-translation mode */
+    _fmode = _O_BINARY;
 
     /* WinSock Library Init. */
-    i_err = WSAStartup( MAKEWORD( 1, 1 ), &Data );
+    if( !WSAStartup( MAKEWORD( 2, 0 ), &Data ) )
+    {
+        /* Confirm that the WinSock DLL supports 2.0.*/
+        if( LOBYTE( Data.wVersion ) != 2 || HIBYTE( Data.wVersion ) != 0 )
+        {
+            /* We could not find a suitable WinSock DLL. */
+            WSACleanup( );
+        }
+        else
+        {
+            /* Everything went ok. */
+            return;
+        }
+    }
 
-    if( i_err )
+    /* Let's try with WinSock 1.1 */
+    if( !WSAStartup( MAKEWORD( 1, 1 ), &Data ) )
     {
-        fprintf( stderr, "error: can't initiate WinSocks, error %i\n", i_err );
+        /* Confirm that the WinSock DLL supports 1.1.*/
+        if( LOBYTE( Data.wVersion ) != 1 || HIBYTE( Data.wVersion ) != 1 )
+        {
+            /* We could not find a suitable WinSock DLL. */
+            WSACleanup( );
+        }
+        else
+        {
+            /* Everything went ok. */
+            return;
+        }
     }
 
-    _fmode = _O_BINARY;  /* sets the default file-translation mode */
+    fprintf( stderr, "error: can't initialize WinSocks\n" );
+
+    return; 
+
+#endif
 }
 
 /*****************************************************************************
@@ -67,8 +109,27 @@ void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
  *****************************************************************************/
 void system_Configure( vlc_t *p_this )
 {
-    p_this->p_vlc->b_fast_mutex = config_GetInt( p_this, "fast-mutex" );
-    p_this->p_vlc->i_win9x_cv = config_GetInt( p_this, "win9x-cv-method" );
+#if !defined( UNDER_CE )
+    p_this->p_libvlc->b_fast_mutex = config_GetInt( p_this, "fast-mutex" );
+    p_this->p_libvlc->i_win9x_cv = config_GetInt( p_this, "win9x-cv-method" );
+
+    /* Raise default priority of the current process */
+#ifndef ABOVE_NORMAL_PRIORITY_CLASS
+#   define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000
+#endif
+    if( config_GetInt( p_this, "high-priority" ) &&
+        !SetPriorityClass( GetCurrentProcess(),
+                           ABOVE_NORMAL_PRIORITY_CLASS ) )
+    {
+        if( !SetPriorityClass( GetCurrentProcess(),
+                               HIGH_PRIORITY_CLASS ) )
+            msg_Dbg( p_this, "can't raise process priority" );
+        else
+            msg_Dbg( p_this, "raised process priority" );
+    }
+    else
+       msg_Dbg( p_this, "raised process priority" );
+#endif
 }
 
 /*****************************************************************************
@@ -76,5 +137,7 @@ void system_Configure( vlc_t *p_this )
  *****************************************************************************/
 void system_End( vlc_t *p_this )
 {
+#if !defined( UNDER_CE )
     WSACleanup();
+#endif
 }