Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

driver.c

00001 /*
00002  * Modified for use with MPlayer, detailed CVS changelog at
00003  * http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
00004  * $Id: driver.c 11593 2005-06-28 18:02:01Z courmisch $
00005  */
00006 
00007 #include "config.h"
00008 
00009 #include <stdio.h>
00010 #ifdef HAVE_MALLOC_H
00011 #include <malloc.h>
00012 #endif
00013 #include <stdlib.h>
00014 #ifdef __FreeBSD__
00015 #include <sys/time.h>
00016 #endif
00017 
00018 #include "win32.h"
00019 #include "wine/driver.h"
00020 #include "wine/pe_image.h"
00021 #include "wine/winreg.h"
00022 #include "wine/vfw.h"
00023 #include "registry.h"
00024 #ifdef WIN32_LOADER
00025 #include "ldt_keeper.h"
00026 #endif
00027 #include "driver.h"
00028 #ifndef __MINGW32__
00029 #include "ext.h"
00030 #endif
00031 
00032 #ifndef WIN32_LOADER
00033 char* def_path=WIN32_PATH;
00034 #else
00035 extern char* def_path;
00036 #endif
00037 
00038 #if 1
00039 
00040 /*
00041  * STORE_ALL/REST_ALL seems like an attempt to workaround problems due to
00042  * WINAPI/no-WINAPI bustage.
00043  *
00044  * There should be no need for the STORE_ALL/REST_ALL hack once all
00045  * function definitions agree with their prototypes (WINAPI-wise) and
00046  * we make sure, that we do not call these functions without a proper
00047  * prototype in scope.
00048  */
00049 
00050 #define STORE_ALL
00051 #define REST_ALL
00052 #else
00053 // this asm code is no longer needed
00054 #define STORE_ALL \
00055     __asm__ __volatile__ ( \
00056     "push %%ebx\n\t" \
00057     "push %%ecx\n\t" \
00058     "push %%edx\n\t" \
00059     "push %%esi\n\t" \
00060     "push %%edi\n\t"::)
00061 
00062 #define REST_ALL \
00063     __asm__ __volatile__ ( \
00064     "pop %%edi\n\t" \
00065     "pop %%esi\n\t" \
00066     "pop %%edx\n\t" \
00067     "pop %%ecx\n\t" \
00068     "pop %%ebx\n\t"::)
00069 #endif
00070 
00071 static int needs_free=0;
00072 void SetCodecPath(const char* path)
00073 {
00074     if(needs_free)free(def_path);
00075     if(path==0)
00076     {
00077         def_path=WIN32_PATH;
00078         needs_free=0;
00079         return;
00080     }
00081     def_path = (char*) malloc(strlen(path)+1);
00082     strcpy(def_path, path);
00083     needs_free=1;
00084 }
00085 
00086 static DWORD dwDrvID = 0;
00087 
00088 LRESULT WINAPI SendDriverMessage(HDRVR hDriver, UINT message,
00089                                  LPARAM lParam1, LPARAM lParam2)
00090 {
00091     DRVR* module=(DRVR*)hDriver;
00092     int result;
00093 #ifndef __svr4__
00094     char qw[300];
00095 #endif
00096 #ifdef DETAILED_OUT
00097     printf("SendDriverMessage: driver %X, message %X, arg1 %X, arg2 %X\n", hDriver, message, lParam1, lParam2);
00098 #endif
00099     if (!module || !module->hDriverModule || !module->DriverProc) return -1;
00100 #ifndef __svr4__
00101     __asm__ __volatile__ ("fsave (%0)\n\t": :"r"(&qw));
00102 #endif
00103 
00104 #ifdef WIN32_LOADER
00105     Setup_FS_Segment();
00106 #endif
00107 
00108     STORE_ALL;
00109     result=module->DriverProc(module->dwDriverID, hDriver, message, lParam1, lParam2);
00110     REST_ALL;
00111 
00112 #ifndef __svr4__
00113     __asm__ __volatile__ ("frstor (%0)\n\t": :"r"(&qw));
00114 #endif
00115 
00116 #ifdef DETAILED_OUT
00117     printf("\t\tResult: %X\n", result);
00118 #endif
00119     return result;
00120 }
00121 
00122 void DrvClose(HDRVR hDriver)
00123 {
00124     if (hDriver)
00125     {
00126         DRVR* d = (DRVR*)hDriver;
00127         if (d->hDriverModule)
00128         {
00129 #ifdef WIN32_LOADER
00130             Setup_FS_Segment();
00131 #endif
00132             if (d->DriverProc)
00133             {
00134                 SendDriverMessage(hDriver, DRV_CLOSE, 0, 0);
00135                 d->dwDriverID = 0;
00136                 SendDriverMessage(hDriver, DRV_FREE, 0, 0);
00137             }
00138             FreeLibrary(d->hDriverModule);
00139         }
00140         free(d);
00141     }
00142 #ifdef WIN32_LOADER
00143     CodecRelease();
00144 #endif
00145 }
00146 
00147 //DrvOpen(LPCSTR lpszDriverName, LPCSTR lpszSectionName, LPARAM lParam2)
00148 HDRVR DrvOpen(LPARAM lParam2)
00149 {
00150     NPDRVR hDriver;
00151     int i;
00152     char unknown[0x124];
00153     const char* filename = (const char*) ((ICOPEN*) lParam2)->pV1Reserved;
00154 
00155 #ifdef MPLAYER
00156 #ifdef WIN32_LOADER
00157     Setup_LDT_Keeper();
00158 #endif
00159     printf("Loading codec DLL: '%s'\n",filename);
00160 #endif
00161 
00162     hDriver = (NPDRVR) malloc(sizeof(DRVR));
00163     if (!hDriver)
00164         return ((HDRVR) 0);
00165     memset((void*)hDriver, 0, sizeof(DRVR));
00166 
00167 #ifdef WIN32_LOADER
00168     CodecAlloc();
00169     Setup_FS_Segment();
00170 #endif
00171 
00172     hDriver->hDriverModule = LoadLibraryA(filename);
00173     if (!hDriver->hDriverModule)
00174     {
00175         printf("Can't open library %s\n", filename);
00176         DrvClose((HDRVR)hDriver);
00177         return ((HDRVR) 0);
00178     }
00179 
00180     hDriver->DriverProc = (DRIVERPROC) GetProcAddress(hDriver->hDriverModule,
00181                                                       "DriverProc");
00182     if (!hDriver->DriverProc)
00183     {
00184         printf("Library %s is not a valid VfW/ACM codec\n", filename);
00185         DrvClose((HDRVR)hDriver);
00186         return ((HDRVR) 0);
00187     }
00188 
00189     TRACE("DriverProc == %X\n", hDriver->DriverProc);
00190     SendDriverMessage((HDRVR)hDriver, DRV_LOAD, 0, 0);
00191     TRACE("DRV_LOAD Ok!\n");
00192     SendDriverMessage((HDRVR)hDriver, DRV_ENABLE, 0, 0);
00193     TRACE("DRV_ENABLE Ok!\n");
00194     hDriver->dwDriverID = ++dwDrvID; // generate new id
00195 
00196     // open driver and remmeber proper DriverID
00197     hDriver->dwDriverID = SendDriverMessage((HDRVR)hDriver, DRV_OPEN, (LPARAM) unknown, lParam2);
00198     TRACE("DRV_OPEN Ok!(%X)\n", hDriver->dwDriverID);
00199 
00200     printf("Loaded DLL driver %s at %x\n", filename, hDriver->hDriverModule);
00201     return (HDRVR)hDriver;
00202 }

Generated on Tue Dec 20 10:14:20 2005 for vlc-0.8.4a by  doxygen 1.4.2