mciqtz32: Add support for MCI_PAUSE.
[wine/multimedia.git] / dlls / mciqtz32 / mciqtz.c
blob75f2c0131cd89673135903f6e293d041faf056d8
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_mciGetOpenDev [internal]
59 static WINE_MCIQTZ* MCIQTZ_mciGetOpenDev(UINT wDevID)
61 WINE_MCIQTZ* wma = (WINE_MCIQTZ*)mciGetDriverData(wDevID);
63 if (!wma) {
64 WARN("Invalid wDevID=%u\n", wDevID);
65 return NULL;
67 return wma;
70 /**************************************************************************
71 * MCIQTZ_drvOpen [internal]
73 static DWORD MCIQTZ_drvOpen(LPCWSTR str, LPMCI_OPEN_DRIVER_PARMSW modp)
75 WINE_MCIQTZ* wma;
76 static const WCHAR mciAviWStr[] = {'M','C','I','A','V','I',0};
78 TRACE("(%s, %p)\n", debugstr_w(str), modp);
80 /* session instance */
81 if (!modp)
82 return 0xFFFFFFFF;
84 wma = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCIQTZ));
85 if (!wma)
86 return 0;
88 modp->wType = MCI_DEVTYPE_DIGITAL_VIDEO;
89 wma->wDevID = modp->wDeviceID;
90 modp->wCustomCommandTable = wma->command_table = mciLoadCommandResource(MCIQTZ_hInstance, mciAviWStr, 0);
91 mciSetDriverData(wma->wDevID, (DWORD_PTR)wma);
93 return modp->wDeviceID;
96 /**************************************************************************
97 * MCIQTZ_drvClose [internal]
99 static DWORD MCIQTZ_drvClose(DWORD dwDevID)
101 WINE_MCIQTZ* wma;
103 TRACE("(%04x)\n", dwDevID);
105 wma = MCIQTZ_mciGetOpenDev(dwDevID);
107 if (wma) {
108 /* finish all outstanding things */
109 MCIQTZ_mciClose(dwDevID, MCI_WAIT, NULL);
111 mciFreeCommandResource(wma->command_table);
112 mciSetDriverData(dwDevID, 0);
113 HeapFree(GetProcessHeap(), 0, wma);
114 return 1;
117 return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
120 /**************************************************************************
121 * MCIQTZ_drvConfigure [internal]
123 static DWORD MCIQTZ_drvConfigure(DWORD dwDevID)
125 WINE_MCIQTZ* wma;
127 TRACE("(%04x)\n", dwDevID);
129 wma = MCIQTZ_mciGetOpenDev(dwDevID);
130 if (!wma)
131 return 0;
133 MCIQTZ_mciStop(dwDevID, MCI_WAIT, NULL);
135 MessageBoxA(0, "Sample QTZ Wine Driver !", "MM-Wine Driver", MB_OK);
137 return 1;
140 /***************************************************************************
141 * MCIQTZ_mciOpen [internal]
143 static DWORD MCIQTZ_mciOpen(UINT wDevID, DWORD dwFlags,
144 LPMCI_DGV_OPEN_PARMSW lpOpenParms)
146 WINE_MCIQTZ* wma;
147 HRESULT hr;
148 IBasicVideo *vidbasic;
149 IVideoWindow *vidwin;
151 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpOpenParms);
153 if (!lpOpenParms)
154 return MCIERR_NULL_PARAMETER_BLOCK;
156 wma = MCIQTZ_mciGetOpenDev(wDevID);
157 if (!wma)
158 return MCIERR_INVALID_DEVICE_ID;
160 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
162 hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
163 wma->uninit = SUCCEEDED(hr);
165 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&wma->pgraph);
166 if (FAILED(hr)) {
167 TRACE("Cannot create filtergraph (hr = %x)\n", hr);
168 goto err;
171 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaControl, (LPVOID*)&wma->pmctrl);
172 if (FAILED(hr)) {
173 TRACE("Cannot get IMediaControl interface (hr = %x)\n", hr);
174 goto err;
177 if (!(dwFlags & MCI_OPEN_ELEMENT) || (dwFlags & MCI_OPEN_ELEMENT_ID)) {
178 TRACE("Wrong dwFlags %x\n", dwFlags);
179 goto err;
182 if (!lpOpenParms->lpstrElementName || !lpOpenParms->lpstrElementName[0]) {
183 TRACE("Invalid filename specified\n");
184 goto err;
187 TRACE("Open file %s\n", debugstr_w(lpOpenParms->lpstrElementName));
189 hr = IGraphBuilder_RenderFile(wma->pgraph, lpOpenParms->lpstrElementName, NULL);
190 if (FAILED(hr)) {
191 TRACE("Cannot render file (hr = %x)\n", hr);
192 goto err;
195 hr = IFilterGraph2_QueryInterface(wma->pgraph, &IID_IVideoWindow, (void**)&vidwin);
196 if (SUCCEEDED(hr))
197 hr = IFilterGraph2_QueryInterface(wma->pgraph, &IID_IBasicVideo, (void**)&vidbasic);
198 if (SUCCEEDED(hr)) {
199 DWORD style;
200 RECT rc = { 0, 0, 0, 0 };
201 IVideoWindow_put_AutoShow(vidwin, OAFALSE);
202 IVideoWindow_put_Visible(vidwin, OAFALSE);
203 style = 0;
204 if (dwFlags & MCI_DGV_OPEN_WS)
205 style |= lpOpenParms->dwStyle;
206 if (dwFlags & MCI_DGV_OPEN_PARENT) {
207 IVideoWindow_put_MessageDrain(vidwin, (OAHWND)lpOpenParms->hWndParent);
208 IVideoWindow_put_WindowState(vidwin, SW_HIDE);
209 IVideoWindow_put_WindowStyle(vidwin, WS_CHILD);
210 IVideoWindow_put_Owner(vidwin, (OAHWND)lpOpenParms->hWndParent);
211 wma->parent = (HWND)lpOpenParms->hWndParent;
213 else if (style)
214 IVideoWindow_put_WindowStyle(vidwin, style);
215 IBasicVideo_GetVideoSize(vidbasic, &rc.right, &rc.bottom);
216 IVideoWindow_SetWindowPosition(vidwin, rc.left, rc.top, rc.right, rc.bottom);
217 IBasicVideo_Release(vidbasic);
219 if (vidwin)
220 IVideoWindow_Release(vidwin);
222 wma->opened = TRUE;
224 return 0;
226 err:
227 if (wma->pgraph)
228 IGraphBuilder_Release(wma->pgraph);
229 wma->pgraph = NULL;
230 if (wma->pmctrl)
231 IMediaControl_Release(wma->pmctrl);
232 wma->pmctrl = NULL;
234 if (wma->uninit)
235 CoUninitialize();
237 return MCIERR_INTERNAL;
240 /***************************************************************************
241 * MCIQTZ_mciClose [internal]
243 static DWORD MCIQTZ_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
245 WINE_MCIQTZ* wma;
247 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
249 wma = MCIQTZ_mciGetOpenDev(wDevID);
250 if (!wma)
251 return MCIERR_INVALID_DEVICE_ID;
253 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
255 if (wma->opened) {
256 IGraphBuilder_Release(wma->pgraph);
257 IMediaControl_Release(wma->pmctrl);
258 if (wma->uninit)
259 CoUninitialize();
260 wma->opened = FALSE;
263 return 0;
266 /***************************************************************************
267 * MCIQTZ_mciPlay [internal]
269 static DWORD MCIQTZ_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
271 WINE_MCIQTZ* wma;
272 HRESULT hr;
274 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
276 if (!lpParms)
277 return MCIERR_NULL_PARAMETER_BLOCK;
279 wma = MCIQTZ_mciGetOpenDev(wDevID);
280 if (!wma)
281 return MCIERR_INVALID_DEVICE_ID;
283 hr = IMediaControl_Run(wma->pmctrl);
284 if (FAILED(hr)) {
285 TRACE("Cannot run filtergraph (hr = %x)\n", hr);
286 return MCIERR_INTERNAL;
289 if (!wma->parent) {
290 IVideoWindow *vidwin;
291 IFilterGraph2_QueryInterface(wma->pgraph, &IID_IVideoWindow, (void**)&vidwin);
292 if (vidwin) {
293 IVideoWindow_put_Visible(vidwin, OATRUE);
294 IVideoWindow_Release(vidwin);
298 return 0;
301 /***************************************************************************
302 * MCIQTZ_mciSeek [internal]
304 static DWORD MCIQTZ_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
306 WINE_MCIQTZ* wma;
307 HRESULT hr;
308 IMediaPosition* pmpos;
309 LONGLONG newpos;
311 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
313 if (!lpParms)
314 return MCIERR_NULL_PARAMETER_BLOCK;
316 wma = MCIQTZ_mciGetOpenDev(wDevID);
317 if (!wma)
318 return MCIERR_INVALID_DEVICE_ID;
320 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
322 if (dwFlags & MCI_SEEK_TO_START) {
323 newpos = 0;
324 } else if (dwFlags & MCI_SEEK_TO_END) {
325 FIXME("MCI_SEEK_TO_END not implemented yet\n");
326 return MCIERR_INTERNAL;
327 } else if (dwFlags & MCI_TO) {
328 FIXME("MCI_TO not implemented yet\n");
329 return MCIERR_INTERNAL;
330 } else {
331 WARN("dwFlag doesn't tell where to seek to...\n");
332 return MCIERR_MISSING_PARAMETER;
335 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaPosition, (LPVOID*)&pmpos);
336 if (FAILED(hr)) {
337 FIXME("Cannot get IMediaPostion interface (hr = %x)\n", hr);
338 return MCIERR_INTERNAL;
341 hr = IMediaPosition_put_CurrentPosition(pmpos, newpos);
342 if (FAILED(hr)) {
343 FIXME("Cannot set position (hr = %x)\n", hr);
344 IMediaPosition_Release(pmpos);
345 return MCIERR_INTERNAL;
348 IMediaPosition_Release(pmpos);
350 if (dwFlags & MCI_NOTIFY)
351 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)), wDevID, MCI_NOTIFY_SUCCESSFUL);
353 return 0;
356 /***************************************************************************
357 * MCIQTZ_mciStop [internal]
359 static DWORD MCIQTZ_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
361 WINE_MCIQTZ* wma;
362 HRESULT hr;
364 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
366 wma = MCIQTZ_mciGetOpenDev(wDevID);
367 if (!wma)
368 return MCIERR_INVALID_DEVICE_ID;
370 if (!wma->opened)
371 return 0;
373 hr = IMediaControl_Stop(wma->pmctrl);
374 if (FAILED(hr)) {
375 TRACE("Cannot stop filtergraph (hr = %x)\n", hr);
376 return MCIERR_INTERNAL;
379 if (!wma->parent) {
380 IVideoWindow *vidwin;
381 IFilterGraph2_QueryInterface(wma->pgraph, &IID_IVideoWindow, (void**)&vidwin);
382 if (vidwin) {
383 IVideoWindow_put_Visible(vidwin, OAFALSE);
384 IVideoWindow_Release(vidwin);
388 return 0;
391 /***************************************************************************
392 * MCIQTZ_mciPause [internal]
394 static DWORD MCIQTZ_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
396 WINE_MCIQTZ* wma;
397 HRESULT hr;
399 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
401 wma = MCIQTZ_mciGetOpenDev(wDevID);
402 if (!wma)
403 return MCIERR_INVALID_DEVICE_ID;
405 hr = IMediaControl_Pause(wma->pmctrl);
406 if (FAILED(hr)) {
407 TRACE("Cannot pause filtergraph (hr = %x)\n", hr);
408 return MCIERR_INTERNAL;
411 return 0;
414 /***************************************************************************
415 * MCIQTZ_mciGetDevCaps [internal]
417 static DWORD MCIQTZ_mciGetDevCaps(UINT wDevID, DWORD dwFlags, LPMCI_GETDEVCAPS_PARMS lpParms)
419 WINE_MCIQTZ* wma;
421 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
423 if (!lpParms)
424 return MCIERR_NULL_PARAMETER_BLOCK;
426 wma = MCIQTZ_mciGetOpenDev(wDevID);
427 if (!wma)
428 return MCIERR_INVALID_DEVICE_ID;
430 if (!(dwFlags & MCI_GETDEVCAPS_ITEM))
431 return MCIERR_MISSING_PARAMETER;
433 switch (lpParms->dwItem) {
434 case MCI_GETDEVCAPS_CAN_RECORD:
435 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
436 TRACE("MCI_GETDEVCAPS_CAN_RECORD = %08x\n", lpParms->dwReturn);
437 break;
438 case MCI_GETDEVCAPS_HAS_AUDIO:
439 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
440 TRACE("MCI_GETDEVCAPS_HAS_AUDIO = %08x\n", lpParms->dwReturn);
441 break;
442 case MCI_GETDEVCAPS_HAS_VIDEO:
443 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
444 TRACE("MCI_GETDEVCAPS_HAS_VIDEO = %08x\n", lpParms->dwReturn);
445 break;
446 case MCI_GETDEVCAPS_DEVICE_TYPE:
447 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_DEVTYPE_DIGITAL_VIDEO, MCI_DEVTYPE_DIGITAL_VIDEO);
448 TRACE("MCI_GETDEVCAPS_DEVICE_TYPE = %08x\n", lpParms->dwReturn);
449 break;
450 case MCI_GETDEVCAPS_USES_FILES:
451 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
452 TRACE("MCI_GETDEVCAPS_USES_FILES = %08x\n", lpParms->dwReturn);
453 break;
454 case MCI_GETDEVCAPS_COMPOUND_DEVICE:
455 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
456 TRACE("MCI_GETDEVCAPS_COMPOUND_DEVICE = %08x\n", lpParms->dwReturn);
457 break;
458 case MCI_GETDEVCAPS_CAN_EJECT:
459 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
460 TRACE("MCI_GETDEVCAPS_EJECT = %08x\n", lpParms->dwReturn);
461 break;
462 case MCI_GETDEVCAPS_CAN_PLAY:
463 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
464 TRACE("MCI_GETDEVCAPS_CAN_PLAY = %08x\n", lpParms->dwReturn);
465 break;
466 case MCI_GETDEVCAPS_CAN_SAVE:
467 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
468 TRACE("MCI_GETDEVCAPS_CAN_SAVE = %08x\n", lpParms->dwReturn);
469 break;
470 case MCI_DGV_GETDEVCAPS_CAN_REVERSE:
471 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
472 TRACE("MCI_DGV_GETDEVCAPS_CAN_REVERSE = %08x\n", lpParms->dwReturn);
473 break;
474 case MCI_DGV_GETDEVCAPS_CAN_STRETCH:
475 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE); /* FIXME */
476 TRACE("MCI_DGV_GETDEVCAPS_CAN_STRETCH = %08x\n", lpParms->dwReturn);
477 break;
478 case MCI_DGV_GETDEVCAPS_CAN_LOCK:
479 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
480 TRACE("MCI_DGV_GETDEVCAPS_CAN_LOCK = %08x\n", lpParms->dwReturn);
481 break;
482 case MCI_DGV_GETDEVCAPS_CAN_FREEZE:
483 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
484 TRACE("MCI_DGV_GETDEVCAPS_CAN_FREEZE = %08x\n", lpParms->dwReturn);
485 break;
486 case MCI_DGV_GETDEVCAPS_CAN_STR_IN:
487 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
488 TRACE("MCI_DGV_GETDEVCAPS_CAN_STRETCH_INPUT = %08x\n", lpParms->dwReturn);
489 break;
490 case MCI_DGV_GETDEVCAPS_HAS_STILL:
491 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
492 TRACE("MCI_DGV_GETDEVCAPS_HAS_STILL = %08x\n", lpParms->dwReturn);
493 break;
494 case MCI_DGV_GETDEVCAPS_CAN_TEST:
495 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE); /* FIXME */
496 TRACE("MCI_DGV_GETDEVCAPS_CAN_TEST = %08x\n", lpParms->dwReturn);
497 break;
498 case MCI_DGV_GETDEVCAPS_MAX_WINDOWS:
499 lpParms->dwReturn = 1;
500 TRACE("MCI_DGV_GETDEVCAPS_MAX_WINDOWS = %u\n", lpParms->dwReturn);
501 return 0;
502 default:
503 WARN("Unknown capability %08x\n", lpParms->dwItem);
504 /* Fall through */
505 case MCI_DGV_GETDEVCAPS_MAXIMUM_RATE: /* unknown to w2k */
506 case MCI_DGV_GETDEVCAPS_MINIMUM_RATE: /* unknown to w2k */
507 return MCIERR_UNSUPPORTED_FUNCTION;
510 return MCI_RESOURCE_RETURNED;
513 /***************************************************************************
514 * MCIQTZ_mciSet [internal]
516 static DWORD MCIQTZ_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SET_PARMS lpParms)
518 WINE_MCIQTZ* wma;
520 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
522 if (!lpParms)
523 return MCIERR_NULL_PARAMETER_BLOCK;
525 wma = MCIQTZ_mciGetOpenDev(wDevID);
526 if (!wma)
527 return MCIERR_INVALID_DEVICE_ID;
529 if (dwFlags & MCI_SET_TIME_FORMAT) {
530 switch (lpParms->dwTimeFormat) {
531 case MCI_FORMAT_MILLISECONDS:
532 TRACE("MCI_SET_TIME_FORMAT = MCI_FORMAT_MILLISECONDS\n");
533 wma->time_format = MCI_FORMAT_MILLISECONDS;
534 break;
535 case MCI_FORMAT_FRAMES:
536 TRACE("MCI_SET_TIME_FORMAT = MCI_FORMAT_FRAMES\n");
537 wma->time_format = MCI_FORMAT_FRAMES;
538 break;
539 default:
540 WARN("Bad time format %u\n", lpParms->dwTimeFormat);
541 return MCIERR_BAD_TIME_FORMAT;
545 if (dwFlags & MCI_SET_DOOR_OPEN)
546 FIXME("MCI_SET_DOOR_OPEN not implemented yet\n");
547 if (dwFlags & MCI_SET_DOOR_CLOSED)
548 FIXME("MCI_SET_DOOR_CLOSED not implemented yet\n");
549 if (dwFlags & MCI_SET_AUDIO)
550 FIXME("MCI_SET_AUDIO not implemented yet\n");
551 if (dwFlags & MCI_SET_VIDEO)
552 FIXME("MCI_SET_VIDEO not implemented yet\n");
553 if (dwFlags & MCI_SET_ON)
554 FIXME("MCI_SET_ON not implemented yet\n");
555 if (dwFlags & MCI_SET_OFF)
556 FIXME("MCI_SET_OFF not implemented yet\n");
557 if (dwFlags & MCI_SET_AUDIO_LEFT)
558 FIXME("MCI_SET_AUDIO_LEFT not implemented yet\n");
559 if (dwFlags & MCI_SET_AUDIO_RIGHT)
560 FIXME("MCI_SET_AUDIO_RIGHT not implemented yet\n");
562 if (dwFlags & ~0x7f03 /* All MCI_SET flags mask */)
563 ERR("Unknown flags %08x\n", dwFlags & ~0x7f03);
565 return 0;
568 /***************************************************************************
569 * MCIQTZ_mciStatus [internal]
571 static DWORD MCIQTZ_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_DGV_STATUS_PARMSW lpParms)
573 WINE_MCIQTZ* wma;
574 HRESULT hr;
576 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
578 if (!lpParms)
579 return MCIERR_NULL_PARAMETER_BLOCK;
581 wma = MCIQTZ_mciGetOpenDev(wDevID);
582 if (!wma)
583 return MCIERR_INVALID_DEVICE_ID;
585 if (!(dwFlags & MCI_STATUS_ITEM)) {
586 WARN("No status item specified\n");
587 return MCIERR_UNRECOGNIZED_COMMAND;
590 switch (lpParms->dwItem) {
591 case MCI_STATUS_LENGTH: {
592 IMediaSeeking *seek;
593 LONGLONG duration = -1;
594 GUID format;
595 switch (wma->time_format) {
596 case MCI_FORMAT_MILLISECONDS: format = TIME_FORMAT_MEDIA_TIME; break;
597 case MCI_FORMAT_FRAMES: format = TIME_FORMAT_FRAME; break;
598 default: ERR("Unhandled format %x\n", wma->time_format); break;
600 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaSeeking, (void**)&seek);
601 if (FAILED(hr)) {
602 FIXME("Cannot get IMediaPostion interface (hr = %x)\n", hr);
603 return MCIERR_INTERNAL;
605 hr = IMediaSeeking_SetTimeFormat(seek, &format);
606 if (FAILED(hr)) {
607 IMediaSeeking_Release(seek);
608 FIXME("Cannot set time format (hr = %x)\n", hr);
609 lpParms->dwReturn = 0;
610 break;
612 hr = IMediaSeeking_GetDuration(seek, &duration);
613 IMediaSeeking_Release(seek);
614 if (FAILED(hr) || duration < 0) {
615 FIXME("Cannot read duration (hr = %x)\n", hr);
616 lpParms->dwReturn = 0;
617 } else if (wma->time_format != MCI_FORMAT_MILLISECONDS)
618 lpParms->dwReturn = duration;
619 else
620 lpParms->dwReturn = duration / 10000;
621 break;
623 case MCI_STATUS_POSITION: {
624 IMediaPosition* pmpos;
625 REFTIME curpos;
627 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaPosition, (LPVOID*)&pmpos);
628 if (FAILED(hr)) {
629 FIXME("Cannot get IMediaPostion interface (hr = %x)\n", hr);
630 return MCIERR_INTERNAL;
633 hr = IMediaPosition_get_CurrentPosition(pmpos, &curpos);
634 if (FAILED(hr)) {
635 FIXME("Cannot get position (hr = %x)\n", hr);
636 IMediaPosition_Release(pmpos);
637 return MCIERR_INTERNAL;
640 IMediaPosition_Release(pmpos);
641 lpParms->dwReturn = curpos / 10000;
643 break;
645 case MCI_STATUS_NUMBER_OF_TRACKS:
646 FIXME("MCI_STATUS_NUMBER_OF_TRACKS not implemented yet\n");
647 return MCIERR_UNRECOGNIZED_COMMAND;
648 case MCI_STATUS_MODE:
649 FIXME("MCI_STATUS_MODE not implemented yet\n");
650 return MCIERR_UNRECOGNIZED_COMMAND;
651 case MCI_STATUS_MEDIA_PRESENT:
652 FIXME("MCI_STATUS_MEDIA_PRESENT not implemented yet\n");
653 return MCIERR_UNRECOGNIZED_COMMAND;
654 case MCI_STATUS_TIME_FORMAT:
655 lpParms->dwReturn = wma->time_format;
656 break;
657 case MCI_STATUS_READY:
658 FIXME("MCI_STATUS_READY not implemented yet\n");
659 return MCIERR_UNRECOGNIZED_COMMAND;
660 case MCI_STATUS_CURRENT_TRACK:
661 FIXME("MCI_STATUS_CURRENT_TRACK not implemented yet\n");
662 return MCIERR_UNRECOGNIZED_COMMAND;
663 default:
664 FIXME("Unknown command %08X\n", lpParms->dwItem);
665 return MCIERR_UNRECOGNIZED_COMMAND;
668 if (dwFlags & MCI_NOTIFY)
669 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)), wDevID, MCI_NOTIFY_SUCCESSFUL);
671 return 0;
674 /***************************************************************************
675 * MCIQTZ_mciWhere [internal]
677 static DWORD MCIQTZ_mciWhere(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
679 WINE_MCIQTZ* wma;
680 IVideoWindow* pVideoWindow;
681 IBasicVideo *pBasicVideo;
682 HRESULT hr;
683 HWND hWnd;
684 RECT rc;
685 DWORD ret = MCIERR_UNRECOGNIZED_COMMAND;
687 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
689 if (!lpParms)
690 return MCIERR_NULL_PARAMETER_BLOCK;
692 wma = MCIQTZ_mciGetOpenDev(wDevID);
693 if (!wma)
694 return MCIERR_INVALID_DEVICE_ID;
696 /* Find if there is a video stream and get the display window */
697 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
698 if (FAILED(hr)) {
699 ERR("Cannot get IVideoWindow interface (hr = %x)\n", hr);
700 return MCIERR_INTERNAL;
703 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
704 if (FAILED(hr)) {
705 ERR("Cannot get IBasicVideo interface (hr = %x)\n", hr);
706 IUnknown_Release(pVideoWindow);
707 return MCIERR_INTERNAL;
710 hr = IVideoWindow_get_Owner(pVideoWindow, (OAHWND*)&hWnd);
711 if (FAILED(hr)) {
712 TRACE("No video stream, returning no window error\n");
713 IUnknown_Release(pVideoWindow);
714 return MCIERR_NO_WINDOW;
717 if (dwFlags & MCI_DGV_WHERE_SOURCE) {
718 if (dwFlags & MCI_DGV_WHERE_MAX)
719 FIXME("MCI_DGV_WHERE_SOURCE_MAX stub %s\n", wine_dbgstr_rect(&rc));
720 IBasicVideo_get_SourceLeft(pBasicVideo, &rc.left);
721 IBasicVideo_get_SourceTop(pBasicVideo, &rc.top);
722 IBasicVideo_get_SourceWidth(pBasicVideo, &rc.right);
723 IBasicVideo_get_SourceHeight(pBasicVideo, &rc.bottom);
724 /* Undo conversion done below */
725 rc.right += rc.left;
726 rc.bottom += rc.top;
727 TRACE("MCI_DGV_WHERE_SOURCE %s\n", wine_dbgstr_rect(&rc));
729 if (dwFlags & MCI_DGV_WHERE_DESTINATION) {
730 if (dwFlags & MCI_DGV_WHERE_MAX) {
731 GetClientRect(hWnd, &rc);
732 TRACE("MCI_DGV_WHERE_DESTINATION_MAX %s\n", wine_dbgstr_rect(&rc));
733 } else {
734 FIXME("MCI_DGV_WHERE_DESTINATION not supported yet\n");
735 goto out;
738 if (dwFlags & MCI_DGV_WHERE_FRAME) {
739 if (dwFlags & MCI_DGV_WHERE_MAX)
740 FIXME("MCI_DGV_WHERE_FRAME_MAX not supported yet\n");
741 else
742 FIXME("MCI_DGV_WHERE_FRAME not supported yet\n");
743 goto out;
745 if (dwFlags & MCI_DGV_WHERE_VIDEO) {
746 if (dwFlags & MCI_DGV_WHERE_MAX)
747 FIXME("MCI_DGV_WHERE_VIDEO_MAX not supported yet\n");
748 else
749 FIXME("MCI_DGV_WHERE_VIDEO not supported yet\n");
750 goto out;
752 if (dwFlags & MCI_DGV_WHERE_WINDOW) {
753 if (dwFlags & MCI_DGV_WHERE_MAX) {
754 GetWindowRect(GetDesktopWindow(), &rc);
755 TRACE("MCI_DGV_WHERE_WINDOW_MAX %s\n", wine_dbgstr_rect(&rc));
756 } else {
757 GetWindowRect(hWnd, &rc);
758 TRACE("MCI_DGV_WHERE_WINDOW %s\n", wine_dbgstr_rect(&rc));
761 ret = 0;
763 out:
764 /* In MCI, RECT structure is used differently: rc.right = width & rc.bottom = height
765 * So convert the normal RECT into a MCI RECT before returning */
766 IVideoWindow_Release(pVideoWindow);
767 IBasicVideo_Release(pBasicVideo);
768 lpParms->rc.left = rc.left;
769 lpParms->rc.top = rc.top;
770 lpParms->rc.right = rc.right - rc.left;
771 lpParms->rc.bottom = rc.bottom - rc.top;
773 return ret;
776 /******************************************************************************
777 * MCIAVI_mciUpdate [internal]
779 static DWORD MCIQTZ_mciUpdate(UINT wDevID, DWORD dwFlags, LPMCI_DGV_UPDATE_PARMS lpParms)
781 WINE_MCIQTZ *wma;
782 DWORD res = 0;
784 TRACE("%04x, %08x, %p\n", wDevID, dwFlags, lpParms);
786 if (!lpParms)
787 return MCIERR_NULL_PARAMETER_BLOCK;
789 wma = MCIQTZ_mciGetOpenDev(wDevID);
790 if (!wma)
791 return MCIERR_INVALID_DEVICE_ID;
793 if (dwFlags & MCI_DGV_UPDATE_HDC) {
794 IBasicVideo *vidbasic;
795 IVideoWindow *vidwin;
796 res = MCIERR_INTERNAL;
797 IFilterGraph2_QueryInterface(wma->pgraph, &IID_IVideoWindow, (void**)&vidwin);
798 IFilterGraph2_QueryInterface(wma->pgraph, &IID_IBasicVideo, (void**)&vidbasic);
799 if (vidbasic && vidwin) {
800 LONG state, size;
801 BYTE *data;
802 BITMAPINFO *info;
803 HRESULT hr;
804 RECT src, dest;
806 /* If in stopped state, nothing has been drawn to screen
807 * moving to pause, which is needed for the old dib renderer, will result
808 * in a single frame drawn, so hide the window here */
809 IVideoWindow_put_Visible(vidwin, OAFALSE);
810 /* FIXME: Should we check the original state and restore it? */
811 IMediaControl_Pause(wma->pmctrl);
812 IMediaControl_GetState(wma->pmctrl, -1, &state);
813 if (FAILED(hr = IBasicVideo_GetCurrentImage(vidbasic, &size, NULL))) {
814 WARN("Could not get image size (hr = %x)\n", hr);
815 goto out;
817 data = HeapAlloc(GetProcessHeap(), 0, size);
818 info = (BITMAPINFO*)data;
819 IBasicVideo_GetCurrentImage(vidbasic, &size, (LONG*)data);
820 data += info->bmiHeader.biSize;
822 IBasicVideo_GetSourcePosition(vidbasic, &src.left, &src.top, &src.right, &src.bottom);
823 IBasicVideo_GetDestinationPosition(vidbasic, &dest.left, &dest.top, &dest.right, &dest.bottom);
824 StretchDIBits(lpParms->hDC,
825 dest.left, dest.top, dest.right + dest.left, dest.bottom + dest.top,
826 src.left, src.top, src.right + src.left, src.bottom + src.top,
827 data, info, DIB_RGB_COLORS, SRCCOPY);
828 HeapFree(GetProcessHeap(), 0, data);
830 res = 0;
831 out:
832 if (vidbasic)
833 IBasicVideo_Release(vidbasic);
834 if (vidwin) {
835 if (wma->parent)
836 IVideoWindow_put_Visible(vidwin, OATRUE);
837 IVideoWindow_Release(vidwin);
840 else if (dwFlags)
841 FIXME("Unhandled flags %x\n", dwFlags);
842 return res;
845 /***************************************************************************
846 * MCIQTZ_mciSetAudio [internal]
848 static DWORD MCIQTZ_mciSetAudio(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SETAUDIO_PARMSW lpParms)
850 WINE_MCIQTZ *wma;
852 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
854 if (!lpParms)
855 return MCIERR_NULL_PARAMETER_BLOCK;
857 wma = MCIQTZ_mciGetOpenDev(wDevID);
858 if (!wma)
859 return MCIERR_INVALID_DEVICE_ID;
861 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
863 return 0;
866 /*======================================================================*
867 * MCI QTZ entry points *
868 *======================================================================*/
870 /**************************************************************************
871 * DriverProc (MCIQTZ.@)
873 LRESULT CALLBACK MCIQTZ_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
874 LPARAM dwParam1, LPARAM dwParam2)
876 TRACE("(%08lX, %p, %08X, %08lX, %08lX)\n",
877 dwDevID, hDriv, wMsg, dwParam1, dwParam2);
879 switch (wMsg) {
880 case DRV_LOAD: return 1;
881 case DRV_FREE: return 1;
882 case DRV_OPEN: return MCIQTZ_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
883 case DRV_CLOSE: return MCIQTZ_drvClose(dwDevID);
884 case DRV_ENABLE: return 1;
885 case DRV_DISABLE: return 1;
886 case DRV_QUERYCONFIGURE: return 1;
887 case DRV_CONFIGURE: return MCIQTZ_drvConfigure(dwDevID);
888 case DRV_INSTALL: return DRVCNF_RESTART;
889 case DRV_REMOVE: return DRVCNF_RESTART;
892 /* session instance */
893 if (dwDevID == 0xFFFFFFFF)
894 return 1;
896 switch (wMsg) {
897 case MCI_OPEN_DRIVER: return MCIQTZ_mciOpen (dwDevID, dwParam1, (LPMCI_DGV_OPEN_PARMSW) dwParam2);
898 case MCI_CLOSE_DRIVER: return MCIQTZ_mciClose (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
899 case MCI_PLAY: return MCIQTZ_mciPlay (dwDevID, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
900 case MCI_SEEK: return MCIQTZ_mciSeek (dwDevID, dwParam1, (LPMCI_SEEK_PARMS) dwParam2);
901 case MCI_STOP: return MCIQTZ_mciStop (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
902 case MCI_PAUSE: return MCIQTZ_mciPause (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
903 case MCI_GETDEVCAPS: return MCIQTZ_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS) dwParam2);
904 case MCI_SET: return MCIQTZ_mciSet (dwDevID, dwParam1, (LPMCI_DGV_SET_PARMS) dwParam2);
905 case MCI_STATUS: return MCIQTZ_mciStatus (dwDevID, dwParam1, (LPMCI_DGV_STATUS_PARMSW) dwParam2);
906 case MCI_WHERE: return MCIQTZ_mciWhere (dwDevID, dwParam1, (LPMCI_DGV_RECT_PARMS) dwParam2);
907 /* Digital Video specific */
908 case MCI_SETAUDIO: return MCIQTZ_mciSetAudio (dwDevID, dwParam1, (LPMCI_DGV_SETAUDIO_PARMSW) dwParam2);
909 case MCI_UPDATE:
910 return MCIQTZ_mciUpdate(dwDevID, dwParam1, (LPMCI_DGV_UPDATE_PARMS)dwParam2);
911 case MCI_RECORD:
912 case MCI_RESUME:
913 case MCI_INFO:
914 case MCI_PUT:
915 case MCI_WINDOW:
916 case MCI_LOAD:
917 case MCI_SAVE:
918 case MCI_FREEZE:
919 case MCI_REALIZE:
920 case MCI_UNFREEZE:
921 case MCI_STEP:
922 case MCI_COPY:
923 case MCI_CUT:
924 case MCI_DELETE:
925 case MCI_PASTE:
926 case MCI_CUE:
927 /* Digital Video specific */
928 case MCI_CAPTURE:
929 case MCI_MONITOR:
930 case MCI_RESERVE:
931 case MCI_SIGNAL:
932 case MCI_SETVIDEO:
933 case MCI_QUALITY:
934 case MCI_LIST:
935 case MCI_UNDO:
936 case MCI_CONFIGURE:
937 case MCI_RESTORE:
938 FIXME("Unimplemented command [%08X]\n", wMsg);
939 break;
940 case MCI_SPIN:
941 case MCI_ESCAPE:
942 WARN("Unsupported command [%08X]\n", wMsg);
943 break;
944 case MCI_OPEN:
945 case MCI_CLOSE:
946 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
947 break;
948 default:
949 TRACE("Sending msg [%08X] to default driver proc\n", wMsg);
950 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
953 return MCIERR_UNRECOGNIZED_COMMAND;