1 |
|
/************************************************************************** |
2 |
|
* |
3 |
|
* XVID VFW FRONTEND |
4 |
|
* driverproc main |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
8 |
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
* (at your option) any later version. |
10 |
|
* |
11 |
|
* This program is distributed in the hope that it will be useful, |
12 |
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
* GNU General Public License for more details. |
15 |
|
* |
16 |
|
* You should have received a copy of the GNU General Public License |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
|
* |
20 |
|
*************************************************************************/ |
21 |
|
|
22 |
|
/************************************************************************** |
23 |
|
* |
24 |
|
* History: |
25 |
|
* |
26 |
|
* 31.08.2002 Configure() export |
27 |
|
* 01.12.2001 inital version; (c)2001 peter ross <pross@xvid.org> |
28 |
|
* |
29 |
|
*************************************************************************/ |
30 |
|
|
31 |
|
#include <windows.h> |
32 |
|
#include <vfw.h> |
33 |
|
|
34 |
|
#include "debug.h" |
35 |
|
#include "codec.h" |
36 |
|
#include "config.h" |
37 |
|
#include "resource.h" |
38 |
|
|
39 |
|
|
40 |
|
BOOL WINAPI DllMain( |
41 |
|
HANDLE hModule, |
42 |
|
DWORD ul_reason_for_call, |
43 |
|
LPVOID lpReserved) |
44 |
|
{ |
45 |
|
g_hInst = (HINSTANCE) hModule; |
46 |
|
return TRUE; |
47 |
|
} |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
/* __declspec(dllexport) */ LRESULT WINAPI DriverProc( |
52 |
|
DWORD dwDriverId, |
53 |
|
HDRVR hDriver, |
54 |
|
UINT uMsg, |
55 |
|
LPARAM lParam1, |
56 |
|
LPARAM lParam2) |
57 |
|
{ |
58 |
|
CODEC * codec = (CODEC *)dwDriverId; |
59 |
|
|
60 |
|
switch(uMsg) |
61 |
|
{ |
62 |
|
|
63 |
|
/* driver primitives */ |
64 |
|
|
65 |
|
case DRV_LOAD : |
66 |
|
case DRV_FREE : |
67 |
|
return DRV_OK; |
68 |
|
|
69 |
|
case DRV_OPEN : |
70 |
|
DPRINTF("DRV_OPEN"); |
71 |
|
{ |
72 |
|
ICOPEN * icopen = (ICOPEN *)lParam2; |
73 |
|
|
74 |
|
if (icopen != NULL && icopen->fccType != ICTYPE_VIDEO) |
75 |
|
{ |
76 |
|
return DRV_CANCEL; |
77 |
|
} |
78 |
|
|
79 |
|
codec = malloc(sizeof(CODEC)); |
80 |
|
|
81 |
|
if (codec == NULL) |
82 |
|
{ |
83 |
|
if (icopen != NULL) |
84 |
|
{ |
85 |
|
icopen->dwError = ICERR_MEMORY; |
86 |
|
} |
87 |
|
return 0; |
88 |
|
} |
89 |
|
|
90 |
|
codec->ehandle = codec->dhandle = NULL; |
91 |
|
codec->fbase = 25; |
92 |
|
codec->fincr = 1; |
93 |
|
config_reg_get(&codec->config); |
94 |
|
|
95 |
|
/* bad things happen if this is uncommented |
96 |
|
if (lstrcmp(XVID_BUILD, codec->config.build)) |
97 |
|
{ |
98 |
|
config_reg_default(&codec->config); |
99 |
|
} |
100 |
|
*/ |
101 |
|
|
102 |
|
if (icopen != NULL) |
103 |
|
{ |
104 |
|
icopen->dwError = ICERR_OK; |
105 |
|
} |
106 |
|
return (LRESULT)codec; |
107 |
|
} |
108 |
|
|
109 |
|
case DRV_CLOSE : |
110 |
|
DPRINTF("DRV_CLOSE"); |
111 |
|
// compress_end/decompress_end don't always get called |
112 |
|
compress_end(codec); |
113 |
|
decompress_end(codec); |
114 |
|
free(codec); |
115 |
|
return DRV_OK; |
116 |
|
|
117 |
|
case DRV_DISABLE : |
118 |
|
case DRV_ENABLE : |
119 |
|
return DRV_OK; |
120 |
|
|
121 |
|
case DRV_INSTALL : |
122 |
|
case DRV_REMOVE : |
123 |
|
return DRV_OK; |
124 |
|
|
125 |
|
case DRV_QUERYCONFIGURE : |
126 |
|
case DRV_CONFIGURE : |
127 |
|
return DRV_CANCEL; |
128 |
|
|
129 |
|
|
130 |
|
/* info */ |
131 |
|
|
132 |
|
case ICM_GETINFO : |
133 |
|
DPRINTF("ICM_GETINFO"); |
134 |
|
{ |
135 |
|
ICINFO *icinfo = (ICINFO *)lParam1; |
136 |
|
|
137 |
|
icinfo->fccType = ICTYPE_VIDEO; |
138 |
|
icinfo->fccHandler = FOURCC_XVID; |
139 |
|
icinfo->dwFlags = |
140 |
|
VIDCF_FASTTEMPORALC | |
141 |
|
VIDCF_FASTTEMPORALD | |
142 |
|
VIDCF_COMPRESSFRAMES; |
143 |
|
|
144 |
|
icinfo->dwVersion = 0; |
145 |
|
icinfo->dwVersionICM = ICVERSION; |
146 |
|
|
147 |
|
wcscpy(icinfo->szName, XVID_NAME_L); |
148 |
|
wcscpy(icinfo->szDescription, XVID_DESC_L); |
149 |
|
|
150 |
|
return lParam2; /* size of struct */ |
151 |
|
} |
152 |
|
|
153 |
|
/* state control */ |
154 |
|
|
155 |
|
case ICM_ABOUT : |
156 |
|
DPRINTF("ICM_ABOUT"); |
157 |
|
DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_ABOUT), (HWND)lParam1, about_proc, 0); |
158 |
|
return ICERR_OK; |
159 |
|
|
160 |
|
case ICM_CONFIGURE : |
161 |
|
DPRINTF("ICM_CONFIGURE"); |
162 |
|
if (lParam1 != -1) |
163 |
|
{ |
164 |
|
CONFIG temp; |
165 |
|
|
166 |
|
codec->config.save = FALSE; |
167 |
|
memcpy(&temp, &codec->config, sizeof(CONFIG)); |
168 |
|
|
169 |
|
DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_MAIN), (HWND)lParam1, main_proc, (LPARAM)&temp); |
170 |
|
|
171 |
|
if (temp.save) |
172 |
|
{ |
173 |
|
memcpy(&codec->config, &temp, sizeof(CONFIG)); |
174 |
|
config_reg_set(&codec->config); |
175 |
|
} |
176 |
|
} |
177 |
|
return ICERR_OK; |
178 |
|
|
179 |
|
case ICM_GETSTATE : |
180 |
|
DPRINTF("ICM_GETSTATE"); |
181 |
|
if ((void*)lParam1 == NULL) |
182 |
|
{ |
183 |
|
return sizeof(CONFIG); |
184 |
|
} |
185 |
|
memcpy((void*)lParam1, &codec->config, sizeof(CONFIG)); |
186 |
|
return ICERR_OK; |
187 |
|
|
188 |
|
case ICM_SETSTATE : |
189 |
|
DPRINTF("ICM_SETSTATE"); |
190 |
|
if ((void*)lParam1 == NULL) |
191 |
|
{ |
192 |
|
DPRINTF("ICM_SETSTATE : DEFAULT"); |
193 |
|
config_reg_get(&codec->config); |
194 |
|
return 0; |
195 |
|
} |
196 |
|
memcpy(&codec->config,(void*)lParam1, sizeof(CONFIG)); |
197 |
|
return 0; // sizeof(CONFIG); |
198 |
|
|
199 |
|
/* not sure the difference, private/public data? */ |
200 |
|
|
201 |
|
case ICM_GET : |
202 |
|
case ICM_SET : |
203 |
|
return ICERR_OK; |
204 |
|
|
205 |
|
|
206 |
|
/* older-stype config */ |
207 |
|
|
208 |
|
case ICM_GETDEFAULTQUALITY : |
209 |
|
case ICM_GETQUALITY : |
210 |
|
case ICM_SETQUALITY : |
211 |
|
case ICM_GETBUFFERSWANTED : |
212 |
|
case ICM_GETDEFAULTKEYFRAMERATE : |
213 |
|
return ICERR_UNSUPPORTED; |
214 |
|
|
215 |
|
|
216 |
|
/* compressor */ |
217 |
|
|
218 |
|
case ICM_COMPRESS_QUERY : |
219 |
|
DPRINTF("ICM_COMPRESS_QUERY"); |
220 |
|
return compress_query(codec, (BITMAPINFO *)lParam1, (BITMAPINFO *)lParam2); |
221 |
|
|
222 |
|
case ICM_COMPRESS_GET_FORMAT : |
223 |
|
DPRINTF("ICM_COMPRESS_GET_FORMAT"); |
224 |
|
return compress_get_format(codec, (BITMAPINFO *)lParam1, (BITMAPINFO *)lParam2); |
225 |
|
|
226 |
|
case ICM_COMPRESS_GET_SIZE : |
227 |
|
DPRINTF("ICM_COMPRESS_GET_SIZE"); |
228 |
|
return compress_get_size(codec, (BITMAPINFO *)lParam1, (BITMAPINFO *)lParam2); |
229 |
|
|
230 |
|
case ICM_COMPRESS_FRAMES_INFO : |
231 |
|
DPRINTF("ICM_COMPRESS_FRAMES_INFO"); |
232 |
|
return compress_frames_info(codec, (ICCOMPRESSFRAMES *)lParam1); |
233 |
|
|
234 |
|
case ICM_COMPRESS_BEGIN : |
235 |
|
DPRINTF("ICM_COMPRESS_BEGIN"); |
236 |
|
return compress_begin(codec, (BITMAPINFO *)lParam1, (BITMAPINFO *)lParam2); |
237 |
|
|
238 |
|
case ICM_COMPRESS_END : |
239 |
|
DPRINTF("ICM_COMPRESS_END"); |
240 |
|
return compress_end(codec); |
241 |
|
|
242 |
|
case ICM_COMPRESS : |
243 |
|
DPRINTF("ICM_COMPRESS"); |
244 |
|
return compress(codec, (ICCOMPRESS *)lParam1); |
245 |
|
|
246 |
|
/* decompressor */ |
247 |
|
|
248 |
|
case ICM_DECOMPRESS_QUERY : |
249 |
|
DPRINTF("ICM_DECOMPRESS_QUERY"); |
250 |
|
return decompress_query(codec, (BITMAPINFO *)lParam1, (BITMAPINFO *)lParam2); |
251 |
|
|
252 |
|
case ICM_DECOMPRESS_GET_FORMAT : |
253 |
|
DPRINTF("ICM_DECOMPRESS_GET_FORMAT"); |
254 |
|
return decompress_get_format(codec, (BITMAPINFO *)lParam1, (BITMAPINFO *)lParam2); |
255 |
|
|
256 |
|
case ICM_DECOMPRESS_BEGIN : |
257 |
|
DPRINTF("ICM_DECOMPRESS_BEGIN"); |
258 |
|
return decompress_begin(codec, (BITMAPINFO *)lParam1, (BITMAPINFO *)lParam2); |
259 |
|
|
260 |
|
case ICM_DECOMPRESS_END : |
261 |
|
DPRINTF("ICM_DECOMPRESS_END"); |
262 |
|
return decompress_end(codec); |
263 |
|
|
264 |
|
case ICM_DECOMPRESS : |
265 |
|
DPRINTF("ICM_DECOMPRESS"); |
266 |
|
return decompress(codec, (ICDECOMPRESS *)lParam1); |
267 |
|
|
268 |
|
case ICM_DECOMPRESS_GET_PALETTE : |
269 |
|
case ICM_DECOMPRESS_SET_PALETTE : |
270 |
|
case ICM_DECOMPRESSEX_QUERY: |
271 |
|
case ICM_DECOMPRESSEX_BEGIN: |
272 |
|
case ICM_DECOMPRESSEX_END: |
273 |
|
case ICM_DECOMPRESSEX: |
274 |
|
return ICERR_UNSUPPORTED; |
275 |
|
|
276 |
|
default: |
277 |
|
return DefDriverProc(dwDriverId, hDriver, uMsg, lParam1, lParam2); |
278 |
|
} |
279 |
|
} |
280 |
|
|
281 |
|
|
282 |
|
void WINAPI Configure(HWND hwnd, HINSTANCE hinst, LPTSTR lpCmdLine, int nCmdShow) |
283 |
|
{ |
284 |
|
DWORD dwDriverId; |
285 |
|
|
286 |
|
dwDriverId = DriverProc(0, 0, DRV_OPEN, 0, 0); |
287 |
|
if (dwDriverId != (DWORD)NULL) |
288 |
|
{ |
289 |
|
DriverProc(dwDriverId, 0, ICM_CONFIGURE, 0, 0); |
290 |
|
DriverProc(dwDriverId, 0, DRV_CLOSE, 0, 0); |
291 |
|
} |
292 |
|
} |