msxml3: Fix IDispatch support for IXMLDocument.
[wine/multimedia.git] / dlls / mciqtz32 / mciqtz.c
blob03f6f9d43a6421c32526ced61736c1adab81a60e
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 static 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 IBasicVideo_GetVideoSize(wma->vidbasic, &rc.right, &rc.bottom);
229 wma->opened = TRUE;
231 if (dwFlags & MCI_NOTIFY)
232 mciDriverNotify(HWND_32(LOWORD(lpOpenParms->dwCallback)), wDevID, MCI_NOTIFY_SUCCESSFUL);
234 return 0;
236 err:
237 if (wma->vidbasic)
238 IUnknown_Release(wma->vidbasic);
239 wma->vidbasic = NULL;
240 if (wma->seek)
241 IUnknown_Release(wma->seek);
242 wma->seek = NULL;
243 if (wma->vidwin)
244 IUnknown_Release(wma->vidwin);
245 wma->vidwin = NULL;
246 if (wma->pgraph)
247 IGraphBuilder_Release(wma->pgraph);
248 wma->pgraph = NULL;
249 if (wma->pmctrl)
250 IMediaControl_Release(wma->pmctrl);
251 wma->pmctrl = NULL;
253 if (wma->uninit)
254 CoUninitialize();
255 wma->uninit = 0;
257 return MCIERR_INTERNAL;
260 /***************************************************************************
261 * MCIQTZ_mciClose [internal]
263 static DWORD MCIQTZ_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
265 WINE_MCIQTZ* wma;
267 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
269 wma = MCIQTZ_mciGetOpenDev(wDevID);
270 if (!wma)
271 return MCIERR_INVALID_DEVICE_ID;
273 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
275 if (wma->opened) {
276 IUnknown_Release(wma->vidwin);
277 IUnknown_Release(wma->vidbasic);
278 IUnknown_Release(wma->seek);
279 IGraphBuilder_Release(wma->pgraph);
280 IMediaControl_Release(wma->pmctrl);
281 if (wma->uninit)
282 CoUninitialize();
283 wma->opened = FALSE;
286 return 0;
289 /***************************************************************************
290 * MCIQTZ_mciPlay [internal]
292 static DWORD MCIQTZ_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
294 WINE_MCIQTZ* wma;
295 HRESULT hr;
296 REFERENCE_TIME time1 = 0, time2 = 0;
297 GUID format;
298 DWORD pos1;
300 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
302 if (!lpParms)
303 return MCIERR_NULL_PARAMETER_BLOCK;
305 wma = MCIQTZ_mciGetOpenDev(wDevID);
306 if (!wma)
307 return MCIERR_INVALID_DEVICE_ID;
309 IMediaSeeking_GetTimeFormat(wma->seek, &format);
310 if (dwFlags & MCI_FROM) {
311 if (IsEqualGUID(&format, &TIME_FORMAT_MEDIA_TIME))
312 time1 = lpParms->dwFrom * 10000;
313 else
314 time1 = lpParms->dwFrom;
315 pos1 = AM_SEEKING_AbsolutePositioning;
316 } else
317 pos1 = AM_SEEKING_NoPositioning;
318 if (dwFlags & MCI_TO) {
319 if (IsEqualGUID(&format, &TIME_FORMAT_MEDIA_TIME))
320 time2 = lpParms->dwTo * 10000;
321 else
322 time2 = lpParms->dwTo;
323 } else
324 IMediaSeeking_GetDuration(wma->seek, &time2);
325 IMediaSeeking_SetPositions(wma->seek, &time1, pos1, &time2, AM_SEEKING_AbsolutePositioning);
327 hr = IMediaControl_Run(wma->pmctrl);
328 if (FAILED(hr)) {
329 TRACE("Cannot run filtergraph (hr = %x)\n", hr);
330 return MCIERR_INTERNAL;
333 IVideoWindow_put_Visible(wma->vidwin, OATRUE);
335 if (dwFlags & MCI_NOTIFY)
336 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)), wDevID, MCI_NOTIFY_SUCCESSFUL);
337 return 0;
340 /***************************************************************************
341 * MCIQTZ_mciSeek [internal]
343 static DWORD MCIQTZ_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
345 WINE_MCIQTZ* wma;
346 HRESULT hr;
347 LONGLONG newpos;
349 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
351 if (!lpParms)
352 return MCIERR_NULL_PARAMETER_BLOCK;
354 wma = MCIQTZ_mciGetOpenDev(wDevID);
355 if (!wma)
356 return MCIERR_INVALID_DEVICE_ID;
358 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
360 if (dwFlags & MCI_SEEK_TO_START) {
361 newpos = 0;
362 } else if (dwFlags & MCI_SEEK_TO_END) {
363 FIXME("MCI_SEEK_TO_END not implemented yet\n");
364 return MCIERR_INTERNAL;
365 } else if (dwFlags & MCI_TO) {
366 FIXME("MCI_TO not implemented yet\n");
367 return MCIERR_INTERNAL;
368 } else {
369 WARN("dwFlag doesn't tell where to seek to...\n");
370 return MCIERR_MISSING_PARAMETER;
373 hr = IMediaSeeking_SetPositions(wma->seek, &newpos, AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
374 if (FAILED(hr)) {
375 FIXME("Cannot set position (hr = %x)\n", hr);
376 return MCIERR_INTERNAL;
379 if (dwFlags & MCI_NOTIFY)
380 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)), wDevID, MCI_NOTIFY_SUCCESSFUL);
382 return 0;
385 /***************************************************************************
386 * MCIQTZ_mciStop [internal]
388 static DWORD MCIQTZ_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
390 WINE_MCIQTZ* wma;
391 HRESULT hr;
393 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
395 wma = MCIQTZ_mciGetOpenDev(wDevID);
396 if (!wma)
397 return MCIERR_INVALID_DEVICE_ID;
399 if (!wma->opened)
400 return 0;
402 hr = IMediaControl_Stop(wma->pmctrl);
403 if (FAILED(hr)) {
404 TRACE("Cannot stop filtergraph (hr = %x)\n", hr);
405 return MCIERR_INTERNAL;
408 if (!wma->parent)
409 IVideoWindow_put_Visible(wma->vidwin, OAFALSE);
411 return 0;
414 /***************************************************************************
415 * MCIQTZ_mciPause [internal]
417 static DWORD MCIQTZ_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
419 WINE_MCIQTZ* wma;
420 HRESULT hr;
422 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
424 wma = MCIQTZ_mciGetOpenDev(wDevID);
425 if (!wma)
426 return MCIERR_INVALID_DEVICE_ID;
428 hr = IMediaControl_Pause(wma->pmctrl);
429 if (FAILED(hr)) {
430 TRACE("Cannot pause filtergraph (hr = %x)\n", hr);
431 return MCIERR_INTERNAL;
434 return 0;
437 /***************************************************************************
438 * MCIQTZ_mciGetDevCaps [internal]
440 static DWORD MCIQTZ_mciGetDevCaps(UINT wDevID, DWORD dwFlags, LPMCI_GETDEVCAPS_PARMS lpParms)
442 WINE_MCIQTZ* wma;
444 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
446 if (!lpParms)
447 return MCIERR_NULL_PARAMETER_BLOCK;
449 wma = MCIQTZ_mciGetOpenDev(wDevID);
450 if (!wma)
451 return MCIERR_INVALID_DEVICE_ID;
453 if (!(dwFlags & MCI_GETDEVCAPS_ITEM))
454 return MCIERR_MISSING_PARAMETER;
456 switch (lpParms->dwItem) {
457 case MCI_GETDEVCAPS_CAN_RECORD:
458 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
459 TRACE("MCI_GETDEVCAPS_CAN_RECORD = %08x\n", lpParms->dwReturn);
460 break;
461 case MCI_GETDEVCAPS_HAS_AUDIO:
462 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
463 TRACE("MCI_GETDEVCAPS_HAS_AUDIO = %08x\n", lpParms->dwReturn);
464 break;
465 case MCI_GETDEVCAPS_HAS_VIDEO:
466 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
467 TRACE("MCI_GETDEVCAPS_HAS_VIDEO = %08x\n", lpParms->dwReturn);
468 break;
469 case MCI_GETDEVCAPS_DEVICE_TYPE:
470 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_DEVTYPE_DIGITAL_VIDEO, MCI_DEVTYPE_DIGITAL_VIDEO);
471 TRACE("MCI_GETDEVCAPS_DEVICE_TYPE = %08x\n", lpParms->dwReturn);
472 break;
473 case MCI_GETDEVCAPS_USES_FILES:
474 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
475 TRACE("MCI_GETDEVCAPS_USES_FILES = %08x\n", lpParms->dwReturn);
476 break;
477 case MCI_GETDEVCAPS_COMPOUND_DEVICE:
478 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
479 TRACE("MCI_GETDEVCAPS_COMPOUND_DEVICE = %08x\n", lpParms->dwReturn);
480 break;
481 case MCI_GETDEVCAPS_CAN_EJECT:
482 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
483 TRACE("MCI_GETDEVCAPS_EJECT = %08x\n", lpParms->dwReturn);
484 break;
485 case MCI_GETDEVCAPS_CAN_PLAY:
486 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
487 TRACE("MCI_GETDEVCAPS_CAN_PLAY = %08x\n", lpParms->dwReturn);
488 break;
489 case MCI_GETDEVCAPS_CAN_SAVE:
490 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
491 TRACE("MCI_GETDEVCAPS_CAN_SAVE = %08x\n", lpParms->dwReturn);
492 break;
493 case MCI_DGV_GETDEVCAPS_CAN_REVERSE:
494 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
495 TRACE("MCI_DGV_GETDEVCAPS_CAN_REVERSE = %08x\n", lpParms->dwReturn);
496 break;
497 case MCI_DGV_GETDEVCAPS_CAN_STRETCH:
498 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE); /* FIXME */
499 TRACE("MCI_DGV_GETDEVCAPS_CAN_STRETCH = %08x\n", lpParms->dwReturn);
500 break;
501 case MCI_DGV_GETDEVCAPS_CAN_LOCK:
502 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
503 TRACE("MCI_DGV_GETDEVCAPS_CAN_LOCK = %08x\n", lpParms->dwReturn);
504 break;
505 case MCI_DGV_GETDEVCAPS_CAN_FREEZE:
506 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
507 TRACE("MCI_DGV_GETDEVCAPS_CAN_FREEZE = %08x\n", lpParms->dwReturn);
508 break;
509 case MCI_DGV_GETDEVCAPS_CAN_STR_IN:
510 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
511 TRACE("MCI_DGV_GETDEVCAPS_CAN_STRETCH_INPUT = %08x\n", lpParms->dwReturn);
512 break;
513 case MCI_DGV_GETDEVCAPS_HAS_STILL:
514 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
515 TRACE("MCI_DGV_GETDEVCAPS_HAS_STILL = %08x\n", lpParms->dwReturn);
516 break;
517 case MCI_DGV_GETDEVCAPS_CAN_TEST:
518 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE); /* FIXME */
519 TRACE("MCI_DGV_GETDEVCAPS_CAN_TEST = %08x\n", lpParms->dwReturn);
520 break;
521 case MCI_DGV_GETDEVCAPS_MAX_WINDOWS:
522 lpParms->dwReturn = 1;
523 TRACE("MCI_DGV_GETDEVCAPS_MAX_WINDOWS = %u\n", lpParms->dwReturn);
524 return 0;
525 default:
526 WARN("Unknown capability %08x\n", lpParms->dwItem);
527 /* Fall through */
528 case MCI_DGV_GETDEVCAPS_MAXIMUM_RATE: /* unknown to w2k */
529 case MCI_DGV_GETDEVCAPS_MINIMUM_RATE: /* unknown to w2k */
530 return MCIERR_UNSUPPORTED_FUNCTION;
533 return MCI_RESOURCE_RETURNED;
536 /***************************************************************************
537 * MCIQTZ_mciSet [internal]
539 static DWORD MCIQTZ_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SET_PARMS lpParms)
541 WINE_MCIQTZ* wma;
543 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
545 if (!lpParms)
546 return MCIERR_NULL_PARAMETER_BLOCK;
548 wma = MCIQTZ_mciGetOpenDev(wDevID);
549 if (!wma)
550 return MCIERR_INVALID_DEVICE_ID;
552 if (dwFlags & MCI_SET_TIME_FORMAT) {
553 switch (lpParms->dwTimeFormat) {
554 case MCI_FORMAT_MILLISECONDS:
555 TRACE("MCI_SET_TIME_FORMAT = MCI_FORMAT_MILLISECONDS\n");
556 wma->time_format = MCI_FORMAT_MILLISECONDS;
557 break;
558 case MCI_FORMAT_FRAMES:
559 TRACE("MCI_SET_TIME_FORMAT = MCI_FORMAT_FRAMES\n");
560 wma->time_format = MCI_FORMAT_FRAMES;
561 break;
562 default:
563 WARN("Bad time format %u\n", lpParms->dwTimeFormat);
564 return MCIERR_BAD_TIME_FORMAT;
568 if (dwFlags & MCI_SET_DOOR_OPEN)
569 FIXME("MCI_SET_DOOR_OPEN not implemented yet\n");
570 if (dwFlags & MCI_SET_DOOR_CLOSED)
571 FIXME("MCI_SET_DOOR_CLOSED not implemented yet\n");
572 if (dwFlags & MCI_SET_AUDIO)
573 FIXME("MCI_SET_AUDIO not implemented yet\n");
574 if (dwFlags & MCI_SET_VIDEO)
575 FIXME("MCI_SET_VIDEO not implemented yet\n");
576 if (dwFlags & MCI_SET_ON)
577 FIXME("MCI_SET_ON not implemented yet\n");
578 if (dwFlags & MCI_SET_OFF)
579 FIXME("MCI_SET_OFF not implemented yet\n");
580 if (dwFlags & MCI_SET_AUDIO_LEFT)
581 FIXME("MCI_SET_AUDIO_LEFT not implemented yet\n");
582 if (dwFlags & MCI_SET_AUDIO_RIGHT)
583 FIXME("MCI_SET_AUDIO_RIGHT not implemented yet\n");
585 if (dwFlags & ~0x7f03 /* All MCI_SET flags mask */)
586 ERR("Unknown flags %08x\n", dwFlags & ~0x7f03);
588 return 0;
591 /***************************************************************************
592 * MCIQTZ_mciStatus [internal]
594 static DWORD MCIQTZ_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_DGV_STATUS_PARMSW lpParms)
596 WINE_MCIQTZ* wma;
597 HRESULT hr;
599 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
601 if (!lpParms)
602 return MCIERR_NULL_PARAMETER_BLOCK;
604 wma = MCIQTZ_mciGetOpenDev(wDevID);
605 if (!wma)
606 return MCIERR_INVALID_DEVICE_ID;
608 if (!(dwFlags & MCI_STATUS_ITEM)) {
609 WARN("No status item specified\n");
610 return MCIERR_UNRECOGNIZED_COMMAND;
613 switch (lpParms->dwItem) {
614 case MCI_STATUS_LENGTH: {
615 LONGLONG duration = -1;
616 GUID format;
617 switch (wma->time_format) {
618 case MCI_FORMAT_MILLISECONDS: format = TIME_FORMAT_MEDIA_TIME; break;
619 case MCI_FORMAT_FRAMES: format = TIME_FORMAT_FRAME; break;
620 default: ERR("Unhandled format %x\n", wma->time_format); break;
622 hr = IMediaSeeking_SetTimeFormat(wma->seek, &format);
623 if (FAILED(hr)) {
624 FIXME("Cannot set time format (hr = %x)\n", hr);
625 lpParms->dwReturn = 0;
626 break;
628 hr = IMediaSeeking_GetDuration(wma->seek, &duration);
629 if (FAILED(hr) || duration < 0) {
630 FIXME("Cannot read duration (hr = %x)\n", hr);
631 lpParms->dwReturn = 0;
632 } else if (wma->time_format != MCI_FORMAT_MILLISECONDS)
633 lpParms->dwReturn = duration;
634 else
635 lpParms->dwReturn = duration / 10000;
636 break;
638 case MCI_STATUS_POSITION: {
639 REFERENCE_TIME curpos;
641 hr = IMediaSeeking_GetCurrentPosition(wma->seek, &curpos);
642 if (FAILED(hr)) {
643 FIXME("Cannot get position (hr = %x)\n", hr);
644 return MCIERR_INTERNAL;
646 lpParms->dwReturn = curpos / 10000;
647 break;
649 case MCI_STATUS_NUMBER_OF_TRACKS:
650 FIXME("MCI_STATUS_NUMBER_OF_TRACKS not implemented yet\n");
651 return MCIERR_UNRECOGNIZED_COMMAND;
652 case MCI_STATUS_MODE: {
653 LONG state = State_Stopped;
654 IMediaControl_GetState(wma->pmctrl, -1, &state);
655 if (state == State_Stopped)
656 state = MCI_MODE_STOP;
657 else if (state == State_Running)
658 state = MCI_MODE_PLAY;
659 else if (state == State_Paused)
660 state = MCI_MODE_PAUSE;
661 break;
663 case MCI_STATUS_MEDIA_PRESENT:
664 FIXME("MCI_STATUS_MEDIA_PRESENT not implemented yet\n");
665 return MCIERR_UNRECOGNIZED_COMMAND;
666 case MCI_STATUS_TIME_FORMAT:
667 lpParms->dwReturn = wma->time_format;
668 break;
669 case MCI_STATUS_READY:
670 FIXME("MCI_STATUS_READY not implemented yet\n");
671 return MCIERR_UNRECOGNIZED_COMMAND;
672 case MCI_STATUS_CURRENT_TRACK:
673 FIXME("MCI_STATUS_CURRENT_TRACK not implemented yet\n");
674 return MCIERR_UNRECOGNIZED_COMMAND;
675 default:
676 FIXME("Unknown command %08X\n", lpParms->dwItem);
677 return MCIERR_UNRECOGNIZED_COMMAND;
680 if (dwFlags & MCI_NOTIFY)
681 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)), wDevID, MCI_NOTIFY_SUCCESSFUL);
683 return 0;
686 /***************************************************************************
687 * MCIQTZ_mciWhere [internal]
689 static DWORD MCIQTZ_mciWhere(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
691 WINE_MCIQTZ* wma;
692 HRESULT hr;
693 HWND hWnd;
694 RECT rc;
695 DWORD ret = MCIERR_UNRECOGNIZED_COMMAND;
697 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
699 if (!lpParms)
700 return MCIERR_NULL_PARAMETER_BLOCK;
702 wma = MCIQTZ_mciGetOpenDev(wDevID);
703 if (!wma)
704 return MCIERR_INVALID_DEVICE_ID;
706 hr = IVideoWindow_get_Owner(wma->vidwin, (OAHWND*)&hWnd);
707 if (FAILED(hr)) {
708 TRACE("No video stream, returning no window error\n");
709 return MCIERR_NO_WINDOW;
712 if (dwFlags & MCI_DGV_WHERE_SOURCE) {
713 if (dwFlags & MCI_DGV_WHERE_MAX)
714 FIXME("MCI_DGV_WHERE_SOURCE_MAX stub %s\n", wine_dbgstr_rect(&rc));
715 IBasicVideo_GetSourcePosition(wma->vidbasic, &rc.left, &rc.top, &rc.right, &rc.bottom);
716 TRACE("MCI_DGV_WHERE_SOURCE %s\n", wine_dbgstr_rect(&rc));
718 if (dwFlags & MCI_DGV_WHERE_DESTINATION) {
719 if (dwFlags & MCI_DGV_WHERE_MAX)
720 FIXME("MCI_DGV_WHERE_DESTINATION_MAX stub %s\n", wine_dbgstr_rect(&rc));
721 IBasicVideo_GetDestinationPosition(wma->vidbasic, &rc.left, &rc.top, &rc.right, &rc.bottom);
722 TRACE("MCI_DGV_WHERE_DESTINATION %s\n", wine_dbgstr_rect(&rc));
724 if (dwFlags & MCI_DGV_WHERE_FRAME) {
725 if (dwFlags & MCI_DGV_WHERE_MAX)
726 FIXME("MCI_DGV_WHERE_FRAME_MAX not supported yet\n");
727 else
728 FIXME("MCI_DGV_WHERE_FRAME not supported yet\n");
729 goto out;
731 if (dwFlags & MCI_DGV_WHERE_VIDEO) {
732 if (dwFlags & MCI_DGV_WHERE_MAX)
733 FIXME("MCI_DGV_WHERE_VIDEO_MAX not supported yet\n");
734 else
735 FIXME("MCI_DGV_WHERE_VIDEO not supported yet\n");
736 goto out;
738 if (dwFlags & MCI_DGV_WHERE_WINDOW) {
739 if (dwFlags & MCI_DGV_WHERE_MAX) {
740 GetWindowRect(GetDesktopWindow(), &rc);
741 rc.right -= rc.left;
742 rc.bottom -= rc.top;
743 TRACE("MCI_DGV_WHERE_WINDOW_MAX %s\n", wine_dbgstr_rect(&rc));
744 } else {
745 IVideoWindow_GetWindowPosition(wma->vidwin, &rc.left, &rc.top, &rc.right, &rc.bottom);
746 TRACE("MCI_DGV_WHERE_WINDOW %s\n", wine_dbgstr_rect(&rc));
749 ret = 0;
750 out:
751 lpParms->rc = rc;
752 return ret;
755 /***************************************************************************
756 * MCIQTZ_mciWindow [internal]
758 static DWORD MCIQTZ_mciWindow(UINT wDevID, DWORD dwFlags, LPMCI_DGV_WINDOW_PARMSW lpParms)
760 WINE_MCIQTZ *wma = MCIQTZ_mciGetOpenDev(wDevID);
762 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
764 if (!lpParms)
765 return MCIERR_NULL_PARAMETER_BLOCK;
766 if (!wma)
767 return MCIERR_INVALID_DEVICE_ID;
768 if (dwFlags & MCI_TEST)
769 return 0;
771 if (dwFlags & MCI_DGV_WINDOW_HWND && (IsWindow(lpParms->hWnd) || !lpParms->hWnd)) {
772 LONG visible = OATRUE;
773 LONG style = 0;
774 TRACE("Setting hWnd to %p\n", lpParms->hWnd);
775 IVideoWindow_get_Visible(wma->vidwin, &visible);
776 IVideoWindow_put_Visible(wma->vidwin, OAFALSE);
777 IVideoWindow_get_WindowStyle(wma->vidwin, &style);
778 style &= ~WS_CHILD;
779 if (lpParms->hWnd)
780 IVideoWindow_put_WindowStyle(wma->vidwin, style|WS_CHILD);
781 else
782 IVideoWindow_put_WindowStyle(wma->vidwin, style);
783 IVideoWindow_put_Owner(wma->vidwin, (OAHWND)lpParms->hWnd);
784 IVideoWindow_put_MessageDrain(wma->vidwin, (OAHWND)lpParms->hWnd);
785 IVideoWindow_put_Visible(wma->vidwin, visible);
786 wma->parent = lpParms->hWnd;
788 if (dwFlags & MCI_DGV_WINDOW_STATE) {
789 TRACE("Setting nCmdShow to %d\n", lpParms->nCmdShow);
790 IVideoWindow_put_WindowState(wma->vidwin, lpParms->nCmdShow);
792 if (dwFlags & MCI_DGV_WINDOW_TEXT) {
793 TRACE("Setting caption to %s\n", debugstr_w(lpParms->lpstrText));
794 IVideoWindow_put_Caption(wma->vidwin, lpParms->lpstrText);
796 return 0;
799 /******************************************************************************
800 * MCIAVI_mciUpdate [internal]
802 static DWORD MCIQTZ_mciUpdate(UINT wDevID, DWORD dwFlags, LPMCI_DGV_UPDATE_PARMS lpParms)
804 WINE_MCIQTZ *wma;
805 DWORD res = 0;
807 TRACE("%04x, %08x, %p\n", wDevID, dwFlags, lpParms);
809 if (!lpParms)
810 return MCIERR_NULL_PARAMETER_BLOCK;
812 wma = MCIQTZ_mciGetOpenDev(wDevID);
813 if (!wma)
814 return MCIERR_INVALID_DEVICE_ID;
816 if (dwFlags & MCI_DGV_UPDATE_HDC) {
817 LONG state, size;
818 BYTE *data;
819 BITMAPINFO *info;
820 HRESULT hr;
821 RECT src, dest;
822 LONG visible = OATRUE;
824 res = MCIERR_INTERNAL;
825 IMediaControl_GetState(wma->pmctrl, -1, &state);
826 if (state == State_Running)
827 return MCIERR_UNSUPPORTED_FUNCTION;
828 /* If in stopped state, nothing has been drawn to screen
829 * moving to pause, which is needed for the old dib renderer, will result
830 * in a single frame drawn, so hide the window here */
831 IVideoWindow_get_Visible(wma->vidwin, &visible);
832 if (wma->parent)
833 IVideoWindow_put_Visible(wma->vidwin, OAFALSE);
834 /* FIXME: Should we check the original state and restore it? */
835 IMediaControl_Pause(wma->pmctrl);
836 IMediaControl_GetState(wma->pmctrl, -1, &state);
837 if (FAILED(hr = IBasicVideo_GetCurrentImage(wma->vidbasic, &size, NULL))) {
838 WARN("Could not get image size (hr = %x)\n", hr);
839 goto out;
841 data = HeapAlloc(GetProcessHeap(), 0, size);
842 info = (BITMAPINFO*)data;
843 IBasicVideo_GetCurrentImage(wma->vidbasic, &size, (LONG*)data);
844 data += info->bmiHeader.biSize;
846 IBasicVideo_GetSourcePosition(wma->vidbasic, &src.left, &src.top, &src.right, &src.bottom);
847 IBasicVideo_GetDestinationPosition(wma->vidbasic, &dest.left, &dest.top, &dest.right, &dest.bottom);
848 StretchDIBits(lpParms->hDC,
849 dest.left, dest.top, dest.right + dest.left, dest.bottom + dest.top,
850 src.left, src.top, src.right + src.left, src.bottom + src.top,
851 data, info, DIB_RGB_COLORS, SRCCOPY);
852 HeapFree(GetProcessHeap(), 0, data);
853 res = 0;
854 out:
855 if (wma->parent)
856 IVideoWindow_put_Visible(wma->vidwin, visible);
858 else if (dwFlags)
859 FIXME("Unhandled flags %x\n", dwFlags);
860 return res;
863 /***************************************************************************
864 * MCIQTZ_mciSetAudio [internal]
866 static DWORD MCIQTZ_mciSetAudio(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SETAUDIO_PARMSW lpParms)
868 WINE_MCIQTZ *wma;
870 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
872 if (!lpParms)
873 return MCIERR_NULL_PARAMETER_BLOCK;
875 wma = MCIQTZ_mciGetOpenDev(wDevID);
876 if (!wma)
877 return MCIERR_INVALID_DEVICE_ID;
879 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
881 return 0;
884 /*======================================================================*
885 * MCI QTZ entry points *
886 *======================================================================*/
888 /**************************************************************************
889 * DriverProc (MCIQTZ.@)
891 LRESULT CALLBACK MCIQTZ_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
892 LPARAM dwParam1, LPARAM dwParam2)
894 TRACE("(%08lX, %p, %08X, %08lX, %08lX)\n",
895 dwDevID, hDriv, wMsg, dwParam1, dwParam2);
897 switch (wMsg) {
898 case DRV_LOAD: return 1;
899 case DRV_FREE: return 1;
900 case DRV_OPEN: return MCIQTZ_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
901 case DRV_CLOSE: return MCIQTZ_drvClose(dwDevID);
902 case DRV_ENABLE: return 1;
903 case DRV_DISABLE: return 1;
904 case DRV_QUERYCONFIGURE: return 1;
905 case DRV_CONFIGURE: return MCIQTZ_drvConfigure(dwDevID);
906 case DRV_INSTALL: return DRVCNF_RESTART;
907 case DRV_REMOVE: return DRVCNF_RESTART;
910 /* session instance */
911 if (dwDevID == 0xFFFFFFFF)
912 return 1;
914 switch (wMsg) {
915 case MCI_OPEN_DRIVER: return MCIQTZ_mciOpen (dwDevID, dwParam1, (LPMCI_DGV_OPEN_PARMSW) dwParam2);
916 case MCI_CLOSE_DRIVER: return MCIQTZ_mciClose (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
917 case MCI_PLAY: return MCIQTZ_mciPlay (dwDevID, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
918 case MCI_SEEK: return MCIQTZ_mciSeek (dwDevID, dwParam1, (LPMCI_SEEK_PARMS) dwParam2);
919 case MCI_STOP: return MCIQTZ_mciStop (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
920 case MCI_PAUSE: return MCIQTZ_mciPause (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
921 case MCI_GETDEVCAPS: return MCIQTZ_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS) dwParam2);
922 case MCI_SET: return MCIQTZ_mciSet (dwDevID, dwParam1, (LPMCI_DGV_SET_PARMS) dwParam2);
923 case MCI_STATUS: return MCIQTZ_mciStatus (dwDevID, dwParam1, (LPMCI_DGV_STATUS_PARMSW) dwParam2);
924 case MCI_WHERE: return MCIQTZ_mciWhere (dwDevID, dwParam1, (LPMCI_DGV_RECT_PARMS) dwParam2);
925 /* Digital Video specific */
926 case MCI_SETAUDIO: return MCIQTZ_mciSetAudio (dwDevID, dwParam1, (LPMCI_DGV_SETAUDIO_PARMSW) dwParam2);
927 case MCI_UPDATE:
928 return MCIQTZ_mciUpdate(dwDevID, dwParam1, (LPMCI_DGV_UPDATE_PARMS)dwParam2);
929 case MCI_WINDOW:
930 return MCIQTZ_mciWindow(dwDevID, dwParam1, (LPMCI_DGV_WINDOW_PARMSW)dwParam2);
931 case MCI_PUT:
932 case MCI_RECORD:
933 case MCI_RESUME:
934 case MCI_INFO:
935 case MCI_LOAD:
936 case MCI_SAVE:
937 case MCI_FREEZE:
938 case MCI_REALIZE:
939 case MCI_UNFREEZE:
940 case MCI_STEP:
941 case MCI_COPY:
942 case MCI_CUT:
943 case MCI_DELETE:
944 case MCI_PASTE:
945 case MCI_CUE:
946 /* Digital Video specific */
947 case MCI_CAPTURE:
948 case MCI_MONITOR:
949 case MCI_RESERVE:
950 case MCI_SIGNAL:
951 case MCI_SETVIDEO:
952 case MCI_QUALITY:
953 case MCI_LIST:
954 case MCI_UNDO:
955 case MCI_CONFIGURE:
956 case MCI_RESTORE:
957 FIXME("Unimplemented command [%08X]\n", wMsg);
958 break;
959 case MCI_SPIN:
960 case MCI_ESCAPE:
961 WARN("Unsupported command [%08X]\n", wMsg);
962 break;
963 case MCI_OPEN:
964 case MCI_CLOSE:
965 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
966 break;
967 default:
968 TRACE("Sending msg [%08X] to default driver proc\n", wMsg);
969 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
972 return MCIERR_UNRECOGNIZED_COMMAND;