Mercurial > mplayer.hg
comparison loader/driver.c @ 7386:174e2a58b4cd
avifile sync - 95% cosmetics 5% bug
author | arpi |
---|---|
date | Fri, 13 Sep 2002 19:43:17 +0000 |
parents | 4dad31e655b6 |
children | fb88ccbc5ccc |
comparison
equal
deleted
inserted
replaced
7385:e2fcdd7608b1 | 7386:174e2a58b4cd |
---|---|
1 #include <config.h> | 1 #include "config.h" |
2 | |
2 #include <stdio.h> | 3 #include <stdio.h> |
3 #ifdef HAVE_MALLOC_H | 4 #ifdef HAVE_MALLOC_H |
4 #include <malloc.h> | 5 #include <malloc.h> |
5 #endif | 6 #endif |
6 #include <stdlib.h> | 7 #include <stdlib.h> |
15 #include "wine/vfw.h" | 16 #include "wine/vfw.h" |
16 #include "registry.h" | 17 #include "registry.h" |
17 #include "ldt_keeper.h" | 18 #include "ldt_keeper.h" |
18 #include "driver.h" | 19 #include "driver.h" |
19 | 20 |
21 extern char* def_path; | |
20 | 22 |
21 #if 1 | 23 #if 1 |
24 | |
22 /* | 25 /* |
23 * STORE_ALL/REST_ALL seems like an attempt to workaround problems due to | 26 * STORE_ALL/REST_ALL seems like an attempt to workaround problems due to |
24 * WINAPI/no-WINAPI bustage. | 27 * WINAPI/no-WINAPI bustage. |
25 * | 28 * |
26 * There should be no need for the STORE_ALL/REST_ALL hack once all | 29 * There should be no need for the STORE_ALL/REST_ALL hack once all |
27 * function definitions agree with their prototypes (WINAPI-wise) and | 30 * function definitions agree with their prototypes (WINAPI-wise) and |
28 * we make sure, that we do not call these functions without a proper | 31 * we make sure, that we do not call these functions without a proper |
29 * prototype in scope. | 32 * prototype in scope. |
30 */ | 33 */ |
31 #define STORE_ALL /**/ | 34 |
32 #define REST_ALL /**/ | 35 #define STORE_ALL |
36 #define REST_ALL | |
33 #else | 37 #else |
38 // this asm code is no longer needed | |
34 #define STORE_ALL \ | 39 #define STORE_ALL \ |
35 __asm__( \ | 40 __asm__ __volatile__ ( \ |
36 "push %%ebx\n\t" \ | 41 "push %%ebx\n\t" \ |
37 "push %%ecx\n\t" \ | 42 "push %%ecx\n\t" \ |
38 "push %%edx\n\t" \ | 43 "push %%edx\n\t" \ |
39 "push %%esi\n\t" \ | 44 "push %%esi\n\t" \ |
40 "push %%edi\n\t"::) | 45 "push %%edi\n\t"::) |
41 | 46 |
42 #define REST_ALL \ | 47 #define REST_ALL \ |
43 __asm__( \ | 48 __asm__ __volatile__ ( \ |
44 "pop %%edi\n\t" \ | 49 "pop %%edi\n\t" \ |
45 "pop %%esi\n\t" \ | 50 "pop %%esi\n\t" \ |
46 "pop %%edx\n\t" \ | 51 "pop %%edx\n\t" \ |
47 "pop %%ecx\n\t" \ | 52 "pop %%ecx\n\t" \ |
48 "pop %%ebx\n\t"::) | 53 "pop %%ebx\n\t"::) |
49 #endif | 54 #endif |
50 | 55 |
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 } | |
51 | 70 |
52 | |
53 | |
54 static DWORD dwDrvID = 0; | 71 static DWORD dwDrvID = 0; |
55 | 72 |
56 | 73 LRESULT WINAPI SendDriverMessage(HDRVR hDriver, UINT message, |
57 LRESULT WINAPI SendDriverMessage( HDRVR hDriver, UINT message, | 74 LPARAM lParam1, LPARAM lParam2) |
58 LPARAM lParam1, LPARAM lParam2 ) | |
59 { | 75 { |
60 DRVR* module=(DRVR*)hDriver; | 76 DRVR* module=(DRVR*)hDriver; |
61 int result; | 77 int result; |
62 #ifdef DETAILED_OUT | 78 #ifndef __svr4__ |
79 char qw[300]; | |
80 #endif | |
81 #ifdef DETAILED_OUT | |
63 printf("SendDriverMessage: driver %X, message %X, arg1 %X, arg2 %X\n", hDriver, message, lParam1, lParam2); | 82 printf("SendDriverMessage: driver %X, message %X, arg1 %X, arg2 %X\n", hDriver, message, lParam1, lParam2); |
64 #endif | 83 #endif |
65 if(module==0)return -1; | 84 if (!module || !module->hDriverModule || !module->DriverProc) return -1; |
66 if(module->hDriverModule==0)return -1; | 85 #ifndef __svr4__ |
67 if(module->DriverProc==0)return -1; | 86 __asm__ __volatile__ ("fsave (%0)\n\t": :"r"(&qw)); |
87 #endif | |
88 | |
89 Setup_FS_Segment(); | |
90 | |
68 STORE_ALL; | 91 STORE_ALL; |
69 result=module->DriverProc(module->dwDriverID,1,message,lParam1,lParam2); | 92 result=module->DriverProc(module->dwDriverID, hDriver, message, lParam1, lParam2); |
70 REST_ALL; | 93 REST_ALL; |
71 #ifdef DETAILED_OUT | 94 |
95 #ifndef __svr4__ | |
96 __asm__ __volatile__ ("frstor (%0)\n\t": :"r"(&qw)); | |
97 #endif | |
98 | |
99 #ifdef DETAILED_OUT | |
72 printf("\t\tResult: %X\n", result); | 100 printf("\t\tResult: %X\n", result); |
73 #endif | 101 #endif |
74 return result; | 102 return result; |
75 } | |
76 | |
77 static NPDRVR DrvAlloc(HDRVR*lpDriver, LPUINT lpDrvResult) | |
78 { | |
79 NPDRVR npDriver; | |
80 /* allocate and lock handle */ | |
81 if (lpDriver) | |
82 { | |
83 if ( (*lpDriver = (HDRVR) malloc(sizeof(DRVR))) ) | |
84 { | |
85 if ((npDriver = (NPDRVR) *lpDriver)) | |
86 { | |
87 *lpDrvResult = MMSYSERR_NOERROR; | |
88 return (npDriver); | |
89 } | |
90 free((NPDRVR)*lpDriver); | |
91 } | |
92 return (*lpDrvResult = MMSYSERR_NOMEM, (NPDRVR) 0); | |
93 } | |
94 return (*lpDrvResult = MMSYSERR_INVALPARAM, (NPDRVR) 0); | |
95 } | 103 } |
96 | 104 |
97 | 105 void DrvClose(HDRVR hDriver) |
98 static void DrvFree(HDRVR hDriver) | |
99 { | 106 { |
100 int i; | 107 if (hDriver) |
101 Setup_FS_Segment(); | 108 { |
102 if(hDriver) | 109 DRVR* d = (DRVR*)hDriver; |
103 if(((DRVR*)hDriver)->hDriverModule) | 110 if (d->hDriverModule) |
104 if(((DRVR*)hDriver)->DriverProc) | 111 { |
105 (((DRVR*)hDriver)->DriverProc)(((DRVR*)hDriver)->dwDriverID, hDriver, DRV_CLOSE, 0, 0); | 112 Setup_FS_Segment(); |
106 if(hDriver) { | 113 if (d->DriverProc) |
107 if(((DRVR*)hDriver)->hDriverModule) | 114 { |
108 if(((DRVR*)hDriver)->DriverProc) | 115 SendDriverMessage(hDriver, DRV_CLOSE, 0, 0); |
109 (((DRVR*)hDriver)->DriverProc)(0, hDriver, DRV_FREE, 0, 0); | 116 d->dwDriverID = 0; |
110 FreeLibrary(((DRVR*)hDriver)->hDriverModule); | 117 SendDriverMessage(hDriver, DRV_FREE, 0, 0); |
111 free((NPDRVR)hDriver); | 118 } |
112 return; | 119 FreeLibrary(d->hDriverModule); |
120 } | |
121 free(d); | |
113 } | 122 } |
123 CodecRelease(); | |
114 } | 124 } |
115 | 125 |
116 void DrvClose(HDRVR hdrvr) | 126 //DrvOpen(LPCSTR lpszDriverName, LPCSTR lpszSectionName, LPARAM lParam2) |
127 HDRVR DrvOpen(LPARAM lParam2) | |
117 { | 128 { |
118 DrvFree(hdrvr); | 129 NPDRVR hDriver; |
119 } | 130 int i; |
131 char unknown[0x124]; | |
132 const char* filename = (const char*) ((ICOPEN*) lParam2)->pV1Reserved; | |
120 | 133 |
134 #ifdef MPLAYER | |
135 Setup_LDT_Keeper(); | |
136 printf("Loading codec DLL: '%s'\n",filename); | |
137 #endif | |
121 | 138 |
122 char* win32_codec_name=NULL; // must be set before calling DrvOpen() !!! | 139 hDriver = (NPDRVR) malloc(sizeof(DRVR)); |
140 if (!hDriver) | |
141 return ((HDRVR) 0); | |
142 memset((void*)hDriver, 0, sizeof(DRVR)); | |
123 | 143 |
124 HDRVR VFWAPI | 144 CodecAlloc(); |
125 DrvOpen(LPARAM lParam2) | 145 Setup_FS_Segment(); |
126 { | |
127 ICOPEN *icopen=(ICOPEN *) lParam2; | |
128 UINT uDrvResult; | |
129 HDRVR hDriver; | |
130 NPDRVR npDriver; | |
131 char unknown[0x24]; | |
132 // char* codec_name=icopen->fccHandler; | |
133 | 146 |
134 Setup_LDT_Keeper(); | 147 hDriver->hDriverModule = LoadLibraryA(filename); |
135 | 148 if (!hDriver->hDriverModule) |
136 if (!(npDriver = DrvAlloc(&hDriver, &uDrvResult))) | 149 { |
150 printf("Can't open library %s\n", filename); | |
151 DrvClose((HDRVR)hDriver); | |
137 return ((HDRVR) 0); | 152 return ((HDRVR) 0); |
138 | |
139 if (!(npDriver->hDriverModule = LoadLibraryA(win32_codec_name))) { | |
140 printf("Can't open library %s\n", win32_codec_name); | |
141 DrvFree(hDriver); | |
142 return ((HDRVR) 0); | |
143 } | 153 } |
144 | 154 |
145 #if 0 | 155 hDriver->DriverProc = (DRIVERPROC) GetProcAddress(hDriver->hDriverModule, |
156 "DriverProc"); | |
157 if (!hDriver->DriverProc) | |
146 { | 158 { |
147 unsigned char *p=((char*)npDriver->hDriverModule); | 159 printf("Library %s is not a valid VfW/ACM codec\n", filename); |
148 double *dp; | 160 DrvClose((HDRVR)hDriver); |
149 int i; | 161 return ((HDRVR) 0); |
150 p+=0x14c0; | |
151 for(i=0;i<16;i++)printf(" %02X",p[i]); printf("\n"); | |
152 dp=(double*)p; | |
153 printf("divx bitrate = %f\n",(float)(*dp)); | |
154 // *(double*)((char*)npDriver->hDriverModule+0x14c0)=bitrate; | |
155 } | |
156 #endif | |
157 | |
158 if (!(npDriver->DriverProc = (DRIVERPROC) | |
159 GetProcAddress(npDriver->hDriverModule, "DriverProc"))) { | |
160 #if 1 | |
161 printf("Library %s is not a VfW/ACM valid codec\n", win32_codec_name); | |
162 #else | |
163 // Try DirectShow... | |
164 GETCLASS func=(GETCLASS)GetProcAddress(npDriver->hDriverModule,"DllGetClassObject"); | |
165 if(!func) | |
166 printf("Library %s is not a valid VfW/ACM/DShow codec\n", win32_codec_name); | |
167 else { | |
168 HRESULT result; | |
169 struct IClassFactory* factory=0; | |
170 struct IUnknown* object=0; | |
171 GUID CLSID_Voxware={0x73f7a062, 0x8829, 0x11d1, | |
172 {0xb5, 0x50, 0x00, 0x60, 0x97, 0x24, 0x2d, 0x8d}}; | |
173 GUID* id=&CLSID_Voxware; | |
174 | |
175 result=func(id, &IID_IClassFactory, (void**)&factory); | |
176 if(result || (!factory)) printf("No such class object (wrong/missing GUID?)\n"); | |
177 | |
178 printf("Calling factory->vt->CreateInstance()\n"); | |
179 printf("addr = %X\n",(unsigned int)factory->vt->CreateInstance); | |
180 result=factory->vt->CreateInstance(factory, 0, &IID_IUnknown, (void**)&object); | |
181 printf("Calling factory->vt->Release()\n"); | |
182 factory->vt->Release((struct IUnknown*)factory); | |
183 if(result || (!object)) printf("Class factory failure\n"); | |
184 | |
185 printf("DirectShow codecs not yet supported...\n"); | |
186 } | |
187 #endif | |
188 | |
189 FreeLibrary(npDriver->hDriverModule); | |
190 DrvFree(hDriver); | |
191 return ((HDRVR) 0); | |
192 | |
193 } | 162 } |
194 | 163 |
195 //TRACE("DriverProc == %X\n", npDriver->DriverProc); | 164 TRACE("DriverProc == %X\n", hDriver->DriverProc); |
196 npDriver->dwDriverID = ++dwDrvID; | 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 | |
197 | 170 |
198 Setup_FS_Segment(); | 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); | |
199 | 174 |
200 STORE_ALL; | 175 printf("Loaded DLL driver %s\n", filename); |
201 (npDriver->DriverProc)(0, hDriver, DRV_LOAD, 0, 0); | 176 return (HDRVR)hDriver; |
202 REST_ALL; | |
203 //TRACE("DRV_LOAD Ok!\n"); | |
204 STORE_ALL; | |
205 (npDriver->DriverProc)(0, hDriver, DRV_ENABLE, 0, 0); | |
206 REST_ALL; | |
207 //TRACE("DRV_ENABLE Ok!\n"); | |
208 | |
209 // open driver | |
210 STORE_ALL; | |
211 npDriver->dwDriverID=(npDriver->DriverProc)(npDriver->dwDriverID, hDriver, DRV_OPEN, | |
212 (LPARAM) (LPSTR) unknown, lParam2); | |
213 REST_ALL; | |
214 | |
215 //TRACE("DRV_OPEN Ok!(%X)\n", npDriver->dwDriverID); | |
216 | |
217 if (uDrvResult) | |
218 { | |
219 DrvFree(hDriver); | |
220 hDriver = (HDRVR) 0; | |
221 } | |
222 | |
223 // printf("Successfully loaded codec %s\n",win32_codec_name); | |
224 | |
225 return (hDriver); | |
226 } | 177 } |
227 |