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_mciGetOpenDev [internal]
59 static WINE_MCIQTZ
* MCIQTZ_mciGetOpenDev(UINT wDevID
)
61 WINE_MCIQTZ
* wma
= (WINE_MCIQTZ
*)mciGetDriverData(wDevID
);
64 WARN("Invalid wDevID=%u\n", wDevID
);
70 /**************************************************************************
71 * MCIQTZ_drvOpen [internal]
73 static DWORD
MCIQTZ_drvOpen(LPCWSTR str
, LPMCI_OPEN_DRIVER_PARMSW modp
)
77 TRACE("(%s, %p)\n", debugstr_w(str
), modp
);
79 /* session instance */
83 wma
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINE_MCIQTZ
));
87 wma
->wDevID
= modp
->wDeviceID
;
88 mciSetDriverData(wma
->wDevID
, (DWORD_PTR
)wma
);
90 return modp
->wDeviceID
;
93 /**************************************************************************
94 * MCIQTZ_drvClose [internal]
96 static DWORD
MCIQTZ_drvClose(DWORD dwDevID
)
100 TRACE("(%04x)\n", dwDevID
);
102 wma
= MCIQTZ_mciGetOpenDev(dwDevID
);
105 /* finish all outstanding things */
106 MCIQTZ_mciClose(dwDevID
, MCI_WAIT
, NULL
);
108 HeapFree(GetProcessHeap(), 0, wma
);
112 return (dwDevID
== 0xFFFFFFFF) ? 1 : 0;
115 /**************************************************************************
116 * MCIQTZ_drvConfigure [internal]
118 static DWORD
MCIQTZ_drvConfigure(DWORD dwDevID
)
122 TRACE("(%04x)\n", dwDevID
);
124 wma
= MCIQTZ_mciGetOpenDev(dwDevID
);
128 MCIQTZ_mciStop(dwDevID
, MCI_WAIT
, NULL
);
130 MessageBoxA(0, "Sample QTZ Wine Driver !", "MM-Wine Driver", MB_OK
);
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
);
147 return MCIERR_NULL_PARAMETER_BLOCK
;
149 wma
= MCIQTZ_mciGetOpenDev(wDevID
);
151 return MCIERR_INVALID_DEVICE_ID
;
153 MCIQTZ_mciStop(wDevID
, MCI_WAIT
, NULL
);
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
|| !lpOpenParms
->lpstrElementName
[0]) {
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
);
193 IGraphBuilder_Release(wma
->pgraph
);
196 IMediaControl_Release(wma
->pmctrl
);
201 return MCIERR_INTERNAL
;
204 /***************************************************************************
205 * MCIQTZ_mciClose [internal]
207 static DWORD
MCIQTZ_mciClose(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
211 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
213 wma
= MCIQTZ_mciGetOpenDev(wDevID
);
215 return MCIERR_INVALID_DEVICE_ID
;
217 MCIQTZ_mciStop(wDevID
, MCI_WAIT
, NULL
);
220 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 return MCIERR_INVALID_DEVICE_ID
;
246 hr
= IMediaControl_Run(wma
->pmctrl
);
248 TRACE("Cannot run filtergraph (hr = %x)\n", hr
);
249 return MCIERR_INTERNAL
;
257 /***************************************************************************
258 * MCIQTZ_mciSeek [internal]
260 static DWORD
MCIQTZ_mciSeek(UINT wDevID
, DWORD dwFlags
, LPMCI_SEEK_PARMS lpParms
)
264 IMediaPosition
* pmpos
;
267 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
270 return MCIERR_NULL_PARAMETER_BLOCK
;
272 wma
= MCIQTZ_mciGetOpenDev(wDevID
);
274 return MCIERR_INVALID_DEVICE_ID
;
276 MCIQTZ_mciStop(wDevID
, MCI_WAIT
, NULL
);
278 if (dwFlags
& MCI_SEEK_TO_START
) {
280 } else if (dwFlags
& MCI_SEEK_TO_END
) {
281 FIXME("MCI_SEEK_TO_END not implemented yet\n");
282 return MCIERR_INTERNAL
;
283 } else if (dwFlags
& MCI_TO
) {
284 FIXME("MCI_TO not implemented yet\n");
285 return MCIERR_INTERNAL
;
287 WARN("dwFlag doesn't tell where to seek to...\n");
288 return MCIERR_MISSING_PARAMETER
;
291 hr
= IGraphBuilder_QueryInterface(wma
->pgraph
, &IID_IMediaPosition
, (LPVOID
*)&pmpos
);
293 FIXME("Cannot get IMediaPostion interface (hr = %x)\n", hr
);
294 return MCIERR_INTERNAL
;
297 hr
= IMediaPosition_put_CurrentPosition(pmpos
, newpos
);
299 FIXME("Cannot set position (hr = %x)\n", hr
);
300 IMediaPosition_Release(pmpos
);
301 return MCIERR_INTERNAL
;
304 IMediaPosition_Release(pmpos
);
306 if (dwFlags
& MCI_NOTIFY
)
307 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)), wDevID
, MCI_NOTIFY_SUCCESSFUL
);
312 /***************************************************************************
313 * MCIQTZ_mciStop [internal]
315 static DWORD
MCIQTZ_mciStop(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
320 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
322 wma
= MCIQTZ_mciGetOpenDev(wDevID
);
324 return MCIERR_INVALID_DEVICE_ID
;
329 hr
= IMediaControl_Stop(wma
->pmctrl
);
331 TRACE("Cannot stop filtergraph (hr = %x)\n", hr
);
332 return MCIERR_INTERNAL
;
335 wma
->started
= FALSE
;
340 /***************************************************************************
341 * MCIQTZ_mciGetDevCaps [internal]
343 static DWORD
MCIQTZ_mciGetDevCaps(UINT wDevID
, DWORD dwFlags
, LPMCI_GETDEVCAPS_PARMS lpParms
)
347 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
350 return MCIERR_NULL_PARAMETER_BLOCK
;
352 wma
= MCIQTZ_mciGetOpenDev(wDevID
);
354 return MCIERR_INVALID_DEVICE_ID
;
356 if (!(dwFlags
& MCI_STATUS_ITEM
)) {
357 WARN("No capability item specified\n");
358 return MCIERR_UNRECOGNIZED_COMMAND
;
361 switch (lpParms
->dwItem
) {
362 case MCI_GETDEVCAPS_CAN_RECORD
:
363 lpParms
->dwReturn
= MAKEMCIRESOURCE(FALSE
, MCI_FALSE
);
364 TRACE("MCI_GETDEVCAPS_CAN_RECORD = %08x\n", lpParms
->dwReturn
);
366 case MCI_GETDEVCAPS_HAS_AUDIO
:
367 lpParms
->dwReturn
= MAKEMCIRESOURCE(TRUE
, MCI_TRUE
);
368 TRACE("MCI_GETDEVCAPS_HAS_AUDIO = %08x\n", lpParms
->dwReturn
);
370 case MCI_GETDEVCAPS_HAS_VIDEO
:
371 lpParms
->dwReturn
= MAKEMCIRESOURCE(TRUE
, MCI_TRUE
);
372 TRACE("MCI_GETDEVCAPS_HAS_VIDEO = %08x\n", lpParms
->dwReturn
);
374 case MCI_GETDEVCAPS_DEVICE_TYPE
:
375 lpParms
->dwReturn
= MAKEMCIRESOURCE(MCI_DEVTYPE_DIGITAL_VIDEO
, MCI_DEVTYPE_DIGITAL_VIDEO
);
376 TRACE("MCI_GETDEVCAPS_DEVICE_TYPE = %08x\n", lpParms
->dwReturn
);
378 case MCI_GETDEVCAPS_USES_FILES
:
379 lpParms
->dwReturn
= MAKEMCIRESOURCE(TRUE
, MCI_TRUE
);
380 TRACE("MCI_GETDEVCAPS_USES_FILES = %08x\n", lpParms
->dwReturn
);
382 case MCI_GETDEVCAPS_COMPOUND_DEVICE
:
383 lpParms
->dwReturn
= MAKEMCIRESOURCE(TRUE
, MCI_TRUE
);
384 TRACE("MCI_GETDEVCAPS_COMPOUND_DEVICE = %08x\n", lpParms
->dwReturn
);
386 case MCI_GETDEVCAPS_CAN_EJECT
:
387 lpParms
->dwReturn
= MAKEMCIRESOURCE(FALSE
, MCI_FALSE
);
388 TRACE("MCI_GETDEVCAPS_EJECT = %08x\n", lpParms
->dwReturn
);
390 case MCI_GETDEVCAPS_CAN_PLAY
:
391 lpParms
->dwReturn
= MAKEMCIRESOURCE(TRUE
, MCI_TRUE
);
392 TRACE("MCI_GETDEVCAPS_CAN_PLAY = %08x\n", lpParms
->dwReturn
);
394 case MCI_GETDEVCAPS_CAN_SAVE
:
395 lpParms
->dwReturn
= MAKEMCIRESOURCE(FALSE
, MCI_FALSE
);
396 TRACE("MCI_GETDEVCAPS_CAN_SAVE = %08x\n", lpParms
->dwReturn
);
399 ERR("Unknown capability %08x\n", lpParms
->dwItem
);
400 return MCIERR_UNRECOGNIZED_COMMAND
;
403 return MCI_RESOURCE_RETURNED
;
406 /***************************************************************************
407 * MCIQTZ_mciStatus [internal]
409 static DWORD
MCIQTZ_mciStatus(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_STATUS_PARMSW lpParms
)
413 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
416 return MCIERR_NULL_PARAMETER_BLOCK
;
418 wma
= MCIQTZ_mciGetOpenDev(wDevID
);
420 return MCIERR_INVALID_DEVICE_ID
;
422 if (!(dwFlags
& MCI_STATUS_ITEM
)) {
423 WARN("No status item specified\n");
424 return MCIERR_UNRECOGNIZED_COMMAND
;
427 switch (lpParms
->dwItem
) {
428 case MCI_STATUS_LENGTH
:
429 FIXME("MCI_STATUS_LENGTH not implemented yet\n");
430 return MCIERR_UNRECOGNIZED_COMMAND
;
431 case MCI_STATUS_POSITION
:
435 IMediaPosition
* pmpos
;
437 hr
= IGraphBuilder_QueryInterface(wma
->pgraph
, &IID_IMediaPosition
, (LPVOID
*)&pmpos
);
439 FIXME("Cannot get IMediaPostion interface (hr = %x)\n", hr
);
440 return MCIERR_INTERNAL
;
443 hr
= IMediaPosition_get_CurrentPosition(pmpos
, &curpos
);
445 FIXME("Cannot get position (hr = %x)\n", hr
);
446 IMediaPosition_Release(pmpos
);
447 return MCIERR_INTERNAL
;
450 IMediaPosition_Release(pmpos
);
451 lpParms
->dwReturn
= curpos
/ 10000;
455 case MCI_STATUS_NUMBER_OF_TRACKS
:
456 FIXME("MCI_STATUS_NUMBER_OF_TRACKS not implemented yet\n");
457 return MCIERR_UNRECOGNIZED_COMMAND
;
458 case MCI_STATUS_MODE
:
459 FIXME("MCI_STATUS_MODE not implemented yet\n");
460 return MCIERR_UNRECOGNIZED_COMMAND
;
461 case MCI_STATUS_MEDIA_PRESENT
:
462 FIXME("MCI_STATUS_MEDIA_PRESENT not implemented yet\n");
463 return MCIERR_UNRECOGNIZED_COMMAND
;
464 case MCI_STATUS_TIME_FORMAT
:
465 FIXME("MCI_STATUS_TIME_FORMAT not implemented yet\n");
466 return MCIERR_UNRECOGNIZED_COMMAND
;
467 case MCI_STATUS_READY
:
468 FIXME("MCI_STATUS_READY not implemented yet\n");
469 return MCIERR_UNRECOGNIZED_COMMAND
;
470 case MCI_STATUS_CURRENT_TRACK
:
471 FIXME("MCI_STATUS_CURRENT_TRACK not implemented yet\n");
472 return MCIERR_UNRECOGNIZED_COMMAND
;
474 FIXME("Unknown command %08X\n", lpParms
->dwItem
);
475 return MCIERR_UNRECOGNIZED_COMMAND
;
478 if (dwFlags
& MCI_NOTIFY
)
479 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)), wDevID
, MCI_NOTIFY_SUCCESSFUL
);
484 /***************************************************************************
485 * MCIQTZ_mciWhere [internal]
487 static DWORD
MCIQTZ_mciWhere(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_RECT_PARMS lpParms
)
490 IVideoWindow
* pVideoWindow
;
495 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
498 return MCIERR_NULL_PARAMETER_BLOCK
;
500 wma
= MCIQTZ_mciGetOpenDev(wDevID
);
502 return MCIERR_INVALID_DEVICE_ID
;
504 /* Find if there is a video stream and get the display window */
505 hr
= IGraphBuilder_QueryInterface(wma
->pgraph
, &IID_IVideoWindow
, (LPVOID
*)&pVideoWindow
);
507 ERR("Cannot get IVideoWindow interface (hr = %x)\n", hr
);
508 return MCIERR_INTERNAL
;
511 hr
= IVideoWindow_get_Owner(pVideoWindow
, (OAHWND
*)&hWnd
);
512 IVideoWindow_Release(pVideoWindow
);
514 TRACE("No video stream, returning no window error\n");
515 return MCIERR_NO_WINDOW
;
518 if (dwFlags
& MCI_DGV_WHERE_SOURCE
) {
519 if (dwFlags
& MCI_DGV_WHERE_MAX
)
520 FIXME("MCI_DGV_WHERE_SOURCE_MAX not supported yet\n");
522 FIXME("MCI_DGV_WHERE_SOURCE not supported yet\n");
523 return MCIERR_UNRECOGNIZED_COMMAND
;
525 if (dwFlags
& MCI_DGV_WHERE_DESTINATION
) {
526 if (dwFlags
& MCI_DGV_WHERE_MAX
) {
527 GetClientRect(hWnd
, &rc
);
528 TRACE("MCI_DGV_WHERE_DESTINATION_MAX %s\n", wine_dbgstr_rect(&rc
));
530 FIXME("MCI_DGV_WHERE_DESTINATION not supported yet\n");
531 return MCIERR_UNRECOGNIZED_COMMAND
;
534 if (dwFlags
& MCI_DGV_WHERE_FRAME
) {
535 if (dwFlags
& MCI_DGV_WHERE_MAX
)
536 FIXME("MCI_DGV_WHERE_FRAME_MAX not supported yet\n");
538 FIXME("MCI_DGV_WHERE_FRAME not supported yet\n");
539 return MCIERR_UNRECOGNIZED_COMMAND
;
541 if (dwFlags
& MCI_DGV_WHERE_VIDEO
) {
542 if (dwFlags
& MCI_DGV_WHERE_MAX
)
543 FIXME("MCI_DGV_WHERE_VIDEO_MAX not supported yet\n");
545 FIXME("MCI_DGV_WHERE_VIDEO not supported yet\n");
546 return MCIERR_UNRECOGNIZED_COMMAND
;
548 if (dwFlags
& MCI_DGV_WHERE_WINDOW
) {
549 if (dwFlags
& MCI_DGV_WHERE_MAX
) {
550 GetWindowRect(GetDesktopWindow(), &rc
);
551 TRACE("MCI_DGV_WHERE_WINDOW_MAX %s\n", wine_dbgstr_rect(&rc
));
553 GetWindowRect(hWnd
, &rc
);
554 TRACE("MCI_DGV_WHERE_WINDOW %s\n", wine_dbgstr_rect(&rc
));
558 /* In MCI, RECT structure is used differently: rc.right = width & rc.bottom = height
559 * So convert the normal RECT into a MCI RECT before returning */
560 lpParms
->rc
.left
= rc
.left
;
561 lpParms
->rc
.top
= rc
.right
;
562 lpParms
->rc
.right
= rc
.right
- rc
.left
;
563 lpParms
->rc
.bottom
= rc
.bottom
- rc
.top
;
568 /*======================================================================*
569 * MCI QTZ entry points *
570 *======================================================================*/
572 /**************************************************************************
573 * DriverProc (MCIQTZ.@)
575 LRESULT CALLBACK
MCIQTZ_DriverProc(DWORD_PTR dwDevID
, HDRVR hDriv
, UINT wMsg
,
576 LPARAM dwParam1
, LPARAM dwParam2
)
578 TRACE("(%08lX, %p, %08X, %08lX, %08lX)\n",
579 dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
582 case DRV_LOAD
: return 1;
583 case DRV_FREE
: return 1;
584 case DRV_OPEN
: return MCIQTZ_drvOpen((LPCWSTR
)dwParam1
, (LPMCI_OPEN_DRIVER_PARMSW
)dwParam2
);
585 case DRV_CLOSE
: return MCIQTZ_drvClose(dwDevID
);
586 case DRV_ENABLE
: return 1;
587 case DRV_DISABLE
: return 1;
588 case DRV_QUERYCONFIGURE
: return 1;
589 case DRV_CONFIGURE
: return MCIQTZ_drvConfigure(dwDevID
);
590 case DRV_INSTALL
: return DRVCNF_RESTART
;
591 case DRV_REMOVE
: return DRVCNF_RESTART
;
594 /* session instance */
595 if (dwDevID
== 0xFFFFFFFF)
599 case MCI_OPEN_DRIVER
: return MCIQTZ_mciOpen (dwDevID
, dwParam1
, (LPMCI_DGV_OPEN_PARMSW
) dwParam2
);
600 case MCI_CLOSE_DRIVER
: return MCIQTZ_mciClose (dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
) dwParam2
);
601 case MCI_PLAY
: return MCIQTZ_mciPlay (dwDevID
, dwParam1
, (LPMCI_PLAY_PARMS
) dwParam2
);
602 case MCI_SEEK
: return MCIQTZ_mciSeek (dwDevID
, dwParam1
, (LPMCI_SEEK_PARMS
) dwParam2
);
603 case MCI_STOP
: return MCIQTZ_mciStop (dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
) dwParam2
);
604 case MCI_GETDEVCAPS
: return MCIQTZ_mciGetDevCaps(dwDevID
, dwParam1
, (LPMCI_GETDEVCAPS_PARMS
) dwParam2
);
605 case MCI_STATUS
: return MCIQTZ_mciStatus (dwDevID
, dwParam1
, (LPMCI_DGV_STATUS_PARMSW
) dwParam2
);
606 case MCI_WHERE
: return MCIQTZ_mciWhere (dwDevID
, dwParam1
, (LPMCI_DGV_RECT_PARMS
) dwParam2
);
626 /* Digital Video specific */
638 FIXME("Unimplemented command [%08X]\n", wMsg
);
642 WARN("Unsupported command [%08X]\n", wMsg
);
646 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
649 TRACE("Sending msg [%08X] to default driver proc\n", wMsg
);
650 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
653 return MCIERR_UNRECOGNIZED_COMMAND
;