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
);
192 IGraphBuilder_Release(wma
->pgraph
);
195 IMediaControl_Release(wma
->pmctrl
);
200 return MCIERR_INTERNAL
;
203 /***************************************************************************
204 * MCIQTZ_mciClose [internal]
206 static DWORD
MCIQTZ_mciClose(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
210 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
212 MCIQTZ_mciStop(wDevID
, MCI_WAIT
, NULL
);
214 wma
= MCIQTZ_mciGetOpenDev(wDevID
);
216 return MCIERR_INVALID_DEVICE_ID
;
219 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 * 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
);
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)
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
);
397 /* Digital Video specific */
409 FIXME("Unimplemented command [%u]\n", wMsg
);
413 WARN("Unsupported command [%u]\n", wMsg
);
417 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
420 TRACE("Sending msg [%u] to default driver proc\n", wMsg
);
421 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
424 return MCIERR_UNRECOGNIZED_COMMAND
;