docs: document --quvi-format
[mplayer.git] / loader / drv.c
blobfbc4007734c7242bbc1506b9acea7a54f776be01
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 #include <stdlib.h>
11 #ifdef __FreeBSD__
12 #include <sys/time.h>
13 #endif
15 #include "win32.h"
16 #include "wine/driver.h"
17 #include "wine/pe_image.h"
18 #include "wine/winreg.h"
19 #include "wine/vfw.h"
20 #include "registry.h"
21 #ifdef WIN32_LOADER
22 #include "ldt_keeper.h"
23 #endif
24 #include "drv.h"
25 #ifndef __MINGW32__
26 #include "ext.h"
27 #endif
28 #include "path.h"
30 #if 1
33 * STORE_ALL/REST_ALL seems like an attempt to workaround problems due to
34 * WINAPI/no-WINAPI bustage.
36 * There should be no need for the STORE_ALL/REST_ALL hack once all
37 * function definitions agree with their prototypes (WINAPI-wise) and
38 * we make sure, that we do not call these functions without a proper
39 * prototype in scope.
42 #define STORE_ALL
43 #define REST_ALL
44 #else
45 // this asm code is no longer needed
46 #define STORE_ALL \
47 __asm__ volatile ( \
48 "push %%ebx\n\t" \
49 "push %%ecx\n\t" \
50 "push %%edx\n\t" \
51 "push %%esi\n\t" \
52 "push %%edi\n\t"::)
54 #define REST_ALL \
55 __asm__ volatile ( \
56 "pop %%edi\n\t" \
57 "pop %%esi\n\t" \
58 "pop %%edx\n\t" \
59 "pop %%ecx\n\t" \
60 "pop %%ebx\n\t"::)
61 #endif
63 static DWORD dwDrvID = 0;
65 LRESULT WINAPI SendDriverMessage(HDRVR hDriver, UINT message,
66 LPARAM lParam1, LPARAM lParam2)
68 DRVR* module=(DRVR*)hDriver;
69 int result;
70 #ifndef __svr4__
71 char qw[300];
72 #endif
73 #ifdef DETAILED_OUT
74 printf("SendDriverMessage: driver %X, message %X, arg1 %X, arg2 %X\n", hDriver, message, lParam1, lParam2);
75 #endif
76 if (!module || !module->hDriverModule || !module->DriverProc) return -1;
77 #ifndef __svr4__
78 __asm__ volatile ("fsave (%0)\n\t": :"r"(&qw));
79 #endif
81 #ifdef WIN32_LOADER
82 Setup_FS_Segment();
83 #endif
85 STORE_ALL;
86 result=module->DriverProc(module->dwDriverID, hDriver, message, lParam1, lParam2);
87 REST_ALL;
89 #ifndef __svr4__
90 __asm__ volatile ("frstor (%0)\n\t": :"r"(&qw));
91 #endif
93 #ifdef DETAILED_OUT
94 printf("\t\tResult: %X\n", result);
95 #endif
96 return result;
99 void DrvClose(HDRVR hDriver)
101 if (hDriver)
103 DRVR* d = (DRVR*)hDriver;
104 if (d->hDriverModule)
106 #ifdef WIN32_LOADER
107 Setup_FS_Segment();
108 #endif
109 if (d->DriverProc)
111 SendDriverMessage(hDriver, DRV_CLOSE, 0, 0);
112 d->dwDriverID = 0;
113 SendDriverMessage(hDriver, DRV_FREE, 0, 0);
115 FreeLibrary(d->hDriverModule);
117 free(d);
119 #ifdef WIN32_LOADER
120 CodecRelease();
121 #endif
124 //DrvOpen(LPCSTR lpszDriverName, LPCSTR lpszSectionName, LPARAM lParam2)
125 HDRVR DrvOpen(LPARAM lParam2)
127 NPDRVR hDriver;
128 char unknown[0x124];
129 const char* filename = (const char*) ((ICOPEN*) lParam2)->pV1Reserved;
131 #ifdef WIN32_LOADER
132 Setup_LDT_Keeper();
133 #endif
134 printf("Loading codec DLL: '%s'\n",filename);
136 hDriver = malloc(sizeof(DRVR));
137 if (!hDriver)
138 return (HDRVR) 0;
139 memset((void*)hDriver, 0, sizeof(DRVR));
141 #ifdef WIN32_LOADER
142 CodecAlloc();
143 Setup_FS_Segment();
144 #endif
146 hDriver->hDriverModule = LoadLibraryA(filename);
147 if (!hDriver->hDriverModule)
149 printf("Can't open library %s\n", filename);
150 DrvClose((HDRVR)hDriver);
151 return (HDRVR) 0;
154 hDriver->DriverProc = (DRIVERPROC) GetProcAddress(hDriver->hDriverModule,
155 "DriverProc");
156 if (!hDriver->DriverProc)
158 printf("Library %s is not a valid VfW/ACM codec\n", filename);
159 DrvClose((HDRVR)hDriver);
160 return (HDRVR) 0;
163 TRACE("DriverProc == %X\n", hDriver->DriverProc);
164 SendDriverMessage((HDRVR)hDriver, DRV_LOAD, 0, 0);
165 TRACE("DRV_LOAD Ok!\n");
166 SendDriverMessage((HDRVR)hDriver, DRV_ENABLE, 0, 0);
167 TRACE("DRV_ENABLE Ok!\n");
168 hDriver->dwDriverID = ++dwDrvID; // generate new id
170 // open driver and remmeber proper DriverID
171 hDriver->dwDriverID = SendDriverMessage((HDRVR)hDriver, DRV_OPEN, (LPARAM) unknown, lParam2);
172 TRACE("DRV_OPEN Ok!(%X)\n", hDriver->dwDriverID);
174 printf("Loaded DLL driver %s at %x\n", filename, hDriver->hDriverModule);
175 return (HDRVR)hDriver;