Qt: synchronization: subtitles duration parameter
[vlc/vlc-skelet.git] / libs / loader / driver.c
blobdde6a1d6ee387a4519d18f03c2e6fa1b73a54ad0
1 /*
2 * $Id$
4 * Copyright 1993, 1994 Martin Ayotte
5 * Copyright 1998 Marcus Meissner
6 * Copyright 1999 Eric Pouech
8 * Originally distributed under LPGL 2.1 (or later) by the Wine project.
10 * Modified for use with MPlayer, detailed CVS changelog at
11 * http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
13 * File now distributed as part of VLC media player with no modifications.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
30 #include "config.h"
32 #include <stdio.h>
33 #ifdef HAVE_MALLOC_H
34 #include <malloc.h>
35 #endif
36 #include <stdlib.h>
37 #ifdef __FreeBSD__
38 #include <sys/time.h>
39 #endif
41 #include "win32.h"
42 #include "wine/driver.h"
43 #include "wine/pe_image.h"
44 #include "wine/winreg.h"
45 #include "wine/vfw.h"
46 #include "registry.h"
47 #ifdef WIN32_LOADER
48 #include "ldt_keeper.h"
49 #endif
50 #include "driver.h"
51 #ifndef __MINGW32__
52 #include "ext.h"
53 #endif
55 #ifndef WIN32_LOADER
56 char* def_path=WIN32_PATH;
57 #else
58 extern char* def_path;
59 #endif
61 #if 1
64 * STORE_ALL/REST_ALL seems like an attempt to workaround problems due to
65 * WINAPI/no-WINAPI bustage.
67 * There should be no need for the STORE_ALL/REST_ALL hack once all
68 * function definitions agree with their prototypes (WINAPI-wise) and
69 * we make sure, that we do not call these functions without a proper
70 * prototype in scope.
73 #define STORE_ALL
74 #define REST_ALL
75 #else
76 // this asm code is no longer needed
77 #define STORE_ALL \
78 __asm__ __volatile__ ( \
79 "push %%ebx\n\t" \
80 "push %%ecx\n\t" \
81 "push %%edx\n\t" \
82 "push %%esi\n\t" \
83 "push %%edi\n\t"::)
85 #define REST_ALL \
86 __asm__ __volatile__ ( \
87 "pop %%edi\n\t" \
88 "pop %%esi\n\t" \
89 "pop %%edx\n\t" \
90 "pop %%ecx\n\t" \
91 "pop %%ebx\n\t"::)
92 #endif
94 static int needs_free=0;
95 void SetCodecPath(const char* path)
97 if(needs_free)free(def_path);
98 if(path==NULL)
100 def_path=WIN32_PATH;
101 needs_free=0;
102 return;
104 def_path = (char*) malloc(strlen(path)+1);
105 strcpy(def_path, path);
106 needs_free=1;
109 static DWORD dwDrvID = 0;
111 LRESULT WINAPI SendDriverMessage(HDRVR hDriver, UINT message,
112 LPARAM lParam1, LPARAM lParam2)
114 DRVR* module=(DRVR*)hDriver;
115 int result;
116 #ifndef __svr4__
117 char qw[300];
118 #endif
119 #ifdef DETAILED_OUT
120 printf("SendDriverMessage: driver %X, message %X, arg1 %X, arg2 %X\n", hDriver, message, lParam1, lParam2);
121 #endif
122 if (!module || !module->hDriverModule || !module->DriverProc) return -1;
123 #ifndef __svr4__
124 __asm__ __volatile__ ("fsave (%0)\n\t": :"r"(&qw));
125 #endif
127 #ifdef WIN32_LOADER
128 Setup_FS_Segment();
129 #endif
131 STORE_ALL;
132 result=module->DriverProc(module->dwDriverID, hDriver, message, lParam1, lParam2);
133 REST_ALL;
135 #ifndef __svr4__
136 __asm__ __volatile__ ("frstor (%0)\n\t": :"r"(&qw));
137 #endif
139 #ifdef DETAILED_OUT
140 printf("\t\tResult: %X\n", result);
141 #endif
142 return result;
145 void DrvClose(HDRVR hDriver)
147 if (hDriver)
149 DRVR* d = (DRVR*)hDriver;
150 if (d->hDriverModule)
152 #ifdef WIN32_LOADER
153 Setup_FS_Segment();
154 #endif
155 if (d->DriverProc)
157 SendDriverMessage(hDriver, DRV_CLOSE, 0, 0);
158 d->dwDriverID = 0;
159 SendDriverMessage(hDriver, DRV_FREE, 0, 0);
161 FreeLibrary(d->hDriverModule);
163 free(d);
165 #ifdef WIN32_LOADER
166 CodecRelease();
167 #endif
170 //DrvOpen(LPCSTR lpszDriverName, LPCSTR lpszSectionName, LPARAM lParam2)
171 HDRVR DrvOpen(LPARAM lParam2)
173 NPDRVR hDriver;
174 int i;
175 char unknown[0x124];
176 const char* filename = (const char*) ((ICOPEN*) lParam2)->pV1Reserved;
178 #ifdef MPLAYER
179 #ifdef WIN32_LOADER
180 Setup_LDT_Keeper();
181 #endif
182 printf("Loading codec DLL: '%s'\n",filename);
183 #endif
185 hDriver = (NPDRVR) malloc(sizeof(DRVR));
186 if (!hDriver)
187 return ((HDRVR) 0);
188 memset((void*)hDriver, 0, sizeof(DRVR));
190 #ifdef WIN32_LOADER
191 CodecAlloc();
192 Setup_FS_Segment();
193 #endif
195 hDriver->hDriverModule = LoadLibraryA(filename);
196 if (!hDriver->hDriverModule)
198 printf("Can't open library %s\n", filename);
199 DrvClose((HDRVR)hDriver);
200 return ((HDRVR) 0);
203 hDriver->DriverProc = (DRIVERPROC) GetProcAddress(hDriver->hDriverModule,
204 "DriverProc");
205 if (!hDriver->DriverProc)
207 printf("Library %s is not a valid VfW/ACM codec\n", filename);
208 DrvClose((HDRVR)hDriver);
209 return ((HDRVR) 0);
212 TRACE("DriverProc == %X\n", hDriver->DriverProc);
213 SendDriverMessage((HDRVR)hDriver, DRV_LOAD, 0, 0);
214 TRACE("DRV_LOAD Ok!\n");
215 SendDriverMessage((HDRVR)hDriver, DRV_ENABLE, 0, 0);
216 TRACE("DRV_ENABLE Ok!\n");
217 hDriver->dwDriverID = ++dwDrvID; // generate new id
219 // open driver and remmeber proper DriverID
220 hDriver->dwDriverID = SendDriverMessage((HDRVR)hDriver, DRV_OPEN, (LPARAM) unknown, lParam2);
221 TRACE("DRV_OPEN Ok!(%X)\n", hDriver->dwDriverID);
223 printf("Loaded DLL driver %s at %x\n", filename, hDriver->hDriverModule);
224 return (HDRVR)hDriver;