kernel32: Add GetConsoleFontInfo stub.
[wine.git] / dlls / mciqtz32 / mciqtz.c
blob4e559b6720bac0e712d848477ca95891e842614a
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 CALLBACK MCIQTZ_taskThread(LPVOID arg);
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_relayTaskMessage [internal]
73 static LRESULT MCIQTZ_relayTaskMessage(DWORD_PTR dwDevID, UINT wMsg,
74 DWORD dwFlags, LPARAM lpParms)
76 WINE_MCIQTZ *wma;
77 LRESULT res;
78 HANDLE handles[2];
79 DWORD ret;
80 TRACE("(%08lX, %08x, %08x, %08lx)\n", dwDevID, wMsg, dwFlags, lpParms);
82 wma = MCIQTZ_mciGetOpenDev(dwDevID);
83 if (!wma)
84 return MCIERR_INVALID_DEVICE_ID;
85 EnterCriticalSection(&wma->cs);
86 wma->task.devid = dwDevID;
87 wma->task.msg = wMsg;
88 wma->task.flags = dwFlags;
89 wma->task.parms = lpParms;
90 SetEvent(wma->task.notify);
91 handles[0] = wma->task.done;
92 handles[1] = wma->task.thread;
93 ret = WaitForMultipleObjects(sizeof(handles)/sizeof(handles[0]), handles,
94 FALSE, INFINITE);
95 if (ret == WAIT_OBJECT_0)
96 res = wma->task.res;
97 else
98 res = MCIERR_INTERNAL;
99 LeaveCriticalSection(&wma->cs);
101 return res;
104 /**************************************************************************
105 * MCIQTZ_drvOpen [internal]
107 static DWORD MCIQTZ_drvOpen(LPCWSTR str, LPMCI_OPEN_DRIVER_PARMSW modp)
109 WINE_MCIQTZ* wma;
110 static const WCHAR mciAviWStr[] = {'M','C','I','A','V','I',0};
112 TRACE("(%s, %p)\n", debugstr_w(str), modp);
114 /* session instance */
115 if (!modp)
116 return 0xFFFFFFFF;
118 wma = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCIQTZ));
119 if (!wma)
120 return 0;
122 wma->stop_event = CreateEventW(NULL, FALSE, FALSE, NULL);
123 wma->task.notify = CreateEventW(NULL, FALSE, FALSE, NULL);
124 if (!wma->task.notify) goto err;
125 wma->task.done = CreateEventW(NULL, FALSE, FALSE, NULL);
126 if (!wma->task.done) goto err;
127 wma->task.thread = CreateThread(NULL, 0, MCIQTZ_taskThread, &wma->task, 0, NULL);
128 if (!wma->task.thread) goto err;
129 InitializeCriticalSection(&wma->cs);
130 wma->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": WINE_MCIQTZ");
131 modp->wType = MCI_DEVTYPE_DIGITAL_VIDEO;
132 wma->wDevID = modp->wDeviceID;
133 modp->wCustomCommandTable = wma->command_table = mciLoadCommandResource(MCIQTZ_hInstance, mciAviWStr, 0);
134 mciSetDriverData(wma->wDevID, (DWORD_PTR)wma);
136 return modp->wDeviceID;
137 err:
138 if (wma->task.notify) CloseHandle(wma->task.notify);
139 if (wma->task.done) CloseHandle(wma->task.done);
140 HeapFree(GetProcessHeap(), 0, wma);
141 return 0;
144 /**************************************************************************
145 * MCIQTZ_drvClose [internal]
147 static DWORD MCIQTZ_drvClose(DWORD dwDevID)
149 WINE_MCIQTZ* wma;
151 TRACE("(%04x)\n", dwDevID);
153 wma = MCIQTZ_mciGetOpenDev(dwDevID);
155 if (wma) {
156 /* finish all outstanding things */
157 MCIQTZ_relayTaskMessage(dwDevID, MCI_CLOSE_DRIVER, MCI_WAIT, 0);
159 mciFreeCommandResource(wma->command_table);
160 MCIQTZ_relayTaskMessage(dwDevID, MCI_CLOSE, MCI_WAIT, 0);
161 WaitForSingleObject(wma->task.thread, INFINITE);
162 CloseHandle(wma->task.notify);
163 CloseHandle(wma->task.done);
164 CloseHandle(wma->task.thread);
165 wma->cs.DebugInfo->Spare[0] = 0;
166 DeleteCriticalSection(&wma->cs);
167 mciSetDriverData(dwDevID, 0);
168 CloseHandle(wma->stop_event);
169 HeapFree(GetProcessHeap(), 0, wma);
170 return 1;
173 return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
176 /**************************************************************************
177 * MCIQTZ_drvConfigure [internal]
179 static DWORD MCIQTZ_drvConfigure(DWORD dwDevID)
181 WINE_MCIQTZ* wma;
183 TRACE("(%04x)\n", dwDevID);
185 wma = MCIQTZ_mciGetOpenDev(dwDevID);
186 if (!wma)
187 return 0;
189 MCIQTZ_mciStop(dwDevID, MCI_WAIT, NULL);
191 MessageBoxA(0, "Sample QTZ Wine Driver !", "MM-Wine Driver", MB_OK);
193 return 1;
196 /**************************************************************************
197 * MCIQTZ_mciNotify [internal]
199 * Notifications in MCI work like a 1-element queue.
200 * Each new notification request supersedes the previous one.
202 static void MCIQTZ_mciNotify(DWORD_PTR hWndCallBack, WINE_MCIQTZ* wma, UINT wStatus)
204 MCIDEVICEID wDevID = wma->notify_devid;
205 HANDLE old = InterlockedExchangePointer(&wma->callback, NULL);
206 if (old) mciDriverNotify(old, wDevID, MCI_NOTIFY_SUPERSEDED);
207 mciDriverNotify(HWND_32(LOWORD(hWndCallBack)), wDevID, wStatus);
210 /***************************************************************************
211 * MCIQTZ_mciOpen [internal]
213 static DWORD MCIQTZ_mciOpen(UINT wDevID, DWORD dwFlags,
214 LPMCI_DGV_OPEN_PARMSW lpOpenParms)
216 WINE_MCIQTZ* wma;
217 HRESULT hr;
218 DWORD style = 0;
219 RECT rc = { 0, 0, 0, 0 };
221 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpOpenParms);
223 wma = MCIQTZ_mciGetOpenDev(wDevID);
224 if (!wma)
225 return MCIERR_INVALID_DEVICE_ID;
227 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
229 hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
230 wma->uninit = SUCCEEDED(hr);
232 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&wma->pgraph);
233 if (FAILED(hr)) {
234 TRACE("Cannot create filtergraph (hr = %x)\n", hr);
235 goto err;
238 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaControl, (LPVOID*)&wma->pmctrl);
239 if (FAILED(hr)) {
240 TRACE("Cannot get IMediaControl interface (hr = %x)\n", hr);
241 goto err;
244 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaSeeking, (void**)&wma->seek);
245 if (FAILED(hr)) {
246 TRACE("Cannot get IMediaSeeking interface (hr = %x)\n", hr);
247 goto err;
250 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaEvent, (void**)&wma->mevent);
251 if (FAILED(hr)) {
252 TRACE("Cannot get IMediaEvent interface (hr = %x)\n", hr);
253 goto err;
256 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IVideoWindow, (void**)&wma->vidwin);
257 if (FAILED(hr)) {
258 TRACE("Cannot get IVideoWindow interface (hr = %x)\n", hr);
259 goto err;
262 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IBasicVideo, (void**)&wma->vidbasic);
263 if (FAILED(hr)) {
264 TRACE("Cannot get IBasicVideo interface (hr = %x)\n", hr);
265 goto err;
268 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IBasicAudio, (void**)&wma->audio);
269 if (FAILED(hr)) {
270 TRACE("Cannot get IBasicAudio interface (hr = %x)\n", hr);
271 goto err;
274 if (!(dwFlags & MCI_OPEN_ELEMENT) || (dwFlags & MCI_OPEN_ELEMENT_ID)) {
275 TRACE("Wrong dwFlags %x\n", dwFlags);
276 goto err;
279 if (!lpOpenParms->lpstrElementName || !lpOpenParms->lpstrElementName[0]) {
280 TRACE("Invalid filename specified\n");
281 goto err;
284 TRACE("Open file %s\n", debugstr_w(lpOpenParms->lpstrElementName));
286 hr = IGraphBuilder_RenderFile(wma->pgraph, lpOpenParms->lpstrElementName, NULL);
287 if (FAILED(hr)) {
288 TRACE("Cannot render file (hr = %x)\n", hr);
289 goto err;
292 IVideoWindow_put_AutoShow(wma->vidwin, OAFALSE);
293 IVideoWindow_put_Visible(wma->vidwin, OAFALSE);
294 if (dwFlags & MCI_DGV_OPEN_WS)
295 style = lpOpenParms->dwStyle;
296 if (dwFlags & MCI_DGV_OPEN_PARENT) {
297 IVideoWindow_put_MessageDrain(wma->vidwin, (OAHWND)lpOpenParms->hWndParent);
298 IVideoWindow_put_WindowState(wma->vidwin, SW_HIDE);
299 IVideoWindow_put_WindowStyle(wma->vidwin, style|WS_CHILD);
300 IVideoWindow_put_Owner(wma->vidwin, (OAHWND)lpOpenParms->hWndParent);
301 GetClientRect(lpOpenParms->hWndParent, &rc);
302 IVideoWindow_SetWindowPosition(wma->vidwin, rc.left, rc.top, rc.right - rc.top, rc.bottom - rc.top);
303 wma->parent = (HWND)lpOpenParms->hWndParent;
305 else if (style)
306 IVideoWindow_put_WindowStyle(wma->vidwin, style);
307 IBasicVideo_GetVideoSize(wma->vidbasic, &rc.right, &rc.bottom);
308 wma->opened = TRUE;
310 if (dwFlags & MCI_NOTIFY)
311 mciDriverNotify(HWND_32(LOWORD(lpOpenParms->dwCallback)), wDevID, MCI_NOTIFY_SUCCESSFUL);
313 return 0;
315 err:
316 if (wma->audio)
317 IBasicAudio_Release(wma->audio);
318 wma->audio = NULL;
319 if (wma->vidbasic)
320 IBasicVideo_Release(wma->vidbasic);
321 wma->vidbasic = NULL;
322 if (wma->seek)
323 IMediaSeeking_Release(wma->seek);
324 wma->seek = NULL;
325 if (wma->vidwin)
326 IVideoWindow_Release(wma->vidwin);
327 wma->vidwin = NULL;
328 if (wma->pgraph)
329 IGraphBuilder_Release(wma->pgraph);
330 wma->pgraph = NULL;
331 if (wma->mevent)
332 IMediaEvent_Release(wma->mevent);
333 wma->mevent = NULL;
334 if (wma->pmctrl)
335 IMediaControl_Release(wma->pmctrl);
336 wma->pmctrl = NULL;
338 if (wma->uninit)
339 CoUninitialize();
340 wma->uninit = FALSE;
342 return MCIERR_INTERNAL;
345 /***************************************************************************
346 * MCIQTZ_mciClose [internal]
348 static DWORD MCIQTZ_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
350 WINE_MCIQTZ* wma;
352 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
354 wma = MCIQTZ_mciGetOpenDev(wDevID);
355 if (!wma)
356 return MCIERR_INVALID_DEVICE_ID;
358 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
360 if (wma->opened) {
361 IVideoWindow_Release(wma->vidwin);
362 IBasicVideo_Release(wma->vidbasic);
363 IBasicAudio_Release(wma->audio);
364 IMediaSeeking_Release(wma->seek);
365 IMediaEvent_Release(wma->mevent);
366 IGraphBuilder_Release(wma->pgraph);
367 IMediaControl_Release(wma->pmctrl);
368 if (wma->uninit)
369 CoUninitialize();
370 wma->opened = FALSE;
373 return 0;
376 /***************************************************************************
377 * MCIQTZ_notifyThread [internal]
379 static DWORD CALLBACK MCIQTZ_notifyThread(LPVOID parm)
381 WINE_MCIQTZ* wma = (WINE_MCIQTZ *)parm;
382 HRESULT hr;
383 HANDLE handle[2];
384 DWORD n = 0, ret = 0;
386 handle[n++] = wma->stop_event;
387 IMediaEvent_GetEventHandle(wma->mevent, (OAEVENT *)&handle[n++]);
389 for (;;) {
390 DWORD r;
391 HANDLE old;
393 r = WaitForMultipleObjects(n, handle, FALSE, INFINITE);
394 if (r == WAIT_OBJECT_0) {
395 TRACE("got stop event\n");
396 old = InterlockedExchangePointer(&wma->callback, NULL);
397 if (old)
398 mciDriverNotify(old, wma->notify_devid, MCI_NOTIFY_ABORTED);
399 break;
401 else if (r == WAIT_OBJECT_0+1) {
402 LONG event_code;
403 LONG_PTR p1, p2;
404 do {
405 hr = IMediaEvent_GetEvent(wma->mevent, &event_code, &p1, &p2, 0);
406 if (SUCCEEDED(hr)) {
407 TRACE("got event_code = 0x%02x\n", event_code);
408 IMediaEvent_FreeEventParams(wma->mevent, event_code, p1, p2);
410 } while (hr == S_OK && event_code != EC_COMPLETE);
411 if (hr == S_OK && event_code == EC_COMPLETE) {
412 old = InterlockedExchangePointer(&wma->callback, NULL);
413 if (old)
414 mciDriverNotify(old, wma->notify_devid, MCI_NOTIFY_SUCCESSFUL);
415 break;
418 else {
419 TRACE("Unknown error (%d)\n", (int)r);
420 break;
424 hr = IMediaControl_Stop(wma->pmctrl);
425 if (FAILED(hr)) {
426 TRACE("Cannot stop filtergraph (hr = %x)\n", hr);
427 ret = MCIERR_INTERNAL;
430 return ret;
433 /***************************************************************************
434 * MCIQTZ_mciPlay [internal]
436 static DWORD MCIQTZ_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
438 WINE_MCIQTZ* wma;
439 HRESULT hr;
440 REFERENCE_TIME time1 = 0, time2 = 0;
441 GUID format;
442 DWORD pos1;
444 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
446 wma = MCIQTZ_mciGetOpenDev(wDevID);
447 if (!wma)
448 return MCIERR_INVALID_DEVICE_ID;
450 ResetEvent(wma->stop_event);
451 if (dwFlags & MCI_NOTIFY) {
452 HANDLE old;
453 old = InterlockedExchangePointer(&wma->callback, HWND_32(LOWORD(lpParms->dwCallback)));
454 if (old)
455 mciDriverNotify(old, wma->notify_devid, MCI_NOTIFY_ABORTED);
458 IMediaSeeking_GetTimeFormat(wma->seek, &format);
459 if (dwFlags & MCI_FROM) {
460 if (IsEqualGUID(&format, &TIME_FORMAT_MEDIA_TIME))
461 time1 = lpParms->dwFrom * 10000;
462 else
463 time1 = lpParms->dwFrom;
464 pos1 = AM_SEEKING_AbsolutePositioning;
465 } else
466 pos1 = AM_SEEKING_NoPositioning;
467 if (dwFlags & MCI_TO) {
468 if (IsEqualGUID(&format, &TIME_FORMAT_MEDIA_TIME))
469 time2 = lpParms->dwTo * 10000;
470 else
471 time2 = lpParms->dwTo;
472 } else
473 IMediaSeeking_GetDuration(wma->seek, &time2);
474 IMediaSeeking_SetPositions(wma->seek, &time1, pos1, &time2, AM_SEEKING_AbsolutePositioning);
476 hr = IMediaControl_Run(wma->pmctrl);
477 if (FAILED(hr)) {
478 TRACE("Cannot run filtergraph (hr = %x)\n", hr);
479 return MCIERR_INTERNAL;
482 IVideoWindow_put_Visible(wma->vidwin, OATRUE);
484 wma->thread = CreateThread(NULL, 0, MCIQTZ_notifyThread, wma, 0, NULL);
485 if (!wma->thread) {
486 TRACE("Can't create thread\n");
487 return MCIERR_INTERNAL;
489 return 0;
492 /***************************************************************************
493 * MCIQTZ_mciSeek [internal]
495 static DWORD MCIQTZ_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
497 WINE_MCIQTZ* wma;
498 HRESULT hr;
499 LONGLONG newpos;
501 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
503 wma = MCIQTZ_mciGetOpenDev(wDevID);
504 if (!wma)
505 return MCIERR_INVALID_DEVICE_ID;
507 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
509 if (dwFlags & MCI_SEEK_TO_START) {
510 newpos = 0;
511 } else if (dwFlags & MCI_SEEK_TO_END) {
512 FIXME("MCI_SEEK_TO_END not implemented yet\n");
513 return MCIERR_INTERNAL;
514 } else if (dwFlags & MCI_TO) {
515 FIXME("MCI_TO not implemented yet\n");
516 return MCIERR_INTERNAL;
517 } else {
518 WARN("dwFlag doesn't tell where to seek to...\n");
519 return MCIERR_MISSING_PARAMETER;
522 hr = IMediaSeeking_SetPositions(wma->seek, &newpos, AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
523 if (FAILED(hr)) {
524 FIXME("Cannot set position (hr = %x)\n", hr);
525 return MCIERR_INTERNAL;
528 if (dwFlags & MCI_NOTIFY)
529 MCIQTZ_mciNotify(lpParms->dwCallback, wma, MCI_NOTIFY_SUCCESSFUL);
531 return 0;
534 /***************************************************************************
535 * MCIQTZ_mciStop [internal]
537 static DWORD MCIQTZ_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
539 WINE_MCIQTZ* wma;
541 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
543 wma = MCIQTZ_mciGetOpenDev(wDevID);
544 if (!wma)
545 return MCIERR_INVALID_DEVICE_ID;
547 if (!wma->opened)
548 return 0;
550 if (wma->thread) {
551 SetEvent(wma->stop_event);
552 WaitForSingleObject(wma->thread, INFINITE);
553 CloseHandle(wma->thread);
554 wma->thread = NULL;
557 if (!wma->parent)
558 IVideoWindow_put_Visible(wma->vidwin, OAFALSE);
560 return 0;
563 /***************************************************************************
564 * MCIQTZ_mciPause [internal]
566 static DWORD MCIQTZ_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
568 WINE_MCIQTZ* wma;
569 HRESULT hr;
571 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
573 wma = MCIQTZ_mciGetOpenDev(wDevID);
574 if (!wma)
575 return MCIERR_INVALID_DEVICE_ID;
577 hr = IMediaControl_Pause(wma->pmctrl);
578 if (FAILED(hr)) {
579 TRACE("Cannot pause filtergraph (hr = %x)\n", hr);
580 return MCIERR_INTERNAL;
583 return 0;
586 /***************************************************************************
587 * MCIQTZ_mciResume [internal]
589 static DWORD MCIQTZ_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
591 WINE_MCIQTZ* wma;
592 HRESULT hr;
594 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
596 wma = MCIQTZ_mciGetOpenDev(wDevID);
597 if (!wma)
598 return MCIERR_INVALID_DEVICE_ID;
600 hr = IMediaControl_Run(wma->pmctrl);
601 if (FAILED(hr)) {
602 TRACE("Cannot run filtergraph (hr = %x)\n", hr);
603 return MCIERR_INTERNAL;
606 return 0;
609 /***************************************************************************
610 * MCIQTZ_mciGetDevCaps [internal]
612 static DWORD MCIQTZ_mciGetDevCaps(UINT wDevID, DWORD dwFlags, LPMCI_GETDEVCAPS_PARMS lpParms)
614 WINE_MCIQTZ* wma;
616 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
618 wma = MCIQTZ_mciGetOpenDev(wDevID);
619 if (!wma)
620 return MCIERR_INVALID_DEVICE_ID;
622 if (!(dwFlags & MCI_GETDEVCAPS_ITEM))
623 return MCIERR_MISSING_PARAMETER;
625 switch (lpParms->dwItem) {
626 case MCI_GETDEVCAPS_CAN_RECORD:
627 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
628 TRACE("MCI_GETDEVCAPS_CAN_RECORD = %08x\n", lpParms->dwReturn);
629 break;
630 case MCI_GETDEVCAPS_HAS_AUDIO:
631 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
632 TRACE("MCI_GETDEVCAPS_HAS_AUDIO = %08x\n", lpParms->dwReturn);
633 break;
634 case MCI_GETDEVCAPS_HAS_VIDEO:
635 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
636 TRACE("MCI_GETDEVCAPS_HAS_VIDEO = %08x\n", lpParms->dwReturn);
637 break;
638 case MCI_GETDEVCAPS_DEVICE_TYPE:
639 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_DEVTYPE_DIGITAL_VIDEO, MCI_DEVTYPE_DIGITAL_VIDEO);
640 TRACE("MCI_GETDEVCAPS_DEVICE_TYPE = %08x\n", lpParms->dwReturn);
641 break;
642 case MCI_GETDEVCAPS_USES_FILES:
643 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
644 TRACE("MCI_GETDEVCAPS_USES_FILES = %08x\n", lpParms->dwReturn);
645 break;
646 case MCI_GETDEVCAPS_COMPOUND_DEVICE:
647 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
648 TRACE("MCI_GETDEVCAPS_COMPOUND_DEVICE = %08x\n", lpParms->dwReturn);
649 break;
650 case MCI_GETDEVCAPS_CAN_EJECT:
651 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
652 TRACE("MCI_GETDEVCAPS_EJECT = %08x\n", lpParms->dwReturn);
653 break;
654 case MCI_GETDEVCAPS_CAN_PLAY:
655 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
656 TRACE("MCI_GETDEVCAPS_CAN_PLAY = %08x\n", lpParms->dwReturn);
657 break;
658 case MCI_GETDEVCAPS_CAN_SAVE:
659 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
660 TRACE("MCI_GETDEVCAPS_CAN_SAVE = %08x\n", lpParms->dwReturn);
661 break;
662 case MCI_DGV_GETDEVCAPS_CAN_REVERSE:
663 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
664 TRACE("MCI_DGV_GETDEVCAPS_CAN_REVERSE = %08x\n", lpParms->dwReturn);
665 break;
666 case MCI_DGV_GETDEVCAPS_CAN_STRETCH:
667 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE); /* FIXME */
668 TRACE("MCI_DGV_GETDEVCAPS_CAN_STRETCH = %08x\n", lpParms->dwReturn);
669 break;
670 case MCI_DGV_GETDEVCAPS_CAN_LOCK:
671 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
672 TRACE("MCI_DGV_GETDEVCAPS_CAN_LOCK = %08x\n", lpParms->dwReturn);
673 break;
674 case MCI_DGV_GETDEVCAPS_CAN_FREEZE:
675 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
676 TRACE("MCI_DGV_GETDEVCAPS_CAN_FREEZE = %08x\n", lpParms->dwReturn);
677 break;
678 case MCI_DGV_GETDEVCAPS_CAN_STR_IN:
679 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
680 TRACE("MCI_DGV_GETDEVCAPS_CAN_STRETCH_INPUT = %08x\n", lpParms->dwReturn);
681 break;
682 case MCI_DGV_GETDEVCAPS_HAS_STILL:
683 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
684 TRACE("MCI_DGV_GETDEVCAPS_HAS_STILL = %08x\n", lpParms->dwReturn);
685 break;
686 case MCI_DGV_GETDEVCAPS_CAN_TEST:
687 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE); /* FIXME */
688 TRACE("MCI_DGV_GETDEVCAPS_CAN_TEST = %08x\n", lpParms->dwReturn);
689 break;
690 case MCI_DGV_GETDEVCAPS_MAX_WINDOWS:
691 lpParms->dwReturn = 1;
692 TRACE("MCI_DGV_GETDEVCAPS_MAX_WINDOWS = %u\n", lpParms->dwReturn);
693 return 0;
694 default:
695 WARN("Unknown capability %08x\n", lpParms->dwItem);
696 /* Fall through */
697 case MCI_DGV_GETDEVCAPS_MAXIMUM_RATE: /* unknown to w2k */
698 case MCI_DGV_GETDEVCAPS_MINIMUM_RATE: /* unknown to w2k */
699 return MCIERR_UNSUPPORTED_FUNCTION;
702 return MCI_RESOURCE_RETURNED;
705 /***************************************************************************
706 * MCIQTZ_mciSet [internal]
708 static DWORD MCIQTZ_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SET_PARMS lpParms)
710 WINE_MCIQTZ* wma;
712 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
714 wma = MCIQTZ_mciGetOpenDev(wDevID);
715 if (!wma)
716 return MCIERR_INVALID_DEVICE_ID;
718 if (dwFlags & MCI_SET_TIME_FORMAT) {
719 switch (lpParms->dwTimeFormat) {
720 case MCI_FORMAT_MILLISECONDS:
721 TRACE("MCI_SET_TIME_FORMAT = MCI_FORMAT_MILLISECONDS\n");
722 wma->time_format = MCI_FORMAT_MILLISECONDS;
723 break;
724 case MCI_FORMAT_FRAMES:
725 TRACE("MCI_SET_TIME_FORMAT = MCI_FORMAT_FRAMES\n");
726 wma->time_format = MCI_FORMAT_FRAMES;
727 break;
728 default:
729 WARN("Bad time format %u\n", lpParms->dwTimeFormat);
730 return MCIERR_BAD_TIME_FORMAT;
734 if (dwFlags & MCI_SET_DOOR_OPEN)
735 FIXME("MCI_SET_DOOR_OPEN not implemented yet\n");
736 if (dwFlags & MCI_SET_DOOR_CLOSED)
737 FIXME("MCI_SET_DOOR_CLOSED not implemented yet\n");
738 if (dwFlags & MCI_SET_AUDIO)
739 FIXME("MCI_SET_AUDIO not implemented yet\n");
740 if (dwFlags & MCI_SET_VIDEO)
741 FIXME("MCI_SET_VIDEO not implemented yet\n");
742 if (dwFlags & MCI_SET_ON)
743 FIXME("MCI_SET_ON not implemented yet\n");
744 if (dwFlags & MCI_SET_OFF)
745 FIXME("MCI_SET_OFF not implemented yet\n");
746 if (dwFlags & MCI_SET_AUDIO_LEFT)
747 FIXME("MCI_SET_AUDIO_LEFT not implemented yet\n");
748 if (dwFlags & MCI_SET_AUDIO_RIGHT)
749 FIXME("MCI_SET_AUDIO_RIGHT not implemented yet\n");
751 if (dwFlags & ~0x7f03 /* All MCI_SET flags mask */)
752 ERR("Unknown flags %08x\n", dwFlags & ~0x7f03);
754 return 0;
757 /***************************************************************************
758 * MCIQTZ_mciStatus [internal]
760 static DWORD MCIQTZ_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_DGV_STATUS_PARMSW lpParms)
762 WINE_MCIQTZ* wma;
763 HRESULT hr;
764 DWORD ret = MCI_INTEGER_RETURNED;
766 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
768 wma = MCIQTZ_mciGetOpenDev(wDevID);
769 if (!wma)
770 return MCIERR_INVALID_DEVICE_ID;
772 if (!(dwFlags & MCI_STATUS_ITEM)) {
773 WARN("No status item specified\n");
774 return MCIERR_UNRECOGNIZED_COMMAND;
777 switch (lpParms->dwItem) {
778 case MCI_STATUS_LENGTH: {
779 LONGLONG duration = -1;
780 GUID format;
781 switch (wma->time_format) {
782 case MCI_FORMAT_MILLISECONDS: format = TIME_FORMAT_MEDIA_TIME; break;
783 case MCI_FORMAT_FRAMES: format = TIME_FORMAT_FRAME; break;
784 default: ERR("Unhandled format %x\n", wma->time_format); break;
786 hr = IMediaSeeking_SetTimeFormat(wma->seek, &format);
787 if (FAILED(hr)) {
788 FIXME("Cannot set time format (hr = %x)\n", hr);
789 lpParms->dwReturn = 0;
790 break;
792 hr = IMediaSeeking_GetDuration(wma->seek, &duration);
793 if (FAILED(hr) || duration < 0) {
794 FIXME("Cannot read duration (hr = %x)\n", hr);
795 lpParms->dwReturn = 0;
796 } else if (wma->time_format != MCI_FORMAT_MILLISECONDS)
797 lpParms->dwReturn = duration;
798 else
799 lpParms->dwReturn = duration / 10000;
800 break;
802 case MCI_STATUS_POSITION: {
803 REFERENCE_TIME curpos;
805 hr = IMediaSeeking_GetCurrentPosition(wma->seek, &curpos);
806 if (FAILED(hr)) {
807 FIXME("Cannot get position (hr = %x)\n", hr);
808 return MCIERR_INTERNAL;
810 lpParms->dwReturn = curpos / 10000;
811 break;
813 case MCI_STATUS_NUMBER_OF_TRACKS:
814 FIXME("MCI_STATUS_NUMBER_OF_TRACKS not implemented yet\n");
815 return MCIERR_UNRECOGNIZED_COMMAND;
816 case MCI_STATUS_MODE: {
817 LONG state = State_Stopped;
818 IMediaControl_GetState(wma->pmctrl, -1, &state);
819 if (state == State_Stopped)
820 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_MODE_STOP, MCI_MODE_STOP);
821 else if (state == State_Running) {
822 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_MODE_PLAY, MCI_MODE_PLAY);
823 if (!wma->thread || WaitForSingleObject(wma->thread, 0) == WAIT_OBJECT_0)
824 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_MODE_STOP, MCI_MODE_STOP);
825 } else if (state == State_Paused)
826 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_MODE_PAUSE, MCI_MODE_PAUSE);
827 ret = MCI_RESOURCE_RETURNED;
828 break;
830 case MCI_STATUS_MEDIA_PRESENT:
831 FIXME("MCI_STATUS_MEDIA_PRESENT not implemented yet\n");
832 return MCIERR_UNRECOGNIZED_COMMAND;
833 case MCI_STATUS_TIME_FORMAT:
834 lpParms->dwReturn = MAKEMCIRESOURCE(wma->time_format,
835 MCI_FORMAT_RETURN_BASE + wma->time_format);
836 ret = MCI_RESOURCE_RETURNED;
837 break;
838 case MCI_STATUS_READY:
839 FIXME("MCI_STATUS_READY not implemented yet\n");
840 return MCIERR_UNRECOGNIZED_COMMAND;
841 case MCI_STATUS_CURRENT_TRACK:
842 FIXME("MCI_STATUS_CURRENT_TRACK not implemented yet\n");
843 return MCIERR_UNRECOGNIZED_COMMAND;
844 default:
845 FIXME("Unknown command %08X\n", lpParms->dwItem);
846 return MCIERR_UNRECOGNIZED_COMMAND;
849 if (dwFlags & MCI_NOTIFY)
850 MCIQTZ_mciNotify(lpParms->dwCallback, wma, MCI_NOTIFY_SUCCESSFUL);
852 return ret;
855 /***************************************************************************
856 * MCIQTZ_mciWhere [internal]
858 static DWORD MCIQTZ_mciWhere(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
860 WINE_MCIQTZ* wma;
861 HRESULT hr;
862 HWND hWnd;
863 RECT rc;
864 DWORD ret = MCIERR_UNRECOGNIZED_COMMAND;
866 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
868 wma = MCIQTZ_mciGetOpenDev(wDevID);
869 if (!wma)
870 return MCIERR_INVALID_DEVICE_ID;
872 hr = IVideoWindow_get_Owner(wma->vidwin, (OAHWND*)&hWnd);
873 if (FAILED(hr)) {
874 TRACE("No video stream, returning no window error\n");
875 return MCIERR_NO_WINDOW;
878 if (dwFlags & MCI_DGV_WHERE_SOURCE) {
879 if (dwFlags & MCI_DGV_WHERE_MAX)
880 FIXME("MCI_DGV_WHERE_SOURCE_MAX stub\n");
881 IBasicVideo_GetSourcePosition(wma->vidbasic, &rc.left, &rc.top, &rc.right, &rc.bottom);
882 TRACE("MCI_DGV_WHERE_SOURCE %s\n", wine_dbgstr_rect(&rc));
884 if (dwFlags & MCI_DGV_WHERE_DESTINATION) {
885 if (dwFlags & MCI_DGV_WHERE_MAX)
886 FIXME("MCI_DGV_WHERE_DESTINATION_MAX stub\n");
887 IBasicVideo_GetDestinationPosition(wma->vidbasic, &rc.left, &rc.top, &rc.right, &rc.bottom);
888 TRACE("MCI_DGV_WHERE_DESTINATION %s\n", wine_dbgstr_rect(&rc));
890 if (dwFlags & MCI_DGV_WHERE_FRAME) {
891 if (dwFlags & MCI_DGV_WHERE_MAX)
892 FIXME("MCI_DGV_WHERE_FRAME_MAX not supported yet\n");
893 else
894 FIXME("MCI_DGV_WHERE_FRAME not supported yet\n");
895 goto out;
897 if (dwFlags & MCI_DGV_WHERE_VIDEO) {
898 if (dwFlags & MCI_DGV_WHERE_MAX)
899 FIXME("MCI_DGV_WHERE_VIDEO_MAX not supported yet\n");
900 else
901 FIXME("MCI_DGV_WHERE_VIDEO not supported yet\n");
902 goto out;
904 if (dwFlags & MCI_DGV_WHERE_WINDOW) {
905 if (dwFlags & MCI_DGV_WHERE_MAX) {
906 GetWindowRect(GetDesktopWindow(), &rc);
907 rc.right -= rc.left;
908 rc.bottom -= rc.top;
909 TRACE("MCI_DGV_WHERE_WINDOW_MAX %s\n", wine_dbgstr_rect(&rc));
910 } else {
911 IVideoWindow_GetWindowPosition(wma->vidwin, &rc.left, &rc.top, &rc.right, &rc.bottom);
912 TRACE("MCI_DGV_WHERE_WINDOW %s\n", wine_dbgstr_rect(&rc));
915 ret = 0;
916 out:
917 lpParms->rc = rc;
918 return ret;
921 /***************************************************************************
922 * MCIQTZ_mciWindow [internal]
924 static DWORD MCIQTZ_mciWindow(UINT wDevID, DWORD dwFlags, LPMCI_DGV_WINDOW_PARMSW lpParms)
926 WINE_MCIQTZ *wma = MCIQTZ_mciGetOpenDev(wDevID);
928 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
930 if (!wma)
931 return MCIERR_INVALID_DEVICE_ID;
932 if (dwFlags & MCI_TEST)
933 return 0;
935 if (dwFlags & MCI_DGV_WINDOW_HWND && (IsWindow(lpParms->hWnd) || !lpParms->hWnd)) {
936 LONG visible = OATRUE;
937 LONG style = 0;
938 TRACE("Setting hWnd to %p\n", lpParms->hWnd);
939 IVideoWindow_get_Visible(wma->vidwin, &visible);
940 IVideoWindow_put_Visible(wma->vidwin, OAFALSE);
941 IVideoWindow_get_WindowStyle(wma->vidwin, &style);
942 style &= ~WS_CHILD;
943 if (lpParms->hWnd)
944 IVideoWindow_put_WindowStyle(wma->vidwin, style|WS_CHILD);
945 else
946 IVideoWindow_put_WindowStyle(wma->vidwin, style);
947 IVideoWindow_put_Owner(wma->vidwin, (OAHWND)lpParms->hWnd);
948 IVideoWindow_put_MessageDrain(wma->vidwin, (OAHWND)lpParms->hWnd);
949 IVideoWindow_put_Visible(wma->vidwin, visible);
950 wma->parent = lpParms->hWnd;
952 if (dwFlags & MCI_DGV_WINDOW_STATE) {
953 TRACE("Setting nCmdShow to %d\n", lpParms->nCmdShow);
954 IVideoWindow_put_WindowState(wma->vidwin, lpParms->nCmdShow);
956 if (dwFlags & MCI_DGV_WINDOW_TEXT) {
957 TRACE("Setting caption to %s\n", debugstr_w(lpParms->lpstrText));
958 IVideoWindow_put_Caption(wma->vidwin, lpParms->lpstrText);
960 return 0;
963 /***************************************************************************
964 * MCIQTZ_mciPut [internal]
966 static DWORD MCIQTZ_mciPut(UINT wDevID, DWORD dwFlags, MCI_GENERIC_PARMS *lpParms)
968 WINE_MCIQTZ *wma = MCIQTZ_mciGetOpenDev(wDevID);
969 MCI_DGV_RECT_PARMS *rectparms;
970 HRESULT hr;
972 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
974 if (!wma)
975 return MCIERR_INVALID_DEVICE_ID;
977 if (!(dwFlags & MCI_DGV_RECT)) {
978 FIXME("No support for non-RECT MCI_PUT\n");
979 return 1;
982 if (dwFlags & MCI_TEST)
983 return 0;
985 dwFlags &= ~MCI_DGV_RECT;
986 rectparms = (MCI_DGV_RECT_PARMS*)lpParms;
988 if (dwFlags & MCI_DGV_PUT_DESTINATION) {
989 hr = IVideoWindow_SetWindowPosition(wma->vidwin,
990 rectparms->rc.left, rectparms->rc.top,
991 rectparms->rc.right - rectparms->rc.left,
992 rectparms->rc.bottom - rectparms->rc.top);
993 if(FAILED(hr))
994 WARN("IVideoWindow_SetWindowPosition failed: 0x%x\n", hr);
996 dwFlags &= ~MCI_DGV_PUT_DESTINATION;
999 if (dwFlags & MCI_NOTIFY) {
1000 MCIQTZ_mciNotify(lpParms->dwCallback, wma, MCI_NOTIFY_SUCCESSFUL);
1001 dwFlags &= ~MCI_NOTIFY;
1004 if (dwFlags)
1005 FIXME("No support for some flags: 0x%x\n", dwFlags);
1007 return 0;
1010 /******************************************************************************
1011 * MCIAVI_mciUpdate [internal]
1013 static DWORD MCIQTZ_mciUpdate(UINT wDevID, DWORD dwFlags, LPMCI_DGV_UPDATE_PARMS lpParms)
1015 WINE_MCIQTZ *wma;
1016 DWORD res = 0;
1018 TRACE("%04x, %08x, %p\n", wDevID, dwFlags, lpParms);
1020 wma = MCIQTZ_mciGetOpenDev(wDevID);
1021 if (!wma)
1022 return MCIERR_INVALID_DEVICE_ID;
1024 if (dwFlags & MCI_DGV_UPDATE_HDC) {
1025 LONG state, size;
1026 BYTE *data;
1027 BITMAPINFO *info;
1028 HRESULT hr;
1029 RECT src, dest;
1030 LONG visible = OATRUE;
1032 res = MCIERR_INTERNAL;
1033 IMediaControl_GetState(wma->pmctrl, -1, &state);
1034 if (state == State_Running)
1035 return MCIERR_UNSUPPORTED_FUNCTION;
1036 /* If in stopped state, nothing has been drawn to screen
1037 * moving to pause, which is needed for the old dib renderer, will result
1038 * in a single frame drawn, so hide the window here */
1039 IVideoWindow_get_Visible(wma->vidwin, &visible);
1040 if (wma->parent)
1041 IVideoWindow_put_Visible(wma->vidwin, OAFALSE);
1042 /* FIXME: Should we check the original state and restore it? */
1043 IMediaControl_Pause(wma->pmctrl);
1044 IMediaControl_GetState(wma->pmctrl, -1, &state);
1045 if (FAILED(hr = IBasicVideo_GetCurrentImage(wma->vidbasic, &size, NULL))) {
1046 WARN("Could not get image size (hr = %x)\n", hr);
1047 goto out;
1049 data = HeapAlloc(GetProcessHeap(), 0, size);
1050 info = (BITMAPINFO*)data;
1051 IBasicVideo_GetCurrentImage(wma->vidbasic, &size, (LONG*)data);
1052 data += info->bmiHeader.biSize;
1054 IBasicVideo_GetSourcePosition(wma->vidbasic, &src.left, &src.top, &src.right, &src.bottom);
1055 IBasicVideo_GetDestinationPosition(wma->vidbasic, &dest.left, &dest.top, &dest.right, &dest.bottom);
1056 StretchDIBits(lpParms->hDC,
1057 dest.left, dest.top, dest.right + dest.left, dest.bottom + dest.top,
1058 src.left, src.top, src.right + src.left, src.bottom + src.top,
1059 data, info, DIB_RGB_COLORS, SRCCOPY);
1060 HeapFree(GetProcessHeap(), 0, data);
1061 res = 0;
1062 out:
1063 if (wma->parent)
1064 IVideoWindow_put_Visible(wma->vidwin, visible);
1066 else if (dwFlags)
1067 FIXME("Unhandled flags %x\n", dwFlags);
1068 return res;
1071 /***************************************************************************
1072 * MCIQTZ_mciSetAudio [internal]
1074 static DWORD MCIQTZ_mciSetAudio(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SETAUDIO_PARMSW lpParms)
1076 WINE_MCIQTZ *wma;
1077 DWORD ret = 0;
1079 TRACE("(%04x, %08x, %p)\n", wDevID, dwFlags, lpParms);
1081 wma = MCIQTZ_mciGetOpenDev(wDevID);
1082 if (!wma)
1083 return MCIERR_INVALID_DEVICE_ID;
1085 if (!(dwFlags & MCI_DGV_SETAUDIO_ITEM)) {
1086 FIXME("Unknown flags (%08x)\n", dwFlags);
1087 return 0;
1090 if (dwFlags & MCI_DGV_SETAUDIO_ITEM) {
1091 switch (lpParms->dwItem) {
1092 case MCI_DGV_SETAUDIO_VOLUME:
1093 if (dwFlags & MCI_DGV_SETAUDIO_VALUE) {
1094 long vol = -10000;
1095 HRESULT hr;
1096 if (lpParms->dwValue > 1000) {
1097 ret = MCIERR_OUTOFRANGE;
1098 break;
1100 if (dwFlags & MCI_TEST)
1101 break;
1102 vol += (long)lpParms->dwValue * 10;
1103 hr = IBasicAudio_put_Volume(wma->audio, vol);
1104 if (FAILED(hr)) {
1105 WARN("Cannot set volume (hr = %x)\n", hr);
1106 ret = MCIERR_INTERNAL;
1109 break;
1110 default:
1111 FIXME("Unknown item %08x\n", lpParms->dwItem);
1112 break;
1116 return ret;
1119 /***************************************************************************
1120 * MCIQTZ_taskThread [internal]
1122 static DWORD CALLBACK MCIQTZ_taskThread(LPVOID arg)
1124 WINE_MCIQTZ_TASK *task = (WINE_MCIQTZ_TASK *)arg;
1126 for (;;) {
1127 DWORD ret = WaitForSingleObject(task->notify, INFINITE);
1128 if (ret != WAIT_OBJECT_0) {
1129 TRACE("Got error (%u)\n", ret);
1130 continue;
1133 switch (task->msg) {
1134 case MCI_OPEN_DRIVER:
1135 task->res = MCIQTZ_mciOpen(task->devid, task->flags, (LPMCI_DGV_OPEN_PARMSW)task->parms);
1136 break;
1137 case MCI_CLOSE_DRIVER:
1138 task->res = MCIQTZ_mciClose(task->devid, task->flags, (LPMCI_GENERIC_PARMS)task->parms);
1139 break;
1140 case MCI_PLAY:
1141 task->res = MCIQTZ_mciPlay(task->devid, task->flags, (LPMCI_PLAY_PARMS)task->parms);
1142 break;
1143 case MCI_SEEK:
1144 task->res = MCIQTZ_mciSeek(task->devid, task->flags, (LPMCI_SEEK_PARMS)task->parms);
1145 break;
1146 case MCI_STOP:
1147 task->res = MCIQTZ_mciStop(task->devid, task->flags, (LPMCI_GENERIC_PARMS)task->parms);
1148 break;
1149 case MCI_PAUSE:
1150 task->res = MCIQTZ_mciPause(task->devid, task->flags, (LPMCI_GENERIC_PARMS)task->parms);
1151 break;
1152 case MCI_RESUME:
1153 task->res = MCIQTZ_mciResume(task->devid, task->flags, (LPMCI_GENERIC_PARMS)task->parms);
1154 break;
1155 case MCI_GETDEVCAPS:
1156 task->res = MCIQTZ_mciGetDevCaps(task->devid, task->flags, (LPMCI_GETDEVCAPS_PARMS)task->parms);
1157 break;
1158 case MCI_SET:
1159 task->res = MCIQTZ_mciSet(task->devid, task->flags, (LPMCI_DGV_SET_PARMS)task->parms);
1160 break;
1161 case MCI_STATUS:
1162 task->res = MCIQTZ_mciStatus(task->devid, task->flags, (LPMCI_DGV_STATUS_PARMSW)task->parms);
1163 break;
1164 case MCI_WHERE:
1165 task->res = MCIQTZ_mciWhere(task->devid, task->flags, (LPMCI_DGV_RECT_PARMS)task->parms);
1166 break;
1167 case MCI_SETAUDIO:
1168 task->res = MCIQTZ_mciSetAudio(task->devid, task->flags, (LPMCI_DGV_SETAUDIO_PARMSW)task->parms);
1169 break;
1170 case MCI_UPDATE:
1171 task->res = MCIQTZ_mciUpdate(task->devid, task->flags, (LPMCI_DGV_UPDATE_PARMS)task->parms);
1172 break;
1173 case MCI_WINDOW:
1174 task->res = MCIQTZ_mciWindow(task->devid, task->flags, (LPMCI_DGV_WINDOW_PARMSW)task->parms);
1175 break;
1176 case MCI_PUT:
1177 task->res = MCIQTZ_mciPut(task->devid, task->flags, (MCI_GENERIC_PARMS*)task->parms);
1178 break;
1179 case MCI_CLOSE:
1180 /* Special internal message */
1181 SetEvent(task->done);
1182 goto end;
1183 default:
1184 FIXME("Shouldn't receive another message (%04x)\n", task->msg);
1185 task->res = MCIERR_UNRECOGNIZED_COMMAND;
1186 break;
1188 SetEvent(task->done);
1191 end:
1192 return 0;
1195 /*======================================================================*
1196 * MCI QTZ entry points *
1197 *======================================================================*/
1199 /**************************************************************************
1200 * DriverProc (MCIQTZ.@)
1202 LRESULT CALLBACK MCIQTZ_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
1203 LPARAM dwParam1, LPARAM dwParam2)
1205 TRACE("(%08lX, %p, %08X, %08lX, %08lX)\n",
1206 dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1208 switch (wMsg) {
1209 case DRV_LOAD: return 1;
1210 case DRV_FREE: return 1;
1211 case DRV_OPEN: return MCIQTZ_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
1212 case DRV_CLOSE: return MCIQTZ_drvClose(dwDevID);
1213 case DRV_ENABLE: return 1;
1214 case DRV_DISABLE: return 1;
1215 case DRV_QUERYCONFIGURE: return 1;
1216 case DRV_CONFIGURE: return MCIQTZ_drvConfigure(dwDevID);
1217 case DRV_INSTALL: return DRVCNF_RESTART;
1218 case DRV_REMOVE: return DRVCNF_RESTART;
1221 /* session instance */
1222 if (dwDevID == 0xFFFFFFFF)
1223 return 1;
1225 switch (wMsg) {
1226 case MCI_OPEN_DRIVER:
1227 case MCI_PLAY:
1228 case MCI_SEEK:
1229 case MCI_GETDEVCAPS:
1230 case MCI_SET:
1231 case MCI_STATUS:
1232 case MCI_WHERE:
1233 if (!dwParam2) return MCIERR_NULL_PARAMETER_BLOCK;
1234 return MCIQTZ_relayTaskMessage(dwDevID, wMsg, dwParam1, dwParam2);
1235 case MCI_CLOSE_DRIVER:
1236 case MCI_STOP:
1237 case MCI_PAUSE:
1238 case MCI_RESUME:
1239 return MCIQTZ_relayTaskMessage(dwDevID, wMsg, dwParam1, dwParam2);
1240 /* Digital Video specific */
1241 case MCI_SETAUDIO:
1242 case MCI_UPDATE:
1243 case MCI_WINDOW:
1244 case MCI_PUT:
1245 if (!dwParam2) return MCIERR_NULL_PARAMETER_BLOCK;
1246 return MCIQTZ_relayTaskMessage(dwDevID, wMsg, dwParam1, dwParam2);
1247 case MCI_RECORD:
1248 case MCI_INFO:
1249 case MCI_LOAD:
1250 case MCI_SAVE:
1251 case MCI_FREEZE:
1252 case MCI_REALIZE:
1253 case MCI_UNFREEZE:
1254 case MCI_STEP:
1255 case MCI_COPY:
1256 case MCI_CUT:
1257 case MCI_DELETE:
1258 case MCI_PASTE:
1259 case MCI_CUE:
1260 /* Digital Video specific */
1261 case MCI_CAPTURE:
1262 case MCI_MONITOR:
1263 case MCI_RESERVE:
1264 case MCI_SIGNAL:
1265 case MCI_SETVIDEO:
1266 case MCI_QUALITY:
1267 case MCI_LIST:
1268 case MCI_UNDO:
1269 case MCI_CONFIGURE:
1270 case MCI_RESTORE:
1271 FIXME("Unimplemented command [%08X]\n", wMsg);
1272 break;
1273 case MCI_SPIN:
1274 case MCI_ESCAPE:
1275 WARN("Unsupported command [%08X]\n", wMsg);
1276 break;
1277 case MCI_OPEN:
1278 case MCI_CLOSE:
1279 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
1280 break;
1281 default:
1282 TRACE("Sending msg [%08X] to default driver proc\n", wMsg);
1283 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1286 return MCIERR_UNRECOGNIZED_COMMAND;