push d49b3885cdb0e58b792f6bf912143b7a9a4ea546
[wine/hacks.git] / dlls / mciqtz32 / mciqtz.c
blobea3a9f7f568b2c0b464898213f29d9f66488610f
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"
30 WINE_DEFAULT_DEBUG_CHANNEL(mciqtz);
32 static DWORD MCIQTZ_mciClose(UINT, DWORD, LPMCI_GENERIC_PARMS);
33 static DWORD MCIQTZ_mciStop(UINT, DWORD, LPMCI_GENERIC_PARMS);
35 /*======================================================================*
36 * MCI QTZ implementation *
37 *======================================================================*/
39 HINSTANCE MCIQTZ_hInstance = 0;
41 /***********************************************************************
42 * DllMain (MCIQTZ.0)
44 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
46 switch (fdwReason) {
47 case DLL_PROCESS_ATTACH:
48 DisableThreadLibraryCalls(hInstDLL);
49 MCIQTZ_hInstance = hInstDLL;
50 break;
52 return TRUE;
55 /**************************************************************************
56 * MCIQTZ_drvOpen [internal]
58 static DWORD MCIQTZ_drvOpen(LPCWSTR str, LPMCI_OPEN_DRIVER_PARMSW modp)
60 WINE_MCIQTZ* wma;
62 TRACE("%s, %p\n", debugstr_w(str), modp);
64 /* session instance */
65 if (!modp)
66 return 0xFFFFFFFF;
68 wma = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCIQTZ));
69 if (!wma)
70 return 0;
72 wma->wDevID = modp->wDeviceID;
73 mciSetDriverData(wma->wDevID, (DWORD_PTR)wma);
75 return modp->wDeviceID;
78 /**************************************************************************
79 * MCIQTZ_drvClose [internal]
81 static DWORD MCIQTZ_drvClose(DWORD dwDevID)
83 WINE_MCIQTZ* wma;
85 TRACE("%04x\n", dwDevID);
87 /* finish all outstanding things */
88 MCIQTZ_mciClose(dwDevID, MCI_WAIT, NULL);
90 wma = (WINE_MCIQTZ*)mciGetDriverData(dwDevID);
92 if (wma) {
93 HeapFree(GetProcessHeap(), 0, wma);
94 return 1;
97 return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
100 /**************************************************************************
101 * MCIQTZ_drvConfigure [internal]
103 static DWORD MCIQTZ_drvConfigure(DWORD dwDevID)
105 WINE_MCIQTZ* wma;
107 TRACE("%04x\n", dwDevID);
109 MCIQTZ_mciStop(dwDevID, MCI_WAIT, NULL);
111 wma = (WINE_MCIQTZ*)mciGetDriverData(dwDevID);
113 if (wma) {
114 MessageBoxA(0, "Sample QTZ Wine Driver !", "MM-Wine Driver", MB_OK);
115 return 1;
118 return 0;
121 /**************************************************************************
122 * MCIQTZ_mciGetOpenDev [internal]
124 static WINE_MCIQTZ* MCIQTZ_mciGetOpenDev(UINT wDevID)
126 WINE_MCIQTZ* wma = (WINE_MCIQTZ*)mciGetDriverData(wDevID);
128 if (!wma) {
129 WARN("Invalid wDevID=%u\n", wDevID);
130 return 0;
132 return wma;
135 /***************************************************************************
136 * MCIQTZ_mciOpen [internal]
138 static DWORD MCIQTZ_mciOpen(UINT wDevID, DWORD dwFlags,
139 LPMCI_DGV_OPEN_PARMSW lpOpenParms)
141 WINE_MCIQTZ* wma;
142 HRESULT hr;
144 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpOpenParms);
146 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
148 if (!lpOpenParms)
149 return MCIERR_NULL_PARAMETER_BLOCK;
151 wma = (WINE_MCIQTZ*)mciGetDriverData(wDevID);
152 if (!wma)
153 return MCIERR_INVALID_DEVICE_ID;
155 CoInitializeEx(NULL, COINIT_MULTITHREADED);
157 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&wma->pgraph);
158 if (FAILED(hr)) {
159 TRACE("Cannot create filtergraph (hr = %x)\n", hr);
160 goto err;
163 hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaControl, (LPVOID*)&wma->pmctrl);
164 if (FAILED(hr)) {
165 TRACE("Cannot get IMediaControl interface (hr = %x)\n", hr);
166 goto err;
169 if (!((dwFlags & MCI_OPEN_ELEMENT) && (dwFlags & MCI_OPEN_ELEMENT))) {
170 TRACE("Wrong dwFlags %x\n", dwFlags);
171 goto err;
174 if (!lpOpenParms->lpstrElementName && !lstrlenW(lpOpenParms->lpstrElementName)) {
175 TRACE("Invalid filename specified\n");
176 goto err;
179 TRACE("Open file %s\n", debugstr_w(lpOpenParms->lpstrElementName));
181 hr = IGraphBuilder_RenderFile(wma->pgraph, lpOpenParms->lpstrElementName, NULL);
182 if (FAILED(hr)) {
183 TRACE("Cannot render file (hr = %x)\n", hr);
184 goto err;
187 return 0;
189 err:
190 if (wma->pgraph)
191 IGraphBuilder_Release(wma->pgraph);
192 wma->pgraph = NULL;
193 if (wma->pmctrl)
194 IMediaControl_Release(wma->pmctrl);
195 wma->pmctrl = NULL;
197 CoUninitialize();
199 return MCIERR_INTERNAL;
202 /***************************************************************************
203 * MCIQTZ_mciClose [internal]
205 static DWORD MCIQTZ_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
207 WINE_MCIQTZ* wma;
209 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
211 MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL);
213 wma = MCIQTZ_mciGetOpenDev(wDevID);
214 if (!wma)
215 return MCIERR_INVALID_DEVICE_ID;
217 if (wma->pgraph)
218 IGraphBuilder_Release(wma->pgraph);
219 wma->pgraph = NULL;
220 if (wma->pmctrl)
221 IMediaControl_Release(wma->pmctrl);
222 wma->pmctrl = NULL;
224 CoUninitialize();
226 return 0;
229 /***************************************************************************
230 * MCIQTZ_mciPlay [internal]
232 static DWORD MCIQTZ_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
234 WINE_MCIQTZ* wma;
235 HRESULT hr;
237 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
239 if (!lpParms)
240 return MCIERR_NULL_PARAMETER_BLOCK;
242 wma = MCIQTZ_mciGetOpenDev(wDevID);
244 hr = IMediaControl_Run(wma->pmctrl);
245 if (FAILED(hr)) {
246 TRACE("Cannot run filtergraph (hr = %x)\n", hr);
247 return MCIERR_INTERNAL;
250 wma->started = TRUE;
252 return 0;
255 /***************************************************************************
256 * MCIQTZ_mciStop [internal]
258 static DWORD MCIQTZ_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
260 WINE_MCIQTZ* wma;
261 HRESULT hr;
263 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
265 wma = MCIQTZ_mciGetOpenDev(wDevID);
266 if (!wma)
267 return MCIERR_INVALID_DEVICE_ID;
269 if (!wma->started)
270 return 0;
272 hr = IMediaControl_Stop(wma->pmctrl);
273 if (FAILED(hr)) {
274 TRACE("Cannot stop filtergraph (hr = %x)\n", hr);
275 return MCIERR_INTERNAL;
278 wma->started = FALSE;
280 return 0;
283 /*======================================================================*
284 * MCI QTZ entry points *
285 *======================================================================*/
287 /**************************************************************************
288 * DriverProc (MCIQTZ.@)
290 LRESULT CALLBACK MCIQTZ_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
291 LPARAM dwParam1, LPARAM dwParam2)
293 TRACE("(%08lX, %p, %08X, %08lX, %08lX)\n",
294 dwDevID, hDriv, wMsg, dwParam1, dwParam2);
296 switch (wMsg) {
297 case DRV_LOAD: return 1;
298 case DRV_FREE: return 1;
299 case DRV_OPEN: return MCIQTZ_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
300 case DRV_CLOSE: return MCIQTZ_drvClose(dwDevID);
301 case DRV_ENABLE: return 1;
302 case DRV_DISABLE: return 1;
303 case DRV_QUERYCONFIGURE: return 1;
304 case DRV_CONFIGURE: return MCIQTZ_drvConfigure(dwDevID);
305 case DRV_INSTALL: return DRVCNF_RESTART;
306 case DRV_REMOVE: return DRVCNF_RESTART;
309 /* session instance */
310 if (dwDevID == 0xFFFFFFFF)
311 return 1;
313 switch (wMsg) {
314 case MCI_OPEN_DRIVER: return MCIQTZ_mciOpen (dwDevID, dwParam1, (LPMCI_DGV_OPEN_PARMSW) dwParam2);
315 case MCI_CLOSE_DRIVER: return MCIQTZ_mciClose (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
316 case MCI_PLAY: return MCIQTZ_mciPlay (dwDevID, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
317 case MCI_RECORD:
318 case MCI_STOP:
319 case MCI_SET:
320 case MCI_PAUSE:
321 case MCI_RESUME:
322 case MCI_STATUS:
323 case MCI_GETDEVCAPS:
324 case MCI_INFO:
325 case MCI_SEEK:
326 case MCI_PUT:
327 case MCI_WINDOW:
328 case MCI_LOAD:
329 case MCI_SAVE:
330 case MCI_FREEZE:
331 case MCI_REALIZE:
332 case MCI_UNFREEZE:
333 case MCI_UPDATE:
334 case MCI_WHERE:
335 case MCI_STEP:
336 case MCI_COPY:
337 case MCI_CUT:
338 case MCI_DELETE:
339 case MCI_PASTE:
340 case MCI_CUE:
341 /* Digital Video specific */
342 case MCI_CAPTURE:
343 case MCI_MONITOR:
344 case MCI_RESERVE:
345 case MCI_SETAUDIO:
346 case MCI_SIGNAL:
347 case MCI_SETVIDEO:
348 case MCI_QUALITY:
349 case MCI_LIST:
350 case MCI_UNDO:
351 case MCI_CONFIGURE:
352 case MCI_RESTORE:
353 FIXME("Unimplemented command [%u]\n", wMsg);
354 break;
355 case MCI_SPIN:
356 case MCI_ESCAPE:
357 WARN("Unsupported command [%u]\n", wMsg);
358 break;
359 case MCI_OPEN:
360 case MCI_CLOSE:
361 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
362 break;
363 default:
364 TRACE("Sending msg [%u] to default driver proc\n", wMsg);
365 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
368 return MCIERR_UNRECOGNIZED_COMMAND;