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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 * ===================================================================
49 * FIXME: should be using the new mmThreadXXXX functions from WINMM
51 * it would require to add a wine internal flag to mmThreadCreate
52 * in order to pass a 32 bit function instead of a 16 bit one
53 * ===================================================================
54 * =================================================================== */
63 /**************************************************************************
64 * MCI_SCAStarter [internal]
66 static DWORD CALLBACK MCI_SCAStarter(LPVOID arg)
68 struct SCA* sca = (struct SCA*)arg;
71 TRACE("In thread before async command (%08x,%04x,%08lx,%08lx)\n",
72 sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2);
73 ret = mciSendCommandA(sca->wDevID, sca->wMsg, sca->dwParam1 | MCI_WAIT, sca->dwParam2);
74 TRACE("In thread after async command (%08x,%04x,%08lx,%08lx)\n",
75 sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2);
76 HeapFree(GetProcessHeap(), 0, sca);
80 /**************************************************************************
81 * MCI_SendCommandAsync [internal]
83 static DWORD MCI_SendCommandAsync(UINT wDevID, UINT wMsg, DWORD dwParam1,
84 DWORD_PTR dwParam2, UINT size)
87 struct SCA* sca = HeapAlloc(GetProcessHeap(), 0, sizeof(struct SCA) + size);
90 return MCIERR_OUT_OF_MEMORY;
94 sca->dwParam1 = dwParam1;
96 if (size && dwParam2) {
97 sca->dwParam2 = (DWORD_PTR)sca + sizeof(struct SCA);
98 /* copy structure passed by program in dwParam2 to be sure
99 * we can still use it whatever the program does
101 memcpy((LPVOID)sca->dwParam2, (LPVOID)dwParam2, size);
103 sca->dwParam2 = dwParam2;
106 if ((handle = CreateThread(NULL, 0, MCI_SCAStarter, sca, 0, NULL)) == 0) {
107 WARN("Couldn't allocate thread for async command handling, sending synchronously\n");
108 return MCI_SCAStarter(&sca);
110 SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL);
115 /*======================================================================*
116 * MCI AVI implemantation *
117 *======================================================================*/
119 HINSTANCE MCIAVI_hInstance = 0;
121 /***********************************************************************
124 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
127 case DLL_PROCESS_ATTACH:
128 DisableThreadLibraryCalls(hInstDLL);
129 MCIAVI_hInstance = hInstDLL;
135 /**************************************************************************
136 * MCIAVI_drvOpen [internal]
138 static DWORD MCIAVI_drvOpen(LPCWSTR str, LPMCI_OPEN_DRIVER_PARMSW modp)
141 static const WCHAR mciAviWStr[] = {'M','C','I','A','V','I',0};
143 TRACE("%s, %p\n", debugstr_w(str), modp);
145 /* session instance */
146 if (!modp) return 0xFFFFFFFF;
148 if (!MCIAVI_RegisterClass()) return 0;
150 wma = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCIAVI));
154 InitializeCriticalSection(&wma->cs);
155 wma->hStopEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
156 wma->wDevID = modp->wDeviceID;
157 wma->wCommandTable = mciLoadCommandResource(MCIAVI_hInstance, mciAviWStr, 0);
158 modp->wCustomCommandTable = wma->wCommandTable;
159 modp->wType = MCI_DEVTYPE_DIGITAL_VIDEO;
160 mciSetDriverData(wma->wDevID, (DWORD)wma);
162 return modp->wDeviceID;
165 /**************************************************************************
166 * MCIAVI_drvClose [internal]
168 static DWORD MCIAVI_drvClose(DWORD dwDevID)
172 TRACE("%04lx\n", dwDevID);
174 /* finish all outstanding things */
175 MCIAVI_mciClose(dwDevID, MCI_WAIT, NULL);
177 wma = (WINE_MCIAVI*)mciGetDriverData(dwDevID);
180 MCIAVI_UnregisterClass();
182 EnterCriticalSection(&wma->cs);
184 mciSetDriverData(dwDevID, 0);
185 mciFreeCommandResource(wma->wCommandTable);
187 CloseHandle(wma->hStopEvent);
189 LeaveCriticalSection(&wma->cs);
190 DeleteCriticalSection(&wma->cs);
192 HeapFree(GetProcessHeap(), 0, wma);
195 return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
198 /**************************************************************************
199 * MCIAVI_drvConfigure [internal]
201 static DWORD MCIAVI_drvConfigure(DWORD dwDevID)
205 TRACE("%04lx\n", dwDevID);
207 MCIAVI_mciStop(dwDevID, MCI_WAIT, NULL);
209 wma = (WINE_MCIAVI*)mciGetDriverData(dwDevID);
212 MessageBoxA(0, "Sample AVI Wine Driver !", "MM-Wine Driver", MB_OK);
218 /**************************************************************************
219 * MCIAVI_mciGetOpenDev [internal]
221 WINE_MCIAVI* MCIAVI_mciGetOpenDev(UINT wDevID)
223 WINE_MCIAVI* wma = (WINE_MCIAVI*)mciGetDriverData(wDevID);
225 if (wma == NULL || wma->nUseCount == 0) {
226 WARN("Invalid wDevID=%u\n", wDevID);
232 static void MCIAVI_CleanUp(WINE_MCIAVI* wma)
234 /* to prevent handling in WindowProc */
235 wma->dwStatus = MCI_MODE_NOT_READY;
237 mmioClose(wma->hFile, 0);
240 HeapFree(GetProcessHeap(), 0, wma->lpFileName);
241 wma->lpFileName = NULL;
243 HeapFree(GetProcessHeap(), 0, wma->lpVideoIndex);
244 wma->lpVideoIndex = NULL;
245 HeapFree(GetProcessHeap(), 0, wma->lpAudioIndex);
246 wma->lpAudioIndex = NULL;
247 if (wma->hic) ICClose(wma->hic);
249 HeapFree(GetProcessHeap(), 0, wma->inbih);
251 HeapFree(GetProcessHeap(), 0, wma->outbih);
253 HeapFree(GetProcessHeap(), 0, wma->indata);
255 HeapFree(GetProcessHeap(), 0, wma->outdata);
257 if (wma->hbmFrame) DeleteObject(wma->hbmFrame);
259 if (wma->hWnd) DestroyWindow(wma->hWnd);
262 HeapFree(GetProcessHeap(), 0, wma->lpWaveFormat);
263 wma->lpWaveFormat = 0;
265 memset(&wma->mah, 0, sizeof(wma->mah));
266 memset(&wma->ash_video, 0, sizeof(wma->ash_video));
267 memset(&wma->ash_audio, 0, sizeof(wma->ash_audio));
268 wma->dwCurrVideoFrame = wma->dwCurrAudioBlock = 0;
269 wma->dwCachedFrame = -1;
273 /***************************************************************************
274 * MCIAVI_mciOpen [internal]
276 static DWORD MCIAVI_mciOpen(UINT wDevID, DWORD dwFlags,
277 LPMCI_DGV_OPEN_PARMSW lpOpenParms)
282 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpOpenParms);
284 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
286 if (lpOpenParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
288 wma = (WINE_MCIAVI *)mciGetDriverData(wDevID);
289 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
291 EnterCriticalSection(&wma->cs);
293 if (wma->nUseCount > 0) {
294 /* The driver is already open on this channel */
295 /* If the driver was opened shareable before and this open specifies */
296 /* shareable then increment the use count */
297 if (wma->fShareable && (dwFlags & MCI_OPEN_SHAREABLE))
301 LeaveCriticalSection(&wma->cs);
302 return MCIERR_MUST_USE_SHAREABLE;
306 wma->fShareable = dwFlags & MCI_OPEN_SHAREABLE;
309 wma->dwStatus = MCI_MODE_NOT_READY;
311 if (dwFlags & MCI_OPEN_ELEMENT) {
312 if (dwFlags & MCI_OPEN_ELEMENT_ID) {
313 /* could it be that (DWORD)lpOpenParms->lpstrElementName
314 * contains the hFile value ?
316 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
317 } else if (strlenW(lpOpenParms->lpstrElementName) > 0) {
318 /* FIXME : what should be done id wma->hFile is already != 0, or the driver is playin' */
319 TRACE("MCI_OPEN_ELEMENT %s!\n", debugstr_w(lpOpenParms->lpstrElementName));
321 if (lpOpenParms->lpstrElementName && (strlenW(lpOpenParms->lpstrElementName) > 0))
323 wma->lpFileName = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpOpenParms->lpstrElementName) + 1) * sizeof(WCHAR));
324 strcpyW(wma->lpFileName, lpOpenParms->lpstrElementName);
326 wma->hFile = mmioOpenW(lpOpenParms->lpstrElementName, NULL,
327 MMIO_ALLOCBUF | MMIO_DENYWRITE | MMIO_READ);
329 if (wma->hFile == 0) {
330 WARN("can't find file=%s!\n", debugstr_w(lpOpenParms->lpstrElementName));
331 dwRet = MCIERR_FILE_NOT_FOUND;
333 if (!MCIAVI_GetInfo(wma))
334 dwRet = MCIERR_INVALID_FILE;
335 else if (!MCIAVI_OpenVideo(wma))
336 dwRet = MCIERR_CANNOT_LOAD_DRIVER;
337 else if (!MCIAVI_CreateWindow(wma, dwFlags, lpOpenParms))
338 dwRet = MCIERR_CREATEWINDOW;
342 FIXME("Don't record yet\n");
343 dwRet = MCIERR_UNSUPPORTED_FUNCTION;
348 TRACE("lpOpenParms->wDeviceID = %04x\n", lpOpenParms->wDeviceID);
350 wma->dwStatus = MCI_MODE_STOP;
351 wma->dwMciTimeFormat = MCI_FORMAT_FRAMES;
356 LeaveCriticalSection(&wma->cs);
360 /***************************************************************************
361 * MCIAVI_mciClose [internal]
363 DWORD MCIAVI_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
368 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
370 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
372 wma = (WINE_MCIAVI *)MCIAVI_mciGetOpenDev(wDevID);
373 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
375 EnterCriticalSection(&wma->cs);
377 if (wma->nUseCount == 1) {
378 if (wma->dwStatus != MCI_MODE_STOP)
379 dwRet = MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
382 if ((dwFlags & MCI_NOTIFY) && lpParms) {
383 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
385 MCI_NOTIFY_SUCCESSFUL);
387 LeaveCriticalSection(&wma->cs);
392 LeaveCriticalSection(&wma->cs);
396 /***************************************************************************
397 * MCIAVI_mciPlay [internal]
399 static DWORD MCIAVI_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
406 LPWAVEHDR waveHdr = NULL;
407 unsigned i, nHdr = 0;
408 DWORD dwFromFrame, dwToFrame;
410 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
412 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
414 wma = (WINE_MCIAVI *)MCIAVI_mciGetOpenDev(wDevID);
415 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
417 EnterCriticalSection(&wma->cs);
421 LeaveCriticalSection(&wma->cs);
422 return MCIERR_FILE_NOT_FOUND;
426 LeaveCriticalSection(&wma->cs);
427 return MCIERR_NO_WINDOW;
430 LeaveCriticalSection(&wma->cs);
432 if (!(dwFlags & MCI_WAIT)) {
433 return MCI_SendCommandAsync(wDevID, MCI_PLAY, dwFlags,
434 (DWORD_PTR)lpParms, sizeof(MCI_PLAY_PARMS));
437 if (!(GetWindowLongW(wma->hWndPaint, GWL_STYLE) & WS_VISIBLE))
438 ShowWindow(wma->hWndPaint, SW_SHOWNA);
440 EnterCriticalSection(&wma->cs);
442 dwFromFrame = wma->dwCurrVideoFrame;
443 dwToFrame = wma->dwPlayableVideoFrames - 1;
445 if (lpParms && (dwFlags & MCI_FROM)) {
446 dwFromFrame = MCIAVI_ConvertTimeFormatToFrame(wma, lpParms->dwFrom);
448 if (lpParms && (dwFlags & MCI_TO)) {
449 dwToFrame = MCIAVI_ConvertTimeFormatToFrame(wma, lpParms->dwTo);
451 if (dwToFrame >= wma->dwPlayableVideoFrames)
452 dwToFrame = wma->dwPlayableVideoFrames - 1;
454 TRACE("Playing from frame=%lu to frame=%lu\n", dwFromFrame, dwToFrame);
456 wma->dwCurrVideoFrame = dwFromFrame;
457 wma->dwToVideoFrame = dwToFrame;
459 /* if already playing exit */
460 if (wma->dwStatus == MCI_MODE_PLAY)
462 LeaveCriticalSection(&wma->cs);
466 if (wma->dwToVideoFrame <= wma->dwCurrVideoFrame)
472 wma->dwStatus = MCI_MODE_PLAY;
474 if (dwFlags & (MCI_DGV_PLAY_REPEAT|MCI_DGV_PLAY_REVERSE|MCI_MCIAVI_PLAY_WINDOW|MCI_MCIAVI_PLAY_FULLSCREEN))
475 FIXME("Unsupported flag %08lx\n", dwFlags);
477 /* time is in microseconds, we should convert it to milliseconds */
478 frameTime = (wma->mah.dwMicroSecPerFrame + 500) / 1000;
480 if (wma->lpWaveFormat) {
481 if (MCIAVI_OpenAudio(wma, &nHdr, &waveHdr) != 0)
483 /* can't play audio */
484 HeapFree(GetProcessHeap(), 0, wma->lpWaveFormat);
485 wma->lpWaveFormat = NULL;
488 /* fill the queue with as many wave headers as possible */
489 MCIAVI_PlayAudioBlocks(wma, nHdr, waveHdr);
492 while (wma->dwStatus == MCI_MODE_PLAY)
498 hDC = wma->hWndPaint ? GetDC(wma->hWndPaint) : 0;
501 MCIAVI_PaintFrame(wma, hDC);
502 ReleaseDC(wma->hWndPaint, hDC);
505 if (wma->lpWaveFormat) {
509 events[0] = wma->hStopEvent;
510 events[1] = wma->hEvent;
512 MCIAVI_PlayAudioBlocks(wma, nHdr, waveHdr);
513 delta = GetTickCount() - tc;
515 LeaveCriticalSection(&wma->cs);
516 ret = MsgWaitForMultipleObjectsEx(2, events,
517 (delta >= frameTime) ? 0 : frameTime - delta, QS_ALLINPUT, MWMO_INPUTAVAILABLE);
518 EnterCriticalSection(&wma->cs);
520 if (ret == WAIT_OBJECT_0 || wma->dwStatus != MCI_MODE_PLAY) break;
523 delta = GetTickCount() - tc;
524 if (delta < frameTime)
528 LeaveCriticalSection(&wma->cs);
529 ret = MsgWaitForMultipleObjectsEx(1, &wma->hStopEvent, frameTime - delta,
530 QS_ALLINPUT, MWMO_INPUTAVAILABLE);
531 EnterCriticalSection(&wma->cs);
532 if (ret == WAIT_OBJECT_0) break;
535 if (wma->dwCurrVideoFrame < dwToFrame)
536 wma->dwCurrVideoFrame++;
541 if (wma->lpWaveFormat) {
542 while (wma->dwEventCount != nHdr - 1)
544 LeaveCriticalSection(&wma->cs);
546 EnterCriticalSection(&wma->cs);
549 /* just to get rid of some race conditions between play, stop and pause */
550 LeaveCriticalSection(&wma->cs);
551 waveOutReset(wma->hWave);
552 EnterCriticalSection(&wma->cs);
554 for (i = 0; i < nHdr; i++)
555 waveOutUnprepareHeader(wma->hWave, &waveHdr[i], sizeof(WAVEHDR));
560 if (wma->lpWaveFormat) {
561 HeapFree(GetProcessHeap(), 0, waveHdr);
564 LeaveCriticalSection(&wma->cs);
565 waveOutClose(wma->hWave);
566 EnterCriticalSection(&wma->cs);
569 CloseHandle(wma->hEvent);
573 wma->dwStatus = MCI_MODE_STOP;
575 if (lpParms && (dwFlags & MCI_NOTIFY)) {
576 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
577 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
578 wDevID, MCI_NOTIFY_SUCCESSFUL);
580 LeaveCriticalSection(&wma->cs);
584 /***************************************************************************
585 * MCIAVI_mciRecord [internal]
587 static DWORD MCIAVI_mciRecord(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECORD_PARMS lpParms)
591 FIXME("(%04x, %08lX, %p) : stub\n", wDevID, dwFlags, lpParms);
593 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
595 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
597 wma = MCIAVI_mciGetOpenDev(wDevID);
598 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
600 EnterCriticalSection(&wma->cs);
601 wma->dwStatus = MCI_MODE_RECORD;
602 LeaveCriticalSection(&wma->cs);
606 /***************************************************************************
607 * MCIAVI_mciStop [internal]
609 static DWORD MCIAVI_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
614 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
616 wma = MCIAVI_mciGetOpenDev(wDevID);
617 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
619 EnterCriticalSection(&wma->cs);
621 switch (wma->dwStatus) {
623 case MCI_MODE_RECORD:
624 LeaveCriticalSection(&wma->cs);
625 SetEvent(wma->hStopEvent);
626 EnterCriticalSection(&wma->cs);
629 /* Since our wave notification callback takes the lock,
630 * we must release it before resetting the device */
631 LeaveCriticalSection(&wma->cs);
632 dwRet = waveOutReset(wma->hWave);
633 EnterCriticalSection(&wma->cs);
636 do /* one more chance for an async thread to finish */
638 LeaveCriticalSection(&wma->cs);
640 EnterCriticalSection(&wma->cs);
641 } while (wma->dwStatus != MCI_MODE_STOP);
645 case MCI_MODE_NOT_READY:
649 if ((dwFlags & MCI_NOTIFY) && lpParms) {
650 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
651 wDevID, MCI_NOTIFY_SUCCESSFUL);
653 LeaveCriticalSection(&wma->cs);
657 /***************************************************************************
658 * MCIAVI_mciPause [internal]
660 static DWORD MCIAVI_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
664 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
666 wma = MCIAVI_mciGetOpenDev(wDevID);
667 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
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, %08lX, %p)\n", wDevID, dwFlags, lpParms);
692 wma = MCIAVI_mciGetOpenDev(wDevID);
693 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
695 EnterCriticalSection(&wma->cs);
697 if (wma->dwStatus == MCI_MODE_PAUSE)
698 wma->dwStatus = MCI_MODE_PLAY;
700 if (wma->lpWaveFormat) {
701 LeaveCriticalSection(&wma->cs);
702 return waveOutRestart(wma->hWave);
705 LeaveCriticalSection(&wma->cs);
709 /***************************************************************************
710 * MCIAVI_mciSeek [internal]
712 static DWORD MCIAVI_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
716 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
718 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
720 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
722 wma = MCIAVI_mciGetOpenDev(wDevID);
723 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
725 EnterCriticalSection(&wma->cs);
727 if (dwFlags & MCI_SEEK_TO_START) {
728 wma->dwCurrVideoFrame = 0;
729 } else if (dwFlags & MCI_SEEK_TO_END) {
730 wma->dwCurrVideoFrame = wma->dwPlayableVideoFrames - 1;
731 } else if (dwFlags & MCI_TO) {
732 if (lpParms->dwTo > wma->dwPlayableVideoFrames - 1)
733 lpParms->dwTo = wma->dwPlayableVideoFrames - 1;
734 wma->dwCurrVideoFrame = MCIAVI_ConvertTimeFormatToFrame(wma, lpParms->dwTo);
736 WARN("dwFlag doesn't tell where to seek to...\n");
737 LeaveCriticalSection(&wma->cs);
738 return MCIERR_MISSING_PARAMETER;
741 TRACE("Seeking to frame=%lu bytes\n", wma->dwCurrVideoFrame);
743 if (dwFlags & MCI_NOTIFY) {
744 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
745 wDevID, MCI_NOTIFY_SUCCESSFUL);
747 LeaveCriticalSection(&wma->cs);
751 /*****************************************************************************
752 * MCIAVI_mciLoad [internal]
754 static DWORD MCIAVI_mciLoad(UINT wDevID, DWORD dwFlags, LPMCI_DGV_LOAD_PARMSW lpParms)
758 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
760 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
762 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
764 wma = MCIAVI_mciGetOpenDev(wDevID);
765 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
770 /******************************************************************************
771 * MCIAVI_mciSave [internal]
773 static DWORD MCIAVI_mciSave(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SAVE_PARMSW lpParms)
777 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
779 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
781 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
783 wma = MCIAVI_mciGetOpenDev(wDevID);
784 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
789 /******************************************************************************
790 * MCIAVI_mciFreeze [internal]
792 static DWORD MCIAVI_mciFreeze(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
796 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
798 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
800 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
802 wma = MCIAVI_mciGetOpenDev(wDevID);
803 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
808 /******************************************************************************
809 * MCIAVI_mciRealize [internal]
811 static DWORD MCIAVI_mciRealize(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
815 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
817 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
819 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
821 wma = MCIAVI_mciGetOpenDev(wDevID);
822 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
827 /******************************************************************************
828 * MCIAVI_mciUnFreeze [internal]
830 static DWORD MCIAVI_mciUnFreeze(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
834 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
836 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
838 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
840 wma = MCIAVI_mciGetOpenDev(wDevID);
841 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
846 /******************************************************************************
847 * MCIAVI_mciUpdate [internal]
849 static DWORD MCIAVI_mciUpdate(UINT wDevID, DWORD dwFlags, LPMCI_DGV_UPDATE_PARMS lpParms)
853 TRACE("%04x, %08lx, %p\n", wDevID, dwFlags, lpParms);
855 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
857 wma = MCIAVI_mciGetOpenDev(wDevID);
858 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
860 EnterCriticalSection(&wma->cs);
862 if (dwFlags & MCI_DGV_UPDATE_HDC)
863 MCIAVI_PaintFrame(wma, lpParms->hDC);
865 LeaveCriticalSection(&wma->cs);
870 /******************************************************************************
871 * MCIAVI_mciStep [internal]
873 static DWORD MCIAVI_mciStep(UINT wDevID, DWORD dwFlags, LPMCI_DGV_STEP_PARMS lpParms)
877 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
879 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
881 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
883 wma = MCIAVI_mciGetOpenDev(wDevID);
884 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
889 /******************************************************************************
890 * MCIAVI_mciCopy [internal]
892 static DWORD MCIAVI_mciCopy(UINT wDevID, DWORD dwFlags, LPMCI_DGV_COPY_PARMS lpParms)
896 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
898 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
900 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
902 wma = MCIAVI_mciGetOpenDev(wDevID);
903 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
908 /******************************************************************************
909 * MCIAVI_mciCut [internal]
911 static DWORD MCIAVI_mciCut(UINT wDevID, DWORD dwFlags, LPMCI_DGV_CUT_PARMS lpParms)
915 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
917 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
919 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
921 wma = MCIAVI_mciGetOpenDev(wDevID);
922 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
927 /******************************************************************************
928 * MCIAVI_mciDelete [internal]
930 static DWORD MCIAVI_mciDelete(UINT wDevID, DWORD dwFlags, LPMCI_DGV_DELETE_PARMS lpParms)
934 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
936 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
938 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
940 wma = MCIAVI_mciGetOpenDev(wDevID);
941 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
946 /******************************************************************************
947 * MCIAVI_mciPaste [internal]
949 static DWORD MCIAVI_mciPaste(UINT wDevID, DWORD dwFlags, LPMCI_DGV_PASTE_PARMS lpParms)
953 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
955 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
957 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
959 wma = MCIAVI_mciGetOpenDev(wDevID);
960 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
965 /******************************************************************************
966 * MCIAVI_mciCue [internal]
968 static DWORD MCIAVI_mciCue(UINT wDevID, DWORD dwFlags, LPMCI_DGV_CUE_PARMS lpParms)
972 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
974 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
976 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
978 wma = MCIAVI_mciGetOpenDev(wDevID);
979 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
984 /******************************************************************************
985 * MCIAVI_mciCapture [internal]
987 static DWORD MCIAVI_mciCapture(UINT wDevID, DWORD dwFlags, LPMCI_DGV_CAPTURE_PARMSW lpParms)
991 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
993 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
995 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
997 wma = MCIAVI_mciGetOpenDev(wDevID);
998 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1003 /******************************************************************************
1004 * MCIAVI_mciMonitor [internal]
1006 static DWORD MCIAVI_mciMonitor(UINT wDevID, DWORD dwFlags, LPMCI_DGV_MONITOR_PARMS lpParms)
1010 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1012 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1014 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1016 wma = MCIAVI_mciGetOpenDev(wDevID);
1017 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1022 /******************************************************************************
1023 * MCIAVI_mciReserve [internal]
1025 static DWORD MCIAVI_mciReserve(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RESERVE_PARMSW lpParms)
1029 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1031 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1033 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1035 wma = MCIAVI_mciGetOpenDev(wDevID);
1036 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1041 /******************************************************************************
1042 * MCIAVI_mciSetAudio [internal]
1044 static DWORD MCIAVI_mciSetAudio(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SETAUDIO_PARMSW lpParms)
1048 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1050 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1052 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1054 wma = MCIAVI_mciGetOpenDev(wDevID);
1055 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1060 /******************************************************************************
1061 * MCIAVI_mciSignal [internal]
1063 static DWORD MCIAVI_mciSignal(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SIGNAL_PARMS lpParms)
1067 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1069 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1071 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1073 wma = MCIAVI_mciGetOpenDev(wDevID);
1074 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1079 /******************************************************************************
1080 * MCIAVI_mciSetVideo [internal]
1082 static DWORD MCIAVI_mciSetVideo(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SETVIDEO_PARMSW lpParms)
1086 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1088 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1090 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1092 wma = MCIAVI_mciGetOpenDev(wDevID);
1093 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1098 /******************************************************************************
1099 * MCIAVI_mciQuality [internal]
1101 static DWORD MCIAVI_mciQuality(UINT wDevID, DWORD dwFlags, LPMCI_DGV_QUALITY_PARMSW lpParms)
1105 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1107 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1109 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1111 wma = MCIAVI_mciGetOpenDev(wDevID);
1112 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1117 /******************************************************************************
1118 * MCIAVI_mciList [internal]
1120 static DWORD MCIAVI_mciList(UINT wDevID, DWORD dwFlags, LPMCI_DGV_LIST_PARMSW lpParms)
1124 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1126 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1128 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1130 wma = MCIAVI_mciGetOpenDev(wDevID);
1131 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1136 /******************************************************************************
1137 * MCIAVI_mciUndo [internal]
1139 static DWORD MCIAVI_mciUndo(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1143 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1145 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1147 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1149 wma = MCIAVI_mciGetOpenDev(wDevID);
1150 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1155 /******************************************************************************
1156 * MCIAVI_mciConfigure [internal]
1158 static DWORD MCIAVI_mciConfigure(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1162 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1164 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1166 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1168 wma = MCIAVI_mciGetOpenDev(wDevID);
1169 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1174 /******************************************************************************
1175 * MCIAVI_mciRestore [internal]
1177 static DWORD MCIAVI_mciRestore(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RESTORE_PARMSW lpParms)
1181 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1183 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1185 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1187 wma = MCIAVI_mciGetOpenDev(wDevID);
1188 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1193 /*======================================================================*
1194 * MCI AVI entry points *
1195 *======================================================================*/
1197 /**************************************************************************
1198 * DriverProc (MCIAVI.@)
1200 LRESULT CALLBACK MCIAVI_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
1201 LPARAM dwParam1, LPARAM dwParam2)
1203 TRACE("(%08lX, %p, %08X, %08lX, %08lX)\n",
1204 dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1207 case DRV_LOAD: return 1;
1208 case DRV_FREE: return 1;
1209 case DRV_OPEN: return MCIAVI_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
1210 case DRV_CLOSE: return MCIAVI_drvClose(dwDevID);
1211 case DRV_ENABLE: return 1;
1212 case DRV_DISABLE: return 1;
1213 case DRV_QUERYCONFIGURE: return 1;
1214 case DRV_CONFIGURE: return MCIAVI_drvConfigure(dwDevID);
1215 case DRV_INSTALL: return DRVCNF_RESTART;
1216 case DRV_REMOVE: return DRVCNF_RESTART;
1219 /* session instance */
1220 if (dwDevID == 0xFFFFFFFF) return 1;
1223 case MCI_OPEN_DRIVER: return MCIAVI_mciOpen (dwDevID, dwParam1, (LPMCI_DGV_OPEN_PARMSW) dwParam2);
1224 case MCI_CLOSE_DRIVER: return MCIAVI_mciClose (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1225 case MCI_PLAY: return MCIAVI_mciPlay (dwDevID, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
1226 case MCI_RECORD: return MCIAVI_mciRecord (dwDevID, dwParam1, (LPMCI_DGV_RECORD_PARMS) dwParam2);
1227 case MCI_STOP: return MCIAVI_mciStop (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1228 case MCI_SET: return MCIAVI_mciSet (dwDevID, dwParam1, (LPMCI_DGV_SET_PARMS) dwParam2);
1229 case MCI_PAUSE: return MCIAVI_mciPause (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1230 case MCI_RESUME: return MCIAVI_mciResume (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1231 case MCI_STATUS: return MCIAVI_mciStatus (dwDevID, dwParam1, (LPMCI_DGV_STATUS_PARMSW) dwParam2);
1232 case MCI_GETDEVCAPS: return MCIAVI_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS) dwParam2);
1233 case MCI_INFO: return MCIAVI_mciInfo (dwDevID, dwParam1, (LPMCI_DGV_INFO_PARMSW) dwParam2);
1234 case MCI_SEEK: return MCIAVI_mciSeek (dwDevID, dwParam1, (LPMCI_SEEK_PARMS) dwParam2);
1235 case MCI_PUT: return MCIAVI_mciPut (dwDevID, dwParam1, (LPMCI_DGV_PUT_PARMS) dwParam2);
1236 case MCI_WINDOW: return MCIAVI_mciWindow (dwDevID, dwParam1, (LPMCI_DGV_WINDOW_PARMSW) dwParam2);
1237 case MCI_LOAD: return MCIAVI_mciLoad (dwDevID, dwParam1, (LPMCI_DGV_LOAD_PARMSW) dwParam2);
1238 case MCI_SAVE: return MCIAVI_mciSave (dwDevID, dwParam1, (LPMCI_DGV_SAVE_PARMSW) dwParam2);
1239 case MCI_FREEZE: return MCIAVI_mciFreeze (dwDevID, dwParam1, (LPMCI_DGV_RECT_PARMS) dwParam2);
1240 case MCI_REALIZE: return MCIAVI_mciRealize (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1241 case MCI_UNFREEZE: return MCIAVI_mciUnFreeze (dwDevID, dwParam1, (LPMCI_DGV_RECT_PARMS) dwParam2);
1242 case MCI_UPDATE: return MCIAVI_mciUpdate (dwDevID, dwParam1, (LPMCI_DGV_UPDATE_PARMS) dwParam2);
1243 case MCI_WHERE: return MCIAVI_mciWhere (dwDevID, dwParam1, (LPMCI_DGV_RECT_PARMS) dwParam2);
1244 case MCI_STEP: return MCIAVI_mciStep (dwDevID, dwParam1, (LPMCI_DGV_STEP_PARMS) dwParam2);
1245 case MCI_COPY: return MCIAVI_mciCopy (dwDevID, dwParam1, (LPMCI_DGV_COPY_PARMS) dwParam2);
1246 case MCI_CUT: return MCIAVI_mciCut (dwDevID, dwParam1, (LPMCI_DGV_CUT_PARMS) dwParam2);
1247 case MCI_DELETE: return MCIAVI_mciDelete (dwDevID, dwParam1, (LPMCI_DGV_DELETE_PARMS) dwParam2);
1248 case MCI_PASTE: return MCIAVI_mciPaste (dwDevID, dwParam1, (LPMCI_DGV_PASTE_PARMS) dwParam2);
1249 case MCI_CUE: return MCIAVI_mciCue (dwDevID, dwParam1, (LPMCI_DGV_CUE_PARMS) dwParam2);
1250 /* Digital Video specific */
1251 case MCI_CAPTURE: return MCIAVI_mciCapture (dwDevID, dwParam1, (LPMCI_DGV_CAPTURE_PARMSW) dwParam2);
1252 case MCI_MONITOR: return MCIAVI_mciMonitor (dwDevID, dwParam1, (LPMCI_DGV_MONITOR_PARMS) dwParam2);
1253 case MCI_RESERVE: return MCIAVI_mciReserve (dwDevID, dwParam1, (LPMCI_DGV_RESERVE_PARMSW) dwParam2);
1254 case MCI_SETAUDIO: return MCIAVI_mciSetAudio (dwDevID, dwParam1, (LPMCI_DGV_SETAUDIO_PARMSW) dwParam2);
1255 case MCI_SIGNAL: return MCIAVI_mciSignal (dwDevID, dwParam1, (LPMCI_DGV_SIGNAL_PARMS) dwParam2);
1256 case MCI_SETVIDEO: return MCIAVI_mciSetVideo (dwDevID, dwParam1, (LPMCI_DGV_SETVIDEO_PARMSW) dwParam2);
1257 case MCI_QUALITY: return MCIAVI_mciQuality (dwDevID, dwParam1, (LPMCI_DGV_QUALITY_PARMSW) dwParam2);
1258 case MCI_LIST: return MCIAVI_mciList (dwDevID, dwParam1, (LPMCI_DGV_LIST_PARMSW) dwParam2);
1259 case MCI_UNDO: return MCIAVI_mciUndo (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1260 case MCI_CONFIGURE: return MCIAVI_mciConfigure (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1261 case MCI_RESTORE: return MCIAVI_mciRestore (dwDevID, dwParam1, (LPMCI_DGV_RESTORE_PARMSW) dwParam2);
1265 WARN("Unsupported command [%u]\n", wMsg);
1269 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
1272 TRACE("Sending msg [%u] to default driver proc\n", wMsg);
1273 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1275 return MCIERR_UNRECOGNIZED_COMMAND;