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 * - better move the AVI handling part to avifile DLL and make use of it
30 * - some files appear to have more than one audio stream (we only play the
32 * - some files contain an index of audio/video frame. Better use it,
33 * instead of rebuilding it
34 * - stopping while playing a file with sound blocks until all buffered
35 * audio is played... still should be stopped ASAP
39 #include "private_mciavi.h"
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(mciavi);
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->ack_event = CreateEventW(NULL, FALSE, FALSE, NULL);
88 wma->hStopEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
89 wma->wDevID = modp->wDeviceID;
90 wma->wCommandTable = mciLoadCommandResource(MCIAVI_hInstance, mciAviWStr, 0);
91 modp->wCustomCommandTable = wma->wCommandTable;
92 modp->wType = MCI_DEVTYPE_DIGITAL_VIDEO;
93 mciSetDriverData(wma->wDevID, (DWORD)wma);
95 return modp->wDeviceID;
98 /**************************************************************************
99 * MCIAVI_drvClose [internal]
101 static DWORD MCIAVI_drvClose(DWORD dwDevID)
105 TRACE("%04x\n", dwDevID);
107 /* finish all outstanding things */
108 MCIAVI_mciClose(dwDevID, MCI_WAIT, NULL);
110 wma = (WINE_MCIAVI*)mciGetDriverData(dwDevID);
113 MCIAVI_UnregisterClass();
115 EnterCriticalSection(&wma->cs);
117 mciSetDriverData(dwDevID, 0);
118 mciFreeCommandResource(wma->wCommandTable);
120 CloseHandle(wma->ack_event);
121 CloseHandle(wma->hStopEvent);
123 LeaveCriticalSection(&wma->cs);
124 DeleteCriticalSection(&wma->cs);
126 HeapFree(GetProcessHeap(), 0, wma);
129 return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
132 /**************************************************************************
133 * MCIAVI_drvConfigure [internal]
135 static DWORD MCIAVI_drvConfigure(DWORD dwDevID)
139 TRACE("%04x\n", dwDevID);
141 MCIAVI_mciStop(dwDevID, MCI_WAIT, NULL);
143 wma = (WINE_MCIAVI*)mciGetDriverData(dwDevID);
146 MessageBoxA(0, "Sample AVI Wine Driver !", "MM-Wine Driver", MB_OK);
152 /**************************************************************************
153 * MCIAVI_mciGetOpenDev [internal]
155 WINE_MCIAVI* MCIAVI_mciGetOpenDev(UINT wDevID)
157 WINE_MCIAVI* wma = (WINE_MCIAVI*)mciGetDriverData(wDevID);
159 if (wma == NULL || wma->nUseCount == 0) {
160 WARN("Invalid wDevID=%u\n", wDevID);
166 static void MCIAVI_CleanUp(WINE_MCIAVI* wma)
168 /* to prevent handling in WindowProc */
169 wma->dwStatus = MCI_MODE_NOT_READY;
171 mmioClose(wma->hFile, 0);
174 HeapFree(GetProcessHeap(), 0, wma->lpFileName);
175 wma->lpFileName = NULL;
177 HeapFree(GetProcessHeap(), 0, wma->lpVideoIndex);
178 wma->lpVideoIndex = NULL;
179 HeapFree(GetProcessHeap(), 0, wma->lpAudioIndex);
180 wma->lpAudioIndex = NULL;
181 if (wma->hic) ICClose(wma->hic);
183 HeapFree(GetProcessHeap(), 0, wma->inbih);
185 HeapFree(GetProcessHeap(), 0, wma->outbih);
187 HeapFree(GetProcessHeap(), 0, wma->indata);
189 HeapFree(GetProcessHeap(), 0, wma->outdata);
191 if (wma->hbmFrame) DeleteObject(wma->hbmFrame);
193 if (wma->hWnd) DestroyWindow(wma->hWnd);
196 HeapFree(GetProcessHeap(), 0, wma->lpWaveFormat);
197 wma->lpWaveFormat = 0;
199 memset(&wma->mah, 0, sizeof(wma->mah));
200 memset(&wma->ash_video, 0, sizeof(wma->ash_video));
201 memset(&wma->ash_audio, 0, sizeof(wma->ash_audio));
202 wma->dwCurrVideoFrame = wma->dwCurrAudioBlock = 0;
203 wma->dwCachedFrame = -1;
207 /***************************************************************************
208 * MCIAVI_mciOpen [internal]
210 static DWORD MCIAVI_mciOpen(UINT wDevID, DWORD dwFlags,
211 LPMCI_DGV_OPEN_PARMSW lpOpenParms)
216 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpOpenParms);
218 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
220 if (lpOpenParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
222 wma = (WINE_MCIAVI *)mciGetDriverData(wDevID);
223 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
225 EnterCriticalSection(&wma->cs);
227 if (wma->nUseCount > 0) {
228 /* The driver is already open on this channel */
229 /* If the driver was opened shareable before and this open specifies */
230 /* shareable then increment the use count */
231 if (wma->fShareable && (dwFlags & MCI_OPEN_SHAREABLE))
235 LeaveCriticalSection(&wma->cs);
236 return MCIERR_MUST_USE_SHAREABLE;
240 wma->fShareable = dwFlags & MCI_OPEN_SHAREABLE;
243 wma->dwStatus = MCI_MODE_NOT_READY;
245 if (dwFlags & MCI_OPEN_ELEMENT) {
246 if (dwFlags & MCI_OPEN_ELEMENT_ID) {
247 /* could it be that (DWORD)lpOpenParms->lpstrElementName
248 * contains the hFile value ?
250 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
251 } else if (strlenW(lpOpenParms->lpstrElementName) > 0) {
252 /* FIXME : what should be done id wma->hFile is already != 0, or the driver is playin' */
253 TRACE("MCI_OPEN_ELEMENT %s!\n", debugstr_w(lpOpenParms->lpstrElementName));
255 if (lpOpenParms->lpstrElementName && (strlenW(lpOpenParms->lpstrElementName) > 0))
257 wma->lpFileName = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpOpenParms->lpstrElementName) + 1) * sizeof(WCHAR));
258 strcpyW(wma->lpFileName, lpOpenParms->lpstrElementName);
260 wma->hFile = mmioOpenW(lpOpenParms->lpstrElementName, NULL,
261 MMIO_ALLOCBUF | MMIO_DENYWRITE | MMIO_READ);
263 if (wma->hFile == 0) {
264 WARN("can't find file=%s!\n", debugstr_w(lpOpenParms->lpstrElementName));
265 dwRet = MCIERR_FILE_NOT_FOUND;
267 if (!MCIAVI_GetInfo(wma))
268 dwRet = MCIERR_INVALID_FILE;
269 else if (!MCIAVI_OpenVideo(wma))
270 dwRet = MCIERR_CANNOT_LOAD_DRIVER;
271 else if (!MCIAVI_CreateWindow(wma, dwFlags, lpOpenParms))
272 dwRet = MCIERR_CREATEWINDOW;
276 FIXME("Don't record yet\n");
277 dwRet = MCIERR_UNSUPPORTED_FUNCTION;
282 TRACE("lpOpenParms->wDeviceID = %04x\n", lpOpenParms->wDeviceID);
284 wma->dwStatus = MCI_MODE_STOP;
285 wma->dwMciTimeFormat = MCI_FORMAT_FRAMES;
290 LeaveCriticalSection(&wma->cs);
294 /***************************************************************************
295 * MCIAVI_mciClose [internal]
297 DWORD MCIAVI_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
302 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
304 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
306 wma = (WINE_MCIAVI *)MCIAVI_mciGetOpenDev(wDevID);
307 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
309 EnterCriticalSection(&wma->cs);
311 if (wma->nUseCount == 1) {
312 if (wma->dwStatus != MCI_MODE_STOP)
313 dwRet = MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
316 if ((dwFlags & MCI_NOTIFY) && lpParms) {
317 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
319 MCI_NOTIFY_SUCCESSFUL);
321 LeaveCriticalSection(&wma->cs);
326 LeaveCriticalSection(&wma->cs);
330 static DWORD MCIAVI_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms);
332 struct MCIAVI_play_data
336 MCI_PLAY_PARMS params;
340 * MCIAVI_mciPlay_thread
342 * FIXME: probably should use a common worker thread created at the driver
343 * load time and queue all async commands to it.
345 static DWORD WINAPI MCIAVI_mciPlay_thread(LPVOID arg)
347 struct MCIAVI_play_data *data = (struct MCIAVI_play_data *)arg;
350 TRACE("In thread before async play command (id %08x, flags %08x)\n", data->wDevID, data->flags);
351 ret = MCIAVI_mciPlay(data->wDevID, data->flags | MCI_WAIT, &data->params);
352 TRACE("In thread after async play command (id %08x, flags %08x)\n", data->wDevID, data->flags);
354 HeapFree(GetProcessHeap(), 0, data);
359 * MCIAVI_mciPlay_async
361 static DWORD MCIAVI_mciPlay_async(WINE_MCIAVI *wma, DWORD dwFlags, LPMCI_PLAY_PARMS lpParams)
363 HANDLE handle, ack_event = wma->ack_event;
364 struct MCIAVI_play_data *data = HeapAlloc(GetProcessHeap(), 0, sizeof(struct MCIAVI_play_data));
366 if (!data) return MCIERR_OUT_OF_MEMORY;
368 data->wDevID = wma->wDevID;
369 data->flags = dwFlags;
370 memcpy(&data->params, lpParams, sizeof(MCI_PLAY_PARMS));
372 if (!(handle = CreateThread(NULL, 0, MCIAVI_mciPlay_thread, data, 0, NULL)))
374 WARN("Couldn't create thread for async play, playing synchronously\n");
375 return MCIAVI_mciPlay_thread(data);
377 SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL);
379 /* wait until the thread starts up, so the app could see a changed status */
380 WaitForSingleObject(ack_event, INFINITE);
381 TRACE("Async play has started\n");
385 /***************************************************************************
386 * MCIAVI_mciPlay [internal]
388 static DWORD MCIAVI_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
395 LPWAVEHDR waveHdr = NULL;
396 unsigned i, nHdr = 0;
397 DWORD dwFromFrame, dwToFrame;
399 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
401 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
403 wma = (WINE_MCIAVI *)MCIAVI_mciGetOpenDev(wDevID);
404 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
406 EnterCriticalSection(&wma->cs);
410 LeaveCriticalSection(&wma->cs);
411 return MCIERR_FILE_NOT_FOUND;
415 LeaveCriticalSection(&wma->cs);
416 return MCIERR_NO_WINDOW;
419 LeaveCriticalSection(&wma->cs);
421 if (!(dwFlags & MCI_WAIT))
422 return MCIAVI_mciPlay_async(wma, dwFlags, lpParms);
424 if (!(GetWindowLongW(wma->hWndPaint, GWL_STYLE) & WS_VISIBLE))
425 ShowWindow(wma->hWndPaint, SW_SHOWNA);
427 EnterCriticalSection(&wma->cs);
429 dwFromFrame = wma->dwCurrVideoFrame;
430 dwToFrame = wma->dwPlayableVideoFrames - 1;
432 if (lpParms && (dwFlags & MCI_FROM)) {
433 dwFromFrame = MCIAVI_ConvertTimeFormatToFrame(wma, lpParms->dwFrom);
435 if (lpParms && (dwFlags & MCI_TO)) {
436 dwToFrame = MCIAVI_ConvertTimeFormatToFrame(wma, lpParms->dwTo);
438 if (dwToFrame >= wma->dwPlayableVideoFrames)
439 dwToFrame = wma->dwPlayableVideoFrames - 1;
441 TRACE("Playing from frame=%u to frame=%u\n", dwFromFrame, dwToFrame);
443 wma->dwCurrVideoFrame = dwFromFrame;
444 wma->dwToVideoFrame = dwToFrame;
446 /* if already playing exit */
447 if (wma->dwStatus == MCI_MODE_PLAY)
449 LeaveCriticalSection(&wma->cs);
450 SetEvent(wma->ack_event);
454 if (wma->dwToVideoFrame <= wma->dwCurrVideoFrame)
457 SetEvent(wma->ack_event);
461 wma->dwStatus = MCI_MODE_PLAY;
462 /* signal the state change */
463 SetEvent(wma->ack_event);
465 if (dwFlags & (MCI_DGV_PLAY_REPEAT|MCI_DGV_PLAY_REVERSE|MCI_MCIAVI_PLAY_WINDOW|MCI_MCIAVI_PLAY_FULLSCREEN))
466 FIXME("Unsupported flag %08x\n", dwFlags);
468 /* time is in microseconds, we should convert it to milliseconds */
469 frameTime = (wma->mah.dwMicroSecPerFrame + 500) / 1000;
471 if (wma->lpWaveFormat) {
472 if (MCIAVI_OpenAudio(wma, &nHdr, &waveHdr) != 0)
474 /* can't play audio */
475 HeapFree(GetProcessHeap(), 0, wma->lpWaveFormat);
476 wma->lpWaveFormat = NULL;
479 /* fill the queue with as many wave headers as possible */
480 MCIAVI_PlayAudioBlocks(wma, nHdr, waveHdr);
483 while (wma->dwStatus == MCI_MODE_PLAY)
490 hDC = wma->hWndPaint ? GetDC(wma->hWndPaint) : 0;
493 MCIAVI_PaintFrame(wma, hDC);
494 ReleaseDC(wma->hWndPaint, hDC);
497 if (wma->lpWaveFormat) {
500 events[0] = wma->hStopEvent;
501 events[1] = wma->hEvent;
503 MCIAVI_PlayAudioBlocks(wma, nHdr, waveHdr);
504 delta = GetTickCount() - tc;
506 LeaveCriticalSection(&wma->cs);
507 ret = MsgWaitForMultipleObjectsEx(2, events,
508 (delta >= frameTime) ? 0 : frameTime - delta, QS_ALLINPUT, MWMO_INPUTAVAILABLE);
509 EnterCriticalSection(&wma->cs);
511 if (ret == WAIT_OBJECT_0 || wma->dwStatus != MCI_MODE_PLAY) break;
514 delta = GetTickCount() - tc;
515 if (delta < frameTime)
516 delta = frameTime - delta;
520 LeaveCriticalSection(&wma->cs);
521 ret = MsgWaitForMultipleObjectsEx(1, &wma->hStopEvent, delta,
522 QS_ALLINPUT, MWMO_INPUTAVAILABLE);
523 EnterCriticalSection(&wma->cs);
524 if (ret == WAIT_OBJECT_0) break;
526 if (wma->dwCurrVideoFrame < dwToFrame)
527 wma->dwCurrVideoFrame++;
532 if (wma->lpWaveFormat) {
533 while (wma->dwEventCount != nHdr - 1)
535 LeaveCriticalSection(&wma->cs);
537 EnterCriticalSection(&wma->cs);
540 /* just to get rid of some race conditions between play, stop and pause */
541 LeaveCriticalSection(&wma->cs);
542 waveOutReset(wma->hWave);
543 EnterCriticalSection(&wma->cs);
545 for (i = 0; i < nHdr; i++)
546 waveOutUnprepareHeader(wma->hWave, &waveHdr[i], sizeof(WAVEHDR));
551 if (wma->lpWaveFormat) {
552 HeapFree(GetProcessHeap(), 0, waveHdr);
555 LeaveCriticalSection(&wma->cs);
556 waveOutClose(wma->hWave);
557 EnterCriticalSection(&wma->cs);
560 CloseHandle(wma->hEvent);
564 wma->dwStatus = MCI_MODE_STOP;
566 if (lpParms && (dwFlags & MCI_NOTIFY)) {
567 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
568 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
569 wDevID, MCI_NOTIFY_SUCCESSFUL);
571 LeaveCriticalSection(&wma->cs);
575 /***************************************************************************
576 * MCIAVI_mciRecord [internal]
578 static DWORD MCIAVI_mciRecord(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECORD_PARMS lpParms)
582 FIXME("(%04x, %08X, %p) : stub\n", wDevID, dwFlags, lpParms);
584 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
586 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
588 wma = MCIAVI_mciGetOpenDev(wDevID);
589 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
591 EnterCriticalSection(&wma->cs);
592 wma->dwStatus = MCI_MODE_RECORD;
593 LeaveCriticalSection(&wma->cs);
597 /***************************************************************************
598 * MCIAVI_mciStop [internal]
600 static DWORD MCIAVI_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
605 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
607 wma = MCIAVI_mciGetOpenDev(wDevID);
608 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
610 EnterCriticalSection(&wma->cs);
612 TRACE("current status %04x\n", wma->dwStatus);
614 switch (wma->dwStatus) {
616 case MCI_MODE_RECORD:
617 LeaveCriticalSection(&wma->cs);
618 SetEvent(wma->hStopEvent);
619 EnterCriticalSection(&wma->cs);
622 /* Since our wave notification callback takes the lock,
623 * we must release it before resetting the device */
624 LeaveCriticalSection(&wma->cs);
625 dwRet = waveOutReset(wma->hWave);
626 EnterCriticalSection(&wma->cs);
629 do /* one more chance for an async thread to finish */
631 LeaveCriticalSection(&wma->cs);
633 EnterCriticalSection(&wma->cs);
634 } while (wma->dwStatus != MCI_MODE_STOP);
638 case MCI_MODE_NOT_READY:
642 if ((dwFlags & MCI_NOTIFY) && lpParms) {
643 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
644 wDevID, MCI_NOTIFY_SUCCESSFUL);
646 LeaveCriticalSection(&wma->cs);
650 /***************************************************************************
651 * MCIAVI_mciPause [internal]
653 static DWORD MCIAVI_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
657 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
659 wma = MCIAVI_mciGetOpenDev(wDevID);
660 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
662 EnterCriticalSection(&wma->cs);
664 if (wma->dwStatus == MCI_MODE_PLAY)
665 wma->dwStatus = MCI_MODE_PAUSE;
667 if (wma->lpWaveFormat) {
668 LeaveCriticalSection(&wma->cs);
669 return waveOutPause(wma->hWave);
672 LeaveCriticalSection(&wma->cs);
676 /***************************************************************************
677 * MCIAVI_mciResume [internal]
679 static DWORD MCIAVI_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
683 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
685 wma = MCIAVI_mciGetOpenDev(wDevID);
686 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
688 EnterCriticalSection(&wma->cs);
690 if (wma->dwStatus == MCI_MODE_PAUSE)
691 wma->dwStatus = MCI_MODE_PLAY;
693 if (wma->lpWaveFormat) {
694 LeaveCriticalSection(&wma->cs);
695 return waveOutRestart(wma->hWave);
698 LeaveCriticalSection(&wma->cs);
702 /***************************************************************************
703 * MCIAVI_mciSeek [internal]
705 static DWORD MCIAVI_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
709 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
711 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
713 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
715 wma = MCIAVI_mciGetOpenDev(wDevID);
716 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
718 EnterCriticalSection(&wma->cs);
720 if (dwFlags & MCI_SEEK_TO_START) {
721 wma->dwCurrVideoFrame = 0;
722 } else if (dwFlags & MCI_SEEK_TO_END) {
723 wma->dwCurrVideoFrame = wma->dwPlayableVideoFrames - 1;
724 } else if (dwFlags & MCI_TO) {
725 if (lpParms->dwTo > wma->dwPlayableVideoFrames - 1)
726 lpParms->dwTo = wma->dwPlayableVideoFrames - 1;
727 wma->dwCurrVideoFrame = MCIAVI_ConvertTimeFormatToFrame(wma, lpParms->dwTo);
729 WARN("dwFlag doesn't tell where to seek to...\n");
730 LeaveCriticalSection(&wma->cs);
731 return MCIERR_MISSING_PARAMETER;
734 TRACE("Seeking to frame=%u bytes\n", wma->dwCurrVideoFrame);
736 if (dwFlags & MCI_NOTIFY) {
737 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
738 wDevID, MCI_NOTIFY_SUCCESSFUL);
740 LeaveCriticalSection(&wma->cs);
744 /*****************************************************************************
745 * MCIAVI_mciLoad [internal]
747 static DWORD MCIAVI_mciLoad(UINT wDevID, DWORD dwFlags, LPMCI_DGV_LOAD_PARMSW lpParms)
751 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
753 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
755 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
757 wma = MCIAVI_mciGetOpenDev(wDevID);
758 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
763 /******************************************************************************
764 * MCIAVI_mciSave [internal]
766 static DWORD MCIAVI_mciSave(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SAVE_PARMSW lpParms)
770 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
772 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
774 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
776 wma = MCIAVI_mciGetOpenDev(wDevID);
777 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
782 /******************************************************************************
783 * MCIAVI_mciFreeze [internal]
785 static DWORD MCIAVI_mciFreeze(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
789 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
791 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
793 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
795 wma = MCIAVI_mciGetOpenDev(wDevID);
796 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
801 /******************************************************************************
802 * MCIAVI_mciRealize [internal]
804 static DWORD MCIAVI_mciRealize(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
808 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
810 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
812 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
814 wma = MCIAVI_mciGetOpenDev(wDevID);
815 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
820 /******************************************************************************
821 * MCIAVI_mciUnFreeze [internal]
823 static DWORD MCIAVI_mciUnFreeze(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
827 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
829 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
831 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
833 wma = MCIAVI_mciGetOpenDev(wDevID);
834 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
839 /******************************************************************************
840 * MCIAVI_mciUpdate [internal]
842 static DWORD MCIAVI_mciUpdate(UINT wDevID, DWORD dwFlags, LPMCI_DGV_UPDATE_PARMS lpParms)
846 TRACE("%04x, %08x, %p\n", wDevID, dwFlags, lpParms);
848 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
850 wma = MCIAVI_mciGetOpenDev(wDevID);
851 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
853 EnterCriticalSection(&wma->cs);
855 if (dwFlags & MCI_DGV_UPDATE_HDC)
856 MCIAVI_PaintFrame(wma, lpParms->hDC);
858 LeaveCriticalSection(&wma->cs);
863 /******************************************************************************
864 * MCIAVI_mciStep [internal]
866 static DWORD MCIAVI_mciStep(UINT wDevID, DWORD dwFlags, LPMCI_DGV_STEP_PARMS lpParms)
870 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
872 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
874 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
876 wma = MCIAVI_mciGetOpenDev(wDevID);
877 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
882 /******************************************************************************
883 * MCIAVI_mciCopy [internal]
885 static DWORD MCIAVI_mciCopy(UINT wDevID, DWORD dwFlags, LPMCI_DGV_COPY_PARMS lpParms)
889 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
891 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
893 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
895 wma = MCIAVI_mciGetOpenDev(wDevID);
896 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
901 /******************************************************************************
902 * MCIAVI_mciCut [internal]
904 static DWORD MCIAVI_mciCut(UINT wDevID, DWORD dwFlags, LPMCI_DGV_CUT_PARMS lpParms)
908 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
910 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
912 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
914 wma = MCIAVI_mciGetOpenDev(wDevID);
915 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
920 /******************************************************************************
921 * MCIAVI_mciDelete [internal]
923 static DWORD MCIAVI_mciDelete(UINT wDevID, DWORD dwFlags, LPMCI_DGV_DELETE_PARMS lpParms)
927 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
929 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
931 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
933 wma = MCIAVI_mciGetOpenDev(wDevID);
934 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
939 /******************************************************************************
940 * MCIAVI_mciPaste [internal]
942 static DWORD MCIAVI_mciPaste(UINT wDevID, DWORD dwFlags, LPMCI_DGV_PASTE_PARMS lpParms)
946 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
948 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
950 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
952 wma = MCIAVI_mciGetOpenDev(wDevID);
953 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
958 /******************************************************************************
959 * MCIAVI_mciCue [internal]
961 static DWORD MCIAVI_mciCue(UINT wDevID, DWORD dwFlags, LPMCI_DGV_CUE_PARMS lpParms)
965 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
967 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
969 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
971 wma = MCIAVI_mciGetOpenDev(wDevID);
972 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
977 /******************************************************************************
978 * MCIAVI_mciCapture [internal]
980 static DWORD MCIAVI_mciCapture(UINT wDevID, DWORD dwFlags, LPMCI_DGV_CAPTURE_PARMSW lpParms)
984 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
986 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
988 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
990 wma = MCIAVI_mciGetOpenDev(wDevID);
991 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
996 /******************************************************************************
997 * MCIAVI_mciMonitor [internal]
999 static DWORD MCIAVI_mciMonitor(UINT wDevID, DWORD dwFlags, LPMCI_DGV_MONITOR_PARMS lpParms)
1003 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
1005 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1007 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1009 wma = MCIAVI_mciGetOpenDev(wDevID);
1010 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1015 /******************************************************************************
1016 * MCIAVI_mciReserve [internal]
1018 static DWORD MCIAVI_mciReserve(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RESERVE_PARMSW lpParms)
1022 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
1024 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1026 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1028 wma = MCIAVI_mciGetOpenDev(wDevID);
1029 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1034 /******************************************************************************
1035 * MCIAVI_mciSetAudio [internal]
1037 static DWORD MCIAVI_mciSetAudio(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SETAUDIO_PARMSW lpParms)
1041 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
1043 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1045 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1047 wma = MCIAVI_mciGetOpenDev(wDevID);
1048 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1053 /******************************************************************************
1054 * MCIAVI_mciSignal [internal]
1056 static DWORD MCIAVI_mciSignal(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SIGNAL_PARMS lpParms)
1060 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
1062 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1064 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1066 wma = MCIAVI_mciGetOpenDev(wDevID);
1067 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1072 /******************************************************************************
1073 * MCIAVI_mciSetVideo [internal]
1075 static DWORD MCIAVI_mciSetVideo(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SETVIDEO_PARMSW lpParms)
1079 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
1081 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1083 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1085 wma = MCIAVI_mciGetOpenDev(wDevID);
1086 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1091 /******************************************************************************
1092 * MCIAVI_mciQuality [internal]
1094 static DWORD MCIAVI_mciQuality(UINT wDevID, DWORD dwFlags, LPMCI_DGV_QUALITY_PARMSW lpParms)
1098 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
1100 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1102 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1104 wma = MCIAVI_mciGetOpenDev(wDevID);
1105 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1110 /******************************************************************************
1111 * MCIAVI_mciList [internal]
1113 static DWORD MCIAVI_mciList(UINT wDevID, DWORD dwFlags, LPMCI_DGV_LIST_PARMSW lpParms)
1117 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
1119 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1121 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1123 wma = MCIAVI_mciGetOpenDev(wDevID);
1124 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1129 /******************************************************************************
1130 * MCIAVI_mciUndo [internal]
1132 static DWORD MCIAVI_mciUndo(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1136 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
1138 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1140 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1142 wma = MCIAVI_mciGetOpenDev(wDevID);
1143 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1148 /******************************************************************************
1149 * MCIAVI_mciConfigure [internal]
1151 static DWORD MCIAVI_mciConfigure(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1155 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
1157 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1159 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1161 wma = MCIAVI_mciGetOpenDev(wDevID);
1162 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1167 /******************************************************************************
1168 * MCIAVI_mciRestore [internal]
1170 static DWORD MCIAVI_mciRestore(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RESTORE_PARMSW lpParms)
1174 FIXME("(%04x, %08x, %p) : stub\n", wDevID, dwFlags, lpParms);
1176 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1178 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1180 wma = MCIAVI_mciGetOpenDev(wDevID);
1181 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1186 /*======================================================================*
1187 * MCI AVI entry points *
1188 *======================================================================*/
1190 /**************************************************************************
1191 * DriverProc (MCIAVI.@)
1193 LRESULT CALLBACK MCIAVI_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
1194 LPARAM dwParam1, LPARAM dwParam2)
1196 TRACE("(%08lX, %p, %08X, %08lX, %08lX)\n",
1197 dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1200 case DRV_LOAD: return 1;
1201 case DRV_FREE: return 1;
1202 case DRV_OPEN: return MCIAVI_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
1203 case DRV_CLOSE: return MCIAVI_drvClose(dwDevID);
1204 case DRV_ENABLE: return 1;
1205 case DRV_DISABLE: return 1;
1206 case DRV_QUERYCONFIGURE: return 1;
1207 case DRV_CONFIGURE: return MCIAVI_drvConfigure(dwDevID);
1208 case DRV_INSTALL: return DRVCNF_RESTART;
1209 case DRV_REMOVE: return DRVCNF_RESTART;
1212 /* session instance */
1213 if (dwDevID == 0xFFFFFFFF) return 1;
1216 case MCI_OPEN_DRIVER: return MCIAVI_mciOpen (dwDevID, dwParam1, (LPMCI_DGV_OPEN_PARMSW) dwParam2);
1217 case MCI_CLOSE_DRIVER: return MCIAVI_mciClose (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1218 case MCI_PLAY: return MCIAVI_mciPlay (dwDevID, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
1219 case MCI_RECORD: return MCIAVI_mciRecord (dwDevID, dwParam1, (LPMCI_DGV_RECORD_PARMS) dwParam2);
1220 case MCI_STOP: return MCIAVI_mciStop (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1221 case MCI_SET: return MCIAVI_mciSet (dwDevID, dwParam1, (LPMCI_DGV_SET_PARMS) dwParam2);
1222 case MCI_PAUSE: return MCIAVI_mciPause (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1223 case MCI_RESUME: return MCIAVI_mciResume (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1224 case MCI_STATUS: return MCIAVI_mciStatus (dwDevID, dwParam1, (LPMCI_DGV_STATUS_PARMSW) dwParam2);
1225 case MCI_GETDEVCAPS: return MCIAVI_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS) dwParam2);
1226 case MCI_INFO: return MCIAVI_mciInfo (dwDevID, dwParam1, (LPMCI_DGV_INFO_PARMSW) dwParam2);
1227 case MCI_SEEK: return MCIAVI_mciSeek (dwDevID, dwParam1, (LPMCI_SEEK_PARMS) dwParam2);
1228 case MCI_PUT: return MCIAVI_mciPut (dwDevID, dwParam1, (LPMCI_DGV_PUT_PARMS) dwParam2);
1229 case MCI_WINDOW: return MCIAVI_mciWindow (dwDevID, dwParam1, (LPMCI_DGV_WINDOW_PARMSW) dwParam2);
1230 case MCI_LOAD: return MCIAVI_mciLoad (dwDevID, dwParam1, (LPMCI_DGV_LOAD_PARMSW) dwParam2);
1231 case MCI_SAVE: return MCIAVI_mciSave (dwDevID, dwParam1, (LPMCI_DGV_SAVE_PARMSW) dwParam2);
1232 case MCI_FREEZE: return MCIAVI_mciFreeze (dwDevID, dwParam1, (LPMCI_DGV_RECT_PARMS) dwParam2);
1233 case MCI_REALIZE: return MCIAVI_mciRealize (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1234 case MCI_UNFREEZE: return MCIAVI_mciUnFreeze (dwDevID, dwParam1, (LPMCI_DGV_RECT_PARMS) dwParam2);
1235 case MCI_UPDATE: return MCIAVI_mciUpdate (dwDevID, dwParam1, (LPMCI_DGV_UPDATE_PARMS) dwParam2);
1236 case MCI_WHERE: return MCIAVI_mciWhere (dwDevID, dwParam1, (LPMCI_DGV_RECT_PARMS) dwParam2);
1237 case MCI_STEP: return MCIAVI_mciStep (dwDevID, dwParam1, (LPMCI_DGV_STEP_PARMS) dwParam2);
1238 case MCI_COPY: return MCIAVI_mciCopy (dwDevID, dwParam1, (LPMCI_DGV_COPY_PARMS) dwParam2);
1239 case MCI_CUT: return MCIAVI_mciCut (dwDevID, dwParam1, (LPMCI_DGV_CUT_PARMS) dwParam2);
1240 case MCI_DELETE: return MCIAVI_mciDelete (dwDevID, dwParam1, (LPMCI_DGV_DELETE_PARMS) dwParam2);
1241 case MCI_PASTE: return MCIAVI_mciPaste (dwDevID, dwParam1, (LPMCI_DGV_PASTE_PARMS) dwParam2);
1242 case MCI_CUE: return MCIAVI_mciCue (dwDevID, dwParam1, (LPMCI_DGV_CUE_PARMS) dwParam2);
1243 /* Digital Video specific */
1244 case MCI_CAPTURE: return MCIAVI_mciCapture (dwDevID, dwParam1, (LPMCI_DGV_CAPTURE_PARMSW) dwParam2);
1245 case MCI_MONITOR: return MCIAVI_mciMonitor (dwDevID, dwParam1, (LPMCI_DGV_MONITOR_PARMS) dwParam2);
1246 case MCI_RESERVE: return MCIAVI_mciReserve (dwDevID, dwParam1, (LPMCI_DGV_RESERVE_PARMSW) dwParam2);
1247 case MCI_SETAUDIO: return MCIAVI_mciSetAudio (dwDevID, dwParam1, (LPMCI_DGV_SETAUDIO_PARMSW) dwParam2);
1248 case MCI_SIGNAL: return MCIAVI_mciSignal (dwDevID, dwParam1, (LPMCI_DGV_SIGNAL_PARMS) dwParam2);
1249 case MCI_SETVIDEO: return MCIAVI_mciSetVideo (dwDevID, dwParam1, (LPMCI_DGV_SETVIDEO_PARMSW) dwParam2);
1250 case MCI_QUALITY: return MCIAVI_mciQuality (dwDevID, dwParam1, (LPMCI_DGV_QUALITY_PARMSW) dwParam2);
1251 case MCI_LIST: return MCIAVI_mciList (dwDevID, dwParam1, (LPMCI_DGV_LIST_PARMSW) dwParam2);
1252 case MCI_UNDO: return MCIAVI_mciUndo (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1253 case MCI_CONFIGURE: return MCIAVI_mciConfigure (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1254 case MCI_RESTORE: return MCIAVI_mciRestore (dwDevID, dwParam1, (LPMCI_DGV_RESTORE_PARMSW) dwParam2);
1258 WARN("Unsupported command [%u]\n", wMsg);
1262 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
1265 TRACE("Sending msg [%u] to default driver proc\n", wMsg);
1266 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1268 return MCIERR_UNRECOGNIZED_COMMAND;