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
40 #include "private_mciavi.h"
43 #include <wine/unicode.h>
45 static DWORD
MCIAVI_mciStop(UINT
, DWORD
, LPMCI_GENERIC_PARMS
);
47 /*======================================================================*
48 * MCI AVI implementation *
49 *======================================================================*/
51 HINSTANCE MCIAVI_hInstance
= 0;
53 /***********************************************************************
56 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID fImpLoad
)
59 case DLL_PROCESS_ATTACH
:
60 DisableThreadLibraryCalls(hInstDLL
);
61 MCIAVI_hInstance
= hInstDLL
;
67 /**************************************************************************
68 * MCIAVI_drvOpen [internal]
70 static DWORD
MCIAVI_drvOpen(LPCWSTR str
, LPMCI_OPEN_DRIVER_PARMSW modp
)
73 static const WCHAR mciAviWStr
[] = {'M','C','I','A','V','I',0};
75 TRACE("%s, %p\n", debugstr_w(str
), modp
);
77 /* session instance */
78 if (!modp
) return 0xFFFFFFFF;
80 if (!MCIAVI_RegisterClass()) return 0;
82 wma
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINE_MCIAVI
));
86 InitializeCriticalSection(&wma
->cs
);
87 wma
->cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": WINE_MCIAVI.cs");
88 wma
->hStopEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
89 wma
->wDevID
= modp
->wDeviceID
;
90 wma
->wCommandTable
= mciLoadCommandResource(MCIAVI_hInstance
, mciAviWStr
, 0);
91 wma
->dwStatus
= MCI_MODE_NOT_READY
;
92 modp
->wCustomCommandTable
= wma
->wCommandTable
;
93 modp
->wType
= MCI_DEVTYPE_DIGITAL_VIDEO
;
94 mciSetDriverData(wma
->wDevID
, (DWORD_PTR
)wma
);
96 return modp
->wDeviceID
;
99 /**************************************************************************
100 * MCIAVI_drvClose [internal]
102 static DWORD
MCIAVI_drvClose(DWORD dwDevID
)
106 TRACE("%04x\n", dwDevID
);
108 /* finish all outstanding things */
109 MCIAVI_mciClose(dwDevID
, MCI_WAIT
, NULL
);
111 wma
= (WINE_MCIAVI
*)mciGetDriverData(dwDevID
);
114 MCIAVI_UnregisterClass();
116 EnterCriticalSection(&wma
->cs
);
118 mciSetDriverData(dwDevID
, 0);
119 mciFreeCommandResource(wma
->wCommandTable
);
121 CloseHandle(wma
->hStopEvent
);
123 LeaveCriticalSection(&wma
->cs
);
124 wma
->cs
.DebugInfo
->Spare
[0] = 0;
125 DeleteCriticalSection(&wma
->cs
);
127 HeapFree(GetProcessHeap(), 0, wma
);
130 return (dwDevID
== 0xFFFFFFFF) ? 1 : 0;
133 /**************************************************************************
134 * MCIAVI_drvConfigure [internal]
136 static DWORD
MCIAVI_drvConfigure(DWORD dwDevID
)
140 TRACE("%04x\n", dwDevID
);
142 MCIAVI_mciStop(dwDevID
, MCI_WAIT
, NULL
);
144 wma
= (WINE_MCIAVI
*)mciGetDriverData(dwDevID
);
147 MessageBoxA(0, "Sample AVI Wine Driver !", "MM-Wine Driver", MB_OK
);
153 /**************************************************************************
154 * MCIAVI_mciGetOpenDev [internal]
156 WINE_MCIAVI
* MCIAVI_mciGetOpenDev(UINT wDevID
)
158 WINE_MCIAVI
* wma
= (WINE_MCIAVI
*)mciGetDriverData(wDevID
);
160 if (wma
== NULL
|| wma
->nUseCount
== 0) {
161 WARN("Invalid wDevID=%u\n", wDevID
);
167 static void MCIAVI_CleanUp(WINE_MCIAVI
* wma
)
169 /* to prevent handling in WindowProc */
170 wma
->dwStatus
= MCI_MODE_NOT_READY
;
172 mmioClose(wma
->hFile
, 0);
175 HeapFree(GetProcessHeap(), 0, wma
->lpFileName
);
176 wma
->lpFileName
= NULL
;
178 HeapFree(GetProcessHeap(), 0, wma
->lpVideoIndex
);
179 wma
->lpVideoIndex
= NULL
;
180 HeapFree(GetProcessHeap(), 0, wma
->lpAudioIndex
);
181 wma
->lpAudioIndex
= NULL
;
182 if (wma
->hic
) ICClose(wma
->hic
);
184 HeapFree(GetProcessHeap(), 0, wma
->inbih
);
186 HeapFree(GetProcessHeap(), 0, wma
->outbih
);
188 HeapFree(GetProcessHeap(), 0, wma
->indata
);
190 HeapFree(GetProcessHeap(), 0, wma
->outdata
);
192 if (wma
->hbmFrame
) DeleteObject(wma
->hbmFrame
);
194 if (wma
->hWnd
) DestroyWindow(wma
->hWnd
);
197 HeapFree(GetProcessHeap(), 0, wma
->lpWaveFormat
);
198 wma
->lpWaveFormat
= 0;
200 memset(&wma
->mah
, 0, sizeof(wma
->mah
));
201 memset(&wma
->ash_video
, 0, sizeof(wma
->ash_video
));
202 memset(&wma
->ash_audio
, 0, sizeof(wma
->ash_audio
));
203 wma
->dwCurrVideoFrame
= wma
->dwCurrAudioBlock
= 0;
204 wma
->dwCachedFrame
= -1;
208 /***************************************************************************
209 * MCIAVI_mciOpen [internal]
211 static DWORD
MCIAVI_mciOpen(UINT wDevID
, DWORD dwFlags
,
212 LPMCI_DGV_OPEN_PARMSW lpOpenParms
)
217 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpOpenParms
);
219 if (lpOpenParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
221 wma
= (WINE_MCIAVI
*)mciGetDriverData(wDevID
);
222 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
224 EnterCriticalSection(&wma
->cs
);
226 if (wma
->nUseCount
> 0) {
227 /* The driver is already open on this channel */
228 /* If the driver was opened shareable before and this open specifies */
229 /* shareable then increment the use count */
230 if (wma
->fShareable
&& (dwFlags
& MCI_OPEN_SHAREABLE
))
234 LeaveCriticalSection(&wma
->cs
);
235 return MCIERR_MUST_USE_SHAREABLE
;
239 wma
->fShareable
= dwFlags
& MCI_OPEN_SHAREABLE
;
242 wma
->dwStatus
= MCI_MODE_NOT_READY
;
244 if (dwFlags
& MCI_OPEN_ELEMENT
) {
245 if (dwFlags
& MCI_OPEN_ELEMENT_ID
) {
246 /* could it be that (DWORD)lpOpenParms->lpstrElementName
247 * contains the hFile value ?
249 dwRet
= MCIERR_UNRECOGNIZED_COMMAND
;
250 } else if (lpOpenParms
->lpstrElementName
&& lpOpenParms
->lpstrElementName
[0]) {
251 /* FIXME : what should be done id wma->hFile is already != 0, or the driver is playin' */
252 TRACE("MCI_OPEN_ELEMENT %s!\n", debugstr_w(lpOpenParms
->lpstrElementName
));
254 wma
->lpFileName
= HeapAlloc(GetProcessHeap(), 0, (strlenW(lpOpenParms
->lpstrElementName
) + 1) * sizeof(WCHAR
));
255 strcpyW(wma
->lpFileName
, lpOpenParms
->lpstrElementName
);
257 if (lpOpenParms
->lpstrElementName
[0] == '@') {
258 /* The file name @11223344 encodes an AVIFile handle in decimal notation
259 * in Win3.1 and w2k/NT, but this feature is absent in win95 (KB140750).
260 * wma->hFile = LongToHandle(strtolW(lpOpenParms->lpstrElementName+1, NULL, 10)); */
261 FIXME("Using AVIFile/Stream %s NIY\n", debugstr_w(lpOpenParms
->lpstrElementName
));
263 wma
->hFile
= mmioOpenW(lpOpenParms
->lpstrElementName
, NULL
,
264 MMIO_ALLOCBUF
| MMIO_DENYWRITE
| MMIO_READ
);
266 if (wma
->hFile
== 0) {
267 WARN("can't find file=%s!\n", debugstr_w(lpOpenParms
->lpstrElementName
));
268 dwRet
= MCIERR_FILE_NOT_FOUND
;
270 if (!MCIAVI_GetInfo(wma
))
271 dwRet
= MCIERR_INVALID_FILE
;
272 else if (!MCIAVI_OpenVideo(wma
))
273 dwRet
= MCIERR_CANNOT_LOAD_DRIVER
;
274 else if (!MCIAVI_CreateWindow(wma
, dwFlags
, lpOpenParms
))
275 dwRet
= MCIERR_CREATEWINDOW
;
278 FIXME("Don't record yet\n");
279 dwRet
= MCIERR_UNSUPPORTED_FUNCTION
;
284 TRACE("lpOpenParms->wDeviceID = %04x\n", lpOpenParms
->wDeviceID
);
286 wma
->dwStatus
= MCI_MODE_STOP
;
287 wma
->dwMciTimeFormat
= MCI_FORMAT_FRAMES
;
292 LeaveCriticalSection(&wma
->cs
);
294 if (!dwRet
&& (dwFlags
& MCI_NOTIFY
)) {
295 mciDriverNotify(HWND_32(LOWORD(lpOpenParms
->dwCallback
)),
296 wDevID
, MCI_NOTIFY_SUCCESSFUL
);
301 /***************************************************************************
302 * MCIAVI_mciClose [internal]
304 DWORD
MCIAVI_mciClose(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
309 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
311 wma
= MCIAVI_mciGetOpenDev(wDevID
);
312 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
314 MCIAVI_mciStop(wDevID
, MCI_WAIT
, NULL
);
316 EnterCriticalSection(&wma
->cs
);
318 if (wma
->nUseCount
== 1) {
321 if ((dwFlags
& MCI_NOTIFY
) && lpParms
) {
322 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
324 MCI_NOTIFY_SUCCESSFUL
);
326 LeaveCriticalSection(&wma
->cs
);
331 LeaveCriticalSection(&wma
->cs
);
335 static double currenttime_us(void)
337 LARGE_INTEGER lc
, lf
;
338 QueryPerformanceCounter(&lc
);
339 QueryPerformanceFrequency(&lf
);
340 return (lc
.QuadPart
* 1000000) / lf
.QuadPart
;
343 /***************************************************************************
344 * MCIAVI_player [internal]
346 static DWORD
MCIAVI_player(WINE_MCIAVI
*wma
, DWORD dwFlags
, LPMCI_PLAY_PARMS lpParms
)
349 LPWAVEHDR waveHdr
= NULL
;
350 unsigned i
, nHdr
= 0;
353 double next_frame_us
;
355 EnterCriticalSection(&wma
->cs
);
357 if (wma
->dwToVideoFrame
<= wma
->dwCurrVideoFrame
)
363 events
[0] = wma
->hStopEvent
;
364 if (wma
->lpWaveFormat
) {
365 if (MCIAVI_OpenAudio(wma
, &nHdr
, &waveHdr
) != 0)
367 /* can't play audio */
368 HeapFree(GetProcessHeap(), 0, wma
->lpWaveFormat
);
369 wma
->lpWaveFormat
= NULL
;
373 /* fill the queue with as many wave headers as possible */
374 MCIAVI_PlayAudioBlocks(wma
, nHdr
, waveHdr
);
375 events
[1] = wma
->hEvent
;
380 next_frame_us
= currenttime_us();
381 while (wma
->dwStatus
== MCI_MODE_PLAY
)
387 tc
= currenttime_us();
389 hDC
= wma
->hWndPaint
? GetDC(wma
->hWndPaint
) : 0;
392 while(next_frame_us
<= tc
&& wma
->dwCurrVideoFrame
< wma
->dwToVideoFrame
){
394 dur
= MCIAVI_PaintFrame(wma
, hDC
);
395 ++wma
->dwCurrVideoFrame
;
398 next_frame_us
+= dur
;
399 TRACE("next_frame: %f\n", next_frame_us
);
401 ReleaseDC(wma
->hWndPaint
, hDC
);
403 if (wma
->dwCurrVideoFrame
>= wma
->dwToVideoFrame
)
405 if (!(dwFlags
& MCI_DGV_PLAY_REPEAT
))
407 TRACE("repeat media as requested\n");
408 wma
->dwCurrVideoFrame
= wma
->dwCurrAudioBlock
= 0;
411 if (wma
->lpWaveFormat
)
412 MCIAVI_PlayAudioBlocks(wma
, nHdr
, waveHdr
);
414 tc
= currenttime_us();
415 if (tc
< next_frame_us
)
416 delta
= next_frame_us
- tc
;
420 LeaveCriticalSection(&wma
->cs
);
421 ret
= WaitForMultipleObjects(numEvents
, events
, FALSE
, delta
/ 1000);
422 EnterCriticalSection(&wma
->cs
);
423 if (ret
== WAIT_OBJECT_0
|| wma
->dwStatus
!= MCI_MODE_PLAY
) break;
426 if (wma
->lpWaveFormat
) {
427 while (wma
->dwEventCount
!= nHdr
- 1)
429 LeaveCriticalSection(&wma
->cs
);
431 EnterCriticalSection(&wma
->cs
);
434 /* just to get rid of some race conditions between play, stop and pause */
435 LeaveCriticalSection(&wma
->cs
);
436 waveOutReset(wma
->hWave
);
437 EnterCriticalSection(&wma
->cs
);
439 for (i
= 0; i
< nHdr
; i
++)
440 waveOutUnprepareHeader(wma
->hWave
, &waveHdr
[i
], sizeof(WAVEHDR
));
445 if (wma
->lpWaveFormat
) {
446 HeapFree(GetProcessHeap(), 0, waveHdr
);
449 LeaveCriticalSection(&wma
->cs
);
450 waveOutClose(wma
->hWave
);
451 EnterCriticalSection(&wma
->cs
);
454 CloseHandle(wma
->hEvent
);
458 wma
->dwStatus
= MCI_MODE_STOP
;
460 if (dwFlags
& MCI_NOTIFY
) {
461 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
462 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
463 wma
->wDevID
, MCI_NOTIFY_SUCCESSFUL
);
465 LeaveCriticalSection(&wma
->cs
);
469 struct MCIAVI_play_data
473 MCI_PLAY_PARMS params
; /* FIXME: notify via wma->hCallback like the other MCI drivers */
477 * MCIAVI_mciPlay_thread
479 * FIXME: probably should use a common worker thread created at the driver
480 * load time and queue all async commands to it.
482 static DWORD WINAPI
MCIAVI_mciPlay_thread(LPVOID arg
)
484 struct MCIAVI_play_data
*data
= (struct MCIAVI_play_data
*)arg
;
487 TRACE("In thread before async play command (id %u, flags %08x)\n", data
->wma
->wDevID
, data
->flags
);
488 ret
= MCIAVI_player(data
->wma
, data
->flags
, &data
->params
);
489 TRACE("In thread after async play command (id %u, flags %08x)\n", data
->wma
->wDevID
, data
->flags
);
491 HeapFree(GetProcessHeap(), 0, data
);
496 * MCIAVI_mciPlay_async
498 static DWORD
MCIAVI_mciPlay_async(WINE_MCIAVI
*wma
, DWORD dwFlags
, LPMCI_PLAY_PARMS lpParams
)
501 struct MCIAVI_play_data
*data
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct MCIAVI_play_data
));
503 if (!data
) return MCIERR_OUT_OF_MEMORY
;
506 data
->flags
= dwFlags
;
507 if (dwFlags
& MCI_NOTIFY
)
508 data
->params
.dwCallback
= lpParams
->dwCallback
;
510 if (!(handle
= CreateThread(NULL
, 0, MCIAVI_mciPlay_thread
, data
, 0, NULL
)))
512 WARN("Couldn't create thread for async play, playing synchronously\n");
513 return MCIAVI_mciPlay_thread(data
);
515 SetThreadPriority(handle
, THREAD_PRIORITY_TIME_CRITICAL
);
520 /***************************************************************************
521 * MCIAVI_mciPlay [internal]
523 static DWORD
MCIAVI_mciPlay(UINT wDevID
, DWORD dwFlags
, LPMCI_PLAY_PARMS lpParms
)
527 DWORD dwFromFrame
, dwToFrame
;
529 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
531 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
533 wma
= MCIAVI_mciGetOpenDev(wDevID
);
534 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
535 if (dwFlags
& MCI_DGV_PLAY_REVERSE
) return MCIERR_UNSUPPORTED_FUNCTION
;
536 if (dwFlags
& MCI_TEST
) return 0;
538 if (dwFlags
& (MCI_MCIAVI_PLAY_WINDOW
|MCI_MCIAVI_PLAY_FULLSCREEN
|MCI_MCIAVI_PLAY_FULLBY2
))
539 FIXME("Unsupported flag %08x\n", dwFlags
);
541 EnterCriticalSection(&wma
->cs
);
545 LeaveCriticalSection(&wma
->cs
);
546 return MCIERR_FILE_NOT_FOUND
;
550 LeaveCriticalSection(&wma
->cs
);
551 return MCIERR_NO_WINDOW
;
554 dwFromFrame
= wma
->dwCurrVideoFrame
;
555 dwToFrame
= wma
->dwPlayableVideoFrames
- 1;
557 if (dwFlags
& MCI_FROM
) {
558 dwFromFrame
= MCIAVI_ConvertTimeFormatToFrame(wma
, lpParms
->dwFrom
);
560 if (dwFlags
& MCI_TO
) {
561 dwToFrame
= MCIAVI_ConvertTimeFormatToFrame(wma
, lpParms
->dwTo
);
563 if (dwToFrame
>= wma
->dwPlayableVideoFrames
)
564 dwToFrame
= wma
->dwPlayableVideoFrames
- 1;
566 TRACE("Playing from frame=%u to frame=%u\n", dwFromFrame
, dwToFrame
);
568 wma
->dwCurrVideoFrame
= dwFromFrame
;
569 wma
->dwToVideoFrame
= dwToFrame
;
571 LeaveCriticalSection(&wma
->cs
);
573 if (!(GetWindowLongW(wma
->hWndPaint
, GWL_STYLE
) & WS_VISIBLE
))
574 ShowWindow(wma
->hWndPaint
, SW_SHOWNA
);
576 EnterCriticalSection(&wma
->cs
);
578 /* if already playing exit */
579 if (wma
->dwStatus
== MCI_MODE_PLAY
)
581 LeaveCriticalSection(&wma
->cs
);
585 wma
->dwStatus
= MCI_MODE_PLAY
;
587 LeaveCriticalSection(&wma
->cs
);
589 if (dwFlags
& MCI_WAIT
)
590 return MCIAVI_player(wma
, dwFlags
, lpParms
);
592 dwRet
= MCIAVI_mciPlay_async(wma
, dwFlags
, lpParms
);
595 EnterCriticalSection(&wma
->cs
);
596 wma
->dwStatus
= MCI_MODE_STOP
;
597 LeaveCriticalSection(&wma
->cs
);
602 /***************************************************************************
603 * MCIAVI_mciStop [internal]
605 static DWORD
MCIAVI_mciStop(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
610 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
612 wma
= MCIAVI_mciGetOpenDev(wDevID
);
613 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
614 if (dwFlags
& MCI_TEST
) return 0;
616 EnterCriticalSection(&wma
->cs
);
618 TRACE("current status %04x\n", wma
->dwStatus
);
620 switch (wma
->dwStatus
) {
622 case MCI_MODE_RECORD
:
623 LeaveCriticalSection(&wma
->cs
);
624 SetEvent(wma
->hStopEvent
);
625 EnterCriticalSection(&wma
->cs
);
628 /* Since our wave notification callback takes the lock,
629 * we must release it before resetting the device */
630 LeaveCriticalSection(&wma
->cs
);
631 dwRet
= waveOutReset(wma
->hWave
);
632 EnterCriticalSection(&wma
->cs
);
635 do /* one more chance for an async thread to finish */
637 LeaveCriticalSection(&wma
->cs
);
639 EnterCriticalSection(&wma
->cs
);
640 } while (wma
->dwStatus
!= MCI_MODE_STOP
);
644 case MCI_MODE_NOT_READY
:
648 if ((dwFlags
& MCI_NOTIFY
) && lpParms
) {
649 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
650 wDevID
, MCI_NOTIFY_SUCCESSFUL
);
652 LeaveCriticalSection(&wma
->cs
);
656 /***************************************************************************
657 * MCIAVI_mciPause [internal]
659 static DWORD
MCIAVI_mciPause(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
663 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
665 wma
= MCIAVI_mciGetOpenDev(wDevID
);
666 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
667 if (dwFlags
& MCI_TEST
) return 0;
669 EnterCriticalSection(&wma
->cs
);
671 if (wma
->dwStatus
== MCI_MODE_PLAY
)
672 wma
->dwStatus
= MCI_MODE_PAUSE
;
674 if (wma
->lpWaveFormat
) {
675 LeaveCriticalSection(&wma
->cs
);
676 return waveOutPause(wma
->hWave
);
679 LeaveCriticalSection(&wma
->cs
);
683 /***************************************************************************
684 * MCIAVI_mciResume [internal]
686 static DWORD
MCIAVI_mciResume(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
690 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
692 wma
= MCIAVI_mciGetOpenDev(wDevID
);
693 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
694 if (dwFlags
& MCI_TEST
) return 0;
696 EnterCriticalSection(&wma
->cs
);
698 if (wma
->dwStatus
== MCI_MODE_PAUSE
)
699 wma
->dwStatus
= MCI_MODE_PLAY
;
701 if (wma
->lpWaveFormat
) {
702 LeaveCriticalSection(&wma
->cs
);
703 return waveOutRestart(wma
->hWave
);
706 LeaveCriticalSection(&wma
->cs
);
710 /***************************************************************************
711 * MCIAVI_mciSeek [internal]
713 static DWORD
MCIAVI_mciSeek(UINT wDevID
, DWORD dwFlags
, LPMCI_SEEK_PARMS lpParms
)
718 TRACE("(%04x, %08X, %p)\n", wDevID
, dwFlags
, lpParms
);
720 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
722 wma
= MCIAVI_mciGetOpenDev(wDevID
);
723 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
725 position
= dwFlags
& (MCI_SEEK_TO_START
|MCI_SEEK_TO_END
|MCI_TO
);
726 if (!position
) return MCIERR_MISSING_PARAMETER
;
727 if (position
&(position
-1)) return MCIERR_FLAGS_NOT_COMPATIBLE
;
729 if (dwFlags
& MCI_TO
) {
730 position
= MCIAVI_ConvertTimeFormatToFrame(wma
, lpParms
->dwTo
);
731 if (position
>= wma
->dwPlayableVideoFrames
)
732 return MCIERR_OUTOFRANGE
;
733 } else if (dwFlags
& MCI_SEEK_TO_START
) {
736 position
= wma
->dwPlayableVideoFrames
- 1;
738 if (dwFlags
& MCI_TEST
) return 0;
740 MCIAVI_mciStop(wDevID
, MCI_WAIT
, NULL
);
742 EnterCriticalSection(&wma
->cs
);
744 wma
->dwCurrVideoFrame
= position
;
745 TRACE("Seeking to frame=%u\n", wma
->dwCurrVideoFrame
);
747 if (dwFlags
& MCI_NOTIFY
) {
748 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
749 wDevID
, MCI_NOTIFY_SUCCESSFUL
);
751 LeaveCriticalSection(&wma
->cs
);
755 /*****************************************************************************
756 * MCIAVI_mciLoad [internal]
758 static DWORD
MCIAVI_mciLoad(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_LOAD_PARMSW lpParms
)
762 FIXME("(%04x, %08x, %p) : stub\n", wDevID
, dwFlags
, lpParms
);
764 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
766 wma
= MCIAVI_mciGetOpenDev(wDevID
);
767 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
769 return MCIERR_UNSUPPORTED_FUNCTION
; /* like w2k */
772 /******************************************************************************
773 * MCIAVI_mciRealize [internal]
775 static DWORD
MCIAVI_mciRealize(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
779 FIXME("(%04x, %08x, %p) : stub\n", wDevID
, dwFlags
, lpParms
);
781 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
783 wma
= MCIAVI_mciGetOpenDev(wDevID
);
784 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
785 if (dwFlags
& MCI_TEST
) return 0;
790 /******************************************************************************
791 * MCIAVI_mciUpdate [internal]
793 static DWORD
MCIAVI_mciUpdate(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_UPDATE_PARMS lpParms
)
797 TRACE("%04x, %08x, %p\n", wDevID
, dwFlags
, lpParms
);
799 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
801 wma
= MCIAVI_mciGetOpenDev(wDevID
);
802 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
803 /* Ignore MCI_TEST flag. */
805 EnterCriticalSection(&wma
->cs
);
807 if (dwFlags
& MCI_DGV_UPDATE_HDC
)
808 MCIAVI_PaintFrame(wma
, lpParms
->hDC
);
810 LeaveCriticalSection(&wma
->cs
);
815 /******************************************************************************
816 * MCIAVI_mciStep [internal]
818 static DWORD
MCIAVI_mciStep(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_STEP_PARMS lpParms
)
824 TRACE("(%04x, %08x, %p)\n", wDevID
, dwFlags
, lpParms
);
826 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
828 wma
= MCIAVI_mciGetOpenDev(wDevID
);
829 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
831 if (dwFlags
& MCI_DGV_STEP_FRAMES
) delta
= lpParms
->dwFrames
;
832 if (dwFlags
& MCI_DGV_STEP_REVERSE
) delta
= -delta
;
833 position
= wma
->dwCurrVideoFrame
+ delta
;
834 if (position
>= wma
->dwPlayableVideoFrames
) return MCIERR_OUTOFRANGE
;
835 if (dwFlags
& MCI_TEST
) return 0;
837 MCIAVI_mciStop(wDevID
, MCI_WAIT
, NULL
);
839 EnterCriticalSection(&wma
->cs
);
841 wma
->dwCurrVideoFrame
= position
;
842 TRACE("Stepping to frame=%u\n", wma
->dwCurrVideoFrame
);
844 if (dwFlags
& MCI_NOTIFY
) {
845 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
846 wDevID
, MCI_NOTIFY_SUCCESSFUL
);
848 LeaveCriticalSection(&wma
->cs
);
852 /******************************************************************************
853 * MCIAVI_mciCue [internal]
855 static DWORD
MCIAVI_mciCue(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_CUE_PARMS lpParms
)
859 FIXME("(%04x, %08x, %p) : stub\n", wDevID
, dwFlags
, lpParms
);
861 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
863 wma
= MCIAVI_mciGetOpenDev(wDevID
);
864 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
865 if (dwFlags
& MCI_DGV_CUE_INPUT
) return MCIERR_UNSUPPORTED_FUNCTION
;
866 if (dwFlags
& MCI_TEST
) return 0;
871 /******************************************************************************
872 * MCIAVI_mciSetAudio [internal]
874 static DWORD
MCIAVI_mciSetAudio(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_SETAUDIO_PARMSW lpParms
)
878 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
880 FIXME("(%04x, %08x, %p) Item %04x: stub\n", wDevID
, dwFlags
, lpParms
, dwFlags
& MCI_DGV_SETAUDIO_ITEM
? lpParms
->dwItem
: 0);
882 wma
= MCIAVI_mciGetOpenDev(wDevID
);
883 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
888 /******************************************************************************
889 * MCIAVI_mciSignal [internal]
891 static DWORD
MCIAVI_mciSignal(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_SIGNAL_PARMS lpParms
)
895 FIXME("(%04x, %08x, %p) : stub\n", wDevID
, dwFlags
, lpParms
);
897 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
899 wma
= MCIAVI_mciGetOpenDev(wDevID
);
900 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
905 /******************************************************************************
906 * MCIAVI_mciSetVideo [internal]
908 static DWORD
MCIAVI_mciSetVideo(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_SETVIDEO_PARMSW lpParms
)
912 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
914 FIXME("(%04x, %08x, %p) Item %04x: stub\n", wDevID
, dwFlags
, lpParms
, dwFlags
& MCI_DGV_SETVIDEO_ITEM
? lpParms
->dwItem
: 0);
916 wma
= MCIAVI_mciGetOpenDev(wDevID
);
917 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
922 /******************************************************************************
923 * MCIAVI_mciConfigure [internal]
925 static DWORD
MCIAVI_mciConfigure(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
929 FIXME("(%04x, %08x, %p) : stub\n", wDevID
, dwFlags
, lpParms
);
931 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
933 wma
= MCIAVI_mciGetOpenDev(wDevID
);
934 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
935 if (dwFlags
& MCI_TEST
) return 0;
940 /*======================================================================*
941 * MCI AVI entry points *
942 *======================================================================*/
944 /**************************************************************************
945 * DriverProc (MCIAVI.@)
947 LRESULT CALLBACK
MCIAVI_DriverProc(DWORD_PTR dwDevID
, HDRVR hDriv
, UINT wMsg
,
948 LPARAM dwParam1
, LPARAM dwParam2
)
950 TRACE("(%08lX, %p, %08X, %08lX, %08lX)\n",
951 dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
954 case DRV_LOAD
: return 1;
955 case DRV_FREE
: return 1;
956 case DRV_OPEN
: return MCIAVI_drvOpen((LPCWSTR
)dwParam1
, (LPMCI_OPEN_DRIVER_PARMSW
)dwParam2
);
957 case DRV_CLOSE
: return MCIAVI_drvClose(dwDevID
);
958 case DRV_ENABLE
: return 1;
959 case DRV_DISABLE
: return 1;
960 case DRV_QUERYCONFIGURE
: return 1;
961 case DRV_CONFIGURE
: return MCIAVI_drvConfigure(dwDevID
);
962 case DRV_INSTALL
: return DRVCNF_RESTART
;
963 case DRV_REMOVE
: return DRVCNF_RESTART
;
966 /* session instance */
967 if (dwDevID
== 0xFFFFFFFF) return 1;
970 case MCI_OPEN_DRIVER
: return MCIAVI_mciOpen (dwDevID
, dwParam1
, (LPMCI_DGV_OPEN_PARMSW
) dwParam2
);
971 case MCI_CLOSE_DRIVER
: return MCIAVI_mciClose (dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
) dwParam2
);
972 case MCI_PLAY
: return MCIAVI_mciPlay (dwDevID
, dwParam1
, (LPMCI_PLAY_PARMS
) dwParam2
);
973 case MCI_STOP
: return MCIAVI_mciStop (dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
) dwParam2
);
974 case MCI_SET
: return MCIAVI_mciSet (dwDevID
, dwParam1
, (LPMCI_DGV_SET_PARMS
) dwParam2
);
975 case MCI_PAUSE
: return MCIAVI_mciPause (dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
) dwParam2
);
976 case MCI_RESUME
: return MCIAVI_mciResume (dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
) dwParam2
);
977 case MCI_STATUS
: return MCIAVI_mciStatus (dwDevID
, dwParam1
, (LPMCI_DGV_STATUS_PARMSW
) dwParam2
);
978 case MCI_GETDEVCAPS
: return MCIAVI_mciGetDevCaps(dwDevID
, dwParam1
, (LPMCI_GETDEVCAPS_PARMS
) dwParam2
);
979 case MCI_INFO
: return MCIAVI_mciInfo (dwDevID
, dwParam1
, (LPMCI_DGV_INFO_PARMSW
) dwParam2
);
980 case MCI_SEEK
: return MCIAVI_mciSeek (dwDevID
, dwParam1
, (LPMCI_SEEK_PARMS
) dwParam2
);
981 case MCI_PUT
: return MCIAVI_mciPut (dwDevID
, dwParam1
, (LPMCI_DGV_PUT_PARMS
) dwParam2
);
982 case MCI_WINDOW
: return MCIAVI_mciWindow (dwDevID
, dwParam1
, (LPMCI_DGV_WINDOW_PARMSW
) dwParam2
);
983 case MCI_LOAD
: return MCIAVI_mciLoad (dwDevID
, dwParam1
, (LPMCI_DGV_LOAD_PARMSW
) dwParam2
);
984 case MCI_REALIZE
: return MCIAVI_mciRealize (dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
) dwParam2
);
985 case MCI_UPDATE
: return MCIAVI_mciUpdate (dwDevID
, dwParam1
, (LPMCI_DGV_UPDATE_PARMS
) dwParam2
);
986 case MCI_WHERE
: return MCIAVI_mciWhere (dwDevID
, dwParam1
, (LPMCI_DGV_RECT_PARMS
) dwParam2
);
987 case MCI_STEP
: return MCIAVI_mciStep (dwDevID
, dwParam1
, (LPMCI_DGV_STEP_PARMS
) dwParam2
);
988 case MCI_CUE
: return MCIAVI_mciCue (dwDevID
, dwParam1
, (LPMCI_DGV_CUE_PARMS
) dwParam2
);
989 /* Digital Video specific */
990 case MCI_SETAUDIO
: return MCIAVI_mciSetAudio (dwDevID
, dwParam1
, (LPMCI_DGV_SETAUDIO_PARMSW
) dwParam2
);
991 case MCI_SIGNAL
: return MCIAVI_mciSignal (dwDevID
, dwParam1
, (LPMCI_DGV_SIGNAL_PARMS
) dwParam2
);
992 case MCI_SETVIDEO
: return MCIAVI_mciSetVideo (dwDevID
, dwParam1
, (LPMCI_DGV_SETVIDEO_PARMSW
) dwParam2
);
993 case MCI_CONFIGURE
: return MCIAVI_mciConfigure (dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
) dwParam2
);
995 /* no editing, recording, saving, locking without inputs */
1011 TRACE("Unsupported function [0x%x] flags=%08x\n", wMsg
, (DWORD
)dwParam1
);
1012 return MCIERR_UNSUPPORTED_FUNCTION
;
1015 WARN("Unsupported command [0x%x] %08x\n", wMsg
, (DWORD
)dwParam1
);
1019 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
1022 TRACE("Sending msg [%u] to default driver proc\n", wMsg
);
1023 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
1025 return MCIERR_UNRECOGNIZED_COMMAND
;