2 * Digital video MCI Wine Driver
4 * Copyright 1999, 2000 Eric POUECH
5 * Copyright 2003 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * - handling of palettes
24 * - recording (which input devices ?), a cam recorder ?
25 * - lots of messages still need to be handled (cf FIXME)
26 * - synchronization between audio and video (especially for interleaved
28 * - robustness when reading file can be enhanced
29 * - reimplement the AVI handling part with avifile DLL because
30 * "open @1122334 type avivideo alias a" expects an AVIFile/Stream
31 * and MCI_DGV_SET|STATUS_SPEED maps to Rate/Scale
32 * - some files appear to have more than one audio stream (we only play the
34 * - some files contain an index of audio/video frame. Better use it,
35 * instead of rebuilding it (AVIFile does that already)
36 * - stopping while playing a file with sound blocks until all buffered
37 * audio is played... still should be stopped ASAP
41 #include "private_mciavi.h"
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(mciavi
);
47 static DWORD
MCIAVI_mciStop(UINT
, DWORD
, LPMCI_GENERIC_PARMS
);
49 /*======================================================================*
50 * MCI AVI implementation *
51 *======================================================================*/
53 HINSTANCE MCIAVI_hInstance
= 0;
55 /***********************************************************************
58 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID fImpLoad
)
61 case DLL_PROCESS_ATTACH
:
62 DisableThreadLibraryCalls(hInstDLL
);
63 MCIAVI_hInstance
= hInstDLL
;
69 /**************************************************************************
70 * MCIAVI_drvOpen [internal]
72 static DWORD
MCIAVI_drvOpen(LPCWSTR str
, LPMCI_OPEN_DRIVER_PARMSW modp
)
75 static const WCHAR mciAviWStr
[] = {'M','C','I','A','V','I',0};
77 TRACE("%s, %p\n", debugstr_w(str
), modp
);
79 /* session instance */
80 if (!modp
) return 0xFFFFFFFF;
82 if (!MCIAVI_RegisterClass()) return 0;
84 wma
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINE_MCIAVI
));
88 InitializeCriticalSection(&wma
->cs
);
89 wma
->cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": WINE_MCIAVI.cs");
90 wma
->hStopEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
91 wma
->wDevID
= modp
->wDeviceID
;
92 wma
->wCommandTable
= mciLoadCommandResource(MCIAVI_hInstance
, mciAviWStr
, 0);
93 wma
->dwStatus
= MCI_MODE_NOT_READY
;
94 modp
->wCustomCommandTable
= wma
->wCommandTable
;
95 modp
->wType
= MCI_DEVTYPE_DIGITAL_VIDEO
;
96 mciSetDriverData(wma
->wDevID
, (DWORD_PTR
)wma
);
98 return modp
->wDeviceID
;
101 /**************************************************************************
102 * MCIAVI_drvClose [internal]
104 static DWORD
MCIAVI_drvClose(DWORD dwDevID
)
108 TRACE("%04x\n", dwDevID
);
110 /* finish all outstanding things */
111 MCIAVI_mciClose(dwDevID
, MCI_WAIT
, NULL
);
113 wma
= (WINE_MCIAVI
*)mciGetDriverData(dwDevID
);
116 MCIAVI_UnregisterClass();
118 EnterCriticalSection(&wma
->cs
);
120 mciSetDriverData(dwDevID
, 0);
121 mciFreeCommandResource(wma
->wCommandTable
);
123 CloseHandle(wma
->hStopEvent
);
125 LeaveCriticalSection(&wma
->cs
);
126 wma
->cs
.DebugInfo
->Spare
[0] = 0;
127 DeleteCriticalSection(&wma
->cs
);
129 HeapFree(GetProcessHeap(), 0, wma
);
132 return (dwDevID
== 0xFFFFFFFF) ? 1 : 0;
135 /**************************************************************************
136 * MCIAVI_drvConfigure [internal]
138 static DWORD
MCIAVI_drvConfigure(DWORD dwDevID
)
142 TRACE("%04x\n", dwDevID
);
144 MCIAVI_mciStop(dwDevID
, MCI_WAIT
, NULL
);
146 wma
= (WINE_MCIAVI
*)mciGetDriverData(dwDevID
);
149 MessageBoxA(0, "Sample AVI Wine Driver !", "MM-Wine Driver", MB_OK
);
155 /**************************************************************************
156 * MCIAVI_mciGetOpenDev [internal]
158 WINE_MCIAVI
* MCIAVI_mciGetOpenDev(UINT wDevID
)
160 WINE_MCIAVI
* wma
= (WINE_MCIAVI
*)mciGetDriverData(wDevID
);
162 if (wma
== NULL
|| wma
->nUseCount
== 0) {
163 WARN("Invalid wDevID=%u\n", wDevID
);
169 static void MCIAVI_CleanUp(WINE_MCIAVI
* wma
)
171 /* to prevent handling in WindowProc */
172 wma
->dwStatus
= MCI_MODE_NOT_READY
;
174 mmioClose(wma
->hFile
, 0);
177 HeapFree(GetProcessHeap(), 0, wma
->lpFileName
);
178 wma
->lpFileName
= NULL
;
180 HeapFree(GetProcessHeap(), 0, wma
->lpVideoIndex
);
181 wma
->lpVideoIndex
= NULL
;
182 HeapFree(GetProcessHeap(), 0, wma
->lpAudioIndex
);
183 wma
->lpAudioIndex
= NULL
;
184 if (wma
->hic
) ICClose(wma
->hic
);
186 HeapFree(GetProcessHeap(), 0, wma
->inbih
);
188 HeapFree(GetProcessHeap(), 0, wma
->outbih
);
190 HeapFree(GetProcessHeap(), 0, wma
->indata
);
192 HeapFree(GetProcessHeap(), 0, wma
->outdata
);
194 if (wma
->hbmFrame
) DeleteObject(wma
->hbmFrame
);
196 if (wma
->hWnd
) DestroyWindow(wma
->hWnd
);
199 HeapFree(GetProcessHeap(), 0, wma
->lpWaveFormat
);
200 wma
->lpWaveFormat
= 0;
202 memset(&wma
->mah
, 0, sizeof(wma
->mah
));
203 memset(&wma
->ash_video
, 0, sizeof(wma
->ash_video
));
204 memset(&wma
->ash_audio
, 0, sizeof(wma
->ash_audio
));
205 wma
->dwCurrVideoFrame
= wma
->dwCurrAudioBlock
= 0;
206 wma
->dwCachedFrame
= -1;
210 /***************************************************************************
211 * MCIAVI_mciOpen [internal]
213 static DWORD
MCIAVI_mciOpen(UINT wDevID
, DWORD dwFlags
,
214 LPMCI_DGV_OPEN_PARMSW lpOpenParms
)
219 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpOpenParms
);
221 if (lpOpenParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
223 wma
= (WINE_MCIAVI
*)mciGetDriverData(wDevID
);
224 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
226 EnterCriticalSection(&wma
->cs
);
228 if (wma
->nUseCount
> 0) {
229 /* The driver is already open on this channel */
230 /* If the driver was opened shareable before and this open specifies */
231 /* shareable then increment the use count */
232 if (wma
->fShareable
&& (dwFlags
& MCI_OPEN_SHAREABLE
))
236 LeaveCriticalSection(&wma
->cs
);
237 return MCIERR_MUST_USE_SHAREABLE
;
241 wma
->fShareable
= dwFlags
& MCI_OPEN_SHAREABLE
;
244 wma
->dwStatus
= MCI_MODE_NOT_READY
;
246 if (dwFlags
& MCI_OPEN_ELEMENT
) {
247 if (dwFlags
& MCI_OPEN_ELEMENT_ID
) {
248 /* could it be that (DWORD)lpOpenParms->lpstrElementName
249 * contains the hFile value ?
251 dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
252 } else if (lpOpenParms
->lpstrElementName
&& lpOpenParms
->lpstrElementName
[0]) {
253 /* FIXME : what should be done id wma->hFile is already != 0, or the driver is playin' */
254 TRACE("MCI_OPEN_ELEMENT %s!\n", debugstr_w(lpOpenParms
->lpstrElementName
));
256 wma
->lpFileName
= HeapAlloc(GetProcessHeap(), 0, (strlenW(lpOpenParms
->lpstrElementName
) + 1) * sizeof(WCHAR
));
257 strcpyW(wma
->lpFileName
, lpOpenParms
->lpstrElementName
);
259 if (lpOpenParms
->lpstrElementName
[0] == '@') {
260 /* The file name @11223344 encodes an AVIFile handle in decimal notation
261 * in Win3.1 and w2k/NT, but this feature is absent in win95 (KB140750).
262 * wma->hFile = LongToHandle(strtolW(lpOpenParms->lpstrElementName+1, NULL, 10)); */
263 FIXME("Using AVIFile/Stream %s NIY\n", debugstr_w(lpOpenParms
->lpstrElementName
));
265 wma
->hFile
= mmioOpenW(lpOpenParms
->lpstrElementName
, NULL
,
266 MMIO_ALLOCBUF
| MMIO_DENYWRITE
| MMIO_READ
);
268 if (wma
->hFile
== 0) {
269 WARN("can't find file=%s!\n", debugstr_w(lpOpenParms
->lpstrElementName
));
270 dwRet
= MCIERR_FILE_NOT_FOUND
;
272 if (!MCIAVI_GetInfo(wma
))
273 dwRet
= MCIERR_INVALID_FILE
;
274 else if (!MCIAVI_OpenVideo(wma
))
275 dwRet
= MCIERR_CANNOT_LOAD_DRIVER
;
276 else if (!MCIAVI_CreateWindow(wma
, dwFlags
, lpOpenParms
))
277 dwRet
= MCIERR_CREATEWINDOW
;
280 FIXME("Don't record yet\n");
281 dwRet
= MCIERR_UNSUPPORTED_FUNCTION
;
286 TRACE("lpOpenParms->wDeviceID = %04x\n", lpOpenParms
->wDeviceID
);
288 wma
->dwStatus
= MCI_MODE_STOP
;
289 wma
->dwMciTimeFormat
= MCI_FORMAT_FRAMES
;
294 LeaveCriticalSection(&wma
->cs
);
296 if (!dwRet
&& (dwFlags
& MCI_NOTIFY
)) {
297 mciDriverNotify(HWND_32(LOWORD(lpOpenParms
->dwCallback
)),
298 wDevID
, MCI_NOTIFY_SUCCESSFUL
);
303 /***************************************************************************
304 * MCIAVI_mciClose [internal]
306 DWORD
MCIAVI_mciClose(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
311 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
313 wma
= MCIAVI_mciGetOpenDev(wDevID
);
314 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
316 MCIAVI_mciStop(wDevID
, MCI_WAIT
, NULL
);
318 EnterCriticalSection(&wma
->cs
);
320 if (wma
->nUseCount
== 1) {
323 if ((dwFlags
& MCI_NOTIFY
) && lpParms
) {
324 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
326 MCI_NOTIFY_SUCCESSFUL
);
328 LeaveCriticalSection(&wma
->cs
);
333 LeaveCriticalSection(&wma
->cs
);
337 static double currenttime_us(void)
339 LARGE_INTEGER lc
, lf
;
340 QueryPerformanceCounter(&lc
);
341 QueryPerformanceFrequency(&lf
);
342 return (lc
.QuadPart
* 1000000) / lf
.QuadPart
;
345 /***************************************************************************
346 * MCIAVI_player [internal]
348 static DWORD
MCIAVI_player(WINE_MCIAVI
*wma
, DWORD dwFlags
, LPMCI_PLAY_PARMS lpParms
)
351 LPWAVEHDR waveHdr
= NULL
;
352 unsigned i
, nHdr
= 0;
355 double next_frame_us
;
357 EnterCriticalSection(&wma
->cs
);
359 if (wma
->dwToVideoFrame
<= wma
->dwCurrVideoFrame
)
365 events
[0] = wma
->hStopEvent
;
366 if (wma
->lpWaveFormat
) {
367 if (MCIAVI_OpenAudio(wma
, &nHdr
, &waveHdr
) != 0)
369 /* can't play audio */
370 HeapFree(GetProcessHeap(), 0, wma
->lpWaveFormat
);
371 wma
->lpWaveFormat
= NULL
;
375 /* fill the queue with as many wave headers as possible */
376 MCIAVI_PlayAudioBlocks(wma
, nHdr
, waveHdr
);
377 events
[1] = wma
->hEvent
;
382 next_frame_us
= currenttime_us();
383 while (wma
->dwStatus
== MCI_MODE_PLAY
)
389 tc
= currenttime_us();
391 hDC
= wma
->hWndPaint
? GetDC(wma
->hWndPaint
) : 0;
394 while(next_frame_us
<= tc
&& wma
->dwCurrVideoFrame
< wma
->dwToVideoFrame
){
396 dur
= MCIAVI_PaintFrame(wma
, hDC
);
397 ++wma
->dwCurrVideoFrame
;
400 next_frame_us
+= dur
;
401 TRACE("next_frame: %f\n", next_frame_us
);
403 ReleaseDC(wma
->hWndPaint
, hDC
);
405 if (wma
->dwCurrVideoFrame
>= wma
->dwToVideoFrame
)
407 if (!(dwFlags
& MCI_DGV_PLAY_REPEAT
))
409 TRACE("repeat media as requested\n");
410 wma
->dwCurrVideoFrame
= wma
->dwCurrAudioBlock
= 0;
413 if (wma
->lpWaveFormat
)
414 MCIAVI_PlayAudioBlocks(wma
, nHdr
, waveHdr
);
416 tc
= currenttime_us();
417 if (tc
< next_frame_us
)
418 delta
= next_frame_us
- tc
;
422 LeaveCriticalSection(&wma
->cs
);
423 ret
= WaitForMultipleObjects(numEvents
, events
, FALSE
, delta
/ 1000);
424 EnterCriticalSection(&wma
->cs
);
425 if (ret
== WAIT_OBJECT_0
|| wma
->dwStatus
!= MCI_MODE_PLAY
) break;
428 if (wma
->lpWaveFormat
) {
429 while (wma
->dwEventCount
!= nHdr
- 1)
431 LeaveCriticalSection(&wma
->cs
);
433 EnterCriticalSection(&wma
->cs
);
436 /* just to get rid of some race conditions between play, stop and pause */
437 LeaveCriticalSection(&wma
->cs
);
438 waveOutReset(wma
->hWave
);
439 EnterCriticalSection(&wma
->cs
);
441 for (i
= 0; i
< nHdr
; i
++)
442 waveOutUnprepareHeader(wma
->hWave
, &waveHdr
[i
], sizeof(WAVEHDR
));
447 if (wma
->lpWaveFormat
) {
448 HeapFree(GetProcessHeap(), 0, waveHdr
);
451 LeaveCriticalSection(&wma
->cs
);
452 waveOutClose(wma
->hWave
);
453 EnterCriticalSection(&wma
->cs
);
456 CloseHandle(wma
->hEvent
);
460 wma
->dwStatus
= MCI_MODE_STOP
;
462 if (dwFlags
& MCI_NOTIFY
) {
463 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
464 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
465 wma
->wDevID
, MCI_NOTIFY_SUCCESSFUL
);
467 LeaveCriticalSection(&wma
->cs
);
471 struct MCIAVI_play_data
475 MCI_PLAY_PARMS params
; /* FIXME: notify via wma->hCallback like the other MCI drivers */
479 * MCIAVI_mciPlay_thread
481 * FIXME: probably should use a common worker thread created at the driver
482 * load time and queue all async commands to it.
484 static DWORD WINAPI
MCIAVI_mciPlay_thread(LPVOID arg
)
486 struct MCIAVI_play_data
*data
= (struct MCIAVI_play_data
*)arg
;
489 TRACE("In thread before async play command (id %u, flags %08x)\n", data
->wma
->wDevID
, data
->flags
);
490 ret
= MCIAVI_player(data
->wma
, data
->flags
, &data
->params
);
491 TRACE("In thread after async play command (id %u, flags %08x)\n", data
->wma
->wDevID
, data
->flags
);
493 HeapFree(GetProcessHeap(), 0, data
);
498 * MCIAVI_mciPlay_async
500 static DWORD
MCIAVI_mciPlay_async(WINE_MCIAVI
*wma
, DWORD dwFlags
, LPMCI_PLAY_PARMS lpParams
)
503 struct MCIAVI_play_data
*data
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct MCIAVI_play_data
));
505 if (!data
) return MCIERR_OUT_OF_MEMORY
;
508 data
->flags
= dwFlags
;
509 if (dwFlags
& MCI_NOTIFY
)
510 data
->params
.dwCallback
= lpParams
->dwCallback
;
512 if (!(handle
= CreateThread(NULL
, 0, MCIAVI_mciPlay_thread
, data
, 0, NULL
)))
514 WARN("Couldn't create thread for async play, playing synchronously\n");
515 return MCIAVI_mciPlay_thread(data
);
517 SetThreadPriority(handle
, THREAD_PRIORITY_TIME_CRITICAL
);
522 /***************************************************************************
523 * MCIAVI_mciPlay [internal]
525 static DWORD
MCIAVI_mciPlay(UINT wDevID
, DWORD dwFlags
, LPMCI_PLAY_PARMS lpParms
)
529 DWORD dwFromFrame
, dwToFrame
;
531 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
533 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
535 wma
= MCIAVI_mciGetOpenDev(wDevID
);
536 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
537 if (dwFlags
& MCI_DGV_PLAY_REVERSE
) return MCIERR_UNSUPPORTED_FUNCTION
;
538 if (dwFlags
& MCI_TEST
) return 0;
540 if (dwFlags
& (MCI_MCIAVI_PLAY_WINDOW
|MCI_MCIAVI_PLAY_FULLSCREEN
|MCI_MCIAVI_PLAY_FULLBY2
))
541 FIXME("Unsupported flag %08x\n", dwFlags
);
543 EnterCriticalSection(&wma
->cs
);
547 LeaveCriticalSection(&wma
->cs
);
548 return MCIERR_FILE_NOT_FOUND
;
552 LeaveCriticalSection(&wma
->cs
);
553 return MCIERR_NO_WINDOW
;
556 dwFromFrame
= wma
->dwCurrVideoFrame
;
557 dwToFrame
= wma
->dwPlayableVideoFrames
- 1;
559 if (dwFlags
& MCI_FROM
) {
560 dwFromFrame
= MCIAVI_ConvertTimeFormatToFrame(wma
, lpParms
->dwFrom
);
562 if (dwFlags
& MCI_TO
) {
563 dwToFrame
= MCIAVI_ConvertTimeFormatToFrame(wma
, lpParms
->dwTo
);
565 if (dwToFrame
>= wma
->dwPlayableVideoFrames
)
566 dwToFrame
= wma
->dwPlayableVideoFrames
- 1;
568 TRACE("Playing from frame=%u to frame=%u\n", dwFromFrame
, dwToFrame
);
570 wma
->dwCurrVideoFrame
= dwFromFrame
;
571 wma
->dwToVideoFrame
= dwToFrame
;
573 LeaveCriticalSection(&wma
->cs
);
575 if (!(GetWindowLongW(wma
->hWndPaint
, GWL_STYLE
) & WS_VISIBLE
))
576 ShowWindow(wma
->hWndPaint
, SW_SHOWNA
);
578 EnterCriticalSection(&wma
->cs
);
580 /* if already playing exit */
581 if (wma
->dwStatus
== MCI_MODE_PLAY
)
583 LeaveCriticalSection(&wma
->cs
);
587 wma
->dwStatus
= MCI_MODE_PLAY
;
589 LeaveCriticalSection(&wma
->cs
);
591 if (dwFlags
& MCI_WAIT
)
592 return MCIAVI_player(wma
, dwFlags
, lpParms
);
594 dwRet
= MCIAVI_mciPlay_async(wma
, dwFlags
, lpParms
);
597 EnterCriticalSection(&wma
->cs
);
598 wma
->dwStatus
= MCI_MODE_STOP
;
599 LeaveCriticalSection(&wma
->cs
);
604 /***************************************************************************
605 * MCIAVI_mciStop [internal]
607 static DWORD
MCIAVI_mciStop(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
612 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
614 wma
= MCIAVI_mciGetOpenDev(wDevID
);
615 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
616 if (dwFlags
& MCI_TEST
) return 0;
618 EnterCriticalSection(&wma
->cs
);
620 TRACE("current status %04x\n", wma
->dwStatus
);
622 switch (wma
->dwStatus
) {
624 case MCI_MODE_RECORD
:
625 LeaveCriticalSection(&wma
->cs
);
626 SetEvent(wma
->hStopEvent
);
627 EnterCriticalSection(&wma
->cs
);
630 /* Since our wave notification callback takes the lock,
631 * we must release it before resetting the device */
632 LeaveCriticalSection(&wma
->cs
);
633 dwRet
= waveOutReset(wma
->hWave
);
634 EnterCriticalSection(&wma
->cs
);
637 do /* one more chance for an async thread to finish */
639 LeaveCriticalSection(&wma
->cs
);
641 EnterCriticalSection(&wma
->cs
);
642 } while (wma
->dwStatus
!= MCI_MODE_STOP
);
646 case MCI_MODE_NOT_READY
:
650 if ((dwFlags
& MCI_NOTIFY
) && lpParms
) {
651 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
652 wDevID
, MCI_NOTIFY_SUCCESSFUL
);
654 LeaveCriticalSection(&wma
->cs
);
658 /***************************************************************************
659 * MCIAVI_mciPause [internal]
661 static DWORD
MCIAVI_mciPause(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
665 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
667 wma
= MCIAVI_mciGetOpenDev(wDevID
);
668 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
669 if (dwFlags
& MCI_TEST
) return 0;
671 EnterCriticalSection(&wma
->cs
);
673 if (wma
->dwStatus
== MCI_MODE_PLAY
)
674 wma
->dwStatus
= MCI_MODE_PAUSE
;
676 if (wma
->lpWaveFormat
) {
677 LeaveCriticalSection(&wma
->cs
);
678 return waveOutPause(wma
->hWave
);
681 LeaveCriticalSection(&wma
->cs
);
685 /***************************************************************************
686 * MCIAVI_mciResume [internal]
688 static DWORD
MCIAVI_mciResume(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
692 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
694 wma
= MCIAVI_mciGetOpenDev(wDevID
);
695 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
696 if (dwFlags
& MCI_TEST
) return 0;
698 EnterCriticalSection(&wma
->cs
);
700 if (wma
->dwStatus
== MCI_MODE_PAUSE
)
701 wma
->dwStatus
= MCI_MODE_PLAY
;
703 if (wma
->lpWaveFormat
) {
704 LeaveCriticalSection(&wma
->cs
);
705 return waveOutRestart(wma
->hWave
);
708 LeaveCriticalSection(&wma
->cs
);
712 /***************************************************************************
713 * MCIAVI_mciSeek [internal]
715 static DWORD
MCIAVI_mciSeek(UINT wDevID
, DWORD dwFlags
, LPMCI_SEEK_PARMS lpParms
)
720 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
722 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
724 wma
= MCIAVI_mciGetOpenDev(wDevID
);
725 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
727 position
= dwFlags
& (MCI_SEEK_TO_START
|MCI_SEEK_TO_END
|MCI_TO
);
728 if (!position
) return MCIERR_MISSING_PARAMETER
;
729 if (position
&(position
-1)) return MCIERR_FLAGS_NOT_COMPATIBLE
;
731 if (dwFlags
& MCI_TO
) {
732 position
= MCIAVI_ConvertTimeFormatToFrame(wma
, lpParms
->dwTo
);
733 if (position
>= wma
->dwPlayableVideoFrames
)
734 return MCIERR_OUTOFRANGE
;
735 } else if (dwFlags
& MCI_SEEK_TO_START
) {
738 position
= wma
->dwPlayableVideoFrames
- 1;
740 if (dwFlags
& MCI_TEST
) return 0;
742 MCIAVI_mciStop(wDevID
, MCI_WAIT
, NULL
);
744 EnterCriticalSection(&wma
->cs
);
746 wma
->dwCurrVideoFrame
= position
;
747 TRACE("Seeking to frame=%u\n", wma
->dwCurrVideoFrame
);
749 if (dwFlags
& MCI_NOTIFY
) {
750 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
751 wDevID
, MCI_NOTIFY_SUCCESSFUL
);
753 LeaveCriticalSection(&wma
->cs
);
757 /*****************************************************************************
758 * MCIAVI_mciLoad [internal]
760 static DWORD
MCIAVI_mciLoad(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_LOAD_PARMSW lpParms
)
764 FIXME("(%04x, %08x, %p) : stub\n", wDevID
, dwFlags
, lpParms
);
766 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
768 wma
= MCIAVI_mciGetOpenDev(wDevID
);
769 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
771 return MCIERR_UNSUPPORTED_FUNCTION
; /* like w2k */
774 /******************************************************************************
775 * MCIAVI_mciRealize [internal]
777 static DWORD
MCIAVI_mciRealize(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
781 FIXME("(%04x, %08x, %p) : stub\n", wDevID
, dwFlags
, lpParms
);
783 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
785 wma
= MCIAVI_mciGetOpenDev(wDevID
);
786 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
787 if (dwFlags
& MCI_TEST
) return 0;
792 /******************************************************************************
793 * MCIAVI_mciUpdate [internal]
795 static DWORD
MCIAVI_mciUpdate(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_UPDATE_PARMS lpParms
)
799 TRACE("%04x, %08x, %p\n", wDevID
, dwFlags
, lpParms
);
801 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
803 wma
= MCIAVI_mciGetOpenDev(wDevID
);
804 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
805 /* Ignore MCI_TEST flag. */
807 EnterCriticalSection(&wma
->cs
);
809 if (dwFlags
& MCI_DGV_UPDATE_HDC
)
810 MCIAVI_PaintFrame(wma
, lpParms
->hDC
);
812 LeaveCriticalSection(&wma
->cs
);
817 /******************************************************************************
818 * MCIAVI_mciStep [internal]
820 static DWORD
MCIAVI_mciStep(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_STEP_PARMS lpParms
)
826 TRACE("(%04x, %08x, %p)\n", wDevID
, dwFlags
, lpParms
);
828 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
830 wma
= MCIAVI_mciGetOpenDev(wDevID
);
831 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
833 if (dwFlags
& MCI_DGV_STEP_FRAMES
) delta
= lpParms
->dwFrames
;
834 if (dwFlags
& MCI_DGV_STEP_REVERSE
) delta
= -delta
;
835 position
= wma
->dwCurrVideoFrame
+ delta
;
836 if (position
>= wma
->dwPlayableVideoFrames
) return MCIERR_OUTOFRANGE
;
837 if (dwFlags
& MCI_TEST
) return 0;
839 MCIAVI_mciStop(wDevID
, MCI_WAIT
, NULL
);
841 EnterCriticalSection(&wma
->cs
);
843 wma
->dwCurrVideoFrame
= position
;
844 TRACE("Stepping to frame=%u\n", wma
->dwCurrVideoFrame
);
846 if (dwFlags
& MCI_NOTIFY
) {
847 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
848 wDevID
, MCI_NOTIFY_SUCCESSFUL
);
850 LeaveCriticalSection(&wma
->cs
);
854 /******************************************************************************
855 * MCIAVI_mciCue [internal]
857 static DWORD
MCIAVI_mciCue(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_CUE_PARMS lpParms
)
861 FIXME("(%04x, %08x, %p) : stub\n", wDevID
, dwFlags
, lpParms
);
863 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
865 wma
= MCIAVI_mciGetOpenDev(wDevID
);
866 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
867 if (dwFlags
& MCI_DGV_CUE_INPUT
) return MCIERR_UNSUPPORTED_FUNCTION
;
868 if (dwFlags
& MCI_TEST
) return 0;
873 /******************************************************************************
874 * MCIAVI_mciSetAudio [internal]
876 static DWORD
MCIAVI_mciSetAudio(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_SETAUDIO_PARMSW lpParms
)
880 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
882 FIXME("(%04x, %08x, %p) Item %04x: stub\n", wDevID
, dwFlags
, lpParms
, dwFlags
& MCI_DGV_SETAUDIO_ITEM
? lpParms
->dwItem
: 0);
884 wma
= MCIAVI_mciGetOpenDev(wDevID
);
885 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
890 /******************************************************************************
891 * MCIAVI_mciSignal [internal]
893 static DWORD
MCIAVI_mciSignal(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_SIGNAL_PARMS lpParms
)
897 FIXME("(%04x, %08x, %p) : stub\n", wDevID
, dwFlags
, lpParms
);
899 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
901 wma
= MCIAVI_mciGetOpenDev(wDevID
);
902 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
907 /******************************************************************************
908 * MCIAVI_mciSetVideo [internal]
910 static DWORD
MCIAVI_mciSetVideo(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_SETVIDEO_PARMSW lpParms
)
914 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
916 FIXME("(%04x, %08x, %p) Item %04x: stub\n", wDevID
, dwFlags
, lpParms
, dwFlags
& MCI_DGV_SETVIDEO_ITEM
? lpParms
->dwItem
: 0);
918 wma
= MCIAVI_mciGetOpenDev(wDevID
);
919 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
924 /******************************************************************************
925 * MCIAVI_mciConfigure [internal]
927 static DWORD
MCIAVI_mciConfigure(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
931 FIXME("(%04x, %08x, %p) : stub\n", wDevID
, dwFlags
, lpParms
);
933 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
935 wma
= MCIAVI_mciGetOpenDev(wDevID
);
936 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
937 if (dwFlags
& MCI_TEST
) return 0;
942 /*======================================================================*
943 * MCI AVI entry points *
944 *======================================================================*/
946 /**************************************************************************
947 * DriverProc (MCIAVI.@)
949 LRESULT CALLBACK
MCIAVI_DriverProc(DWORD_PTR dwDevID
, HDRVR hDriv
, UINT wMsg
,
950 LPARAM dwParam1
, LPARAM dwParam2
)
952 TRACE("(%08lX, %p, %08X, %08lX, %08lX)\n",
953 dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
956 case DRV_LOAD
: return 1;
957 case DRV_FREE
: return 1;
958 case DRV_OPEN
: return MCIAVI_drvOpen((LPCWSTR
)dwParam1
, (LPMCI_OPEN_DRIVER_PARMSW
)dwParam2
);
959 case DRV_CLOSE
: return MCIAVI_drvClose(dwDevID
);
960 case DRV_ENABLE
: return 1;
961 case DRV_DISABLE
: return 1;
962 case DRV_QUERYCONFIGURE
: return 1;
963 case DRV_CONFIGURE
: return MCIAVI_drvConfigure(dwDevID
);
964 case DRV_INSTALL
: return DRVCNF_RESTART
;
965 case DRV_REMOVE
: return DRVCNF_RESTART
;
968 /* session instance */
969 if (dwDevID
== 0xFFFFFFFF) return 1;
972 case MCI_OPEN_DRIVER
: return MCIAVI_mciOpen (dwDevID
, dwParam1
, (LPMCI_DGV_OPEN_PARMSW
) dwParam2
);
973 case MCI_CLOSE_DRIVER
: return MCIAVI_mciClose (dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
) dwParam2
);
974 case MCI_PLAY
: return MCIAVI_mciPlay (dwDevID
, dwParam1
, (LPMCI_PLAY_PARMS
) dwParam2
);
975 case MCI_STOP
: return MCIAVI_mciStop (dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
) dwParam2
);
976 case MCI_SET
: return MCIAVI_mciSet (dwDevID
, dwParam1
, (LPMCI_DGV_SET_PARMS
) dwParam2
);
977 case MCI_PAUSE
: return MCIAVI_mciPause (dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
) dwParam2
);
978 case MCI_RESUME
: return MCIAVI_mciResume (dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
) dwParam2
);
979 case MCI_STATUS
: return MCIAVI_mciStatus (dwDevID
, dwParam1
, (LPMCI_DGV_STATUS_PARMSW
) dwParam2
);
980 case MCI_GETDEVCAPS
: return MCIAVI_mciGetDevCaps(dwDevID
, dwParam1
, (LPMCI_GETDEVCAPS_PARMS
) dwParam2
);
981 case MCI_INFO
: return MCIAVI_mciInfo (dwDevID
, dwParam1
, (LPMCI_DGV_INFO_PARMSW
) dwParam2
);
982 case MCI_SEEK
: return MCIAVI_mciSeek (dwDevID
, dwParam1
, (LPMCI_SEEK_PARMS
) dwParam2
);
983 case MCI_PUT
: return MCIAVI_mciPut (dwDevID
, dwParam1
, (LPMCI_DGV_PUT_PARMS
) dwParam2
);
984 case MCI_WINDOW
: return MCIAVI_mciWindow (dwDevID
, dwParam1
, (LPMCI_DGV_WINDOW_PARMSW
) dwParam2
);
985 case MCI_LOAD
: return MCIAVI_mciLoad (dwDevID
, dwParam1
, (LPMCI_DGV_LOAD_PARMSW
) dwParam2
);
986 case MCI_REALIZE
: return MCIAVI_mciRealize (dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
) dwParam2
);
987 case MCI_UPDATE
: return MCIAVI_mciUpdate (dwDevID
, dwParam1
, (LPMCI_DGV_UPDATE_PARMS
) dwParam2
);
988 case MCI_WHERE
: return MCIAVI_mciWhere (dwDevID
, dwParam1
, (LPMCI_DGV_RECT_PARMS
) dwParam2
);
989 case MCI_STEP
: return MCIAVI_mciStep (dwDevID
, dwParam1
, (LPMCI_DGV_STEP_PARMS
) dwParam2
);
990 case MCI_CUE
: return MCIAVI_mciCue (dwDevID
, dwParam1
, (LPMCI_DGV_CUE_PARMS
) dwParam2
);
991 /* Digital Video specific */
992 case MCI_SETAUDIO
: return MCIAVI_mciSetAudio (dwDevID
, dwParam1
, (LPMCI_DGV_SETAUDIO_PARMSW
) dwParam2
);
993 case MCI_SIGNAL
: return MCIAVI_mciSignal (dwDevID
, dwParam1
, (LPMCI_DGV_SIGNAL_PARMS
) dwParam2
);
994 case MCI_SETVIDEO
: return MCIAVI_mciSetVideo (dwDevID
, dwParam1
, (LPMCI_DGV_SETVIDEO_PARMSW
) dwParam2
);
995 case MCI_CONFIGURE
: return MCIAVI_mciConfigure (dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
) dwParam2
);
997 /* no editing, recording, saving, locking without inputs */
1013 TRACE("Unsupported function [0x%x] flags=%08x\n", wMsg
, (DWORD
)dwParam1
);
1014 return MCIERR_UNSUPPORTED_FUNCTION
;
1017 WARN("Unsupported command [0x%x] %08x\n", wMsg
, (DWORD
)dwParam1
);
1021 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
1024 TRACE("Sending msg [%u] to default driver proc\n", wMsg
);
1025 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
1027 return MCIERR_UNRECOGNIZED_COMMAND
;