rpcrt4: Always skip the conformance format, even if conformance is not present in...
[wine] / dlls / mciqtz32 / mciqtz.c
1 /*
2  * DirectShow MCI Driver
3  *
4  * Copyright 2009 Christian Costa
5  *
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.
10  *
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.
15  *
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
19  */
20
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"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(mciqtz);
32
33 static DWORD MCIQTZ_mciClose(UINT, DWORD, LPMCI_GENERIC_PARMS);
34 static DWORD MCIQTZ_mciStop(UINT, DWORD, LPMCI_GENERIC_PARMS);
35
36 /*======================================================================*
37  *                          MCI QTZ implementation                      *
38  *======================================================================*/
39
40 HINSTANCE MCIQTZ_hInstance = 0;
41
42 /***********************************************************************
43  *              DllMain (MCIQTZ.0)
44  */
45 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
46 {
47     switch (fdwReason) {
48     case DLL_PROCESS_ATTACH:
49         DisableThreadLibraryCalls(hInstDLL);
50         MCIQTZ_hInstance = hInstDLL;
51         break;
52     }
53     return TRUE;
54 }
55
56 /**************************************************************************
57  *                              MCIQTZ_mciGetOpenDev            [internal]
58  */
59 static WINE_MCIQTZ* MCIQTZ_mciGetOpenDev(UINT wDevID)
60 {
61     WINE_MCIQTZ* wma = (WINE_MCIQTZ*)mciGetDriverData(wDevID);
62
63     if (!wma) {
64         WARN("Invalid wDevID=%u\n", wDevID);
65         return NULL;
66     }
67     return wma;
68 }
69
70 /**************************************************************************
71  *                              MCIQTZ_drvOpen                  [internal]
72  */
73 static DWORD MCIQTZ_drvOpen(LPCWSTR str, LPMCI_OPEN_DRIVER_PARMSW modp)
74 {
75     WINE_MCIQTZ* wma;
76
77     TRACE("(%s, %p)\n", debugstr_w(str), modp);
78
79     /* session instance */
80     if (!modp)
81         return 0xFFFFFFFF;
82
83     wma = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCIQTZ));
84     if (!wma)
85         return 0;
86
87     wma->wDevID = modp->wDeviceID;
88     mciSetDriverData(wma->wDevID, (DWORD_PTR)wma);
89
90     return modp->wDeviceID;
91 }
92
93 /**************************************************************************
94  *                              MCIQTZ_drvClose         [internal]
95  */
96 static DWORD MCIQTZ_drvClose(DWORD dwDevID)
97 {
98     WINE_MCIQTZ* wma;
99
100     TRACE("(%04x)\n", dwDevID);
101
102     wma = MCIQTZ_mciGetOpenDev(dwDevID);
103
104     if (wma) {
105         /* finish all outstanding things */
106         MCIQTZ_mciClose(dwDevID, MCI_WAIT, NULL);
107
108         mciSetDriverData(dwDevID, 0);
109         HeapFree(GetProcessHeap(), 0, wma);
110         return 1;
111     }
112
113     return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
114 }
115
116 /**************************************************************************
117  *                              MCIQTZ_drvConfigure             [internal]
118  */
119 static DWORD MCIQTZ_drvConfigure(DWORD dwDevID)
120 {
121     WINE_MCIQTZ* wma;
122
123     TRACE("(%04x)\n", dwDevID);
124
125     wma = MCIQTZ_mciGetOpenDev(dwDevID);
126     if (!wma)
127         return 0;
128
129     MCIQTZ_mciStop(dwDevID, MCI_WAIT, NULL);
130
131     MessageBoxA(0, "Sample QTZ Wine Driver !", "MM-Wine Driver", MB_OK);
132
133     return 1;
134 }
135
136 /***************************************************************************
137  *                              MCIQTZ_mciOpen                  [internal]
138  */
139 static DWORD MCIQTZ_mciOpen(UINT wDevID, DWORD dwFlags,
140                             LPMCI_DGV_OPEN_PARMSW lpOpenParms)
141 {
142     WINE_MCIQTZ* wma;
143     HRESULT hr;
144
145     TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpOpenParms);
146
147     if (!lpOpenParms)
148         return MCIERR_NULL_PARAMETER_BLOCK;
149
150     wma = MCIQTZ_mciGetOpenDev(wDevID);
151     if (!wma)
152         return MCIERR_INVALID_DEVICE_ID;
153
154     MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
155
156     CoInitializeEx(NULL, COINIT_MULTITHREADED);
157
158     hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&wma->pgraph);
159     if (FAILED(hr)) {
160         TRACE("Cannot create filtergraph (hr = %x)\n", hr);
161         goto err;
162     }
163
164     hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaControl, (LPVOID*)&wma->pmctrl);
165     if (FAILED(hr)) {
166         TRACE("Cannot get IMediaControl interface (hr = %x)\n", hr);
167         goto err;
168     }
169
170     if (!(dwFlags & MCI_OPEN_ELEMENT) || (dwFlags & MCI_OPEN_ELEMENT_ID)) {
171         TRACE("Wrong dwFlags %x\n", dwFlags);
172         goto err;
173     }
174
175     if (!lpOpenParms->lpstrElementName || !lpOpenParms->lpstrElementName[0]) {
176         TRACE("Invalid filename specified\n");
177         goto err;
178     }
179
180     TRACE("Open file %s\n", debugstr_w(lpOpenParms->lpstrElementName));
181
182     hr = IGraphBuilder_RenderFile(wma->pgraph, lpOpenParms->lpstrElementName, NULL);
183     if (FAILED(hr)) {
184         TRACE("Cannot render file (hr = %x)\n", hr);
185         goto err;
186     }
187
188     wma->opened = TRUE;
189
190     return 0;
191
192 err:
193     if (wma->pgraph)
194         IGraphBuilder_Release(wma->pgraph);
195     wma->pgraph = NULL;
196     if (wma->pmctrl)
197         IMediaControl_Release(wma->pmctrl);
198     wma->pmctrl = NULL;
199
200     CoUninitialize();
201
202     return MCIERR_INTERNAL;
203 }
204
205 /***************************************************************************
206  *                              MCIQTZ_mciClose                 [internal]
207  */
208 static DWORD MCIQTZ_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
209 {
210     WINE_MCIQTZ* wma;
211
212     TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
213
214     wma = MCIQTZ_mciGetOpenDev(wDevID);
215     if (!wma)
216         return MCIERR_INVALID_DEVICE_ID;
217
218     MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
219
220     if (wma->opened) {
221         IGraphBuilder_Release(wma->pgraph);
222         IMediaControl_Release(wma->pmctrl);
223         CoUninitialize();
224         wma->opened = FALSE;
225     }
226
227     return 0;
228 }
229
230 /***************************************************************************
231  *                              MCIQTZ_mciPlay                  [internal]
232  */
233 static DWORD MCIQTZ_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
234 {
235     WINE_MCIQTZ* wma;
236     HRESULT hr;
237
238     TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
239
240     if (!lpParms)
241         return MCIERR_NULL_PARAMETER_BLOCK;
242
243     wma = MCIQTZ_mciGetOpenDev(wDevID);
244     if (!wma)
245         return MCIERR_INVALID_DEVICE_ID;
246
247     hr = IMediaControl_Run(wma->pmctrl);
248     if (FAILED(hr)) {
249         TRACE("Cannot run filtergraph (hr = %x)\n", hr);
250         return MCIERR_INTERNAL;
251     }
252
253     wma->started = TRUE;
254
255     return 0;
256 }
257
258 /***************************************************************************
259  *                              MCIQTZ_mciSeek                  [internal]
260  */
261 static DWORD MCIQTZ_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
262 {
263     WINE_MCIQTZ* wma;
264     HRESULT hr;
265     IMediaPosition* pmpos;
266     LONGLONG newpos;
267
268     TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
269
270     if (!lpParms)
271         return MCIERR_NULL_PARAMETER_BLOCK;
272
273     wma = MCIQTZ_mciGetOpenDev(wDevID);
274     if (!wma)
275         return MCIERR_INVALID_DEVICE_ID;
276
277     MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
278
279     if (dwFlags & MCI_SEEK_TO_START) {
280         newpos = 0;
281     } else if (dwFlags & MCI_SEEK_TO_END) {
282         FIXME("MCI_SEEK_TO_END not implemented yet\n");
283         return MCIERR_INTERNAL;
284     } else if (dwFlags & MCI_TO) {
285         FIXME("MCI_TO not implemented yet\n");
286         return MCIERR_INTERNAL;
287     } else {
288         WARN("dwFlag doesn't tell where to seek to...\n");
289         return MCIERR_MISSING_PARAMETER;
290     }
291
292     hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaPosition, (LPVOID*)&pmpos);
293     if (FAILED(hr)) {
294         FIXME("Cannot get IMediaPostion interface (hr = %x)\n", hr);
295         return MCIERR_INTERNAL;
296     }
297
298     hr = IMediaPosition_put_CurrentPosition(pmpos, newpos);
299     if (FAILED(hr)) {
300         FIXME("Cannot set position (hr = %x)\n", hr);
301         IMediaPosition_Release(pmpos);
302         return MCIERR_INTERNAL;
303     }
304
305     IMediaPosition_Release(pmpos);
306
307     if (dwFlags & MCI_NOTIFY)
308         mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)), wDevID, MCI_NOTIFY_SUCCESSFUL);
309
310     return 0;
311 }
312
313 /***************************************************************************
314  *                              MCIQTZ_mciStop                  [internal]
315  */
316 static DWORD MCIQTZ_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
317 {
318     WINE_MCIQTZ* wma;
319     HRESULT hr;
320
321     TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
322
323     wma = MCIQTZ_mciGetOpenDev(wDevID);
324     if (!wma)
325         return MCIERR_INVALID_DEVICE_ID;
326
327     if (!wma->started)
328         return 0;
329
330     hr = IMediaControl_Stop(wma->pmctrl);
331     if (FAILED(hr)) {
332         TRACE("Cannot stop filtergraph (hr = %x)\n", hr);
333         return MCIERR_INTERNAL;
334     }
335
336     wma->started = FALSE;
337
338     return 0;
339 }
340
341 /***************************************************************************
342  *                              MCIQTZ_mciGetDevCaps            [internal]
343  */
344 static DWORD MCIQTZ_mciGetDevCaps(UINT wDevID, DWORD dwFlags, LPMCI_GETDEVCAPS_PARMS lpParms)
345 {
346     WINE_MCIQTZ* wma;
347
348     TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
349
350     if (!lpParms)
351         return MCIERR_NULL_PARAMETER_BLOCK;
352
353     wma = MCIQTZ_mciGetOpenDev(wDevID);
354     if (!wma)
355         return MCIERR_INVALID_DEVICE_ID;
356
357     if (!(dwFlags & MCI_GETDEVCAPS_ITEM))
358         return MCIERR_MISSING_PARAMETER;
359
360     switch (lpParms->dwItem) {
361         case MCI_GETDEVCAPS_CAN_RECORD:
362             lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
363             TRACE("MCI_GETDEVCAPS_CAN_RECORD = %08x\n", lpParms->dwReturn);
364             break;
365         case MCI_GETDEVCAPS_HAS_AUDIO:
366             lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
367             TRACE("MCI_GETDEVCAPS_HAS_AUDIO = %08x\n", lpParms->dwReturn);
368             break;
369         case MCI_GETDEVCAPS_HAS_VIDEO:
370             lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
371             TRACE("MCI_GETDEVCAPS_HAS_VIDEO = %08x\n", lpParms->dwReturn);
372             break;
373         case MCI_GETDEVCAPS_DEVICE_TYPE:
374             lpParms->dwReturn = MAKEMCIRESOURCE(MCI_DEVTYPE_DIGITAL_VIDEO, MCI_DEVTYPE_DIGITAL_VIDEO);
375             TRACE("MCI_GETDEVCAPS_DEVICE_TYPE = %08x\n", lpParms->dwReturn);
376             break;
377         case MCI_GETDEVCAPS_USES_FILES:
378             lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
379             TRACE("MCI_GETDEVCAPS_USES_FILES = %08x\n", lpParms->dwReturn);
380             break;
381         case MCI_GETDEVCAPS_COMPOUND_DEVICE:
382             lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
383             TRACE("MCI_GETDEVCAPS_COMPOUND_DEVICE = %08x\n", lpParms->dwReturn);
384             break;
385         case MCI_GETDEVCAPS_CAN_EJECT:
386             lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
387             TRACE("MCI_GETDEVCAPS_EJECT = %08x\n", lpParms->dwReturn);
388             break;
389         case MCI_GETDEVCAPS_CAN_PLAY:
390             lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
391             TRACE("MCI_GETDEVCAPS_CAN_PLAY = %08x\n", lpParms->dwReturn);
392             break;
393         case MCI_GETDEVCAPS_CAN_SAVE:
394             lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
395             TRACE("MCI_GETDEVCAPS_CAN_SAVE = %08x\n", lpParms->dwReturn);
396             break;
397         case MCI_DGV_GETDEVCAPS_CAN_REVERSE:
398             lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
399             TRACE("MCI_DGV_GETDEVCAPS_CAN_REVERSE = %08x\n", lpParms->dwReturn);
400             break;
401         case MCI_DGV_GETDEVCAPS_CAN_STRETCH:
402             lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE); /* FIXME */
403             TRACE("MCI_DGV_GETDEVCAPS_CAN_STRETCH = %08x\n", lpParms->dwReturn);
404             break;
405         case MCI_DGV_GETDEVCAPS_CAN_LOCK:
406             lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
407             TRACE("MCI_DGV_GETDEVCAPS_CAN_LOCK = %08x\n", lpParms->dwReturn);
408             break;
409         case MCI_DGV_GETDEVCAPS_CAN_FREEZE:
410             lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
411             TRACE("MCI_DGV_GETDEVCAPS_CAN_FREEZE = %08x\n", lpParms->dwReturn);
412             break;
413         case MCI_DGV_GETDEVCAPS_CAN_STR_IN:
414             lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
415             TRACE("MCI_DGV_GETDEVCAPS_CAN_STRETCH_INPUT = %08x\n", lpParms->dwReturn);
416             break;
417         case MCI_DGV_GETDEVCAPS_HAS_STILL:
418             lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
419             TRACE("MCI_DGV_GETDEVCAPS_HAS_STILL = %08x\n", lpParms->dwReturn);
420             break;
421         case MCI_DGV_GETDEVCAPS_CAN_TEST:
422             lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE); /* FIXME */
423             TRACE("MCI_DGV_GETDEVCAPS_CAN_TEST = %08x\n", lpParms->dwReturn);
424             break;
425         case MCI_DGV_GETDEVCAPS_MAX_WINDOWS:
426             lpParms->dwReturn = 1;
427             TRACE("MCI_DGV_GETDEVCAPS_MAX_WINDOWS = %u\n", lpParms->dwReturn);
428             return 0;
429         default:
430             WARN("Unknown capability %08x\n", lpParms->dwItem);
431             /* Fall through */
432         case MCI_DGV_GETDEVCAPS_MAXIMUM_RATE: /* unknown to w2k */
433         case MCI_DGV_GETDEVCAPS_MINIMUM_RATE: /* unknown to w2k */
434             return MCIERR_UNSUPPORTED_FUNCTION;
435     }
436
437     return MCI_RESOURCE_RETURNED;
438 }
439
440 /***************************************************************************
441  *                              MCIQTZ_mciSet                   [internal]
442  */
443 static DWORD MCIQTZ_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SET_PARMS lpParms)
444 {
445     WINE_MCIQTZ* wma;
446
447     TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
448
449     if (!lpParms)
450         return MCIERR_NULL_PARAMETER_BLOCK;
451
452     wma = MCIQTZ_mciGetOpenDev(wDevID);
453     if (!wma)
454         return MCIERR_INVALID_DEVICE_ID;
455
456     if (dwFlags & MCI_SET_TIME_FORMAT) {
457         switch (lpParms->dwTimeFormat) {
458             case MCI_FORMAT_MILLISECONDS:
459                 TRACE("MCI_SET_TIME_FORMAT = MCI_FORMAT_MILLISECONDS\n");
460                 wma->time_format = MCI_FORMAT_MILLISECONDS;
461                 break;
462             case MCI_FORMAT_FRAMES:
463                 TRACE("MCI_SET_TIME_FORMAT = MCI_FORMAT_FRAMES\n");
464                 wma->time_format = MCI_FORMAT_FRAMES;
465                 break;
466             default:
467                 WARN("Bad time format %u\n", lpParms->dwTimeFormat);
468                 return MCIERR_BAD_TIME_FORMAT;
469         }
470     }
471
472     if (dwFlags & MCI_SET_DOOR_OPEN)
473         FIXME("MCI_SET_DOOR_OPEN not implemented yet\n");
474     if (dwFlags & MCI_SET_DOOR_CLOSED)
475         FIXME("MCI_SET_DOOR_CLOSED not implemented yet\n");
476     if (dwFlags & MCI_SET_AUDIO)
477         FIXME("MCI_SET_AUDIO not implemented yet\n");
478     if (dwFlags & MCI_SET_VIDEO)
479         FIXME("MCI_SET_VIDEO not implemented yet\n");
480     if (dwFlags & MCI_SET_ON)
481         FIXME("MCI_SET_ON not implemented yet\n");
482     if (dwFlags & MCI_SET_OFF)
483         FIXME("MCI_SET_OFF not implemented yet\n");
484     if (dwFlags & MCI_SET_AUDIO_LEFT)
485         FIXME("MCI_SET_AUDIO_LEFT not implemented yet\n");
486     if (dwFlags & MCI_SET_AUDIO_RIGHT)
487         FIXME("MCI_SET_AUDIO_RIGHT not implemented yet\n");
488
489     if (dwFlags & ~0x7f03 /* All MCI_SET flags mask */)
490         ERR("Unknown flags %08x\n", dwFlags & ~0x7f03);
491
492     return 0;
493 }
494
495 /***************************************************************************
496  *                              MCIQTZ_mciStatus                [internal]
497  */
498 static DWORD MCIQTZ_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_DGV_STATUS_PARMSW lpParms)
499 {
500     WINE_MCIQTZ* wma;
501
502     TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
503
504     if (!lpParms)
505         return MCIERR_NULL_PARAMETER_BLOCK;
506
507     wma = MCIQTZ_mciGetOpenDev(wDevID);
508     if (!wma)
509         return MCIERR_INVALID_DEVICE_ID;
510
511     if (!(dwFlags & MCI_STATUS_ITEM)) {
512         WARN("No status item specified\n");
513         return MCIERR_UNRECOGNIZED_COMMAND;
514     }
515
516     switch (lpParms->dwItem) {
517         case MCI_STATUS_LENGTH:
518             FIXME("MCI_STATUS_LENGTH not implemented yet\n");
519             return MCIERR_UNRECOGNIZED_COMMAND;
520         case MCI_STATUS_POSITION:
521         {
522             HRESULT hr;
523             REFTIME curpos;
524             IMediaPosition* pmpos;
525
526             hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaPosition, (LPVOID*)&pmpos);
527             if (FAILED(hr)) {
528                 FIXME("Cannot get IMediaPostion interface (hr = %x)\n", hr);
529                 return MCIERR_INTERNAL;
530             }
531
532             hr = IMediaPosition_get_CurrentPosition(pmpos, &curpos);
533             if (FAILED(hr)) {
534                 FIXME("Cannot get position (hr = %x)\n", hr);
535                 IMediaPosition_Release(pmpos);
536                 return MCIERR_INTERNAL;
537             }
538
539             IMediaPosition_Release(pmpos);
540             lpParms->dwReturn = curpos / 10000;
541
542             break;
543         }
544         case MCI_STATUS_NUMBER_OF_TRACKS:
545             FIXME("MCI_STATUS_NUMBER_OF_TRACKS not implemented yet\n");
546             return MCIERR_UNRECOGNIZED_COMMAND;
547         case MCI_STATUS_MODE:
548             FIXME("MCI_STATUS_MODE not implemented yet\n");
549             return MCIERR_UNRECOGNIZED_COMMAND;
550         case MCI_STATUS_MEDIA_PRESENT:
551             FIXME("MCI_STATUS_MEDIA_PRESENT not implemented yet\n");
552             return MCIERR_UNRECOGNIZED_COMMAND;
553         case MCI_STATUS_TIME_FORMAT:
554             FIXME("MCI_STATUS_TIME_FORMAT not implemented yet\n");
555             return MCIERR_UNRECOGNIZED_COMMAND;
556         case MCI_STATUS_READY:
557             FIXME("MCI_STATUS_READY not implemented yet\n");
558             return MCIERR_UNRECOGNIZED_COMMAND;
559         case MCI_STATUS_CURRENT_TRACK:
560             FIXME("MCI_STATUS_CURRENT_TRACK not implemented yet\n");
561             return MCIERR_UNRECOGNIZED_COMMAND;
562         default:
563             FIXME("Unknown command %08X\n", lpParms->dwItem);
564             return MCIERR_UNRECOGNIZED_COMMAND;
565     }
566
567     if (dwFlags & MCI_NOTIFY)
568         mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)), wDevID, MCI_NOTIFY_SUCCESSFUL);
569
570     return 0;
571 }
572
573 /***************************************************************************
574  *                              MCIQTZ_mciWhere                 [internal]
575  */
576 static DWORD MCIQTZ_mciWhere(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
577 {
578     WINE_MCIQTZ* wma;
579     IVideoWindow* pVideoWindow;
580     HRESULT hr;
581     HWND hWnd;
582     RECT rc;
583
584     TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
585
586     if (!lpParms)
587         return MCIERR_NULL_PARAMETER_BLOCK;
588
589     wma = MCIQTZ_mciGetOpenDev(wDevID);
590     if (!wma)
591         return MCIERR_INVALID_DEVICE_ID;
592
593     /* Find if there is a video stream and get the display window */
594     hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
595     if (FAILED(hr)) {
596         ERR("Cannot get IVideoWindow interface (hr = %x)\n", hr);
597         return MCIERR_INTERNAL;
598     }
599
600     hr = IVideoWindow_get_Owner(pVideoWindow, (OAHWND*)&hWnd);
601     IVideoWindow_Release(pVideoWindow);
602     if (FAILED(hr)) {
603         TRACE("No video stream, returning no window error\n");
604         return MCIERR_NO_WINDOW;
605     }
606
607     if (dwFlags & MCI_DGV_WHERE_SOURCE) {
608         if (dwFlags & MCI_DGV_WHERE_MAX)
609             FIXME("MCI_DGV_WHERE_SOURCE_MAX not supported yet\n");
610         else
611             FIXME("MCI_DGV_WHERE_SOURCE not supported yet\n");
612         return MCIERR_UNRECOGNIZED_COMMAND;
613     }
614     if (dwFlags & MCI_DGV_WHERE_DESTINATION) {
615         if (dwFlags & MCI_DGV_WHERE_MAX) {
616             GetClientRect(hWnd, &rc);
617             TRACE("MCI_DGV_WHERE_DESTINATION_MAX %s\n", wine_dbgstr_rect(&rc));
618         } else {
619             FIXME("MCI_DGV_WHERE_DESTINATION not supported yet\n");
620             return MCIERR_UNRECOGNIZED_COMMAND;
621         }
622     }
623     if (dwFlags & MCI_DGV_WHERE_FRAME) {
624         if (dwFlags & MCI_DGV_WHERE_MAX)
625             FIXME("MCI_DGV_WHERE_FRAME_MAX not supported yet\n");
626         else
627             FIXME("MCI_DGV_WHERE_FRAME not supported yet\n");
628         return MCIERR_UNRECOGNIZED_COMMAND;
629     }
630     if (dwFlags & MCI_DGV_WHERE_VIDEO) {
631         if (dwFlags & MCI_DGV_WHERE_MAX)
632             FIXME("MCI_DGV_WHERE_VIDEO_MAX not supported yet\n");
633         else
634             FIXME("MCI_DGV_WHERE_VIDEO not supported yet\n");
635         return MCIERR_UNRECOGNIZED_COMMAND;
636     }
637     if (dwFlags & MCI_DGV_WHERE_WINDOW) {
638         if (dwFlags & MCI_DGV_WHERE_MAX) {
639             GetWindowRect(GetDesktopWindow(), &rc);
640             TRACE("MCI_DGV_WHERE_WINDOW_MAX %s\n", wine_dbgstr_rect(&rc));
641         } else {
642             GetWindowRect(hWnd, &rc);
643             TRACE("MCI_DGV_WHERE_WINDOW %s\n", wine_dbgstr_rect(&rc));
644         }
645     }
646
647     /* In MCI, RECT structure is used differently: rc.right = width & rc.bottom = height
648      * So convert the normal RECT into a MCI RECT before returning */
649     lpParms->rc.left = rc.left;
650     lpParms->rc.top = rc.right;
651     lpParms->rc.right = rc.right - rc.left;
652     lpParms->rc.bottom = rc.bottom - rc.top;
653
654     return 0;
655 }
656
657 /***************************************************************************
658  *                              MCIQTZ_mciSetAudio              [internal]
659  */
660 static DWORD MCIQTZ_mciSetAudio(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SETAUDIO_PARMSW lpParms)
661 {
662     WINE_MCIQTZ *wma;
663
664     FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
665
666     if (!lpParms)
667         return MCIERR_NULL_PARAMETER_BLOCK;
668
669     wma = MCIQTZ_mciGetOpenDev(wDevID);
670     if (!wma)
671         return MCIERR_INVALID_DEVICE_ID;
672
673     MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
674
675     return 0;
676 }
677
678 /*======================================================================*
679  *                          MCI QTZ entry points                        *
680  *======================================================================*/
681
682 /**************************************************************************
683  *                              DriverProc (MCIQTZ.@)
684  */
685 LRESULT CALLBACK MCIQTZ_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
686                                    LPARAM dwParam1, LPARAM dwParam2)
687 {
688     TRACE("(%08lX, %p, %08X, %08lX, %08lX)\n",
689           dwDevID, hDriv, wMsg, dwParam1, dwParam2);
690
691     switch (wMsg) {
692         case DRV_LOAD:                  return 1;
693         case DRV_FREE:                  return 1;
694         case DRV_OPEN:                  return MCIQTZ_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
695         case DRV_CLOSE:                 return MCIQTZ_drvClose(dwDevID);
696         case DRV_ENABLE:                return 1;
697         case DRV_DISABLE:               return 1;
698         case DRV_QUERYCONFIGURE:        return 1;
699         case DRV_CONFIGURE:             return MCIQTZ_drvConfigure(dwDevID);
700         case DRV_INSTALL:               return DRVCNF_RESTART;
701         case DRV_REMOVE:                return DRVCNF_RESTART;
702     }
703
704     /* session instance */
705     if (dwDevID == 0xFFFFFFFF)
706         return 1;
707
708     switch (wMsg) {
709         case MCI_OPEN_DRIVER:   return MCIQTZ_mciOpen      (dwDevID, dwParam1, (LPMCI_DGV_OPEN_PARMSW)     dwParam2);
710         case MCI_CLOSE_DRIVER:  return MCIQTZ_mciClose     (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)       dwParam2);
711         case MCI_PLAY:          return MCIQTZ_mciPlay      (dwDevID, dwParam1, (LPMCI_PLAY_PARMS)          dwParam2);
712         case MCI_SEEK:          return MCIQTZ_mciSeek      (dwDevID, dwParam1, (LPMCI_SEEK_PARMS)          dwParam2);
713         case MCI_STOP:          return MCIQTZ_mciStop      (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)       dwParam2);
714         case MCI_GETDEVCAPS:    return MCIQTZ_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)    dwParam2);
715         case MCI_SET:           return MCIQTZ_mciSet       (dwDevID, dwParam1, (LPMCI_DGV_SET_PARMS)       dwParam2);
716         case MCI_STATUS:        return MCIQTZ_mciStatus    (dwDevID, dwParam1, (LPMCI_DGV_STATUS_PARMSW)   dwParam2);
717         case MCI_WHERE:         return MCIQTZ_mciWhere     (dwDevID, dwParam1, (LPMCI_DGV_RECT_PARMS)      dwParam2);
718         /* Digital Video specific */
719         case MCI_SETAUDIO:      return MCIQTZ_mciSetAudio  (dwDevID, dwParam1, (LPMCI_DGV_SETAUDIO_PARMSW) dwParam2);
720         case MCI_RECORD:
721         case MCI_PAUSE:
722         case MCI_RESUME:
723         case MCI_INFO:
724         case MCI_PUT:
725         case MCI_WINDOW:
726         case MCI_LOAD:
727         case MCI_SAVE:
728         case MCI_FREEZE:
729         case MCI_REALIZE:
730         case MCI_UNFREEZE:
731         case MCI_UPDATE:
732         case MCI_STEP:
733         case MCI_COPY:
734         case MCI_CUT:
735         case MCI_DELETE:
736         case MCI_PASTE:
737         case MCI_CUE:
738         /* Digital Video specific */
739         case MCI_CAPTURE:
740         case MCI_MONITOR:
741         case MCI_RESERVE:
742         case MCI_SIGNAL:
743         case MCI_SETVIDEO:
744         case MCI_QUALITY:
745         case MCI_LIST:
746         case MCI_UNDO:
747         case MCI_CONFIGURE:
748         case MCI_RESTORE:
749             FIXME("Unimplemented command [%08X]\n", wMsg);
750             break;
751         case MCI_SPIN:
752         case MCI_ESCAPE:
753             WARN("Unsupported command [%08X]\n", wMsg);
754             break;
755         case MCI_OPEN:
756         case MCI_CLOSE:
757             FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
758             break;
759         default:
760             TRACE("Sending msg [%08X] to default driver proc\n", wMsg);
761             return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
762     }
763
764     return MCIERR_UNRECOGNIZED_COMMAND;
765 }