Add support for extracting the release version number from a VERSION file.
[mplayer/glamo.git] / loader / drv.c
blobe3fb4da1169bdc4f32ce44753c58cddebd4ee3c4
1 /*
2 * Modified for use with MPlayer, detailed changelog at
3 * http://svn.mplayerhq.hu/mplayer/trunk/
4 */
6 #include "config.h"
7 #include "debug.h"
9 #include <stdio.h>
10 #if HAVE_MALLOC_H
11 #include <malloc.h>
12 #endif
13 #include <stdlib.h>
14 #ifdef __FreeBSD__
15 #include <sys/time.h>
16 #endif
18 #include "win32.h"
19 #include "wine/driver.h"
20 #include "wine/pe_image.h"
21 #include "wine/winreg.h"
22 #include "wine/vfw.h"
23 #include "registry.h"
24 #ifdef WIN32_LOADER
25 #include "ldt_keeper.h"
26 #endif
27 #include "drv.h"
28 #ifndef __MINGW32__
29 #include "ext.h"
30 #endif
32 #ifndef WIN32_LOADER
33 char* def_path=WIN32_PATH;
34 #else
35 extern char* def_path;
36 #endif
38 #if 1
41 * STORE_ALL/REST_ALL seems like an attempt to workaround problems due to
42 * WINAPI/no-WINAPI bustage.
44 * There should be no need for the STORE_ALL/REST_ALL hack once all
45 * function definitions agree with their prototypes (WINAPI-wise) and
46 * we make sure, that we do not call these functions without a proper
47 * prototype in scope.
50 #define STORE_ALL
51 #define REST_ALL
52 #else
53 // this asm code is no longer needed
54 #define STORE_ALL \
55 __asm__ volatile ( \
56 "push %%ebx\n\t" \
57 "push %%ecx\n\t" \
58 "push %%edx\n\t" \
59 "push %%esi\n\t" \
60 "push %%edi\n\t"::)
62 #define REST_ALL \
63 __asm__ volatile ( \
64 "pop %%edi\n\t" \
65 "pop %%esi\n\t" \
66 "pop %%edx\n\t" \
67 "pop %%ecx\n\t" \
68 "pop %%ebx\n\t"::)
69 #endif
71 static int needs_free=0;
72 void SetCodecPath(const char* path)
74 if(needs_free)free(def_path);
75 if(path==0)
77 def_path=WIN32_PATH;
78 needs_free=0;
79 return;
81 def_path = (char*) malloc(strlen(path)+1);
82 strcpy(def_path, path);
83 needs_free=1;
86 static DWORD dwDrvID = 0;
88 LRESULT WINAPI SendDriverMessage(HDRVR hDriver, UINT message,
89 LPARAM lParam1, LPARAM lParam2)
91 DRVR* module=(DRVR*)hDriver;
92 int result;
93 #ifndef __svr4__
94 char qw[300];
95 #endif
96 #ifdef DETAILED_OUT
97 printf("SendDriverMessage: driver %X, message %X, arg1 %X, arg2 %X\n", hDriver, message, lParam1, lParam2);
98 #endif
99 if (!module || !module->hDriverModule || !module->DriverProc) return -1;
100 #ifndef __svr4__
101 __asm__ volatile ("fsave (%0)\n\t": :"r"(&qw));
102 #endif
104 #ifdef WIN32_LOADER
105 Setup_FS_Segment();
106 #endif
108 STORE_ALL;
109 result=module->DriverProc(module->dwDriverID, hDriver, message, lParam1, lParam2);
110 REST_ALL;
112 #ifndef __svr4__
113 __asm__ volatile ("frstor (%0)\n\t": :"r"(&qw));
114 #endif
116 #ifdef DETAILED_OUT
117 printf("\t\tResult: %X\n", result);
118 #endif
119 return result;
122 void DrvClose(HDRVR hDriver)
124 if (hDriver)
126 DRVR* d = (DRVR*)hDriver;
127 if (d->hDriverModule)
129 #ifdef WIN32_LOADER
130 Setup_FS_Segment();
131 #endif
132 if (d->DriverProc)
134 SendDriverMessage(hDriver, DRV_CLOSE, 0, 0);
135 d->dwDriverID = 0;
136 SendDriverMessage(hDriver, DRV_FREE, 0, 0);
138 FreeLibrary(d->hDriverModule);
140 free(d);
142 #ifdef WIN32_LOADER
143 CodecRelease();
144 #endif
147 //DrvOpen(LPCSTR lpszDriverName, LPCSTR lpszSectionName, LPARAM lParam2)
148 HDRVR DrvOpen(LPARAM lParam2)
150 NPDRVR hDriver;
151 char unknown[0x124];
152 const char* filename = (const char*) ((ICOPEN*) lParam2)->pV1Reserved;
154 #ifdef WIN32_LOADER
155 Setup_LDT_Keeper();
156 #endif
157 printf("Loading codec DLL: '%s'\n",filename);
159 hDriver = (NPDRVR) malloc(sizeof(DRVR));
160 if (!hDriver)
161 return (HDRVR) 0;
162 memset((void*)hDriver, 0, sizeof(DRVR));
164 #ifdef WIN32_LOADER
165 CodecAlloc();
166 Setup_FS_Segment();
167 #endif
169 hDriver->hDriverModule = LoadLibraryA(filename);
170 if (!hDriver->hDriverModule)
172 printf("Can't open library %s\n", filename);
173 DrvClose((HDRVR)hDriver);
174 return (HDRVR) 0;
177 hDriver->DriverProc = (DRIVERPROC) GetProcAddress(hDriver->hDriverModule,
178 "DriverProc");
179 if (!hDriver->DriverProc)
181 printf("Library %s is not a valid VfW/ACM codec\n", filename);
182 DrvClose((HDRVR)hDriver);
183 return (HDRVR) 0;
186 TRACE("DriverProc == %X\n", hDriver->DriverProc);
187 SendDriverMessage((HDRVR)hDriver, DRV_LOAD, 0, 0);
188 TRACE("DRV_LOAD Ok!\n");
189 SendDriverMessage((HDRVR)hDriver, DRV_ENABLE, 0, 0);
190 TRACE("DRV_ENABLE Ok!\n");
191 hDriver->dwDriverID = ++dwDrvID; // generate new id
193 // open driver and remmeber proper DriverID
194 hDriver->dwDriverID = SendDriverMessage((HDRVR)hDriver, DRV_OPEN, (LPARAM) unknown, lParam2);
195 TRACE("DRV_OPEN Ok!(%X)\n", hDriver->dwDriverID);
197 printf("Loaded DLL driver %s at %x\n", filename, hDriver->hDriverModule);
198 return (HDRVR)hDriver;