Mercurial > mplayer.hg
annotate loader/driver.c @ 7933:ebe28de81548
sync, patch by Ioannis Panteleakis.
author | diego |
---|---|
date | Sun, 27 Oct 2002 10:43:38 +0000 |
parents | 174e2a58b4cd |
children | fb88ccbc5ccc |
rev | line source |
---|---|
7386 | 1 #include "config.h" |
2 | |
1 | 3 #include <stdio.h> |
4 #ifdef HAVE_MALLOC_H | |
5 #include <malloc.h> | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
6 #endif |
1 | 7 #include <stdlib.h> |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
8 #ifdef __FreeBSD__ |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
9 #include <sys/time.h> |
1 | 10 #endif |
11 | |
2068
3189c317dfc1
using ldt_keeper instead of setup_fs, includes changed
arpi
parents:
1307
diff
changeset
|
12 #include "win32.h" |
3189c317dfc1
using ldt_keeper instead of setup_fs, includes changed
arpi
parents:
1307
diff
changeset
|
13 #include "wine/driver.h" |
3189c317dfc1
using ldt_keeper instead of setup_fs, includes changed
arpi
parents:
1307
diff
changeset
|
14 #include "wine/pe_image.h" |
3189c317dfc1
using ldt_keeper instead of setup_fs, includes changed
arpi
parents:
1307
diff
changeset
|
15 #include "wine/winreg.h" |
3189c317dfc1
using ldt_keeper instead of setup_fs, includes changed
arpi
parents:
1307
diff
changeset
|
16 #include "wine/vfw.h" |
3189c317dfc1
using ldt_keeper instead of setup_fs, includes changed
arpi
parents:
1307
diff
changeset
|
17 #include "registry.h" |
3189c317dfc1
using ldt_keeper instead of setup_fs, includes changed
arpi
parents:
1307
diff
changeset
|
18 #include "ldt_keeper.h" |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
19 #include "driver.h" |
1 | 20 |
7386 | 21 extern char* def_path; |
1 | 22 |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
23 #if 1 |
7386 | 24 |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
25 /* |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
26 * STORE_ALL/REST_ALL seems like an attempt to workaround problems due to |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
27 * WINAPI/no-WINAPI bustage. |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
28 * |
7386 | 29 * There should be no need for the STORE_ALL/REST_ALL hack once all |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
30 * function definitions agree with their prototypes (WINAPI-wise) and |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
31 * we make sure, that we do not call these functions without a proper |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
32 * prototype in scope. |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
33 */ |
7386 | 34 |
35 #define STORE_ALL | |
36 #define REST_ALL | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
37 #else |
7386 | 38 // this asm code is no longer needed |
1 | 39 #define STORE_ALL \ |
7386 | 40 __asm__ __volatile__ ( \ |
1 | 41 "push %%ebx\n\t" \ |
42 "push %%ecx\n\t" \ | |
43 "push %%edx\n\t" \ | |
44 "push %%esi\n\t" \ | |
45 "push %%edi\n\t"::) | |
46 | |
47 #define REST_ALL \ | |
7386 | 48 __asm__ __volatile__ ( \ |
1 | 49 "pop %%edi\n\t" \ |
50 "pop %%esi\n\t" \ | |
51 "pop %%edx\n\t" \ | |
52 "pop %%ecx\n\t" \ | |
53 "pop %%ebx\n\t"::) | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
54 #endif |
1 | 55 |
7386 | 56 static int needs_free=0; |
57 void SetCodecPath(const char* path) | |
58 { | |
59 if(needs_free)free(def_path); | |
60 if(path==0) | |
61 { | |
62 def_path=WIN32_PATH; | |
63 needs_free=0; | |
64 return; | |
65 } | |
66 def_path = (char*) malloc(strlen(path)+1); | |
67 strcpy(def_path, path); | |
68 needs_free=1; | |
69 } | |
1 | 70 |
71 static DWORD dwDrvID = 0; | |
72 | |
7386 | 73 LRESULT WINAPI SendDriverMessage(HDRVR hDriver, UINT message, |
74 LPARAM lParam1, LPARAM lParam2) | |
1 | 75 { |
76 DRVR* module=(DRVR*)hDriver; | |
77 int result; | |
7386 | 78 #ifndef __svr4__ |
79 char qw[300]; | |
80 #endif | |
81 #ifdef DETAILED_OUT | |
1 | 82 printf("SendDriverMessage: driver %X, message %X, arg1 %X, arg2 %X\n", hDriver, message, lParam1, lParam2); |
83 #endif | |
7386 | 84 if (!module || !module->hDriverModule || !module->DriverProc) return -1; |
85 #ifndef __svr4__ | |
86 __asm__ __volatile__ ("fsave (%0)\n\t": :"r"(&qw)); | |
87 #endif | |
88 | |
89 Setup_FS_Segment(); | |
1 | 90 |
7386 | 91 STORE_ALL; |
92 result=module->DriverProc(module->dwDriverID, hDriver, message, lParam1, lParam2); | |
93 REST_ALL; | |
94 | |
95 #ifndef __svr4__ | |
96 __asm__ __volatile__ ("frstor (%0)\n\t": :"r"(&qw)); | |
97 #endif | |
98 | |
99 #ifdef DETAILED_OUT | |
100 printf("\t\tResult: %X\n", result); | |
101 #endif | |
102 return result; | |
1 | 103 } |
104 | |
7386 | 105 void DrvClose(HDRVR hDriver) |
1 | 106 { |
7386 | 107 if (hDriver) |
108 { | |
109 DRVR* d = (DRVR*)hDriver; | |
110 if (d->hDriverModule) | |
111 { | |
112 Setup_FS_Segment(); | |
113 if (d->DriverProc) | |
114 { | |
115 SendDriverMessage(hDriver, DRV_CLOSE, 0, 0); | |
116 d->dwDriverID = 0; | |
117 SendDriverMessage(hDriver, DRV_FREE, 0, 0); | |
118 } | |
119 FreeLibrary(d->hDriverModule); | |
120 } | |
121 free(d); | |
1 | 122 } |
7386 | 123 CodecRelease(); |
1 | 124 } |
125 | |
7386 | 126 //DrvOpen(LPCSTR lpszDriverName, LPCSTR lpszSectionName, LPARAM lParam2) |
127 HDRVR DrvOpen(LPARAM lParam2) | |
1 | 128 { |
7386 | 129 NPDRVR hDriver; |
130 int i; | |
131 char unknown[0x124]; | |
132 const char* filename = (const char*) ((ICOPEN*) lParam2)->pV1Reserved; | |
1 | 133 |
7386 | 134 #ifdef MPLAYER |
236 | 135 Setup_LDT_Keeper(); |
7386 | 136 printf("Loading codec DLL: '%s'\n",filename); |
137 #endif | |
236 | 138 |
7386 | 139 hDriver = (NPDRVR) malloc(sizeof(DRVR)); |
140 if (!hDriver) | |
1 | 141 return ((HDRVR) 0); |
7386 | 142 memset((void*)hDriver, 0, sizeof(DRVR)); |
1 | 143 |
7386 | 144 CodecAlloc(); |
145 Setup_FS_Segment(); | |
146 | |
147 hDriver->hDriverModule = LoadLibraryA(filename); | |
148 if (!hDriver->hDriverModule) | |
149 { | |
150 printf("Can't open library %s\n", filename); | |
151 DrvClose((HDRVR)hDriver); | |
152 return ((HDRVR) 0); | |
1 | 153 } |
154 | |
7386 | 155 hDriver->DriverProc = (DRIVERPROC) GetProcAddress(hDriver->hDriverModule, |
156 "DriverProc"); | |
157 if (!hDriver->DriverProc) | |
1 | 158 { |
7386 | 159 printf("Library %s is not a valid VfW/ACM codec\n", filename); |
160 DrvClose((HDRVR)hDriver); | |
161 return ((HDRVR) 0); | |
1 | 162 } |
163 | |
7386 | 164 TRACE("DriverProc == %X\n", hDriver->DriverProc); |
165 SendDriverMessage((HDRVR)hDriver, DRV_LOAD, 0, 0); | |
166 TRACE("DRV_LOAD Ok!\n"); | |
167 SendDriverMessage((HDRVR)hDriver, DRV_ENABLE, 0, 0); | |
168 TRACE("DRV_ENABLE Ok!\n"); | |
169 hDriver->dwDriverID = ++dwDrvID; // generate new id | |
1 | 170 |
7386 | 171 // open driver and remmeber proper DriverID |
172 hDriver->dwDriverID = SendDriverMessage((HDRVR)hDriver, DRV_OPEN, (LPARAM) unknown, lParam2); | |
173 TRACE("DRV_OPEN Ok!(%X)\n", hDriver->dwDriverID); | |
1 | 174 |
7386 | 175 printf("Loaded DLL driver %s\n", filename); |
176 return (HDRVR)hDriver; | |
1 | 177 } |