push d2ed94b6221baa59db3b40852d651a773c374f7d
[wine/hacks.git] / dlls / mciqtz32 / mciqtz.c
blob507956cd6bbbc73328feacc307289c42224567de
1 /*
2 * DirectShow MCI Driver
4 * Copyright 2009 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winuser.h"
25 #include "mmddk.h"
26 #include "wine/debug.h"
27 #include "mciqtz_private.h"
28 #include "digitalv.h"
29 #include "wownt32.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(mciqtz);
33 static DWORD MCIQTZ_mciClose(UINT, DWORD, LPMCI_GENERIC_PARMS);
34 static DWORD MCIQTZ_mciStop(UINT, DWORD, LPMCI_GENERIC_PARMS);
36 /*======================================================================*
37 * MCI QTZ implementation *
38 *======================================================================*/
40 HINSTANCE MCIQTZ_hInstance = 0;
42 /***********************************************************************
43 * DllMain (MCIQTZ.0)
45 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
47 switch (fdwReason) {
48 case DLL_PROCESS_ATTACH:
49 DisableThreadLibraryCalls(hInstDLL);
50 MCIQTZ_hInstance = hInstDLL;
51 break;
53 return TRUE;
56 /**************************************************************************
57 * MCIQTZ_drvOpen [internal]
59 static DWORD MCIQTZ_drvOpen(LPCWSTR str, LPMCI_OPEN_DRIVER_PARMSW modp)
61 WINE_MCIQTZ* wma;
63 TRACE("%s, %p\n", debugstr_w(str), modp);
65 /* session instance */
66 if (!modp)
67 return 0xFFFFFFFF;
69 wma = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCIQTZ));
70 if (!wma)
71 return 0;
73 wma->wDevID = modp->wDeviceID;
74 mciSetDriverData(wma->wDevID, (DWORD_PTR)wma);
76 return modp->wDeviceID;
79 /**************************************************************************
80 * MCIQTZ_drvClose [internal]
82 static DWORD MCIQTZ_drvClose(DWORD dwDevID)
84 WINE_MCIQTZ* wma;
86 TRACE("%04x\n", dwDevID);
88 /* finish all outstanding things */
89 MCIQTZ_mciClose(dwDevID, MCI_WAIT, NULL);
91 wma = (WINE_MCIQTZ*)mciGetDriverData(dwDevID);
93 if (wma) {
94 HeapFree(GetProcessHeap(), 0, wma);
95 return 1;
98 return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
101 /**************************************************************************
102 * MCIQTZ_drvConfigure [internal]
104 static DWORD MCIQTZ_drvConfigure(DWORD dwDevID)
106 WINE_MCIQTZ* wma;
108 TRACE("%04x\n", dwDevID);
110 MCIQTZ_mciStop(dwDevID, MCI_WAIT, NULL);
112 wma = (WINE_MCIQTZ*)mciGetDriverData(dwDevID);
114 if (wma) {
115 MessageBoxA(0, "Sample QTZ Wine Driver !", "MM-Wine Driver", MB_OK);
116 return 1;
119 return 0;
122 /**************************************************************************
123 * MCIQTZ_mciGetOpenDev [internal]
125 static WINE_MCIQTZ* MCIQTZ_mciGetOpenDev(UINT wDevID)
127 WINE_MCIQTZ* wma = (WINE_MCIQTZ*)mciGetDriverData(wDevID);
129 if (!wma) {
130 WARN("Invalid wDevID=%u\n", wDevID);
131 return 0;
133 return wma;
136 /***************************************************************************
137 * MCIQTZ_mciOpen [internal]
139 static DWORD MCIQTZ_mciOpen(UINT wDevID, DWORD dwFlags,
140 LPMCI_DGV_OPEN_PARMSW lpOpenParms)
142 WINE_MCIQTZ* wma;
143 HRESULT hr;
145 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpOpenParms);
147 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
149 if (!lpOpenParms)
150 return MCIERR_NULL_PARAMETER_BLOCK;
152 wma = (WINE_MCIQTZ*)mciGetDriverData(wDevID);
153 if (!wma)
154 return MCIERR_INVALID_DEVICE_ID;
156 CoInitializeEx(NULL, COINIT_MULTITHREADED);
158 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&wma->pgraph);
159 if (FAILED(hr)) {
160 TRACE("Cannot create filtergraph (hr = %x)\n", hr);
161 goto err;
164 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaControl, (LPVOID*)&wma->pmctrl);
165 if (FAILED(hr)) {
166 TRACE("Cannot get IMediaControl interface (hr = %x)\n", hr);
167 goto err;
170 if (!((dwFlags & MCI_OPEN_ELEMENT) && (dwFlags & MCI_OPEN_ELEMENT))) {
171 TRACE("Wrong dwFlags %x\n", dwFlags);
172 goto err;
175 if (!lpOpenParms->lpstrElementName && !lstrlenW(lpOpenParms->lpstrElementName)) {
176 TRACE("Invalid filename specified\n");
177 goto err;
180 TRACE("Open file %s\n", debugstr_w(lpOpenParms->lpstrElementName));
182 hr = IGraphBuilder_RenderFile(wma->pgraph, lpOpenParms->lpstrElementName, NULL);
183 if (FAILED(hr)) {
184 TRACE("Cannot render file (hr = %x)\n", hr);
185 goto err;
188 return 0;
190 err:
191 if (wma->pgraph)
192 IGraphBuilder_Release(wma->pgraph);
193 wma->pgraph = NULL;
194 if (wma->pmctrl)
195 IMediaControl_Release(wma->pmctrl);
196 wma->pmctrl = NULL;
198 CoUninitialize();
200 return MCIERR_INTERNAL;
203 /***************************************************************************
204 * MCIQTZ_mciClose [internal]
206 static DWORD MCIQTZ_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
208 WINE_MCIQTZ* wma;
210 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
212 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
214 wma = MCIQTZ_mciGetOpenDev(wDevID);
215 if (!wma)
216 return MCIERR_INVALID_DEVICE_ID;
218 if (wma->pgraph)
219 IGraphBuilder_Release(wma->pgraph);
220 wma->pgraph = NULL;
221 if (wma->pmctrl)
222 IMediaControl_Release(wma->pmctrl);
223 wma->pmctrl = NULL;
225 CoUninitialize();
227 return 0;
230 /***************************************************************************
231 * MCIQTZ_mciPlay [internal]
233 static DWORD MCIQTZ_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
235 WINE_MCIQTZ* wma;
236 HRESULT hr;
238 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
240 if (!lpParms)
241 return MCIERR_NULL_PARAMETER_BLOCK;
243 wma = MCIQTZ_mciGetOpenDev(wDevID);
245 hr = IMediaControl_Run(wma->pmctrl);
246 if (FAILED(hr)) {
247 TRACE("Cannot run filtergraph (hr = %x)\n", hr);
248 return MCIERR_INTERNAL;
251 wma->started = TRUE;
253 return 0;
256 /***************************************************************************
257 * MCIQTZ_mciSeek [internal]
259 static DWORD MCIQTZ_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
261 WINE_MCIQTZ* wma;
262 HRESULT hr;
263 IMediaPosition* pmpos;
264 LONGLONG newpos;
266 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
268 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
270 if (!lpParms)
271 return MCIERR_NULL_PARAMETER_BLOCK;
273 wma = MCIQTZ_mciGetOpenDev(wDevID);
274 if (!wma)
275 return MCIERR_INVALID_DEVICE_ID;
277 if (dwFlags & MCI_SEEK_TO_START) {
278 newpos = 0;
279 } else if (dwFlags & MCI_SEEK_TO_END) {
280 FIXME("MCI_SEEK_TO_END not implemented yet\n");
281 return MCIERR_INTERNAL;
282 } else if (dwFlags & MCI_TO) {
283 FIXME("MCI_TO not implemented yet\n");
284 return MCIERR_INTERNAL;
285 } else {
286 WARN("dwFlag doesn't tell where to seek to...\n");
287 return MCIERR_MISSING_PARAMETER;
290 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaPosition, (LPVOID*)&pmpos);
291 if (FAILED(hr)) {
292 FIXME("Cannot get IMediaPostion interface (hr = %x)\n", hr);
293 return MCIERR_INTERNAL;
296 hr = IMediaPosition_put_CurrentPosition(pmpos, newpos);
297 if (FAILED(hr)) {
298 FIXME("Cannot set position (hr = %x)\n", hr);
299 IMediaPosition_Release(pmpos);
300 return MCIERR_INTERNAL;
303 IMediaPosition_Release(pmpos);
305 if (dwFlags & MCI_NOTIFY)
306 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)), wDevID, MCI_NOTIFY_SUCCESSFUL);
308 return 0;
311 /***************************************************************************
312 * MCIQTZ_mciStop [internal]
314 static DWORD MCIQTZ_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
316 WINE_MCIQTZ* wma;
317 HRESULT hr;
319 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
321 wma = MCIQTZ_mciGetOpenDev(wDevID);
322 if (!wma)
323 return MCIERR_INVALID_DEVICE_ID;
325 if (!wma->started)
326 return 0;
328 hr = IMediaControl_Stop(wma->pmctrl);
329 if (FAILED(hr)) {
330 TRACE("Cannot stop filtergraph (hr = %x)\n", hr);
331 return MCIERR_INTERNAL;
334 wma->started = FALSE;
336 return 0;
339 /*======================================================================*
340 * MCI QTZ entry points *
341 *======================================================================*/
343 /**************************************************************************
344 * DriverProc (MCIQTZ.@)
346 LRESULT CALLBACK MCIQTZ_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
347 LPARAM dwParam1, LPARAM dwParam2)
349 TRACE("(%08lX, %p, %08X, %08lX, %08lX)\n",
350 dwDevID, hDriv, wMsg, dwParam1, dwParam2);
352 switch (wMsg) {
353 case DRV_LOAD: return 1;
354 case DRV_FREE: return 1;
355 case DRV_OPEN: return MCIQTZ_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
356 case DRV_CLOSE: return MCIQTZ_drvClose(dwDevID);
357 case DRV_ENABLE: return 1;
358 case DRV_DISABLE: return 1;
359 case DRV_QUERYCONFIGURE: return 1;
360 case DRV_CONFIGURE: return MCIQTZ_drvConfigure(dwDevID);
361 case DRV_INSTALL: return DRVCNF_RESTART;
362 case DRV_REMOVE: return DRVCNF_RESTART;
365 /* session instance */
366 if (dwDevID == 0xFFFFFFFF)
367 return 1;
369 switch (wMsg) {
370 case MCI_OPEN_DRIVER: return MCIQTZ_mciOpen (dwDevID, dwParam1, (LPMCI_DGV_OPEN_PARMSW) dwParam2);
371 case MCI_CLOSE_DRIVER: return MCIQTZ_mciClose (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
372 case MCI_PLAY: return MCIQTZ_mciPlay (dwDevID, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
373 case MCI_SEEK: return MCIQTZ_mciSeek (dwDevID, dwParam1, (LPMCI_SEEK_PARMS) dwParam2);
374 case MCI_RECORD:
375 case MCI_STOP:
376 case MCI_SET:
377 case MCI_PAUSE:
378 case MCI_RESUME:
379 case MCI_STATUS:
380 case MCI_GETDEVCAPS:
381 case MCI_INFO:
382 case MCI_PUT:
383 case MCI_WINDOW:
384 case MCI_LOAD:
385 case MCI_SAVE:
386 case MCI_FREEZE:
387 case MCI_REALIZE:
388 case MCI_UNFREEZE:
389 case MCI_UPDATE:
390 case MCI_WHERE:
391 case MCI_STEP:
392 case MCI_COPY:
393 case MCI_CUT:
394 case MCI_DELETE:
395 case MCI_PASTE:
396 case MCI_CUE:
397 /* Digital Video specific */
398 case MCI_CAPTURE:
399 case MCI_MONITOR:
400 case MCI_RESERVE:
401 case MCI_SETAUDIO:
402 case MCI_SIGNAL:
403 case MCI_SETVIDEO:
404 case MCI_QUALITY:
405 case MCI_LIST:
406 case MCI_UNDO:
407 case MCI_CONFIGURE:
408 case MCI_RESTORE:
409 FIXME("Unimplemented command [%u]\n", wMsg);
410 break;
411 case MCI_SPIN:
412 case MCI_ESCAPE:
413 WARN("Unsupported command [%u]\n", wMsg);
414 break;
415 case MCI_OPEN:
416 case MCI_CLOSE:
417 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
418 break;
419 default:
420 TRACE("Sending msg [%u] to default driver proc\n", wMsg);
421 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
424 return MCIERR_UNRECOGNIZED_COMMAND;