4 * Digital video MCI Wine Driver
6 * Copyright 1999, 2000 Eric POUECH
7 * Copyright 2003 Dmitry Timoshkov
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * - handling of palettes
26 * - recording (which input devices ?), a cam recorder ?
27 * - lots of messages still need to be handled (cf FIXME)
28 * - synchronization between audio and video (especially for interleaved
30 * - robustness when reading file can be enhanced
31 * - better move the AVI handling part to avifile DLL and make use of it
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
36 * - stopping while playing a file with sound blocks until all buffered
37 * audio is played... still should be stopped ASAP
41 #include "private_mciavi.h"
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(mciavi);
47 static DWORD MCIAVI_mciStop(UINT, DWORD, LPMCI_GENERIC_PARMS);
49 /* ===================================================================
50 * ===================================================================
51 * FIXME: should be using the new mmThreadXXXX functions from WINMM
53 * it would require to add a wine internal flag to mmThreadCreate
54 * in order to pass a 32 bit function instead of a 16 bit one
55 * ===================================================================
56 * =================================================================== */
65 /**************************************************************************
66 * MCI_SCAStarter [internal]
68 static DWORD CALLBACK MCI_SCAStarter(LPVOID arg)
70 struct SCA* sca = (struct SCA*)arg;
73 TRACE("In thread before async command (%08x,%04x,%08lx,%08lx)\n",
74 sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2);
75 ret = mciSendCommandA(sca->wDevID, sca->wMsg, sca->dwParam1 | MCI_WAIT, sca->dwParam2);
76 TRACE("In thread after async command (%08x,%04x,%08lx,%08lx)\n",
77 sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2);
78 HeapFree(GetProcessHeap(), 0, sca);
82 /**************************************************************************
83 * MCI_SendCommandAsync [internal]
85 static DWORD MCI_SendCommandAsync(UINT wDevID, UINT wMsg, DWORD dwParam1,
86 DWORD_PTR dwParam2, UINT size)
89 struct SCA* sca = HeapAlloc(GetProcessHeap(), 0, sizeof(struct SCA) + size);
92 return MCIERR_OUT_OF_MEMORY;
96 sca->dwParam1 = dwParam1;
98 if (size && dwParam2) {
99 sca->dwParam2 = (DWORD_PTR)sca + sizeof(struct SCA);
100 /* copy structure passed by program in dwParam2 to be sure
101 * we can still use it whatever the program does
103 memcpy((LPVOID)sca->dwParam2, (LPVOID)dwParam2, size);
105 sca->dwParam2 = dwParam2;
108 if ((handle = CreateThread(NULL, 0, MCI_SCAStarter, sca, 0, NULL)) == 0) {
109 WARN("Couldn't allocate thread for async command handling, sending synchronously\n");
110 return MCI_SCAStarter(&sca);
112 SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL);
117 /*======================================================================*
118 * MCI AVI implemantation *
119 *======================================================================*/
121 HINSTANCE MCIAVI_hInstance = 0;
123 /***********************************************************************
126 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
129 case DLL_PROCESS_ATTACH:
130 DisableThreadLibraryCalls(hInstDLL);
131 MCIAVI_hInstance = hInstDLL;
137 /**************************************************************************
138 * MCIAVI_drvOpen [internal]
140 static DWORD MCIAVI_drvOpen(LPCWSTR str, LPMCI_OPEN_DRIVER_PARMSW modp)
143 static const WCHAR mciAviWStr[] = {'M','C','I','A','V','I',0};
145 TRACE("%s, %p\n", debugstr_w(str), modp);
147 /* session instance */
148 if (!modp) return 0xFFFFFFFF;
150 if (!MCIAVI_RegisterClass()) return 0;
152 wma = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCIAVI));
156 InitializeCriticalSection(&wma->cs);
157 wma->hStopEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
158 wma->wDevID = modp->wDeviceID;
159 wma->wCommandTable = mciLoadCommandResource(MCIAVI_hInstance, mciAviWStr, 0);
160 modp->wCustomCommandTable = wma->wCommandTable;
161 modp->wType = MCI_DEVTYPE_DIGITAL_VIDEO;
162 mciSetDriverData(wma->wDevID, (DWORD)wma);
164 return modp->wDeviceID;
167 /**************************************************************************
168 * MCIAVI_drvClose [internal]
170 static DWORD MCIAVI_drvClose(DWORD dwDevID)
174 TRACE("%04lx\n", dwDevID);
176 /* finish all outstanding things */
177 MCIAVI_mciClose(dwDevID, MCI_WAIT, NULL);
179 wma = (WINE_MCIAVI*)mciGetDriverData(dwDevID);
182 MCIAVI_UnregisterClass();
184 EnterCriticalSection(&wma->cs);
186 mciSetDriverData(dwDevID, 0);
187 mciFreeCommandResource(wma->wCommandTable);
189 CloseHandle(wma->hStopEvent);
191 LeaveCriticalSection(&wma->cs);
192 DeleteCriticalSection(&wma->cs);
194 HeapFree(GetProcessHeap(), 0, wma);
197 return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
200 /**************************************************************************
201 * MCIAVI_drvConfigure [internal]
203 static DWORD MCIAVI_drvConfigure(DWORD dwDevID)
207 TRACE("%04lx\n", dwDevID);
209 MCIAVI_mciStop(dwDevID, MCI_WAIT, NULL);
211 wma = (WINE_MCIAVI*)mciGetDriverData(dwDevID);
214 MessageBoxA(0, "Sample AVI Wine Driver !", "MM-Wine Driver", MB_OK);
220 /**************************************************************************
221 * MCIAVI_mciGetOpenDev [internal]
223 WINE_MCIAVI* MCIAVI_mciGetOpenDev(UINT wDevID)
225 WINE_MCIAVI* wma = (WINE_MCIAVI*)mciGetDriverData(wDevID);
227 if (wma == NULL || wma->nUseCount == 0) {
228 WARN("Invalid wDevID=%u\n", wDevID);
234 static void MCIAVI_CleanUp(WINE_MCIAVI* wma)
236 /* to prevent handling in WindowProc */
237 wma->dwStatus = MCI_MODE_NOT_READY;
239 mmioClose(wma->hFile, 0);
242 HeapFree(GetProcessHeap(), 0, wma->lpFileName);
243 wma->lpFileName = NULL;
245 HeapFree(GetProcessHeap(), 0, wma->lpVideoIndex);
246 wma->lpVideoIndex = NULL;
247 HeapFree(GetProcessHeap(), 0, wma->lpAudioIndex);
248 wma->lpAudioIndex = NULL;
249 if (wma->hic) ICClose(wma->hic);
251 HeapFree(GetProcessHeap(), 0, wma->inbih);
253 HeapFree(GetProcessHeap(), 0, wma->outbih);
255 HeapFree(GetProcessHeap(), 0, wma->indata);
257 HeapFree(GetProcessHeap(), 0, wma->outdata);
259 if (wma->hbmFrame) DeleteObject(wma->hbmFrame);
261 if (wma->hWnd) DestroyWindow(wma->hWnd);
264 HeapFree(GetProcessHeap(), 0, wma->lpWaveFormat);
265 wma->lpWaveFormat = 0;
267 memset(&wma->mah, 0, sizeof(wma->mah));
268 memset(&wma->ash_video, 0, sizeof(wma->ash_video));
269 memset(&wma->ash_audio, 0, sizeof(wma->ash_audio));
270 wma->dwCurrVideoFrame = wma->dwCurrAudioBlock = 0;
271 wma->dwCachedFrame = -1;
275 /***************************************************************************
276 * MCIAVI_mciOpen [internal]
278 static DWORD MCIAVI_mciOpen(UINT wDevID, DWORD dwFlags,
279 LPMCI_DGV_OPEN_PARMSW lpOpenParms)
284 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpOpenParms);
286 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
288 if (lpOpenParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
290 wma = (WINE_MCIAVI *)mciGetDriverData(wDevID);
291 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
293 EnterCriticalSection(&wma->cs);
295 if (wma->nUseCount > 0) {
296 /* The driver is already open on this channel */
297 /* If the driver was opened shareable before and this open specifies */
298 /* shareable then increment the use count */
299 if (wma->fShareable && (dwFlags & MCI_OPEN_SHAREABLE))
303 LeaveCriticalSection(&wma->cs);
304 return MCIERR_MUST_USE_SHAREABLE;
308 wma->fShareable = dwFlags & MCI_OPEN_SHAREABLE;
311 wma->dwStatus = MCI_MODE_NOT_READY;
313 if (dwFlags & MCI_OPEN_ELEMENT) {
314 if (dwFlags & MCI_OPEN_ELEMENT_ID) {
315 /* could it be that (DWORD)lpOpenParms->lpstrElementName
316 * contains the hFile value ?
318 dwRet = MCIERR_UNRECOGNIZED_COMMAND;
319 } else if (strlenW(lpOpenParms->lpstrElementName) > 0) {
320 /* FIXME : what should be done id wma->hFile is already != 0, or the driver is playin' */
321 TRACE("MCI_OPEN_ELEMENT %s!\n", debugstr_w(lpOpenParms->lpstrElementName));
323 if (lpOpenParms->lpstrElementName && (strlenW(lpOpenParms->lpstrElementName) > 0))
325 wma->lpFileName = HeapAlloc(GetProcessHeap(), 0, (strlenW(lpOpenParms->lpstrElementName) + 1) * sizeof(WCHAR));
326 strcpyW(wma->lpFileName, lpOpenParms->lpstrElementName);
328 wma->hFile = mmioOpenW(lpOpenParms->lpstrElementName, NULL,
329 MMIO_ALLOCBUF | MMIO_DENYWRITE | MMIO_READ);
331 if (wma->hFile == 0) {
332 WARN("can't find file=%s!\n", debugstr_w(lpOpenParms->lpstrElementName));
333 dwRet = MCIERR_FILE_NOT_FOUND;
335 if (!MCIAVI_GetInfo(wma))
336 dwRet = MCIERR_INVALID_FILE;
337 else if (!MCIAVI_OpenVideo(wma))
338 dwRet = MCIERR_CANNOT_LOAD_DRIVER;
339 else if (!MCIAVI_CreateWindow(wma, dwFlags, lpOpenParms))
340 dwRet = MCIERR_CREATEWINDOW;
344 FIXME("Don't record yet\n");
345 dwRet = MCIERR_UNSUPPORTED_FUNCTION;
350 TRACE("lpOpenParms->wDeviceID = %04x\n", lpOpenParms->wDeviceID);
352 wma->dwStatus = MCI_MODE_STOP;
353 wma->dwMciTimeFormat = MCI_FORMAT_FRAMES;
358 LeaveCriticalSection(&wma->cs);
362 /***************************************************************************
363 * MCIAVI_mciClose [internal]
365 DWORD MCIAVI_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
370 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
372 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
374 wma = (WINE_MCIAVI *)MCIAVI_mciGetOpenDev(wDevID);
375 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
377 EnterCriticalSection(&wma->cs);
379 if (wma->nUseCount == 1) {
380 if (wma->dwStatus != MCI_MODE_STOP)
381 dwRet = MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
384 if ((dwFlags & MCI_NOTIFY) && lpParms) {
385 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
387 MCI_NOTIFY_SUCCESSFUL);
389 LeaveCriticalSection(&wma->cs);
394 LeaveCriticalSection(&wma->cs);
398 /***************************************************************************
399 * MCIAVI_mciPlay [internal]
401 static DWORD MCIAVI_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
408 LPWAVEHDR waveHdr = NULL;
409 unsigned i, nHdr = 0;
410 DWORD dwFromFrame, dwToFrame;
412 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
414 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
416 wma = (WINE_MCIAVI *)MCIAVI_mciGetOpenDev(wDevID);
417 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
419 EnterCriticalSection(&wma->cs);
423 LeaveCriticalSection(&wma->cs);
424 return MCIERR_FILE_NOT_FOUND;
428 LeaveCriticalSection(&wma->cs);
429 return MCIERR_NO_WINDOW;
432 LeaveCriticalSection(&wma->cs);
434 if (!(dwFlags & MCI_WAIT)) {
435 return MCI_SendCommandAsync(wDevID, MCI_PLAY, dwFlags,
436 (DWORD_PTR)lpParms, sizeof(MCI_PLAY_PARMS));
439 if (!(GetWindowLongW(wma->hWndPaint, GWL_STYLE) & WS_VISIBLE))
440 ShowWindow(wma->hWndPaint, SW_SHOWNA);
442 EnterCriticalSection(&wma->cs);
444 dwFromFrame = wma->dwCurrVideoFrame;
445 dwToFrame = wma->dwPlayableVideoFrames - 1;
447 if (lpParms && (dwFlags & MCI_FROM)) {
448 dwFromFrame = MCIAVI_ConvertTimeFormatToFrame(wma, lpParms->dwFrom);
450 if (lpParms && (dwFlags & MCI_TO)) {
451 dwToFrame = MCIAVI_ConvertTimeFormatToFrame(wma, lpParms->dwTo);
453 if (dwToFrame >= wma->dwPlayableVideoFrames)
454 dwToFrame = wma->dwPlayableVideoFrames - 1;
456 TRACE("Playing from frame=%lu to frame=%lu\n", dwFromFrame, dwToFrame);
458 wma->dwCurrVideoFrame = dwFromFrame;
459 wma->dwToVideoFrame = dwToFrame;
461 /* if already playing exit */
462 if (wma->dwStatus == MCI_MODE_PLAY)
464 LeaveCriticalSection(&wma->cs);
468 if (wma->dwToVideoFrame <= wma->dwCurrVideoFrame)
474 wma->dwStatus = MCI_MODE_PLAY;
476 if (dwFlags & (MCI_DGV_PLAY_REPEAT|MCI_DGV_PLAY_REVERSE|MCI_MCIAVI_PLAY_WINDOW|MCI_MCIAVI_PLAY_FULLSCREEN))
477 FIXME("Unsupported flag %08lx\n", dwFlags);
479 /* time is in microseconds, we should convert it to milliseconds */
480 frameTime = (wma->mah.dwMicroSecPerFrame + 500) / 1000;
482 if (wma->lpWaveFormat) {
483 if (MCIAVI_OpenAudio(wma, &nHdr, &waveHdr) != 0)
485 /* can't play audio */
486 HeapFree(GetProcessHeap(), 0, wma->lpWaveFormat);
487 wma->lpWaveFormat = NULL;
490 /* fill the queue with as many wave headers as possible */
491 MCIAVI_PlayAudioBlocks(wma, nHdr, waveHdr);
494 while (wma->dwStatus == MCI_MODE_PLAY)
500 hDC = wma->hWndPaint ? GetDC(wma->hWndPaint) : 0;
503 MCIAVI_PaintFrame(wma, hDC);
504 ReleaseDC(wma->hWndPaint, hDC);
507 if (wma->lpWaveFormat) {
511 events[0] = wma->hStopEvent;
512 events[1] = wma->hEvent;
514 MCIAVI_PlayAudioBlocks(wma, nHdr, waveHdr);
515 delta = GetTickCount() - tc;
517 LeaveCriticalSection(&wma->cs);
518 ret = MsgWaitForMultipleObjectsEx(2, events,
519 (delta >= frameTime) ? 0 : frameTime - delta, QS_ALLINPUT, MWMO_INPUTAVAILABLE);
520 EnterCriticalSection(&wma->cs);
522 if (ret == WAIT_OBJECT_0 || wma->dwStatus != MCI_MODE_PLAY) break;
525 delta = GetTickCount() - tc;
526 if (delta < frameTime)
530 LeaveCriticalSection(&wma->cs);
531 ret = MsgWaitForMultipleObjectsEx(1, &wma->hStopEvent, frameTime - delta,
532 QS_ALLINPUT, MWMO_INPUTAVAILABLE);
533 EnterCriticalSection(&wma->cs);
534 if (ret == WAIT_OBJECT_0) break;
537 if (wma->dwCurrVideoFrame < dwToFrame)
538 wma->dwCurrVideoFrame++;
543 if (wma->lpWaveFormat) {
544 while (wma->dwEventCount != nHdr - 1)
546 LeaveCriticalSection(&wma->cs);
548 EnterCriticalSection(&wma->cs);
551 /* just to get rid of some race conditions between play, stop and pause */
552 LeaveCriticalSection(&wma->cs);
553 waveOutReset(wma->hWave);
554 EnterCriticalSection(&wma->cs);
556 for (i = 0; i < nHdr; i++)
557 waveOutUnprepareHeader(wma->hWave, &waveHdr[i], sizeof(WAVEHDR));
562 if (wma->lpWaveFormat) {
563 HeapFree(GetProcessHeap(), 0, waveHdr);
566 LeaveCriticalSection(&wma->cs);
567 waveOutClose(wma->hWave);
568 EnterCriticalSection(&wma->cs);
571 CloseHandle(wma->hEvent);
575 wma->dwStatus = MCI_MODE_STOP;
577 if (lpParms && (dwFlags & MCI_NOTIFY)) {
578 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
579 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
580 wDevID, MCI_NOTIFY_SUCCESSFUL);
582 LeaveCriticalSection(&wma->cs);
586 /***************************************************************************
587 * MCIAVI_mciRecord [internal]
589 static DWORD MCIAVI_mciRecord(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECORD_PARMS lpParms)
593 FIXME("(%04x, %08lX, %p) : stub\n", wDevID, dwFlags, lpParms);
595 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
597 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
599 wma = MCIAVI_mciGetOpenDev(wDevID);
600 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
602 EnterCriticalSection(&wma->cs);
603 wma->dwStatus = MCI_MODE_RECORD;
604 LeaveCriticalSection(&wma->cs);
608 /***************************************************************************
609 * MCIAVI_mciStop [internal]
611 static DWORD MCIAVI_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
616 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
618 wma = MCIAVI_mciGetOpenDev(wDevID);
619 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
621 EnterCriticalSection(&wma->cs);
623 switch (wma->dwStatus) {
625 case MCI_MODE_RECORD:
626 LeaveCriticalSection(&wma->cs);
627 SetEvent(wma->hStopEvent);
628 EnterCriticalSection(&wma->cs);
631 /* Since our wave notification callback takes the lock,
632 * we must release it before resetting the device */
633 LeaveCriticalSection(&wma->cs);
634 dwRet = waveOutReset(wma->hWave);
635 EnterCriticalSection(&wma->cs);
638 do /* one more chance for an async thread to finish */
640 LeaveCriticalSection(&wma->cs);
642 EnterCriticalSection(&wma->cs);
643 } while (wma->dwStatus != MCI_MODE_STOP);
647 case MCI_MODE_NOT_READY:
651 if ((dwFlags & MCI_NOTIFY) && lpParms) {
652 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
653 wDevID, MCI_NOTIFY_SUCCESSFUL);
655 LeaveCriticalSection(&wma->cs);
659 /***************************************************************************
660 * MCIAVI_mciPause [internal]
662 static DWORD MCIAVI_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
666 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
668 wma = MCIAVI_mciGetOpenDev(wDevID);
669 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
671 EnterCriticalSection(&wma->cs);
673 if (wma->dwStatus == MCI_MODE_PLAY)
674 wma->dwStatus = MCI_MODE_PAUSE;
676 if (wma->lpWaveFormat) {
677 LeaveCriticalSection(&wma->cs);
678 return waveOutPause(wma->hWave);
681 LeaveCriticalSection(&wma->cs);
685 /***************************************************************************
686 * MCIAVI_mciResume [internal]
688 static DWORD MCIAVI_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
692 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
694 wma = MCIAVI_mciGetOpenDev(wDevID);
695 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
697 EnterCriticalSection(&wma->cs);
699 if (wma->dwStatus == MCI_MODE_PAUSE)
700 wma->dwStatus = MCI_MODE_PLAY;
702 if (wma->lpWaveFormat) {
703 LeaveCriticalSection(&wma->cs);
704 return waveOutRestart(wma->hWave);
707 LeaveCriticalSection(&wma->cs);
711 /***************************************************************************
712 * MCIAVI_mciSeek [internal]
714 static DWORD MCIAVI_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
718 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
720 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
722 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
724 wma = MCIAVI_mciGetOpenDev(wDevID);
725 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
727 EnterCriticalSection(&wma->cs);
729 if (dwFlags & MCI_SEEK_TO_START) {
730 wma->dwCurrVideoFrame = 0;
731 } else if (dwFlags & MCI_SEEK_TO_END) {
732 wma->dwCurrVideoFrame = wma->dwPlayableVideoFrames - 1;
733 } else if (dwFlags & MCI_TO) {
734 if (lpParms->dwTo > wma->dwPlayableVideoFrames - 1)
735 lpParms->dwTo = wma->dwPlayableVideoFrames - 1;
736 wma->dwCurrVideoFrame = MCIAVI_ConvertTimeFormatToFrame(wma, lpParms->dwTo);
738 WARN("dwFlag doesn't tell where to seek to...\n");
739 LeaveCriticalSection(&wma->cs);
740 return MCIERR_MISSING_PARAMETER;
743 TRACE("Seeking to frame=%lu bytes\n", wma->dwCurrVideoFrame);
745 if (dwFlags & MCI_NOTIFY) {
746 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
747 wDevID, MCI_NOTIFY_SUCCESSFUL);
749 LeaveCriticalSection(&wma->cs);
753 /*****************************************************************************
754 * MCIAVI_mciLoad [internal]
756 static DWORD MCIAVI_mciLoad(UINT wDevID, DWORD dwFlags, LPMCI_DGV_LOAD_PARMSW lpParms)
760 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
762 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
764 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
766 wma = MCIAVI_mciGetOpenDev(wDevID);
767 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
772 /******************************************************************************
773 * MCIAVI_mciSave [internal]
775 static DWORD MCIAVI_mciSave(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SAVE_PARMSW lpParms)
779 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
781 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
783 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
785 wma = MCIAVI_mciGetOpenDev(wDevID);
786 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
791 /******************************************************************************
792 * MCIAVI_mciFreeze [internal]
794 static DWORD MCIAVI_mciFreeze(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
798 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
800 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
802 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
804 wma = MCIAVI_mciGetOpenDev(wDevID);
805 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
810 /******************************************************************************
811 * MCIAVI_mciRealize [internal]
813 static DWORD MCIAVI_mciRealize(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
817 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
819 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
821 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
823 wma = MCIAVI_mciGetOpenDev(wDevID);
824 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
829 /******************************************************************************
830 * MCIAVI_mciUnFreeze [internal]
832 static DWORD MCIAVI_mciUnFreeze(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
836 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
838 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
840 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
842 wma = MCIAVI_mciGetOpenDev(wDevID);
843 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
848 /******************************************************************************
849 * MCIAVI_mciUpdate [internal]
851 static DWORD MCIAVI_mciUpdate(UINT wDevID, DWORD dwFlags, LPMCI_DGV_UPDATE_PARMS lpParms)
855 TRACE("%04x, %08lx, %p\n", wDevID, dwFlags, lpParms);
857 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
859 wma = MCIAVI_mciGetOpenDev(wDevID);
860 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
862 EnterCriticalSection(&wma->cs);
864 if (dwFlags & MCI_DGV_UPDATE_HDC)
865 MCIAVI_PaintFrame(wma, lpParms->hDC);
867 LeaveCriticalSection(&wma->cs);
872 /******************************************************************************
873 * MCIAVI_mciStep [internal]
875 static DWORD MCIAVI_mciStep(UINT wDevID, DWORD dwFlags, LPMCI_DGV_STEP_PARMS lpParms)
879 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
881 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
883 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
885 wma = MCIAVI_mciGetOpenDev(wDevID);
886 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
891 /******************************************************************************
892 * MCIAVI_mciCopy [internal]
894 static DWORD MCIAVI_mciCopy(UINT wDevID, DWORD dwFlags, LPMCI_DGV_COPY_PARMS lpParms)
898 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
900 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
902 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
904 wma = MCIAVI_mciGetOpenDev(wDevID);
905 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
910 /******************************************************************************
911 * MCIAVI_mciCut [internal]
913 static DWORD MCIAVI_mciCut(UINT wDevID, DWORD dwFlags, LPMCI_DGV_CUT_PARMS lpParms)
917 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
919 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
921 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
923 wma = MCIAVI_mciGetOpenDev(wDevID);
924 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
929 /******************************************************************************
930 * MCIAVI_mciDelete [internal]
932 static DWORD MCIAVI_mciDelete(UINT wDevID, DWORD dwFlags, LPMCI_DGV_DELETE_PARMS lpParms)
936 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
938 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
940 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
942 wma = MCIAVI_mciGetOpenDev(wDevID);
943 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
948 /******************************************************************************
949 * MCIAVI_mciPaste [internal]
951 static DWORD MCIAVI_mciPaste(UINT wDevID, DWORD dwFlags, LPMCI_DGV_PASTE_PARMS lpParms)
955 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
957 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
959 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
961 wma = MCIAVI_mciGetOpenDev(wDevID);
962 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
967 /******************************************************************************
968 * MCIAVI_mciCue [internal]
970 static DWORD MCIAVI_mciCue(UINT wDevID, DWORD dwFlags, LPMCI_DGV_CUE_PARMS lpParms)
974 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
976 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
978 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
980 wma = MCIAVI_mciGetOpenDev(wDevID);
981 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
986 /******************************************************************************
987 * MCIAVI_mciCapture [internal]
989 static DWORD MCIAVI_mciCapture(UINT wDevID, DWORD dwFlags, LPMCI_DGV_CAPTURE_PARMSW lpParms)
993 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
995 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
997 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
999 wma = MCIAVI_mciGetOpenDev(wDevID);
1000 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1005 /******************************************************************************
1006 * MCIAVI_mciMonitor [internal]
1008 static DWORD MCIAVI_mciMonitor(UINT wDevID, DWORD dwFlags, LPMCI_DGV_MONITOR_PARMS lpParms)
1012 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1014 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1016 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1018 wma = MCIAVI_mciGetOpenDev(wDevID);
1019 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1024 /******************************************************************************
1025 * MCIAVI_mciReserve [internal]
1027 static DWORD MCIAVI_mciReserve(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RESERVE_PARMSW lpParms)
1031 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1033 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1035 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1037 wma = MCIAVI_mciGetOpenDev(wDevID);
1038 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1043 /******************************************************************************
1044 * MCIAVI_mciSetAudio [internal]
1046 static DWORD MCIAVI_mciSetAudio(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SETAUDIO_PARMSW lpParms)
1050 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1052 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1054 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1056 wma = MCIAVI_mciGetOpenDev(wDevID);
1057 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1062 /******************************************************************************
1063 * MCIAVI_mciSignal [internal]
1065 static DWORD MCIAVI_mciSignal(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SIGNAL_PARMS lpParms)
1069 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1071 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1073 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1075 wma = MCIAVI_mciGetOpenDev(wDevID);
1076 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1081 /******************************************************************************
1082 * MCIAVI_mciSetVideo [internal]
1084 static DWORD MCIAVI_mciSetVideo(UINT wDevID, DWORD dwFlags, LPMCI_DGV_SETVIDEO_PARMSW lpParms)
1088 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1090 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1092 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1094 wma = MCIAVI_mciGetOpenDev(wDevID);
1095 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1100 /******************************************************************************
1101 * MCIAVI_mciQuality [internal]
1103 static DWORD MCIAVI_mciQuality(UINT wDevID, DWORD dwFlags, LPMCI_DGV_QUALITY_PARMSW lpParms)
1107 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1109 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1111 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1113 wma = MCIAVI_mciGetOpenDev(wDevID);
1114 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1119 /******************************************************************************
1120 * MCIAVI_mciList [internal]
1122 static DWORD MCIAVI_mciList(UINT wDevID, DWORD dwFlags, LPMCI_DGV_LIST_PARMSW lpParms)
1126 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1128 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1130 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1132 wma = MCIAVI_mciGetOpenDev(wDevID);
1133 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1138 /******************************************************************************
1139 * MCIAVI_mciUndo [internal]
1141 static DWORD MCIAVI_mciUndo(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1145 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1147 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1149 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1151 wma = MCIAVI_mciGetOpenDev(wDevID);
1152 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1157 /******************************************************************************
1158 * MCIAVI_mciConfigure [internal]
1160 static DWORD MCIAVI_mciConfigure(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1164 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1166 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1168 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1170 wma = MCIAVI_mciGetOpenDev(wDevID);
1171 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1176 /******************************************************************************
1177 * MCIAVI_mciRestore [internal]
1179 static DWORD MCIAVI_mciRestore(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RESTORE_PARMSW lpParms)
1183 FIXME("(%04x, %08lx, %p) : stub\n", wDevID, dwFlags, lpParms);
1185 MCIAVI_mciStop(wDevID, MCI_WAIT, NULL);
1187 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1189 wma = MCIAVI_mciGetOpenDev(wDevID);
1190 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
1195 /*======================================================================*
1196 * MCI AVI entry points *
1197 *======================================================================*/
1199 /**************************************************************************
1200 * DriverProc (MCIAVI.@)
1202 LONG CALLBACK MCIAVI_DriverProc(DWORD dwDevID, HDRVR hDriv, DWORD wMsg,
1203 DWORD dwParam1, DWORD dwParam2)
1205 TRACE("(%08lX, %p, %08lX, %08lX, %08lX)\n",
1206 dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1209 case DRV_LOAD: return 1;
1210 case DRV_FREE: return 1;
1211 case DRV_OPEN: return MCIAVI_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
1212 case DRV_CLOSE: return MCIAVI_drvClose(dwDevID);
1213 case DRV_ENABLE: return 1;
1214 case DRV_DISABLE: return 1;
1215 case DRV_QUERYCONFIGURE: return 1;
1216 case DRV_CONFIGURE: return MCIAVI_drvConfigure(dwDevID);
1217 case DRV_INSTALL: return DRVCNF_RESTART;
1218 case DRV_REMOVE: return DRVCNF_RESTART;
1221 /* session instance */
1222 if (dwDevID == 0xFFFFFFFF) return 1;
1225 case MCI_OPEN_DRIVER: return MCIAVI_mciOpen (dwDevID, dwParam1, (LPMCI_DGV_OPEN_PARMSW) dwParam2);
1226 case MCI_CLOSE_DRIVER: return MCIAVI_mciClose (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1227 case MCI_PLAY: return MCIAVI_mciPlay (dwDevID, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
1228 case MCI_RECORD: return MCIAVI_mciRecord (dwDevID, dwParam1, (LPMCI_DGV_RECORD_PARMS) dwParam2);
1229 case MCI_STOP: return MCIAVI_mciStop (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1230 case MCI_SET: return MCIAVI_mciSet (dwDevID, dwParam1, (LPMCI_DGV_SET_PARMS) dwParam2);
1231 case MCI_PAUSE: return MCIAVI_mciPause (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1232 case MCI_RESUME: return MCIAVI_mciResume (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1233 case MCI_STATUS: return MCIAVI_mciStatus (dwDevID, dwParam1, (LPMCI_DGV_STATUS_PARMSW) dwParam2);
1234 case MCI_GETDEVCAPS: return MCIAVI_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS) dwParam2);
1235 case MCI_INFO: return MCIAVI_mciInfo (dwDevID, dwParam1, (LPMCI_DGV_INFO_PARMSW) dwParam2);
1236 case MCI_SEEK: return MCIAVI_mciSeek (dwDevID, dwParam1, (LPMCI_SEEK_PARMS) dwParam2);
1237 case MCI_PUT: return MCIAVI_mciPut (dwDevID, dwParam1, (LPMCI_DGV_PUT_PARMS) dwParam2);
1238 case MCI_WINDOW: return MCIAVI_mciWindow (dwDevID, dwParam1, (LPMCI_DGV_WINDOW_PARMSW) dwParam2);
1239 case MCI_LOAD: return MCIAVI_mciLoad (dwDevID, dwParam1, (LPMCI_DGV_LOAD_PARMSW) dwParam2);
1240 case MCI_SAVE: return MCIAVI_mciSave (dwDevID, dwParam1, (LPMCI_DGV_SAVE_PARMSW) dwParam2);
1241 case MCI_FREEZE: return MCIAVI_mciFreeze (dwDevID, dwParam1, (LPMCI_DGV_RECT_PARMS) dwParam2);
1242 case MCI_REALIZE: return MCIAVI_mciRealize (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1243 case MCI_UNFREEZE: return MCIAVI_mciUnFreeze (dwDevID, dwParam1, (LPMCI_DGV_RECT_PARMS) dwParam2);
1244 case MCI_UPDATE: return MCIAVI_mciUpdate (dwDevID, dwParam1, (LPMCI_DGV_UPDATE_PARMS) dwParam2);
1245 case MCI_WHERE: return MCIAVI_mciWhere (dwDevID, dwParam1, (LPMCI_DGV_RECT_PARMS) dwParam2);
1246 case MCI_STEP: return MCIAVI_mciStep (dwDevID, dwParam1, (LPMCI_DGV_STEP_PARMS) dwParam2);
1247 case MCI_COPY: return MCIAVI_mciCopy (dwDevID, dwParam1, (LPMCI_DGV_COPY_PARMS) dwParam2);
1248 case MCI_CUT: return MCIAVI_mciCut (dwDevID, dwParam1, (LPMCI_DGV_CUT_PARMS) dwParam2);
1249 case MCI_DELETE: return MCIAVI_mciDelete (dwDevID, dwParam1, (LPMCI_DGV_DELETE_PARMS) dwParam2);
1250 case MCI_PASTE: return MCIAVI_mciPaste (dwDevID, dwParam1, (LPMCI_DGV_PASTE_PARMS) dwParam2);
1251 case MCI_CUE: return MCIAVI_mciCue (dwDevID, dwParam1, (LPMCI_DGV_CUE_PARMS) dwParam2);
1252 /* Digital Video specific */
1253 case MCI_CAPTURE: return MCIAVI_mciCapture (dwDevID, dwParam1, (LPMCI_DGV_CAPTURE_PARMSW) dwParam2);
1254 case MCI_MONITOR: return MCIAVI_mciMonitor (dwDevID, dwParam1, (LPMCI_DGV_MONITOR_PARMS) dwParam2);
1255 case MCI_RESERVE: return MCIAVI_mciReserve (dwDevID, dwParam1, (LPMCI_DGV_RESERVE_PARMSW) dwParam2);
1256 case MCI_SETAUDIO: return MCIAVI_mciSetAudio (dwDevID, dwParam1, (LPMCI_DGV_SETAUDIO_PARMSW) dwParam2);
1257 case MCI_SIGNAL: return MCIAVI_mciSignal (dwDevID, dwParam1, (LPMCI_DGV_SIGNAL_PARMS) dwParam2);
1258 case MCI_SETVIDEO: return MCIAVI_mciSetVideo (dwDevID, dwParam1, (LPMCI_DGV_SETVIDEO_PARMSW) dwParam2);
1259 case MCI_QUALITY: return MCIAVI_mciQuality (dwDevID, dwParam1, (LPMCI_DGV_QUALITY_PARMSW) dwParam2);
1260 case MCI_LIST: return MCIAVI_mciList (dwDevID, dwParam1, (LPMCI_DGV_LIST_PARMSW) dwParam2);
1261 case MCI_UNDO: return MCIAVI_mciUndo (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1262 case MCI_CONFIGURE: return MCIAVI_mciConfigure (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1263 case MCI_RESTORE: return MCIAVI_mciRestore (dwDevID, dwParam1, (LPMCI_DGV_RESTORE_PARMSW) dwParam2);
1267 WARN("Unsupported command [%lu]\n", wMsg);
1271 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
1274 TRACE("Sending msg [%lu] to default driver proc\n", wMsg);
1275 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1277 return MCIERR_UNRECOGNIZED_COMMAND;