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