wineandroid: Use the user driver interface to create host desktops.
[wine.git] / dlls / mciqtz32 / mciqtz.c
blob6fb9c2f43b42d242fcf11d470163e8ac1cdc5106
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 <stdbool.h>
23 #include <math.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "mmddk.h"
28 #include "wine/debug.h"
29 #include "mciqtz_private.h"
30 #include "digitalv.h"
31 #include "wownt32.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mciqtz);
35 static const WCHAR mciqtz_class[] = L"MCIQTZ_Window";
37 static DWORD MCIQTZ_mciClose(UINT, DWORD, LPMCI_GENERIC_PARMS);
38 static DWORD MCIQTZ_mciStop(UINT, DWORD, LPMCI_GENERIC_PARMS);
40 /*======================================================================*
41 * MCI QTZ implementation *
42 *======================================================================*/
44 static HINSTANCE MCIQTZ_hInstance = 0;
46 /***********************************************************************
47 * DllMain (MCIQTZ.0)
49 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
51 switch (fdwReason) {
52 case DLL_PROCESS_ATTACH:
53 DisableThreadLibraryCalls(hInstDLL);
54 MCIQTZ_hInstance = hInstDLL;
55 break;
57 return TRUE;
60 /**************************************************************************
61 * MCIQTZ_mciGetOpenDev [internal]
63 static WINE_MCIQTZ* MCIQTZ_mciGetOpenDev(UINT wDevID)
65 WINE_MCIQTZ* wma = (WINE_MCIQTZ*)mciGetDriverData(wDevID);
67 if (!wma) {
68 WARN("Invalid wDevID=%u\n", wDevID);
69 return NULL;
71 return wma;
74 static void unregister_class(void)
76 UnregisterClassW(mciqtz_class, MCIQTZ_hInstance);
79 static bool register_class(void)
81 WNDCLASSW class = {0};
83 class.lpfnWndProc = DefWindowProcW;
84 class.cbWndExtra = sizeof(MCIDEVICEID);
85 class.hInstance = MCIQTZ_hInstance;
86 class.hCursor = LoadCursorW(0, (const WCHAR *)IDC_ARROW);
87 class.lpszClassName = mciqtz_class;
89 return RegisterClassW(&class) || GetLastError() == ERROR_CLASS_ALREADY_EXISTS;
92 /**************************************************************************
93 * MCIQTZ_drvOpen [internal]
95 static DWORD MCIQTZ_drvOpen(LPCWSTR str, LPMCI_OPEN_DRIVER_PARMSW modp)
97 WINE_MCIQTZ* wma;
99 TRACE("(%s, %p)\n", debugstr_w(str), modp);
101 /* session instance */
102 if (!modp)
103 return 0xFFFFFFFF;
105 if (!register_class())
106 return 0;
108 wma = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCIQTZ));
109 if (!wma)
110 return 0;
112 wma->stop_event = CreateEventW(NULL, FALSE, FALSE, NULL);
113 modp->wType = MCI_DEVTYPE_DIGITAL_VIDEO;
114 wma->wDevID = modp->wDeviceID;
115 modp->wCustomCommandTable = wma->command_table = mciLoadCommandResource(MCIQTZ_hInstance, L"MCIAVI", 0);
116 mciSetDriverData(wma->wDevID, (DWORD_PTR)wma);
118 return modp->wDeviceID;
121 /**************************************************************************
122 * MCIQTZ_drvClose [internal]
124 static DWORD MCIQTZ_drvClose(DWORD dwDevID)
126 WINE_MCIQTZ* wma;
128 TRACE("(%04lx)\n", dwDevID);
130 wma = MCIQTZ_mciGetOpenDev(dwDevID);
132 if (wma) {
133 /* finish all outstanding things */
134 MCIQTZ_mciClose(dwDevID, MCI_WAIT, NULL);
136 unregister_class();
137 mciFreeCommandResource(wma->command_table);
138 mciSetDriverData(dwDevID, 0);
139 CloseHandle(wma->stop_event);
140 HeapFree(GetProcessHeap(), 0, wma);
141 return 1;
144 return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
147 /**************************************************************************
148 * MCIQTZ_drvConfigure [internal]
150 static DWORD MCIQTZ_drvConfigure(DWORD dwDevID)
152 WINE_MCIQTZ* wma;
154 TRACE("(%04lx)\n", dwDevID);
156 wma = MCIQTZ_mciGetOpenDev(dwDevID);
157 if (!wma)
158 return 0;
160 MCIQTZ_mciStop(dwDevID, MCI_WAIT, NULL);
162 MessageBoxA(0, "Sample QTZ Wine Driver !", "MM-Wine Driver", MB_OK);
164 return 1;
167 static bool create_window(WINE_MCIQTZ *wma, DWORD flags, const MCI_DGV_OPEN_PARMSW *params)
169 DWORD style = (WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN) & ~WS_MAXIMIZEBOX;
170 LONG width, height, min_width;
171 HWND parent = NULL;
172 HRESULT hr;
173 RECT rc;
175 if (flags & MCI_DGV_OPEN_PARENT)
176 parent = params->hWndParent;
177 if (flags & MCI_DGV_OPEN_WS)
178 style = params->dwStyle;
180 hr = IBasicVideo_GetVideoSize(wma->vidbasic, &width, &height);
181 if (hr == E_NOINTERFACE)
182 return true; /* audio file */
183 else if (FAILED(hr))
185 ERR("Failed to get video size, hr %#lx.\n", hr);
186 return false;
189 /* Native always assumes an overlapped window
190 * when calculating default video window size. */
191 SetRect(&rc, 0, 0, width, height);
192 AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);
193 min_width = GetSystemMetrics(SM_CXMIN);
194 width = max(rc.right - rc.left, min_width);
195 height = rc.bottom - rc.top;
197 wma->window = CreateWindowW(mciqtz_class, params->lpstrElementName, style,
198 CW_USEDEFAULT, CW_USEDEFAULT, width, height, parent, NULL, MCIQTZ_hInstance, NULL);
200 TRACE("device %#x, flags %#lx, style %#lx, parent %p, dimensions %ldx%ld, created window %p.\n",
201 wma->wDevID, flags, style, parent, width, height, wma->window);
203 if (!wma->window)
205 ERR("Failed to create window, error %lu.\n", GetLastError());
206 return false;
209 IVideoWindow_put_AutoShow(wma->vidwin, OAFALSE);
210 IVideoWindow_put_MessageDrain(wma->vidwin, (OAHWND)wma->window);
211 IVideoWindow_put_Owner(wma->vidwin, (OAHWND)wma->window);
212 IVideoWindow_put_WindowStyle(wma->vidwin, WS_CHILD); /* reset window style */
214 if (style & (WS_POPUP | WS_CHILD))
215 IBasicVideo_GetVideoSize(wma->vidbasic, &width, &height);
216 else
218 GetClientRect(wma->window, &rc);
219 width = rc.right;
220 height = rc.bottom;
223 IVideoWindow_SetWindowPosition(wma->vidwin, 0, 0, width, height);
224 IVideoWindow_put_Visible(wma->vidwin, OATRUE);
225 wma->parent = wma->window;
227 return true;
230 /**************************************************************************
231 * MCIQTZ_mciNotify [internal]
233 * Notifications in MCI work like a 1-element queue.
234 * Each new notification request supersedes the previous one.
236 static void MCIQTZ_mciNotify(DWORD_PTR hWndCallBack, WINE_MCIQTZ* wma, UINT wStatus)
238 MCIDEVICEID wDevID = wma->notify_devid;
239 HANDLE old = InterlockedExchangePointer(&wma->callback, NULL);
240 if (old) mciDriverNotify(old, wDevID, MCI_NOTIFY_SUPERSEDED);
241 mciDriverNotify(HWND_32(LOWORD(hWndCallBack)), wDevID, wStatus);
244 /***************************************************************************
245 * MCIQTZ_mciOpen [internal]
247 static DWORD MCIQTZ_mciOpen(UINT wDevID, DWORD dwFlags,
248 LPMCI_DGV_OPEN_PARMSW lpOpenParms)
250 WINE_MCIQTZ* wma;
251 HRESULT hr;
253 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpOpenParms);
255 if(!lpOpenParms)
256 return MCIERR_NULL_PARAMETER_BLOCK;
258 wma = MCIQTZ_mciGetOpenDev(wDevID);
259 if (!wma)
260 return MCIERR_INVALID_DEVICE_ID;
262 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
264 hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
265 wma->uninit = SUCCEEDED(hr);
267 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&wma->pgraph);
268 if (FAILED(hr)) {
269 TRACE("Cannot create filtergraph (hr = %lx)\n", hr);
270 goto err;
273 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaControl, (LPVOID*)&wma->pmctrl);
274 if (FAILED(hr)) {
275 TRACE("Cannot get IMediaControl interface (hr = %lx)\n", hr);
276 goto err;
279 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaSeeking, (void**)&wma->seek);
280 if (FAILED(hr)) {
281 TRACE("Cannot get IMediaSeeking interface (hr = %lx)\n", hr);
282 goto err;
285 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaEvent, (void**)&wma->mevent);
286 if (FAILED(hr)) {
287 TRACE("Cannot get IMediaEvent interface (hr = %lx)\n", hr);
288 goto err;
291 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IVideoWindow, (void**)&wma->vidwin);
292 if (FAILED(hr)) {
293 TRACE("Cannot get IVideoWindow interface (hr = %lx)\n", hr);
294 goto err;
297 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IBasicVideo, (void**)&wma->vidbasic);
298 if (FAILED(hr)) {
299 TRACE("Cannot get IBasicVideo interface (hr = %lx)\n", hr);
300 goto err;
303 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IBasicAudio, (void**)&wma->audio);
304 if (FAILED(hr)) {
305 TRACE("Cannot get IBasicAudio interface (hr = %lx)\n", hr);
306 goto err;
309 if (!(dwFlags & MCI_OPEN_ELEMENT) || (dwFlags & MCI_OPEN_ELEMENT_ID)) {
310 TRACE("Wrong dwFlags %lx\n", dwFlags);
311 goto err;
314 if (!lpOpenParms->lpstrElementName || !lpOpenParms->lpstrElementName[0]) {
315 TRACE("Invalid filename specified\n");
316 goto err;
319 TRACE("Open file %s\n", debugstr_w(lpOpenParms->lpstrElementName));
321 hr = IGraphBuilder_RenderFile(wma->pgraph, lpOpenParms->lpstrElementName, NULL);
322 if (FAILED(hr)) {
323 TRACE("Cannot render file (hr = %lx)\n", hr);
324 goto err;
327 if (!create_window(wma, dwFlags, lpOpenParms))
328 goto err;
329 wma->opened = TRUE;
331 if (dwFlags & MCI_NOTIFY)
332 mciDriverNotify(HWND_32(LOWORD(lpOpenParms->dwCallback)), wDevID, MCI_NOTIFY_SUCCESSFUL);
334 return 0;
336 err:
337 if (wma->audio)
338 IBasicAudio_Release(wma->audio);
339 wma->audio = NULL;
340 if (wma->vidbasic)
341 IBasicVideo_Release(wma->vidbasic);
342 wma->vidbasic = NULL;
343 if (wma->seek)
344 IMediaSeeking_Release(wma->seek);
345 wma->seek = NULL;
346 if (wma->vidwin)
347 IVideoWindow_Release(wma->vidwin);
348 wma->vidwin = NULL;
349 if (wma->pgraph)
350 IGraphBuilder_Release(wma->pgraph);
351 wma->pgraph = NULL;
352 if (wma->mevent)
353 IMediaEvent_Release(wma->mevent);
354 wma->mevent = NULL;
355 if (wma->pmctrl)
356 IMediaControl_Release(wma->pmctrl);
357 wma->pmctrl = NULL;
359 if (wma->uninit)
360 CoUninitialize();
361 wma->uninit = FALSE;
363 return MCIERR_INTERNAL;
366 /***************************************************************************
367 * MCIQTZ_mciClose [internal]
369 static DWORD MCIQTZ_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
371 WINE_MCIQTZ* wma;
373 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
375 wma = MCIQTZ_mciGetOpenDev(wDevID);
376 if (!wma)
377 return MCIERR_INVALID_DEVICE_ID;
379 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
381 if (wma->opened) {
382 if (wma->window)
384 IVideoWindow_put_MessageDrain(wma->vidwin, (OAHWND)NULL);
385 IVideoWindow_put_Owner(wma->vidwin, (OAHWND)NULL);
386 DestroyWindow(wma->window);
387 wma->window = NULL;
389 IVideoWindow_Release(wma->vidwin);
390 IBasicVideo_Release(wma->vidbasic);
391 IBasicAudio_Release(wma->audio);
392 IMediaSeeking_Release(wma->seek);
393 IMediaEvent_Release(wma->mevent);
394 IGraphBuilder_Release(wma->pgraph);
395 IMediaControl_Release(wma->pmctrl);
396 if (wma->uninit)
397 CoUninitialize();
398 wma->opened = FALSE;
401 return 0;
404 /***************************************************************************
405 * MCIQTZ_notifyThread [internal]
407 static DWORD CALLBACK MCIQTZ_notifyThread(LPVOID parm)
409 WINE_MCIQTZ* wma = (WINE_MCIQTZ *)parm;
410 HRESULT hr;
411 HANDLE handle[2];
412 DWORD n = 0, ret = 0;
414 handle[n++] = wma->stop_event;
415 IMediaEvent_GetEventHandle(wma->mevent, (OAEVENT *)&handle[n++]);
417 for (;;) {
418 DWORD r;
419 HANDLE old;
421 r = WaitForMultipleObjects(n, handle, FALSE, INFINITE);
422 if (r == WAIT_OBJECT_0) {
423 TRACE("got stop event\n");
424 old = InterlockedExchangePointer(&wma->callback, NULL);
425 if (old)
426 mciDriverNotify(old, wma->notify_devid, MCI_NOTIFY_ABORTED);
427 break;
429 else if (r == WAIT_OBJECT_0+1) {
430 LONG event_code;
431 LONG_PTR p1, p2;
432 do {
433 hr = IMediaEvent_GetEvent(wma->mevent, &event_code, &p1, &p2, 0);
434 if (SUCCEEDED(hr)) {
435 TRACE("got event_code = 0x%02lx\n", event_code);
436 IMediaEvent_FreeEventParams(wma->mevent, event_code, p1, p2);
438 } while (hr == S_OK && event_code != EC_COMPLETE);
439 if (hr == S_OK && event_code == EC_COMPLETE) {
440 /* Repeat the music by seeking and running again */
441 if (wma->mci_flags & MCI_DGV_PLAY_REPEAT) {
442 TRACE("repeat media as requested\n");
443 IMediaControl_Stop(wma->pmctrl);
444 IMediaSeeking_SetPositions(wma->seek,
445 &wma->seek_start,
446 AM_SEEKING_AbsolutePositioning,
447 &wma->seek_stop,
448 AM_SEEKING_AbsolutePositioning);
449 IMediaControl_Run(wma->pmctrl);
450 continue;
452 old = InterlockedExchangePointer(&wma->callback, NULL);
453 if (old)
454 mciDriverNotify(old, wma->notify_devid, MCI_NOTIFY_SUCCESSFUL);
455 break;
458 else {
459 TRACE("Unknown error (%d)\n", (int)r);
460 break;
464 hr = IMediaControl_Stop(wma->pmctrl);
465 if (FAILED(hr)) {
466 TRACE("Cannot stop filtergraph (hr = %lx)\n", hr);
467 ret = MCIERR_INTERNAL;
470 return ret;
473 /***************************************************************************
474 * MCIQTZ_mciPlay [internal]
476 static DWORD MCIQTZ_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
478 WINE_MCIQTZ* wma;
479 HRESULT hr;
480 GUID format;
481 DWORD start_flags;
483 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
485 if(!lpParms)
486 return MCIERR_NULL_PARAMETER_BLOCK;
488 wma = MCIQTZ_mciGetOpenDev(wDevID);
489 if (!wma)
490 return MCIERR_INVALID_DEVICE_ID;
492 ResetEvent(wma->stop_event);
493 if (dwFlags & MCI_NOTIFY) {
494 HANDLE old;
495 old = InterlockedExchangePointer(&wma->callback, HWND_32(LOWORD(lpParms->dwCallback)));
496 if (old)
497 mciDriverNotify(old, wma->notify_devid, MCI_NOTIFY_ABORTED);
500 wma->mci_flags = dwFlags;
501 IMediaSeeking_GetTimeFormat(wma->seek, &format);
502 if (dwFlags & MCI_FROM) {
503 wma->seek_start = lpParms->dwFrom;
504 if (IsEqualGUID(&format, &TIME_FORMAT_MEDIA_TIME))
505 wma->seek_start *= 10000;
507 start_flags = AM_SEEKING_AbsolutePositioning;
508 } else {
509 wma->seek_start = 0;
510 start_flags = AM_SEEKING_NoPositioning;
512 if (dwFlags & MCI_TO) {
513 wma->seek_stop = lpParms->dwTo;
514 if (IsEqualGUID(&format, &TIME_FORMAT_MEDIA_TIME))
515 wma->seek_stop *= 10000;
516 } else {
517 wma->seek_stop = 0;
518 IMediaSeeking_GetDuration(wma->seek, &wma->seek_stop);
520 IMediaSeeking_SetPositions(wma->seek, &wma->seek_start, start_flags,
521 &wma->seek_stop, AM_SEEKING_AbsolutePositioning);
523 hr = IMediaControl_Run(wma->pmctrl);
524 if (FAILED(hr)) {
525 TRACE("Cannot run filtergraph (hr = %lx)\n", hr);
526 return MCIERR_INTERNAL;
529 if (wma->parent)
530 ShowWindow(wma->parent, SW_SHOW);
532 if (!wma->thread)
534 wma->thread = CreateThread(NULL, 0, MCIQTZ_notifyThread, wma, 0, NULL);
535 if (!wma->thread) {
536 TRACE("Can't create thread\n");
537 return MCIERR_INTERNAL;
540 return 0;
543 /***************************************************************************
544 * MCIQTZ_mciSeek [internal]
546 static DWORD MCIQTZ_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
548 WINE_MCIQTZ* wma;
549 HRESULT hr;
550 LONGLONG newpos;
552 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
554 if(!lpParms)
555 return MCIERR_NULL_PARAMETER_BLOCK;
557 wma = MCIQTZ_mciGetOpenDev(wDevID);
558 if (!wma)
559 return MCIERR_INVALID_DEVICE_ID;
561 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
563 if (dwFlags & MCI_SEEK_TO_START) {
564 newpos = 0;
565 } else if (dwFlags & MCI_SEEK_TO_END) {
566 FIXME("MCI_SEEK_TO_END not implemented yet\n");
567 return MCIERR_INTERNAL;
568 } else if (dwFlags & MCI_TO) {
569 FIXME("MCI_TO not implemented yet\n");
570 return MCIERR_INTERNAL;
571 } else {
572 WARN("dwFlag doesn't tell where to seek to...\n");
573 return MCIERR_MISSING_PARAMETER;
576 hr = IMediaSeeking_SetPositions(wma->seek, &newpos, AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
577 if (FAILED(hr)) {
578 FIXME("Cannot set position (hr = %lx)\n", hr);
579 return MCIERR_INTERNAL;
582 if (dwFlags & MCI_NOTIFY)
583 MCIQTZ_mciNotify(lpParms->dwCallback, wma, MCI_NOTIFY_SUCCESSFUL);
585 return 0;
588 /***************************************************************************
589 * MCIQTZ_mciStop [internal]
591 static DWORD MCIQTZ_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
593 WINE_MCIQTZ* wma;
595 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
597 wma = MCIQTZ_mciGetOpenDev(wDevID);
598 if (!wma)
599 return MCIERR_INVALID_DEVICE_ID;
601 if (!wma->opened)
602 return 0;
604 if (wma->thread) {
605 SetEvent(wma->stop_event);
606 WaitForSingleObject(wma->thread, INFINITE);
607 CloseHandle(wma->thread);
608 wma->thread = NULL;
611 return 0;
614 /***************************************************************************
615 * MCIQTZ_mciPause [internal]
617 static DWORD MCIQTZ_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
619 WINE_MCIQTZ* wma;
620 HRESULT hr;
622 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
624 wma = MCIQTZ_mciGetOpenDev(wDevID);
625 if (!wma)
626 return MCIERR_INVALID_DEVICE_ID;
628 hr = IMediaControl_Pause(wma->pmctrl);
629 if (FAILED(hr)) {
630 TRACE("Cannot pause filtergraph (hr = %lx)\n", hr);
631 return MCIERR_INTERNAL;
634 return 0;
637 /***************************************************************************
638 * MCIQTZ_mciResume [internal]
640 static DWORD MCIQTZ_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
642 WINE_MCIQTZ* wma;
643 HRESULT hr;
645 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
647 wma = MCIQTZ_mciGetOpenDev(wDevID);
648 if (!wma)
649 return MCIERR_INVALID_DEVICE_ID;
651 hr = IMediaControl_Run(wma->pmctrl);
652 if (FAILED(hr)) {
653 TRACE("Cannot run filtergraph (hr = %lx)\n", hr);
654 return MCIERR_INTERNAL;
657 return 0;
660 /***************************************************************************
661 * MCIQTZ_mciGetDevCaps [internal]
663 static DWORD MCIQTZ_mciGetDevCaps(UINT wDevID, DWORD dwFlags, LPMCI_GETDEVCAPS_PARMS lpParms)
665 WINE_MCIQTZ* wma;
667 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
669 if(!lpParms)
670 return MCIERR_NULL_PARAMETER_BLOCK;
672 wma = MCIQTZ_mciGetOpenDev(wDevID);
673 if (!wma)
674 return MCIERR_INVALID_DEVICE_ID;
676 if (!(dwFlags & MCI_GETDEVCAPS_ITEM))
677 return MCIERR_MISSING_PARAMETER;
679 switch (lpParms->dwItem) {
680 case MCI_GETDEVCAPS_CAN_RECORD:
681 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
682 TRACE("MCI_GETDEVCAPS_CAN_RECORD = %08lx\n", lpParms->dwReturn);
683 break;
684 case MCI_GETDEVCAPS_HAS_AUDIO:
685 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
686 TRACE("MCI_GETDEVCAPS_HAS_AUDIO = %08lx\n", lpParms->dwReturn);
687 break;
688 case MCI_GETDEVCAPS_HAS_VIDEO:
689 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
690 TRACE("MCI_GETDEVCAPS_HAS_VIDEO = %08lx\n", lpParms->dwReturn);
691 break;
692 case MCI_GETDEVCAPS_DEVICE_TYPE:
693 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_DEVTYPE_DIGITAL_VIDEO, MCI_DEVTYPE_DIGITAL_VIDEO);
694 TRACE("MCI_GETDEVCAPS_DEVICE_TYPE = %08lx\n", lpParms->dwReturn);
695 break;
696 case MCI_GETDEVCAPS_USES_FILES:
697 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
698 TRACE("MCI_GETDEVCAPS_USES_FILES = %08lx\n", lpParms->dwReturn);
699 break;
700 case MCI_GETDEVCAPS_COMPOUND_DEVICE:
701 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
702 TRACE("MCI_GETDEVCAPS_COMPOUND_DEVICE = %08lx\n", lpParms->dwReturn);
703 break;
704 case MCI_GETDEVCAPS_CAN_EJECT:
705 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
706 TRACE("MCI_GETDEVCAPS_EJECT = %08lx\n", lpParms->dwReturn);
707 break;
708 case MCI_GETDEVCAPS_CAN_PLAY:
709 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
710 TRACE("MCI_GETDEVCAPS_CAN_PLAY = %08lx\n", lpParms->dwReturn);
711 break;
712 case MCI_GETDEVCAPS_CAN_SAVE:
713 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
714 TRACE("MCI_GETDEVCAPS_CAN_SAVE = %08lx\n", lpParms->dwReturn);
715 break;
716 case MCI_DGV_GETDEVCAPS_CAN_REVERSE:
717 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
718 TRACE("MCI_DGV_GETDEVCAPS_CAN_REVERSE = %08lx\n", lpParms->dwReturn);
719 break;
720 case MCI_DGV_GETDEVCAPS_CAN_STRETCH:
721 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE); /* FIXME */
722 TRACE("MCI_DGV_GETDEVCAPS_CAN_STRETCH = %08lx\n", lpParms->dwReturn);
723 break;
724 case MCI_DGV_GETDEVCAPS_CAN_LOCK:
725 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
726 TRACE("MCI_DGV_GETDEVCAPS_CAN_LOCK = %08lx\n", lpParms->dwReturn);
727 break;
728 case MCI_DGV_GETDEVCAPS_CAN_FREEZE:
729 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
730 TRACE("MCI_DGV_GETDEVCAPS_CAN_FREEZE = %08lx\n", lpParms->dwReturn);
731 break;
732 case MCI_DGV_GETDEVCAPS_CAN_STR_IN:
733 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
734 TRACE("MCI_DGV_GETDEVCAPS_CAN_STRETCH_INPUT = %08lx\n", lpParms->dwReturn);
735 break;
736 case MCI_DGV_GETDEVCAPS_HAS_STILL:
737 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
738 TRACE("MCI_DGV_GETDEVCAPS_HAS_STILL = %08lx\n", lpParms->dwReturn);
739 break;
740 case MCI_DGV_GETDEVCAPS_CAN_TEST:
741 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE); /* FIXME */
742 TRACE("MCI_DGV_GETDEVCAPS_CAN_TEST = %08lx\n", lpParms->dwReturn);
743 break;
744 case MCI_DGV_GETDEVCAPS_MAX_WINDOWS:
745 lpParms->dwReturn = 1;
746 TRACE("MCI_DGV_GETDEVCAPS_MAX_WINDOWS = %lu\n", lpParms->dwReturn);
747 return 0;
748 default:
749 WARN("Unknown capability %08lx\n", lpParms->dwItem);
750 /* Fall through */
751 case MCI_DGV_GETDEVCAPS_MAXIMUM_RATE: /* unknown to w2k */
752 case MCI_DGV_GETDEVCAPS_MINIMUM_RATE: /* unknown to w2k */
753 return MCIERR_UNSUPPORTED_FUNCTION;
756 return MCI_RESOURCE_RETURNED;
759 /***************************************************************************
760 * MCIQTZ_mciSet [internal]
762 static DWORD MCIQTZ_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SET_PARMS lpParms)
764 WINE_MCIQTZ* wma;
766 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
768 if(!lpParms)
769 return MCIERR_NULL_PARAMETER_BLOCK;
771 wma = MCIQTZ_mciGetOpenDev(wDevID);
772 if (!wma)
773 return MCIERR_INVALID_DEVICE_ID;
775 if (dwFlags & MCI_SET_TIME_FORMAT) {
776 switch (lpParms->dwTimeFormat) {
777 case MCI_FORMAT_MILLISECONDS:
778 TRACE("MCI_SET_TIME_FORMAT = MCI_FORMAT_MILLISECONDS\n");
779 wma->time_format = MCI_FORMAT_MILLISECONDS;
780 break;
781 case MCI_FORMAT_FRAMES:
782 TRACE("MCI_SET_TIME_FORMAT = MCI_FORMAT_FRAMES\n");
783 wma->time_format = MCI_FORMAT_FRAMES;
784 break;
785 default:
786 WARN("Bad time format %lu\n", lpParms->dwTimeFormat);
787 return MCIERR_BAD_TIME_FORMAT;
791 if (dwFlags & MCI_SET_DOOR_OPEN)
792 FIXME("MCI_SET_DOOR_OPEN not implemented yet\n");
793 if (dwFlags & MCI_SET_DOOR_CLOSED)
794 FIXME("MCI_SET_DOOR_CLOSED not implemented yet\n");
795 if (dwFlags & MCI_SET_AUDIO)
796 FIXME("MCI_SET_AUDIO not implemented yet\n");
797 if (dwFlags & MCI_SET_VIDEO)
798 FIXME("MCI_SET_VIDEO not implemented yet\n");
799 if (dwFlags & MCI_SET_ON)
800 FIXME("MCI_SET_ON not implemented yet\n");
801 if (dwFlags & MCI_SET_OFF)
802 FIXME("MCI_SET_OFF not implemented yet\n");
803 if (dwFlags & MCI_SET_AUDIO_LEFT)
804 FIXME("MCI_SET_AUDIO_LEFT not implemented yet\n");
805 if (dwFlags & MCI_SET_AUDIO_RIGHT)
806 FIXME("MCI_SET_AUDIO_RIGHT not implemented yet\n");
808 if (dwFlags & ~0x7f03 /* All MCI_SET flags mask */)
809 ERR("Unknown flags %08lx\n", dwFlags & ~0x7f03);
811 return 0;
814 /***************************************************************************
815 * MCIQTZ_mciStatus [internal]
817 static DWORD MCIQTZ_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_DGV_STATUS_PARMSW lpParms)
819 WINE_MCIQTZ* wma;
820 HRESULT hr;
821 DWORD ret = MCI_INTEGER_RETURNED;
823 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
825 if(!lpParms)
826 return MCIERR_NULL_PARAMETER_BLOCK;
828 wma = MCIQTZ_mciGetOpenDev(wDevID);
829 if (!wma)
830 return MCIERR_INVALID_DEVICE_ID;
832 if (!(dwFlags & MCI_STATUS_ITEM)) {
833 WARN("No status item specified\n");
834 return MCIERR_UNRECOGNIZED_COMMAND;
837 switch (lpParms->dwItem) {
838 case MCI_STATUS_LENGTH: {
839 LONGLONG duration = -1;
840 GUID format;
841 switch (wma->time_format) {
842 case MCI_FORMAT_MILLISECONDS: format = TIME_FORMAT_MEDIA_TIME; break;
843 case MCI_FORMAT_FRAMES: format = TIME_FORMAT_FRAME; break;
844 default: ERR("Unhandled format %lx\n", wma->time_format); break;
846 hr = IMediaSeeking_SetTimeFormat(wma->seek, &format);
847 if (FAILED(hr)) {
848 FIXME("Cannot set time format (hr = %lx)\n", hr);
849 lpParms->dwReturn = 0;
850 break;
852 hr = IMediaSeeking_GetDuration(wma->seek, &duration);
853 if (FAILED(hr) || duration < 0) {
854 FIXME("Cannot read duration (hr = %lx)\n", hr);
855 lpParms->dwReturn = 0;
856 } else if (wma->time_format != MCI_FORMAT_MILLISECONDS)
857 lpParms->dwReturn = duration;
858 else
859 lpParms->dwReturn = duration / 10000;
860 break;
862 case MCI_STATUS_POSITION: {
863 REFERENCE_TIME curpos;
865 hr = IMediaSeeking_GetCurrentPosition(wma->seek, &curpos);
866 if (FAILED(hr)) {
867 FIXME("Cannot get position (hr = %lx)\n", hr);
868 return MCIERR_INTERNAL;
870 lpParms->dwReturn = curpos / 10000;
871 break;
873 case MCI_STATUS_NUMBER_OF_TRACKS:
874 FIXME("MCI_STATUS_NUMBER_OF_TRACKS not implemented yet\n");
875 return MCIERR_UNRECOGNIZED_COMMAND;
876 case MCI_STATUS_MODE: {
877 LONG state = State_Stopped;
878 IMediaControl_GetState(wma->pmctrl, -1, &state);
879 if (state == State_Stopped)
880 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_MODE_STOP, MCI_MODE_STOP);
881 else if (state == State_Running) {
882 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_MODE_PLAY, MCI_MODE_PLAY);
883 if (!wma->thread || WaitForSingleObject(wma->thread, 0) == WAIT_OBJECT_0)
884 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_MODE_STOP, MCI_MODE_STOP);
885 } else if (state == State_Paused)
886 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_MODE_PAUSE, MCI_MODE_PAUSE);
887 ret = MCI_RESOURCE_RETURNED;
888 break;
890 case MCI_STATUS_MEDIA_PRESENT:
891 FIXME("MCI_STATUS_MEDIA_PRESENT not implemented yet\n");
892 return MCIERR_UNRECOGNIZED_COMMAND;
893 case MCI_STATUS_TIME_FORMAT:
894 lpParms->dwReturn = MAKEMCIRESOURCE(wma->time_format,
895 MCI_FORMAT_RETURN_BASE + wma->time_format);
896 ret = MCI_RESOURCE_RETURNED;
897 break;
898 case MCI_STATUS_READY:
899 FIXME("MCI_STATUS_READY not implemented yet\n");
900 return MCIERR_UNRECOGNIZED_COMMAND;
901 case MCI_STATUS_CURRENT_TRACK:
902 FIXME("MCI_STATUS_CURRENT_TRACK not implemented yet\n");
903 return MCIERR_UNRECOGNIZED_COMMAND;
904 default:
905 FIXME("Unknown command %08lX\n", lpParms->dwItem);
906 return MCIERR_UNRECOGNIZED_COMMAND;
909 if (dwFlags & MCI_NOTIFY)
910 MCIQTZ_mciNotify(lpParms->dwCallback, wma, MCI_NOTIFY_SUCCESSFUL);
912 return ret;
915 /***************************************************************************
916 * MCIQTZ_mciWhere [internal]
918 static DWORD MCIQTZ_mciWhere(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
920 WINE_MCIQTZ* wma;
921 HRESULT hr;
922 HWND hWnd;
923 RECT rc;
924 DWORD ret = MCIERR_UNRECOGNIZED_COMMAND;
926 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
928 if(!lpParms)
929 return MCIERR_NULL_PARAMETER_BLOCK;
931 wma = MCIQTZ_mciGetOpenDev(wDevID);
932 if (!wma)
933 return MCIERR_INVALID_DEVICE_ID;
935 hr = IVideoWindow_get_Owner(wma->vidwin, (OAHWND*)&hWnd);
936 if (FAILED(hr)) {
937 TRACE("No video stream, returning no window error\n");
938 return MCIERR_NO_WINDOW;
941 if (dwFlags & MCI_DGV_WHERE_SOURCE) {
942 if (dwFlags & MCI_DGV_WHERE_MAX)
943 FIXME("MCI_DGV_WHERE_SOURCE_MAX stub\n");
944 IBasicVideo_GetSourcePosition(wma->vidbasic, &rc.left, &rc.top, &rc.right, &rc.bottom);
945 TRACE("MCI_DGV_WHERE_SOURCE %s\n", wine_dbgstr_rect(&rc));
947 if (dwFlags & MCI_DGV_WHERE_DESTINATION) {
948 if (dwFlags & MCI_DGV_WHERE_MAX)
949 FIXME("MCI_DGV_WHERE_DESTINATION_MAX stub\n");
950 IBasicVideo_GetDestinationPosition(wma->vidbasic, &rc.left, &rc.top, &rc.right, &rc.bottom);
951 TRACE("MCI_DGV_WHERE_DESTINATION %s\n", wine_dbgstr_rect(&rc));
953 if (dwFlags & MCI_DGV_WHERE_FRAME) {
954 if (dwFlags & MCI_DGV_WHERE_MAX)
955 FIXME("MCI_DGV_WHERE_FRAME_MAX not supported yet\n");
956 else
957 FIXME("MCI_DGV_WHERE_FRAME not supported yet\n");
958 goto out;
960 if (dwFlags & MCI_DGV_WHERE_VIDEO) {
961 if (dwFlags & MCI_DGV_WHERE_MAX)
962 FIXME("MCI_DGV_WHERE_VIDEO_MAX not supported yet\n");
963 else
964 FIXME("MCI_DGV_WHERE_VIDEO not supported yet\n");
965 goto out;
967 if (dwFlags & MCI_DGV_WHERE_WINDOW) {
968 if (dwFlags & MCI_DGV_WHERE_MAX) {
969 GetWindowRect(GetDesktopWindow(), &rc);
970 rc.right -= rc.left;
971 rc.bottom -= rc.top;
972 TRACE("MCI_DGV_WHERE_WINDOW_MAX %s\n", wine_dbgstr_rect(&rc));
973 } else {
974 GetWindowRect(wma->parent, &rc);
975 rc.right -= rc.left;
976 rc.bottom -= rc.top;
977 TRACE("MCI_DGV_WHERE_WINDOW %s\n", wine_dbgstr_rect(&rc));
980 ret = 0;
981 out:
982 lpParms->rc = rc;
983 return ret;
986 /***************************************************************************
987 * MCIQTZ_mciWindow [internal]
989 static DWORD MCIQTZ_mciWindow(UINT wDevID, DWORD dwFlags, LPMCI_DGV_WINDOW_PARMSW lpParms)
991 WINE_MCIQTZ *wma = MCIQTZ_mciGetOpenDev(wDevID);
993 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
995 if(!lpParms)
996 return MCIERR_NULL_PARAMETER_BLOCK;
998 if (!wma)
999 return MCIERR_INVALID_DEVICE_ID;
1000 if (dwFlags & MCI_TEST)
1001 return 0;
1003 if (dwFlags & MCI_DGV_WINDOW_HWND) {
1004 HWND hwnd;
1005 if (lpParms->hWnd && !IsWindow(lpParms->hWnd))
1006 return MCIERR_NO_WINDOW;
1007 if (!wma->parent)
1008 return MCIERR_INTERNAL;
1009 hwnd = lpParms->hWnd ? lpParms->hWnd : wma->window;
1010 TRACE("Setting parent window to %p.\n", hwnd);
1011 if (wma->parent != hwnd)
1013 LONG width, height;
1015 IVideoWindow_put_MessageDrain(wma->vidwin, (OAHWND)hwnd);
1016 IVideoWindow_put_Owner(wma->vidwin, (OAHWND)hwnd);
1018 IBasicVideo_GetVideoSize(wma->vidbasic, &width, &height);
1019 IVideoWindow_SetWindowPosition(wma->vidwin, 0, 0, width, height);
1021 if (wma->parent == wma->window)
1022 ShowWindow(wma->window, SW_HIDE);
1023 else if (hwnd == wma->window)
1024 ShowWindow(wma->window, SW_SHOW);
1026 wma->parent = hwnd;
1029 if (dwFlags & MCI_DGV_WINDOW_STATE) {
1030 if (!wma->parent)
1031 return MCIERR_NO_WINDOW;
1032 TRACE("Setting nCmdShow to %d\n", lpParms->nCmdShow);
1033 ShowWindow(wma->parent, lpParms->nCmdShow);
1035 if (dwFlags & MCI_DGV_WINDOW_TEXT) {
1036 if (!wma->parent)
1037 return MCIERR_NO_WINDOW;
1038 TRACE("Setting caption to %s\n", debugstr_w(lpParms->lpstrText));
1039 SetWindowTextW(wma->parent, lpParms->lpstrText);
1041 return 0;
1044 /***************************************************************************
1045 * MCIQTZ_mciPut [internal]
1047 static DWORD MCIQTZ_mciPut(UINT wDevID, DWORD dwFlags, MCI_GENERIC_PARMS *lpParms)
1049 WINE_MCIQTZ *wma = MCIQTZ_mciGetOpenDev(wDevID);
1050 MCI_DGV_RECT_PARMS *rectparms;
1051 HRESULT hr;
1053 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
1055 if(!lpParms)
1056 return MCIERR_NULL_PARAMETER_BLOCK;
1058 if (!wma)
1059 return MCIERR_INVALID_DEVICE_ID;
1061 if (!(dwFlags & MCI_DGV_RECT)) {
1062 FIXME("No support for non-RECT MCI_PUT\n");
1063 return 1;
1066 if (dwFlags & MCI_TEST)
1067 return 0;
1069 dwFlags &= ~MCI_DGV_RECT;
1070 rectparms = (MCI_DGV_RECT_PARMS*)lpParms;
1072 if (dwFlags & MCI_DGV_PUT_DESTINATION) {
1073 hr = IVideoWindow_SetWindowPosition(wma->vidwin,
1074 rectparms->rc.left, rectparms->rc.top,
1075 rectparms->rc.right - rectparms->rc.left,
1076 rectparms->rc.bottom - rectparms->rc.top);
1077 if(FAILED(hr))
1078 WARN("IVideoWindow_SetWindowPosition failed: 0x%lx\n", hr);
1080 dwFlags &= ~MCI_DGV_PUT_DESTINATION;
1083 if (dwFlags & MCI_NOTIFY) {
1084 MCIQTZ_mciNotify(lpParms->dwCallback, wma, MCI_NOTIFY_SUCCESSFUL);
1085 dwFlags &= ~MCI_NOTIFY;
1088 if (dwFlags)
1089 FIXME("No support for some flags: 0x%lx\n", dwFlags);
1091 return 0;
1094 /******************************************************************************
1095 * MCIAVI_mciUpdate [internal]
1097 static DWORD MCIQTZ_mciUpdate(UINT wDevID, DWORD dwFlags, LPMCI_DGV_UPDATE_PARMS lpParms)
1099 WINE_MCIQTZ *wma;
1100 DWORD res = 0;
1102 TRACE("%04x, %08lx, %p\n", wDevID, dwFlags, lpParms);
1104 if(!lpParms)
1105 return MCIERR_NULL_PARAMETER_BLOCK;
1107 wma = MCIQTZ_mciGetOpenDev(wDevID);
1108 if (!wma)
1109 return MCIERR_INVALID_DEVICE_ID;
1111 if (dwFlags & MCI_DGV_UPDATE_HDC) {
1112 LONG state, size;
1113 BYTE *data;
1114 BITMAPINFO *info;
1115 HRESULT hr;
1116 RECT src, dest;
1117 LONG visible = OATRUE;
1119 res = MCIERR_INTERNAL;
1120 IMediaControl_GetState(wma->pmctrl, -1, &state);
1121 if (state == State_Running)
1122 return MCIERR_UNSUPPORTED_FUNCTION;
1123 /* If in stopped state, nothing has been drawn to screen
1124 * moving to pause, which is needed for the old dib renderer, will result
1125 * in a single frame drawn, so hide the window here */
1126 IVideoWindow_get_Visible(wma->vidwin, &visible);
1127 if (wma->parent)
1128 IVideoWindow_put_Visible(wma->vidwin, OAFALSE);
1129 /* FIXME: Should we check the original state and restore it? */
1130 IMediaControl_Pause(wma->pmctrl);
1131 IMediaControl_GetState(wma->pmctrl, -1, &state);
1132 if (FAILED(hr = IBasicVideo_GetCurrentImage(wma->vidbasic, &size, NULL))) {
1133 WARN("Could not get image size (hr = %lx)\n", hr);
1134 goto out;
1136 data = HeapAlloc(GetProcessHeap(), 0, size);
1137 info = (BITMAPINFO*)data;
1138 IBasicVideo_GetCurrentImage(wma->vidbasic, &size, (LONG*)data);
1139 data += info->bmiHeader.biSize;
1141 IBasicVideo_GetSourcePosition(wma->vidbasic, &src.left, &src.top, &src.right, &src.bottom);
1142 IBasicVideo_GetDestinationPosition(wma->vidbasic, &dest.left, &dest.top, &dest.right, &dest.bottom);
1143 StretchDIBits(lpParms->hDC,
1144 dest.left, dest.top, dest.right + dest.left, dest.bottom + dest.top,
1145 src.left, src.top, src.right + src.left, src.bottom + src.top,
1146 data, info, DIB_RGB_COLORS, SRCCOPY);
1147 HeapFree(GetProcessHeap(), 0, data);
1148 res = 0;
1149 out:
1150 if (wma->parent)
1151 IVideoWindow_put_Visible(wma->vidwin, visible);
1153 else if (dwFlags)
1154 FIXME("Unhandled flags %lx\n", dwFlags);
1155 return res;
1158 /***************************************************************************
1159 * MCIQTZ_mciSetAudio [internal]
1161 static DWORD MCIQTZ_mciSetAudio(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SETAUDIO_PARMSW lpParms)
1163 WINE_MCIQTZ *wma;
1164 DWORD ret = 0;
1166 TRACE("(%04x, %08lx, %p)\n", wDevID, dwFlags, lpParms);
1168 if(!lpParms)
1169 return MCIERR_NULL_PARAMETER_BLOCK;
1171 wma = MCIQTZ_mciGetOpenDev(wDevID);
1172 if (!wma)
1173 return MCIERR_INVALID_DEVICE_ID;
1175 if (!(dwFlags & MCI_DGV_SETAUDIO_ITEM)) {
1176 FIXME("Unknown flags (%08lx)\n", dwFlags);
1177 return 0;
1180 if (dwFlags & MCI_DGV_SETAUDIO_ITEM) {
1181 switch (lpParms->dwItem) {
1182 case MCI_DGV_SETAUDIO_VOLUME:
1183 if (dwFlags & MCI_DGV_SETAUDIO_VALUE) {
1184 long vol;
1185 HRESULT hr;
1186 if (lpParms->dwValue > 1000) {
1187 ret = MCIERR_OUTOFRANGE;
1188 break;
1190 if (dwFlags & MCI_TEST)
1191 break;
1192 if (lpParms->dwValue != 0)
1193 vol = (long)(2000.0 * (log10(lpParms->dwValue) - 3.0));
1194 else
1195 vol = -10000;
1196 TRACE("Setting volume to %ld\n", vol);
1197 hr = IBasicAudio_put_Volume(wma->audio, vol);
1198 if (FAILED(hr)) {
1199 WARN("Cannot set volume (hr = %lx)\n", hr);
1200 ret = MCIERR_INTERNAL;
1203 break;
1204 default:
1205 FIXME("Unknown item %08lx\n", lpParms->dwItem);
1206 break;
1210 return ret;
1213 /*======================================================================*
1214 * MCI QTZ entry points *
1215 *======================================================================*/
1217 /**************************************************************************
1218 * DriverProc (MCIQTZ.@)
1220 LRESULT CALLBACK MCIQTZ_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
1221 LPARAM dwParam1, LPARAM dwParam2)
1223 TRACE("(%08IX, %p, %08X, %08IX, %08IX)\n",
1224 dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1226 switch (wMsg) {
1227 case DRV_LOAD: return 1;
1228 case DRV_FREE: return 1;
1229 case DRV_OPEN: return MCIQTZ_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
1230 case DRV_CLOSE: return MCIQTZ_drvClose(dwDevID);
1231 case DRV_ENABLE: return 1;
1232 case DRV_DISABLE: return 1;
1233 case DRV_QUERYCONFIGURE: return 1;
1234 case DRV_CONFIGURE: return MCIQTZ_drvConfigure(dwDevID);
1235 case DRV_INSTALL: return DRVCNF_RESTART;
1236 case DRV_REMOVE: return DRVCNF_RESTART;
1239 /* session instance */
1240 if (dwDevID == 0xFFFFFFFF)
1241 return 1;
1243 switch (wMsg) {
1244 case MCI_OPEN_DRIVER: return MCIQTZ_mciOpen (dwDevID, dwParam1, (LPMCI_DGV_OPEN_PARMSW) dwParam2);
1245 case MCI_CLOSE_DRIVER: return MCIQTZ_mciClose (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1246 case MCI_PLAY: return MCIQTZ_mciPlay (dwDevID, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
1247 case MCI_SEEK: return MCIQTZ_mciSeek (dwDevID, dwParam1, (LPMCI_SEEK_PARMS) dwParam2);
1248 case MCI_STOP: return MCIQTZ_mciStop (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1249 case MCI_PAUSE: return MCIQTZ_mciPause (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1250 case MCI_RESUME: return MCIQTZ_mciResume (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1251 case MCI_GETDEVCAPS: return MCIQTZ_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS) dwParam2);
1252 case MCI_SET: return MCIQTZ_mciSet (dwDevID, dwParam1, (LPMCI_DGV_SET_PARMS) dwParam2);
1253 case MCI_STATUS: return MCIQTZ_mciStatus (dwDevID, dwParam1, (LPMCI_DGV_STATUS_PARMSW) dwParam2);
1254 case MCI_WHERE: return MCIQTZ_mciWhere (dwDevID, dwParam1, (LPMCI_DGV_RECT_PARMS) dwParam2);
1255 /* Digital Video specific */
1256 case MCI_SETAUDIO: return MCIQTZ_mciSetAudio (dwDevID, dwParam1, (LPMCI_DGV_SETAUDIO_PARMSW) dwParam2);
1257 case MCI_UPDATE:
1258 return MCIQTZ_mciUpdate(dwDevID, dwParam1, (LPMCI_DGV_UPDATE_PARMS)dwParam2);
1259 case MCI_WINDOW:
1260 return MCIQTZ_mciWindow(dwDevID, dwParam1, (LPMCI_DGV_WINDOW_PARMSW)dwParam2);
1261 case MCI_PUT:
1262 return MCIQTZ_mciPut(dwDevID, dwParam1, (MCI_GENERIC_PARMS*)dwParam2);
1263 case MCI_RECORD:
1264 case MCI_INFO:
1265 case MCI_LOAD:
1266 case MCI_SAVE:
1267 case MCI_FREEZE:
1268 case MCI_REALIZE:
1269 case MCI_UNFREEZE:
1270 case MCI_STEP:
1271 case MCI_COPY:
1272 case MCI_CUT:
1273 case MCI_DELETE:
1274 case MCI_PASTE:
1275 case MCI_CUE:
1276 /* Digital Video specific */
1277 case MCI_CAPTURE:
1278 case MCI_MONITOR:
1279 case MCI_RESERVE:
1280 case MCI_SIGNAL:
1281 case MCI_SETVIDEO:
1282 case MCI_QUALITY:
1283 case MCI_LIST:
1284 case MCI_UNDO:
1285 case MCI_CONFIGURE:
1286 case MCI_RESTORE:
1287 FIXME("Unimplemented command [%08X]\n", wMsg);
1288 break;
1289 case MCI_SPIN:
1290 case MCI_ESCAPE:
1291 WARN("Unsupported command [%08X]\n", wMsg);
1292 break;
1293 case MCI_OPEN:
1294 case MCI_CLOSE:
1295 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
1296 break;
1297 default:
1298 TRACE("Sending msg [%08X] to default driver proc\n", wMsg);
1299 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1302 return MCIERR_UNRECOGNIZED_COMMAND;