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
26 #include "wine/debug.h"
27 #include "mciqtz_private.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 /***********************************************************************
45 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
48 case DLL_PROCESS_ATTACH:
49 DisableThreadLibraryCalls(hInstDLL);
50 MCIQTZ_hInstance = hInstDLL;
56 /**************************************************************************
57 * MCIQTZ_drvOpen [internal]
59 static DWORD MCIQTZ_drvOpen(LPCWSTR str, LPMCI_OPEN_DRIVER_PARMSW modp)
63 TRACE("(%s, %p)\n", debugstr_w(str), modp);
65 /* session instance */
69 wma = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCIQTZ));
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)
86 TRACE("(%04x)\n", dwDevID);
88 /* finish all outstanding things */
89 MCIQTZ_mciClose(dwDevID, MCI_WAIT, NULL);
91 wma = (WINE_MCIQTZ*)mciGetDriverData(dwDevID);
94 HeapFree(GetProcessHeap(), 0, wma);
98 return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
101 /**************************************************************************
102 * MCIQTZ_drvConfigure [internal]
104 static DWORD MCIQTZ_drvConfigure(DWORD dwDevID)
108 TRACE("(%04x)\n", dwDevID);
110 MCIQTZ_mciStop(dwDevID, MCI_WAIT, NULL);
112 wma = (WINE_MCIQTZ*)mciGetDriverData(dwDevID);
115 MessageBoxA(0, "Sample QTZ Wine Driver !", "MM-Wine Driver", MB_OK);
122 /**************************************************************************
123 * MCIQTZ_mciGetOpenDev [internal]
125 static WINE_MCIQTZ* MCIQTZ_mciGetOpenDev(UINT wDevID)
127 WINE_MCIQTZ* wma = (WINE_MCIQTZ*)mciGetDriverData(wDevID);
130 WARN("Invalid wDevID=%u\n", wDevID);
136 /***************************************************************************
137 * MCIQTZ_mciOpen [internal]
139 static DWORD MCIQTZ_mciOpen(UINT wDevID, DWORD dwFlags,
140 LPMCI_DGV_OPEN_PARMSW lpOpenParms)
145 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpOpenParms);
147 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
150 return MCIERR_NULL_PARAMETER_BLOCK;
152 wma = (WINE_MCIQTZ*)mciGetDriverData(wDevID);
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);
160 TRACE("Cannot create filtergraph (hr = %x)\n", hr);
164 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaControl, (LPVOID*)&wma->pmctrl);
166 TRACE("Cannot get IMediaControl interface (hr = %x)\n", hr);
170 if (!((dwFlags & MCI_OPEN_ELEMENT) && (dwFlags & MCI_OPEN_ELEMENT))) {
171 TRACE("Wrong dwFlags %x\n", dwFlags);
175 if (!lpOpenParms->lpstrElementName || !lpOpenParms->lpstrElementName[0]) {
176 TRACE("Invalid filename specified\n");
180 TRACE("Open file %s\n", debugstr_w(lpOpenParms->lpstrElementName));
182 hr = IGraphBuilder_RenderFile(wma->pgraph, lpOpenParms->lpstrElementName, NULL);
184 TRACE("Cannot render file (hr = %x)\n", hr);
194 IGraphBuilder_Release(wma->pgraph);
197 IMediaControl_Release(wma->pmctrl);
202 return MCIERR_INTERNAL;
205 /***************************************************************************
206 * MCIQTZ_mciClose [internal]
208 static DWORD MCIQTZ_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
212 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
214 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
216 wma = MCIQTZ_mciGetOpenDev(wDevID);
218 return MCIERR_INVALID_DEVICE_ID;
221 IGraphBuilder_Release(wma->pgraph);
222 IMediaControl_Release(wma->pmctrl);
230 /***************************************************************************
231 * MCIQTZ_mciPlay [internal]
233 static DWORD MCIQTZ_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
238 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
241 return MCIERR_NULL_PARAMETER_BLOCK;
243 wma = MCIQTZ_mciGetOpenDev(wDevID);
245 hr = IMediaControl_Run(wma->pmctrl);
247 TRACE("Cannot run filtergraph (hr = %x)\n", hr);
248 return MCIERR_INTERNAL;
256 /***************************************************************************
257 * MCIQTZ_mciSeek [internal]
259 static DWORD MCIQTZ_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
263 IMediaPosition* pmpos;
266 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
268 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
271 return MCIERR_NULL_PARAMETER_BLOCK;
273 wma = MCIQTZ_mciGetOpenDev(wDevID);
275 return MCIERR_INVALID_DEVICE_ID;
277 if (dwFlags & MCI_SEEK_TO_START) {
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;
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);
292 FIXME("Cannot get IMediaPostion interface (hr = %x)\n", hr);
293 return MCIERR_INTERNAL;
296 hr = IMediaPosition_put_CurrentPosition(pmpos, newpos);
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);
311 /***************************************************************************
312 * MCIQTZ_mciStop [internal]
314 static DWORD MCIQTZ_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
319 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
321 wma = MCIQTZ_mciGetOpenDev(wDevID);
323 return MCIERR_INVALID_DEVICE_ID;
328 hr = IMediaControl_Stop(wma->pmctrl);
330 TRACE("Cannot stop filtergraph (hr = %x)\n", hr);
331 return MCIERR_INTERNAL;
334 wma->started = FALSE;
339 /***************************************************************************
340 * MCIQTZ_mciStatus [internal]
342 static DWORD MCIQTZ_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_DGV_STATUS_PARMSW lpParms)
346 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
349 return MCIERR_NULL_PARAMETER_BLOCK;
351 wma = MCIQTZ_mciGetOpenDev(wDevID);
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:
368 IMediaPosition* pmpos;
370 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaPosition, (LPVOID*)&pmpos);
372 FIXME("Cannot get IMediaPostion interface (hr = %x)\n", hr);
373 return MCIERR_INTERNAL;
376 hr = IMediaPosition_get_CurrentPosition(pmpos, &curpos);
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;
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;
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);
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);
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)
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);
475 /* Digital Video specific */
487 FIXME("Unimplemented command [%08X]\n", wMsg);
491 WARN("Unsupported command [%08X]\n", wMsg);
495 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
498 TRACE("Sending msg [%08X] to default driver proc\n", wMsg);
499 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
502 return MCIERR_UNRECOGNIZED_COMMAND;