mciqtz32: Remove all remaining tabs.
[wine/hacks.git] / dlls / mciqtz32 / mciqtz.c
blob63b80f581781ef815f99befb7141871a9f20a4f6
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 || !lpOpenParms->lpstrElementName[0]) {
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 wma->opened = TRUE;
190 return 0;
192 err:
193 if (wma->pgraph)
194 IGraphBuilder_Release(wma->pgraph);
195 wma->pgraph = NULL;
196 if (wma->pmctrl)
197 IMediaControl_Release(wma->pmctrl);
198 wma->pmctrl = NULL;
200 CoUninitialize();
202 return MCIERR_INTERNAL;
205 /***************************************************************************
206 * MCIQTZ_mciClose [internal]
208 static DWORD MCIQTZ_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
210 WINE_MCIQTZ* wma;
212 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
214 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
216 wma = MCIQTZ_mciGetOpenDev(wDevID);
217 if (!wma)
218 return MCIERR_INVALID_DEVICE_ID;
220 if (wma->opened) {
221 IGraphBuilder_Release(wma->pgraph);
222 IMediaControl_Release(wma->pmctrl);
223 CoUninitialize();
224 wma->opened = FALSE;
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 * MCIQTZ_mciStatus [internal]
342 static DWORD MCIQTZ_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_DGV_STATUS_PARMSW lpParms)
344 WINE_MCIQTZ* wma;
346 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
348 if (!lpParms)
349 return MCIERR_NULL_PARAMETER_BLOCK;
351 wma = MCIQTZ_mciGetOpenDev(wDevID);
352 if (!wma)
353 return MCIERR_INVALID_DEVICE_ID;
355 if (!(dwFlags & MCI_STATUS_ITEM)) {
356 WARN("No status item specified\n");
357 return MCIERR_UNRECOGNIZED_COMMAND;
360 switch (lpParms->dwItem) {
361 case MCI_STATUS_LENGTH:
362 FIXME("MCI_STATUS_LENGTH not implemented yet\n");
363 return MCIERR_UNRECOGNIZED_COMMAND;
364 case MCI_STATUS_POSITION:
366 HRESULT hr;
367 REFTIME curpos;
368 IMediaPosition* pmpos;
370 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaPosition, (LPVOID*)&pmpos);
371 if (FAILED(hr)) {
372 FIXME("Cannot get IMediaPostion interface (hr = %x)\n", hr);
373 return MCIERR_INTERNAL;
376 hr = IMediaPosition_get_CurrentPosition(pmpos, &curpos);
377 if (FAILED(hr)) {
378 FIXME("Cannot get position (hr = %x)\n", hr);
379 IMediaPosition_Release(pmpos);
380 return MCIERR_INTERNAL;
383 IMediaPosition_Release(pmpos);
384 lpParms->dwReturn = curpos / 10000;
386 break;
388 case MCI_STATUS_NUMBER_OF_TRACKS:
389 FIXME("MCI_STATUS_NUMBER_OF_TRACKS not implemented yet\n");
390 return MCIERR_UNRECOGNIZED_COMMAND;
391 case MCI_STATUS_MODE:
392 FIXME("MCI_STATUS_MODE not implemented yet\n");
393 return MCIERR_UNRECOGNIZED_COMMAND;
394 case MCI_STATUS_MEDIA_PRESENT:
395 FIXME("MCI_STATUS_MEDIA_PRESENT not implemented yet\n");
396 return MCIERR_UNRECOGNIZED_COMMAND;
397 case MCI_STATUS_TIME_FORMAT:
398 FIXME("MCI_STATUS_TIME_FORMAT not implemented yet\n");
399 return MCIERR_UNRECOGNIZED_COMMAND;
400 case MCI_STATUS_READY:
401 FIXME("MCI_STATUS_READY not implemented yet\n");
402 return MCIERR_UNRECOGNIZED_COMMAND;
403 case MCI_STATUS_CURRENT_TRACK:
404 FIXME("MCI_STATUS_CURRENT_TRACK not implemented yet\n");
405 return MCIERR_UNRECOGNIZED_COMMAND;
406 default:
407 FIXME("Unknown command %08X\n", lpParms->dwItem);
408 return MCIERR_UNRECOGNIZED_COMMAND;
411 if (dwFlags & MCI_NOTIFY)
412 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)), wDevID, MCI_NOTIFY_SUCCESSFUL);
414 return 0;
417 /*======================================================================*
418 * MCI QTZ entry points *
419 *======================================================================*/
421 /**************************************************************************
422 * DriverProc (MCIQTZ.@)
424 LRESULT CALLBACK MCIQTZ_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
425 LPARAM dwParam1, LPARAM dwParam2)
427 TRACE("(%08lX, %p, %08X, %08lX, %08lX)\n",
428 dwDevID, hDriv, wMsg, dwParam1, dwParam2);
430 switch (wMsg) {
431 case DRV_LOAD: return 1;
432 case DRV_FREE: return 1;
433 case DRV_OPEN: return MCIQTZ_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
434 case DRV_CLOSE: return MCIQTZ_drvClose(dwDevID);
435 case DRV_ENABLE: return 1;
436 case DRV_DISABLE: return 1;
437 case DRV_QUERYCONFIGURE: return 1;
438 case DRV_CONFIGURE: return MCIQTZ_drvConfigure(dwDevID);
439 case DRV_INSTALL: return DRVCNF_RESTART;
440 case DRV_REMOVE: return DRVCNF_RESTART;
443 /* session instance */
444 if (dwDevID == 0xFFFFFFFF)
445 return 1;
447 switch (wMsg) {
448 case MCI_OPEN_DRIVER: return MCIQTZ_mciOpen (dwDevID, dwParam1, (LPMCI_DGV_OPEN_PARMSW) dwParam2);
449 case MCI_CLOSE_DRIVER: return MCIQTZ_mciClose (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
450 case MCI_PLAY: return MCIQTZ_mciPlay (dwDevID, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
451 case MCI_SEEK: return MCIQTZ_mciSeek (dwDevID, dwParam1, (LPMCI_SEEK_PARMS) dwParam2);
452 case MCI_STOP: return MCIQTZ_mciStop (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
453 case MCI_STATUS: return MCIQTZ_mciStatus (dwDevID, dwParam1, (LPMCI_DGV_STATUS_PARMSW) dwParam2);
454 case MCI_RECORD:
455 case MCI_SET:
456 case MCI_PAUSE:
457 case MCI_RESUME:
458 case MCI_GETDEVCAPS:
459 case MCI_INFO:
460 case MCI_PUT:
461 case MCI_WINDOW:
462 case MCI_LOAD:
463 case MCI_SAVE:
464 case MCI_FREEZE:
465 case MCI_REALIZE:
466 case MCI_UNFREEZE:
467 case MCI_UPDATE:
468 case MCI_WHERE:
469 case MCI_STEP:
470 case MCI_COPY:
471 case MCI_CUT:
472 case MCI_DELETE:
473 case MCI_PASTE:
474 case MCI_CUE:
475 /* Digital Video specific */
476 case MCI_CAPTURE:
477 case MCI_MONITOR:
478 case MCI_RESERVE:
479 case MCI_SETAUDIO:
480 case MCI_SIGNAL:
481 case MCI_SETVIDEO:
482 case MCI_QUALITY:
483 case MCI_LIST:
484 case MCI_UNDO:
485 case MCI_CONFIGURE:
486 case MCI_RESTORE:
487 FIXME("Unimplemented command [%08X]\n", wMsg);
488 break;
489 case MCI_SPIN:
490 case MCI_ESCAPE:
491 WARN("Unsupported command [%08X]\n", wMsg);
492 break;
493 case MCI_OPEN:
494 case MCI_CLOSE:
495 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
496 break;
497 default:
498 TRACE("Sending msg [%08X] to default driver proc\n", wMsg);
499 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
502 return MCIERR_UNRECOGNIZED_COMMAND;