mciqtz32: Add support for mciWindow.
[wine/multimedia.git] / dlls / mciqtz32 / mciqtz.c
blob50faf13b0c0edd0c095a3f8ac890f0c975c277bd
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 DWORD style = 0;
149 RECT rc = { 0, 0, 0, 0 };
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 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaSeeking, (void**)&wma->seek);
178 if (FAILED(hr)) {
179 TRACE("Cannot get IMediaSeeking interface (hr = %x)\n", hr);
180 goto err;
183 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IVideoWindow, (void**)&wma->vidwin);
184 if (FAILED(hr)) {
185 TRACE("Cannot get IVideoWindow interface (hr = %x)\n", hr);
186 goto err;
189 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IBasicVideo, (void**)&wma->vidbasic);
190 if (FAILED(hr)) {
191 TRACE("Cannot get IBasicVideo interface (hr = %x)\n", hr);
192 goto err;
195 if (!(dwFlags & MCI_OPEN_ELEMENT) || (dwFlags & MCI_OPEN_ELEMENT_ID)) {
196 TRACE("Wrong dwFlags %x\n", dwFlags);
197 goto err;
200 if (!lpOpenParms->lpstrElementName || !lpOpenParms->lpstrElementName[0]) {
201 TRACE("Invalid filename specified\n");
202 goto err;
205 TRACE("Open file %s\n", debugstr_w(lpOpenParms->lpstrElementName));
207 hr = IGraphBuilder_RenderFile(wma->pgraph, lpOpenParms->lpstrElementName, NULL);
208 if (FAILED(hr)) {
209 TRACE("Cannot render file (hr = %x)\n", hr);
210 goto err;
213 IVideoWindow_put_AutoShow(wma->vidwin, OAFALSE);
214 IVideoWindow_put_Visible(wma->vidwin, OAFALSE);
215 if (dwFlags & MCI_DGV_OPEN_WS)
216 style = lpOpenParms->dwStyle;
217 if (dwFlags & MCI_DGV_OPEN_PARENT) {
218 IVideoWindow_put_MessageDrain(wma->vidwin, (OAHWND)lpOpenParms->hWndParent);
219 IVideoWindow_put_WindowState(wma->vidwin, SW_HIDE);
220 IVideoWindow_put_WindowStyle(wma->vidwin, style|WS_CHILD);
221 IVideoWindow_put_Owner(wma->vidwin, (OAHWND)lpOpenParms->hWndParent);
222 GetClientRect(lpOpenParms->hWndParent, &rc);
223 IVideoWindow_SetWindowPosition(wma->vidwin, rc.left, rc.top, rc.right - rc.top, rc.bottom - rc.top);
224 wma->parent = (HWND)lpOpenParms->hWndParent;
226 else if (style)
227 IVideoWindow_put_WindowStyle(wma->vidwin, style);
228 wma->opened = TRUE;
230 if (dwFlags & MCI_NOTIFY)
231 mciDriverNotify(HWND_32(LOWORD(lpOpenParms->dwCallback)), wDevID, MCI_NOTIFY_SUCCESSFUL);
233 return 0;
235 err:
236 if (wma->vidbasic)
237 IUnknown_Release(wma->vidbasic);
238 wma->vidbasic = NULL;
239 if (wma->seek)
240 IUnknown_Release(wma->seek);
241 wma->seek = NULL;
242 if (wma->vidwin)
243 IUnknown_Release(wma->vidwin);
244 wma->vidwin = NULL;
245 if (wma->pgraph)
246 IGraphBuilder_Release(wma->pgraph);
247 wma->pgraph = NULL;
248 if (wma->pmctrl)
249 IMediaControl_Release(wma->pmctrl);
250 wma->pmctrl = NULL;
252 if (wma->uninit)
253 CoUninitialize();
255 return MCIERR_INTERNAL;
258 /***************************************************************************
259 * MCIQTZ_mciClose [internal]
261 static DWORD MCIQTZ_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
263 WINE_MCIQTZ* wma;
265 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
267 wma = MCIQTZ_mciGetOpenDev(wDevID);
268 if (!wma)
269 return MCIERR_INVALID_DEVICE_ID;
271 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
273 if (wma->opened) {
274 IUnknown_Release(wma->vidwin);
275 IUnknown_Release(wma->vidbasic);
276 IUnknown_Release(wma->seek);
277 IGraphBuilder_Release(wma->pgraph);
278 IMediaControl_Release(wma->pmctrl);
279 if (wma->uninit)
280 CoUninitialize();
281 wma->opened = FALSE;
284 return 0;
287 /***************************************************************************
288 * MCIQTZ_mciPlay [internal]
290 static DWORD MCIQTZ_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
292 WINE_MCIQTZ* wma;
293 HRESULT hr;
295 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
297 if (!lpParms)
298 return MCIERR_NULL_PARAMETER_BLOCK;
300 wma = MCIQTZ_mciGetOpenDev(wDevID);
301 if (!wma)
302 return MCIERR_INVALID_DEVICE_ID;
304 hr = IMediaControl_Run(wma->pmctrl);
305 if (FAILED(hr)) {
306 TRACE("Cannot run filtergraph (hr = %x)\n", hr);
307 return MCIERR_INTERNAL;
310 if (!wma->parent)
311 IVideoWindow_put_Visible(wma->vidwin, OATRUE);
313 return 0;
316 /***************************************************************************
317 * MCIQTZ_mciSeek [internal]
319 static DWORD MCIQTZ_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
321 WINE_MCIQTZ* wma;
322 HRESULT hr;
323 LONGLONG newpos;
325 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
327 if (!lpParms)
328 return MCIERR_NULL_PARAMETER_BLOCK;
330 wma = MCIQTZ_mciGetOpenDev(wDevID);
331 if (!wma)
332 return MCIERR_INVALID_DEVICE_ID;
334 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
336 if (dwFlags & MCI_SEEK_TO_START) {
337 newpos = 0;
338 } else if (dwFlags & MCI_SEEK_TO_END) {
339 FIXME("MCI_SEEK_TO_END not implemented yet\n");
340 return MCIERR_INTERNAL;
341 } else if (dwFlags & MCI_TO) {
342 FIXME("MCI_TO not implemented yet\n");
343 return MCIERR_INTERNAL;
344 } else {
345 WARN("dwFlag doesn't tell where to seek to...\n");
346 return MCIERR_MISSING_PARAMETER;
349 hr = IMediaSeeking_SetPositions(wma->seek, &newpos, AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
350 if (FAILED(hr)) {
351 FIXME("Cannot set position (hr = %x)\n", hr);
352 return MCIERR_INTERNAL;
355 if (dwFlags & MCI_NOTIFY)
356 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)), wDevID, MCI_NOTIFY_SUCCESSFUL);
358 return 0;
361 /***************************************************************************
362 * MCIQTZ_mciStop [internal]
364 static DWORD MCIQTZ_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
366 WINE_MCIQTZ* wma;
367 HRESULT hr;
369 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
371 wma = MCIQTZ_mciGetOpenDev(wDevID);
372 if (!wma)
373 return MCIERR_INVALID_DEVICE_ID;
375 if (!wma->opened)
376 return 0;
378 hr = IMediaControl_Stop(wma->pmctrl);
379 if (FAILED(hr)) {
380 TRACE("Cannot stop filtergraph (hr = %x)\n", hr);
381 return MCIERR_INTERNAL;
384 if (!wma->parent)
385 IVideoWindow_put_Visible(wma->vidwin, OAFALSE);
387 return 0;
390 /***************************************************************************
391 * MCIQTZ_mciPause [internal]
393 static DWORD MCIQTZ_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
395 WINE_MCIQTZ* wma;
396 HRESULT hr;
398 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
400 wma = MCIQTZ_mciGetOpenDev(wDevID);
401 if (!wma)
402 return MCIERR_INVALID_DEVICE_ID;
404 hr = IMediaControl_Pause(wma->pmctrl);
405 if (FAILED(hr)) {
406 TRACE("Cannot pause filtergraph (hr = %x)\n", hr);
407 return MCIERR_INTERNAL;
410 return 0;
413 /***************************************************************************
414 * MCIQTZ_mciGetDevCaps [internal]
416 static DWORD MCIQTZ_mciGetDevCaps(UINT wDevID, DWORD dwFlags, LPMCI_GETDEVCAPS_PARMS lpParms)
418 WINE_MCIQTZ* wma;
420 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
422 if (!lpParms)
423 return MCIERR_NULL_PARAMETER_BLOCK;
425 wma = MCIQTZ_mciGetOpenDev(wDevID);
426 if (!wma)
427 return MCIERR_INVALID_DEVICE_ID;
429 if (!(dwFlags & MCI_GETDEVCAPS_ITEM))
430 return MCIERR_MISSING_PARAMETER;
432 switch (lpParms->dwItem) {
433 case MCI_GETDEVCAPS_CAN_RECORD:
434 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
435 TRACE("MCI_GETDEVCAPS_CAN_RECORD = %08x\n", lpParms->dwReturn);
436 break;
437 case MCI_GETDEVCAPS_HAS_AUDIO:
438 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
439 TRACE("MCI_GETDEVCAPS_HAS_AUDIO = %08x\n", lpParms->dwReturn);
440 break;
441 case MCI_GETDEVCAPS_HAS_VIDEO:
442 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
443 TRACE("MCI_GETDEVCAPS_HAS_VIDEO = %08x\n", lpParms->dwReturn);
444 break;
445 case MCI_GETDEVCAPS_DEVICE_TYPE:
446 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_DEVTYPE_DIGITAL_VIDEO, MCI_DEVTYPE_DIGITAL_VIDEO);
447 TRACE("MCI_GETDEVCAPS_DEVICE_TYPE = %08x\n", lpParms->dwReturn);
448 break;
449 case MCI_GETDEVCAPS_USES_FILES:
450 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
451 TRACE("MCI_GETDEVCAPS_USES_FILES = %08x\n", lpParms->dwReturn);
452 break;
453 case MCI_GETDEVCAPS_COMPOUND_DEVICE:
454 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
455 TRACE("MCI_GETDEVCAPS_COMPOUND_DEVICE = %08x\n", lpParms->dwReturn);
456 break;
457 case MCI_GETDEVCAPS_CAN_EJECT:
458 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
459 TRACE("MCI_GETDEVCAPS_EJECT = %08x\n", lpParms->dwReturn);
460 break;
461 case MCI_GETDEVCAPS_CAN_PLAY:
462 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
463 TRACE("MCI_GETDEVCAPS_CAN_PLAY = %08x\n", lpParms->dwReturn);
464 break;
465 case MCI_GETDEVCAPS_CAN_SAVE:
466 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
467 TRACE("MCI_GETDEVCAPS_CAN_SAVE = %08x\n", lpParms->dwReturn);
468 break;
469 case MCI_DGV_GETDEVCAPS_CAN_REVERSE:
470 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
471 TRACE("MCI_DGV_GETDEVCAPS_CAN_REVERSE = %08x\n", lpParms->dwReturn);
472 break;
473 case MCI_DGV_GETDEVCAPS_CAN_STRETCH:
474 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE); /* FIXME */
475 TRACE("MCI_DGV_GETDEVCAPS_CAN_STRETCH = %08x\n", lpParms->dwReturn);
476 break;
477 case MCI_DGV_GETDEVCAPS_CAN_LOCK:
478 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
479 TRACE("MCI_DGV_GETDEVCAPS_CAN_LOCK = %08x\n", lpParms->dwReturn);
480 break;
481 case MCI_DGV_GETDEVCAPS_CAN_FREEZE:
482 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
483 TRACE("MCI_DGV_GETDEVCAPS_CAN_FREEZE = %08x\n", lpParms->dwReturn);
484 break;
485 case MCI_DGV_GETDEVCAPS_CAN_STR_IN:
486 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
487 TRACE("MCI_DGV_GETDEVCAPS_CAN_STRETCH_INPUT = %08x\n", lpParms->dwReturn);
488 break;
489 case MCI_DGV_GETDEVCAPS_HAS_STILL:
490 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
491 TRACE("MCI_DGV_GETDEVCAPS_HAS_STILL = %08x\n", lpParms->dwReturn);
492 break;
493 case MCI_DGV_GETDEVCAPS_CAN_TEST:
494 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE); /* FIXME */
495 TRACE("MCI_DGV_GETDEVCAPS_CAN_TEST = %08x\n", lpParms->dwReturn);
496 break;
497 case MCI_DGV_GETDEVCAPS_MAX_WINDOWS:
498 lpParms->dwReturn = 1;
499 TRACE("MCI_DGV_GETDEVCAPS_MAX_WINDOWS = %u\n", lpParms->dwReturn);
500 return 0;
501 default:
502 WARN("Unknown capability %08x\n", lpParms->dwItem);
503 /* Fall through */
504 case MCI_DGV_GETDEVCAPS_MAXIMUM_RATE: /* unknown to w2k */
505 case MCI_DGV_GETDEVCAPS_MINIMUM_RATE: /* unknown to w2k */
506 return MCIERR_UNSUPPORTED_FUNCTION;
509 return MCI_RESOURCE_RETURNED;
512 /***************************************************************************
513 * MCIQTZ_mciSet [internal]
515 static DWORD MCIQTZ_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SET_PARMS lpParms)
517 WINE_MCIQTZ* wma;
519 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
521 if (!lpParms)
522 return MCIERR_NULL_PARAMETER_BLOCK;
524 wma = MCIQTZ_mciGetOpenDev(wDevID);
525 if (!wma)
526 return MCIERR_INVALID_DEVICE_ID;
528 if (dwFlags & MCI_SET_TIME_FORMAT) {
529 switch (lpParms->dwTimeFormat) {
530 case MCI_FORMAT_MILLISECONDS:
531 TRACE("MCI_SET_TIME_FORMAT = MCI_FORMAT_MILLISECONDS\n");
532 wma->time_format = MCI_FORMAT_MILLISECONDS;
533 break;
534 case MCI_FORMAT_FRAMES:
535 TRACE("MCI_SET_TIME_FORMAT = MCI_FORMAT_FRAMES\n");
536 wma->time_format = MCI_FORMAT_FRAMES;
537 break;
538 default:
539 WARN("Bad time format %u\n", lpParms->dwTimeFormat);
540 return MCIERR_BAD_TIME_FORMAT;
544 if (dwFlags & MCI_SET_DOOR_OPEN)
545 FIXME("MCI_SET_DOOR_OPEN not implemented yet\n");
546 if (dwFlags & MCI_SET_DOOR_CLOSED)
547 FIXME("MCI_SET_DOOR_CLOSED not implemented yet\n");
548 if (dwFlags & MCI_SET_AUDIO)
549 FIXME("MCI_SET_AUDIO not implemented yet\n");
550 if (dwFlags & MCI_SET_VIDEO)
551 FIXME("MCI_SET_VIDEO not implemented yet\n");
552 if (dwFlags & MCI_SET_ON)
553 FIXME("MCI_SET_ON not implemented yet\n");
554 if (dwFlags & MCI_SET_OFF)
555 FIXME("MCI_SET_OFF not implemented yet\n");
556 if (dwFlags & MCI_SET_AUDIO_LEFT)
557 FIXME("MCI_SET_AUDIO_LEFT not implemented yet\n");
558 if (dwFlags & MCI_SET_AUDIO_RIGHT)
559 FIXME("MCI_SET_AUDIO_RIGHT not implemented yet\n");
561 if (dwFlags & ~0x7f03 /* All MCI_SET flags mask */)
562 ERR("Unknown flags %08x\n", dwFlags & ~0x7f03);
564 return 0;
567 /***************************************************************************
568 * MCIQTZ_mciStatus [internal]
570 static DWORD MCIQTZ_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_DGV_STATUS_PARMSW lpParms)
572 WINE_MCIQTZ* wma;
573 HRESULT hr;
575 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
577 if (!lpParms)
578 return MCIERR_NULL_PARAMETER_BLOCK;
580 wma = MCIQTZ_mciGetOpenDev(wDevID);
581 if (!wma)
582 return MCIERR_INVALID_DEVICE_ID;
584 if (!(dwFlags & MCI_STATUS_ITEM)) {
585 WARN("No status item specified\n");
586 return MCIERR_UNRECOGNIZED_COMMAND;
589 switch (lpParms->dwItem) {
590 case MCI_STATUS_LENGTH: {
591 LONGLONG duration = -1;
592 GUID format;
593 switch (wma->time_format) {
594 case MCI_FORMAT_MILLISECONDS: format = TIME_FORMAT_MEDIA_TIME; break;
595 case MCI_FORMAT_FRAMES: format = TIME_FORMAT_FRAME; break;
596 default: ERR("Unhandled format %x\n", wma->time_format); break;
598 hr = IMediaSeeking_SetTimeFormat(wma->seek, &format);
599 if (FAILED(hr)) {
600 FIXME("Cannot set time format (hr = %x)\n", hr);
601 lpParms->dwReturn = 0;
602 break;
604 hr = IMediaSeeking_GetDuration(wma->seek, &duration);
605 if (FAILED(hr) || duration < 0) {
606 FIXME("Cannot read duration (hr = %x)\n", hr);
607 lpParms->dwReturn = 0;
608 } else if (wma->time_format != MCI_FORMAT_MILLISECONDS)
609 lpParms->dwReturn = duration;
610 else
611 lpParms->dwReturn = duration / 10000;
612 break;
614 case MCI_STATUS_POSITION: {
615 REFERENCE_TIME curpos;
617 hr = IMediaSeeking_GetCurrentPosition(wma->seek, &curpos);
618 if (FAILED(hr)) {
619 FIXME("Cannot get position (hr = %x)\n", hr);
620 return MCIERR_INTERNAL;
622 lpParms->dwReturn = curpos / 10000;
623 break;
625 case MCI_STATUS_NUMBER_OF_TRACKS:
626 FIXME("MCI_STATUS_NUMBER_OF_TRACKS not implemented yet\n");
627 return MCIERR_UNRECOGNIZED_COMMAND;
628 case MCI_STATUS_MODE:
629 FIXME("MCI_STATUS_MODE not implemented yet\n");
630 return MCIERR_UNRECOGNIZED_COMMAND;
631 case MCI_STATUS_MEDIA_PRESENT:
632 FIXME("MCI_STATUS_MEDIA_PRESENT not implemented yet\n");
633 return MCIERR_UNRECOGNIZED_COMMAND;
634 case MCI_STATUS_TIME_FORMAT:
635 lpParms->dwReturn = wma->time_format;
636 break;
637 case MCI_STATUS_READY:
638 FIXME("MCI_STATUS_READY not implemented yet\n");
639 return MCIERR_UNRECOGNIZED_COMMAND;
640 case MCI_STATUS_CURRENT_TRACK:
641 FIXME("MCI_STATUS_CURRENT_TRACK not implemented yet\n");
642 return MCIERR_UNRECOGNIZED_COMMAND;
643 default:
644 FIXME("Unknown command %08X\n", lpParms->dwItem);
645 return MCIERR_UNRECOGNIZED_COMMAND;
648 if (dwFlags & MCI_NOTIFY)
649 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)), wDevID, MCI_NOTIFY_SUCCESSFUL);
651 return 0;
654 /***************************************************************************
655 * MCIQTZ_mciWhere [internal]
657 static DWORD MCIQTZ_mciWhere(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
659 WINE_MCIQTZ* wma;
660 HRESULT hr;
661 HWND hWnd;
662 RECT rc;
663 DWORD ret = MCIERR_UNRECOGNIZED_COMMAND;
665 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
667 if (!lpParms)
668 return MCIERR_NULL_PARAMETER_BLOCK;
670 wma = MCIQTZ_mciGetOpenDev(wDevID);
671 if (!wma)
672 return MCIERR_INVALID_DEVICE_ID;
674 hr = IVideoWindow_get_Owner(wma->vidwin, (OAHWND*)&hWnd);
675 if (FAILED(hr)) {
676 TRACE("No video stream, returning no window error\n");
677 return MCIERR_NO_WINDOW;
680 if (dwFlags & MCI_DGV_WHERE_SOURCE) {
681 if (dwFlags & MCI_DGV_WHERE_MAX)
682 FIXME("MCI_DGV_WHERE_SOURCE_MAX stub %s\n", wine_dbgstr_rect(&rc));
683 IBasicVideo_get_SourceLeft(wma->vidbasic, &rc.left);
684 IBasicVideo_get_SourceTop(wma->vidbasic, &rc.top);
685 IBasicVideo_get_SourceWidth(wma->vidbasic, &rc.right);
686 IBasicVideo_get_SourceHeight(wma->vidbasic, &rc.bottom);
687 /* Undo conversion done below */
688 rc.right += rc.left;
689 rc.bottom += rc.top;
690 TRACE("MCI_DGV_WHERE_SOURCE %s\n", wine_dbgstr_rect(&rc));
692 if (dwFlags & MCI_DGV_WHERE_DESTINATION) {
693 if (dwFlags & MCI_DGV_WHERE_MAX) {
694 GetClientRect(hWnd, &rc);
695 TRACE("MCI_DGV_WHERE_DESTINATION_MAX %s\n", wine_dbgstr_rect(&rc));
696 } else {
697 FIXME("MCI_DGV_WHERE_DESTINATION not supported yet\n");
698 goto out;
701 if (dwFlags & MCI_DGV_WHERE_FRAME) {
702 if (dwFlags & MCI_DGV_WHERE_MAX)
703 FIXME("MCI_DGV_WHERE_FRAME_MAX not supported yet\n");
704 else
705 FIXME("MCI_DGV_WHERE_FRAME not supported yet\n");
706 goto out;
708 if (dwFlags & MCI_DGV_WHERE_VIDEO) {
709 if (dwFlags & MCI_DGV_WHERE_MAX)
710 FIXME("MCI_DGV_WHERE_VIDEO_MAX not supported yet\n");
711 else
712 FIXME("MCI_DGV_WHERE_VIDEO not supported yet\n");
713 goto out;
715 if (dwFlags & MCI_DGV_WHERE_WINDOW) {
716 if (dwFlags & MCI_DGV_WHERE_MAX) {
717 GetWindowRect(GetDesktopWindow(), &rc);
718 TRACE("MCI_DGV_WHERE_WINDOW_MAX %s\n", wine_dbgstr_rect(&rc));
719 } else {
720 GetWindowRect(hWnd, &rc);
721 TRACE("MCI_DGV_WHERE_WINDOW %s\n", wine_dbgstr_rect(&rc));
724 ret = 0;
726 out:
727 /* In MCI, RECT structure is used differently: rc.right = width & rc.bottom = height
728 * So convert the normal RECT into a MCI RECT before returning */
729 lpParms->rc.left = rc.left;
730 lpParms->rc.top = rc.top;
731 lpParms->rc.right = rc.right - rc.left;
732 lpParms->rc.bottom = rc.bottom - rc.top;
734 return ret;
737 /***************************************************************************
738 * MCIQTZ_mciWindow [internal]
740 static DWORD MCIQTZ_mciWindow(UINT wDevID, DWORD dwFlags, LPMCI_DGV_WINDOW_PARMSW lpParms)
742 WINE_MCIQTZ *wma = MCIQTZ_mciGetOpenDev(wDevID);
744 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
746 if (!lpParms)
747 return MCIERR_NULL_PARAMETER_BLOCK;
748 if (!wma)
749 return MCIERR_INVALID_DEVICE_ID;
750 if (dwFlags & MCI_TEST)
751 return 0;
753 if (dwFlags & MCI_DGV_WINDOW_HWND && (IsWindow(lpParms->hWnd) || !lpParms->hWnd)) {
754 LONG style = 0;
755 TRACE("Setting hWnd to %p\n", lpParms->hWnd);
756 IVideoWindow_put_Visible(wma->vidwin, OAFALSE);
757 IVideoWindow_get_WindowStyle(wma->vidwin, &style);
758 style &= ~WS_CHILD;
759 if (lpParms->hWnd)
760 IVideoWindow_put_WindowStyle(wma->vidwin, style|WS_CHILD);
761 else
762 IVideoWindow_put_WindowStyle(wma->vidwin, style);
763 IVideoWindow_put_Owner(wma->vidwin, (OAHWND)lpParms->hWnd);
764 IVideoWindow_put_MessageDrain(wma->vidwin, (OAHWND)lpParms->hWnd);
765 IVideoWindow_put_Visible(wma->vidwin, OATRUE);
766 wma->parent = lpParms->hWnd;
768 if (dwFlags & MCI_DGV_WINDOW_STATE) {
769 TRACE("Setting nCmdShow to %d\n", lpParms->nCmdShow);
770 IVideoWindow_put_WindowState(wma->vidwin, lpParms->nCmdShow);
772 if (dwFlags & MCI_DGV_WINDOW_TEXT) {
773 TRACE("Setting caption to %s\n", debugstr_w(lpParms->lpstrText));
774 IVideoWindow_put_Caption(wma->vidwin, lpParms->lpstrText);
776 return 0;
779 /******************************************************************************
780 * MCIAVI_mciUpdate [internal]
782 static DWORD MCIQTZ_mciUpdate(UINT wDevID, DWORD dwFlags, LPMCI_DGV_UPDATE_PARMS lpParms)
784 WINE_MCIQTZ *wma;
785 DWORD res = 0;
787 TRACE("%04x, %08x, %p\n", wDevID, dwFlags, lpParms);
789 if (!lpParms)
790 return MCIERR_NULL_PARAMETER_BLOCK;
792 wma = MCIQTZ_mciGetOpenDev(wDevID);
793 if (!wma)
794 return MCIERR_INVALID_DEVICE_ID;
796 if (dwFlags & MCI_DGV_UPDATE_HDC) {
797 LONG state, size;
798 BYTE *data;
799 BITMAPINFO *info;
800 HRESULT hr;
801 RECT src, dest;
803 res = MCIERR_INTERNAL;
804 /* If in stopped state, nothing has been drawn to screen
805 * moving to pause, which is needed for the old dib renderer, will result
806 * in a single frame drawn, so hide the window here */
807 IVideoWindow_put_Visible(wma->vidwin, OAFALSE);
808 /* FIXME: Should we check the original state and restore it? */
809 IMediaControl_Pause(wma->pmctrl);
810 IMediaControl_GetState(wma->pmctrl, -1, &state);
811 if (FAILED(hr = IBasicVideo_GetCurrentImage(wma->vidbasic, &size, NULL))) {
812 WARN("Could not get image size (hr = %x)\n", hr);
813 goto out;
815 data = HeapAlloc(GetProcessHeap(), 0, size);
816 info = (BITMAPINFO*)data;
817 IBasicVideo_GetCurrentImage(wma->vidbasic, &size, (LONG*)data);
818 data += info->bmiHeader.biSize;
820 IBasicVideo_GetSourcePosition(wma->vidbasic, &src.left, &src.top, &src.right, &src.bottom);
821 IBasicVideo_GetDestinationPosition(wma->vidbasic, &dest.left, &dest.top, &dest.right, &dest.bottom);
822 StretchDIBits(lpParms->hDC,
823 dest.left, dest.top, dest.right + dest.left, dest.bottom + dest.top,
824 src.left, src.top, src.right + src.left, src.bottom + src.top,
825 data, info, DIB_RGB_COLORS, SRCCOPY);
826 HeapFree(GetProcessHeap(), 0, data);
827 res = 0;
828 out:
829 if (wma->parent)
830 IVideoWindow_put_Visible(wma->vidwin, OATRUE);
832 else if (dwFlags)
833 FIXME("Unhandled flags %x\n", dwFlags);
834 return res;
837 /***************************************************************************
838 * MCIQTZ_mciSetAudio [internal]
840 static DWORD MCIQTZ_mciSetAudio(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SETAUDIO_PARMSW lpParms)
842 WINE_MCIQTZ *wma;
844 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
846 if (!lpParms)
847 return MCIERR_NULL_PARAMETER_BLOCK;
849 wma = MCIQTZ_mciGetOpenDev(wDevID);
850 if (!wma)
851 return MCIERR_INVALID_DEVICE_ID;
853 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
855 return 0;
858 /*======================================================================*
859 * MCI QTZ entry points *
860 *======================================================================*/
862 /**************************************************************************
863 * DriverProc (MCIQTZ.@)
865 LRESULT CALLBACK MCIQTZ_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
866 LPARAM dwParam1, LPARAM dwParam2)
868 TRACE("(%08lX, %p, %08X, %08lX, %08lX)\n",
869 dwDevID, hDriv, wMsg, dwParam1, dwParam2);
871 switch (wMsg) {
872 case DRV_LOAD: return 1;
873 case DRV_FREE: return 1;
874 case DRV_OPEN: return MCIQTZ_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
875 case DRV_CLOSE: return MCIQTZ_drvClose(dwDevID);
876 case DRV_ENABLE: return 1;
877 case DRV_DISABLE: return 1;
878 case DRV_QUERYCONFIGURE: return 1;
879 case DRV_CONFIGURE: return MCIQTZ_drvConfigure(dwDevID);
880 case DRV_INSTALL: return DRVCNF_RESTART;
881 case DRV_REMOVE: return DRVCNF_RESTART;
884 /* session instance */
885 if (dwDevID == 0xFFFFFFFF)
886 return 1;
888 switch (wMsg) {
889 case MCI_OPEN_DRIVER: return MCIQTZ_mciOpen (dwDevID, dwParam1, (LPMCI_DGV_OPEN_PARMSW) dwParam2);
890 case MCI_CLOSE_DRIVER: return MCIQTZ_mciClose (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
891 case MCI_PLAY: return MCIQTZ_mciPlay (dwDevID, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
892 case MCI_SEEK: return MCIQTZ_mciSeek (dwDevID, dwParam1, (LPMCI_SEEK_PARMS) dwParam2);
893 case MCI_STOP: return MCIQTZ_mciStop (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
894 case MCI_PAUSE: return MCIQTZ_mciPause (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
895 case MCI_GETDEVCAPS: return MCIQTZ_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS) dwParam2);
896 case MCI_SET: return MCIQTZ_mciSet (dwDevID, dwParam1, (LPMCI_DGV_SET_PARMS) dwParam2);
897 case MCI_STATUS: return MCIQTZ_mciStatus (dwDevID, dwParam1, (LPMCI_DGV_STATUS_PARMSW) dwParam2);
898 case MCI_WHERE: return MCIQTZ_mciWhere (dwDevID, dwParam1, (LPMCI_DGV_RECT_PARMS) dwParam2);
899 /* Digital Video specific */
900 case MCI_SETAUDIO: return MCIQTZ_mciSetAudio (dwDevID, dwParam1, (LPMCI_DGV_SETAUDIO_PARMSW) dwParam2);
901 case MCI_UPDATE:
902 return MCIQTZ_mciUpdate(dwDevID, dwParam1, (LPMCI_DGV_UPDATE_PARMS)dwParam2);
903 case MCI_WINDOW:
904 return MCIQTZ_mciWindow(dwDevID, dwParam1, (LPMCI_DGV_WINDOW_PARMSW)dwParam2);
905 case MCI_PUT:
906 case MCI_RECORD:
907 case MCI_RESUME:
908 case MCI_INFO:
909 case MCI_LOAD:
910 case MCI_SAVE:
911 case MCI_FREEZE:
912 case MCI_REALIZE:
913 case MCI_UNFREEZE:
914 case MCI_STEP:
915 case MCI_COPY:
916 case MCI_CUT:
917 case MCI_DELETE:
918 case MCI_PASTE:
919 case MCI_CUE:
920 /* Digital Video specific */
921 case MCI_CAPTURE:
922 case MCI_MONITOR:
923 case MCI_RESERVE:
924 case MCI_SIGNAL:
925 case MCI_SETVIDEO:
926 case MCI_QUALITY:
927 case MCI_LIST:
928 case MCI_UNDO:
929 case MCI_CONFIGURE:
930 case MCI_RESTORE:
931 FIXME("Unimplemented command [%08X]\n", wMsg);
932 break;
933 case MCI_SPIN:
934 case MCI_ESCAPE:
935 WARN("Unsupported command [%08X]\n", wMsg);
936 break;
937 case MCI_OPEN:
938 case MCI_CLOSE:
939 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
940 break;
941 default:
942 TRACE("Sending msg [%08X] to default driver proc\n", wMsg);
943 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
946 return MCIERR_UNRECOGNIZED_COMMAND;