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"
30 WINE_DEFAULT_DEBUG_CHANNEL(mciqtz);
32 static DWORD MCIQTZ_mciClose(UINT, DWORD, LPMCI_GENERIC_PARMS);
33 static DWORD MCIQTZ_mciStop(UINT, DWORD, LPMCI_GENERIC_PARMS);
35 /*======================================================================*
36 * MCI QTZ implementation *
37 *======================================================================*/
39 HINSTANCE MCIQTZ_hInstance = 0;
41 /***********************************************************************
44 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
47 case DLL_PROCESS_ATTACH:
48 DisableThreadLibraryCalls(hInstDLL);
49 MCIQTZ_hInstance = hInstDLL;
55 /**************************************************************************
56 * MCIQTZ_drvOpen [internal]
58 static DWORD MCIQTZ_drvOpen(LPCWSTR str, LPMCI_OPEN_DRIVER_PARMSW modp)
62 TRACE("%s, %p\n", debugstr_w(str), modp);
64 /* session instance */
68 wma = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCIQTZ));
72 wma->wDevID = modp->wDeviceID;
73 mciSetDriverData(wma->wDevID, (DWORD_PTR)wma);
75 return modp->wDeviceID;
78 /**************************************************************************
79 * MCIQTZ_drvClose [internal]
81 static DWORD MCIQTZ_drvClose(DWORD dwDevID)
85 TRACE("%04x\n", dwDevID);
87 /* finish all outstanding things */
88 MCIQTZ_mciClose(dwDevID, MCI_WAIT, NULL);
90 wma = (WINE_MCIQTZ*)mciGetDriverData(dwDevID);
93 HeapFree(GetProcessHeap(), 0, wma);
97 return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
100 /**************************************************************************
101 * MCIQTZ_drvConfigure [internal]
103 static DWORD MCIQTZ_drvConfigure(DWORD dwDevID)
107 TRACE("%04x\n", dwDevID);
109 MCIQTZ_mciStop(dwDevID, MCI_WAIT, NULL);
111 wma = (WINE_MCIQTZ*)mciGetDriverData(dwDevID);
114 MessageBoxA(0, "Sample QTZ Wine Driver !", "MM-Wine Driver", MB_OK);
121 /**************************************************************************
122 * MCIQTZ_mciGetOpenDev [internal]
124 static WINE_MCIQTZ* MCIQTZ_mciGetOpenDev(UINT wDevID)
126 WINE_MCIQTZ* wma = (WINE_MCIQTZ*)mciGetDriverData(wDevID);
129 WARN("Invalid wDevID=%u\n", wDevID);
135 /***************************************************************************
136 * MCIQTZ_mciOpen [internal]
138 static DWORD MCIQTZ_mciOpen(UINT wDevID, DWORD dwFlags,
139 LPMCI_DGV_OPEN_PARMSW lpOpenParms)
144 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpOpenParms);
146 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
149 return MCIERR_NULL_PARAMETER_BLOCK;
151 wma = (WINE_MCIQTZ*)mciGetDriverData(wDevID);
153 return MCIERR_INVALID_DEVICE_ID;
155 CoInitializeEx(NULL, COINIT_MULTITHREADED);
157 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&wma->pgraph);
159 TRACE("Cannot create filtergraph (hr = %x)\n", hr);
163 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaControl, (LPVOID*)&wma->pmctrl);
165 TRACE("Cannot get IMediaControl interface (hr = %x)\n", hr);
169 if (!((dwFlags & MCI_OPEN_ELEMENT) && (dwFlags & MCI_OPEN_ELEMENT))) {
170 TRACE("Wrong dwFlags %x\n", dwFlags);
174 if (!lpOpenParms->lpstrElementName && !lstrlenW(lpOpenParms->lpstrElementName)) {
175 TRACE("Invalid filename specified\n");
179 TRACE("Open file %s\n", debugstr_w(lpOpenParms->lpstrElementName));
181 hr = IGraphBuilder_RenderFile(wma->pgraph, lpOpenParms->lpstrElementName, NULL);
183 TRACE("Cannot render file (hr = %x)\n", hr);
191 IGraphBuilder_Release(wma->pgraph);
194 IMediaControl_Release(wma->pmctrl);
199 return MCIERR_INTERNAL;
202 /***************************************************************************
203 * MCIQTZ_mciClose [internal]
205 static DWORD MCIQTZ_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
209 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
211 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
213 wma = MCIQTZ_mciGetOpenDev(wDevID);
215 return MCIERR_INVALID_DEVICE_ID;
218 IGraphBuilder_Release(wma->pgraph);
221 IMediaControl_Release(wma->pmctrl);
229 /***************************************************************************
230 * MCIQTZ_mciPlay [internal]
232 static DWORD MCIQTZ_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
237 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
240 return MCIERR_NULL_PARAMETER_BLOCK;
242 wma = MCIQTZ_mciGetOpenDev(wDevID);
244 hr = IMediaControl_Run(wma->pmctrl);
246 TRACE("Cannot run filtergraph (hr = %x)\n", hr);
247 return MCIERR_INTERNAL;
255 /***************************************************************************
256 * MCIQTZ_mciStop [internal]
258 static DWORD MCIQTZ_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
263 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
265 wma = MCIQTZ_mciGetOpenDev(wDevID);
267 return MCIERR_INVALID_DEVICE_ID;
272 hr = IMediaControl_Stop(wma->pmctrl);
274 TRACE("Cannot stop filtergraph (hr = %x)\n", hr);
275 return MCIERR_INTERNAL;
278 wma->started = FALSE;
283 /*======================================================================*
284 * MCI QTZ entry points *
285 *======================================================================*/
287 /**************************************************************************
288 * DriverProc (MCIQTZ.@)
290 LRESULT CALLBACK MCIQTZ_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
291 LPARAM dwParam1, LPARAM dwParam2)
293 TRACE("(%08lX, %p, %08X, %08lX, %08lX)\n",
294 dwDevID, hDriv, wMsg, dwParam1, dwParam2);
297 case DRV_LOAD: return 1;
298 case DRV_FREE: return 1;
299 case DRV_OPEN: return MCIQTZ_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
300 case DRV_CLOSE: return MCIQTZ_drvClose(dwDevID);
301 case DRV_ENABLE: return 1;
302 case DRV_DISABLE: return 1;
303 case DRV_QUERYCONFIGURE: return 1;
304 case DRV_CONFIGURE: return MCIQTZ_drvConfigure(dwDevID);
305 case DRV_INSTALL: return DRVCNF_RESTART;
306 case DRV_REMOVE: return DRVCNF_RESTART;
309 /* session instance */
310 if (dwDevID == 0xFFFFFFFF)
314 case MCI_OPEN_DRIVER: return MCIQTZ_mciOpen (dwDevID, dwParam1, (LPMCI_DGV_OPEN_PARMSW) dwParam2);
315 case MCI_CLOSE_DRIVER: return MCIQTZ_mciClose (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
316 case MCI_PLAY: return MCIQTZ_mciPlay (dwDevID, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
341 /* Digital Video specific */
353 FIXME("Unimplemented command [%u]\n", wMsg);
357 WARN("Unsupported command [%u]\n", wMsg);
361 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
364 TRACE("Sending msg [%u] to default driver proc\n", wMsg);
365 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
368 return MCIERR_UNRECOGNIZED_COMMAND;