From 9f65a719fb51112488a88a1150c0e12d3a2d51e9 Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Sun, 11 Oct 1998 14:14:24 +0000 Subject: [PATCH] Started coding 32 bit MCI handling. Added Open/Close to low-level MCI drivers (audio, midi, anim, cda). Wrote MCI MIDI support. --- include/mmsystem.h | 45 +- include/multimedia.h | 61 +- multimedia/audio.c | 2918 +++++++++++++++++++------------------- multimedia/init.c | 42 +- multimedia/mcianim.c | 974 ++++++------- multimedia/mcicda.c | 1650 +++++++++++----------- multimedia/mcistring.c | 3053 ++++++++++++++++++++-------------------- multimedia/midi.c | 997 +++++++++---- multimedia/mmsystem.c | 1068 +++++++++----- 9 files changed, 5842 insertions(+), 4966 deletions(-) diff --git a/include/mmsystem.h b/include/mmsystem.h index 28affc09f9d..c3673acdc6a 100644 --- a/include/mmsystem.h +++ b/include/mmsystem.h @@ -2766,27 +2766,27 @@ typedef struct { } MIDIOPENDESC, *LPMIDIOPENDESC; typedef struct { - UINT16 wDelay; - UINT16 wResolution; + UINT16 wDelay; + UINT16 wResolution; LPTIMECALLBACK16 lpFunction; - DWORD dwUser; - UINT16 wFlags; + DWORD dwUser; + UINT16 wFlags; } TIMEREVENT, *LPTIMEREVENT; typedef struct tMIXEROPENDESC { HMIXEROBJ16 hmx; - DWORD dwCallback; - DWORD dwInstance; + DWORD dwCallback; + DWORD dwInstance; UINT16 uDeviceID; } MIXEROPENDESC,*LPMIXEROPENDESC; typedef struct { - UINT16 wDeviceID; /* device ID */ - LPSTR lpstrParams; /* parameter string for entry in SYSTEM.INI */ + UINT16 wDeviceID; /* device ID */ + LPSTR lpstrParams; /* parameter string for entry in SYSTEM.INI */ UINT16 wCustomCommandTable; /* custom command table (0xFFFF if none) - * filled in by the driver */ - UINT16 wType; /* driver type (filled in by the driver) */ + * filled in by the driver */ + UINT16 wType; /* driver type (filled in by the driver) */ } MCI_OPEN_DRIVER_PARMS, *LPMCI_OPEN_DRIVER_PARMS; DWORD WINAPI mciGetDriverData(UINT16 uDeviceID); @@ -2811,14 +2811,6 @@ BOOL16 WINAPI DriverCallback(DWORD dwCallBack, UINT16 uFlags, HANDLE16 hDev, DWORD WINAPI auxMessage(WORD wDevID, WORD wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2); -struct LINUX_MCIDRIVER { - HDRVR16 hdrv; - DRIVERPROC16 driverproc; - MCI_OPEN_DRIVER_PARMS modp; - MCI_OPEN_PARMS16 mop; - DWORD private; -}; - #pragma pack(4) DWORD WINAPI mixMessage(WORD wDevID, WORD wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2); @@ -2832,4 +2824,21 @@ DWORD WINAPI wodMessage(WORD wDevID, WORD wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2); #pragma pack(4) +LONG WAVE_DriverProc16(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, + DWORD dwParam1, DWORD dwParam2); +LONG WAVE_DriverProc32(DWORD dwDevID, HDRVR16 hDriv, DWORD wMsg, + DWORD dwParam1, DWORD dwParam2); +LONG MIDI_DriverProc16(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, + DWORD dwParam1, DWORD dwParam2); +LONG MIDI_DriverProc32(DWORD dwDevID, HDRVR16 hDriv, DWORD wMsg, + DWORD dwParam1, DWORD dwParam2); +LONG CDAUDIO_DriverProc16(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, + DWORD dwParam1, DWORD dwParam2); +LONG CDAUDIO_DriverProc32(DWORD dwDevID, HDRVR16 hDriv, DWORD wMsg, + DWORD dwParam1, DWORD dwParam2); +LONG ANIM_DriverProc16(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, + DWORD dwParam1, DWORD dwParam2); +LONG ANIM_DriverProc32(DWORD dwDevID, HDRVR16 hDriv, DWORD wMsg, + DWORD dwParam1, DWORD dwParam2); + #endif /* __WINE_MMSYSTEM_H */ diff --git a/include/multimedia.h b/include/multimedia.h index b1ccca7aff7..dd01540fcee 100644 --- a/include/multimedia.h +++ b/include/multimedia.h @@ -38,60 +38,19 @@ #ifdef SOUND_VERSION #define IOCTL(a,b,c) ioctl(a,b,&c) #else -#define IOCTL(a,b,c) (c = ioctl(a,b,c) ) +#define IOCTL(a,b,c) (c = ioctl(a,b,c)) #endif -typedef struct { -#ifndef HAVE_OSS - int unixdev; -#endif - int state; - DWORD bufsize; - LPMIDIOPENDESC midiDesc; - WORD wFlags; - LPMIDIHDR lpQueueHdr; - DWORD dwTotalPlayed; -#ifdef HAVE_OSS - unsigned char incoming[3]; - unsigned char incPrev; - char incLen; - DWORD startTime; -#endif -} LINUX_MIDIIN; - -typedef struct { -#ifndef HAVE_OSS - int unixdev; -#endif - int state; - DWORD bufsize; - LPMIDIOPENDESC midiDesc; - WORD wFlags; - LPMIDIHDR lpQueueHdr; - DWORD dwTotalPlayed; -#ifdef HAVE_OSS - void* lpExtra; /* according to port type (MIDI, FM...), extra data when needed */ -#endif -} LINUX_MIDIOUT; - -typedef struct { - int nUseCount; /* Incremented for each shared open */ - BOOL16 fShareable; /* TRUE if first open was shareable */ - WORD wNotifyDeviceID; /* MCI device ID with a pending notification */ - HANDLE16 hCallback; /* Callback handle for pending notification */ - HMMIO16 hFile; /* mmio file handle open as Element */ - DWORD dwBeginData; - DWORD dwTotalLen; - WORD wFormat; - WORD nTracks; - WORD nTempo; - MCI_OPEN_PARMS16 openParms; -/* MIDIHDR MidiHdr; */ - HLOCAL16 hMidiHdr; - WORD dwStatus; -} LINUX_MCIMIDI; +struct WINE_MCIDRIVER { + HDRVR16 hDrv; + DRIVERPROC16 driverProc; + MCI_OPEN_DRIVER_PARMS modp; + MCI_OPEN_PARMS16 mop; + DWORD dwPrivate; +}; /* function prototypes */ -extern BOOL32 MULTIMEDIA_Init( void ); +extern BOOL32 MULTIMEDIA_Init(void); +extern DWORD mciSendCommandAsync32(UINT32 wDevID, UINT32 wMsg, DWORD dwParam1, DWORD dwParam2); #endif /* __WINE_MULTIMEDIA_H */ diff --git a/multimedia/audio.c b/multimedia/audio.c index 07cfc13a322..bade5c73684 100644 --- a/multimedia/audio.c +++ b/multimedia/audio.c @@ -1,3 +1,4 @@ +/* -*- tab-width: 8; c-basic-offset: 4 -*- */ /* * Sample Wine Driver for Open Sound System (featured in Linux and FreeBSD) * @@ -49,193 +50,194 @@ #define MAX_MCIWAVDRV (1) typedef struct { - int unixdev; - int state; - DWORD bufsize; - WAVEOPENDESC waveDesc; - WORD wFlags; - PCMWAVEFORMAT Format; - LPWAVEHDR lpQueueHdr; - DWORD dwTotalPlayed; -} LINUX_WAVEOUT; + int unixdev; + int state; + DWORD bufsize; + WAVEOPENDESC waveDesc; + WORD wFlags; + PCMWAVEFORMAT Format; + LPWAVEHDR lpQueueHdr; + DWORD dwTotalPlayed; +} WINE_WAVEOUT; typedef struct { - int unixdev; - int state; - DWORD bufsize; /* OpenSound '/dev/dsp' give us that size */ - WAVEOPENDESC waveDesc; - WORD wFlags; - PCMWAVEFORMAT Format; - LPWAVEHDR lpQueueHdr; - DWORD dwTotalRecorded; -} LINUX_WAVEIN; + int unixdev; + int state; + DWORD bufsize; /* OpenSound '/dev/dsp' give us that size */ + WAVEOPENDESC waveDesc; + WORD wFlags; + PCMWAVEFORMAT Format; + LPWAVEHDR lpQueueHdr; + DWORD dwTotalRecorded; +} WINE_WAVEIN; typedef struct { - int nUseCount; /* Incremented for each shared open */ - BOOL16 fShareable; /* TRUE if first open was shareable */ - WORD wNotifyDeviceID;/* MCI device ID with a pending notification */ - HANDLE16 hCallback; /* Callback handle for pending notification */ - HMMIO16 hFile; /* mmio file handle open as Element */ - MCI_WAVE_OPEN_PARMS16 openParms; - PCMWAVEFORMAT WaveFormat; - WAVEHDR WaveHdr; - BOOL16 fInput; /* FALSE = Output, TRUE = Input */ -} LINUX_MCIWAVE; - -static LINUX_WAVEOUT WOutDev[MAX_WAVOUTDRV]; -static LINUX_WAVEIN WInDev[MAX_WAVOUTDRV]; -static LINUX_MCIWAVE MCIWavDev[MAX_MCIWAVDRV]; + int nUseCount; /* Incremented for each shared open */ + BOOL16 fShareable; /* TRUE if first open was shareable */ + WORD wNotifyDeviceID;/* MCI device ID with a pending notification */ + HANDLE16 hCallback; /* Callback handle for pending notification */ + HMMIO32 hFile; /* mmio file handle open as Element */ + MCI_WAVE_OPEN_PARMS16 openParms; + PCMWAVEFORMAT WaveFormat; + WAVEHDR WaveHdr; + BOOL16 fInput; /* FALSE = Output, TRUE = Input */ +} WINE_MCIWAVE; +static WINE_WAVEOUT WOutDev[MAX_WAVOUTDRV]; +static WINE_WAVEIN WInDev[MAX_WAVOUTDRV]; +static WINE_MCIWAVE MCIWavDev[MAX_MCIWAVDRV]; /************************************************************************** * WAVE_NotifyClient [internal] */ static DWORD WAVE_NotifyClient(UINT16 wDevID, WORD wMsg, - DWORD dwParam1, DWORD dwParam2) + DWORD dwParam1, DWORD dwParam2) { - TRACE(mciwave,"wDevID = %04X wMsg = %d dwParm1 = %04lX dwParam2 = %04lX\n",wDevID, wMsg, dwParam1, dwParam2); - - switch (wMsg) { - case WOM_OPEN: - case WOM_CLOSE: - case WOM_DONE: - if (wDevID > MAX_WAVOUTDRV) return MCIERR_INTERNAL; - - if (WOutDev[wDevID].wFlags != DCB_NULL && !DriverCallback( - WOutDev[wDevID].waveDesc.dwCallBack, - WOutDev[wDevID].wFlags, - WOutDev[wDevID].waveDesc.hWave, - wMsg, - WOutDev[wDevID].waveDesc.dwInstance, - dwParam1, - dwParam2)) { + TRACE(mciwave,"wDevID = %04X wMsg = %d dwParm1 = %04lX dwParam2 = %04lX\n",wDevID, wMsg, dwParam1, dwParam2); + + switch (wMsg) { + case WOM_OPEN: + case WOM_CLOSE: + case WOM_DONE: + if (wDevID > MAX_WAVOUTDRV) return MCIERR_INTERNAL; + + if (WOutDev[wDevID].wFlags != DCB_NULL && !DriverCallback( + WOutDev[wDevID].waveDesc.dwCallBack, + WOutDev[wDevID].wFlags, + WOutDev[wDevID].waveDesc.hWave, + wMsg, + WOutDev[wDevID].waveDesc.dwInstance, + dwParam1, + dwParam2)) { WARN(mciwave, "can't notify client !\n"); return MMSYSERR_NOERROR; - } - break; - - case WIM_OPEN: - case WIM_CLOSE: - case WIM_DATA: - if (wDevID > MAX_WAVINDRV) return MCIERR_INTERNAL; - - if (WInDev[wDevID].wFlags != DCB_NULL && !DriverCallback( - WInDev[wDevID].waveDesc.dwCallBack, WInDev[wDevID].wFlags, - WInDev[wDevID].waveDesc.hWave, wMsg, - WInDev[wDevID].waveDesc.dwInstance, dwParam1, dwParam2)) { - WARN(mciwave, "can't notify client !\n"); - return MMSYSERR_NOERROR; - } - break; } - return 0; + break; + + case WIM_OPEN: + case WIM_CLOSE: + case WIM_DATA: + if (wDevID > MAX_WAVINDRV) return MCIERR_INTERNAL; + + if (WInDev[wDevID].wFlags != DCB_NULL && !DriverCallback( + WInDev[wDevID].waveDesc.dwCallBack, WInDev[wDevID].wFlags, + WInDev[wDevID].waveDesc.hWave, wMsg, + WInDev[wDevID].waveDesc.dwInstance, dwParam1, dwParam2)) { + WARN(mciwave, "can't notify client !\n"); + return MMSYSERR_NOERROR; + } + break; + } + return 0; } /************************************************************************** * WAVE_mciOpen [internal] */ -static DWORD WAVE_mciOpen(UINT16 wDevID, DWORD dwFlags, LPMCI_WAVE_OPEN_PARMS16 lpParms) +static DWORD WAVE_mciOpen(UINT16 wDevID, DWORD dwFlags, void* lp, BOOL32 is32) { - LPPCMWAVEFORMAT lpWaveFormat; - WAVEOPENDESC waveDesc; - LPSTR lpstrElementName; - DWORD dwRet; - char str[128]; - - TRACE(mciwave,"(%04X, %08lX, %p)\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - - if (MCIWavDev[wDevID].nUseCount > 0) { - /* The driver already open on this channel */ - /* If the driver was opened shareable before and this open specifies */ - /* shareable then increment the use count */ - if (MCIWavDev[wDevID].fShareable && (dwFlags & MCI_OPEN_SHAREABLE)) - ++MCIWavDev[wDevID].nUseCount; - else - return MCIERR_MUST_USE_SHAREABLE; - } else { - MCIWavDev[wDevID].nUseCount = 1; - MCIWavDev[wDevID].fShareable = dwFlags & MCI_OPEN_SHAREABLE; + LPPCMWAVEFORMAT lpWaveFormat; + WAVEOPENDESC waveDesc; + DWORD dwRet; + DWORD dwDeviceID; + + TRACE(mciwave,"(%04X, %08lX, %p)\n", wDevID, dwFlags, lp); + if (lp == NULL) return MCIERR_INTERNAL; + + if (is32) dwDeviceID = ((LPMCI_OPEN_PARMS32A)lp)->wDeviceID; + else dwDeviceID = ((LPMCI_OPEN_PARMS16)lp)->wDeviceID; + + if (MCIWavDev[wDevID].nUseCount > 0) { + /* The driver already open on this channel */ + /* If the driver was opened shareable before and this open specifies */ + /* shareable then increment the use count */ + if (MCIWavDev[wDevID].fShareable && (dwFlags & MCI_OPEN_SHAREABLE)) + ++MCIWavDev[wDevID].nUseCount; + else + return MCIERR_MUST_USE_SHAREABLE; + } else { + MCIWavDev[wDevID].nUseCount = 1; + MCIWavDev[wDevID].fShareable = dwFlags & MCI_OPEN_SHAREABLE; + } + + MCIWavDev[wDevID].fInput = FALSE; + + TRACE(mciwave,"wDevID=%04X\n", wDevID); + TRACE(mciwave,"before OPEN_ELEMENT\n"); + if (dwFlags & MCI_OPEN_ELEMENT) { + LPSTR lpstrElementName; + + if (is32) lpstrElementName = ((LPMCI_WAVE_OPEN_PARMS32A)lp)->lpstrElementName; + else lpstrElementName = (LPSTR)PTR_SEG_TO_LIN(((LPMCI_WAVE_OPEN_PARMS16)lp)->lpstrElementName); + + TRACE(mciwave,"MCI_OPEN_ELEMENT '%s' !\n", lpstrElementName); + if (lpstrElementName && (strlen(lpstrElementName) > 0)) { + MCIWavDev[wDevID].hFile = mmioOpen32A(lpstrElementName, NULL, + MMIO_ALLOCBUF | MMIO_READWRITE | MMIO_EXCLUSIVE); + if (MCIWavDev[wDevID].hFile == 0) { + WARN(mciwave, "can't find file='%s' !\n", lpstrElementName); + return MCIERR_FILE_NOT_FOUND; + } } - - MCIWavDev[wDevID].fInput = FALSE; - - TRACE(mciwave,"wDevID=%04X\n", wDevID); - TRACE(mciwave,"before OPEN_ELEMENT\n"); - if (dwFlags & MCI_OPEN_ELEMENT) { - lpstrElementName = (LPSTR)PTR_SEG_TO_LIN(lpParms->lpstrElementName); - TRACE(mciwave,"MCI_OPEN_ELEMENT '%s' !\n", - lpstrElementName); - if ( lpstrElementName && (strlen(lpstrElementName) > 0)) { - strcpy(str, lpstrElementName); - CharUpper32A(str); - MCIWavDev[wDevID].hFile = mmioOpen16(str, NULL, - MMIO_ALLOCBUF | MMIO_READWRITE | MMIO_EXCLUSIVE); - if (MCIWavDev[wDevID].hFile == 0) { - WARN(mciwave, "can't find file='%s' !\n", str); - return MCIERR_FILE_NOT_FOUND; - } - } - else - MCIWavDev[wDevID].hFile = 0; - } - TRACE(mciwave,"hFile=%u\n", MCIWavDev[wDevID].hFile); - memcpy(&MCIWavDev[wDevID].openParms, lpParms, sizeof(MCI_WAVE_OPEN_PARMS16)); - MCIWavDev[wDevID].wNotifyDeviceID = lpParms->wDeviceID; - lpWaveFormat = &MCIWavDev[wDevID].WaveFormat; - - waveDesc.hWave = 0; -/* - lpWaveFormat->wf.wFormatTag = WAVE_FORMAT_PCM; - lpWaveFormat->wBitsPerSample = 8; - lpWaveFormat->wf.nChannels = 1; - lpWaveFormat->wf.nSamplesPerSec = 11025; - lpWaveFormat->wf.nAvgBytesPerSec = 11025; - lpWaveFormat->wf.nBlockAlign = 1; -*/ - if (MCIWavDev[wDevID].hFile != 0) { - MMCKINFO mmckInfo; - MMCKINFO ckMainRIFF; - if (mmioDescend(MCIWavDev[wDevID].hFile, &ckMainRIFF, NULL, 0) != 0) - return MCIERR_INTERNAL; - TRACE(mciwave, "ParentChunk ckid=%.4s fccType=%.4s cksize=%08lX \n", - (LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType, - ckMainRIFF.cksize); - if ((ckMainRIFF.ckid != FOURCC_RIFF) || - (ckMainRIFF.fccType != mmioFOURCC('W', 'A', 'V', 'E'))) - return MCIERR_INTERNAL; - mmckInfo.ckid = mmioFOURCC('f', 'm', 't', ' '); - if (mmioDescend(MCIWavDev[wDevID].hFile, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK) != 0) - return MCIERR_INTERNAL; - TRACE(mciwave, "Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n", - (LPSTR)&mmckInfo.ckid, (LPSTR)&mmckInfo.fccType, - mmckInfo.cksize); - if (mmioRead32(MCIWavDev[wDevID].hFile, (HPSTR) lpWaveFormat, - (long) sizeof(PCMWAVEFORMAT)) != (long) sizeof(PCMWAVEFORMAT)) - return MCIERR_INTERNAL; - mmckInfo.ckid = mmioFOURCC('d', 'a', 't', 'a'); - if (mmioDescend(MCIWavDev[wDevID].hFile, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK) != 0) - return MCIERR_INTERNAL; - TRACE(mciwave,"Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n", - (LPSTR)&mmckInfo.ckid, (LPSTR)&mmckInfo.fccType, - mmckInfo.cksize); - TRACE(mciwave, "nChannels=%d nSamplesPerSec=%ld\n", - lpWaveFormat->wf.nChannels, lpWaveFormat->wf.nSamplesPerSec); - lpWaveFormat->wBitsPerSample = 0; - } - lpWaveFormat->wf.nAvgBytesPerSec = - lpWaveFormat->wf.nSamplesPerSec * lpWaveFormat->wf.nBlockAlign; - waveDesc.lpFormat = (LPWAVEFORMAT)lpWaveFormat; - -/* - By default the device will be opened for output, the MCI_CUE function is there to - change from output to input and back -*/ - - dwRet=wodMessage(wDevID,WODM_OPEN,0,(DWORD)&waveDesc,CALLBACK_NULL); - return 0; + else + MCIWavDev[wDevID].hFile = 0; + } + TRACE(mciwave,"hFile=%u\n", MCIWavDev[wDevID].hFile); + memcpy(&MCIWavDev[wDevID].openParms, lp, sizeof(MCI_WAVE_OPEN_PARMS16)); + MCIWavDev[wDevID].wNotifyDeviceID = dwDeviceID; + lpWaveFormat = &MCIWavDev[wDevID].WaveFormat; + + waveDesc.hWave = 0; + /* + lpWaveFormat->wf.wFormatTag = WAVE_FORMAT_PCM; + lpWaveFormat->wBitsPerSample = 8; + lpWaveFormat->wf.nChannels = 1; + lpWaveFormat->wf.nSamplesPerSec = 11025; + lpWaveFormat->wf.nAvgBytesPerSec = 11025; + lpWaveFormat->wf.nBlockAlign = 1; + */ + if (MCIWavDev[wDevID].hFile != 0) { + MMCKINFO mmckInfo; + MMCKINFO ckMainRIFF; + if (mmioDescend(MCIWavDev[wDevID].hFile, &ckMainRIFF, NULL, 0) != 0) + return MCIERR_INTERNAL; + TRACE(mciwave, "ParentChunk ckid=%.4s fccType=%.4s cksize=%08lX \n", + (LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType, + ckMainRIFF.cksize); + if ((ckMainRIFF.ckid != FOURCC_RIFF) || + (ckMainRIFF.fccType != mmioFOURCC('W', 'A', 'V', 'E'))) + return MCIERR_INTERNAL; + mmckInfo.ckid = mmioFOURCC('f', 'm', 't', ' '); + if (mmioDescend(MCIWavDev[wDevID].hFile, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK) != 0) + return MCIERR_INTERNAL; + TRACE(mciwave, "Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n", + (LPSTR)&mmckInfo.ckid, (LPSTR)&mmckInfo.fccType, + mmckInfo.cksize); + if (mmioRead32(MCIWavDev[wDevID].hFile, (HPSTR) lpWaveFormat, + (long) sizeof(PCMWAVEFORMAT)) != (long) sizeof(PCMWAVEFORMAT)) + return MCIERR_INTERNAL; + mmckInfo.ckid = mmioFOURCC('d', 'a', 't', 'a'); + if (mmioDescend(MCIWavDev[wDevID].hFile, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK) != 0) + return MCIERR_INTERNAL; + TRACE(mciwave,"Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n", + (LPSTR)&mmckInfo.ckid, (LPSTR)&mmckInfo.fccType, + mmckInfo.cksize); + TRACE(mciwave, "nChannels=%d nSamplesPerSec=%ld\n", + lpWaveFormat->wf.nChannels, lpWaveFormat->wf.nSamplesPerSec); + lpWaveFormat->wBitsPerSample = 0; + } + lpWaveFormat->wf.nAvgBytesPerSec = + lpWaveFormat->wf.nSamplesPerSec * lpWaveFormat->wf.nBlockAlign; + waveDesc.lpFormat = (LPWAVEFORMAT)lpWaveFormat; + + /* + By default the device will be opened for output, the MCI_CUE function is there to + change from output to input and back + */ + + dwRet=wodMessage(wDevID,WODM_OPEN,0,(DWORD)&waveDesc,CALLBACK_NULL); + return 0; } /************************************************************************** @@ -244,49 +246,49 @@ static DWORD WAVE_mciOpen(UINT16 wDevID, DWORD dwFlags, LPMCI_WAVE_OPEN_PARMS16 static DWORD WAVE_mciCue(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms) { -/* - FIXME - - This routine is far from complete. At the moment only a check is done on the - MCI_WAVE_INPUT flag. No explicit check on MCI_WAVE_OUTPUT is done since that - is the default. - - The flags MCI_NOTIFY (and the callback parameter in lpParms) and MCI_WAIT - are ignored -*/ - - DWORD dwRet; - WAVEOPENDESC waveDesc; - - TRACE(mciwave,"(%u, %08lX, %p);\n", wDevID, dwParam, lpParms); - -/* always close elements ? */ - - if (MCIWavDev[wDevID].hFile != 0) { - mmioClose32(MCIWavDev[wDevID].hFile, 0); - MCIWavDev[wDevID].hFile = 0; - } - - dwRet = MMSYSERR_NOERROR; /* assume success */ - if ((dwParam & MCI_WAVE_INPUT) && !MCIWavDev[wDevID].fInput) { -/* FIXME this is just a hack WOutDev should be hidden here */ - memcpy(&waveDesc,&WOutDev[wDevID].waveDesc,sizeof(WAVEOPENDESC)); - - dwRet = wodMessage(wDevID, WODM_CLOSE, 0, 0L, 0L); - if (dwRet != MMSYSERR_NOERROR) return MCIERR_INTERNAL; - dwRet = widMessage(wDevID, WIDM_OPEN, 0, (DWORD)&waveDesc, CALLBACK_NULL); - MCIWavDev[wDevID].fInput = TRUE; - } - else if (MCIWavDev[wDevID].fInput) { -/* FIXME this is just a hack WInDev should be hidden here */ - memcpy(&waveDesc,&WInDev[wDevID].waveDesc,sizeof(WAVEOPENDESC)); - - dwRet = widMessage(wDevID, WIDM_CLOSE, 0, 0L, 0L); - if (dwRet != MMSYSERR_NOERROR) return MCIERR_INTERNAL; - dwRet = wodMessage(wDevID, WODM_OPEN, 0, (DWORD)&waveDesc, CALLBACK_NULL); - MCIWavDev[wDevID].fInput = FALSE; - } - return dwRet; + /* + FIXME + + This routine is far from complete. At the moment only a check is done on the + MCI_WAVE_INPUT flag. No explicit check on MCI_WAVE_OUTPUT is done since that + is the default. + + The flags MCI_NOTIFY (and the callback parameter in lpParms) and MCI_WAIT + are ignored + */ + + DWORD dwRet; + WAVEOPENDESC waveDesc; + + TRACE(mciwave,"(%u, %08lX, %p);\n", wDevID, dwParam, lpParms); + + /* always close elements ? */ + + if (MCIWavDev[wDevID].hFile != 0) { + mmioClose32(MCIWavDev[wDevID].hFile, 0); + MCIWavDev[wDevID].hFile = 0; + } + + dwRet = MMSYSERR_NOERROR; /* assume success */ + if ((dwParam & MCI_WAVE_INPUT) && !MCIWavDev[wDevID].fInput) { + /* FIXME this is just a hack WOutDev should be hidden here */ + memcpy(&waveDesc,&WOutDev[wDevID].waveDesc,sizeof(WAVEOPENDESC)); + + dwRet = wodMessage(wDevID, WODM_CLOSE, 0, 0L, 0L); + if (dwRet != MMSYSERR_NOERROR) return MCIERR_INTERNAL; + dwRet = widMessage(wDevID, WIDM_OPEN, 0, (DWORD)&waveDesc, CALLBACK_NULL); + MCIWavDev[wDevID].fInput = TRUE; + } + else if (MCIWavDev[wDevID].fInput) { + /* FIXME this is just a hack WInDev should be hidden here */ + memcpy(&waveDesc,&WInDev[wDevID].waveDesc,sizeof(WAVEOPENDESC)); + + dwRet = widMessage(wDevID, WIDM_CLOSE, 0, 0L, 0L); + if (dwRet != MMSYSERR_NOERROR) return MCIERR_INTERNAL; + dwRet = wodMessage(wDevID, WODM_OPEN, 0, (DWORD)&waveDesc, CALLBACK_NULL); + MCIWavDev[wDevID].fInput = FALSE; + } + return dwRet; } /************************************************************************** @@ -294,23 +296,23 @@ static DWORD WAVE_mciCue(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpPar */ static DWORD WAVE_mciClose(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms) { - DWORD dwRet; - - TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwParam, lpParms); - MCIWavDev[wDevID].nUseCount--; - if (MCIWavDev[wDevID].nUseCount == 0) { - if (MCIWavDev[wDevID].hFile != 0) { - mmioClose32(MCIWavDev[wDevID].hFile, 0); - MCIWavDev[wDevID].hFile = 0; - } - if (MCIWavDev[wDevID].fInput) - dwRet = widMessage(wDevID, WIDM_CLOSE, 0, 0L, 0L); - else - dwRet = wodMessage(wDevID, WODM_CLOSE, 0, 0L, 0L); - - if (dwRet != MMSYSERR_NOERROR) return MCIERR_INTERNAL; + DWORD dwRet; + + TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwParam, lpParms); + MCIWavDev[wDevID].nUseCount--; + if (MCIWavDev[wDevID].nUseCount == 0) { + if (MCIWavDev[wDevID].hFile != 0) { + mmioClose32(MCIWavDev[wDevID].hFile, 0); + MCIWavDev[wDevID].hFile = 0; } - return 0; + if (MCIWavDev[wDevID].fInput) + dwRet = widMessage(wDevID, WIDM_CLOSE, 0, 0L, 0L); + else + dwRet = wodMessage(wDevID, WODM_CLOSE, 0, 0L, 0L); + + if (dwRet != MMSYSERR_NOERROR) return MCIERR_INTERNAL; + } + return 0; } @@ -319,78 +321,78 @@ static DWORD WAVE_mciClose(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpP */ static DWORD WAVE_mciPlay(UINT16 wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms) { - int start, end; - LONG bufsize, count; - HGLOBAL16 hData; - LPWAVEHDR lpWaveHdr; - DWORD dwRet; - - TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); - - if (MCIWavDev[wDevID].fInput) { - WARN(mciwave, "cannot play on input device\n"); - return MCIERR_NONAPPLICABLE_FUNCTION; - } - - if (MCIWavDev[wDevID].hFile == 0) { - WARN(mciwave, "can't find file='%08lx' !\n", - MCIWavDev[wDevID].openParms.lpstrElementName); - return MCIERR_FILE_NOT_FOUND; - } - start = 1; end = 99999; - if (dwFlags & MCI_FROM) { - start = lpParms->dwFrom; - TRACE(mciwave, "MCI_FROM=%d \n", start); - } - if (dwFlags & MCI_TO) { - end = lpParms->dwTo; - TRACE(mciwave,"MCI_TO=%d \n", end); - } + int start, end; + LONG bufsize, count; + HGLOBAL16 hData; + LPWAVEHDR lpWaveHdr; + DWORD dwRet; + + TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); + + if (MCIWavDev[wDevID].fInput) { + WARN(mciwave, "cannot play on input device\n"); + return MCIERR_NONAPPLICABLE_FUNCTION; + } + + if (MCIWavDev[wDevID].hFile == 0) { + WARN(mciwave, "can't find file='%08lx' !\n", + MCIWavDev[wDevID].openParms.lpstrElementName); + return MCIERR_FILE_NOT_FOUND; + } + start = 1; end = 99999; + if (dwFlags & MCI_FROM) { + start = lpParms->dwFrom; + TRACE(mciwave, "MCI_FROM=%d \n", start); + } + if (dwFlags & MCI_TO) { + end = lpParms->dwTo; + TRACE(mciwave,"MCI_TO=%d \n", end); + } #if 0 - if (dwFlags & MCI_NOTIFY) { - TRACE(mciwave, "MCI_NOTIFY %08lX !\n", lpParms->dwCallback); - switch(fork()) { - case -1: - WARN(mciwave, "Can't 'fork' process !\n"); - break; - case 0: - break; - default: - TRACE(mciwave,"process started ! return to caller...\n"); - return 0; - } - } + if (dwFlags & MCI_NOTIFY) { + TRACE(mciwave, "MCI_NOTIFY %08lX !\n", lpParms->dwCallback); + switch(fork()) { + case -1: + WARN(mciwave, "Can't 'fork' process !\n"); + break; + case 0: + break; + default: + TRACE(mciwave,"process started ! return to caller...\n"); + return 0; + } + } #endif - bufsize = 64000; - lpWaveHdr = &MCIWavDev[wDevID].WaveHdr; - hData = GlobalAlloc16(GMEM_MOVEABLE, bufsize); - lpWaveHdr->lpData = (LPSTR) GlobalLock16(hData); - lpWaveHdr->dwUser = 0L; - lpWaveHdr->dwFlags = 0L; - lpWaveHdr->dwLoops = 0L; - dwRet=wodMessage(wDevID,WODM_PREPARE,0,(DWORD)lpWaveHdr,sizeof(WAVEHDR)); - while(TRUE) { - count = mmioRead32(MCIWavDev[wDevID].hFile, lpWaveHdr->lpData, bufsize); - TRACE(mciwave,"mmioRead bufsize=%ld count=%ld\n", bufsize, count); - if (count < 1) break; - lpWaveHdr->dwBufferLength = count; -/* lpWaveHdr->dwBytesRecorded = count; */ - TRACE(mciwave,"before WODM_WRITE lpWaveHdr=%p dwBufferLength=%lu dwBytesRecorded=%lu\n", - lpWaveHdr, lpWaveHdr->dwBufferLength, lpWaveHdr->dwBytesRecorded); - dwRet=wodMessage(wDevID,WODM_WRITE,0,(DWORD)lpWaveHdr,sizeof(WAVEHDR)); - } - dwRet = wodMessage(wDevID,WODM_UNPREPARE,0,(DWORD)lpWaveHdr,sizeof(WAVEHDR)); - if (lpWaveHdr->lpData != NULL) { - GlobalUnlock16(hData); - GlobalFree16(hData); - lpWaveHdr->lpData = NULL; - } - if (dwFlags & MCI_NOTIFY) { - TRACE(mciwave,"MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + bufsize = 64000; + lpWaveHdr = &MCIWavDev[wDevID].WaveHdr; + hData = GlobalAlloc16(GMEM_MOVEABLE, bufsize); + lpWaveHdr->lpData = (LPSTR) GlobalLock16(hData); + lpWaveHdr->dwUser = 0L; + lpWaveHdr->dwFlags = 0L; + lpWaveHdr->dwLoops = 0L; + dwRet=wodMessage(wDevID,WODM_PREPARE,0,(DWORD)lpWaveHdr,sizeof(WAVEHDR)); + while(TRUE) { + count = mmioRead32(MCIWavDev[wDevID].hFile, lpWaveHdr->lpData, bufsize); + TRACE(mciwave,"mmioRead bufsize=%ld count=%ld\n", bufsize, count); + if (count < 1) break; + lpWaveHdr->dwBufferLength = count; + /* lpWaveHdr->dwBytesRecorded = count; */ + TRACE(mciwave,"before WODM_WRITE lpWaveHdr=%p dwBufferLength=%lu dwBytesRecorded=%lu\n", + lpWaveHdr, lpWaveHdr->dwBufferLength, lpWaveHdr->dwBytesRecorded); + dwRet=wodMessage(wDevID,WODM_WRITE,0,(DWORD)lpWaveHdr,sizeof(WAVEHDR)); + } + dwRet = wodMessage(wDevID,WODM_UNPREPARE,0,(DWORD)lpWaveHdr,sizeof(WAVEHDR)); + if (lpWaveHdr->lpData != NULL) { + GlobalUnlock16(hData); + GlobalFree16(hData); + lpWaveHdr->lpData = NULL; + } + if (dwFlags & MCI_NOTIFY) { + TRACE(mciwave,"MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), MCIWavDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); - } - return 0; + } + return 0; } @@ -399,64 +401,64 @@ static DWORD WAVE_mciPlay(UINT16 wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms */ static DWORD WAVE_mciRecord(UINT16 wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpParms) { - int start, end; - LONG bufsize; - HGLOBAL16 hData; - LPWAVEHDR lpWaveHdr; - DWORD dwRet; - - TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); - - if (!MCIWavDev[wDevID].fInput) { - WARN(mciwave, "cannot record on output device\n"); - return MCIERR_NONAPPLICABLE_FUNCTION; - } - - if (MCIWavDev[wDevID].hFile == 0) { - WARN(mciwave, "can't find file='%08lx' !\n", - MCIWavDev[wDevID].openParms.lpstrElementName); - return MCIERR_FILE_NOT_FOUND; - } - start = 1; end = 99999; - if (dwFlags & MCI_FROM) { - start = lpParms->dwFrom; - TRACE(mciwave, "MCI_FROM=%d \n", start); - } - if (dwFlags & MCI_TO) { - end = lpParms->dwTo; - TRACE(mciwave,"MCI_TO=%d \n", end); - } - bufsize = 64000; - lpWaveHdr = &MCIWavDev[wDevID].WaveHdr; - hData = GlobalAlloc16(GMEM_MOVEABLE, bufsize); - lpWaveHdr->lpData = (LPSTR)GlobalLock16(hData); - lpWaveHdr->dwBufferLength = bufsize; - lpWaveHdr->dwUser = 0L; - lpWaveHdr->dwFlags = 0L; - lpWaveHdr->dwLoops = 0L; - dwRet=widMessage(wDevID,WIDM_PREPARE,0,(DWORD)lpWaveHdr,sizeof(WAVEHDR)); - TRACE(mciwave,"after WIDM_PREPARE \n"); - while(TRUE) { - lpWaveHdr->dwBytesRecorded = 0; - dwRet = widMessage(wDevID, WIDM_START, 0, 0L, 0L); - TRACE(mciwave, "after WIDM_START lpWaveHdr=%p dwBytesRecorded=%lu\n", - lpWaveHdr, lpWaveHdr->dwBytesRecorded); - if (lpWaveHdr->dwBytesRecorded == 0) break; - } - TRACE(mciwave,"before WIDM_UNPREPARE \n"); - dwRet = widMessage(wDevID,WIDM_UNPREPARE,0,(DWORD)lpWaveHdr,sizeof(WAVEHDR)); - TRACE(mciwave,"after WIDM_UNPREPARE \n"); - if (lpWaveHdr->lpData != NULL) { - GlobalUnlock16(hData); - GlobalFree16(hData); - lpWaveHdr->lpData = NULL; - } - if (dwFlags & MCI_NOTIFY) { - TRACE(mciwave,"MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + int start, end; + LONG bufsize; + HGLOBAL16 hData; + LPWAVEHDR lpWaveHdr; + DWORD dwRet; + + TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); + + if (!MCIWavDev[wDevID].fInput) { + WARN(mciwave, "cannot record on output device\n"); + return MCIERR_NONAPPLICABLE_FUNCTION; + } + + if (MCIWavDev[wDevID].hFile == 0) { + WARN(mciwave, "can't find file='%08lx' !\n", + MCIWavDev[wDevID].openParms.lpstrElementName); + return MCIERR_FILE_NOT_FOUND; + } + start = 1; end = 99999; + if (dwFlags & MCI_FROM) { + start = lpParms->dwFrom; + TRACE(mciwave, "MCI_FROM=%d \n", start); + } + if (dwFlags & MCI_TO) { + end = lpParms->dwTo; + TRACE(mciwave,"MCI_TO=%d \n", end); + } + bufsize = 64000; + lpWaveHdr = &MCIWavDev[wDevID].WaveHdr; + hData = GlobalAlloc16(GMEM_MOVEABLE, bufsize); + lpWaveHdr->lpData = (LPSTR)GlobalLock16(hData); + lpWaveHdr->dwBufferLength = bufsize; + lpWaveHdr->dwUser = 0L; + lpWaveHdr->dwFlags = 0L; + lpWaveHdr->dwLoops = 0L; + dwRet=widMessage(wDevID,WIDM_PREPARE,0,(DWORD)lpWaveHdr,sizeof(WAVEHDR)); + TRACE(mciwave,"after WIDM_PREPARE \n"); + while(TRUE) { + lpWaveHdr->dwBytesRecorded = 0; + dwRet = widMessage(wDevID, WIDM_START, 0, 0L, 0L); + TRACE(mciwave, "after WIDM_START lpWaveHdr=%p dwBytesRecorded=%lu\n", + lpWaveHdr, lpWaveHdr->dwBytesRecorded); + if (lpWaveHdr->dwBytesRecorded == 0) break; + } + TRACE(mciwave,"before WIDM_UNPREPARE \n"); + dwRet = widMessage(wDevID,WIDM_UNPREPARE,0,(DWORD)lpWaveHdr,sizeof(WAVEHDR)); + TRACE(mciwave,"after WIDM_UNPREPARE \n"); + if (lpWaveHdr->lpData != NULL) { + GlobalUnlock16(hData); + GlobalFree16(hData); + lpWaveHdr->lpData = NULL; + } + if (dwFlags & MCI_NOTIFY) { + TRACE(mciwave,"MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), MCIWavDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); - } - return 0; + } + return 0; } @@ -465,16 +467,16 @@ static DWORD WAVE_mciRecord(UINT16 wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpP */ static DWORD WAVE_mciStop(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms) { - DWORD dwRet; - - TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - if (MCIWavDev[wDevID].fInput) - dwRet = widMessage(wDevID, WIDM_STOP, 0, dwFlags, (DWORD)lpParms); - else - dwRet = wodMessage(wDevID, WODM_STOP, 0, dwFlags, (DWORD)lpParms); - - return dwRet; + DWORD dwRet; + + TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + if (MCIWavDev[wDevID].fInput) + dwRet = widMessage(wDevID, WIDM_STOP, 0, dwFlags, (DWORD)lpParms); + else + dwRet = wodMessage(wDevID, WODM_STOP, 0, dwFlags, (DWORD)lpParms); + + return dwRet; } @@ -483,16 +485,16 @@ static DWORD WAVE_mciStop(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpPa */ static DWORD WAVE_mciPause(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms) { - DWORD dwRet; - - TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - if (MCIWavDev[wDevID].fInput) - dwRet = widMessage(wDevID, WIDM_PAUSE, 0, dwFlags, (DWORD)lpParms); - else - dwRet = wodMessage(wDevID, WODM_PAUSE, 0, dwFlags, (DWORD)lpParms); - - return dwRet; + DWORD dwRet; + + TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + if (MCIWavDev[wDevID].fInput) + dwRet = widMessage(wDevID, WIDM_PAUSE, 0, dwFlags, (DWORD)lpParms); + else + dwRet = wodMessage(wDevID, WODM_PAUSE, 0, dwFlags, (DWORD)lpParms); + + return dwRet; } @@ -501,9 +503,9 @@ static DWORD WAVE_mciPause(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpP */ static DWORD WAVE_mciResume(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms) { - TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - return 0; + TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + return 0; } @@ -512,61 +514,61 @@ static DWORD WAVE_mciResume(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lp */ static DWORD WAVE_mciSet(UINT16 wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms) { - TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - TRACE(mciwave, "dwTimeFormat=%08lX\n", lpParms->dwTimeFormat); - TRACE(mciwave, "dwAudio=%08lX\n", lpParms->dwAudio); - if (dwFlags & MCI_SET_TIME_FORMAT) { - switch (lpParms->dwTimeFormat) { - case MCI_FORMAT_MILLISECONDS: - TRACE(mciwave, "MCI_FORMAT_MILLISECONDS !\n"); - break; - case MCI_FORMAT_BYTES: - TRACE(mciwave, "MCI_FORMAT_BYTES !\n"); - break; - case MCI_FORMAT_SAMPLES: - TRACE(mciwave, "MCI_FORMAT_SAMPLES !\n"); - break; - default: - WARN(mciwave, "bad time format !\n"); - return MCIERR_BAD_TIME_FORMAT; - } + TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + TRACE(mciwave, "dwTimeFormat=%08lX\n", lpParms->dwTimeFormat); + TRACE(mciwave, "dwAudio=%08lX\n", lpParms->dwAudio); + if (dwFlags & MCI_SET_TIME_FORMAT) { + switch (lpParms->dwTimeFormat) { + case MCI_FORMAT_MILLISECONDS: + TRACE(mciwave, "MCI_FORMAT_MILLISECONDS !\n"); + break; + case MCI_FORMAT_BYTES: + TRACE(mciwave, "MCI_FORMAT_BYTES !\n"); + break; + case MCI_FORMAT_SAMPLES: + TRACE(mciwave, "MCI_FORMAT_SAMPLES !\n"); + break; + default: + WARN(mciwave, "bad time format !\n"); + return MCIERR_BAD_TIME_FORMAT; } - if (dwFlags & MCI_SET_VIDEO) return MCIERR_UNSUPPORTED_FUNCTION; - if (dwFlags & MCI_SET_DOOR_OPEN) return MCIERR_UNSUPPORTED_FUNCTION; - if (dwFlags & MCI_SET_DOOR_CLOSED) return MCIERR_UNSUPPORTED_FUNCTION; - if (dwFlags & MCI_SET_AUDIO) - TRACE(mciwave,"MCI_SET_AUDIO !\n"); - if (dwFlags && MCI_SET_ON) { - TRACE(mciwave,"MCI_SET_ON !\n"); - if (dwFlags && MCI_SET_AUDIO_LEFT) + } + if (dwFlags & MCI_SET_VIDEO) return MCIERR_UNSUPPORTED_FUNCTION; + if (dwFlags & MCI_SET_DOOR_OPEN) return MCIERR_UNSUPPORTED_FUNCTION; + if (dwFlags & MCI_SET_DOOR_CLOSED) return MCIERR_UNSUPPORTED_FUNCTION; + if (dwFlags & MCI_SET_AUDIO) + TRACE(mciwave,"MCI_SET_AUDIO !\n"); + if (dwFlags && MCI_SET_ON) { + TRACE(mciwave,"MCI_SET_ON !\n"); + if (dwFlags && MCI_SET_AUDIO_LEFT) TRACE(mciwave,"MCI_SET_AUDIO_LEFT !\n"); - if (dwFlags && MCI_SET_AUDIO_RIGHT) + if (dwFlags && MCI_SET_AUDIO_RIGHT) TRACE(mciwave,"MCI_SET_AUDIO_RIGHT !\n"); - } - if (dwFlags & MCI_SET_OFF) - TRACE(mciwave,"MCI_SET_OFF !\n"); - if (dwFlags & MCI_WAVE_INPUT) - TRACE(mciwave,"MCI_WAVE_INPUT !\n"); - if (dwFlags & MCI_WAVE_OUTPUT) - TRACE(mciwave,"MCI_WAVE_OUTPUT !\n"); - if (dwFlags & MCI_WAVE_SET_ANYINPUT) - TRACE(mciwave,"MCI_WAVE_SET_ANYINPUT !\n"); - if (dwFlags & MCI_WAVE_SET_ANYOUTPUT) - TRACE(mciwave,"MCI_WAVE_SET_ANYOUTPUT !\n"); - if (dwFlags & MCI_WAVE_SET_AVGBYTESPERSEC) - TRACE(mciwave, "MCI_WAVE_SET_AVGBYTESPERSEC !\n"); - if (dwFlags & MCI_WAVE_SET_BITSPERSAMPLE) - TRACE(mciwave, "MCI_WAVE_SET_BITSPERSAMPLE !\n"); - if (dwFlags & MCI_WAVE_SET_BLOCKALIGN) - TRACE(mciwave,"MCI_WAVE_SET_BLOCKALIGN !\n"); - if (dwFlags & MCI_WAVE_SET_CHANNELS) - TRACE(mciwave,"MCI_WAVE_SET_CHANNELS !\n"); - if (dwFlags & MCI_WAVE_SET_FORMATTAG) - TRACE(mciwave,"MCI_WAVE_SET_FORMATTAG !\n"); - if (dwFlags & MCI_WAVE_SET_SAMPLESPERSEC) - TRACE(mciwave, "MCI_WAVE_SET_SAMPLESPERSEC !\n"); - return 0; + } + if (dwFlags & MCI_SET_OFF) + TRACE(mciwave,"MCI_SET_OFF !\n"); + if (dwFlags & MCI_WAVE_INPUT) + TRACE(mciwave,"MCI_WAVE_INPUT !\n"); + if (dwFlags & MCI_WAVE_OUTPUT) + TRACE(mciwave,"MCI_WAVE_OUTPUT !\n"); + if (dwFlags & MCI_WAVE_SET_ANYINPUT) + TRACE(mciwave,"MCI_WAVE_SET_ANYINPUT !\n"); + if (dwFlags & MCI_WAVE_SET_ANYOUTPUT) + TRACE(mciwave,"MCI_WAVE_SET_ANYOUTPUT !\n"); + if (dwFlags & MCI_WAVE_SET_AVGBYTESPERSEC) + TRACE(mciwave, "MCI_WAVE_SET_AVGBYTESPERSEC !\n"); + if (dwFlags & MCI_WAVE_SET_BITSPERSAMPLE) + TRACE(mciwave, "MCI_WAVE_SET_BITSPERSAMPLE !\n"); + if (dwFlags & MCI_WAVE_SET_BLOCKALIGN) + TRACE(mciwave,"MCI_WAVE_SET_BLOCKALIGN !\n"); + if (dwFlags & MCI_WAVE_SET_CHANNELS) + TRACE(mciwave,"MCI_WAVE_SET_CHANNELS !\n"); + if (dwFlags & MCI_WAVE_SET_FORMATTAG) + TRACE(mciwave,"MCI_WAVE_SET_FORMATTAG !\n"); + if (dwFlags & MCI_WAVE_SET_SAMPLESPERSEC) + TRACE(mciwave, "MCI_WAVE_SET_SAMPLESPERSEC !\n"); + return 0; } @@ -575,144 +577,144 @@ static DWORD WAVE_mciSet(UINT16 wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms) */ static DWORD WAVE_mciStatus(UINT16 wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms) { - TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - if (dwFlags & MCI_STATUS_ITEM) { - switch(lpParms->dwItem) { - case MCI_STATUS_CURRENT_TRACK: - lpParms->dwReturn = 1; - break; - case MCI_STATUS_LENGTH: - lpParms->dwReturn = 5555; - if (dwFlags & MCI_TRACK) { - lpParms->dwTrack = 1; - lpParms->dwReturn = 2222; - } - break; - case MCI_STATUS_MODE: - lpParms->dwReturn = MCI_MODE_STOP; - break; - case MCI_STATUS_MEDIA_PRESENT: - TRACE(mciwave,"MCI_STATUS_MEDIA_PRESENT !\n"); - lpParms->dwReturn = TRUE; - break; - case MCI_STATUS_NUMBER_OF_TRACKS: - lpParms->dwReturn = 1; - break; - case MCI_STATUS_POSITION: - lpParms->dwReturn = 3333; - if (dwFlags & MCI_STATUS_START) - lpParms->dwItem = 1; - if (dwFlags & MCI_TRACK) { - lpParms->dwTrack = 1; - lpParms->dwReturn = 777; - } - break; - case MCI_STATUS_READY: - TRACE(mciwave,"MCI_STATUS_READY !\n"); - lpParms->dwReturn = TRUE; - break; - case MCI_STATUS_TIME_FORMAT: - TRACE(mciwave,"MCI_STATUS_TIME_FORMAT !\n"); - lpParms->dwReturn = MCI_FORMAT_MILLISECONDS; - break; - case MCI_WAVE_INPUT: - TRACE(mciwave,"MCI_WAVE_INPUT !\n"); - lpParms->dwReturn = 0; - break; - case MCI_WAVE_OUTPUT: - TRACE(mciwave,"MCI_WAVE_OUTPUT !\n"); - lpParms->dwReturn = 0; - break; - case MCI_WAVE_STATUS_AVGBYTESPERSEC: - TRACE(mciwave,"MCI_WAVE_STATUS_AVGBYTESPERSEC !\n"); - lpParms->dwReturn = 22050; - break; - case MCI_WAVE_STATUS_BITSPERSAMPLE: - TRACE(mciwave,"MCI_WAVE_STATUS_BITSPERSAMPLE !\n"); - lpParms->dwReturn = 8; - break; - case MCI_WAVE_STATUS_BLOCKALIGN: - TRACE(mciwave,"MCI_WAVE_STATUS_BLOCKALIGN !\n"); - lpParms->dwReturn = 1; - break; - case MCI_WAVE_STATUS_CHANNELS: - TRACE(mciwave,"MCI_WAVE_STATUS_CHANNELS !\n"); - lpParms->dwReturn = 1; - break; - case MCI_WAVE_STATUS_FORMATTAG: - TRACE(mciwave,"MCI_WAVE_FORMATTAG !\n"); - lpParms->dwReturn = WAVE_FORMAT_PCM; - break; - case MCI_WAVE_STATUS_LEVEL: - TRACE(mciwave,"MCI_WAVE_STATUS_LEVEL !\n"); - lpParms->dwReturn = 0xAAAA5555; - break; - case MCI_WAVE_STATUS_SAMPLESPERSEC: - TRACE(mciwave,"MCI_WAVE_STATUS_SAMPLESPERSEC !\n"); - lpParms->dwReturn = 22050; - break; - default: - WARN(mciwave,"unknown command %08lX !\n", lpParms->dwItem); - return MCIERR_UNRECOGNIZED_COMMAND; - } + TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + if (dwFlags & MCI_STATUS_ITEM) { + switch(lpParms->dwItem) { + case MCI_STATUS_CURRENT_TRACK: + lpParms->dwReturn = 1; + break; + case MCI_STATUS_LENGTH: + lpParms->dwReturn = 5555; + if (dwFlags & MCI_TRACK) { + lpParms->dwTrack = 1; + lpParms->dwReturn = 2222; + } + break; + case MCI_STATUS_MODE: + lpParms->dwReturn = MCI_MODE_STOP; + break; + case MCI_STATUS_MEDIA_PRESENT: + TRACE(mciwave,"MCI_STATUS_MEDIA_PRESENT !\n"); + lpParms->dwReturn = TRUE; + break; + case MCI_STATUS_NUMBER_OF_TRACKS: + lpParms->dwReturn = 1; + break; + case MCI_STATUS_POSITION: + lpParms->dwReturn = 3333; + if (dwFlags & MCI_STATUS_START) + lpParms->dwItem = 1; + if (dwFlags & MCI_TRACK) { + lpParms->dwTrack = 1; + lpParms->dwReturn = 777; + } + break; + case MCI_STATUS_READY: + TRACE(mciwave,"MCI_STATUS_READY !\n"); + lpParms->dwReturn = TRUE; + break; + case MCI_STATUS_TIME_FORMAT: + TRACE(mciwave,"MCI_STATUS_TIME_FORMAT !\n"); + lpParms->dwReturn = MCI_FORMAT_MILLISECONDS; + break; + case MCI_WAVE_INPUT: + TRACE(mciwave,"MCI_WAVE_INPUT !\n"); + lpParms->dwReturn = 0; + break; + case MCI_WAVE_OUTPUT: + TRACE(mciwave,"MCI_WAVE_OUTPUT !\n"); + lpParms->dwReturn = 0; + break; + case MCI_WAVE_STATUS_AVGBYTESPERSEC: + TRACE(mciwave,"MCI_WAVE_STATUS_AVGBYTESPERSEC !\n"); + lpParms->dwReturn = 22050; + break; + case MCI_WAVE_STATUS_BITSPERSAMPLE: + TRACE(mciwave,"MCI_WAVE_STATUS_BITSPERSAMPLE !\n"); + lpParms->dwReturn = 8; + break; + case MCI_WAVE_STATUS_BLOCKALIGN: + TRACE(mciwave,"MCI_WAVE_STATUS_BLOCKALIGN !\n"); + lpParms->dwReturn = 1; + break; + case MCI_WAVE_STATUS_CHANNELS: + TRACE(mciwave,"MCI_WAVE_STATUS_CHANNELS !\n"); + lpParms->dwReturn = 1; + break; + case MCI_WAVE_STATUS_FORMATTAG: + TRACE(mciwave,"MCI_WAVE_FORMATTAG !\n"); + lpParms->dwReturn = WAVE_FORMAT_PCM; + break; + case MCI_WAVE_STATUS_LEVEL: + TRACE(mciwave,"MCI_WAVE_STATUS_LEVEL !\n"); + lpParms->dwReturn = 0xAAAA5555; + break; + case MCI_WAVE_STATUS_SAMPLESPERSEC: + TRACE(mciwave,"MCI_WAVE_STATUS_SAMPLESPERSEC !\n"); + lpParms->dwReturn = 22050; + break; + default: + WARN(mciwave,"unknown command %08lX !\n", lpParms->dwItem); + return MCIERR_UNRECOGNIZED_COMMAND; } - if (dwFlags & MCI_NOTIFY) { - TRACE(mciwave,"MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + } + if (dwFlags & MCI_NOTIFY) { + TRACE(mciwave,"MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), MCIWavDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); - } - return 0; + } + return 0; } /************************************************************************** * WAVE_mciGetDevCaps [internal] */ static DWORD WAVE_mciGetDevCaps(UINT16 wDevID, DWORD dwFlags, - LPMCI_GETDEVCAPS_PARMS lpParms) + LPMCI_GETDEVCAPS_PARMS lpParms) { - TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - if (dwFlags & MCI_GETDEVCAPS_ITEM) { - switch(lpParms->dwItem) { - case MCI_GETDEVCAPS_CAN_RECORD: - lpParms->dwReturn = TRUE; - break; - case MCI_GETDEVCAPS_HAS_AUDIO: - lpParms->dwReturn = TRUE; - break; - case MCI_GETDEVCAPS_HAS_VIDEO: - lpParms->dwReturn = FALSE; - break; - case MCI_GETDEVCAPS_DEVICE_TYPE: - lpParms->dwReturn = MCI_DEVTYPE_WAVEFORM_AUDIO; - break; - case MCI_GETDEVCAPS_USES_FILES: - lpParms->dwReturn = TRUE; - break; - case MCI_GETDEVCAPS_COMPOUND_DEVICE: - lpParms->dwReturn = TRUE; - break; - case MCI_GETDEVCAPS_CAN_EJECT: - lpParms->dwReturn = FALSE; - break; - case MCI_GETDEVCAPS_CAN_PLAY: - lpParms->dwReturn = TRUE; - break; - case MCI_GETDEVCAPS_CAN_SAVE: - lpParms->dwReturn = TRUE; - break; - case MCI_WAVE_GETDEVCAPS_INPUTS: - lpParms->dwReturn = 1; - break; - case MCI_WAVE_GETDEVCAPS_OUTPUTS: - lpParms->dwReturn = 1; - break; - default: - return MCIERR_UNRECOGNIZED_COMMAND; - } + TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + if (dwFlags & MCI_GETDEVCAPS_ITEM) { + switch(lpParms->dwItem) { + case MCI_GETDEVCAPS_CAN_RECORD: + lpParms->dwReturn = TRUE; + break; + case MCI_GETDEVCAPS_HAS_AUDIO: + lpParms->dwReturn = TRUE; + break; + case MCI_GETDEVCAPS_HAS_VIDEO: + lpParms->dwReturn = FALSE; + break; + case MCI_GETDEVCAPS_DEVICE_TYPE: + lpParms->dwReturn = MCI_DEVTYPE_WAVEFORM_AUDIO; + break; + case MCI_GETDEVCAPS_USES_FILES: + lpParms->dwReturn = TRUE; + break; + case MCI_GETDEVCAPS_COMPOUND_DEVICE: + lpParms->dwReturn = TRUE; + break; + case MCI_GETDEVCAPS_CAN_EJECT: + lpParms->dwReturn = FALSE; + break; + case MCI_GETDEVCAPS_CAN_PLAY: + lpParms->dwReturn = TRUE; + break; + case MCI_GETDEVCAPS_CAN_SAVE: + lpParms->dwReturn = TRUE; + break; + case MCI_WAVE_GETDEVCAPS_INPUTS: + lpParms->dwReturn = 1; + break; + case MCI_WAVE_GETDEVCAPS_OUTPUTS: + lpParms->dwReturn = 1; + break; + default: + return MCIERR_UNRECOGNIZED_COMMAND; } - return 0; + } + return 0; } /************************************************************************** @@ -720,31 +722,31 @@ static DWORD WAVE_mciGetDevCaps(UINT16 wDevID, DWORD dwFlags, */ static DWORD WAVE_mciInfo(UINT16 wDevID, DWORD dwFlags, LPMCI_INFO_PARMS16 lpParms) { - TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - lpParms->lpstrReturn = NULL; - switch(dwFlags) { - case MCI_INFO_PRODUCT: - lpParms->lpstrReturn = "Open Sound System 0.5"; - break; - case MCI_INFO_FILE: - lpParms->lpstrReturn = - (LPSTR)MCIWavDev[wDevID].openParms.lpstrElementName; - break; - case MCI_WAVE_INPUT: - lpParms->lpstrReturn = "Open Sound System 0.5"; - break; - case MCI_WAVE_OUTPUT: - lpParms->lpstrReturn = "Open Sound System 0.5"; - break; - default: - return MCIERR_UNRECOGNIZED_COMMAND; - } - if (lpParms->lpstrReturn != NULL) - lpParms->dwRetSize = strlen(lpParms->lpstrReturn); - else - lpParms->dwRetSize = 0; - return 0; + TRACE(mciwave, "(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + lpParms->lpstrReturn = NULL; + switch(dwFlags) { + case MCI_INFO_PRODUCT: + lpParms->lpstrReturn = "Open Sound System 0.5"; + break; + case MCI_INFO_FILE: + lpParms->lpstrReturn = + (LPSTR)MCIWavDev[wDevID].openParms.lpstrElementName; + break; + case MCI_WAVE_INPUT: + lpParms->lpstrReturn = "Open Sound System 0.5"; + break; + case MCI_WAVE_OUTPUT: + lpParms->lpstrReturn = "Open Sound System 0.5"; + break; + default: + return MCIERR_UNRECOGNIZED_COMMAND; + } + if (lpParms->lpstrReturn != NULL) + lpParms->dwRetSize = strlen(lpParms->lpstrReturn); + else + lpParms->dwRetSize = 0; + return 0; } @@ -756,72 +758,72 @@ static DWORD WAVE_mciInfo(UINT16 wDevID, DWORD dwFlags, LPMCI_INFO_PARMS16 lpPar */ static DWORD wodGetDevCaps(WORD wDevID, LPWAVEOUTCAPS16 lpCaps, DWORD dwSize) { - int audio; - int smplrate; - int samplesize = 16; - int dsp_stereo = 1; - int bytespersmpl; - - TRACE(mciwave, "(%u, %p, %lu);\n", wDevID, lpCaps, dwSize); - if (lpCaps == NULL) return MMSYSERR_NOTENABLED; - if (access(SOUND_DEV,0) != 0) return MMSYSERR_NOTENABLED; - audio = open (SOUND_DEV, O_WRONLY, 0); - if (audio == -1) return MMSYSERR_ALLOCATED ; + int audio; + int smplrate; + int samplesize = 16; + int dsp_stereo = 1; + int bytespersmpl; + + TRACE(mciwave, "(%u, %p, %lu);\n", wDevID, lpCaps, dwSize); + if (lpCaps == NULL) return MMSYSERR_NOTENABLED; + if (access(SOUND_DEV,0) != 0) return MMSYSERR_NOTENABLED; + audio = open (SOUND_DEV, O_WRONLY, 0); + if (audio == -1) return MMSYSERR_ALLOCATED ; #ifdef EMULATE_SB16 - lpCaps->wMid = 0x0002; - lpCaps->wPid = 0x0104; - strcpy(lpCaps->szPname, "SB16 Wave Out"); + lpCaps->wMid = 0x0002; + lpCaps->wPid = 0x0104; + strcpy(lpCaps->szPname, "SB16 Wave Out"); #else - lpCaps->wMid = 0x00FF; /* Manufac ID */ - lpCaps->wPid = 0x0001; /* Product ID */ - strcpy(lpCaps->szPname, "OpenSoundSystem WAVOUT Driver"); + lpCaps->wMid = 0x00FF; /* Manufac ID */ + lpCaps->wPid = 0x0001; /* Product ID */ + strcpy(lpCaps->szPname, "OpenSoundSystem WAVOUT Driver"); #endif - lpCaps->vDriverVersion = 0x0100; - lpCaps->dwFormats = 0x00000000; - lpCaps->dwSupport = WAVECAPS_VOLUME; - - /* First bytespersampl, then stereo */ - bytespersmpl = (IOCTL(audio, SNDCTL_DSP_SAMPLESIZE, samplesize) != 0) ? 1 : 2; - - lpCaps->wChannels = (IOCTL(audio, SNDCTL_DSP_STEREO, dsp_stereo) != 0) ? 1 : 2; - if (lpCaps->wChannels > 1) lpCaps->dwSupport |= WAVECAPS_LRVOLUME; - - smplrate = 44100; - if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) { - lpCaps->dwFormats |= WAVE_FORMAT_4M08; - if (lpCaps->wChannels > 1) - lpCaps->dwFormats |= WAVE_FORMAT_4S08; - if (bytespersmpl > 1) { - lpCaps->dwFormats |= WAVE_FORMAT_4M16; - if (lpCaps->wChannels > 1) - lpCaps->dwFormats |= WAVE_FORMAT_4S16; - } + lpCaps->vDriverVersion = 0x0100; + lpCaps->dwFormats = 0x00000000; + lpCaps->dwSupport = WAVECAPS_VOLUME; + + /* First bytespersampl, then stereo */ + bytespersmpl = (IOCTL(audio, SNDCTL_DSP_SAMPLESIZE, samplesize) != 0) ? 1 : 2; + + lpCaps->wChannels = (IOCTL(audio, SNDCTL_DSP_STEREO, dsp_stereo) != 0) ? 1 : 2; + if (lpCaps->wChannels > 1) lpCaps->dwSupport |= WAVECAPS_LRVOLUME; + + smplrate = 44100; + if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) { + lpCaps->dwFormats |= WAVE_FORMAT_4M08; + if (lpCaps->wChannels > 1) + lpCaps->dwFormats |= WAVE_FORMAT_4S08; + if (bytespersmpl > 1) { + lpCaps->dwFormats |= WAVE_FORMAT_4M16; + if (lpCaps->wChannels > 1) + lpCaps->dwFormats |= WAVE_FORMAT_4S16; } - smplrate = 22050; - if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) { - lpCaps->dwFormats |= WAVE_FORMAT_2M08; - if (lpCaps->wChannels > 1) - lpCaps->dwFormats |= WAVE_FORMAT_2S08; - if (bytespersmpl > 1) { - lpCaps->dwFormats |= WAVE_FORMAT_2M16; - if (lpCaps->wChannels > 1) - lpCaps->dwFormats |= WAVE_FORMAT_2S16; - } + } + smplrate = 22050; + if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) { + lpCaps->dwFormats |= WAVE_FORMAT_2M08; + if (lpCaps->wChannels > 1) + lpCaps->dwFormats |= WAVE_FORMAT_2S08; + if (bytespersmpl > 1) { + lpCaps->dwFormats |= WAVE_FORMAT_2M16; + if (lpCaps->wChannels > 1) + lpCaps->dwFormats |= WAVE_FORMAT_2S16; } - smplrate = 11025; - if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) { - lpCaps->dwFormats |= WAVE_FORMAT_1M08; - if (lpCaps->wChannels > 1) - lpCaps->dwFormats |= WAVE_FORMAT_1S08; - if (bytespersmpl > 1) { - lpCaps->dwFormats |= WAVE_FORMAT_1M16; - if (lpCaps->wChannels > 1) - lpCaps->dwFormats |= WAVE_FORMAT_1S16; - } + } + smplrate = 11025; + if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) { + lpCaps->dwFormats |= WAVE_FORMAT_1M08; + if (lpCaps->wChannels > 1) + lpCaps->dwFormats |= WAVE_FORMAT_1S08; + if (bytespersmpl > 1) { + lpCaps->dwFormats |= WAVE_FORMAT_1M16; + if (lpCaps->wChannels > 1) + lpCaps->dwFormats |= WAVE_FORMAT_1S16; } - close(audio); - TRACE(mciwave, "dwFormats = %08lX\n", lpCaps->dwFormats); - return MMSYSERR_NOERROR; + } + close(audio); + TRACE(mciwave, "dwFormats = %08lX\n", lpCaps->dwFormats); + return MMSYSERR_NOERROR; } @@ -830,99 +832,99 @@ static DWORD wodGetDevCaps(WORD wDevID, LPWAVEOUTCAPS16 lpCaps, DWORD dwSize) */ static DWORD wodOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags) { - int audio,abuf_size,smplrate,samplesize,dsp_stereo; - LPWAVEFORMAT lpFormat; - - TRACE(mciwave, "(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags); - if (lpDesc == NULL) { - WARN(mciwave, "Invalid Parameter !\n"); - return MMSYSERR_INVALPARAM; - } - if (wDevID >= MAX_WAVOUTDRV) { - TRACE(mciwave,"MAX_WAVOUTDRV reached !\n"); - return MMSYSERR_ALLOCATED; - } - WOutDev[wDevID].unixdev = 0; - if (access(SOUND_DEV,0) != 0) return MMSYSERR_NOTENABLED; - audio = open (SOUND_DEV, O_WRONLY, 0); - if (audio == -1) { - WARN(mciwave, "can't open !\n"); - return MMSYSERR_ALLOCATED ; - } - IOCTL(audio, SNDCTL_DSP_GETBLKSIZE, abuf_size); - if (abuf_size < 1024 || abuf_size > 65536) { - if (abuf_size == -1) - WARN(mciwave, "IOCTL can't 'SNDCTL_DSP_GETBLKSIZE' !\n"); - else - WARN(mciwave, "SNDCTL_DSP_GETBLKSIZE Invalid bufsize !\n"); - return MMSYSERR_NOTENABLED; - } - WOutDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK); - switch(WOutDev[wDevID].wFlags) { - case DCB_NULL: - TRACE(mciwave, "CALLBACK_NULL !\n"); - break; - case DCB_WINDOW: - TRACE(mciwave, "CALLBACK_WINDOW !\n"); - break; - case DCB_TASK: - TRACE(mciwave, "CALLBACK_TASK !\n"); - break; - case DCB_FUNCTION: - TRACE(mciwave, "CALLBACK_FUNCTION !\n"); - break; - } - WOutDev[wDevID].lpQueueHdr = NULL; - WOutDev[wDevID].unixdev = audio; - WOutDev[wDevID].dwTotalPlayed = 0; - WOutDev[wDevID].bufsize = abuf_size; - /* FIXME: copy lpFormat too? */ - memcpy(&WOutDev[wDevID].waveDesc, lpDesc, sizeof(WAVEOPENDESC)); - TRACE(mciwave,"lpDesc->lpFormat = %p\n",lpDesc->lpFormat); - lpFormat = lpDesc->lpFormat; - TRACE(mciwave,"lpFormat = %p\n",lpFormat); - if (lpFormat->wFormatTag != WAVE_FORMAT_PCM) { - WARN(mciwave,"Bad format %04X !\n", - lpFormat->wFormatTag); - WARN(mciwave,"Bad nChannels %d !\n", - lpFormat->nChannels); - WARN(mciwave,"Bad nSamplesPerSec %ld !\n", - lpFormat->nSamplesPerSec); - return WAVERR_BADFORMAT; - } - memcpy(&WOutDev[wDevID].Format, lpFormat, sizeof(PCMWAVEFORMAT)); - if (WOutDev[wDevID].Format.wf.nChannels == 0) return WAVERR_BADFORMAT; - if (WOutDev[wDevID].Format.wf.nSamplesPerSec == 0) return WAVERR_BADFORMAT; - TRACE(mciwave,"wBitsPerSample=%u !\n", - WOutDev[wDevID].Format.wBitsPerSample); - if (WOutDev[wDevID].Format.wBitsPerSample == 0) { - WOutDev[wDevID].Format.wBitsPerSample = 8 * - (WOutDev[wDevID].Format.wf.nAvgBytesPerSec / - WOutDev[wDevID].Format.wf.nSamplesPerSec) / - WOutDev[wDevID].Format.wf.nChannels; - } - samplesize = WOutDev[wDevID].Format.wBitsPerSample; - smplrate = WOutDev[wDevID].Format.wf.nSamplesPerSec; - dsp_stereo = (WOutDev[wDevID].Format.wf.nChannels > 1) ? TRUE : FALSE; - - /* First size and stereo then samplerate */ - IOCTL(audio, SNDCTL_DSP_SAMPLESIZE, samplesize); - IOCTL(audio, SNDCTL_DSP_STEREO, dsp_stereo); - IOCTL(audio, SNDCTL_DSP_SPEED, smplrate); - - TRACE(mciwave,"wBitsPerSample=%u !\n", - WOutDev[wDevID].Format.wBitsPerSample); - TRACE(mciwave,"nAvgBytesPerSec=%lu !\n", - WOutDev[wDevID].Format.wf.nAvgBytesPerSec); - TRACE(mciwave,"nSamplesPerSec=%lu !\n", - WOutDev[wDevID].Format.wf.nSamplesPerSec); - TRACE(mciwave,"nChannels=%u !\n", - WOutDev[wDevID].Format.wf.nChannels); - if (WAVE_NotifyClient(wDevID, WOM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) { - WARN(mciwave, "can't notify client !\n"); - return MMSYSERR_INVALPARAM; - } - return MMSYSERR_NOERROR; + int audio,abuf_size,smplrate,samplesize,dsp_stereo; + LPWAVEFORMAT lpFormat; + + TRACE(mciwave, "(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags); + if (lpDesc == NULL) { + WARN(mciwave, "Invalid Parameter !\n"); + return MMSYSERR_INVALPARAM; + } + if (wDevID >= MAX_WAVOUTDRV) { + TRACE(mciwave,"MAX_WAVOUTDRV reached !\n"); + return MMSYSERR_ALLOCATED; + } + WOutDev[wDevID].unixdev = 0; + if (access(SOUND_DEV,0) != 0) return MMSYSERR_NOTENABLED; + audio = open (SOUND_DEV, O_WRONLY, 0); + if (audio == -1) { + WARN(mciwave, "can't open !\n"); + return MMSYSERR_ALLOCATED ; + } + IOCTL(audio, SNDCTL_DSP_GETBLKSIZE, abuf_size); + if (abuf_size < 1024 || abuf_size > 65536) { + if (abuf_size == -1) + WARN(mciwave, "IOCTL can't 'SNDCTL_DSP_GETBLKSIZE' !\n"); + else + WARN(mciwave, "SNDCTL_DSP_GETBLKSIZE Invalid bufsize !\n"); + return MMSYSERR_NOTENABLED; + } + WOutDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK); + switch(WOutDev[wDevID].wFlags) { + case DCB_NULL: + TRACE(mciwave, "CALLBACK_NULL !\n"); + break; + case DCB_WINDOW: + TRACE(mciwave, "CALLBACK_WINDOW !\n"); + break; + case DCB_TASK: + TRACE(mciwave, "CALLBACK_TASK !\n"); + break; + case DCB_FUNCTION: + TRACE(mciwave, "CALLBACK_FUNCTION !\n"); + break; + } + WOutDev[wDevID].lpQueueHdr = NULL; + WOutDev[wDevID].unixdev = audio; + WOutDev[wDevID].dwTotalPlayed = 0; + WOutDev[wDevID].bufsize = abuf_size; + /* FIXME: copy lpFormat too? */ + memcpy(&WOutDev[wDevID].waveDesc, lpDesc, sizeof(WAVEOPENDESC)); + TRACE(mciwave,"lpDesc->lpFormat = %p\n",lpDesc->lpFormat); + lpFormat = lpDesc->lpFormat; + TRACE(mciwave,"lpFormat = %p\n",lpFormat); + if (lpFormat->wFormatTag != WAVE_FORMAT_PCM) { + WARN(mciwave,"Bad format %04X !\n", + lpFormat->wFormatTag); + WARN(mciwave,"Bad nChannels %d !\n", + lpFormat->nChannels); + WARN(mciwave,"Bad nSamplesPerSec %ld !\n", + lpFormat->nSamplesPerSec); + return WAVERR_BADFORMAT; + } + memcpy(&WOutDev[wDevID].Format, lpFormat, sizeof(PCMWAVEFORMAT)); + if (WOutDev[wDevID].Format.wf.nChannels == 0) return WAVERR_BADFORMAT; + if (WOutDev[wDevID].Format.wf.nSamplesPerSec == 0) return WAVERR_BADFORMAT; + TRACE(mciwave,"wBitsPerSample=%u !\n", + WOutDev[wDevID].Format.wBitsPerSample); + if (WOutDev[wDevID].Format.wBitsPerSample == 0) { + WOutDev[wDevID].Format.wBitsPerSample = 8 * + (WOutDev[wDevID].Format.wf.nAvgBytesPerSec / + WOutDev[wDevID].Format.wf.nSamplesPerSec) / + WOutDev[wDevID].Format.wf.nChannels; + } + samplesize = WOutDev[wDevID].Format.wBitsPerSample; + smplrate = WOutDev[wDevID].Format.wf.nSamplesPerSec; + dsp_stereo = (WOutDev[wDevID].Format.wf.nChannels > 1) ? TRUE : FALSE; + + /* First size and stereo then samplerate */ + IOCTL(audio, SNDCTL_DSP_SAMPLESIZE, samplesize); + IOCTL(audio, SNDCTL_DSP_STEREO, dsp_stereo); + IOCTL(audio, SNDCTL_DSP_SPEED, smplrate); + + TRACE(mciwave,"wBitsPerSample=%u !\n", + WOutDev[wDevID].Format.wBitsPerSample); + TRACE(mciwave,"nAvgBytesPerSec=%lu !\n", + WOutDev[wDevID].Format.wf.nAvgBytesPerSec); + TRACE(mciwave,"nSamplesPerSec=%lu !\n", + WOutDev[wDevID].Format.wf.nSamplesPerSec); + TRACE(mciwave,"nChannels=%u !\n", + WOutDev[wDevID].Format.wf.nChannels); + if (WAVE_NotifyClient(wDevID, WOM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) { + WARN(mciwave, "can't notify client !\n"); + return MMSYSERR_INVALPARAM; + } + return MMSYSERR_NOERROR; } /************************************************************************** @@ -930,26 +932,26 @@ static DWORD wodOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags) */ static DWORD wodClose(WORD wDevID) { - TRACE(mciwave,"(%u);\n", wDevID); - if (wDevID > MAX_WAVOUTDRV) return MMSYSERR_INVALPARAM; - if (WOutDev[wDevID].unixdev == 0) { - WARN(mciwave, "can't close !\n"); - return MMSYSERR_NOTENABLED; - } - if (WOutDev[wDevID].lpQueueHdr != NULL) { - WARN(mciwave, "still buffers open !\n"); - /* Don't care. Who needs those buffers anyway */ - /*return WAVERR_STILLPLAYING; */ - } - close(WOutDev[wDevID].unixdev); - WOutDev[wDevID].unixdev = 0; - WOutDev[wDevID].bufsize = 0; - WOutDev[wDevID].lpQueueHdr = NULL; - if (WAVE_NotifyClient(wDevID, WOM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) { - WARN(mciwave, "can't notify client !\n"); - return MMSYSERR_INVALPARAM; - } - return MMSYSERR_NOERROR; + TRACE(mciwave,"(%u);\n", wDevID); + if (wDevID > MAX_WAVOUTDRV) return MMSYSERR_INVALPARAM; + if (WOutDev[wDevID].unixdev == 0) { + WARN(mciwave, "can't close !\n"); + return MMSYSERR_NOTENABLED; + } + if (WOutDev[wDevID].lpQueueHdr != NULL) { + WARN(mciwave, "still buffers open !\n"); + /* Don't care. Who needs those buffers anyway */ + /*return WAVERR_STILLPLAYING; */ + } + close(WOutDev[wDevID].unixdev); + WOutDev[wDevID].unixdev = 0; + WOutDev[wDevID].bufsize = 0; + WOutDev[wDevID].lpQueueHdr = NULL; + if (WAVE_NotifyClient(wDevID, WOM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) { + WARN(mciwave, "can't notify client !\n"); + return MMSYSERR_INVALPARAM; + } + return MMSYSERR_NOERROR; } /************************************************************************** @@ -959,52 +961,52 @@ static DWORD wodClose(WORD wDevID) */ static DWORD wodWrite(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize) { - int count; - LPSTR lpData; - LPWAVEHDR xwavehdr; - - TRACE(mciwave,"(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize); - if (WOutDev[wDevID].unixdev == 0) { + int count; + LPSTR lpData; + LPWAVEHDR xwavehdr; + + TRACE(mciwave,"(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize); + if (WOutDev[wDevID].unixdev == 0) { WARN(mciwave, "can't play !\n"); - return MMSYSERR_NOTENABLED; + return MMSYSERR_NOTENABLED; + } + if (lpWaveHdr->lpData == NULL) return WAVERR_UNPREPARED; + if (!(lpWaveHdr->dwFlags & WHDR_PREPARED)) return WAVERR_UNPREPARED; + if (lpWaveHdr->dwFlags & WHDR_INQUEUE) return WAVERR_STILLPLAYING; + lpWaveHdr->dwFlags &= ~WHDR_DONE; + lpWaveHdr->dwFlags |= WHDR_INQUEUE; + TRACE(mciwave, "dwBufferLength %lu !\n", + lpWaveHdr->dwBufferLength); + TRACE(mciwave, "WOutDev[%u].unixdev %u !\n", + wDevID, WOutDev[wDevID].unixdev); + lpData = lpWaveHdr->lpData; + count = write (WOutDev[wDevID].unixdev, lpData, lpWaveHdr->dwBufferLength); + TRACE(mciwave,"write returned count %u !\n",count); + if (count != lpWaveHdr->dwBufferLength) { + WARN(mciwave, " error writting !\n"); + return MMSYSERR_NOTENABLED; + } + WOutDev[wDevID].dwTotalPlayed += count; + lpWaveHdr->dwFlags &= ~WHDR_INQUEUE; + lpWaveHdr->dwFlags |= WHDR_DONE; + if ((DWORD)lpWaveHdr->lpData!=lpWaveHdr->reserved) { + /* FIXME: what if it expects it's OWN lpwavehdr back? */ + xwavehdr = SEGPTR_NEW(WAVEHDR); + memcpy(xwavehdr,lpWaveHdr,sizeof(WAVEHDR)); + xwavehdr->lpData = (LPBYTE)xwavehdr->reserved; + if (WAVE_NotifyClient(wDevID, WOM_DONE, (DWORD)SEGPTR_GET(xwavehdr), count) != MMSYSERR_NOERROR) { + WARN(mciwave, "can't notify client !\n"); + SEGPTR_FREE(xwavehdr); + return MMSYSERR_INVALPARAM; } - if (lpWaveHdr->lpData == NULL) return WAVERR_UNPREPARED; - if (!(lpWaveHdr->dwFlags & WHDR_PREPARED)) return WAVERR_UNPREPARED; - if (lpWaveHdr->dwFlags & WHDR_INQUEUE) return WAVERR_STILLPLAYING; - lpWaveHdr->dwFlags &= ~WHDR_DONE; - lpWaveHdr->dwFlags |= WHDR_INQUEUE; - TRACE(mciwave, "dwBufferLength %lu !\n", - lpWaveHdr->dwBufferLength); - TRACE(mciwave, "WOutDev[%u].unixdev %u !\n", - wDevID, WOutDev[wDevID].unixdev); - lpData = lpWaveHdr->lpData; - count = write (WOutDev[wDevID].unixdev, lpData, lpWaveHdr->dwBufferLength); - TRACE(mciwave,"write returned count %u !\n",count); - if (count != lpWaveHdr->dwBufferLength) { - WARN(mciwave, " error writting !\n"); - return MMSYSERR_NOTENABLED; + SEGPTR_FREE(xwavehdr); + } else { + if (WAVE_NotifyClient(wDevID, WOM_DONE, (DWORD)lpWaveHdr, count) != MMSYSERR_NOERROR) { + WARN(mciwave, "can't notify client !\n"); + return MMSYSERR_INVALPARAM; } - WOutDev[wDevID].dwTotalPlayed += count; - lpWaveHdr->dwFlags &= ~WHDR_INQUEUE; - lpWaveHdr->dwFlags |= WHDR_DONE; - if ((DWORD)lpWaveHdr->lpData!=lpWaveHdr->reserved) { - /* FIXME: what if it expects it's OWN lpwavehdr back? */ - xwavehdr = SEGPTR_NEW(WAVEHDR); - memcpy(xwavehdr,lpWaveHdr,sizeof(WAVEHDR)); - xwavehdr->lpData = (LPBYTE)xwavehdr->reserved; - if (WAVE_NotifyClient(wDevID, WOM_DONE, (DWORD)SEGPTR_GET(xwavehdr), count) != MMSYSERR_NOERROR) { - WARN(mciwave, "can't notify client !\n"); - SEGPTR_FREE(xwavehdr); - return MMSYSERR_INVALPARAM; - } - SEGPTR_FREE(xwavehdr); - } else { - if (WAVE_NotifyClient(wDevID, WOM_DONE, (DWORD)lpWaveHdr, count) != MMSYSERR_NOERROR) { - WARN(mciwave, "can't notify client !\n"); - return MMSYSERR_INVALPARAM; - } - } - return MMSYSERR_NOERROR; + } + return MMSYSERR_NOERROR; } /************************************************************************** @@ -1012,18 +1014,18 @@ static DWORD wodWrite(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize) */ static DWORD wodPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize) { - TRACE(mciwave, "(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize); - if (WOutDev[wDevID].unixdev == 0) { - WARN(mciwave, "can't prepare !\n"); - return MMSYSERR_NOTENABLED; - } - /* don't append to queue, wodWrite does that */ - WOutDev[wDevID].dwTotalPlayed = 0; - if (lpWaveHdr->dwFlags & WHDR_INQUEUE) - return WAVERR_STILLPLAYING; - lpWaveHdr->dwFlags |= WHDR_PREPARED; - lpWaveHdr->dwFlags &= ~WHDR_DONE; - return MMSYSERR_NOERROR; + TRACE(mciwave, "(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize); + if (WOutDev[wDevID].unixdev == 0) { + WARN(mciwave, "can't prepare !\n"); + return MMSYSERR_NOTENABLED; + } + /* don't append to queue, wodWrite does that */ + WOutDev[wDevID].dwTotalPlayed = 0; + if (lpWaveHdr->dwFlags & WHDR_INQUEUE) + return WAVERR_STILLPLAYING; + lpWaveHdr->dwFlags |= WHDR_PREPARED; + lpWaveHdr->dwFlags &= ~WHDR_DONE; + return MMSYSERR_NOERROR; } /************************************************************************** @@ -1031,18 +1033,18 @@ static DWORD wodPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize) */ static DWORD wodUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize) { - TRACE(mciwave, "(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize); - if (WOutDev[wDevID].unixdev == 0) { - WARN(mciwave, "can't unprepare !\n"); - return MMSYSERR_NOTENABLED; - } - if (lpWaveHdr->dwFlags & WHDR_INQUEUE) - return WAVERR_STILLPLAYING; - - lpWaveHdr->dwFlags &= ~WHDR_PREPARED; - lpWaveHdr->dwFlags |= WHDR_DONE; - TRACE(mciwave, "all headers unprepared !\n"); - return MMSYSERR_NOERROR; + TRACE(mciwave, "(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize); + if (WOutDev[wDevID].unixdev == 0) { + WARN(mciwave, "can't unprepare !\n"); + return MMSYSERR_NOTENABLED; + } + if (lpWaveHdr->dwFlags & WHDR_INQUEUE) + return WAVERR_STILLPLAYING; + + lpWaveHdr->dwFlags &= ~WHDR_PREPARED; + lpWaveHdr->dwFlags |= WHDR_DONE; + TRACE(mciwave, "all headers unprepared !\n"); + return MMSYSERR_NOERROR; } /************************************************************************** @@ -1050,20 +1052,20 @@ static DWORD wodUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize) */ static DWORD wodRestart(WORD wDevID) { - TRACE(mciwave,"(%u);\n", wDevID); - if (WOutDev[wDevID].unixdev == 0) { - WARN(mciwave, "can't restart !\n"); - return MMSYSERR_NOTENABLED; - } - /* FIXME: is NotifyClient with WOM_DONE right ? (Comet Busters 1.3.3 needs this notification) */ - /* FIXME: Myst crashes with this ... hmm -MM - if (WAVE_NotifyClient(wDevID, WOM_DONE, 0L, 0L) != MMSYSERR_NOERROR) { - WARN(mciwave, "can't notify client !\n"); - return MMSYSERR_INVALPARAM; - } - */ - - return MMSYSERR_NOERROR; + TRACE(mciwave,"(%u);\n", wDevID); + if (WOutDev[wDevID].unixdev == 0) { + WARN(mciwave, "can't restart !\n"); + return MMSYSERR_NOTENABLED; + } + /* FIXME: is NotifyClient with WOM_DONE right ? (Comet Busters 1.3.3 needs this notification) */ + /* FIXME: Myst crashes with this ... hmm -MM + if (WAVE_NotifyClient(wDevID, WOM_DONE, 0L, 0L) != MMSYSERR_NOERROR) { + WARN(mciwave, "can't notify client !\n"); + return MMSYSERR_INVALPARAM; + } + */ + + return MMSYSERR_NOERROR; } /************************************************************************** @@ -1071,12 +1073,12 @@ static DWORD wodRestart(WORD wDevID) */ static DWORD wodReset(WORD wDevID) { - TRACE(mciwave,"(%u);\n", wDevID); - if (WOutDev[wDevID].unixdev == 0) { - WARN(mciwave, "can't reset !\n"); - return MMSYSERR_NOTENABLED; - } - return MMSYSERR_NOERROR; + TRACE(mciwave,"(%u);\n", wDevID); + if (WOutDev[wDevID].unixdev == 0) { + WARN(mciwave, "can't reset !\n"); + return MMSYSERR_NOTENABLED; + } + return MMSYSERR_NOERROR; } @@ -1085,63 +1087,63 @@ static DWORD wodReset(WORD wDevID) */ static DWORD wodGetPosition(WORD wDevID, LPMMTIME16 lpTime, DWORD uSize) { - int time; - TRACE(mciwave,"(%u, %p, %lu);\n", wDevID, lpTime, uSize); - if (WOutDev[wDevID].unixdev == 0) { - WARN(mciwave, "can't get pos !\n"); - return MMSYSERR_NOTENABLED; - } - if (lpTime == NULL) return MMSYSERR_INVALPARAM; - TRACE(mciwave,"wType=%04X !\n", - lpTime->wType); - TRACE(mciwave,"wBitsPerSample=%u\n", - WOutDev[wDevID].Format.wBitsPerSample); - TRACE(mciwave,"nSamplesPerSec=%lu\n", - WOutDev[wDevID].Format.wf.nSamplesPerSec); - TRACE(mciwave,"nChannels=%u\n", - WOutDev[wDevID].Format.wf.nChannels); - TRACE(mciwave,"nAvgBytesPerSec=%lu\n", - WOutDev[wDevID].Format.wf.nAvgBytesPerSec); - switch(lpTime->wType) { - case TIME_BYTES: - lpTime->u.cb = WOutDev[wDevID].dwTotalPlayed; - TRACE(mciwave,"TIME_BYTES=%lu\n", lpTime->u.cb); - break; - case TIME_SAMPLES: - TRACE(mciwave,"dwTotalPlayed=%lu\n", - WOutDev[wDevID].dwTotalPlayed); - TRACE(mciwave,"wBitsPerSample=%u\n", - WOutDev[wDevID].Format.wBitsPerSample); - lpTime->u.sample = WOutDev[wDevID].dwTotalPlayed * 8 / - WOutDev[wDevID].Format.wBitsPerSample; - TRACE(mciwave,"TIME_SAMPLES=%lu\n", lpTime->u.sample); - break; - case TIME_SMPTE: - time = WOutDev[wDevID].dwTotalPlayed / - (WOutDev[wDevID].Format.wf.nAvgBytesPerSec / 1000); - lpTime->u.smpte.hour = time / 108000; - time -= lpTime->u.smpte.hour * 108000; - lpTime->u.smpte.min = time / 1800; - time -= lpTime->u.smpte.min * 1800; - lpTime->u.smpte.sec = time / 30; - time -= lpTime->u.smpte.sec * 30; - lpTime->u.smpte.frame = time; - lpTime->u.smpte.fps = 30; - TRACE(mciwave, - "wodGetPosition // TIME_SMPTE=%02u:%02u:%02u:%02u\n", - lpTime->u.smpte.hour, lpTime->u.smpte.min, - lpTime->u.smpte.sec, lpTime->u.smpte.frame); - break; - default: - FIXME(mciwave, "wodGetPosition() format %d not supported ! use TIME_MS !\n",lpTime->wType); - lpTime->wType = TIME_MS; - case TIME_MS: - lpTime->u.ms = WOutDev[wDevID].dwTotalPlayed / - (WOutDev[wDevID].Format.wf.nAvgBytesPerSec / 1000); - TRACE(mciwave,"wodGetPosition // TIME_MS=%lu\n", lpTime->u.ms); - break; - } - return MMSYSERR_NOERROR; + int time; + TRACE(mciwave,"(%u, %p, %lu);\n", wDevID, lpTime, uSize); + if (WOutDev[wDevID].unixdev == 0) { + WARN(mciwave, "can't get pos !\n"); + return MMSYSERR_NOTENABLED; + } + if (lpTime == NULL) return MMSYSERR_INVALPARAM; + TRACE(mciwave,"wType=%04X !\n", + lpTime->wType); + TRACE(mciwave,"wBitsPerSample=%u\n", + WOutDev[wDevID].Format.wBitsPerSample); + TRACE(mciwave,"nSamplesPerSec=%lu\n", + WOutDev[wDevID].Format.wf.nSamplesPerSec); + TRACE(mciwave,"nChannels=%u\n", + WOutDev[wDevID].Format.wf.nChannels); + TRACE(mciwave,"nAvgBytesPerSec=%lu\n", + WOutDev[wDevID].Format.wf.nAvgBytesPerSec); + switch(lpTime->wType) { + case TIME_BYTES: + lpTime->u.cb = WOutDev[wDevID].dwTotalPlayed; + TRACE(mciwave,"TIME_BYTES=%lu\n", lpTime->u.cb); + break; + case TIME_SAMPLES: + TRACE(mciwave,"dwTotalPlayed=%lu\n", + WOutDev[wDevID].dwTotalPlayed); + TRACE(mciwave,"wBitsPerSample=%u\n", + WOutDev[wDevID].Format.wBitsPerSample); + lpTime->u.sample = WOutDev[wDevID].dwTotalPlayed * 8 / + WOutDev[wDevID].Format.wBitsPerSample; + TRACE(mciwave,"TIME_SAMPLES=%lu\n", lpTime->u.sample); + break; + case TIME_SMPTE: + time = WOutDev[wDevID].dwTotalPlayed / + (WOutDev[wDevID].Format.wf.nAvgBytesPerSec / 1000); + lpTime->u.smpte.hour = time / 108000; + time -= lpTime->u.smpte.hour * 108000; + lpTime->u.smpte.min = time / 1800; + time -= lpTime->u.smpte.min * 1800; + lpTime->u.smpte.sec = time / 30; + time -= lpTime->u.smpte.sec * 30; + lpTime->u.smpte.frame = time; + lpTime->u.smpte.fps = 30; + TRACE(mciwave, + "wodGetPosition // TIME_SMPTE=%02u:%02u:%02u:%02u\n", + lpTime->u.smpte.hour, lpTime->u.smpte.min, + lpTime->u.smpte.sec, lpTime->u.smpte.frame); + break; + default: + FIXME(mciwave, "wodGetPosition() format %d not supported ! use TIME_MS !\n",lpTime->wType); + lpTime->wType = TIME_MS; + case TIME_MS: + lpTime->u.ms = WOutDev[wDevID].dwTotalPlayed / + (WOutDev[wDevID].Format.wf.nAvgBytesPerSec / 1000); + TRACE(mciwave,"wodGetPosition // TIME_MS=%lu\n", lpTime->u.ms); + break; + } + return MMSYSERR_NOERROR; } /************************************************************************** @@ -1149,24 +1151,24 @@ static DWORD wodGetPosition(WORD wDevID, LPMMTIME16 lpTime, DWORD uSize) */ static DWORD wodGetVolume(WORD wDevID, LPDWORD lpdwVol) { - int mixer; - int volume, left, right; - TRACE(mciwave,"(%u, %p);\n", wDevID, lpdwVol); - if (lpdwVol == NULL) return MMSYSERR_NOTENABLED; - if ((mixer = open(MIXER_DEV, O_RDONLY)) < 0) { - WARN(mciwave, "mixer device not available !\n"); - return MMSYSERR_NOTENABLED; - } - if (ioctl(mixer, SOUND_MIXER_READ_PCM, &volume) == -1) { - WARN(mciwave, "unable read mixer !\n"); - return MMSYSERR_NOTENABLED; - } - close(mixer); - left = volume & 0x7F; - right = (volume >> 8) & 0x7F; - TRACE(mciwave,"left=%d right=%d !\n", left, right); - *lpdwVol = MAKELONG(left << 9, right << 9); - return MMSYSERR_NOERROR; + int mixer; + int volume, left, right; + TRACE(mciwave,"(%u, %p);\n", wDevID, lpdwVol); + if (lpdwVol == NULL) return MMSYSERR_NOTENABLED; + if ((mixer = open(MIXER_DEV, O_RDONLY)) < 0) { + WARN(mciwave, "mixer device not available !\n"); + return MMSYSERR_NOTENABLED; + } + if (ioctl(mixer, SOUND_MIXER_READ_PCM, &volume) == -1) { + WARN(mciwave, "unable read mixer !\n"); + return MMSYSERR_NOTENABLED; + } + close(mixer); + left = volume & 0x7F; + right = (volume >> 8) & 0x7F; + TRACE(mciwave,"left=%d right=%d !\n", left, right); + *lpdwVol = MAKELONG(left << 9, right << 9); + return MMSYSERR_NOERROR; } @@ -1175,83 +1177,83 @@ static DWORD wodGetVolume(WORD wDevID, LPDWORD lpdwVol) */ static DWORD wodSetVolume(WORD wDevID, DWORD dwParam) { - int mixer; - int volume; - TRACE(mciwave,"(%u, %08lX);\n", wDevID, dwParam); - volume = (LOWORD(dwParam) >> 9 & 0x7F) + - ((HIWORD(dwParam) >> 9 & 0x7F) << 8); - if ((mixer = open(MIXER_DEV, O_WRONLY)) < 0) { - WARN(mciwave, "mixer device not available !\n"); - return MMSYSERR_NOTENABLED; - } + int mixer; + int volume; + TRACE(mciwave,"(%u, %08lX);\n", wDevID, dwParam); + volume = (LOWORD(dwParam) >> 9 & 0x7F) + + ((HIWORD(dwParam) >> 9 & 0x7F) << 8); + if ((mixer = open(MIXER_DEV, O_WRONLY)) < 0) { + WARN(mciwave, "mixer device not available !\n"); + return MMSYSERR_NOTENABLED; + } if (ioctl(mixer, SOUND_MIXER_WRITE_PCM, &volume) == -1) { - WARN(mciwave, "unable set mixer !\n"); - return MMSYSERR_NOTENABLED; - } - close(mixer); - return MMSYSERR_NOERROR; + WARN(mciwave, "unable set mixer !\n"); + return MMSYSERR_NOTENABLED; + } + close(mixer); + return MMSYSERR_NOERROR; } /************************************************************************** * wodMessage [sample driver] */ DWORD WINAPI wodMessage(WORD wDevID, WORD wMsg, DWORD dwUser, - DWORD dwParam1, DWORD dwParam2) + DWORD dwParam1, DWORD dwParam2) { - int audio; - TRACE(mciwave,"wodMessage(%u, %04X, %08lX, %08lX, %08lX);\n", - wDevID, wMsg, dwUser, dwParam1, dwParam2); - switch(wMsg) { - case WODM_OPEN: - return wodOpen(wDevID, (LPWAVEOPENDESC)dwParam1, dwParam2); - case WODM_CLOSE: - return wodClose(wDevID); - case WODM_WRITE: - return wodWrite(wDevID, (LPWAVEHDR)dwParam1, dwParam2); - case WODM_PAUSE: - return MMSYSERR_NOTSUPPORTED; - case WODM_STOP: - return MMSYSERR_NOTSUPPORTED; - case WODM_GETPOS: - return wodGetPosition(wDevID, (LPMMTIME16)dwParam1, dwParam2); - case WODM_BREAKLOOP: - return MMSYSERR_NOTSUPPORTED; - case WODM_PREPARE: - return wodPrepare(wDevID, (LPWAVEHDR)dwParam1, dwParam2); - case WODM_UNPREPARE: - return wodUnprepare(wDevID, (LPWAVEHDR)dwParam1, dwParam2); - case WODM_GETDEVCAPS: - return wodGetDevCaps(wDevID,(LPWAVEOUTCAPS16)dwParam1,dwParam2); - case WODM_GETNUMDEVS: - /* FIXME: For now, only one sound device (SOUND_DEV) is allowed */ - audio = open (SOUND_DEV, O_WRONLY, 0); - if (audio == -1) - if (errno == EBUSY) - return 1; - else - return 0; - close (audio); - return 1; - case WODM_GETPITCH: - return MMSYSERR_NOTSUPPORTED; - case WODM_SETPITCH: - return MMSYSERR_NOTSUPPORTED; - case WODM_GETPLAYBACKRATE: - return MMSYSERR_NOTSUPPORTED; - case WODM_SETPLAYBACKRATE: - return MMSYSERR_NOTSUPPORTED; - case WODM_GETVOLUME: - return wodGetVolume(wDevID, (LPDWORD)dwParam1); - case WODM_SETVOLUME: - return wodSetVolume(wDevID, dwParam1); - case WODM_RESTART: - return wodRestart(wDevID); - case WODM_RESET: - return wodReset(wDevID); - default: - WARN(mciwave,"unknown message !\n"); - } + int audio; + TRACE(mciwave,"wodMessage(%u, %04X, %08lX, %08lX, %08lX);\n", + wDevID, wMsg, dwUser, dwParam1, dwParam2); + switch(wMsg) { + case WODM_OPEN: + return wodOpen(wDevID, (LPWAVEOPENDESC)dwParam1, dwParam2); + case WODM_CLOSE: + return wodClose(wDevID); + case WODM_WRITE: + return wodWrite(wDevID, (LPWAVEHDR)dwParam1, dwParam2); + case WODM_PAUSE: return MMSYSERR_NOTSUPPORTED; + case WODM_STOP: + return MMSYSERR_NOTSUPPORTED; + case WODM_GETPOS: + return wodGetPosition(wDevID, (LPMMTIME16)dwParam1, dwParam2); + case WODM_BREAKLOOP: + return MMSYSERR_NOTSUPPORTED; + case WODM_PREPARE: + return wodPrepare(wDevID, (LPWAVEHDR)dwParam1, dwParam2); + case WODM_UNPREPARE: + return wodUnprepare(wDevID, (LPWAVEHDR)dwParam1, dwParam2); + case WODM_GETDEVCAPS: + return wodGetDevCaps(wDevID,(LPWAVEOUTCAPS16)dwParam1,dwParam2); + case WODM_GETNUMDEVS: + /* FIXME: For now, only one sound device (SOUND_DEV) is allowed */ + audio = open (SOUND_DEV, O_WRONLY, 0); + if (audio == -1) + if (errno == EBUSY) + return 1; + else + return 0; + close (audio); + return 1; + case WODM_GETPITCH: + return MMSYSERR_NOTSUPPORTED; + case WODM_SETPITCH: + return MMSYSERR_NOTSUPPORTED; + case WODM_GETPLAYBACKRATE: + return MMSYSERR_NOTSUPPORTED; + case WODM_SETPLAYBACKRATE: + return MMSYSERR_NOTSUPPORTED; + case WODM_GETVOLUME: + return wodGetVolume(wDevID, (LPDWORD)dwParam1); + case WODM_SETVOLUME: + return wodSetVolume(wDevID, dwParam1); + case WODM_RESTART: + return wodRestart(wDevID); + case WODM_RESET: + return wodReset(wDevID); + default: + WARN(mciwave,"unknown message !\n"); + } + return MMSYSERR_NOTSUPPORTED; } @@ -1262,61 +1264,61 @@ DWORD WINAPI wodMessage(WORD wDevID, WORD wMsg, DWORD dwUser, */ static DWORD widGetDevCaps(WORD wDevID, LPWAVEINCAPS16 lpCaps, DWORD dwSize) { - int audio,smplrate,samplesize=16,dsp_stereo=1,bytespersmpl; - - TRACE(mciwave, "(%u, %p, %lu);\n", wDevID, lpCaps, dwSize); - if (lpCaps == NULL) return MMSYSERR_NOTENABLED; - if (access(SOUND_DEV,0) != 0) return MMSYSERR_NOTENABLED; - audio = open (SOUND_DEV, O_RDONLY, 0); - if (audio == -1) return MMSYSERR_ALLOCATED ; + int audio,smplrate,samplesize=16,dsp_stereo=1,bytespersmpl; + + TRACE(mciwave, "(%u, %p, %lu);\n", wDevID, lpCaps, dwSize); + if (lpCaps == NULL) return MMSYSERR_NOTENABLED; + if (access(SOUND_DEV,0) != 0) return MMSYSERR_NOTENABLED; + audio = open (SOUND_DEV, O_RDONLY, 0); + if (audio == -1) return MMSYSERR_ALLOCATED ; #ifdef EMULATE_SB16 - lpCaps->wMid = 0x0002; - lpCaps->wPid = 0x0004; - strcpy(lpCaps->szPname, "SB16 Wave In"); + lpCaps->wMid = 0x0002; + lpCaps->wPid = 0x0004; + strcpy(lpCaps->szPname, "SB16 Wave In"); #else - lpCaps->wMid = 0x00FF; /* Manufac ID */ - lpCaps->wPid = 0x0001; /* Product ID */ - strcpy(lpCaps->szPname, "OpenSoundSystem WAVIN Driver"); + lpCaps->wMid = 0x00FF; /* Manufac ID */ + lpCaps->wPid = 0x0001; /* Product ID */ + strcpy(lpCaps->szPname, "OpenSoundSystem WAVIN Driver"); #endif - lpCaps->dwFormats = 0x00000000; - lpCaps->wChannels = (IOCTL(audio, SNDCTL_DSP_STEREO, dsp_stereo) != 0) ? 1 : 2; - bytespersmpl = (IOCTL(audio, SNDCTL_DSP_SAMPLESIZE, samplesize) != 0) ? 1 : 2; - smplrate = 44100; - if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) { - lpCaps->dwFormats |= WAVE_FORMAT_4M08; - if (lpCaps->wChannels > 1) - lpCaps->dwFormats |= WAVE_FORMAT_4S08; - if (bytespersmpl > 1) { - lpCaps->dwFormats |= WAVE_FORMAT_4M16; - if (lpCaps->wChannels > 1) - lpCaps->dwFormats |= WAVE_FORMAT_4S16; - } + lpCaps->dwFormats = 0x00000000; + lpCaps->wChannels = (IOCTL(audio, SNDCTL_DSP_STEREO, dsp_stereo) != 0) ? 1 : 2; + bytespersmpl = (IOCTL(audio, SNDCTL_DSP_SAMPLESIZE, samplesize) != 0) ? 1 : 2; + smplrate = 44100; + if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) { + lpCaps->dwFormats |= WAVE_FORMAT_4M08; + if (lpCaps->wChannels > 1) + lpCaps->dwFormats |= WAVE_FORMAT_4S08; + if (bytespersmpl > 1) { + lpCaps->dwFormats |= WAVE_FORMAT_4M16; + if (lpCaps->wChannels > 1) + lpCaps->dwFormats |= WAVE_FORMAT_4S16; } - smplrate = 22050; - if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) { - lpCaps->dwFormats |= WAVE_FORMAT_2M08; - if (lpCaps->wChannels > 1) - lpCaps->dwFormats |= WAVE_FORMAT_2S08; - if (bytespersmpl > 1) { - lpCaps->dwFormats |= WAVE_FORMAT_2M16; - if (lpCaps->wChannels > 1) - lpCaps->dwFormats |= WAVE_FORMAT_2S16; - } + } + smplrate = 22050; + if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) { + lpCaps->dwFormats |= WAVE_FORMAT_2M08; + if (lpCaps->wChannels > 1) + lpCaps->dwFormats |= WAVE_FORMAT_2S08; + if (bytespersmpl > 1) { + lpCaps->dwFormats |= WAVE_FORMAT_2M16; + if (lpCaps->wChannels > 1) + lpCaps->dwFormats |= WAVE_FORMAT_2S16; } - smplrate = 11025; - if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) { - lpCaps->dwFormats |= WAVE_FORMAT_1M08; - if (lpCaps->wChannels > 1) - lpCaps->dwFormats |= WAVE_FORMAT_1S08; - if (bytespersmpl > 1) { - lpCaps->dwFormats |= WAVE_FORMAT_1M16; - if (lpCaps->wChannels > 1) - lpCaps->dwFormats |= WAVE_FORMAT_1S16; - } + } + smplrate = 11025; + if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) { + lpCaps->dwFormats |= WAVE_FORMAT_1M08; + if (lpCaps->wChannels > 1) + lpCaps->dwFormats |= WAVE_FORMAT_1S08; + if (bytespersmpl > 1) { + lpCaps->dwFormats |= WAVE_FORMAT_1M16; + if (lpCaps->wChannels > 1) + lpCaps->dwFormats |= WAVE_FORMAT_1S16; } - close(audio); - TRACE(mciwave, "dwFormats = %08lX\n", lpCaps->dwFormats); - return MMSYSERR_NOERROR; + } + close(audio); + TRACE(mciwave, "dwFormats = %08lX\n", lpCaps->dwFormats); + return MMSYSERR_NOERROR; } @@ -1325,91 +1327,91 @@ static DWORD widGetDevCaps(WORD wDevID, LPWAVEINCAPS16 lpCaps, DWORD dwSize) */ static DWORD widOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags) { - int audio,abuf_size,smplrate,samplesize,dsp_stereo; - LPWAVEFORMAT lpFormat; - - TRACE(mciwave, "(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags); - if (lpDesc == NULL) { - WARN(mciwave, "Invalid Parameter !\n"); - return MMSYSERR_INVALPARAM; - } - if (wDevID >= MAX_WAVINDRV) { - TRACE(mciwave,"MAX_WAVINDRV reached !\n"); - return MMSYSERR_ALLOCATED; - } - WInDev[wDevID].unixdev = 0; - if (access(SOUND_DEV,0) != 0) return MMSYSERR_NOTENABLED; - audio = open (SOUND_DEV, O_RDONLY, 0); - if (audio == -1) { - WARN(mciwave,"can't open !\n"); - return MMSYSERR_ALLOCATED; - } - IOCTL(audio, SNDCTL_DSP_GETBLKSIZE, abuf_size); - if (abuf_size < 1024 || abuf_size > 65536) { - if (abuf_size == -1) - WARN(mciwave, "IOCTL can't 'SNDCTL_DSP_GETBLKSIZE' !\n"); - else - WARN(mciwave, "SNDCTL_DSP_GETBLKSIZE Invalid bufsize !\n"); - return MMSYSERR_NOTENABLED; - } - WInDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK); - switch(WInDev[wDevID].wFlags) { - case DCB_NULL: - TRACE(mciwave,"CALLBACK_NULL!\n"); - break; - case DCB_WINDOW: - TRACE(mciwave,"CALLBACK_WINDOW!\n"); - break; - case DCB_TASK: - TRACE(mciwave,"CALLBACK_TASK!\n"); - break; - case DCB_FUNCTION: - TRACE(mciwave,"CALLBACK_FUNCTION!\n"); - break; - } - if (WInDev[wDevID].lpQueueHdr) { - HeapFree(GetProcessHeap(),0,WInDev[wDevID].lpQueueHdr); - WInDev[wDevID].lpQueueHdr = NULL; - } - WInDev[wDevID].unixdev = audio; - WInDev[wDevID].bufsize = abuf_size; - WInDev[wDevID].dwTotalRecorded = 0; - memcpy(&WInDev[wDevID].waveDesc, lpDesc, sizeof(WAVEOPENDESC)); - lpFormat = (LPWAVEFORMAT) lpDesc->lpFormat; - if (lpFormat->wFormatTag != WAVE_FORMAT_PCM) { - WARN(mciwave, "Bad format %04X !\n", - lpFormat->wFormatTag); - return WAVERR_BADFORMAT; - } - memcpy(&WInDev[wDevID].Format, lpFormat, sizeof(PCMWAVEFORMAT)); - WInDev[wDevID].Format.wBitsPerSample = 8; /* <-------------- */ - if (WInDev[wDevID].Format.wf.nChannels == 0) return WAVERR_BADFORMAT; - if (WInDev[wDevID].Format.wf.nSamplesPerSec == 0) return WAVERR_BADFORMAT; - if (WInDev[wDevID].Format.wBitsPerSample == 0) { - WInDev[wDevID].Format.wBitsPerSample = 8 * - (WInDev[wDevID].Format.wf.nAvgBytesPerSec / - WInDev[wDevID].Format.wf.nSamplesPerSec) / - WInDev[wDevID].Format.wf.nChannels; - } - samplesize = WInDev[wDevID].Format.wBitsPerSample; - smplrate = WInDev[wDevID].Format.wf.nSamplesPerSec; - dsp_stereo = (WInDev[wDevID].Format.wf.nChannels > 1) ? TRUE : FALSE; - IOCTL(audio, SNDCTL_DSP_SPEED, smplrate); - IOCTL(audio, SNDCTL_DSP_SAMPLESIZE, samplesize); - IOCTL(audio, SNDCTL_DSP_STEREO, dsp_stereo); - TRACE(mciwave,"wBitsPerSample=%u !\n", - WInDev[wDevID].Format.wBitsPerSample); - TRACE(mciwave,"nSamplesPerSec=%lu !\n", - WInDev[wDevID].Format.wf.nSamplesPerSec); - TRACE(mciwave,"nChannels=%u !\n", - WInDev[wDevID].Format.wf.nChannels); - TRACE(mciwave,"nAvgBytesPerSec=%lu\n", - WInDev[wDevID].Format.wf.nAvgBytesPerSec); - if (WAVE_NotifyClient(wDevID, WIM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) { - WARN(mciwave,"can't notify client !\n"); - return MMSYSERR_INVALPARAM; - } - return MMSYSERR_NOERROR; + int audio,abuf_size,smplrate,samplesize,dsp_stereo; + LPWAVEFORMAT lpFormat; + + TRACE(mciwave, "(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags); + if (lpDesc == NULL) { + WARN(mciwave, "Invalid Parameter !\n"); + return MMSYSERR_INVALPARAM; + } + if (wDevID >= MAX_WAVINDRV) { + TRACE(mciwave,"MAX_WAVINDRV reached !\n"); + return MMSYSERR_ALLOCATED; + } + WInDev[wDevID].unixdev = 0; + if (access(SOUND_DEV,0) != 0) return MMSYSERR_NOTENABLED; + audio = open (SOUND_DEV, O_RDONLY, 0); + if (audio == -1) { + WARN(mciwave,"can't open !\n"); + return MMSYSERR_ALLOCATED; + } + IOCTL(audio, SNDCTL_DSP_GETBLKSIZE, abuf_size); + if (abuf_size < 1024 || abuf_size > 65536) { + if (abuf_size == -1) + WARN(mciwave, "IOCTL can't 'SNDCTL_DSP_GETBLKSIZE' !\n"); + else + WARN(mciwave, "SNDCTL_DSP_GETBLKSIZE Invalid bufsize !\n"); + return MMSYSERR_NOTENABLED; + } + WInDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK); + switch(WInDev[wDevID].wFlags) { + case DCB_NULL: + TRACE(mciwave,"CALLBACK_NULL!\n"); + break; + case DCB_WINDOW: + TRACE(mciwave,"CALLBACK_WINDOW!\n"); + break; + case DCB_TASK: + TRACE(mciwave,"CALLBACK_TASK!\n"); + break; + case DCB_FUNCTION: + TRACE(mciwave,"CALLBACK_FUNCTION!\n"); + break; + } + if (WInDev[wDevID].lpQueueHdr) { + HeapFree(GetProcessHeap(),0,WInDev[wDevID].lpQueueHdr); + WInDev[wDevID].lpQueueHdr = NULL; + } + WInDev[wDevID].unixdev = audio; + WInDev[wDevID].bufsize = abuf_size; + WInDev[wDevID].dwTotalRecorded = 0; + memcpy(&WInDev[wDevID].waveDesc, lpDesc, sizeof(WAVEOPENDESC)); + lpFormat = (LPWAVEFORMAT) lpDesc->lpFormat; + if (lpFormat->wFormatTag != WAVE_FORMAT_PCM) { + WARN(mciwave, "Bad format %04X !\n", + lpFormat->wFormatTag); + return WAVERR_BADFORMAT; + } + memcpy(&WInDev[wDevID].Format, lpFormat, sizeof(PCMWAVEFORMAT)); + WInDev[wDevID].Format.wBitsPerSample = 8; /* <-------------- */ + if (WInDev[wDevID].Format.wf.nChannels == 0) return WAVERR_BADFORMAT; + if (WInDev[wDevID].Format.wf.nSamplesPerSec == 0) return WAVERR_BADFORMAT; + if (WInDev[wDevID].Format.wBitsPerSample == 0) { + WInDev[wDevID].Format.wBitsPerSample = 8 * + (WInDev[wDevID].Format.wf.nAvgBytesPerSec / + WInDev[wDevID].Format.wf.nSamplesPerSec) / + WInDev[wDevID].Format.wf.nChannels; + } + samplesize = WInDev[wDevID].Format.wBitsPerSample; + smplrate = WInDev[wDevID].Format.wf.nSamplesPerSec; + dsp_stereo = (WInDev[wDevID].Format.wf.nChannels > 1) ? TRUE : FALSE; + IOCTL(audio, SNDCTL_DSP_SPEED, smplrate); + IOCTL(audio, SNDCTL_DSP_SAMPLESIZE, samplesize); + IOCTL(audio, SNDCTL_DSP_STEREO, dsp_stereo); + TRACE(mciwave,"wBitsPerSample=%u !\n", + WInDev[wDevID].Format.wBitsPerSample); + TRACE(mciwave,"nSamplesPerSec=%lu !\n", + WInDev[wDevID].Format.wf.nSamplesPerSec); + TRACE(mciwave,"nChannels=%u !\n", + WInDev[wDevID].Format.wf.nChannels); + TRACE(mciwave,"nAvgBytesPerSec=%lu\n", + WInDev[wDevID].Format.wf.nAvgBytesPerSec); + if (WAVE_NotifyClient(wDevID, WIM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) { + WARN(mciwave,"can't notify client !\n"); + return MMSYSERR_INVALPARAM; + } + return MMSYSERR_NOERROR; } /************************************************************************** @@ -1417,24 +1419,24 @@ static DWORD widOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags) */ static DWORD widClose(WORD wDevID) { - TRACE(mciwave,"(%u);\n", wDevID); - if (wDevID > MAX_WAVINDRV) return MMSYSERR_INVALPARAM; - if (WInDev[wDevID].unixdev == 0) { - WARN(mciwave,"can't close !\n"); - return MMSYSERR_NOTENABLED; - } - if (WInDev[wDevID].lpQueueHdr != NULL) { - WARN(mciwave, "still buffers open !\n"); - return WAVERR_STILLPLAYING; - } - close(WInDev[wDevID].unixdev); - WInDev[wDevID].unixdev = 0; - WInDev[wDevID].bufsize = 0; - if (WAVE_NotifyClient(wDevID, WIM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) { - WARN(mciwave,"can't notify client !\n"); - return MMSYSERR_INVALPARAM; - } - return MMSYSERR_NOERROR; + TRACE(mciwave,"(%u);\n", wDevID); + if (wDevID > MAX_WAVINDRV) return MMSYSERR_INVALPARAM; + if (WInDev[wDevID].unixdev == 0) { + WARN(mciwave,"can't close !\n"); + return MMSYSERR_NOTENABLED; + } + if (WInDev[wDevID].lpQueueHdr != NULL) { + WARN(mciwave, "still buffers open !\n"); + return WAVERR_STILLPLAYING; + } + close(WInDev[wDevID].unixdev); + WInDev[wDevID].unixdev = 0; + WInDev[wDevID].bufsize = 0; + if (WAVE_NotifyClient(wDevID, WIM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) { + WARN(mciwave,"can't notify client !\n"); + return MMSYSERR_INVALPARAM; + } + return MMSYSERR_NOERROR; } /************************************************************************** @@ -1442,40 +1444,40 @@ static DWORD widClose(WORD wDevID) */ static DWORD widAddBuffer(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize) { - int count = 1; - LPWAVEHDR lpWIHdr; - - TRACE(mciwave, "(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize); - if (WInDev[wDevID].unixdev == 0) { - WARN(mciwave,"can't do it !\n"); - return MMSYSERR_NOTENABLED; + int count = 1; + LPWAVEHDR lpWIHdr; + + TRACE(mciwave, "(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize); + if (WInDev[wDevID].unixdev == 0) { + WARN(mciwave,"can't do it !\n"); + return MMSYSERR_NOTENABLED; + } + if (!(lpWaveHdr->dwFlags & WHDR_PREPARED)) { + TRACE(mciwave, "never been prepared !\n"); + return WAVERR_UNPREPARED; + } + if (lpWaveHdr->dwFlags & WHDR_INQUEUE) { + TRACE(mciwave, "header already in use !\n"); + return WAVERR_STILLPLAYING; + } + lpWaveHdr->dwFlags |= WHDR_PREPARED; + lpWaveHdr->dwFlags |= WHDR_INQUEUE; + lpWaveHdr->dwFlags &= ~WHDR_DONE; + lpWaveHdr->dwBytesRecorded = 0; + if (WInDev[wDevID].lpQueueHdr == NULL) { + WInDev[wDevID].lpQueueHdr = lpWaveHdr; + } else { + lpWIHdr = WInDev[wDevID].lpQueueHdr; + while (lpWIHdr->lpNext != NULL) { + lpWIHdr = lpWIHdr->lpNext; + count++; } - if (!(lpWaveHdr->dwFlags & WHDR_PREPARED)) { - TRACE(mciwave, "never been prepared !\n"); - return WAVERR_UNPREPARED; - } - if (lpWaveHdr->dwFlags & WHDR_INQUEUE) { - TRACE(mciwave, "header already in use !\n"); - return WAVERR_STILLPLAYING; - } - lpWaveHdr->dwFlags |= WHDR_PREPARED; - lpWaveHdr->dwFlags |= WHDR_INQUEUE; - lpWaveHdr->dwFlags &= ~WHDR_DONE; - lpWaveHdr->dwBytesRecorded = 0; - if (WInDev[wDevID].lpQueueHdr == NULL) { - WInDev[wDevID].lpQueueHdr = lpWaveHdr; - } else { - lpWIHdr = WInDev[wDevID].lpQueueHdr; - while (lpWIHdr->lpNext != NULL) { - lpWIHdr = lpWIHdr->lpNext; - count++; - } - lpWIHdr->lpNext = lpWaveHdr; - lpWaveHdr->lpNext = NULL; - count++; - } - TRACE(mciwave, "buffer added ! (now %u in queue)\n", count); - return MMSYSERR_NOERROR; + lpWIHdr->lpNext = lpWaveHdr; + lpWaveHdr->lpNext = NULL; + count++; + } + TRACE(mciwave, "buffer added ! (now %u in queue)\n", count); + return MMSYSERR_NOERROR; } /************************************************************************** @@ -1483,19 +1485,19 @@ static DWORD widAddBuffer(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize) */ static DWORD widPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize) { - TRACE(mciwave, "(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize); - if (WInDev[wDevID].unixdev == 0) { - WARN(mciwave,"can't prepare !\n"); - return MMSYSERR_NOTENABLED; - } - if (lpWaveHdr->dwFlags & WHDR_INQUEUE) - return WAVERR_STILLPLAYING; - lpWaveHdr->dwFlags |= WHDR_PREPARED; - lpWaveHdr->dwFlags &= ~WHDR_INQUEUE; - lpWaveHdr->dwFlags &= ~WHDR_DONE; - lpWaveHdr->dwBytesRecorded = 0; - TRACE(mciwave,"header prepared !\n"); - return MMSYSERR_NOERROR; + TRACE(mciwave, "(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize); + if (WInDev[wDevID].unixdev == 0) { + WARN(mciwave,"can't prepare !\n"); + return MMSYSERR_NOTENABLED; + } + if (lpWaveHdr->dwFlags & WHDR_INQUEUE) + return WAVERR_STILLPLAYING; + lpWaveHdr->dwFlags |= WHDR_PREPARED; + lpWaveHdr->dwFlags &= ~WHDR_INQUEUE; + lpWaveHdr->dwFlags &= ~WHDR_DONE; + lpWaveHdr->dwBytesRecorded = 0; + TRACE(mciwave,"header prepared !\n"); + return MMSYSERR_NOERROR; } /************************************************************************** @@ -1503,17 +1505,17 @@ static DWORD widPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize) */ static DWORD widUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize) { - TRACE(mciwave, "(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize); - if (WInDev[wDevID].unixdev == 0) { - WARN(mciwave,"can't unprepare !\n"); - return MMSYSERR_NOTENABLED; - } - lpWaveHdr->dwFlags &= ~WHDR_PREPARED; - lpWaveHdr->dwFlags &= ~WHDR_INQUEUE; - lpWaveHdr->dwFlags |= WHDR_DONE; - - TRACE(mciwave, "all headers unprepared !\n"); - return MMSYSERR_NOERROR; + TRACE(mciwave, "(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize); + if (WInDev[wDevID].unixdev == 0) { + WARN(mciwave,"can't unprepare !\n"); + return MMSYSERR_NOTENABLED; + } + lpWaveHdr->dwFlags &= ~WHDR_PREPARED; + lpWaveHdr->dwFlags &= ~WHDR_INQUEUE; + lpWaveHdr->dwFlags |= WHDR_DONE; + + TRACE(mciwave, "all headers unprepared !\n"); + return MMSYSERR_NOERROR; } /************************************************************************** @@ -1521,53 +1523,53 @@ static DWORD widUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize) */ static DWORD widStart(WORD wDevID) { - int count = 1; - int bytesRead; - LPWAVEHDR lpWIHdr; - LPWAVEHDR *lpWaveHdr; - - TRACE(mciwave,"(%u);\n", wDevID); - if (WInDev[wDevID].unixdev == 0) { - WARN(mciwave, "can't start recording !\n"); - return MMSYSERR_NOTENABLED; - } - - lpWaveHdr = &(WInDev[wDevID].lpQueueHdr); - TRACE(mciwave,"lpWaveHdr = %08lx\n",(DWORD)lpWaveHdr); - if (!*lpWaveHdr || !(*lpWaveHdr)->lpData) { - TRACE(mciwave,"never been prepared !\n"); - return WAVERR_UNPREPARED; - } - - while(*lpWaveHdr != NULL) { - lpWIHdr = *lpWaveHdr; - TRACE(mciwave, "recording buf#%u=%p size=%lu \n", - count, lpWIHdr->lpData, lpWIHdr->dwBufferLength); - fflush(stddeb); - bytesRead = read (WInDev[wDevID].unixdev, - lpWIHdr->lpData, - lpWIHdr->dwBufferLength); - if (bytesRead==-1) - perror("read from audio device"); - TRACE(mciwave,"bytesread=%d (%ld)\n", - bytesRead,lpWIHdr->dwBufferLength); - lpWIHdr->dwBytesRecorded = bytesRead; - WInDev[wDevID].dwTotalRecorded += lpWIHdr->dwBytesRecorded; - lpWIHdr->dwFlags &= ~WHDR_INQUEUE; - lpWIHdr->dwFlags |= WHDR_DONE; - - /* FIXME: should pass segmented pointer here, do we need that?*/ - if (WAVE_NotifyClient(wDevID, WIM_DATA, (DWORD)lpWaveHdr, lpWIHdr->dwBytesRecorded) != MMSYSERR_NOERROR) { - WARN(mciwave, "can't notify client !\n"); - return MMSYSERR_INVALPARAM; - } - /* removes the current block from the queue */ - *lpWaveHdr = lpWIHdr->lpNext; - count++; - } - TRACE(mciwave,"end of recording !\n"); + int count = 1; + int bytesRead; + LPWAVEHDR lpWIHdr; + LPWAVEHDR *lpWaveHdr; + + TRACE(mciwave,"(%u);\n", wDevID); + if (WInDev[wDevID].unixdev == 0) { + WARN(mciwave, "can't start recording !\n"); + return MMSYSERR_NOTENABLED; + } + + lpWaveHdr = &(WInDev[wDevID].lpQueueHdr); + TRACE(mciwave,"lpWaveHdr = %08lx\n",(DWORD)lpWaveHdr); + if (!*lpWaveHdr || !(*lpWaveHdr)->lpData) { + TRACE(mciwave,"never been prepared !\n"); + return WAVERR_UNPREPARED; + } + + while(*lpWaveHdr != NULL) { + lpWIHdr = *lpWaveHdr; + TRACE(mciwave, "recording buf#%u=%p size=%lu \n", + count, lpWIHdr->lpData, lpWIHdr->dwBufferLength); fflush(stddeb); - return MMSYSERR_NOERROR; + bytesRead = read (WInDev[wDevID].unixdev, + lpWIHdr->lpData, + lpWIHdr->dwBufferLength); + if (bytesRead==-1) + perror("read from audio device"); + TRACE(mciwave,"bytesread=%d (%ld)\n", + bytesRead,lpWIHdr->dwBufferLength); + lpWIHdr->dwBytesRecorded = bytesRead; + WInDev[wDevID].dwTotalRecorded += lpWIHdr->dwBytesRecorded; + lpWIHdr->dwFlags &= ~WHDR_INQUEUE; + lpWIHdr->dwFlags |= WHDR_DONE; + + /* FIXME: should pass segmented pointer here, do we need that?*/ + if (WAVE_NotifyClient(wDevID, WIM_DATA, (DWORD)lpWaveHdr, lpWIHdr->dwBytesRecorded) != MMSYSERR_NOERROR) { + WARN(mciwave, "can't notify client !\n"); + return MMSYSERR_INVALPARAM; + } + /* removes the current block from the queue */ + *lpWaveHdr = lpWIHdr->lpNext; + count++; + } + TRACE(mciwave,"end of recording !\n"); + fflush(stddeb); + return MMSYSERR_NOERROR; } /************************************************************************** @@ -1575,12 +1577,12 @@ static DWORD widStart(WORD wDevID) */ static DWORD widStop(WORD wDevID) { - TRACE(mciwave,"(%u);\n", wDevID); - if (WInDev[wDevID].unixdev == 0) { - WARN(mciwave,"can't stop !\n"); - return MMSYSERR_NOTENABLED; - } - return MMSYSERR_NOERROR; + TRACE(mciwave,"(%u);\n", wDevID); + if (WInDev[wDevID].unixdev == 0) { + WARN(mciwave,"can't stop !\n"); + return MMSYSERR_NOTENABLED; + } + return MMSYSERR_NOERROR; } /************************************************************************** @@ -1588,12 +1590,12 @@ static DWORD widStop(WORD wDevID) */ static DWORD widReset(WORD wDevID) { - TRACE(mciwave,"(%u);\n", wDevID); - if (WInDev[wDevID].unixdev == 0) { - WARN(mciwave,"can't reset !\n"); - return MMSYSERR_NOTENABLED; - } - return MMSYSERR_NOERROR; + TRACE(mciwave,"(%u);\n", wDevID); + if (WInDev[wDevID].unixdev == 0) { + WARN(mciwave,"can't reset !\n"); + return MMSYSERR_NOTENABLED; + } + return MMSYSERR_NOERROR; } /************************************************************************** @@ -1601,208 +1603,223 @@ static DWORD widReset(WORD wDevID) */ static DWORD widGetPosition(WORD wDevID, LPMMTIME16 lpTime, DWORD uSize) { - int time; + int time; - TRACE(mciwave, "(%u, %p, %lu);\n", wDevID, lpTime, uSize); - if (WInDev[wDevID].unixdev == 0) { - WARN(mciwave,"can't get pos !\n"); - return MMSYSERR_NOTENABLED; - } - if (lpTime == NULL) return MMSYSERR_INVALPARAM; - TRACE(mciwave,"wType=%04X !\n", - lpTime->wType); - TRACE(mciwave,"wBitsPerSample=%u\n", - WInDev[wDevID].Format.wBitsPerSample); - TRACE(mciwave,"nSamplesPerSec=%lu\n", - WInDev[wDevID].Format.wf.nSamplesPerSec); - TRACE(mciwave,"nChannels=%u\n", - WInDev[wDevID].Format.wf.nChannels); - TRACE(mciwave,"nAvgBytesPerSec=%lu\n", - WInDev[wDevID].Format.wf.nAvgBytesPerSec); - fflush(stddeb); - switch(lpTime->wType) { - case TIME_BYTES: - lpTime->u.cb = WInDev[wDevID].dwTotalRecorded; - TRACE(mciwave,"TIME_BYTES=%lu\n", lpTime->u.cb); - break; - case TIME_SAMPLES: - lpTime->u.sample = WInDev[wDevID].dwTotalRecorded * 8 / - WInDev[wDevID].Format.wBitsPerSample; - TRACE(mciwave, "TIME_SAMPLES=%lu\n", lpTime->u.sample); - break; - case TIME_SMPTE: - time = WInDev[wDevID].dwTotalRecorded / - (WInDev[wDevID].Format.wf.nAvgBytesPerSec / 1000); - lpTime->u.smpte.hour = time / 108000; - time -= lpTime->u.smpte.hour * 108000; - lpTime->u.smpte.min = time / 1800; - time -= lpTime->u.smpte.min * 1800; - lpTime->u.smpte.sec = time / 30; - time -= lpTime->u.smpte.sec * 30; - lpTime->u.smpte.frame = time; - lpTime->u.smpte.fps = 30; - TRACE(mciwave,"TIME_SMPTE=%02u:%02u:%02u:%02u\n", - lpTime->u.smpte.hour, lpTime->u.smpte.min, - lpTime->u.smpte.sec, lpTime->u.smpte.frame); - break; - default: - FIXME(mciwave, "format not supported ! use TIME_MS !\n"); - lpTime->wType = TIME_MS; - case TIME_MS: - lpTime->u.ms = WInDev[wDevID].dwTotalRecorded / - (WInDev[wDevID].Format.wf.nAvgBytesPerSec / 1000); - TRACE(mciwave, "TIME_MS=%lu\n", lpTime->u.ms); - break; - } - return MMSYSERR_NOERROR; + TRACE(mciwave, "(%u, %p, %lu);\n", wDevID, lpTime, uSize); + if (WInDev[wDevID].unixdev == 0) { + WARN(mciwave,"can't get pos !\n"); + return MMSYSERR_NOTENABLED; + } + if (lpTime == NULL) return MMSYSERR_INVALPARAM; + TRACE(mciwave,"wType=%04X !\n", + lpTime->wType); + TRACE(mciwave,"wBitsPerSample=%u\n", + WInDev[wDevID].Format.wBitsPerSample); + TRACE(mciwave,"nSamplesPerSec=%lu\n", + WInDev[wDevID].Format.wf.nSamplesPerSec); + TRACE(mciwave,"nChannels=%u\n", + WInDev[wDevID].Format.wf.nChannels); + TRACE(mciwave,"nAvgBytesPerSec=%lu\n", + WInDev[wDevID].Format.wf.nAvgBytesPerSec); + fflush(stddeb); + switch(lpTime->wType) { + case TIME_BYTES: + lpTime->u.cb = WInDev[wDevID].dwTotalRecorded; + TRACE(mciwave,"TIME_BYTES=%lu\n", lpTime->u.cb); + break; + case TIME_SAMPLES: + lpTime->u.sample = WInDev[wDevID].dwTotalRecorded * 8 / + WInDev[wDevID].Format.wBitsPerSample; + TRACE(mciwave, "TIME_SAMPLES=%lu\n", lpTime->u.sample); + break; + case TIME_SMPTE: + time = WInDev[wDevID].dwTotalRecorded / + (WInDev[wDevID].Format.wf.nAvgBytesPerSec / 1000); + lpTime->u.smpte.hour = time / 108000; + time -= lpTime->u.smpte.hour * 108000; + lpTime->u.smpte.min = time / 1800; + time -= lpTime->u.smpte.min * 1800; + lpTime->u.smpte.sec = time / 30; + time -= lpTime->u.smpte.sec * 30; + lpTime->u.smpte.frame = time; + lpTime->u.smpte.fps = 30; + TRACE(mciwave,"TIME_SMPTE=%02u:%02u:%02u:%02u\n", + lpTime->u.smpte.hour, lpTime->u.smpte.min, + lpTime->u.smpte.sec, lpTime->u.smpte.frame); + break; + default: + FIXME(mciwave, "format not supported ! use TIME_MS !\n"); + lpTime->wType = TIME_MS; + case TIME_MS: + lpTime->u.ms = WInDev[wDevID].dwTotalRecorded / + (WInDev[wDevID].Format.wf.nAvgBytesPerSec / 1000); + TRACE(mciwave, "TIME_MS=%lu\n", lpTime->u.ms); + break; + } + return MMSYSERR_NOERROR; } /************************************************************************** * widMessage [sample driver] */ DWORD WINAPI widMessage(WORD wDevID, WORD wMsg, DWORD dwUser, - DWORD dwParam1, DWORD dwParam2) + DWORD dwParam1, DWORD dwParam2) { - int audio; - TRACE(mciwave,"widMessage(%u, %04X, %08lX, %08lX, %08lX);\n", - wDevID, wMsg, dwUser, dwParam1, dwParam2); - switch(wMsg) { - case WIDM_OPEN: - return widOpen(wDevID, (LPWAVEOPENDESC)dwParam1, dwParam2); - case WIDM_CLOSE: - return widClose(wDevID); - case WIDM_ADDBUFFER: - return widAddBuffer(wDevID, (LPWAVEHDR)dwParam1, dwParam2); - case WIDM_PREPARE: - return widPrepare(wDevID, (LPWAVEHDR)dwParam1, dwParam2); - case WIDM_UNPREPARE: - return widUnprepare(wDevID, (LPWAVEHDR)dwParam1, dwParam2); - case WIDM_GETDEVCAPS: - return widGetDevCaps(wDevID, (LPWAVEINCAPS16)dwParam1,dwParam2); - case WIDM_GETNUMDEVS: - /* FIXME: For now, only one sound device (SOUND_DEV) is allowed */ - audio = open (SOUND_DEV, O_RDONLY, 0); - if (audio == -1) + int audio; + TRACE(mciwave,"widMessage(%u, %04X, %08lX, %08lX, %08lX);\n", + wDevID, wMsg, dwUser, dwParam1, dwParam2); + switch(wMsg) { + case WIDM_OPEN: + return widOpen(wDevID, (LPWAVEOPENDESC)dwParam1, dwParam2); + case WIDM_CLOSE: + return widClose(wDevID); + case WIDM_ADDBUFFER: + return widAddBuffer(wDevID, (LPWAVEHDR)dwParam1, dwParam2); + case WIDM_PREPARE: + return widPrepare(wDevID, (LPWAVEHDR)dwParam1, dwParam2); + case WIDM_UNPREPARE: + return widUnprepare(wDevID, (LPWAVEHDR)dwParam1, dwParam2); + case WIDM_GETDEVCAPS: + return widGetDevCaps(wDevID, (LPWAVEINCAPS16)dwParam1,dwParam2); + case WIDM_GETNUMDEVS: + /* FIXME: For now, only one sound device (SOUND_DEV) is allowed */ + audio = open (SOUND_DEV, O_RDONLY, 0); + if (audio == -1) if (errno == EBUSY) - return 1; - else - return 0; - close (audio); return 1; - case WIDM_GETPOS: - return widGetPosition(wDevID, (LPMMTIME16)dwParam1, dwParam2); - case WIDM_RESET: - return widReset(wDevID); - case WIDM_START: - return widStart(wDevID); - case WIDM_PAUSE: - return widStop(wDevID); - case WIDM_STOP: - return widStop(wDevID); - default: - WARN(mciwave,"unknown message !\n"); - } - return MMSYSERR_NOTSUPPORTED; + else + return 0; + close (audio); + return 1; + case WIDM_GETPOS: + return widGetPosition(wDevID, (LPMMTIME16)dwParam1, dwParam2); + case WIDM_RESET: + return widReset(wDevID); + case WIDM_START: + return widStart(wDevID); + case WIDM_PAUSE: + return widStop(wDevID); + case WIDM_STOP: + return widStop(wDevID); + default: + WARN(mciwave,"unknown message !\n"); + } + return MMSYSERR_NOTSUPPORTED; } /************************************************************************** - * AUDIO_DriverProc [sample driver] + * WAVE_DriverProc16 [sample driver] */ -LONG WAVE_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, - DWORD dwParam1, DWORD dwParam2) +LONG WAVE_DriverProc16(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, + DWORD dwParam1, DWORD dwParam2) { - TRACE(mciwave,"(%08lX, %04X, %04X, %08lX, %08lX)\n", - dwDevID, hDriv, wMsg, dwParam1, dwParam2); - switch(wMsg) { - case DRV_LOAD: - return 1; - case DRV_FREE: - return 1; - case DRV_OPEN: - return 1; - case DRV_CLOSE: - return 1; - case DRV_ENABLE: - return 1; - case DRV_DISABLE: - return 1; - case DRV_QUERYCONFIGURE: - return 1; - case DRV_CONFIGURE: - MessageBox16(0, "Sample MultiMedia Linux Driver !", - "MMLinux Driver", MB_OK); - return 1; - case DRV_INSTALL: - return DRVCNF_RESTART; - case DRV_REMOVE: - return DRVCNF_RESTART; - case MCI_OPEN_DRIVER: - case MCI_OPEN: - return WAVE_mciOpen(dwDevID, dwParam1, (LPMCI_WAVE_OPEN_PARMS16)PTR_SEG_TO_LIN(dwParam2)); - case MCI_CUE: - return WAVE_mciCue(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_CLOSE_DRIVER: - case MCI_CLOSE: - return WAVE_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_PLAY: - return WAVE_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_RECORD: - return WAVE_mciRecord(dwDevID, dwParam1, (LPMCI_RECORD_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_STOP: - return WAVE_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_SET: - return WAVE_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_PAUSE: - return WAVE_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_RESUME: - return WAVE_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_STATUS: - return WAVE_mciStatus(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_GETDEVCAPS: - return WAVE_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_INFO: - return WAVE_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS16)PTR_SEG_TO_LIN(dwParam2)); - - case MCI_LOAD: - return MMSYSERR_NOTSUPPORTED; - case MCI_SAVE: - return MMSYSERR_NOTSUPPORTED; - case MCI_SEEK: - return MMSYSERR_NOTSUPPORTED; - case MCI_FREEZE: - return MMSYSERR_NOTSUPPORTED; - case MCI_PUT: - return MMSYSERR_NOTSUPPORTED; - case MCI_REALIZE: - return MMSYSERR_NOTSUPPORTED; - case MCI_UNFREEZE: - return MMSYSERR_NOTSUPPORTED; - case MCI_UPDATE: - return MMSYSERR_NOTSUPPORTED; - case MCI_WHERE: - return MMSYSERR_NOTSUPPORTED; - case MCI_WINDOW: - return MMSYSERR_NOTSUPPORTED; - case MCI_STEP: - return MMSYSERR_NOTSUPPORTED; - case MCI_SPIN: - return MMSYSERR_NOTSUPPORTED; - case MCI_ESCAPE: - return MMSYSERR_NOTSUPPORTED; - case MCI_COPY: - return MMSYSERR_NOTSUPPORTED; - case MCI_CUT: - return MMSYSERR_NOTSUPPORTED; - case MCI_DELETE: - return MMSYSERR_NOTSUPPORTED; - case MCI_PASTE: - return MMSYSERR_NOTSUPPORTED; - - default: - return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2); - } - return MMSYSERR_NOTENABLED; + TRACE(mciwave,"(%08lX, %04X, %04X, %08lX, %08lX)\n", + dwDevID, hDriv, wMsg, dwParam1, dwParam2); + switch(wMsg) { + case DRV_LOAD: return 1; + case DRV_FREE: return 1; + case DRV_OPEN: return 1; + case DRV_CLOSE: return 1; + case DRV_ENABLE: return 1; + case DRV_DISABLE: return 1; + case DRV_QUERYCONFIGURE: return 1; + case DRV_CONFIGURE: MessageBox16(0, "Sample MultiMedia Linux Driver !", "MMLinux Driver", MB_OK); return 1; + case DRV_INSTALL: return DRVCNF_RESTART; + case DRV_REMOVE: return DRVCNF_RESTART; + case MCI_OPEN_DRIVER: + case MCI_OPEN: return WAVE_mciOpen(dwDevID, dwParam1, PTR_SEG_TO_LIN(dwParam2), FALSE); + case MCI_CUE: return WAVE_mciCue(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_CLOSE_DRIVER: + case MCI_CLOSE: return WAVE_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_PLAY: return WAVE_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_RECORD: return WAVE_mciRecord(dwDevID, dwParam1, (LPMCI_RECORD_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_STOP: return WAVE_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_SET: return WAVE_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_PAUSE: return WAVE_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_RESUME: return WAVE_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_STATUS: return WAVE_mciStatus(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_GETDEVCAPS: return WAVE_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_INFO: return WAVE_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS16)PTR_SEG_TO_LIN(dwParam2)); + case MCI_LOAD: return MMSYSERR_NOTSUPPORTED; + case MCI_SAVE: return MMSYSERR_NOTSUPPORTED; + case MCI_SEEK: return MMSYSERR_NOTSUPPORTED; + case MCI_FREEZE: return MMSYSERR_NOTSUPPORTED; + case MCI_PUT: return MMSYSERR_NOTSUPPORTED; + case MCI_REALIZE: return MMSYSERR_NOTSUPPORTED; + case MCI_UNFREEZE: return MMSYSERR_NOTSUPPORTED; + case MCI_UPDATE: return MMSYSERR_NOTSUPPORTED; + case MCI_WHERE: return MMSYSERR_NOTSUPPORTED; + case MCI_WINDOW: return MMSYSERR_NOTSUPPORTED; + case MCI_STEP: return MMSYSERR_NOTSUPPORTED; + case MCI_SPIN: return MMSYSERR_NOTSUPPORTED; + case MCI_ESCAPE: return MMSYSERR_NOTSUPPORTED; + case MCI_COPY: return MMSYSERR_NOTSUPPORTED; + case MCI_CUT: return MMSYSERR_NOTSUPPORTED; + case MCI_DELETE: return MMSYSERR_NOTSUPPORTED; + case MCI_PASTE: return MMSYSERR_NOTSUPPORTED; + + default: + return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2); + } + return MMSYSERR_NOTENABLED; +} +/************************************************************************** + * WAVE_DriverProc32 [sample driver] + */ +LONG WAVE_DriverProc32(DWORD dwDevID, HDRVR16 hDriv, DWORD wMsg, + DWORD dwParam1, DWORD dwParam2) +{ + TRACE(mciwave,"(%08lX, %04X, %08lX, %08lX, %08lX)\n", + dwDevID, hDriv, wMsg, dwParam1, dwParam2); + switch(wMsg) { + case DRV_LOAD: return 1; + case DRV_FREE: return 1; + case DRV_OPEN: return 1; + case DRV_CLOSE: return 1; + case DRV_ENABLE: return 1; + case DRV_DISABLE: return 1; + case DRV_QUERYCONFIGURE: return 1; + case DRV_CONFIGURE: MessageBox16(0, "Sample MultiMedia Linux Driver !", "MMLinux Driver", MB_OK); return 1; + case DRV_INSTALL: return DRVCNF_RESTART; + case DRV_REMOVE: return DRVCNF_RESTART; + case MCI_OPEN_DRIVER: + case MCI_OPEN: return WAVE_mciOpen(dwDevID, dwParam1, (LPMCI_WAVE_OPEN_PARMS32A)dwParam2, TRUE); + case MCI_CUE: return WAVE_mciCue(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case MCI_CLOSE_DRIVER: + case MCI_CLOSE: return WAVE_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case MCI_PLAY: return WAVE_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)dwParam2); + case MCI_RECORD: return WAVE_mciRecord(dwDevID, dwParam1, (LPMCI_RECORD_PARMS)dwParam2); + case MCI_STOP: return WAVE_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case MCI_SET: return WAVE_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)dwParam2); + case MCI_PAUSE: return WAVE_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case MCI_RESUME: return WAVE_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case MCI_STATUS: return WAVE_mciStatus(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)dwParam2); + case MCI_GETDEVCAPS: return WAVE_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)dwParam2); + case MCI_INFO: return WAVE_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS16)dwParam2); + case MCI_LOAD: return MMSYSERR_NOTSUPPORTED; + case MCI_SAVE: return MMSYSERR_NOTSUPPORTED; + case MCI_SEEK: return MMSYSERR_NOTSUPPORTED; + case MCI_FREEZE: return MMSYSERR_NOTSUPPORTED; + case MCI_PUT: return MMSYSERR_NOTSUPPORTED; + case MCI_REALIZE: return MMSYSERR_NOTSUPPORTED; + case MCI_UNFREEZE: return MMSYSERR_NOTSUPPORTED; + case MCI_UPDATE: return MMSYSERR_NOTSUPPORTED; + case MCI_WHERE: return MMSYSERR_NOTSUPPORTED; + case MCI_WINDOW: return MMSYSERR_NOTSUPPORTED; + case MCI_STEP: return MMSYSERR_NOTSUPPORTED; + case MCI_SPIN: return MMSYSERR_NOTSUPPORTED; + case MCI_ESCAPE: return MMSYSERR_NOTSUPPORTED; + case MCI_COPY: return MMSYSERR_NOTSUPPORTED; + case MCI_CUT: return MMSYSERR_NOTSUPPORTED; + case MCI_DELETE: return MMSYSERR_NOTSUPPORTED; + case MCI_PASTE: return MMSYSERR_NOTSUPPORTED; + + default: + FIXME(mciwave, "is probably wrong\n"); + return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2); + } + return MMSYSERR_NOTENABLED; } #else /* !HAVE_OSS */ @@ -1811,30 +1828,39 @@ LONG WAVE_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, * wodMessage [sample driver] */ DWORD WINAPI wodMessage(WORD wDevID, WORD wMsg, DWORD dwUser, - DWORD dwParam1, DWORD dwParam2) + DWORD dwParam1, DWORD dwParam2) { - FIXME(mciwave,"(%u, %04X, %08lX, %08lX, %08lX):stub\n", - wDevID, wMsg, dwUser, dwParam1, dwParam2); - return MMSYSERR_NOTENABLED; + FIXME(mciwave,"(%u, %04X, %08lX, %08lX, %08lX):stub\n", + wDevID, wMsg, dwUser, dwParam1, dwParam2); + return MMSYSERR_NOTENABLED; } /************************************************************************** * widMessage [sample driver] */ DWORD WINAPI widMessage(WORD wDevID, WORD wMsg, DWORD dwUser, - DWORD dwParam1, DWORD dwParam2) + DWORD dwParam1, DWORD dwParam2) { - FIXME(mciwave,"(%u, %04X, %08lX, %08lX, %08lX):stub\n", - wDevID, wMsg, dwUser, dwParam1, dwParam2); - return MMSYSERR_NOTENABLED; + FIXME(mciwave,"(%u, %04X, %08lX, %08lX, %08lX):stub\n", + wDevID, wMsg, dwUser, dwParam1, dwParam2); + return MMSYSERR_NOTENABLED; } /************************************************************************** - * AUDIO_DriverProc [sample driver] + * WAVE_DriverProc16 [sample driver] */ -LONG WAVE_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, - DWORD dwParam1, DWORD dwParam2) +LONG WAVE_DriverProc16(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, + DWORD dwParam1, DWORD dwParam2) { - return MMSYSERR_NOTENABLED; + return MMSYSERR_NOTENABLED; +} + +/************************************************************************** + * WAVE_DriverProc32 [sample driver] + */ +LONG WAVE_DriverProc32(DWORD dwDevID, HDRVR16 hDriv, DWORD wMsg, + DWORD dwParam1, DWORD dwParam2) +{ + return MMSYSERR_NOTENABLED; } #endif /* HAVE_OSS */ diff --git a/multimedia/init.c b/multimedia/init.c index 78e81997e32..e9c780d0247 100644 --- a/multimedia/init.c +++ b/multimedia/init.c @@ -59,12 +59,12 @@ int unixToWindowsDeviceType(int type) #endif /************************************************************************** - * MultimediaInit [internal] + * MULTIMEDIA_MidiInit [internal] * * Initializes the MIDI devices information variables * */ -BOOL32 MULTIMEDIA_Init(void) +BOOL32 MULTIMEDIA_MidiInit(void) { #ifdef HAVE_OSS int i, status, numsynthdevs = 255, nummididevs = 255; @@ -90,7 +90,7 @@ BOOL32 MULTIMEDIA_Init(void) close(fd); return TRUE; } - + if (numsynthdevs > MAX_MIDIOUTDRV) { ERR(midi, "MAX_MIDIOUTDRV (%d) was enough for the number of devices (%d). " "Some FM devices will not be available.\n",MAX_MIDIOUTDRV,numsynthdevs); @@ -247,3 +247,39 @@ BOOL32 MULTIMEDIA_Init(void) return TRUE; } + +extern int mciInstalledCount; +extern int mciInstalledListLen; +extern LPSTR lpmciInstallNames; + +BOOL32 MULTIMEDIA_MciInit(void) +{ + int len; + LPSTR ptr; + LPSTR SysFile = "SYSTEM.INI"; + + mciInstalledCount = 0; + mciInstalledListLen = 0; + ptr = lpmciInstallNames = xmalloc(2048); + /* FIXME: should do also some registry diving here */ + GetPrivateProfileString32A("mci", NULL, "", lpmciInstallNames, 2000, SysFile); + while (strlen(ptr) > 0) { + TRACE(mci, "---> '%s' \n", ptr); + len = strlen(ptr) + 1; + ptr += len; + mciInstalledListLen += len; + mciInstalledCount++; + } + return TRUE; +} + +/************************************************************************** + * MULTIMEDIA_Init [internal] + * + * Initializes the multimedia information variables + * + */ +BOOL32 MULTIMEDIA_Init(void) +{ + return MULTIMEDIA_MidiInit() && MULTIMEDIA_MciInit(); +} diff --git a/multimedia/mcianim.c b/multimedia/mcianim.c index ed74df64b2c..76dff47b003 100644 --- a/multimedia/mcianim.c +++ b/multimedia/mcianim.c @@ -1,3 +1,4 @@ +/* -*- tab-width: 8; c-basic-offset: 4 -*- */ /* * Sample MCI ANIMATION Wine Driver for Linux * @@ -22,581 +23,588 @@ #define SECONDS_PERMIN 60 typedef struct { - int nUseCount; /* Incremented for each shared open */ - BOOL16 fShareable; /* TRUE if first open was shareable */ - WORD wNotifyDeviceID; /* MCI device ID with a pending notification */ - HANDLE16 hCallback; /* Callback handle for pending notification */ + int nUseCount; /* Incremented for each shared open */ + BOOL16 fShareable; /* TRUE if first open was shareable */ + WORD wNotifyDeviceID; /* MCI device ID with a pending notification */ + HANDLE16 hCallback; /* Callback handle for pending notification */ MCI_OPEN_PARMS16 openParms; - DWORD dwTimeFormat; + DWORD dwTimeFormat; int mode; - UINT16 nCurTrack; - DWORD dwCurFrame; - UINT16 nTracks; - DWORD dwTotalLen; - LPDWORD lpdwTrackLen; - LPDWORD lpdwTrackPos; -} LINUX_ANIM; + UINT16 nCurTrack; + DWORD dwCurFrame; + UINT16 nTracks; + DWORD dwTotalLen; + LPDWORD lpdwTrackLen; + LPDWORD lpdwTrackPos; +} WINE_ANIM; -static LINUX_ANIM AnimDev[MAX_ANIMDRV]; +static WINE_ANIM AnimDev[MAX_ANIMDRV]; /*-----------------------------------------------------------------------*/ /************************************************************************** -* ANIM_mciOpen [internal] -*/ -static DWORD ANIM_mciOpen(UINT16 wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS16 lpParms) + * ANIM_mciOpen [internal] + */ +static DWORD ANIM_mciOpen(UINT16 wDevID, DWORD dwFlags, void* lp, BOOL32 is32) { - LPSTR lpstrElementName; - char str[128]; + DWORD dwDeviceID; - TRACE(mcianim,"(%04X, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - if (AnimDev[wDevID].nUseCount > 0) { - /* The driver already open on this channel */ - /* If the driver was opened shareable before and this open specifies */ - /* shareable then increment the use count */ - if (AnimDev[wDevID].fShareable && (dwFlags & MCI_OPEN_SHAREABLE)) - ++AnimDev[wDevID].nUseCount; - else - return MCIERR_MUST_USE_SHAREABLE; - } - else { - AnimDev[wDevID].nUseCount = 1; - AnimDev[wDevID].fShareable = dwFlags & MCI_OPEN_SHAREABLE; - } - TRACE(mcianim,"wDevID=%04X\n", wDevID); - lpParms->wDeviceID = wDevID; - TRACE(mcianim,"lpParms->wDevID=%04X\n", lpParms->wDeviceID); + TRACE(mcianim,"(%04X, %08lX, %p);\n", wDevID, dwFlags, lp); + if (lp == NULL) return MCIERR_INTERNAL; + if (AnimDev[wDevID].nUseCount > 0) { + /* The driver already open on this channel */ + /* If the driver was opened shareable before and this open specifies */ + /* shareable then increment the use count */ + if (AnimDev[wDevID].fShareable && (dwFlags & MCI_OPEN_SHAREABLE)) + ++AnimDev[wDevID].nUseCount; + else + return MCIERR_MUST_USE_SHAREABLE; + } + else { + AnimDev[wDevID].nUseCount = 1; + AnimDev[wDevID].fShareable = dwFlags & MCI_OPEN_SHAREABLE; + } + + if (is32) dwDeviceID = ((LPMCI_OPEN_PARMS32A)lp)->wDeviceID; + else dwDeviceID = ((LPMCI_OPEN_PARMS16)lp)->wDeviceID; + + TRACE(mcianim,"wDevID=%04X\n", wDevID); + /* FIXME this is not consistent with other implementations */ + if (is32) ((LPMCI_OPEN_PARMS32A)lp)->wDeviceID = wDevID; + else ((LPMCI_OPEN_PARMS16)lp)->wDeviceID = wDevID; + + /*TRACE(mcianim,"lpParms->wDevID=%04X\n", lpParms->wDeviceID);*/ if (dwFlags & MCI_OPEN_ELEMENT) { - lpstrElementName = (LPSTR)PTR_SEG_TO_LIN(lpParms->lpstrElementName); - TRACE(mcianim,"MCI_OPEN_ELEMENT '%s' !\n", - lpstrElementName); - if (strlen(lpstrElementName) > 0) { - strcpy(str, lpstrElementName); - CharUpper32A(str); - } - } - memcpy(&AnimDev[wDevID].openParms, lpParms, sizeof(MCI_OPEN_PARMS16)); - AnimDev[wDevID].wNotifyDeviceID = lpParms->wDeviceID; - AnimDev[wDevID].mode = 0; - AnimDev[wDevID].dwTimeFormat = MCI_FORMAT_TMSF; - AnimDev[wDevID].nCurTrack = 0; - AnimDev[wDevID].nTracks = 0; - AnimDev[wDevID].dwTotalLen = 0; - AnimDev[wDevID].lpdwTrackLen = NULL; - AnimDev[wDevID].lpdwTrackPos = NULL; -/* - Moved to mmsystem.c mciOpen routine + LPSTR lpstrElementName; - if (dwFlags & MCI_NOTIFY) { - TRACE(mcianim, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", - lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), - AnimDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); - } -*/ - return 0; + if (is32) lpstrElementName = ((LPMCI_OPEN_PARMS32A)lp)->lpstrElementName; + else lpstrElementName = (LPSTR)PTR_SEG_TO_LIN(((LPMCI_OPEN_PARMS16)lp)->lpstrElementName); + + TRACE(mcianim,"MCI_OPEN_ELEMENT '%s' !\n", lpstrElementName); + if (lpstrElementName && strlen(lpstrElementName) > 0) { + } + FIXME(mcianim, "element is not opened\n"); + } + memcpy(&AnimDev[wDevID].openParms, lp, sizeof(MCI_OPEN_PARMS16)); + AnimDev[wDevID].wNotifyDeviceID = dwDeviceID; + AnimDev[wDevID].mode = 0; + AnimDev[wDevID].dwTimeFormat = MCI_FORMAT_TMSF; + AnimDev[wDevID].nCurTrack = 0; + AnimDev[wDevID].nTracks = 0; + AnimDev[wDevID].dwTotalLen = 0; + AnimDev[wDevID].lpdwTrackLen = NULL; + AnimDev[wDevID].lpdwTrackPos = NULL; + /* + Moved to mmsystem.c mciOpen routine + + if (dwFlags & MCI_NOTIFY) { + TRACE(mcianim, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", + lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + AnimDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); + } + */ + return 0; } /************************************************************************** -* ANIM_mciClose [internal] -*/ + * ANIM_mciClose [internal] + */ static DWORD ANIM_mciClose(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms) { - TRACE(mcianim,"(%u, %08lX, %p);\n", - wDevID, dwParam, lpParms); - if (AnimDev[wDevID].lpdwTrackLen != NULL) free(AnimDev[wDevID].lpdwTrackLen); - if (AnimDev[wDevID].lpdwTrackPos != NULL) free(AnimDev[wDevID].lpdwTrackPos); - return 0; + TRACE(mcianim,"(%u, %08lX, %p);\n", + wDevID, dwParam, lpParms); + if (AnimDev[wDevID].lpdwTrackLen != NULL) free(AnimDev[wDevID].lpdwTrackLen); + if (AnimDev[wDevID].lpdwTrackPos != NULL) free(AnimDev[wDevID].lpdwTrackPos); + return 0; } /************************************************************************** -* ANIM_mciGetDevCaps [internal] -*/ + * ANIM_mciGetDevCaps [internal] + */ static DWORD ANIM_mciGetDevCaps(UINT16 wDevID, DWORD dwFlags, - LPMCI_GETDEVCAPS_PARMS lpParms) + LPMCI_GETDEVCAPS_PARMS lpParms) { - TRACE(mcianim,"(%u, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - if (dwFlags & MCI_GETDEVCAPS_ITEM) { - TRACE(mcianim, "MCI_GETDEVCAPS_ITEM dwItem=%08lX;\n", - lpParms->dwItem); - switch(lpParms->dwItem) { - case MCI_GETDEVCAPS_CAN_RECORD: - lpParms->dwReturn = FALSE; - break; - case MCI_GETDEVCAPS_HAS_AUDIO: - lpParms->dwReturn = FALSE; - break; - case MCI_GETDEVCAPS_HAS_VIDEO: - lpParms->dwReturn = FALSE; - break; - case MCI_GETDEVCAPS_DEVICE_TYPE: - lpParms->dwReturn = MCI_DEVTYPE_ANIMATION; - break; - case MCI_GETDEVCAPS_USES_FILES: - lpParms->dwReturn = TRUE; - break; - case MCI_GETDEVCAPS_COMPOUND_DEVICE: - lpParms->dwReturn = FALSE; - break; - case MCI_GETDEVCAPS_CAN_EJECT: - lpParms->dwReturn = TRUE; - break; - case MCI_GETDEVCAPS_CAN_PLAY: - lpParms->dwReturn = FALSE; - break; - case MCI_GETDEVCAPS_CAN_SAVE: - lpParms->dwReturn = FALSE; - break; - default: - return MCIERR_UNRECOGNIZED_COMMAND; - } - } - TRACE(mcianim, "lpParms->dwReturn=%08lX;\n", - lpParms->dwReturn); - return 0; + TRACE(mcianim,"(%u, %08lX, %p);\n", + wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + if (dwFlags & MCI_GETDEVCAPS_ITEM) { + TRACE(mcianim, "MCI_GETDEVCAPS_ITEM dwItem=%08lX;\n", + lpParms->dwItem); + switch(lpParms->dwItem) { + case MCI_GETDEVCAPS_CAN_RECORD: + lpParms->dwReturn = FALSE; + break; + case MCI_GETDEVCAPS_HAS_AUDIO: + lpParms->dwReturn = FALSE; + break; + case MCI_GETDEVCAPS_HAS_VIDEO: + lpParms->dwReturn = FALSE; + break; + case MCI_GETDEVCAPS_DEVICE_TYPE: + lpParms->dwReturn = MCI_DEVTYPE_ANIMATION; + break; + case MCI_GETDEVCAPS_USES_FILES: + lpParms->dwReturn = TRUE; + break; + case MCI_GETDEVCAPS_COMPOUND_DEVICE: + lpParms->dwReturn = FALSE; + break; + case MCI_GETDEVCAPS_CAN_EJECT: + lpParms->dwReturn = TRUE; + break; + case MCI_GETDEVCAPS_CAN_PLAY: + lpParms->dwReturn = FALSE; + break; + case MCI_GETDEVCAPS_CAN_SAVE: + lpParms->dwReturn = FALSE; + break; + default: + return MCIERR_UNRECOGNIZED_COMMAND; + } + } + TRACE(mcianim, "lpParms->dwReturn=%08lX;\n", + lpParms->dwReturn); + return 0; } /************************************************************************** -* ANIM_CalcTime [internal] -*/ + * ANIM_CalcTime [internal] + */ static DWORD ANIM_CalcTime(UINT16 wDevID, DWORD dwFormatType, DWORD dwFrame) { - DWORD dwTime = 0; - UINT16 wTrack; - UINT16 wMinutes; - UINT16 wSeconds; - UINT16 wFrames; - TRACE(mcianim,"(%u, %08lX, %lu);\n", - wDevID, dwFormatType, dwFrame); + DWORD dwTime = 0; + UINT16 wTrack; + UINT16 wMinutes; + UINT16 wSeconds; + UINT16 wFrames; + TRACE(mcianim,"(%u, %08lX, %lu);\n", + wDevID, dwFormatType, dwFrame); - switch (dwFormatType) { - case MCI_FORMAT_MILLISECONDS: - dwTime = dwFrame / ANIMFRAMES_PERSEC * 1000; - TRACE(mcianim, "MILLISECONDS %lu\n", dwTime); - break; - case MCI_FORMAT_MSF: - wMinutes = dwFrame / ANIMFRAMES_PERMIN; - wSeconds = (dwFrame - ANIMFRAMES_PERMIN * wMinutes) / ANIMFRAMES_PERSEC; - wFrames = dwFrame - ANIMFRAMES_PERMIN * wMinutes - - ANIMFRAMES_PERSEC * wSeconds; - dwTime = MCI_MAKE_MSF(wMinutes, wSeconds, wFrames); - TRACE(mcianim,"MSF %02u:%02u:%02u -> dwTime=%lu\n", - wMinutes, wSeconds, wFrames, dwTime); - break; - default: - /* unknown format ! force TMSF ! ... */ - dwFormatType = MCI_FORMAT_TMSF; - case MCI_FORMAT_TMSF: - for (wTrack = 0; wTrack < AnimDev[wDevID].nTracks; wTrack++) { -/* dwTime += AnimDev[wDevID].lpdwTrackLen[wTrack - 1]; - TRACE(mcianim, "Adding trk#%u curpos=%u \n", dwTime); - if (dwTime >= dwFrame) break; */ - if (AnimDev[wDevID].lpdwTrackPos[wTrack - 1] >= dwFrame) break; - } - wMinutes = dwFrame / ANIMFRAMES_PERMIN; - wSeconds = (dwFrame - ANIMFRAMES_PERMIN * wMinutes) / ANIMFRAMES_PERSEC; - wFrames = dwFrame - ANIMFRAMES_PERMIN * wMinutes - - ANIMFRAMES_PERSEC * wSeconds; - dwTime = MCI_MAKE_TMSF(wTrack, wMinutes, wSeconds, wFrames); - TRACE(mcianim, "%02u-%02u:%02u:%02u\n", - wTrack, wMinutes, wSeconds, wFrames); - break; - } - return dwTime; + switch (dwFormatType) { + case MCI_FORMAT_MILLISECONDS: + dwTime = dwFrame / ANIMFRAMES_PERSEC * 1000; + TRACE(mcianim, "MILLISECONDS %lu\n", dwTime); + break; + case MCI_FORMAT_MSF: + wMinutes = dwFrame / ANIMFRAMES_PERMIN; + wSeconds = (dwFrame - ANIMFRAMES_PERMIN * wMinutes) / ANIMFRAMES_PERSEC; + wFrames = dwFrame - ANIMFRAMES_PERMIN * wMinutes - + ANIMFRAMES_PERSEC * wSeconds; + dwTime = MCI_MAKE_MSF(wMinutes, wSeconds, wFrames); + TRACE(mcianim,"MSF %02u:%02u:%02u -> dwTime=%lu\n", + wMinutes, wSeconds, wFrames, dwTime); + break; + default: + /* unknown format ! force TMSF ! ... */ + dwFormatType = MCI_FORMAT_TMSF; + case MCI_FORMAT_TMSF: + for (wTrack = 0; wTrack < AnimDev[wDevID].nTracks; wTrack++) { + /* dwTime += AnimDev[wDevID].lpdwTrackLen[wTrack - 1]; + TRACE(mcianim, "Adding trk#%u curpos=%u \n", dwTime); + if (dwTime >= dwFrame) break; */ + if (AnimDev[wDevID].lpdwTrackPos[wTrack - 1] >= dwFrame) break; + } + wMinutes = dwFrame / ANIMFRAMES_PERMIN; + wSeconds = (dwFrame - ANIMFRAMES_PERMIN * wMinutes) / ANIMFRAMES_PERSEC; + wFrames = dwFrame - ANIMFRAMES_PERMIN * wMinutes - + ANIMFRAMES_PERSEC * wSeconds; + dwTime = MCI_MAKE_TMSF(wTrack, wMinutes, wSeconds, wFrames); + TRACE(mcianim, "%02u-%02u:%02u:%02u\n", + wTrack, wMinutes, wSeconds, wFrames); + break; + } + return dwTime; } /************************************************************************** -* ANIM_CalcFrame [internal] -*/ + * ANIM_CalcFrame [internal] + */ static DWORD ANIM_CalcFrame(UINT16 wDevID, DWORD dwFormatType, DWORD dwTime) { - DWORD dwFrame = 0; - UINT16 wTrack; - TRACE(mcianim,"(%u, %08lX, %lu);\n", - wDevID, dwFormatType, dwTime); - - switch (dwFormatType) { - case MCI_FORMAT_MILLISECONDS: - dwFrame = dwTime * ANIMFRAMES_PERSEC / 1000; - TRACE(mcianim, "MILLISECONDS %lu\n", dwFrame); - break; - case MCI_FORMAT_MSF: - TRACE(mcianim, "MSF %02u:%02u:%02u\n", - MCI_MSF_MINUTE(dwTime), MCI_MSF_SECOND(dwTime), - MCI_MSF_FRAME(dwTime)); - dwFrame += ANIMFRAMES_PERMIN * MCI_MSF_MINUTE(dwTime); - dwFrame += ANIMFRAMES_PERSEC * MCI_MSF_SECOND(dwTime); - dwFrame += MCI_MSF_FRAME(dwTime); - break; - default: - /* unknown format ! force TMSF ! ... */ - dwFormatType = MCI_FORMAT_TMSF; - case MCI_FORMAT_TMSF: - wTrack = MCI_TMSF_TRACK(dwTime); - TRACE(mcianim, "TMSF %02u-%02u:%02u:%02u\n", - MCI_TMSF_TRACK(dwTime), MCI_TMSF_MINUTE(dwTime), - MCI_TMSF_SECOND(dwTime), MCI_TMSF_FRAME(dwTime)); - TRACE(mcianim, "TMSF trackpos[%u]=%lu\n", - wTrack, AnimDev[wDevID].lpdwTrackPos[wTrack - 1]); - dwFrame = AnimDev[wDevID].lpdwTrackPos[wTrack - 1]; - dwFrame += ANIMFRAMES_PERMIN * MCI_TMSF_MINUTE(dwTime); - dwFrame += ANIMFRAMES_PERSEC * MCI_TMSF_SECOND(dwTime); - dwFrame += MCI_TMSF_FRAME(dwTime); - break; - } - return dwFrame; + DWORD dwFrame = 0; + UINT16 wTrack; + TRACE(mcianim,"(%u, %08lX, %lu);\n", + wDevID, dwFormatType, dwTime); + + switch (dwFormatType) { + case MCI_FORMAT_MILLISECONDS: + dwFrame = dwTime * ANIMFRAMES_PERSEC / 1000; + TRACE(mcianim, "MILLISECONDS %lu\n", dwFrame); + break; + case MCI_FORMAT_MSF: + TRACE(mcianim, "MSF %02u:%02u:%02u\n", + MCI_MSF_MINUTE(dwTime), MCI_MSF_SECOND(dwTime), + MCI_MSF_FRAME(dwTime)); + dwFrame += ANIMFRAMES_PERMIN * MCI_MSF_MINUTE(dwTime); + dwFrame += ANIMFRAMES_PERSEC * MCI_MSF_SECOND(dwTime); + dwFrame += MCI_MSF_FRAME(dwTime); + break; + default: + /* unknown format ! force TMSF ! ... */ + dwFormatType = MCI_FORMAT_TMSF; + case MCI_FORMAT_TMSF: + wTrack = MCI_TMSF_TRACK(dwTime); + TRACE(mcianim, "TMSF %02u-%02u:%02u:%02u\n", + MCI_TMSF_TRACK(dwTime), MCI_TMSF_MINUTE(dwTime), + MCI_TMSF_SECOND(dwTime), MCI_TMSF_FRAME(dwTime)); + TRACE(mcianim, "TMSF trackpos[%u]=%lu\n", + wTrack, AnimDev[wDevID].lpdwTrackPos[wTrack - 1]); + dwFrame = AnimDev[wDevID].lpdwTrackPos[wTrack - 1]; + dwFrame += ANIMFRAMES_PERMIN * MCI_TMSF_MINUTE(dwTime); + dwFrame += ANIMFRAMES_PERSEC * MCI_TMSF_SECOND(dwTime); + dwFrame += MCI_TMSF_FRAME(dwTime); + break; + } + return dwFrame; } /************************************************************************** -* ANIM_mciInfo [internal] -*/ + * ANIM_mciInfo [internal] + */ static DWORD ANIM_mciInfo(UINT16 wDevID, DWORD dwFlags, LPMCI_INFO_PARMS16 lpParms) { - TRACE(mcianim,"(%u, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - lpParms->lpstrReturn = NULL; - switch(dwFlags) { - case MCI_INFO_PRODUCT: - lpParms->lpstrReturn = "Linux ANIMATION 0.5"; - break; - case MCI_INFO_FILE: - lpParms->lpstrReturn = - (LPSTR)AnimDev[wDevID].openParms.lpstrElementName; - break; - case MCI_ANIM_INFO_TEXT: - lpParms->lpstrReturn = "Animation Window"; - break; - default: - return MCIERR_UNRECOGNIZED_COMMAND; - } - if (lpParms->lpstrReturn != NULL) - lpParms->dwRetSize = strlen(lpParms->lpstrReturn); - else - lpParms->dwRetSize = 0; - return 0; + TRACE(mcianim,"(%u, %08lX, %p);\n", + wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + lpParms->lpstrReturn = NULL; + switch(dwFlags) { + case MCI_INFO_PRODUCT: + lpParms->lpstrReturn = "Linux ANIMATION 0.5"; + break; + case MCI_INFO_FILE: + lpParms->lpstrReturn = + (LPSTR)AnimDev[wDevID].openParms.lpstrElementName; + break; + case MCI_ANIM_INFO_TEXT: + lpParms->lpstrReturn = "Animation Window"; + break; + default: + return MCIERR_UNRECOGNIZED_COMMAND; + } + if (lpParms->lpstrReturn != NULL) + lpParms->dwRetSize = strlen(lpParms->lpstrReturn); + else + lpParms->dwRetSize = 0; + return 0; } /************************************************************************** -* ANIM_mciStatus [internal] -*/ + * ANIM_mciStatus [internal] + */ static DWORD ANIM_mciStatus(UINT16 wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms) { - TRACE(mcianim,"(%u, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - if (dwFlags & MCI_NOTIFY) { - TRACE(mcianim, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", - lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + TRACE(mcianim,"(%u, %08lX, %p);\n", + wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + if (dwFlags & MCI_NOTIFY) { + TRACE(mcianim, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", + lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), AnimDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); - } - if (dwFlags & MCI_STATUS_ITEM) { - switch(lpParms->dwItem) { - case MCI_STATUS_CURRENT_TRACK: - lpParms->dwReturn = AnimDev[wDevID].nCurTrack; - TRACE(mcianim,"CURRENT_TRACK=%lu!\n", lpParms->dwReturn); - return 0; - case MCI_STATUS_LENGTH: - if (dwFlags & MCI_TRACK) { - TRACE(mcianim,"MCI_TRACK #%lu LENGTH=??? !\n", - lpParms->dwTrack); - if (lpParms->dwTrack > AnimDev[wDevID].nTracks) - return MCIERR_OUTOFRANGE; - lpParms->dwReturn = AnimDev[wDevID].lpdwTrackLen[lpParms->dwTrack]; - } - else - lpParms->dwReturn = AnimDev[wDevID].dwTotalLen; - lpParms->dwReturn = ANIM_CalcTime(wDevID, - AnimDev[wDevID].dwTimeFormat, lpParms->dwReturn); - TRACE(mcianim,"LENGTH=%lu !\n", lpParms->dwReturn); - return 0; - case MCI_STATUS_MODE: - lpParms->dwReturn = AnimDev[wDevID].mode; - TRACE(mcianim,"MCI_STATUS_MODE=%08lX !\n", - lpParms->dwReturn); - return 0; - case MCI_STATUS_MEDIA_PRESENT: - lpParms->dwReturn = TRUE; - TRACE(mcianim,"MCI_STATUS_MEDIA_PRESENT !\n"); - return 0; - case MCI_STATUS_NUMBER_OF_TRACKS: - lpParms->dwReturn = 1; - TRACE(mcianim,"MCI_STATUS_NUMBER_OF_TRACKS = %lu !\n", - lpParms->dwReturn); - if (lpParms->dwReturn == (WORD)-1) return MCIERR_INTERNAL; - return 0; - case MCI_STATUS_POSITION: - lpParms->dwReturn = AnimDev[wDevID].dwCurFrame; - if (dwFlags & MCI_STATUS_START) { - lpParms->dwReturn = 0; - TRACE(mcianim,"get MCI_STATUS_START !\n"); - } - if (dwFlags & MCI_TRACK) { - if (lpParms->dwTrack > AnimDev[wDevID].nTracks) - return MCIERR_OUTOFRANGE; - lpParms->dwReturn = AnimDev[wDevID].lpdwTrackPos[lpParms->dwTrack - 1]; - TRACE(mcianim,"get MCI_TRACK #%lu !\n", lpParms->dwTrack); - } - lpParms->dwReturn = ANIM_CalcTime(wDevID, - AnimDev[wDevID].dwTimeFormat, lpParms->dwReturn); - TRACE(mcianim,"MCI_STATUS_POSITION=%08lX !\n", - lpParms->dwReturn); - return 0; - case MCI_STATUS_READY: - TRACE(mcianim,"MCI_STATUS_READY !\n"); - lpParms->dwReturn = TRUE; - return 0; - case MCI_STATUS_TIME_FORMAT: - TRACE(mcianim,"MCI_STATUS_TIME_FORMAT !\n"); - lpParms->dwReturn = MCI_FORMAT_MILLISECONDS; - return 0; - default: - WARN(mcianim,"Unknown command %08lX !\n", lpParms->dwItem); - return MCIERR_UNRECOGNIZED_COMMAND; - } - } + } + if (dwFlags & MCI_STATUS_ITEM) { + switch(lpParms->dwItem) { + case MCI_STATUS_CURRENT_TRACK: + lpParms->dwReturn = AnimDev[wDevID].nCurTrack; + TRACE(mcianim,"CURRENT_TRACK=%lu!\n", lpParms->dwReturn); + return 0; + case MCI_STATUS_LENGTH: + if (dwFlags & MCI_TRACK) { + TRACE(mcianim,"MCI_TRACK #%lu LENGTH=??? !\n", + lpParms->dwTrack); + if (lpParms->dwTrack > AnimDev[wDevID].nTracks) + return MCIERR_OUTOFRANGE; + lpParms->dwReturn = AnimDev[wDevID].lpdwTrackLen[lpParms->dwTrack]; + } + else + lpParms->dwReturn = AnimDev[wDevID].dwTotalLen; + lpParms->dwReturn = ANIM_CalcTime(wDevID, + AnimDev[wDevID].dwTimeFormat, lpParms->dwReturn); + TRACE(mcianim,"LENGTH=%lu !\n", lpParms->dwReturn); + return 0; + case MCI_STATUS_MODE: + lpParms->dwReturn = AnimDev[wDevID].mode; + TRACE(mcianim,"MCI_STATUS_MODE=%08lX !\n", + lpParms->dwReturn); + return 0; + case MCI_STATUS_MEDIA_PRESENT: + lpParms->dwReturn = TRUE; + TRACE(mcianim,"MCI_STATUS_MEDIA_PRESENT !\n"); + return 0; + case MCI_STATUS_NUMBER_OF_TRACKS: + lpParms->dwReturn = 1; + TRACE(mcianim,"MCI_STATUS_NUMBER_OF_TRACKS = %lu !\n", + lpParms->dwReturn); + if (lpParms->dwReturn == (WORD)-1) return MCIERR_INTERNAL; + return 0; + case MCI_STATUS_POSITION: + lpParms->dwReturn = AnimDev[wDevID].dwCurFrame; + if (dwFlags & MCI_STATUS_START) { + lpParms->dwReturn = 0; + TRACE(mcianim,"get MCI_STATUS_START !\n"); + } + if (dwFlags & MCI_TRACK) { + if (lpParms->dwTrack > AnimDev[wDevID].nTracks) + return MCIERR_OUTOFRANGE; + lpParms->dwReturn = AnimDev[wDevID].lpdwTrackPos[lpParms->dwTrack - 1]; + TRACE(mcianim,"get MCI_TRACK #%lu !\n", lpParms->dwTrack); + } + lpParms->dwReturn = ANIM_CalcTime(wDevID, + AnimDev[wDevID].dwTimeFormat, lpParms->dwReturn); + TRACE(mcianim,"MCI_STATUS_POSITION=%08lX !\n", + lpParms->dwReturn); + return 0; + case MCI_STATUS_READY: + TRACE(mcianim,"MCI_STATUS_READY !\n"); + lpParms->dwReturn = TRUE; + return 0; + case MCI_STATUS_TIME_FORMAT: + TRACE(mcianim,"MCI_STATUS_TIME_FORMAT !\n"); + lpParms->dwReturn = MCI_FORMAT_MILLISECONDS; + return 0; + default: + WARN(mcianim,"Unknown command %08lX !\n", lpParms->dwItem); + return MCIERR_UNRECOGNIZED_COMMAND; + } + } WARN(mcianim,"Not MCI_STATUS_ITEM !\n"); - return 0; + return 0; } /************************************************************************** -* ANIM_mciPlay [internal] -*/ + * ANIM_mciPlay [internal] + */ static DWORD ANIM_mciPlay(UINT16 wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms) { - int start, end; - TRACE(mcianim,"(%u, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - start = 0; end = AnimDev[wDevID].dwTotalLen; - AnimDev[wDevID].nCurTrack = 1; - if (dwFlags & MCI_FROM) { - start = ANIM_CalcFrame(wDevID, - AnimDev[wDevID].dwTimeFormat, lpParms->dwFrom); + int start, end; + TRACE(mcianim,"(%u, %08lX, %p);\n", + wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + start = 0; end = AnimDev[wDevID].dwTotalLen; + AnimDev[wDevID].nCurTrack = 1; + if (dwFlags & MCI_FROM) { + start = ANIM_CalcFrame(wDevID, + AnimDev[wDevID].dwTimeFormat, lpParms->dwFrom); TRACE(mcianim,"MCI_FROM=%08lX -> %u \n", - lpParms->dwFrom, start); - } - if (dwFlags & MCI_TO) { - end = ANIM_CalcFrame(wDevID, - AnimDev[wDevID].dwTimeFormat, lpParms->dwTo); - TRACE(mcianim, "MCI_TO=%08lX -> %u \n", - lpParms->dwTo, end); - } - AnimDev[wDevID].mode = MCI_MODE_PLAY; - if (dwFlags & MCI_NOTIFY) { - TRACE(mcianim, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", - lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + lpParms->dwFrom, start); + } + if (dwFlags & MCI_TO) { + end = ANIM_CalcFrame(wDevID, + AnimDev[wDevID].dwTimeFormat, lpParms->dwTo); + TRACE(mcianim, "MCI_TO=%08lX -> %u \n", + lpParms->dwTo, end); + } + AnimDev[wDevID].mode = MCI_MODE_PLAY; + if (dwFlags & MCI_NOTIFY) { + TRACE(mcianim, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", + lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), AnimDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); - } - return 0; + } + return 0; } /************************************************************************** -* ANIM_mciStop [internal] -*/ + * ANIM_mciStop [internal] + */ static DWORD ANIM_mciStop(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms) { - TRACE(mcianim,"(%u, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - AnimDev[wDevID].mode = MCI_MODE_STOP; - if (dwFlags & MCI_NOTIFY) { - TRACE(mcianim, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", - lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + TRACE(mcianim,"(%u, %08lX, %p);\n", + wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + AnimDev[wDevID].mode = MCI_MODE_STOP; + if (dwFlags & MCI_NOTIFY) { + TRACE(mcianim, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", + lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), AnimDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); - } - return 0; + } + return 0; } /************************************************************************** -* ANIM_mciPause [internal] -*/ + * ANIM_mciPause [internal] + */ static DWORD ANIM_mciPause(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms) { - TRACE(mcianim,"(%u, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - AnimDev[wDevID].mode = MCI_MODE_PAUSE; - if (dwFlags & MCI_NOTIFY) { - TRACE(mcianim, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", - lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + TRACE(mcianim,"(%u, %08lX, %p);\n", + wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + AnimDev[wDevID].mode = MCI_MODE_PAUSE; + if (dwFlags & MCI_NOTIFY) { + TRACE(mcianim, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", + lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), AnimDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); - } - return 0; + } + return 0; } /************************************************************************** -* ANIM_mciResume [internal] -*/ + * ANIM_mciResume [internal] + */ static DWORD ANIM_mciResume(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms) { - TRACE(mcianim,"(%u, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - AnimDev[wDevID].mode = MCI_MODE_STOP; - if (dwFlags & MCI_NOTIFY) { - TRACE(mcianim, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", - lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + TRACE(mcianim,"(%u, %08lX, %p);\n", + wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + AnimDev[wDevID].mode = MCI_MODE_STOP; + if (dwFlags & MCI_NOTIFY) { + TRACE(mcianim, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", + lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), AnimDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); - } - return 0; + } + return 0; } /************************************************************************** -* ANIM_mciSeek [internal] -*/ + * ANIM_mciSeek [internal] + */ static DWORD ANIM_mciSeek(UINT16 wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms) { - DWORD dwRet; - MCI_PLAY_PARMS PlayParms; - TRACE(mcianim,"(%u, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - AnimDev[wDevID].mode = MCI_MODE_SEEK; - switch(dwFlags) { - case MCI_SEEK_TO_START: - PlayParms.dwFrom = 0; - break; - case MCI_SEEK_TO_END: - PlayParms.dwFrom = AnimDev[wDevID].dwTotalLen; - break; - case MCI_TO: - PlayParms.dwFrom = lpParms->dwTo; - break; - } - dwRet = ANIM_mciPlay(wDevID, MCI_WAIT | MCI_FROM, &PlayParms); - if (dwRet != 0) return dwRet; - dwRet = ANIM_mciStop(wDevID, MCI_WAIT, (LPMCI_GENERIC_PARMS)&PlayParms); - if (dwFlags & MCI_NOTIFY) { - TRACE(mcianim, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", - lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + DWORD dwRet; + MCI_PLAY_PARMS PlayParms; + TRACE(mcianim,"(%u, %08lX, %p);\n", + wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + AnimDev[wDevID].mode = MCI_MODE_SEEK; + switch(dwFlags) { + case MCI_SEEK_TO_START: + PlayParms.dwFrom = 0; + break; + case MCI_SEEK_TO_END: + PlayParms.dwFrom = AnimDev[wDevID].dwTotalLen; + break; + case MCI_TO: + PlayParms.dwFrom = lpParms->dwTo; + break; + } + dwRet = ANIM_mciPlay(wDevID, MCI_WAIT | MCI_FROM, &PlayParms); + if (dwRet != 0) return dwRet; + dwRet = ANIM_mciStop(wDevID, MCI_WAIT, (LPMCI_GENERIC_PARMS)&PlayParms); + if (dwFlags & MCI_NOTIFY) { + TRACE(mcianim, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", + lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), AnimDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); - } - return dwRet; + } + return dwRet; } /************************************************************************** -* ANIM_mciSet [internal] -*/ + * ANIM_mciSet [internal] + */ static DWORD ANIM_mciSet(UINT16 wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms) { - TRACE(mcianim,"(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; -/* - TRACE(mcianim,"(dwTimeFormat=%08lX)\n", lpParms->dwTimeFormat); - TRACE(mcianim,"(dwAudio=%08lX)\n", lpParms->dwAudio); -*/ - if (dwFlags & MCI_SET_TIME_FORMAT) { - switch (lpParms->dwTimeFormat) { - case MCI_FORMAT_MILLISECONDS: - TRACE(mcianim, "MCI_FORMAT_MILLISECONDS !\n"); - break; - case MCI_FORMAT_MSF: - TRACE(mcianim,"MCI_FORMAT_MSF !\n"); - break; - case MCI_FORMAT_TMSF: - TRACE(mcianim,"MCI_FORMAT_TMSF !\n"); - break; - default: - WARN(mcianim,"Bad time format !\n"); - return MCIERR_BAD_TIME_FORMAT; - } - AnimDev[wDevID].dwTimeFormat = lpParms->dwTimeFormat; - } - if (dwFlags & MCI_SET_VIDEO) return MCIERR_UNSUPPORTED_FUNCTION; - if (dwFlags & MCI_SET_ON) return MCIERR_UNSUPPORTED_FUNCTION; - if (dwFlags & MCI_SET_OFF) return MCIERR_UNSUPPORTED_FUNCTION; - if (dwFlags & MCI_NOTIFY) { - TRACE(mcianim, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", - lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + TRACE(mcianim,"(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + /* + TRACE(mcianim,"(dwTimeFormat=%08lX)\n", lpParms->dwTimeFormat); + TRACE(mcianim,"(dwAudio=%08lX)\n", lpParms->dwAudio); + */ + if (dwFlags & MCI_SET_TIME_FORMAT) { + switch (lpParms->dwTimeFormat) { + case MCI_FORMAT_MILLISECONDS: + TRACE(mcianim, "MCI_FORMAT_MILLISECONDS !\n"); + break; + case MCI_FORMAT_MSF: + TRACE(mcianim,"MCI_FORMAT_MSF !\n"); + break; + case MCI_FORMAT_TMSF: + TRACE(mcianim,"MCI_FORMAT_TMSF !\n"); + break; + default: + WARN(mcianim,"Bad time format !\n"); + return MCIERR_BAD_TIME_FORMAT; + } + AnimDev[wDevID].dwTimeFormat = lpParms->dwTimeFormat; + } + if (dwFlags & MCI_SET_VIDEO) return MCIERR_UNSUPPORTED_FUNCTION; + if (dwFlags & MCI_SET_ON) return MCIERR_UNSUPPORTED_FUNCTION; + if (dwFlags & MCI_SET_OFF) return MCIERR_UNSUPPORTED_FUNCTION; + if (dwFlags & MCI_NOTIFY) { + TRACE(mcianim, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", + lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), AnimDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); - } - return 0; + } + return 0; } /************************************************************************** -* ANIM_DriverProc [sample driver] -*/ -LONG ANIM_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, - DWORD dwParam1, DWORD dwParam2) + * ANIM_DriverProc16 [sample driver] + */ +LONG ANIM_DriverProc16(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, + DWORD dwParam1, DWORD dwParam2) { - switch(wMsg) { - case DRV_LOAD: - return 1; - case DRV_FREE: - return 1; - case DRV_OPEN: - case MCI_OPEN_DRIVER: - case MCI_OPEN: - return ANIM_mciOpen(dwDevID, dwParam1, - (LPMCI_OPEN_PARMS16)PTR_SEG_TO_LIN(dwParam2)); - case DRV_CLOSE: - case MCI_CLOSE_DRIVER: - case MCI_CLOSE: - return ANIM_mciClose(dwDevID, dwParam1, - (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case DRV_ENABLE: - return 1; - case DRV_DISABLE: - return 1; - case DRV_QUERYCONFIGURE: - return 1; - case DRV_CONFIGURE: - MessageBox16(0, "Sample MultiMedia Linux Driver !", - "MMLinux Driver", MB_OK); - return 1; - case DRV_INSTALL: - return DRVCNF_RESTART; - case DRV_REMOVE: - return DRVCNF_RESTART; - case MCI_GETDEVCAPS: - return ANIM_mciGetDevCaps(dwDevID, dwParam1, - (LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_INFO: - return ANIM_mciInfo(dwDevID, dwParam1, - (LPMCI_INFO_PARMS16)PTR_SEG_TO_LIN(dwParam2)); - case MCI_STATUS: - return ANIM_mciStatus(dwDevID, dwParam1, - (LPMCI_STATUS_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_SET: - return ANIM_mciSet(dwDevID, dwParam1, - (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_PLAY: - return ANIM_mciPlay(dwDevID, dwParam1, - (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_STOP: - return ANIM_mciStop(dwDevID, dwParam1, - (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_PAUSE: - return ANIM_mciPause(dwDevID, dwParam1, - (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_RESUME: - return ANIM_mciResume(dwDevID, dwParam1, - (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_SEEK: - return ANIM_mciSeek(dwDevID, dwParam1, - (LPMCI_SEEK_PARMS)PTR_SEG_TO_LIN(dwParam2)); - default: - return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2); - } + switch(wMsg) { + case DRV_LOAD: return 1; + case DRV_FREE: return 1; + case DRV_OPEN: + case MCI_OPEN_DRIVER: + case MCI_OPEN: return ANIM_mciOpen(dwDevID, dwParam1, (LPMCI_OPEN_PARMS16)PTR_SEG_TO_LIN(dwParam2), FALSE); + case DRV_CLOSE: + case MCI_CLOSE_DRIVER: + case MCI_CLOSE: return ANIM_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case DRV_ENABLE: return 1; + case DRV_DISABLE: return 1; + case DRV_QUERYCONFIGURE: return 1; + case DRV_CONFIGURE: MessageBox16(0, "Sample MultiMedia Linux Driver !", "MMLinux Driver", MB_OK); return 1; + case DRV_INSTALL: return DRVCNF_RESTART; + case DRV_REMOVE: return DRVCNF_RESTART; + case MCI_GETDEVCAPS: return ANIM_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_INFO: return ANIM_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS16)PTR_SEG_TO_LIN(dwParam2)); + case MCI_STATUS: return ANIM_mciStatus(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_SET: return ANIM_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_PLAY: return ANIM_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_STOP: return ANIM_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_PAUSE: return ANIM_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_RESUME: return ANIM_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_SEEK: return ANIM_mciSeek(dwDevID, dwParam1, (LPMCI_SEEK_PARMS)PTR_SEG_TO_LIN(dwParam2)); + default: return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2); + } +} +/************************************************************************** + * ANIM_DriverProc32 [sample driver] + */ +LONG ANIM_DriverProc32(DWORD dwDevID, HDRVR16 hDriv, DWORD wMsg, + DWORD dwParam1, DWORD dwParam2) +{ + switch(wMsg) { + case DRV_LOAD: return 1; + case DRV_FREE: return 1; + case DRV_OPEN: + case MCI_OPEN_DRIVER: + case MCI_OPEN: return ANIM_mciOpen(dwDevID, dwParam1, (LPMCI_OPEN_PARMS32A)dwParam2, TRUE); + case DRV_CLOSE: + case MCI_CLOSE_DRIVER: + case MCI_CLOSE: return ANIM_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case DRV_ENABLE: return 1; + case DRV_DISABLE: return 1; + case DRV_QUERYCONFIGURE: return 1; + case DRV_CONFIGURE: MessageBox16(0, "Sample MultiMedia Linux Driver !", "MMLinux Driver", MB_OK); return 1; + case DRV_INSTALL: return DRVCNF_RESTART; + case DRV_REMOVE: return DRVCNF_RESTART; + case MCI_GETDEVCAPS: return ANIM_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)dwParam2); + case MCI_INFO: return ANIM_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS16)dwParam2); + case MCI_STATUS: return ANIM_mciStatus(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)dwParam2); + case MCI_SET: return ANIM_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)dwParam2); + case MCI_PLAY: return ANIM_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)dwParam2); + case MCI_STOP: return ANIM_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case MCI_PAUSE: return ANIM_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case MCI_RESUME: return ANIM_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case MCI_SEEK: return ANIM_mciSeek(dwDevID, dwParam1, (LPMCI_SEEK_PARMS)dwParam2); + default: return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2); + } } diff --git a/multimedia/mcicda.c b/multimedia/mcicda.c index ea34de97111..b90c5f4c6d4 100644 --- a/multimedia/mcicda.c +++ b/multimedia/mcicda.c @@ -1,3 +1,4 @@ +/* -*- tab-width: 8; c-basic-offset: 4 -*- */ /* * Sample MCI CDAUDIO Wine Driver for Linux * @@ -46,1044 +47,1075 @@ #if defined(linux) || defined(__FreeBSD__) typedef struct { - int nUseCount; /* Incremented for each shared open */ - BOOL16 fShareable; /* TRUE if first open was shareable */ - WORD wNotifyDeviceID; /* MCI device ID with a pending notification */ - HANDLE16 hCallback; /* Callback handle for pending notification */ - MCI_OPEN_PARMS16 openParms; - DWORD dwTimeFormat; - int unixdev; + int nUseCount; /* Incremented for each shared open */ + BOOL16 fShareable; /* TRUE if first open was shareable */ + WORD wNotifyDeviceID; /* MCI device ID with a pending notification */ + HANDLE16 hCallback; /* Callback handle for pending notification */ + MCI_OPEN_PARMS16 openParms; + DWORD dwTimeFormat; + int unixdev; #ifdef linux - struct cdrom_subchnl sc; + struct cdrom_subchnl sc; #elif __FreeBSD__ - struct cd_sub_channel_info sc; + struct cd_sub_channel_info sc; #endif - int mode; - UINT16 nCurTrack; - DWORD dwCurFrame; - UINT16 nTracks; - DWORD dwTotalLen; - LPDWORD lpdwTrackLen; - LPDWORD lpdwTrackPos; - DWORD dwFirstOffset; - } LINUX_CDAUDIO; + int mode; + UINT16 nCurTrack; + DWORD dwCurFrame; + UINT16 nTracks; + DWORD dwTotalLen; + LPDWORD lpdwTrackLen; + LPDWORD lpdwTrackPos; + DWORD dwFirstOffset; +} WINE_CDAUDIO; -static LINUX_CDAUDIO CDADev[MAX_CDAUDIODRV]; +static WINE_CDAUDIO CDADev[MAX_CDAUDIODRV]; #endif - /*-----------------------------------------------------------------------*/ /************************************************************************** -* CDAUDIO_GetNumberOfTracks [internal] -*/ + * CDAUDIO_GetNumberOfTracks [internal] + */ static UINT16 CDAUDIO_GetNumberOfTracks(UINT16 wDevID) { #if defined(linux) || defined(__FreeBSD__) #ifdef linux - struct cdrom_tochdr hdr; + struct cdrom_tochdr hdr; #elif __FreeBSD__ - struct ioc_toc_header hdr; + struct ioc_toc_header hdr; #endif - - if (CDADev[wDevID].nTracks == 0) { - if (ioctl(CDADev[wDevID].unixdev, + + if (CDADev[wDevID].nTracks == 0) { + if (ioctl(CDADev[wDevID].unixdev, #ifdef linux - CDROMREADTOCHDR + CDROMREADTOCHDR #elif __FreeBSD__ - CDIOREADTOCHEADER + CDIOREADTOCHEADER #endif - , &hdr)) { - WARN(cdaudio, "(%04X) -- Error occured !\n", - wDevID); - return (WORD)-1; - } + , &hdr)) { + WARN(cdaudio, "(%04X) -- Error occured !\n", + wDevID); + return (WORD)-1; + } #ifdef linux - CDADev[wDevID].nTracks = hdr.cdth_trk1; + CDADev[wDevID].nTracks = hdr.cdth_trk1; #elif __FreeBSD__ - CDADev[wDevID].nTracks = hdr.ending_track - hdr.starting_track + 1; + CDADev[wDevID].nTracks = hdr.ending_track - hdr.starting_track + 1; #endif - } - return CDADev[wDevID].nTracks; + } + return CDADev[wDevID].nTracks; #else - return (WORD)-1; + return (WORD)-1; #endif } /************************************************************************** -* CDAUDIO_GetTracksInfo [internal] -*/ + * CDAUDIO_GetTracksInfo [internal] + */ static BOOL32 CDAUDIO_GetTracksInfo(UINT16 wDevID) { #if defined(linux) || defined(__FreeBSD__) - int i, length; - int start, last_start = 0; - int total_length = 0; + int i, length; + int start, last_start = 0; + int total_length = 0; #ifdef linux - struct cdrom_tocentry entry; + struct cdrom_tocentry entry; #elif __FreeBSD__ - struct ioc_read_toc_entry entry; - struct cd_toc_entry toc_buffer; + struct ioc_read_toc_entry entry; + struct cd_toc_entry toc_buffer; #endif - - if (CDADev[wDevID].nTracks == 0) { - if (CDAUDIO_GetNumberOfTracks(wDevID) == (WORD)-1) return FALSE; - } - TRACE(cdaudio,"nTracks=%u\n", - CDADev[wDevID].nTracks); - if (CDADev[wDevID].lpdwTrackLen != NULL) - free(CDADev[wDevID].lpdwTrackLen); - CDADev[wDevID].lpdwTrackLen = (LPDWORD)malloc( - (CDADev[wDevID].nTracks + 1) * sizeof(DWORD)); - if (CDADev[wDevID].lpdwTrackPos != NULL) - free(CDADev[wDevID].lpdwTrackPos); - CDADev[wDevID].lpdwTrackPos = (LPDWORD)malloc( - (CDADev[wDevID].nTracks + 1) * sizeof(DWORD)); - if (CDADev[wDevID].lpdwTrackLen == NULL || - CDADev[wDevID].lpdwTrackPos == NULL) { - WARN(cdaudio, "error allocating track table !\n"); - return FALSE; - } - memset(CDADev[wDevID].lpdwTrackLen, 0, - (CDADev[wDevID].nTracks + 1) * sizeof(DWORD)); - memset(CDADev[wDevID].lpdwTrackPos, 0, - (CDADev[wDevID].nTracks + 1) * sizeof(DWORD)); - for (i = 0; i <= CDADev[wDevID].nTracks; i++) { - if (i == CDADev[wDevID].nTracks) + + if (CDADev[wDevID].nTracks == 0) { + if (CDAUDIO_GetNumberOfTracks(wDevID) == (WORD)-1) return FALSE; + } + TRACE(cdaudio,"nTracks=%u\n", + CDADev[wDevID].nTracks); + if (CDADev[wDevID].lpdwTrackLen != NULL) + free(CDADev[wDevID].lpdwTrackLen); + CDADev[wDevID].lpdwTrackLen = (LPDWORD)malloc( + (CDADev[wDevID].nTracks + 1) * sizeof(DWORD)); + if (CDADev[wDevID].lpdwTrackPos != NULL) + free(CDADev[wDevID].lpdwTrackPos); + CDADev[wDevID].lpdwTrackPos = (LPDWORD)malloc( + (CDADev[wDevID].nTracks + 1) * sizeof(DWORD)); + if (CDADev[wDevID].lpdwTrackLen == NULL || + CDADev[wDevID].lpdwTrackPos == NULL) { + WARN(cdaudio, "error allocating track table !\n"); + return FALSE; + } + memset(CDADev[wDevID].lpdwTrackLen, 0, + (CDADev[wDevID].nTracks + 1) * sizeof(DWORD)); + memset(CDADev[wDevID].lpdwTrackPos, 0, + (CDADev[wDevID].nTracks + 1) * sizeof(DWORD)); + for (i = 0; i <= CDADev[wDevID].nTracks; i++) { + if (i == CDADev[wDevID].nTracks) #ifdef linux - entry.cdte_track = CDROM_LEADOUT; + entry.cdte_track = CDROM_LEADOUT; #elif __FreeBSD__ #define LEADOUT 0xaa - entry.starting_track = LEADOUT; /* XXX */ + entry.starting_track = LEADOUT; /* XXX */ #endif - else + else #ifdef linux - entry.cdte_track = i + 1; + entry.cdte_track = i + 1; #elif __FreeBSD__ - entry.starting_track = i + 1; + entry.starting_track = i + 1; #endif #ifdef linux - entry.cdte_format = CDROM_MSF; + entry.cdte_format = CDROM_MSF; #elif __FreeBSD__ - bzero((char *)&toc_buffer, sizeof(toc_buffer)); - entry.address_format = CD_MSF_FORMAT; - entry.data_len = sizeof(toc_buffer); - entry.data = &toc_buffer; + bzero((char *)&toc_buffer, sizeof(toc_buffer)); + entry.address_format = CD_MSF_FORMAT; + entry.data_len = sizeof(toc_buffer); + entry.data = &toc_buffer; #endif - if (ioctl(CDADev[wDevID].unixdev, + if (ioctl(CDADev[wDevID].unixdev, #ifdef linux - CDROMREADTOCENTRY + CDROMREADTOCENTRY #elif __FreeBSD__ - CDIOREADTOCENTRYS + CDIOREADTOCENTRYS #endif - , &entry)) { - WARN(cdaudio, "error read entry\n"); - return FALSE; - } + , &entry)) { + WARN(cdaudio, "error read entry\n"); + return FALSE; + } #ifdef linux - start = CDFRAMES_PERSEC * (SECONDS_PERMIN * - entry.cdte_addr.msf.minute + entry.cdte_addr.msf.second) + - entry.cdte_addr.msf.frame; + start = CDFRAMES_PERSEC * (SECONDS_PERMIN * + entry.cdte_addr.msf.minute + entry.cdte_addr.msf.second) + + entry.cdte_addr.msf.frame; #elif __FreeBSD__ - start = CDFRAMES_PERSEC * (SECONDS_PERMIN * - toc_buffer.addr.msf.minute + toc_buffer.addr.msf.second) + - toc_buffer.addr.msf.frame; + start = CDFRAMES_PERSEC * (SECONDS_PERMIN * + toc_buffer.addr.msf.minute + toc_buffer.addr.msf.second) + + toc_buffer.addr.msf.frame; #endif - if (i == 0) { - last_start = start; - CDADev[wDevID].dwFirstOffset = start; - TRACE(cdaudio, "dwFirstOffset=%u\n", - start); - } - else { - length = start - last_start; - last_start = start; - start = last_start - length; - total_length += length; - CDADev[wDevID].lpdwTrackLen[i - 1] = length; - CDADev[wDevID].lpdwTrackPos[i - 1] = start; - TRACE(cdaudio, "track #%u start=%u len=%u\n", - i, start, length); - } - } - CDADev[wDevID].dwTotalLen = total_length; - TRACE(cdaudio,"total_len=%u\n", - total_length); - return TRUE; + if (i == 0) { + last_start = start; + CDADev[wDevID].dwFirstOffset = start; + TRACE(cdaudio, "dwFirstOffset=%u\n", + start); + } + else { + length = start - last_start; + last_start = start; + start = last_start - length; + total_length += length; + CDADev[wDevID].lpdwTrackLen[i - 1] = length; + CDADev[wDevID].lpdwTrackPos[i - 1] = start; + TRACE(cdaudio, "track #%u start=%u len=%u\n", + i, start, length); + } + } + CDADev[wDevID].dwTotalLen = total_length; + TRACE(cdaudio,"total_len=%u\n", + total_length); + return TRUE; #else - return FALSE; + return FALSE; #endif } /************************************************************************** -* CDAUDIO_mciOpen [internal] -*/ -static DWORD CDAUDIO_mciOpen(UINT16 wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS16 lpParms) + * CDAUDIO_mciOpen [internal] + */ +static DWORD CDAUDIO_mciOpen(UINT16 wDevID, DWORD dwFlags, void* lp, BOOL32 is32) { #if defined(linux) || defined(__FreeBSD__) - TRACE(cdaudio,"(%04X, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; + DWORD dwDeviceID; - if (CDADev[wDevID].nUseCount > 0) { - /* The driver already open on this channel */ - /* If the driver was opened shareable before and this open specifies */ - /* shareable then increment the use count */ - if (CDADev[wDevID].fShareable && (dwFlags & MCI_OPEN_SHAREABLE)) - ++CDADev[wDevID].nUseCount; - else - return MCIERR_MUST_USE_SHAREABLE; - } - else { - CDADev[wDevID].nUseCount = 1; - CDADev[wDevID].fShareable = dwFlags & MCI_OPEN_SHAREABLE; - } + TRACE(cdaudio,"(%04X, %08lX, %p);\n", + wDevID, dwFlags, lp); + if (lp == NULL) return MCIERR_INTERNAL; + + if (is32) dwDeviceID = ((LPMCI_OPEN_PARMS32A)lp)->wDeviceID; + else dwDeviceID = ((LPMCI_OPEN_PARMS16)lp)->wDeviceID; + + if (CDADev[wDevID].nUseCount > 0) { + /* The driver already open on this channel */ + /* If the driver was opened shareable before and this open specifies */ + /* shareable then increment the use count */ + if (CDADev[wDevID].fShareable && (dwFlags & MCI_OPEN_SHAREABLE)) + ++CDADev[wDevID].nUseCount; + else + return MCIERR_MUST_USE_SHAREABLE; + } else { + CDADev[wDevID].nUseCount = 1; + CDADev[wDevID].fShareable = dwFlags & MCI_OPEN_SHAREABLE; + } if (dwFlags & MCI_OPEN_ELEMENT) { - TRACE(cdaudio,"MCI_OPEN_ELEMENT !\n"); -/* return MCIERR_NO_ELEMENT_ALLOWED; */ - } - memcpy(&CDADev[wDevID].openParms, lpParms, sizeof(MCI_OPEN_PARMS16)); - CDADev[wDevID].wNotifyDeviceID = lpParms->wDeviceID; - CDADev[wDevID].unixdev = open (CDAUDIO_DEV, O_RDONLY, 0); - if (CDADev[wDevID].unixdev == -1) { - WARN(cdaudio,"can't open '%s' !\n", CDAUDIO_DEV); - return MCIERR_HARDWARE; - } - CDADev[wDevID].mode = 0; - CDADev[wDevID].dwTimeFormat = MCI_FORMAT_TMSF; - CDADev[wDevID].nCurTrack = 0; - CDADev[wDevID].nTracks = 0; - CDADev[wDevID].dwTotalLen = 0; - CDADev[wDevID].dwFirstOffset = 0; - CDADev[wDevID].lpdwTrackLen = NULL; - CDADev[wDevID].lpdwTrackPos = NULL; - if (!CDAUDIO_GetTracksInfo(wDevID)) { - WARN(cdaudio,"error reading TracksInfo !\n"); -/* return MCIERR_INTERNAL; */ - } - -/* - Moved to mmsystem.c mciOpen routine - - if (dwFlags & MCI_NOTIFY) { - TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", - lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), - CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); - } -*/ - return 0; -#else + TRACE(cdaudio,"MCI_OPEN_ELEMENT !\n"); + /* return MCIERR_NO_ELEMENT_ALLOWED; */ + } + memcpy(&CDADev[wDevID].openParms, lp, sizeof(MCI_OPEN_PARMS16)); + CDADev[wDevID].wNotifyDeviceID = dwDeviceID; + CDADev[wDevID].unixdev = open (CDAUDIO_DEV, O_RDONLY, 0); + if (CDADev[wDevID].unixdev == -1) { + WARN(cdaudio,"can't open '%s' !\n", CDAUDIO_DEV); return MCIERR_HARDWARE; + } + CDADev[wDevID].mode = 0; + CDADev[wDevID].dwTimeFormat = MCI_FORMAT_TMSF; + CDADev[wDevID].nCurTrack = 0; + CDADev[wDevID].nTracks = 0; + CDADev[wDevID].dwTotalLen = 0; + CDADev[wDevID].dwFirstOffset = 0; + CDADev[wDevID].lpdwTrackLen = NULL; + CDADev[wDevID].lpdwTrackPos = NULL; + if (!CDAUDIO_GetTracksInfo(wDevID)) { + WARN(cdaudio,"error reading TracksInfo !\n"); + /* return MCIERR_INTERNAL; */ + } + + /* + Moved to mmsystem.c mciOpen routine + + if (dwFlags & MCI_NOTIFY) { + TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", + lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); + } + */ + return 0; +#else + return MCIERR_HARDWARE; #endif } /************************************************************************** -* CDAUDIO_mciClose [internal] -*/ + * CDAUDIO_mciClose [internal] + */ static DWORD CDAUDIO_mciClose(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms) { #if defined(linux) || defined(__FreeBSD__) - TRACE(cdaudio,"(%04X, %08lX, %p);\n", - wDevID, dwParam, lpParms); + TRACE(cdaudio,"(%04X, %08lX, %p);\n", + wDevID, dwParam, lpParms); + if (--CDADev[wDevID].nUseCount == 0) { if (CDADev[wDevID].lpdwTrackLen != NULL) free(CDADev[wDevID].lpdwTrackLen); if (CDADev[wDevID].lpdwTrackPos != NULL) free(CDADev[wDevID].lpdwTrackPos); close(CDADev[wDevID].unixdev); + } #endif - return 0; + return 0; } /************************************************************************** -* CDAUDIO_mciGetDevCaps [internal] -*/ + * CDAUDIO_mciGetDevCaps [internal] + */ static DWORD CDAUDIO_mciGetDevCaps(UINT16 wDevID, DWORD dwFlags, - LPMCI_GETDEVCAPS_PARMS lpParms) + LPMCI_GETDEVCAPS_PARMS lpParms) { #if defined(linux) || defined(__FreeBSD__) - TRACE(cdaudio,"(%04X, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - if (dwFlags & MCI_GETDEVCAPS_ITEM) { - TRACE(cdaudio, "MCI_GETDEVCAPS_ITEM dwItem=%08lX;\n", - lpParms->dwItem); - switch(lpParms->dwItem) { - case MCI_GETDEVCAPS_CAN_RECORD: - lpParms->dwReturn = FALSE; - break; - case MCI_GETDEVCAPS_HAS_AUDIO: - lpParms->dwReturn = TRUE; - break; - case MCI_GETDEVCAPS_HAS_VIDEO: - lpParms->dwReturn = FALSE; - break; - case MCI_GETDEVCAPS_DEVICE_TYPE: - lpParms->dwReturn = MCI_DEVTYPE_CD_AUDIO; - break; - case MCI_GETDEVCAPS_USES_FILES: - lpParms->dwReturn = FALSE; - break; - case MCI_GETDEVCAPS_COMPOUND_DEVICE: - lpParms->dwReturn = FALSE; - break; - case MCI_GETDEVCAPS_CAN_EJECT: - lpParms->dwReturn = TRUE; - break; - case MCI_GETDEVCAPS_CAN_PLAY: - lpParms->dwReturn = TRUE; - break; - case MCI_GETDEVCAPS_CAN_SAVE: - lpParms->dwReturn = FALSE; - break; - default: - return MCIERR_UNRECOGNIZED_COMMAND; - } - } - TRACE(cdaudio, "lpParms->dwReturn=%08lX;\n", - lpParms->dwReturn); - return 0; + TRACE(cdaudio,"(%04X, %08lX, %p);\n", + wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + if (dwFlags & MCI_GETDEVCAPS_ITEM) { + TRACE(cdaudio, "MCI_GETDEVCAPS_ITEM dwItem=%08lX;\n", + lpParms->dwItem); + switch(lpParms->dwItem) { + case MCI_GETDEVCAPS_CAN_RECORD: + lpParms->dwReturn = FALSE; + break; + case MCI_GETDEVCAPS_HAS_AUDIO: + lpParms->dwReturn = TRUE; + break; + case MCI_GETDEVCAPS_HAS_VIDEO: + lpParms->dwReturn = FALSE; + break; + case MCI_GETDEVCAPS_DEVICE_TYPE: + lpParms->dwReturn = MCI_DEVTYPE_CD_AUDIO; + break; + case MCI_GETDEVCAPS_USES_FILES: + lpParms->dwReturn = FALSE; + break; + case MCI_GETDEVCAPS_COMPOUND_DEVICE: + lpParms->dwReturn = FALSE; + break; + case MCI_GETDEVCAPS_CAN_EJECT: + lpParms->dwReturn = TRUE; + break; + case MCI_GETDEVCAPS_CAN_PLAY: + lpParms->dwReturn = TRUE; + break; + case MCI_GETDEVCAPS_CAN_SAVE: + lpParms->dwReturn = FALSE; + break; + default: + return MCIERR_UNRECOGNIZED_COMMAND; + } + } + TRACE(cdaudio, "lpParms->dwReturn=%08lX;\n", + lpParms->dwReturn); + return 0; #else - return MCIERR_INTERNAL; + return MCIERR_INTERNAL; #endif } /************************************************************************** -* CDAUDIO_mciInfo [internal] -*/ + * CDAUDIO_mciInfo [internal] + */ static DWORD CDAUDIO_mciInfo(UINT16 wDevID, DWORD dwFlags, LPMCI_INFO_PARMS16 lpParms) { #if defined(linux) || defined(__FreeBSD__) - TRACE(cdaudio,"(%04X, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - lpParms->lpstrReturn = NULL; - switch(dwFlags) { - case MCI_INFO_PRODUCT: - lpParms->lpstrReturn = "Linux CDROM 0.5"; - break; - default: - return MCIERR_UNRECOGNIZED_COMMAND; - } - if (lpParms->lpstrReturn != NULL) - lpParms->dwRetSize = strlen(lpParms->lpstrReturn); - else - lpParms->dwRetSize = 0; - return 0; + TRACE(cdaudio,"(%04X, %08lX, %p);\n", + wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + lpParms->lpstrReturn = NULL; + switch(dwFlags) { + case MCI_INFO_PRODUCT: + lpParms->lpstrReturn = "Linux CDROM 0.5"; + break; + default: + return MCIERR_UNRECOGNIZED_COMMAND; + } + if (lpParms->lpstrReturn != NULL) + lpParms->dwRetSize = strlen(lpParms->lpstrReturn); + else + lpParms->dwRetSize = 0; + return 0; #else - return MCIERR_INTERNAL; + return MCIERR_INTERNAL; #endif } /************************************************************************** -* CDAUDIO_CalcFrame [internal] -*/ + * CDAUDIO_CalcFrame [internal] + */ static DWORD CDAUDIO_CalcFrame(UINT16 wDevID, DWORD dwFormatType, DWORD dwTime) { - DWORD dwFrame = 0; + DWORD dwFrame = 0; #if defined(linux) || defined(__FreeBSD__) - UINT16 wTrack; + UINT16 wTrack; - TRACE(cdaudio,"(%04X, %08lX, %lu);\n", - wDevID, dwFormatType, dwTime); + TRACE(cdaudio,"(%04X, %08lX, %lu);\n", + wDevID, dwFormatType, dwTime); - switch (dwFormatType) { - case MCI_FORMAT_MILLISECONDS: - dwFrame = dwTime * CDFRAMES_PERSEC / 1000; - TRACE(cdaudio, "MILLISECONDS %lu\n", - dwFrame); - break; - case MCI_FORMAT_MSF: - TRACE(cdaudio, "MSF %02u:%02u:%02u\n", - MCI_MSF_MINUTE(dwTime), MCI_MSF_SECOND(dwTime), - MCI_MSF_FRAME(dwTime)); - dwFrame += CDFRAMES_PERMIN * MCI_MSF_MINUTE(dwTime); - dwFrame += CDFRAMES_PERSEC * MCI_MSF_SECOND(dwTime); - dwFrame += MCI_MSF_FRAME(dwTime); - break; - default: - /* unknown format ! force TMSF ! ... */ - dwFormatType = MCI_FORMAT_TMSF; - case MCI_FORMAT_TMSF: - wTrack = MCI_TMSF_TRACK(dwTime); - TRACE(cdaudio, "MSF %02u-%02u:%02u:%02u\n", - MCI_TMSF_TRACK(dwTime), MCI_TMSF_MINUTE(dwTime), - MCI_TMSF_SECOND(dwTime), MCI_TMSF_FRAME(dwTime)); - TRACE(cdaudio, "TMSF trackpos[%u]=%lu\n", - wTrack, CDADev[wDevID].lpdwTrackPos[wTrack - 1]); - dwFrame = CDADev[wDevID].lpdwTrackPos[wTrack - 1]; - dwFrame += CDFRAMES_PERMIN * MCI_TMSF_MINUTE(dwTime); - dwFrame += CDFRAMES_PERSEC * MCI_TMSF_SECOND(dwTime); - dwFrame += MCI_TMSF_FRAME(dwTime); - break; - } + switch (dwFormatType) { + case MCI_FORMAT_MILLISECONDS: + dwFrame = dwTime * CDFRAMES_PERSEC / 1000; + TRACE(cdaudio, "MILLISECONDS %lu\n", + dwFrame); + break; + case MCI_FORMAT_MSF: + TRACE(cdaudio, "MSF %02u:%02u:%02u\n", + MCI_MSF_MINUTE(dwTime), MCI_MSF_SECOND(dwTime), + MCI_MSF_FRAME(dwTime)); + dwFrame += CDFRAMES_PERMIN * MCI_MSF_MINUTE(dwTime); + dwFrame += CDFRAMES_PERSEC * MCI_MSF_SECOND(dwTime); + dwFrame += MCI_MSF_FRAME(dwTime); + break; + default: + /* unknown format ! force TMSF ! ... */ + dwFormatType = MCI_FORMAT_TMSF; + case MCI_FORMAT_TMSF: + wTrack = MCI_TMSF_TRACK(dwTime); + TRACE(cdaudio, "MSF %02u-%02u:%02u:%02u\n", + MCI_TMSF_TRACK(dwTime), MCI_TMSF_MINUTE(dwTime), + MCI_TMSF_SECOND(dwTime), MCI_TMSF_FRAME(dwTime)); + TRACE(cdaudio, "TMSF trackpos[%u]=%lu\n", + wTrack, CDADev[wDevID].lpdwTrackPos[wTrack - 1]); + dwFrame = CDADev[wDevID].lpdwTrackPos[wTrack - 1]; + dwFrame += CDFRAMES_PERMIN * MCI_TMSF_MINUTE(dwTime); + dwFrame += CDFRAMES_PERSEC * MCI_TMSF_SECOND(dwTime); + dwFrame += MCI_TMSF_FRAME(dwTime); + break; + } #endif - return dwFrame; + return dwFrame; } /************************************************************************** -* CDAUDIO_GetCDStatus [internal] -*/ + * CDAUDIO_GetCDStatus [internal] + */ static BOOL32 CDAUDIO_GetCDStatus(UINT16 wDevID) { #if defined(linux) || defined(__FreeBSD__) - int oldmode = CDADev[wDevID].mode; + int oldmode = CDADev[wDevID].mode; #ifdef __FreeBSD__ - struct ioc_read_subchannel read_sc; - - read_sc.address_format = CD_MSF_FORMAT; - read_sc.data_format = CD_CURRENT_POSITION; - read_sc.track = 0; - read_sc.data_len = sizeof(CDADev[wDevID].sc); - read_sc.data = (struct cd_sub_channel_info *)&CDADev[wDevID].sc; + struct ioc_read_subchannel read_sc; + + read_sc.address_format = CD_MSF_FORMAT; + read_sc.data_format = CD_CURRENT_POSITION; + read_sc.track = 0; + read_sc.data_len = sizeof(CDADev[wDevID].sc); + read_sc.data = (struct cd_sub_channel_info *)&CDADev[wDevID].sc; #elif linux - CDADev[wDevID].sc.cdsc_format = CDROM_MSF; + CDADev[wDevID].sc.cdsc_format = CDROM_MSF; #endif - if (ioctl(CDADev[wDevID].unixdev, + if (ioctl(CDADev[wDevID].unixdev, #ifdef linux - CDROMSUBCHNL, &CDADev[wDevID].sc + CDROMSUBCHNL, &CDADev[wDevID].sc #elif __FreeBSD__ - CDIOCREADSUBCHANNEL, &read_sc + CDIOCREADSUBCHANNEL, &read_sc #endif - )) { - TRACE(cdaudio,"opened or no_media !\n"); - CDADev[wDevID].mode = MCI_MODE_NOT_READY; - return TRUE; - } - switch ( -#ifdef linux - CDADev[wDevID].sc.cdsc_audiostatus -#elif __FreeBSD__ - CDADev[wDevID].sc.header.audio_status -#endif - ) { -#ifdef linux - case CDROM_AUDIO_INVALID: -#elif __FreeBSD__ - case CD_AS_AUDIO_INVALID: -#endif - WARN(cdaudio, "device doesn't support status, returning NOT_READY.\n"); -#ifdef linux - CDADev[wDevID].mode = MCI_MODE_NOT_READY; -#elif __FreeBSD__ - CDADev[wDevID].mode = MCI_MODE_STOP; -#endif - break; -#ifdef linux - case CDROM_AUDIO_NO_STATUS: -#elif __FreeBSD__ - case CD_AS_NO_STATUS: -#endif - CDADev[wDevID].mode = MCI_MODE_STOP; - TRACE(cdaudio,"MCI_MODE_STOP !\n"); - break; -#ifdef linux - case CDROM_AUDIO_PLAY: -#elif __FreeBSD__ - case CD_AS_PLAY_IN_PROGRESS: -#endif - CDADev[wDevID].mode = MCI_MODE_PLAY; - TRACE(cdaudio,"MCI_MODE_PLAY !\n"); - break; -#ifdef linux - case CDROM_AUDIO_PAUSED: -#elif __FreeBSD__ - case CD_AS_PLAY_PAUSED: -#endif - CDADev[wDevID].mode = MCI_MODE_PAUSE; - TRACE(cdaudio,"MCI_MODE_PAUSE !\n"); - break; - default: -#ifdef linux - TRACE(cdaudio,"status=%02X !\n", - CDADev[wDevID].sc.cdsc_audiostatus); -#elif __FreeBSD__ - TRACE(cdaudio,"status=%02X !\n", - CDADev[wDevID].sc.header.audio_status); -#endif - } -#ifdef linux - CDADev[wDevID].nCurTrack = CDADev[wDevID].sc.cdsc_trk; - CDADev[wDevID].dwCurFrame = - CDFRAMES_PERMIN * CDADev[wDevID].sc.cdsc_absaddr.msf.minute + - CDFRAMES_PERSEC * CDADev[wDevID].sc.cdsc_absaddr.msf.second + - CDADev[wDevID].sc.cdsc_absaddr.msf.frame; -#elif __FreeBSD__ - CDADev[wDevID].nCurTrack = CDADev[wDevID].sc.what.position.track_number; - CDADev[wDevID].dwCurFrame = - CDFRAMES_PERMIN * CDADev[wDevID].sc.what.position.absaddr.msf.minute + - CDFRAMES_PERSEC * CDADev[wDevID].sc.what.position.absaddr.msf.second + - CDADev[wDevID].sc.what.position.absaddr.msf.frame; -#endif -#ifdef linux - TRACE(cdaudio,"%02u-%02u:%02u:%02u \n", - CDADev[wDevID].sc.cdsc_trk, - CDADev[wDevID].sc.cdsc_absaddr.msf.minute, - CDADev[wDevID].sc.cdsc_absaddr.msf.second, - CDADev[wDevID].sc.cdsc_absaddr.msf.frame); -#elif __FreeBSD__ - TRACE(cdaudio,"%02u-%02u:%02u:%02u \n", - CDADev[wDevID].sc.what.position.track_number, - CDADev[wDevID].sc.what.position.absaddr.msf.minute, - CDADev[wDevID].sc.what.position.absaddr.msf.second, - CDADev[wDevID].sc.what.position.absaddr.msf.frame); -#endif - - if (oldmode != CDADev[wDevID].mode && oldmode == MCI_MODE_OPEN) { - if (!CDAUDIO_GetTracksInfo(wDevID)) { - WARN(cdaudio, "error updating TracksInfo !\n"); - return MCIERR_INTERNAL; - } - } + )) { + TRACE(cdaudio,"opened or no_media !\n"); + CDADev[wDevID].mode = MCI_MODE_NOT_READY; return TRUE; + } + switch ( +#ifdef linux + CDADev[wDevID].sc.cdsc_audiostatus +#elif __FreeBSD__ + CDADev[wDevID].sc.header.audio_status +#endif + ) { +#ifdef linux + case CDROM_AUDIO_INVALID: +#elif __FreeBSD__ + case CD_AS_AUDIO_INVALID: +#endif + WARN(cdaudio, "device doesn't support status, returning NOT_READY.\n"); +#ifdef linux + CDADev[wDevID].mode = MCI_MODE_NOT_READY; +#elif __FreeBSD__ + CDADev[wDevID].mode = MCI_MODE_STOP; +#endif + break; +#ifdef linux + case CDROM_AUDIO_NO_STATUS: +#elif __FreeBSD__ + case CD_AS_NO_STATUS: +#endif + CDADev[wDevID].mode = MCI_MODE_STOP; + TRACE(cdaudio,"MCI_MODE_STOP !\n"); + break; +#ifdef linux + case CDROM_AUDIO_PLAY: +#elif __FreeBSD__ + case CD_AS_PLAY_IN_PROGRESS: +#endif + CDADev[wDevID].mode = MCI_MODE_PLAY; + TRACE(cdaudio,"MCI_MODE_PLAY !\n"); + break; +#ifdef linux + case CDROM_AUDIO_PAUSED: +#elif __FreeBSD__ + case CD_AS_PLAY_PAUSED: +#endif + CDADev[wDevID].mode = MCI_MODE_PAUSE; + TRACE(cdaudio,"MCI_MODE_PAUSE !\n"); + break; + default: +#ifdef linux + TRACE(cdaudio,"status=%02X !\n", + CDADev[wDevID].sc.cdsc_audiostatus); +#elif __FreeBSD__ + TRACE(cdaudio,"status=%02X !\n", + CDADev[wDevID].sc.header.audio_status); +#endif + } +#ifdef linux + CDADev[wDevID].nCurTrack = CDADev[wDevID].sc.cdsc_trk; + CDADev[wDevID].dwCurFrame = + CDFRAMES_PERMIN * CDADev[wDevID].sc.cdsc_absaddr.msf.minute + + CDFRAMES_PERSEC * CDADev[wDevID].sc.cdsc_absaddr.msf.second + + CDADev[wDevID].sc.cdsc_absaddr.msf.frame; +#elif __FreeBSD__ + CDADev[wDevID].nCurTrack = CDADev[wDevID].sc.what.position.track_number; + CDADev[wDevID].dwCurFrame = + CDFRAMES_PERMIN * CDADev[wDevID].sc.what.position.absaddr.msf.minute + + CDFRAMES_PERSEC * CDADev[wDevID].sc.what.position.absaddr.msf.second + + CDADev[wDevID].sc.what.position.absaddr.msf.frame; +#endif +#ifdef linux + TRACE(cdaudio,"%02u-%02u:%02u:%02u \n", + CDADev[wDevID].sc.cdsc_trk, + CDADev[wDevID].sc.cdsc_absaddr.msf.minute, + CDADev[wDevID].sc.cdsc_absaddr.msf.second, + CDADev[wDevID].sc.cdsc_absaddr.msf.frame); +#elif __FreeBSD__ + TRACE(cdaudio,"%02u-%02u:%02u:%02u \n", + CDADev[wDevID].sc.what.position.track_number, + CDADev[wDevID].sc.what.position.absaddr.msf.minute, + CDADev[wDevID].sc.what.position.absaddr.msf.second, + CDADev[wDevID].sc.what.position.absaddr.msf.frame); +#endif + + if (oldmode != CDADev[wDevID].mode && oldmode == MCI_MODE_OPEN) { + if (!CDAUDIO_GetTracksInfo(wDevID)) { + WARN(cdaudio, "error updating TracksInfo !\n"); + return MCIERR_INTERNAL; + } + } + return TRUE; #else - return FALSE; + return FALSE; #endif } /************************************************************************** -* CDAUDIO_CalcTime [internal] -*/ + * CDAUDIO_CalcTime [internal] + */ static DWORD CDAUDIO_CalcTime(UINT16 wDevID, DWORD dwFormatType, DWORD dwFrame) { - DWORD dwTime = 0; + DWORD dwTime = 0; #if defined(linux) || defined(__FreeBSD__) - UINT16 wTrack; - UINT16 wMinutes; - UINT16 wSeconds; - UINT16 wFrames; - - TRACE(cdaudio,"(%04X, %08lX, %lu);\n", - wDevID, dwFormatType, dwFrame); - - switch (dwFormatType) { - case MCI_FORMAT_MILLISECONDS: - dwTime = dwFrame / CDFRAMES_PERSEC * 1000; - TRACE(cdaudio, "MILLISECONDS %lu\n", - dwTime); - break; - case MCI_FORMAT_MSF: - wMinutes = dwFrame / CDFRAMES_PERMIN; - wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC; - wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes - - CDFRAMES_PERSEC * wSeconds; - dwTime = MCI_MAKE_MSF(wMinutes, wSeconds, wFrames); - TRACE(cdaudio,"MSF %02u:%02u:%02u -> dwTime=%lu\n", - wMinutes, wSeconds, wFrames, dwTime); - break; - default: - /* unknown format ! force TMSF ! ... */ - dwFormatType = MCI_FORMAT_TMSF; - case MCI_FORMAT_TMSF: - for (wTrack = 0; wTrack < CDADev[wDevID].nTracks; wTrack++) { -/* dwTime += CDADev[wDevID].lpdwTrackLen[wTrack - 1]; - TRACE(cdaudio, "Adding trk#%u curpos=%u \n", dwTime); - if (dwTime >= dwFrame) break; */ - if (CDADev[wDevID].lpdwTrackPos[wTrack - 1] >= dwFrame) break; - } - wMinutes = dwFrame / CDFRAMES_PERMIN; - wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC; - wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes - - CDFRAMES_PERSEC * wSeconds; - dwTime = MCI_MAKE_TMSF(wTrack, wMinutes, wSeconds, wFrames); - TRACE(cdaudio, "%02u-%02u:%02u:%02u\n", - wTrack, wMinutes, wSeconds, wFrames); - break; - } + UINT16 wTrack; + UINT16 wMinutes; + UINT16 wSeconds; + UINT16 wFrames; + + TRACE(cdaudio,"(%04X, %08lX, %lu);\n", + wDevID, dwFormatType, dwFrame); + + switch (dwFormatType) { + case MCI_FORMAT_MILLISECONDS: + dwTime = dwFrame / CDFRAMES_PERSEC * 1000; + TRACE(cdaudio, "MILLISECONDS %lu\n", + dwTime); + break; + case MCI_FORMAT_MSF: + wMinutes = dwFrame / CDFRAMES_PERMIN; + wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC; + wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes - + CDFRAMES_PERSEC * wSeconds; + dwTime = MCI_MAKE_MSF(wMinutes, wSeconds, wFrames); + TRACE(cdaudio,"MSF %02u:%02u:%02u -> dwTime=%lu\n", + wMinutes, wSeconds, wFrames, dwTime); + break; + default: + /* unknown format ! force TMSF ! ... */ + dwFormatType = MCI_FORMAT_TMSF; + case MCI_FORMAT_TMSF: + for (wTrack = 0; wTrack < CDADev[wDevID].nTracks; wTrack++) { + /* dwTime += CDADev[wDevID].lpdwTrackLen[wTrack - 1]; + TRACE(cdaudio, "Adding trk#%u curpos=%u \n", dwTime); + if (dwTime >= dwFrame) break; */ + if (CDADev[wDevID].lpdwTrackPos[wTrack - 1] >= dwFrame) break; + } + wMinutes = dwFrame / CDFRAMES_PERMIN; + wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC; + wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes - + CDFRAMES_PERSEC * wSeconds; + dwTime = MCI_MAKE_TMSF(wTrack, wMinutes, wSeconds, wFrames); + TRACE(cdaudio, "%02u-%02u:%02u:%02u\n", + wTrack, wMinutes, wSeconds, wFrames); + break; + } #endif - return dwTime; + return dwTime; } /************************************************************************** -* CDAUDIO_mciStatus [internal] -*/ + * CDAUDIO_mciStatus [internal] + */ static DWORD CDAUDIO_mciStatus(UINT16 wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms) { #if defined(linux) || defined(__FreeBSD__) - TRACE(cdaudio,"(%04X, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - if (CDADev[wDevID].unixdev == 0) return MMSYSERR_NOTENABLED; - if (dwFlags & MCI_NOTIFY) { - TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", - lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + TRACE(cdaudio,"(%04X, %08lX, %p);\n", + wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + if (CDADev[wDevID].unixdev == 0) return MMSYSERR_NOTENABLED; + if (dwFlags & MCI_NOTIFY) { + TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", + lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); + } + if (dwFlags & MCI_STATUS_ITEM) { + switch(lpParms->dwItem) { + case MCI_STATUS_CURRENT_TRACK: + if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL; + lpParms->dwReturn = CDADev[wDevID].nCurTrack; + TRACE(cdaudio,"CURRENT_TRACK=%lu!\n", lpParms->dwReturn); + return 0; + case MCI_STATUS_LENGTH: + if (CDADev[wDevID].nTracks == 0) { + if (!CDAUDIO_GetTracksInfo(wDevID)) { + WARN(cdaudio, "error reading TracksInfo !\n"); + return MCIERR_INTERNAL; } - if (dwFlags & MCI_STATUS_ITEM) { - switch(lpParms->dwItem) { - case MCI_STATUS_CURRENT_TRACK: - if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL; - lpParms->dwReturn = CDADev[wDevID].nCurTrack; - TRACE(cdaudio,"CURRENT_TRACK=%lu!\n", lpParms->dwReturn); - return 0; - case MCI_STATUS_LENGTH: - if (CDADev[wDevID].nTracks == 0) { - if (!CDAUDIO_GetTracksInfo(wDevID)) { - WARN(cdaudio, "error reading TracksInfo !\n"); - return MCIERR_INTERNAL; - } - } - if (dwFlags & MCI_TRACK) { - TRACE(cdaudio,"MCI_TRACK #%lu LENGTH=??? !\n", - lpParms->dwTrack); - if (lpParms->dwTrack > CDADev[wDevID].nTracks) - return MCIERR_OUTOFRANGE; - lpParms->dwReturn = CDADev[wDevID].lpdwTrackLen[lpParms->dwTrack]; - } - else - lpParms->dwReturn = CDADev[wDevID].dwTotalLen; - lpParms->dwReturn = CDAUDIO_CalcTime(wDevID, - CDADev[wDevID].dwTimeFormat, lpParms->dwReturn); - TRACE(cdaudio,"LENGTH=%lu !\n", lpParms->dwReturn); - return 0; - case MCI_STATUS_MODE: - if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL; - lpParms->dwReturn = CDADev[wDevID].mode; - TRACE(cdaudio,"MCI_STATUS_MODE=%08lX !\n", - lpParms->dwReturn); - return 0; - case MCI_STATUS_MEDIA_PRESENT: - lpParms->dwReturn = (CDADev[wDevID].nTracks > 0) ? TRUE : FALSE; - if (lpParms->dwReturn == FALSE) - TRACE(cdaudio,"MEDIA_NOT_PRESENT !\n"); - else - TRACE(cdaudio,"MCI_STATUS_MEDIA_PRESENT !\n"); - return 0; - case MCI_STATUS_NUMBER_OF_TRACKS: - lpParms->dwReturn = CDAUDIO_GetNumberOfTracks(wDevID); - TRACE(cdaudio,"MCI_STATUS_NUMBER_OF_TRACKS = %lu !\n", - lpParms->dwReturn); - if (lpParms->dwReturn == (WORD)-1) return MCIERR_INTERNAL; - return 0; - case MCI_STATUS_POSITION: - if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL; - lpParms->dwReturn = CDADev[wDevID].dwCurFrame; - if (dwFlags & MCI_STATUS_START) { - lpParms->dwReturn = CDADev[wDevID].dwFirstOffset; - TRACE(cdaudio,"get MCI_STATUS_START !\n"); - } - if (dwFlags & MCI_TRACK) { - if (lpParms->dwTrack > CDADev[wDevID].nTracks) - return MCIERR_OUTOFRANGE; - lpParms->dwReturn = CDADev[wDevID].lpdwTrackPos[lpParms->dwTrack - 1]; - TRACE(cdaudio,"get MCI_TRACK #%lu !\n", lpParms->dwTrack); - } - lpParms->dwReturn = CDAUDIO_CalcTime(wDevID, - CDADev[wDevID].dwTimeFormat, lpParms->dwReturn); - TRACE(cdaudio,"MCI_STATUS_POSITION=%08lX !\n", - lpParms->dwReturn); - return 0; - case MCI_STATUS_READY: - TRACE(cdaudio,"MCI_STATUS_READY !\n"); - lpParms->dwReturn = TRUE; - return 0; - case MCI_STATUS_TIME_FORMAT: - TRACE(cdaudio,"MCI_STATUS_TIME_FORMAT !\n"); - lpParms->dwReturn = CDADev[wDevID].dwTimeFormat; - return 0; - default: - WARN(cdaudio, "unknown command %08lX !\n", lpParms->dwItem); - return MCIERR_UNRECOGNIZED_COMMAND; - } - } - WARN(cdaudio, "not MCI_STATUS_ITEM !\n"); - return 0; + } + if (dwFlags & MCI_TRACK) { + TRACE(cdaudio,"MCI_TRACK #%lu LENGTH=??? !\n", + lpParms->dwTrack); + if (lpParms->dwTrack > CDADev[wDevID].nTracks) + return MCIERR_OUTOFRANGE; + lpParms->dwReturn = CDADev[wDevID].lpdwTrackLen[lpParms->dwTrack]; + } + else + lpParms->dwReturn = CDADev[wDevID].dwTotalLen; + lpParms->dwReturn = CDAUDIO_CalcTime(wDevID, + CDADev[wDevID].dwTimeFormat, lpParms->dwReturn); + TRACE(cdaudio,"LENGTH=%lu !\n", lpParms->dwReturn); + return 0; + case MCI_STATUS_MODE: + if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL; + lpParms->dwReturn = CDADev[wDevID].mode; + TRACE(cdaudio,"MCI_STATUS_MODE=%08lX !\n", + lpParms->dwReturn); + return 0; + case MCI_STATUS_MEDIA_PRESENT: + lpParms->dwReturn = (CDADev[wDevID].nTracks > 0) ? TRUE : FALSE; + if (lpParms->dwReturn == FALSE) + TRACE(cdaudio,"MEDIA_NOT_PRESENT !\n"); + else + TRACE(cdaudio,"MCI_STATUS_MEDIA_PRESENT !\n"); + return 0; + case MCI_STATUS_NUMBER_OF_TRACKS: + lpParms->dwReturn = CDAUDIO_GetNumberOfTracks(wDevID); + TRACE(cdaudio,"MCI_STATUS_NUMBER_OF_TRACKS = %lu !\n", + lpParms->dwReturn); + if (lpParms->dwReturn == (WORD)-1) return MCIERR_INTERNAL; + return 0; + case MCI_STATUS_POSITION: + if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL; + lpParms->dwReturn = CDADev[wDevID].dwCurFrame; + if (dwFlags & MCI_STATUS_START) { + lpParms->dwReturn = CDADev[wDevID].dwFirstOffset; + TRACE(cdaudio,"get MCI_STATUS_START !\n"); + } + if (dwFlags & MCI_TRACK) { + if (lpParms->dwTrack > CDADev[wDevID].nTracks) + return MCIERR_OUTOFRANGE; + lpParms->dwReturn = CDADev[wDevID].lpdwTrackPos[lpParms->dwTrack - 1]; + TRACE(cdaudio,"get MCI_TRACK #%lu !\n", lpParms->dwTrack); + } + lpParms->dwReturn = CDAUDIO_CalcTime(wDevID, + CDADev[wDevID].dwTimeFormat, lpParms->dwReturn); + TRACE(cdaudio,"MCI_STATUS_POSITION=%08lX !\n", + lpParms->dwReturn); + return 0; + case MCI_STATUS_READY: + TRACE(cdaudio,"MCI_STATUS_READY !\n"); + lpParms->dwReturn = TRUE; + return 0; + case MCI_STATUS_TIME_FORMAT: + TRACE(cdaudio,"MCI_STATUS_TIME_FORMAT !\n"); + lpParms->dwReturn = CDADev[wDevID].dwTimeFormat; + return 0; + default: + WARN(cdaudio, "unknown command %08lX !\n", lpParms->dwItem); + return MCIERR_UNRECOGNIZED_COMMAND; + } + } + WARN(cdaudio, "not MCI_STATUS_ITEM !\n"); + return 0; #else - return MMSYSERR_NOTENABLED; + return MMSYSERR_NOTENABLED; #endif } /************************************************************************** -* CDAUDIO_mciPlay [internal] -*/ + * CDAUDIO_mciPlay [internal] + */ static DWORD CDAUDIO_mciPlay(UINT16 wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms) { #if defined(linux) || defined(__FreeBSD__) - int start, end; + int start, end; #ifdef linux - struct cdrom_msf msf; + struct cdrom_msf msf; #elif __FreeBSD__ - struct ioc_play_msf msf; + struct ioc_play_msf msf; #endif - - TRACE(cdaudio,"(%04X, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - if (CDADev[wDevID].unixdev == 0) return MMSYSERR_NOTENABLED; - start = 0; end = CDADev[wDevID].dwTotalLen; - CDADev[wDevID].nCurTrack = 1; - if (dwFlags & MCI_FROM) { - start = CDAUDIO_CalcFrame(wDevID, - CDADev[wDevID].dwTimeFormat, lpParms->dwFrom); + + TRACE(cdaudio,"(%04X, %08lX, %p);\n", + wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + if (CDADev[wDevID].unixdev == 0) return MMSYSERR_NOTENABLED; + start = 0; end = CDADev[wDevID].dwTotalLen; + CDADev[wDevID].nCurTrack = 1; + if (dwFlags & MCI_FROM) { + start = CDAUDIO_CalcFrame(wDevID, + CDADev[wDevID].dwTimeFormat, lpParms->dwFrom); TRACE(cdaudio,"MCI_FROM=%08lX -> %u \n", - lpParms->dwFrom, start); - } - if (dwFlags & MCI_TO) { - end = CDAUDIO_CalcFrame(wDevID, - CDADev[wDevID].dwTimeFormat, lpParms->dwTo); - TRACE(cdaudio, "MCI_TO=%08lX -> %u \n", - lpParms->dwTo, end); - } - start += CDADev[wDevID].dwFirstOffset; - end += CDADev[wDevID].dwFirstOffset; + lpParms->dwFrom, start); + } + if (dwFlags & MCI_TO) { + end = CDAUDIO_CalcFrame(wDevID, + CDADev[wDevID].dwTimeFormat, lpParms->dwTo); + TRACE(cdaudio, "MCI_TO=%08lX -> %u \n", + lpParms->dwTo, end); + } + start += CDADev[wDevID].dwFirstOffset; + end += CDADev[wDevID].dwFirstOffset; #ifdef linux - msf.cdmsf_min0 = start / CDFRAMES_PERMIN; - msf.cdmsf_sec0 = (start % CDFRAMES_PERMIN) / CDFRAMES_PERSEC; - msf.cdmsf_frame0 = start % CDFRAMES_PERSEC; - msf.cdmsf_min1 = end / CDFRAMES_PERMIN; - msf.cdmsf_sec1 = (end % CDFRAMES_PERMIN) / CDFRAMES_PERSEC; - msf.cdmsf_frame1 = end % CDFRAMES_PERSEC; + msf.cdmsf_min0 = start / CDFRAMES_PERMIN; + msf.cdmsf_sec0 = (start % CDFRAMES_PERMIN) / CDFRAMES_PERSEC; + msf.cdmsf_frame0 = start % CDFRAMES_PERSEC; + msf.cdmsf_min1 = end / CDFRAMES_PERMIN; + msf.cdmsf_sec1 = (end % CDFRAMES_PERMIN) / CDFRAMES_PERSEC; + msf.cdmsf_frame1 = end % CDFRAMES_PERSEC; #elif __FreeBSD__ - msf.start_m = start / CDFRAMES_PERMIN; - msf.start_s = (start % CDFRAMES_PERMIN) / CDFRAMES_PERSEC; - msf.start_f = start % CDFRAMES_PERSEC; - msf.end_m = end / CDFRAMES_PERMIN; - msf.end_s = (end % CDFRAMES_PERMIN) / CDFRAMES_PERSEC; - msf.end_f = end % CDFRAMES_PERSEC; + msf.start_m = start / CDFRAMES_PERMIN; + msf.start_s = (start % CDFRAMES_PERMIN) / CDFRAMES_PERSEC; + msf.start_f = start % CDFRAMES_PERSEC; + msf.end_m = end / CDFRAMES_PERMIN; + msf.end_s = (end % CDFRAMES_PERMIN) / CDFRAMES_PERSEC; + msf.end_f = end % CDFRAMES_PERSEC; #endif - if (ioctl(CDADev[wDevID].unixdev, + if (ioctl(CDADev[wDevID].unixdev, #ifdef linux - CDROMSTART + CDROMSTART #elif __FreeBSD__ - CDIOCSTART + CDIOCSTART #endif - )) { - WARN(cdaudio, "motor doesn't start !\n"); - return MCIERR_HARDWARE; - } - if (ioctl(CDADev[wDevID].unixdev, -#ifdef linux - CDROMPLAYMSF -#elif __FreeBSD__ - CDIOCPLAYMSF -#endif - , &msf)) { - WARN(cdaudio, "device doesn't play !\n"); - return MCIERR_HARDWARE; - } -#ifdef linux - TRACE(cdaudio,"msf = %d:%d:%d %d:%d:%d\n", - msf.cdmsf_min0, msf.cdmsf_sec0, msf.cdmsf_frame0, - msf.cdmsf_min1, msf.cdmsf_sec1, msf.cdmsf_frame1); -#elif __FreeBSD__ - TRACE(cdaudio,"msf = %d:%d:%d %d:%d:%d\n", - msf.start_m, msf.start_s, msf.start_f, - msf.end_m, msf.end_s, msf.end_f); -#endif - CDADev[wDevID].mode = MCI_MODE_PLAY; - if (dwFlags & MCI_NOTIFY) { - TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", - lpParms->dwCallback); -/* - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), - CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); -*/ - } - return 0; -#else + )) { + WARN(cdaudio, "motor doesn't start !\n"); return MCIERR_HARDWARE; + } + if (ioctl(CDADev[wDevID].unixdev, +#ifdef linux + CDROMPLAYMSF +#elif __FreeBSD__ + CDIOCPLAYMSF +#endif + , &msf)) { + WARN(cdaudio, "device doesn't play !\n"); + return MCIERR_HARDWARE; + } +#ifdef linux + TRACE(cdaudio,"msf = %d:%d:%d %d:%d:%d\n", + msf.cdmsf_min0, msf.cdmsf_sec0, msf.cdmsf_frame0, + msf.cdmsf_min1, msf.cdmsf_sec1, msf.cdmsf_frame1); +#elif __FreeBSD__ + TRACE(cdaudio,"msf = %d:%d:%d %d:%d:%d\n", + msf.start_m, msf.start_s, msf.start_f, + msf.end_m, msf.end_s, msf.end_f); +#endif + CDADev[wDevID].mode = MCI_MODE_PLAY; + if (dwFlags & MCI_NOTIFY) { + TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", + lpParms->dwCallback); + /* + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); + */ + } + return 0; +#else + return MCIERR_HARDWARE; #endif } /************************************************************************** -* CDAUDIO_mciStop [internal] -*/ + * CDAUDIO_mciStop [internal] + */ static DWORD CDAUDIO_mciStop(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms) { #if defined(linux) || defined(__FreeBSD__) - TRACE(cdaudio,"(%04X, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - if (ioctl(CDADev[wDevID].unixdev, + TRACE(cdaudio,"(%04X, %08lX, %p);\n", + wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + if (ioctl(CDADev[wDevID].unixdev, #ifdef linux - CDROMSTOP + CDROMSTOP #elif __FreeBSD__ - CDIOCSTOP + CDIOCSTOP #endif - )) return MCIERR_HARDWARE; - CDADev[wDevID].mode = MCI_MODE_STOP; - if (dwFlags & MCI_NOTIFY) { - TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", - lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + )) return MCIERR_HARDWARE; + CDADev[wDevID].mode = MCI_MODE_STOP; + if (dwFlags & MCI_NOTIFY) { + TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", + lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); - } - return 0; + } + return 0; #else - return MCIERR_HARDWARE; + return MCIERR_HARDWARE; #endif } /************************************************************************** -* CDAUDIO_mciPause [internal] -*/ + * CDAUDIO_mciPause [internal] + */ static DWORD CDAUDIO_mciPause(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms) { #if defined(linux) || defined(__FreeBSD__) - TRACE(cdaudio,"(%04X, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - if (ioctl(CDADev[wDevID].unixdev, + TRACE(cdaudio,"(%04X, %08lX, %p);\n", + wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + if (ioctl(CDADev[wDevID].unixdev, #ifdef linux - CDROMPAUSE + CDROMPAUSE #elif __FreeBSD__ - CDIOCPAUSE + CDIOCPAUSE #endif - )) return MCIERR_HARDWARE; - CDADev[wDevID].mode = MCI_MODE_PAUSE; - if (dwFlags & MCI_NOTIFY) { + )) return MCIERR_HARDWARE; + CDADev[wDevID].mode = MCI_MODE_PAUSE; + if (dwFlags & MCI_NOTIFY) { TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", - lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); - } - return 0; + } + return 0; #else - return MCIERR_HARDWARE; + return MCIERR_HARDWARE; #endif } /************************************************************************** -* CDAUDIO_mciResume [internal] -*/ + * CDAUDIO_mciResume [internal] + */ static DWORD CDAUDIO_mciResume(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms) { #if defined(linux) || defined(__FreeBSD__) - TRACE(cdaudio,"(%04X, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - if (ioctl(CDADev[wDevID].unixdev, + TRACE(cdaudio,"(%04X, %08lX, %p);\n", + wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + if (ioctl(CDADev[wDevID].unixdev, #ifdef linux - CDROMRESUME + CDROMRESUME #elif __FreeBSD__ - CDIOCRESUME + CDIOCRESUME #endif - )) return MCIERR_HARDWARE; - CDADev[wDevID].mode = MCI_MODE_STOP; - if (dwFlags & MCI_NOTIFY) { - TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", - lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + )) return MCIERR_HARDWARE; + CDADev[wDevID].mode = MCI_MODE_STOP; + if (dwFlags & MCI_NOTIFY) { + TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", + lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); - } - return 0; + } + return 0; #else - return MCIERR_HARDWARE; + return MCIERR_HARDWARE; #endif } /************************************************************************** -* CDAUDIO_mciSeek [internal] -*/ + * CDAUDIO_mciSeek [internal] + */ static DWORD CDAUDIO_mciSeek(UINT16 wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms) { #if defined(linux) || defined(__FreeBSD__) - DWORD dwRet; - MCI_PLAY_PARMS PlayParms; - TRACE(cdaudio,"(%04X, %08lX, %p);\n", - wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; - if (ioctl(CDADev[wDevID].unixdev, + DWORD dwRet; + MCI_PLAY_PARMS PlayParms; + TRACE(cdaudio,"(%04X, %08lX, %p);\n", + wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + if (ioctl(CDADev[wDevID].unixdev, #ifdef linux - CDROMRESUME + CDROMRESUME #elif __FreeBSD__ - CDIOCRESUME + CDIOCRESUME #endif - )) { - perror("ioctl CDROMRESUME"); - return MCIERR_HARDWARE; - } - CDADev[wDevID].mode = MCI_MODE_SEEK; - switch(dwFlags) { - case MCI_SEEK_TO_START: - PlayParms.dwFrom = 0; - break; - case MCI_SEEK_TO_END: - PlayParms.dwFrom = CDADev[wDevID].dwTotalLen; - break; - case MCI_TO: - PlayParms.dwFrom = lpParms->dwTo; - break; - } - dwRet = CDAUDIO_mciPlay(wDevID, MCI_WAIT | MCI_FROM, &PlayParms); - if (dwRet != 0) return dwRet; - dwRet = CDAUDIO_mciStop(wDevID, MCI_WAIT, (LPMCI_GENERIC_PARMS)&PlayParms); - if (dwFlags & MCI_NOTIFY) { - TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", - lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), - CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); - } - return dwRet; -#else + )) { + perror("ioctl CDROMRESUME"); return MCIERR_HARDWARE; + } + CDADev[wDevID].mode = MCI_MODE_SEEK; + switch(dwFlags) { + case MCI_SEEK_TO_START: + PlayParms.dwFrom = 0; + break; + case MCI_SEEK_TO_END: + PlayParms.dwFrom = CDADev[wDevID].dwTotalLen; + break; + case MCI_TO: + PlayParms.dwFrom = lpParms->dwTo; + break; + } + dwRet = CDAUDIO_mciPlay(wDevID, MCI_WAIT | MCI_FROM, &PlayParms); + if (dwRet != 0) return dwRet; + dwRet = CDAUDIO_mciStop(wDevID, MCI_WAIT, (LPMCI_GENERIC_PARMS)&PlayParms); + if (dwFlags & MCI_NOTIFY) { + TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", + lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); + } + return dwRet; +#else + return MCIERR_HARDWARE; #endif } /************************************************************************** -* CDAUDIO_mciSet [internal] -*/ + * CDAUDIO_mciSet [internal] + */ static DWORD CDAUDIO_mciSet(UINT16 wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms) { #if defined(linux) || defined(__FreeBSD__) - TRACE(cdaudio,"(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; -/* - TRACE(cdaudio,"dwTimeFormat=%08lX\n", lpParms->dwTimeFormat); - TRACE(cdaudio,"dwAudio=%08lX\n", lpParms->dwAudio); -*/ - if (dwFlags & MCI_SET_TIME_FORMAT) { - switch (lpParms->dwTimeFormat) { - case MCI_FORMAT_MILLISECONDS: - TRACE(cdaudio, "MCI_FORMAT_MILLISECONDS !\n"); - break; - case MCI_FORMAT_MSF: - TRACE(cdaudio,"MCI_FORMAT_MSF !\n"); - break; - case MCI_FORMAT_TMSF: - TRACE(cdaudio,"MCI_FORMAT_TMSF !\n"); - break; - default: - WARN(cdaudio, "bad time format !\n"); - return MCIERR_BAD_TIME_FORMAT; - } - CDADev[wDevID].dwTimeFormat = lpParms->dwTimeFormat; - } - if (dwFlags & MCI_SET_DOOR_OPEN) { - TRACE(cdaudio, "MCI_SET_DOOR_OPEN !\n"); + TRACE(cdaudio,"(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + /* + TRACE(cdaudio,"dwTimeFormat=%08lX\n", lpParms->dwTimeFormat); + TRACE(cdaudio,"dwAudio=%08lX\n", lpParms->dwAudio); + */ + if (dwFlags & MCI_SET_TIME_FORMAT) { + switch (lpParms->dwTimeFormat) { + case MCI_FORMAT_MILLISECONDS: + TRACE(cdaudio, "MCI_FORMAT_MILLISECONDS !\n"); + break; + case MCI_FORMAT_MSF: + TRACE(cdaudio,"MCI_FORMAT_MSF !\n"); + break; + case MCI_FORMAT_TMSF: + TRACE(cdaudio,"MCI_FORMAT_TMSF !\n"); + break; + default: + WARN(cdaudio, "bad time format !\n"); + return MCIERR_BAD_TIME_FORMAT; + } + CDADev[wDevID].dwTimeFormat = lpParms->dwTimeFormat; + } + if (dwFlags & MCI_SET_DOOR_OPEN) { + TRACE(cdaudio, "MCI_SET_DOOR_OPEN !\n"); #ifdef __FreeBSD__ - if (ioctl(CDADev[wDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE; - if (ioctl(CDADev[wDevID].unixdev, CDIOCEJECT)) return MCIERR_HARDWARE; - if (ioctl(CDADev[wDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE; + if (ioctl(CDADev[wDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE; + if (ioctl(CDADev[wDevID].unixdev, CDIOCEJECT)) return MCIERR_HARDWARE; + if (ioctl(CDADev[wDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE; #elif linux - if (ioctl(CDADev[wDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE; + if (ioctl(CDADev[wDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE; #endif - CDADev[wDevID].nTracks = 0; - } - if (dwFlags & MCI_SET_DOOR_CLOSED) { - TRACE(cdaudio, "MCI_SET_DOOR_CLOSED !\n"); + CDADev[wDevID].nTracks = 0; + } + if (dwFlags & MCI_SET_DOOR_CLOSED) { + TRACE(cdaudio, "MCI_SET_DOOR_CLOSED !\n"); #ifdef __FreeBSD__ - if (ioctl(CDADev[wDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE; - if (ioctl(CDADev[wDevID].unixdev, CDIOCCLOSE)) return MCIERR_HARDWARE; - if (ioctl(CDADev[wDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE; + if (ioctl(CDADev[wDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE; + if (ioctl(CDADev[wDevID].unixdev, CDIOCCLOSE)) return MCIERR_HARDWARE; + if (ioctl(CDADev[wDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE; #elif linux - if (ioctl(CDADev[wDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE; - /* XXX should it be ",1" ??? */ + if (ioctl(CDADev[wDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE; + /* XXX should it be ",1" ??? */ #endif - CDADev[wDevID].nTracks = 0; - } - if (dwFlags & MCI_SET_VIDEO) return MCIERR_UNSUPPORTED_FUNCTION; - if (dwFlags & MCI_SET_ON) return MCIERR_UNSUPPORTED_FUNCTION; - if (dwFlags & MCI_SET_OFF) return MCIERR_UNSUPPORTED_FUNCTION; - if (dwFlags & MCI_NOTIFY) { - TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", - lpParms->dwCallback); - mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + CDADev[wDevID].nTracks = 0; + } + if (dwFlags & MCI_SET_VIDEO) return MCIERR_UNSUPPORTED_FUNCTION; + if (dwFlags & MCI_SET_ON) return MCIERR_UNSUPPORTED_FUNCTION; + if (dwFlags & MCI_SET_OFF) return MCIERR_UNSUPPORTED_FUNCTION; + if (dwFlags & MCI_NOTIFY) { + TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", + lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); - } - return 0; + } + return 0; #else - return MCIERR_HARDWARE; + return MCIERR_HARDWARE; #endif } /************************************************************************** -* CDAUDIO_DriverProc [sample driver] -*/ -LONG CDAUDIO_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, - DWORD dwParam1, DWORD dwParam2) + * CDAUDIO_DriverProc16 [sample driver] + */ +LONG CDAUDIO_DriverProc16(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, + DWORD dwParam1, DWORD dwParam2) { #if defined(linux) || defined(__FreeBSD__) - switch(wMsg) { - case DRV_LOAD: - return 1; - case DRV_FREE: - return 1; - case DRV_OPEN: - case MCI_OPEN_DRIVER: - case MCI_OPEN: - return CDAUDIO_mciOpen(dwDevID, dwParam1, (LPMCI_OPEN_PARMS16)PTR_SEG_TO_LIN(dwParam2)); - case DRV_CLOSE: - case MCI_CLOSE_DRIVER: - case MCI_CLOSE: - return CDAUDIO_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case DRV_ENABLE: - return 1; - case DRV_DISABLE: - return 1; - case DRV_QUERYCONFIGURE: - return 1; - case DRV_CONFIGURE: - MessageBox16(0, "Sample MultiMedia Linux Driver !", - "MMLinux Driver", MB_OK); - return 1; - case DRV_INSTALL: - return DRVCNF_RESTART; - case DRV_REMOVE: - return DRVCNF_RESTART; - case MCI_GETDEVCAPS: - return CDAUDIO_mciGetDevCaps(dwDevID, dwParam1, - (LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_INFO: - return CDAUDIO_mciInfo(dwDevID, dwParam1, - (LPMCI_INFO_PARMS16)PTR_SEG_TO_LIN(dwParam2)); - case MCI_STATUS: - return CDAUDIO_mciStatus(dwDevID, dwParam1, - (LPMCI_STATUS_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_SET: - return CDAUDIO_mciSet(dwDevID, dwParam1, - (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_PLAY: - return CDAUDIO_mciPlay(dwDevID, dwParam1, - (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_STOP: - return CDAUDIO_mciStop(dwDevID, dwParam1, - (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_PAUSE: - return CDAUDIO_mciPause(dwDevID, dwParam1, - (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_RESUME: - return CDAUDIO_mciResume(dwDevID, dwParam1, - (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_SEEK: - return CDAUDIO_mciSeek(dwDevID, dwParam1, - (LPMCI_SEEK_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_SET_DOOR_OPEN: - TRACE(cdaudio, "MCI_SET_DOOR_OPEN !\n"); + switch(wMsg) { + case DRV_LOAD: return 1; + case DRV_FREE: return 1; + case DRV_OPEN: + case MCI_OPEN_DRIVER: + case MCI_OPEN: return CDAUDIO_mciOpen(dwDevID, dwParam1, (LPMCI_OPEN_PARMS16)PTR_SEG_TO_LIN(dwParam2), FALSE); + case DRV_CLOSE: + case MCI_CLOSE_DRIVER: + case MCI_CLOSE: return CDAUDIO_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case DRV_ENABLE: return 1; + case DRV_DISABLE: return 1; + case DRV_QUERYCONFIGURE: return 1; + case DRV_CONFIGURE: MessageBox16(0, "Sample MultiMedia Linux Driver !", "MMLinux Driver", MB_OK); return 1; + case DRV_INSTALL: return DRVCNF_RESTART; + case DRV_REMOVE: return DRVCNF_RESTART; + case MCI_GETDEVCAPS: return CDAUDIO_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_INFO: return CDAUDIO_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS16)PTR_SEG_TO_LIN(dwParam2)); + case MCI_STATUS: return CDAUDIO_mciStatus(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_SET: return CDAUDIO_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_PLAY: return CDAUDIO_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_STOP: return CDAUDIO_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_PAUSE: return CDAUDIO_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_RESUME: return CDAUDIO_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_SEEK: return CDAUDIO_mciSeek(dwDevID, dwParam1, (LPMCI_SEEK_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_SET_DOOR_OPEN: TRACE(cdaudio, "MCI_SET_DOOR_OPEN !\n"); #ifdef __FreeBSD__ - if (ioctl(CDADev[dwDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE; - if (ioctl(CDADev[dwDevID].unixdev, CDIOCEJECT)) return MCIERR_HARDWARE; - if (ioctl(CDADev[dwDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE; + if (ioctl(CDADev[dwDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE; + if (ioctl(CDADev[dwDevID].unixdev, CDIOCEJECT)) return MCIERR_HARDWARE; + if (ioctl(CDADev[dwDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE; #elif linux - if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE; + if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE; #endif - CDADev[dwDevID].nTracks = 0; - return 0; - case MCI_SET_DOOR_CLOSED: - TRACE(cdaudio,"MCI_SET_DOOR_CLOSED !\n"); + CDADev[dwDevID].nTracks = 0; + return 0; + case MCI_SET_DOOR_CLOSED: TRACE(cdaudio,"MCI_SET_DOOR_CLOSED !\n"); #ifdef __FreeBSD__ - if (ioctl(CDADev[dwDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE; - if (ioctl(CDADev[dwDevID].unixdev, CDIOCCLOSE)) return MCIERR_HARDWARE; - if (ioctl(CDADev[dwDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE; + if (ioctl(CDADev[dwDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE; + if (ioctl(CDADev[dwDevID].unixdev, CDIOCCLOSE)) return MCIERR_HARDWARE; + if (ioctl(CDADev[dwDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE; #elif linux - if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT, 1)) return MCIERR_HARDWARE; + if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT, 1)) return MCIERR_HARDWARE; #endif - CDADev[dwDevID].nTracks = 0; - return 0; - default: - return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2); - } + CDADev[dwDevID].nTracks = 0; + return 0; + default: + return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2); + } #else - return MCIERR_HARDWARE; + return MCIERR_HARDWARE; +#endif +} +/************************************************************************** + * CDAUDIO_DriverProc32 [sample driver] + */ +LONG CDAUDIO_DriverProc32(DWORD dwDevID, HDRVR16 hDriv, DWORD wMsg, + DWORD dwParam1, DWORD dwParam2) +{ +#if defined(linux) || defined(__FreeBSD__) + switch(wMsg) { + case DRV_LOAD: return 1; + case DRV_FREE: return 1; + case DRV_OPEN: + case MCI_OPEN_DRIVER: + case MCI_OPEN: return CDAUDIO_mciOpen(dwDevID, dwParam1, (LPMCI_OPEN_PARMS32A)dwParam2, TRUE); + case DRV_CLOSE: + case MCI_CLOSE_DRIVER: + case MCI_CLOSE: return CDAUDIO_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case DRV_ENABLE: return 1; + case DRV_DISABLE: return 1; + case DRV_QUERYCONFIGURE: return 1; + case DRV_CONFIGURE: MessageBox16(0, "Sample MultiMedia Linux Driver !", "MMLinux Driver", MB_OK); return 1; + case DRV_INSTALL: return DRVCNF_RESTART; + case DRV_REMOVE: return DRVCNF_RESTART; + case MCI_GETDEVCAPS: return CDAUDIO_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)dwParam2); + case MCI_INFO: return CDAUDIO_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS16)dwParam2); + case MCI_STATUS: return CDAUDIO_mciStatus(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)dwParam2); + case MCI_SET: return CDAUDIO_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)dwParam2); + case MCI_PLAY: return CDAUDIO_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)dwParam2); + case MCI_STOP: return CDAUDIO_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case MCI_PAUSE: return CDAUDIO_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case MCI_RESUME: return CDAUDIO_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case MCI_SEEK: return CDAUDIO_mciSeek(dwDevID, dwParam1, (LPMCI_SEEK_PARMS)dwParam2); + case MCI_SET_DOOR_OPEN: TRACE(cdaudio, "MCI_SET_DOOR_OPEN !\n"); +#ifdef __FreeBSD__ + if (ioctl(CDADev[dwDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE; + if (ioctl(CDADev[dwDevID].unixdev, CDIOCEJECT)) return MCIERR_HARDWARE; + if (ioctl(CDADev[dwDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE; +#elif linux + if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE; +#endif + CDADev[dwDevID].nTracks = 0; + return 0; + case MCI_SET_DOOR_CLOSED: TRACE(cdaudio,"MCI_SET_DOOR_CLOSED !\n"); +#ifdef __FreeBSD__ + if (ioctl(CDADev[dwDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE; + if (ioctl(CDADev[dwDevID].unixdev, CDIOCCLOSE)) return MCIERR_HARDWARE; + if (ioctl(CDADev[dwDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE; +#elif linux + if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT, 1)) return MCIERR_HARDWARE; +#endif + CDADev[dwDevID].nTracks = 0; + return 0; + default: + return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2); + } +#else + return MCIERR_HARDWARE; #endif } diff --git a/multimedia/mcistring.c b/multimedia/mcistring.c index e32e99d384b..1319d65d5fa 100644 --- a/multimedia/mcistring.c +++ b/multimedia/mcistring.c @@ -1,3 +1,5 @@ +/* -*- tab-width: 8; c-basic-offset: 4 -*- */ + /* * MCI stringinterface * @@ -22,15 +24,16 @@ #include "user.h" #include "driver.h" #include "mmsystem.h" +#include "multimedia.h" #include "callback.h" #include "debug.h" #include "xmalloc.h" -extern struct LINUX_MCIDRIVER mciDrv[MAXMCIDRIVERS]; +extern struct WINE_MCIDRIVER mciDrv[MAXMCIDRIVERS]; -#define GetDrv(wDevID) (&mciDrv[MMSYSTEM_DevIDToIndex(wDevID)]) -#define GetOpenDrv(wDevID) (&(GetDrv(wDevID)->mop)) +#define mciGetDrv(wDevID) (&mciDrv[MMSYSTEM_DevIDToIndex(wDevID)]) +#define mciGetOpenDrv(wDevID) (&(mciGetDrv(wDevID)->mop)) extern int MMSYSTEM_DevIDToIndex(UINT16 wDevID); extern UINT16 MMSYSTEM_FirstDevID(void); @@ -40,15 +43,6 @@ extern BOOL32 MMSYSTEM_DevIDValid(UINT16 wDevID); LONG WINAPI DrvDefDriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, DWORD dwParam1, DWORD dwParam2); -LONG WAVE_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, - DWORD dwParam1, DWORD dwParam2); -LONG MIDI_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, - DWORD dwParam1, DWORD dwParam2); -LONG CDAUDIO_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, - DWORD dwParam1, DWORD dwParam2); -LONG ANIM_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, - DWORD dwParam1, DWORD dwParam2); - /* The reason why I just don't lowercase the keywords array in * mciSendString is left as an exercise to the reader. */ @@ -71,68 +65,68 @@ LONG ANIM_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, }\ } while(0) -/* calling DriverProc. We need to pass the struct as SEGMENTED POINTER. */ +/* calling DriverProc. We need to pass the struct as linear pointer. */ #define _MCI_CALL_DRIVER(cmd,params) \ switch(uDevTyp) {\ case MCI_DEVTYPE_CD_AUDIO:\ - res=CDAUDIO_DriverProc(GetDrv(wDevID)->modp.wDeviceID,0,cmd,dwFlags, (DWORD)(params));\ + res=CDAUDIO_DriverProc32(mciGetDrv(wDevID)->modp.wDeviceID,0,cmd,dwFlags, (DWORD)(params));\ break;\ case MCI_DEVTYPE_WAVEFORM_AUDIO:\ - res=WAVE_DriverProc(GetDrv(wDevID)->modp.wDeviceID,0,cmd,dwFlags,(DWORD)(params));\ + res=WAVE_DriverProc32(mciGetDrv(wDevID)->modp.wDeviceID,0,cmd,dwFlags,(DWORD)(params));\ break;\ case MCI_DEVTYPE_SEQUENCER:\ - res=MIDI_DriverProc(GetDrv(wDevID)->modp.wDeviceID,0,cmd,dwFlags,(DWORD)(params));\ + res=MIDI_DriverProc32(mciGetDrv(wDevID)->modp.wDeviceID,0,cmd,dwFlags,(DWORD)(params));\ break;\ case MCI_DEVTYPE_ANIMATION:\ - res=ANIM_DriverProc(GetDrv(wDevID)->modp.wDeviceID,0,cmd,dwFlags,(DWORD)(params));\ + res=ANIM_DriverProc32(mciGetDrv(wDevID)->modp.wDeviceID,0,cmd,dwFlags,(DWORD)(params));\ break;\ case MCI_DEVTYPE_DIGITAL_VIDEO:\ FIXME(mci,"_MCI_CALL_DRIVER: No DIGITAL_VIDEO yet !\n");\ res=MCIERR_DEVICE_NOT_INSTALLED;\ break;\ default:\ - /*res = Callbacks->CallDriverProc(GetDrv(wDevID)->driverproc,GetDrv(wDevID)->modp.wDeviceID,GetDrv(wDevID)->hdrv,cmd,dwFlags,(DWORD)(params));\ - break;*/\ + /*res = Callbacks->CallDriverProc(mciGetDrv(wDevID)->driverproc,mciGetDrv(wDevID)->modp.wDeviceID,mciGetDrv(wDevID)->hdrv,cmd,dwFlags,(DWORD)(params));\ + break;*/\ res = MCIERR_DEVICE_NOT_INSTALLED;\ break;\ } /* print a DWORD in the specified timeformat */ static void _MCISTR_printtf(char *buf,UINT16 uDevType,DWORD timef,DWORD val) { - *buf='\0'; - switch (timef) { - case MCI_FORMAT_MILLISECONDS: - case MCI_FORMAT_FRAMES: - case MCI_FORMAT_BYTES: - case MCI_FORMAT_SAMPLES: - case MCI_VD_FORMAT_TRACK: + *buf='\0'; + switch (timef) { + case MCI_FORMAT_MILLISECONDS: + case MCI_FORMAT_FRAMES: + case MCI_FORMAT_BYTES: + case MCI_FORMAT_SAMPLES: + case MCI_VD_FORMAT_TRACK: /*case MCI_SEQ_FORMAT_SONGPTR: sameas MCI_VD_FORMAT_TRACK */ - sprintf(buf,"%ld",val); - break; - case MCI_FORMAT_HMS: - /* well, the macros have the same content*/ - /*FALLTRHOUGH*/ - case MCI_FORMAT_MSF: - sprintf(buf,"%d:%d:%d", - MCI_HMS_HOUR(val), - MCI_HMS_MINUTE(val), - MCI_HMS_SECOND(val) + sprintf(buf,"%ld",val); + break; + case MCI_FORMAT_HMS: + /* well, the macros have the same content*/ + /*FALLTRHOUGH*/ + case MCI_FORMAT_MSF: + sprintf(buf,"%d:%d:%d", + MCI_HMS_HOUR(val), + MCI_HMS_MINUTE(val), + MCI_HMS_SECOND(val) ); - break; - case MCI_FORMAT_TMSF: - sprintf(buf,"%d:%d:%d:%d", - MCI_TMSF_TRACK(val), - MCI_TMSF_MINUTE(val), - MCI_TMSF_SECOND(val), - MCI_TMSF_FRAME(val) + break; + case MCI_FORMAT_TMSF: + sprintf(buf,"%d:%d:%d:%d", + MCI_TMSF_TRACK(val), + MCI_TMSF_MINUTE(val), + MCI_TMSF_SECOND(val), + MCI_TMSF_FRAME(val) ); - break; - default: - FIXME(mci, "missing timeformat for %ld, report.\n",timef); - strcpy(buf,"0"); /* hmm */ - break; - } - return; + break; + default: + FIXME(mci, "missing timeformat for %ld, report.\n",timef); + strcpy(buf,"0"); /* hmm */ + break; + } + return; } /* possible different return types */ #define _MCISTR_int 1 @@ -147,99 +141,99 @@ _MCISTR_printtf(char *buf,UINT16 uDevType,DWORD timef,DWORD val) { static void _MCISTR_convreturn(int type,DWORD dwReturn,LPSTR lpstrReturnString, - WORD uReturnLength,WORD uDevTyp,int timef -) { - switch (type) { - case _MCISTR_vdmtype: - switch (dwReturn) { - case MCI_VD_MEDIA_CLV:_MCI_STR("CLV");break; - case MCI_VD_MEDIA_CAV:_MCI_STR("CAV");break; - default: - case MCI_VD_MEDIA_OTHER:_MCI_STR("other");break; - } - break; - case _MCISTR_seqtype: - switch (dwReturn) { - case MCI_SEQ_NONE:_MCI_STR("none");break; - case MCI_SEQ_SMPTE:_MCI_STR("smpte");break; - case MCI_SEQ_FILE:_MCI_STR("file");break; - case MCI_SEQ_MIDI:_MCI_STR("midi");break; - default:FIXME(mci,"missing sequencer mode %ld\n",dwReturn); - } - break; - case _MCISTR_mode: - switch (dwReturn) { - case MCI_MODE_NOT_READY:_MCI_STR("not ready");break; - case MCI_MODE_STOP:_MCI_STR("stopped");break; - case MCI_MODE_PLAY:_MCI_STR("playing");break; - case MCI_MODE_RECORD:_MCI_STR("recording");break; - case MCI_MODE_SEEK:_MCI_STR("seeking");break; - case MCI_MODE_PAUSE:_MCI_STR("paused");break; - case MCI_MODE_OPEN:_MCI_STR("open");break; - default:break; - } - break; - case _MCISTR_bool: - if (dwReturn) - _MCI_STR("true"); - else - _MCI_STR("false"); - break; - case _MCISTR_int:{ - char buf[16]; - sprintf(buf,"%ld",dwReturn); - _MCI_STR(buf); - break; - } - case _MCISTR_time: { - char buf[100]; - _MCISTR_printtf(buf,uDevTyp,timef,dwReturn); - _MCI_STR(buf); - break; - } - case _MCISTR_tfname: - switch (timef) { - case MCI_FORMAT_MILLISECONDS:_MCI_STR("milliseconds");break; - case MCI_FORMAT_FRAMES:_MCI_STR("frames");break; - case MCI_FORMAT_BYTES:_MCI_STR("bytes");break; - case MCI_FORMAT_SAMPLES:_MCI_STR("samples");break; - case MCI_FORMAT_HMS:_MCI_STR("hms");break; - case MCI_FORMAT_MSF:_MCI_STR("msf");break; - case MCI_FORMAT_TMSF:_MCI_STR("tmsf");break; - default: - FIXME(mci,"missing timefmt for %d, report.\n",timef); - break; - } - break; - case _MCISTR_divtype: - switch (dwReturn) { - case MCI_SEQ_DIV_PPQN:_MCI_STR("PPQN");break; - case MCI_SEQ_DIV_SMPTE_24:_MCI_STR("SMPTE 24 frame");break; - case MCI_SEQ_DIV_SMPTE_25:_MCI_STR("SMPTE 25 frame");break; - case MCI_SEQ_DIV_SMPTE_30:_MCI_STR("SMPTE 30 frame");break; - case MCI_SEQ_DIV_SMPTE_30DROP:_MCI_STR("SMPTE 30 frame drop");break; - } - case _MCISTR_devtype: - switch (dwReturn) { - case MCI_DEVTYPE_VCR:_MCI_STR("vcr");break; - case MCI_DEVTYPE_VIDEODISC:_MCI_STR("videodisc");break; - case MCI_DEVTYPE_CD_AUDIO:_MCI_STR("cd audio");break; - case MCI_DEVTYPE_OVERLAY:_MCI_STR("overlay");break; - case MCI_DEVTYPE_DAT:_MCI_STR("dat");break; - case MCI_DEVTYPE_SCANNER:_MCI_STR("scanner");break; - case MCI_DEVTYPE_ANIMATION:_MCI_STR("animation");break; - case MCI_DEVTYPE_DIGITAL_VIDEO:_MCI_STR("digital video");break; - case MCI_DEVTYPE_OTHER:_MCI_STR("other");break; - case MCI_DEVTYPE_WAVEFORM_AUDIO:_MCI_STR("waveform audio");break; - case MCI_DEVTYPE_SEQUENCER:_MCI_STR("sequencer");break; - default:FIXME(mci,"unknown device type %ld, report.\n", - dwReturn);break; - } - break; + WORD uReturnLength,WORD uDevTyp,int timef + ) { + switch (type) { + case _MCISTR_vdmtype: + switch (dwReturn) { + case MCI_VD_MEDIA_CLV:_MCI_STR("CLV");break; + case MCI_VD_MEDIA_CAV:_MCI_STR("CAV");break; default: - FIXME(mci,"unknown resulttype %d, report.\n",type); - break; + case MCI_VD_MEDIA_OTHER:_MCI_STR("other");break; } + break; + case _MCISTR_seqtype: + switch (dwReturn) { + case MCI_SEQ_NONE:_MCI_STR("none");break; + case MCI_SEQ_SMPTE:_MCI_STR("smpte");break; + case MCI_SEQ_FILE:_MCI_STR("file");break; + case MCI_SEQ_MIDI:_MCI_STR("midi");break; + default:FIXME(mci,"missing sequencer mode %ld\n",dwReturn); + } + break; + case _MCISTR_mode: + switch (dwReturn) { + case MCI_MODE_NOT_READY:_MCI_STR("not ready");break; + case MCI_MODE_STOP:_MCI_STR("stopped");break; + case MCI_MODE_PLAY:_MCI_STR("playing");break; + case MCI_MODE_RECORD:_MCI_STR("recording");break; + case MCI_MODE_SEEK:_MCI_STR("seeking");break; + case MCI_MODE_PAUSE:_MCI_STR("paused");break; + case MCI_MODE_OPEN:_MCI_STR("open");break; + default:break; + } + break; + case _MCISTR_bool: + if (dwReturn) + _MCI_STR("true"); + else + _MCI_STR("false"); + break; + case _MCISTR_int:{ + char buf[16]; + sprintf(buf,"%ld",dwReturn); + _MCI_STR(buf); + break; + } + case _MCISTR_time: { + char buf[100]; + _MCISTR_printtf(buf,uDevTyp,timef,dwReturn); + _MCI_STR(buf); + break; + } + case _MCISTR_tfname: + switch (timef) { + case MCI_FORMAT_MILLISECONDS:_MCI_STR("milliseconds");break; + case MCI_FORMAT_FRAMES:_MCI_STR("frames");break; + case MCI_FORMAT_BYTES:_MCI_STR("bytes");break; + case MCI_FORMAT_SAMPLES:_MCI_STR("samples");break; + case MCI_FORMAT_HMS:_MCI_STR("hms");break; + case MCI_FORMAT_MSF:_MCI_STR("msf");break; + case MCI_FORMAT_TMSF:_MCI_STR("tmsf");break; + default: + FIXME(mci,"missing timefmt for %d, report.\n",timef); + break; + } + break; + case _MCISTR_divtype: + switch (dwReturn) { + case MCI_SEQ_DIV_PPQN:_MCI_STR("PPQN");break; + case MCI_SEQ_DIV_SMPTE_24:_MCI_STR("SMPTE 24 frame");break; + case MCI_SEQ_DIV_SMPTE_25:_MCI_STR("SMPTE 25 frame");break; + case MCI_SEQ_DIV_SMPTE_30:_MCI_STR("SMPTE 30 frame");break; + case MCI_SEQ_DIV_SMPTE_30DROP:_MCI_STR("SMPTE 30 frame drop");break; + } + case _MCISTR_devtype: + switch (dwReturn) { + case MCI_DEVTYPE_VCR:_MCI_STR("vcr");break; + case MCI_DEVTYPE_VIDEODISC:_MCI_STR("videodisc");break; + case MCI_DEVTYPE_CD_AUDIO:_MCI_STR("cd audio");break; + case MCI_DEVTYPE_OVERLAY:_MCI_STR("overlay");break; + case MCI_DEVTYPE_DAT:_MCI_STR("dat");break; + case MCI_DEVTYPE_SCANNER:_MCI_STR("scanner");break; + case MCI_DEVTYPE_ANIMATION:_MCI_STR("animation");break; + case MCI_DEVTYPE_DIGITAL_VIDEO:_MCI_STR("digital video");break; + case MCI_DEVTYPE_OTHER:_MCI_STR("other");break; + case MCI_DEVTYPE_WAVEFORM_AUDIO:_MCI_STR("waveform audio");break; + case MCI_DEVTYPE_SEQUENCER:_MCI_STR("sequencer");break; + default:FIXME(mci,"unknown device type %ld, report.\n", + dwReturn);break; + } + break; + default: + FIXME(mci,"unknown resulttype %d, report.\n",type); + break; + } } #define FLAG1(str,flag) \ @@ -299,147 +293,148 @@ _MCISTR_convreturn(int type,DWORD dwReturn,LPSTR lpstrReturnString, */ static DWORD MCISTR_Open(_MCISTR_PROTO_) { - int res,i; - char *s; - union U { - MCI_OPEN_PARMS16 openParams; - MCI_WAVE_OPEN_PARMS16 waveopenParams; - MCI_ANIM_OPEN_PARMS16 animopenParams; - MCI_OVLY_OPEN_PARMS16 ovlyopenParams; - }; - union U *pU = SEGPTR_NEW(union U); - - pU->openParams.lpstrElementName = NULL; - s=strchr(dev,'!'); - if (s!=NULL) { - *s++='\0'; - pU->openParams.lpstrElementName=(LPSTR)SEGPTR_GET(SEGPTR_STRDUP(s)); - dwFlags |= MCI_OPEN_ELEMENT; + int res,i; + char *s; + union U { + MCI_OPEN_PARMS16 openParams; + MCI_WAVE_OPEN_PARMS16 waveopenParams; + MCI_ANIM_OPEN_PARMS16 animopenParams; + MCI_OVLY_OPEN_PARMS16 ovlyopenParams; + }; + union U *pU = xmalloc(sizeof(union U)); + + pU->openParams.lpstrElementName = NULL; + s=strchr(dev,'!'); + if (s!=NULL) { + *s++='\0'; + pU->openParams.lpstrElementName=strdup(s); + dwFlags |= MCI_OPEN_ELEMENT; + } + if (!STRCMP(dev,"cdaudio")) { + uDevTyp=MCI_DEVTYPE_CD_AUDIO; + } else if (!STRCMP(dev,"waveaudio")) { + uDevTyp=MCI_DEVTYPE_WAVEFORM_AUDIO; + } else if (!STRCMP(dev,"sequencer")) { + uDevTyp=MCI_DEVTYPE_SEQUENCER; + } else if (!STRCMP(dev,"animation1")) { + uDevTyp=MCI_DEVTYPE_ANIMATION; + } else if (!STRCMP(dev,"avivideo")) { + uDevTyp=MCI_DEVTYPE_DIGITAL_VIDEO; + } else { + free(pU->openParams.lpstrElementName); + free(pU); + return MCIERR_INVALID_DEVICE_NAME; + } + wDevID=MMSYSTEM_FirstDevID(); + while(mciGetDrv(wDevID)->modp.wType) { + wDevID = MMSYSTEM_NextDevID(wDevID); + if (!MMSYSTEM_DevIDValid(wDevID)) { + TRACE(mci, "MAXMCIDRIVERS reached (%x) !\n", wDevID); + free(pU->openParams.lpstrElementName); + free(pU); + return MCIERR_INTERNAL; } - if (!STRCMP(dev,"cdaudio")) { - uDevTyp=MCI_DEVTYPE_CD_AUDIO; - } else if (!STRCMP(dev,"waveaudio")) { - uDevTyp=MCI_DEVTYPE_WAVEFORM_AUDIO; - } else if (!STRCMP(dev,"sequencer")) { - uDevTyp=MCI_DEVTYPE_SEQUENCER; - } else if (!STRCMP(dev,"animation1")) { - uDevTyp=MCI_DEVTYPE_ANIMATION; - } else if (!STRCMP(dev,"avivideo")) { - uDevTyp=MCI_DEVTYPE_DIGITAL_VIDEO; - } else { - SEGPTR_FREE(PTR_SEG_TO_LIN(pU->openParams.lpstrElementName)); - SEGPTR_FREE(pU); - return MCIERR_INVALID_DEVICE_NAME; + } + mciGetDrv(wDevID)->modp.wType = uDevTyp; + mciGetDrv(wDevID)->modp.wDeviceID = 0; /* FIXME? for multiple devices */ + pU->openParams.dwCallback = hwndCallback ; + pU->openParams.wDeviceID = wDevID; + pU->openParams.wReserved0 = 0; + pU->ovlyopenParams.dwStyle = 0; + pU->animopenParams.dwStyle = 0; + pU->openParams.lpstrDeviceType = strdup(dev); + pU->openParams.lpstrAlias = NULL; + dwFlags |= MCI_OPEN_TYPE; + i=0; + while (iopenParams.lpstrAlias=strdup(keywords[i+1]); + i+=2; + continue; } - wDevID=MMSYSTEM_FirstDevID(); - while(GetDrv(wDevID)->modp.wType) { - wDevID = MMSYSTEM_NextDevID(wDevID); - if (!MMSYSTEM_DevIDValid(wDevID)) { - TRACE(mci, "MAXMCIDRIVERS reached (%x) !\n", wDevID); - SEGPTR_FREE(PTR_SEG_TO_LIN(pU->openParams.lpstrElementName)); - SEGPTR_FREE(pU); - return MCIERR_INTERNAL; - } + if (!STRCMP(keywords[i],"element") && (i+1openParams.lpstrElementName=strdup(keywords[i+1]); + i+=2; + continue; } - GetDrv(wDevID)->modp.wType = uDevTyp; - GetDrv(wDevID)->modp.wDeviceID = 0; /* FIXME? for multiple devices */ - pU->openParams.dwCallback = hwndCallback ; - pU->openParams.wDeviceID = wDevID; - pU->ovlyopenParams.dwStyle = 0; - pU->animopenParams.dwStyle = 0; - pU->openParams.lpstrDeviceType = (LPSTR)SEGPTR_GET(SEGPTR_STRDUP(dev)); - pU->openParams.lpstrAlias = NULL; - dwFlags |= MCI_OPEN_TYPE; - i=0; - while (iopenParams.lpstrAlias=(LPSTR)SEGPTR_GET(SEGPTR_STRDUP(keywords[i+1])); - i+=2; - continue; - } - if (!STRCMP(keywords[i],"element") && (i+1openParams.lpstrElementName=(LPSTR)SEGPTR_GET(SEGPTR_STRDUP(keywords[i+1])); - i+=2; - continue; - } - switch (uDevTyp) { - case MCI_DEVTYPE_ANIMATION: - case MCI_DEVTYPE_DIGITAL_VIDEO: - FLAG1("nostatic",MCI_ANIM_OPEN_NOSTATIC); - if (!STRCMP(keywords[i],"parent") && (i+1animopenParams.hWndParent)); - i+=2; - continue; - } - if (!STRCMP(keywords[i],"style") && (i+1animopenParams.dwStyle |= WS_POPUP; - } else if (!STRCMP(keywords[i+1],"overlap")) { - pU->animopenParams.dwStyle |= WS_OVERLAPPED; - } else if (!STRCMP(keywords[i+1],"child")) { - pU->animopenParams.dwStyle |= WS_CHILD; - } else if (sscanf(keywords[i+1],"%ld",&st)) { - pU->animopenParams.dwStyle |= st; - } else - FIXME(mci,"unknown 'style' keyword %s, please report.\n",keywords[i+1]); - i+=2; - continue; - } - break; - case MCI_DEVTYPE_WAVEFORM_AUDIO: - if (!STRCMP(keywords[i],"buffer") && (i+1waveopenParams.dwBufferSeconds)); - } - break; - case MCI_DEVTYPE_OVERLAY: - /* looks just like anim, but without NOSTATIC */ - if (!STRCMP(keywords[i],"parent") && (i+1ovlyopenParams.hWndParent)); - i+=2; - continue; - } - if (!STRCMP(keywords[i],"style") && (i+1ovlyopenParams.dwStyle |= WS_POPUP; - } else if (!STRCMP(keywords[i+1],"overlap")) { - pU->ovlyopenParams.dwStyle |= WS_OVERLAPPED; - } else if (!STRCMP(keywords[i+1],"child")) { - pU->ovlyopenParams.dwStyle |= WS_CHILD; - } else if (sscanf(keywords[i+1],"%ld",&st)) { - pU->ovlyopenParams.dwStyle |= st; - } else - FIXME(mci,"unknown 'style' keyword %s, please report.\n",keywords[i+1]); - i+=2; - continue; - } - break; - } - FIXME(mci,"unknown parameter passed %s, please report.\n", - keywords[i]); - i++; + switch (uDevTyp) { + case MCI_DEVTYPE_ANIMATION: + case MCI_DEVTYPE_DIGITAL_VIDEO: + FLAG1("nostatic",MCI_ANIM_OPEN_NOSTATIC); + if (!STRCMP(keywords[i],"parent") && (i+1animopenParams.hWndParent)); + i+=2; + continue; + } + if (!STRCMP(keywords[i],"style") && (i+1animopenParams.dwStyle |= WS_POPUP; + } else if (!STRCMP(keywords[i+1],"overlap")) { + pU->animopenParams.dwStyle |= WS_OVERLAPPED; + } else if (!STRCMP(keywords[i+1],"child")) { + pU->animopenParams.dwStyle |= WS_CHILD; + } else if (sscanf(keywords[i+1],"%ld",&st)) { + pU->animopenParams.dwStyle |= st; + } else + FIXME(mci,"unknown 'style' keyword %s, please report.\n",keywords[i+1]); + i+=2; + continue; + } + break; + case MCI_DEVTYPE_WAVEFORM_AUDIO: + if (!STRCMP(keywords[i],"buffer") && (i+1waveopenParams.dwBufferSeconds)); + } + break; + case MCI_DEVTYPE_OVERLAY: + /* looks just like anim, but without NOSTATIC */ + if (!STRCMP(keywords[i],"parent") && (i+1ovlyopenParams.hWndParent)); + i+=2; + continue; + } + if (!STRCMP(keywords[i],"style") && (i+1ovlyopenParams.dwStyle |= WS_POPUP; + } else if (!STRCMP(keywords[i+1],"overlap")) { + pU->ovlyopenParams.dwStyle |= WS_OVERLAPPED; + } else if (!STRCMP(keywords[i+1],"child")) { + pU->ovlyopenParams.dwStyle |= WS_CHILD; + } else if (sscanf(keywords[i+1],"%ld",&st)) { + pU->ovlyopenParams.dwStyle |= st; + } else + FIXME(mci,"unknown 'style' keyword %s, please report.\n",keywords[i+1]); + i+=2; + continue; + } + break; } - _MCI_CALL_DRIVER( MCI_OPEN, SEGPTR_GET(pU) ); - if (res==0) - memcpy(GetOpenDrv(wDevID),&pU->openParams,sizeof(MCI_OPEN_PARMS16)); - else { - SEGPTR_FREE(PTR_SEG_TO_LIN(pU->openParams.lpstrElementName)); - SEGPTR_FREE(PTR_SEG_TO_LIN(pU->openParams.lpstrDeviceType)); - SEGPTR_FREE(PTR_SEG_TO_LIN(pU->openParams.lpstrAlias)); - } - SEGPTR_FREE(pU); - return res; + FIXME(mci,"unknown parameter passed %s, please report.\n", + keywords[i]); + i++; + } + _MCI_CALL_DRIVER(MCI_OPEN, pU); + if (res==0) + memcpy(mciGetOpenDrv(wDevID),&pU->openParams,sizeof(MCI_OPEN_PARMS16)); + else { + free(pU->openParams.lpstrElementName); + free(pU->openParams.lpstrDeviceType); + free(pU->openParams.lpstrAlias); + } + free(pU); + return res; } /* A help function for a lot of others ... @@ -450,14 +445,14 @@ _MCISTR_determine_timeformat(LPCSTR dev,WORD wDevID,WORD uDevTyp,int *timef) { int res; DWORD dwFlags = MCI_STATUS_ITEM; - MCI_STATUS_PARMS *statusParams = SEGPTR_NEW(MCI_STATUS_PARMS); - + MCI_STATUS_PARMS *statusParams = xmalloc(sizeof(MCI_STATUS_PARMS)); + if (!statusParams) return 0; statusParams->dwItem = MCI_STATUS_TIME_FORMAT; statusParams->dwReturn = 0; - _MCI_CALL_DRIVER( MCI_STATUS, SEGPTR_GET(statusParams) ); + _MCI_CALL_DRIVER( MCI_STATUS, statusParams ); if (res==0) *timef = statusParams->dwReturn; - SEGPTR_FREE(statusParams); + free(statusParams); return res; } @@ -544,93 +539,93 @@ _MCISTR_determine_timeformat(LPCSTR dev,WORD wDevID,WORD uDevTyp,int *timef) } static DWORD MCISTR_Status(_MCISTR_PROTO_) { - MCI_STATUS_PARMS *statusParams = SEGPTR_NEW(MCI_STATUS_PARMS); - int type = 0,i,res,timef; - - statusParams->dwCallback = hwndCallback; - dwFlags |= MCI_STATUS_ITEM; - res = _MCISTR_determine_timeformat(dev,wDevID,uDevTyp,&timef); - if (res) return res; - - statusParams->dwReturn = 0; - statusParams->dwItem = 0; - i = 0; - - while (idwTrack)); - dwFlags |= MCI_TRACK; - i+=2; - continue; - } - FLAG1("start",MCI_STATUS_START); - /* generic things */ - ITEM2("current","track",MCI_STATUS_CURRENT_TRACK,_MCISTR_time); - ITEM2("time","format",MCI_STATUS_TIME_FORMAT,_MCISTR_tfname); - ITEM1("ready",MCI_STATUS_READY,_MCISTR_bool); - ITEM1("mode",MCI_STATUS_MODE,_MCISTR_mode); - ITEM3("number","of","tracks",MCI_STATUS_NUMBER_OF_TRACKS,_MCISTR_int); - ITEM1("length",MCI_STATUS_LENGTH,_MCISTR_time); - ITEM1("position",MCI_STATUS_POSITION,_MCISTR_time); - ITEM2("media","present",MCI_STATUS_MEDIA_PRESENT,_MCISTR_bool); - - switch (uDevTyp) { - case MCI_DEVTYPE_ANIMATION: - case MCI_DEVTYPE_DIGITAL_VIDEO: - ITEM2("palette","handle",MCI_ANIM_STATUS_HPAL,_MCISTR_int); - ITEM2("window","handle",MCI_ANIM_STATUS_HWND,_MCISTR_int); - ITEM1("stretch",MCI_ANIM_STATUS_STRETCH,_MCISTR_bool); - ITEM1("speed",MCI_ANIM_STATUS_SPEED,_MCISTR_int); - ITEM1("forward",MCI_ANIM_STATUS_FORWARD,_MCISTR_bool); - break; - case MCI_DEVTYPE_SEQUENCER: - /* just completing the list, not working correctly */ - ITEM2("division","type",MCI_SEQ_STATUS_DIVTYPE,_MCISTR_divtype); - /* tempo ... PPQN in frames/second, SMPTE in hmsf */ - ITEM1("tempo",MCI_SEQ_STATUS_TEMPO,_MCISTR_int); - ITEM1("port",MCI_SEQ_STATUS_PORT,_MCISTR_int); - ITEM1("slave",MCI_SEQ_STATUS_SLAVE,_MCISTR_seqtype); - ITEM1("master",MCI_SEQ_STATUS_SLAVE,_MCISTR_seqtype); - /* offset ... PPQN in frames/second, SMPTE in hmsf */ - ITEM1("offset",MCI_SEQ_STATUS_SLAVE,_MCISTR_time); - break; - case MCI_DEVTYPE_OVERLAY: - ITEM2("window","handle",MCI_OVLY_STATUS_HWND,_MCISTR_int); - ITEM1("stretch",MCI_OVLY_STATUS_STRETCH,_MCISTR_bool); - break; - case MCI_DEVTYPE_VIDEODISC: - ITEM1("speed",MCI_VD_STATUS_SPEED,_MCISTR_int); - ITEM1("forward",MCI_VD_STATUS_FORWARD,_MCISTR_bool); - ITEM1("side",MCI_VD_STATUS_SIDE,_MCISTR_int); - ITEM2("media","type",MCI_VD_STATUS_SIDE,_MCISTR_vdmtype); - /* returns 8 or 12 */ - ITEM2("disc","size",MCI_VD_STATUS_DISC_SIZE,_MCISTR_int); - break; - case MCI_DEVTYPE_WAVEFORM_AUDIO: - /* I am not quite sure if foll. 2 lines are right. */ - FLAG1("input",MCI_WAVE_INPUT); - FLAG1("output",MCI_WAVE_OUTPUT); - - ITEM2("format","tag",MCI_WAVE_STATUS_FORMATTAG,_MCISTR_int); - ITEM1("channels",MCI_WAVE_STATUS_CHANNELS,_MCISTR_int); - ITEM1("bytespersec",MCI_WAVE_STATUS_AVGBYTESPERSEC,_MCISTR_int); - ITEM1("samplespersec",MCI_WAVE_STATUS_SAMPLESPERSEC,_MCISTR_int); - ITEM1("bitspersample",MCI_WAVE_STATUS_BITSPERSAMPLE,_MCISTR_int); - ITEM1("alignment",MCI_WAVE_STATUS_BLOCKALIGN,_MCISTR_int); - ITEM1("level",MCI_WAVE_STATUS_LEVEL,_MCISTR_int); - break; - } - FIXME(mci,"unknown keyword '%s'\n",keywords[i]); - i++; + MCI_STATUS_PARMS *statusParams = xmalloc(sizeof(MCI_STATUS_PARMS)); + int type = 0,i,res,timef; + + statusParams->dwCallback = hwndCallback; + dwFlags |= MCI_STATUS_ITEM; + res = _MCISTR_determine_timeformat(dev,wDevID,uDevTyp,&timef); + if (res) return res; + + statusParams->dwReturn = 0; + statusParams->dwItem = 0; + i = 0; + + while (idwTrack)); + dwFlags |= MCI_TRACK; + i+=2; + continue; } - if (!statusParams->dwItem) - return MCIERR_MISSING_STRING_ARGUMENT; - - _MCI_CALL_DRIVER( MCI_STATUS, SEGPTR_GET(statusParams) ); - if (res==0) - _MCISTR_convreturn(type,statusParams->dwReturn,lpstrReturnString,uReturnLength,uDevTyp,timef); - SEGPTR_FREE(statusParams); - return res; + FLAG1("start",MCI_STATUS_START); + /* generic things */ + ITEM2("current","track",MCI_STATUS_CURRENT_TRACK,_MCISTR_time); + ITEM2("time","format",MCI_STATUS_TIME_FORMAT,_MCISTR_tfname); + ITEM1("ready",MCI_STATUS_READY,_MCISTR_bool); + ITEM1("mode",MCI_STATUS_MODE,_MCISTR_mode); + ITEM3("number","of","tracks",MCI_STATUS_NUMBER_OF_TRACKS,_MCISTR_int); + ITEM1("length",MCI_STATUS_LENGTH,_MCISTR_time); + ITEM1("position",MCI_STATUS_POSITION,_MCISTR_time); + ITEM2("media","present",MCI_STATUS_MEDIA_PRESENT,_MCISTR_bool); + + switch (uDevTyp) { + case MCI_DEVTYPE_ANIMATION: + case MCI_DEVTYPE_DIGITAL_VIDEO: + ITEM2("palette","handle",MCI_ANIM_STATUS_HPAL,_MCISTR_int); + ITEM2("window","handle",MCI_ANIM_STATUS_HWND,_MCISTR_int); + ITEM1("stretch",MCI_ANIM_STATUS_STRETCH,_MCISTR_bool); + ITEM1("speed",MCI_ANIM_STATUS_SPEED,_MCISTR_int); + ITEM1("forward",MCI_ANIM_STATUS_FORWARD,_MCISTR_bool); + break; + case MCI_DEVTYPE_SEQUENCER: + /* just completing the list, not working correctly */ + ITEM2("division","type",MCI_SEQ_STATUS_DIVTYPE,_MCISTR_divtype); + /* tempo ... PPQN in frames/second, SMPTE in hmsf */ + ITEM1("tempo",MCI_SEQ_STATUS_TEMPO,_MCISTR_int); + ITEM1("port",MCI_SEQ_STATUS_PORT,_MCISTR_int); + ITEM1("slave",MCI_SEQ_STATUS_SLAVE,_MCISTR_seqtype); + ITEM1("master",MCI_SEQ_STATUS_SLAVE,_MCISTR_seqtype); + /* offset ... PPQN in frames/second, SMPTE in hmsf */ + ITEM1("offset",MCI_SEQ_STATUS_SLAVE,_MCISTR_time); + break; + case MCI_DEVTYPE_OVERLAY: + ITEM2("window","handle",MCI_OVLY_STATUS_HWND,_MCISTR_int); + ITEM1("stretch",MCI_OVLY_STATUS_STRETCH,_MCISTR_bool); + break; + case MCI_DEVTYPE_VIDEODISC: + ITEM1("speed",MCI_VD_STATUS_SPEED,_MCISTR_int); + ITEM1("forward",MCI_VD_STATUS_FORWARD,_MCISTR_bool); + ITEM1("side",MCI_VD_STATUS_SIDE,_MCISTR_int); + ITEM2("media","type",MCI_VD_STATUS_SIDE,_MCISTR_vdmtype); + /* returns 8 or 12 */ + ITEM2("disc","size",MCI_VD_STATUS_DISC_SIZE,_MCISTR_int); + break; + case MCI_DEVTYPE_WAVEFORM_AUDIO: + /* I am not quite sure if foll. 2 lines are right. */ + FLAG1("input",MCI_WAVE_INPUT); + FLAG1("output",MCI_WAVE_OUTPUT); + + ITEM2("format","tag",MCI_WAVE_STATUS_FORMATTAG,_MCISTR_int); + ITEM1("channels",MCI_WAVE_STATUS_CHANNELS,_MCISTR_int); + ITEM1("bytespersec",MCI_WAVE_STATUS_AVGBYTESPERSEC,_MCISTR_int); + ITEM1("samplespersec",MCI_WAVE_STATUS_SAMPLESPERSEC,_MCISTR_int); + ITEM1("bitspersample",MCI_WAVE_STATUS_BITSPERSAMPLE,_MCISTR_int); + ITEM1("alignment",MCI_WAVE_STATUS_BLOCKALIGN,_MCISTR_int); + ITEM1("level",MCI_WAVE_STATUS_LEVEL,_MCISTR_int); + break; + } + FIXME(mci,"unknown keyword '%s'\n",keywords[i]); + i++; + } + if (!statusParams->dwItem) + return MCIERR_MISSING_STRING_ARGUMENT; + + _MCI_CALL_DRIVER( MCI_STATUS, statusParams ); + if (res==0) + _MCISTR_convreturn(type,statusParams->dwReturn,lpstrReturnString,uReturnLength,uDevTyp,timef); + free(statusParams); + return res; } #undef ITEM1 #undef ITEM2 @@ -668,99 +663,99 @@ MCISTR_Status(_MCISTR_PROTO_) { */ static DWORD MCISTR_Set(_MCISTR_PROTO_) { - union U { - MCI_SET_PARMS setParams; - MCI_WAVE_SET_PARMS16 wavesetParams; - MCI_SEQ_SET_PARMS seqsetParams; - }; - union U *pU = SEGPTR_NEW(union U); - int i,res; - - pU->setParams.dwCallback = hwndCallback; - i = 0; - while (isetParams.dwCallback = hwndCallback; + i = 0; + while (isetParams.dwTimeFormat = MCI_FORMAT_MILLISECONDS; - - if (!STRCMP(keywords[i+2],"milliseconds")) - pU->setParams.dwTimeFormat = MCI_FORMAT_MILLISECONDS; - if (!STRCMP(keywords[i+2],"msf")) - pU->setParams.dwTimeFormat = MCI_FORMAT_MSF; - if (!STRCMP(keywords[i+2],"hms")) - pU->setParams.dwTimeFormat = MCI_FORMAT_HMS; - if (!STRCMP(keywords[i+2],"frames")) - pU->setParams.dwTimeFormat = MCI_FORMAT_FRAMES; - if (!STRCMP(keywords[i+2],"track")) - pU->setParams.dwTimeFormat = MCI_VD_FORMAT_TRACK; - if (!STRCMP(keywords[i+2],"bytes")) - pU->setParams.dwTimeFormat = MCI_FORMAT_BYTES; - if (!STRCMP(keywords[i+2],"samples")) - pU->setParams.dwTimeFormat = MCI_FORMAT_SAMPLES; - if (!STRCMP(keywords[i+2],"tmsf")) - pU->setParams.dwTimeFormat = MCI_FORMAT_TMSF; - if ( !STRCMP(keywords[i+2],"song") && - (i+3setParams.dwTimeFormat = MCI_FORMAT_MILLISECONDS; + + if (!STRCMP(keywords[i+2],"milliseconds")) + pU->setParams.dwTimeFormat = MCI_FORMAT_MILLISECONDS; + if (!STRCMP(keywords[i+2],"msf")) + pU->setParams.dwTimeFormat = MCI_FORMAT_MSF; + if (!STRCMP(keywords[i+2],"hms")) + pU->setParams.dwTimeFormat = MCI_FORMAT_HMS; + if (!STRCMP(keywords[i+2],"frames")) + pU->setParams.dwTimeFormat = MCI_FORMAT_FRAMES; + if (!STRCMP(keywords[i+2],"track")) + pU->setParams.dwTimeFormat = MCI_VD_FORMAT_TRACK; + if (!STRCMP(keywords[i+2],"bytes")) + pU->setParams.dwTimeFormat = MCI_FORMAT_BYTES; + if (!STRCMP(keywords[i+2],"samples")) + pU->setParams.dwTimeFormat = MCI_FORMAT_SAMPLES; + if (!STRCMP(keywords[i+2],"tmsf")) + pU->setParams.dwTimeFormat = MCI_FORMAT_TMSF; + if ( !STRCMP(keywords[i+2],"song") && + (i+3setParams.dwTimeFormat = MCI_SEQ_FORMAT_SONGPTR; - if (!STRCMP(keywords[i+2],"smpte") && (i+3setParams.dwTimeFormat = MCI_FORMAT_SMPTE_24; - if (!STRCMP(keywords[i+3],"25")) - pU->setParams.dwTimeFormat = MCI_FORMAT_SMPTE_25; - if (!STRCMP(keywords[i+3],"30")) - pU->setParams.dwTimeFormat = MCI_FORMAT_SMPTE_30; - if (!STRCMP(keywords[i+3],"drop") && (i+4setParams.dwTimeFormat = MCI_FORMAT_SMPTE_30DROP; - i++; - } - i++; + pU->setParams.dwTimeFormat = MCI_SEQ_FORMAT_SONGPTR; + if (!STRCMP(keywords[i+2],"smpte") && (i+3setParams.dwTimeFormat = MCI_FORMAT_SMPTE_24; + if (!STRCMP(keywords[i+3],"25")) + pU->setParams.dwTimeFormat = MCI_FORMAT_SMPTE_25; + if (!STRCMP(keywords[i+3],"30")) + pU->setParams.dwTimeFormat = MCI_FORMAT_SMPTE_30; + if (!STRCMP(keywords[i+3],"drop") && (i+4setParams.dwTimeFormat = MCI_FORMAT_SMPTE_30DROP; + i++; + } + i++; /*FALLTHROUGH*/ - } - i+=3; - continue; - } - if (!STRCMP(keywords[i],"audio") && (i+1setParams.dwAudio = MCI_SET_AUDIO_ALL; - if (!STRCMP(keywords[i+1],"left")) - pU->setParams.dwAudio = MCI_SET_AUDIO_LEFT; - if (!STRCMP(keywords[i+1],"right")) - pU->setParams.dwAudio = MCI_SET_AUDIO_RIGHT; - i+=2; - continue; - } - FLAG1("video",MCI_SET_VIDEO); - FLAG1("on",MCI_SET_ON); - FLAG1("off",MCI_SET_OFF); - switch (uDevTyp) { - case MCI_DEVTYPE_WAVEFORM_AUDIO: - FLAG2("any","input",MCI_WAVE_SET_ANYINPUT); - FLAG2("any","output",MCI_WAVE_SET_ANYOUTPUT); - - if ( !STRCMP(keywords[i],"formattag") && - (i+1setParams.dwAudio = MCI_SET_AUDIO_ALL; + if (!STRCMP(keywords[i+1],"left")) + pU->setParams.dwAudio = MCI_SET_AUDIO_LEFT; + if (!STRCMP(keywords[i+1],"right")) + pU->setParams.dwAudio = MCI_SET_AUDIO_RIGHT; + i+=2; + continue; + } + FLAG1("video",MCI_SET_VIDEO); + FLAG1("on",MCI_SET_ON); + FLAG1("off",MCI_SET_OFF); + switch (uDevTyp) { + case MCI_DEVTYPE_WAVEFORM_AUDIO: + FLAG2("any","input",MCI_WAVE_SET_ANYINPUT); + FLAG2("any","output",MCI_WAVE_SET_ANYOUTPUT); + + if ( !STRCMP(keywords[i],"formattag") && + (i+1wavesetParams.wFormatTag = WAVE_FORMAT_PCM; - i+=2; - continue; - } - - /* */ + dwFlags |= MCI_WAVE_SET_FORMATTAG; + pU->wavesetParams.wFormatTag = WAVE_FORMAT_PCM; + i+=2; + continue; + } + + /* */ #define WII(str,flag,fmt,element) \ if (!STRCMP(keywords[i],str) && (i+1wavesetParams. element ));\ @@ -768,52 +763,52 @@ MCISTR_Set(_MCISTR_PROTO_) { i+=2;\ continue;\ } - WII("formattag",MCI_WAVE_SET_FORMATTAG,"%hu",wFormatTag); - WII("channels",MCI_WAVE_SET_CHANNELS,"%hu",nChannels); - WII("bytespersec",MCI_WAVE_SET_AVGBYTESPERSEC,"%lu",nAvgBytesPerSec); - WII("samplespersec",MCI_WAVE_SET_SAMPLESPERSEC,"%lu",nSamplesPerSec); - WII("alignment",MCI_WAVE_SET_BLOCKALIGN,"%hu",nBlockAlign); - WII("bitspersample",MCI_WAVE_SET_BITSPERSAMPLE,"%hu",wBitsPerSample); - WII("input",MCI_WAVE_INPUT,"%hu",wInput); - WII("output",MCI_WAVE_OUTPUT,"%hu",wOutput); + WII("formattag",MCI_WAVE_SET_FORMATTAG,"%hu",wFormatTag); + WII("channels",MCI_WAVE_SET_CHANNELS,"%hu",nChannels); + WII("bytespersec",MCI_WAVE_SET_AVGBYTESPERSEC,"%lu",nAvgBytesPerSec); + WII("samplespersec",MCI_WAVE_SET_SAMPLESPERSEC,"%lu",nSamplesPerSec); + WII("alignment",MCI_WAVE_SET_BLOCKALIGN,"%hu",nBlockAlign); + WII("bitspersample",MCI_WAVE_SET_BITSPERSAMPLE,"%hu",wBitsPerSample); + WII("input",MCI_WAVE_INPUT,"%hu",wInput); + WII("output",MCI_WAVE_OUTPUT,"%hu",wOutput); #undef WII - break; - case MCI_DEVTYPE_SEQUENCER: - if (!STRCMP(keywords[i],"master") && (i+1seqsetParams.dwMaster = MCI_SEQ_MIDI; - if (!STRCMP(keywords[i+1],"file")) - pU->seqsetParams.dwMaster = MCI_SEQ_FILE; - if (!STRCMP(keywords[i+1],"smpte")) - pU->seqsetParams.dwMaster = MCI_SEQ_SMPTE; - if (!STRCMP(keywords[i+1],"none")) - pU->seqsetParams.dwMaster = MCI_SEQ_NONE; - i+=2; - continue; - } - if (!STRCMP(keywords[i],"slave") && (i+1seqsetParams.dwMaster = MCI_SEQ_MIDI; - if (!STRCMP(keywords[i+1],"file")) - pU->seqsetParams.dwMaster = MCI_SEQ_FILE; - if (!STRCMP(keywords[i+1],"smpte")) - pU->seqsetParams.dwMaster = MCI_SEQ_SMPTE; - if (!STRCMP(keywords[i+1],"none")) - pU->seqsetParams.dwMaster = MCI_SEQ_NONE; - i+=2; - continue; - } - if ( !STRCMP(keywords[i],"port") && - (i+1seqsetParams.dwMaster = MCI_SEQ_MIDI; + if (!STRCMP(keywords[i+1],"file")) + pU->seqsetParams.dwMaster = MCI_SEQ_FILE; + if (!STRCMP(keywords[i+1],"smpte")) + pU->seqsetParams.dwMaster = MCI_SEQ_SMPTE; + if (!STRCMP(keywords[i+1],"none")) + pU->seqsetParams.dwMaster = MCI_SEQ_NONE; + i+=2; + continue; + } + if (!STRCMP(keywords[i],"slave") && (i+1seqsetParams.dwMaster = MCI_SEQ_MIDI; + if (!STRCMP(keywords[i+1],"file")) + pU->seqsetParams.dwMaster = MCI_SEQ_FILE; + if (!STRCMP(keywords[i+1],"smpte")) + pU->seqsetParams.dwMaster = MCI_SEQ_SMPTE; + if (!STRCMP(keywords[i+1],"none")) + pU->seqsetParams.dwMaster = MCI_SEQ_NONE; + i+=2; + continue; + } + if ( !STRCMP(keywords[i],"port") && + (i+1seqsetParams.dwPort=-1;/* FIXME:not sure*/ - dwFlags |= MCI_SEQ_SET_PORT; - i+=2; - continue; - } + pU->seqsetParams.dwPort=-1;/* FIXME:not sure*/ + dwFlags |= MCI_SEQ_SET_PORT; + i+=2; + continue; + } #define SII(str,flag,element) \ if (!STRCMP(keywords[i],str) && (i+1seqsetParams. element ));\ @@ -821,17 +816,17 @@ MCISTR_Set(_MCISTR_PROTO_) { i+=2;\ continue;\ } - SII("tempo",MCI_SEQ_SET_TEMPO,dwTempo); - SII("port",MCI_SEQ_SET_PORT,dwPort); - SII("offset",MCI_SEQ_SET_PORT,dwOffset); - } - i++; + SII("tempo",MCI_SEQ_SET_TEMPO,dwTempo); + SII("port",MCI_SEQ_SET_PORT,dwPort); + SII("offset",MCI_SEQ_SET_PORT,dwOffset); } - if (!dwFlags) - return MCIERR_MISSING_STRING_ARGUMENT; - _MCI_CALL_DRIVER( MCI_SET, SEGPTR_GET(pU) ); - SEGPTR_FREE(pU); - return res; + i++; + } + if (!dwFlags) + return MCIERR_MISSING_STRING_ARGUMENT; + _MCI_CALL_DRIVER( MCI_SET, pU ); + free(pU); + return res; } /* specify break key @@ -846,24 +841,23 @@ MCISTR_Set(_MCISTR_PROTO_) { static DWORD MCISTR_Break(_MCISTR_PROTO_) { - MCI_BREAK_PARMS16 *breakParams = SEGPTR_NEW(MCI_BREAK_PARMS16); + MCI_BREAK_PARMS16 *breakParams = xmalloc(sizeof(MCI_BREAK_PARMS16)); int res,i; - + if (!breakParams) return 0; - /*breakParams.hwndBreak ? */ - for (i = 0; i < nrofkeywords; i++) - { - FLAG1("off",MCI_BREAK_OFF); - if (!strcmp(keywords[i],"on") && (nrofkeywords>i+1)) { - dwFlags&=~MCI_BREAK_OFF; - dwFlags|=MCI_BREAK_KEY; - sscanf(keywords[i+1],"%hd",&(breakParams->nVirtKey)); - i+=2; - continue; - } + /*breakParams.hwndBreak ? */ + for (i = 0; i < nrofkeywords; i++) { + FLAG1("off",MCI_BREAK_OFF); + if (!strcmp(keywords[i],"on") && (nrofkeywords>i+1)) { + dwFlags&=~MCI_BREAK_OFF; + dwFlags|=MCI_BREAK_KEY; + sscanf(keywords[i+1],"%hd",&(breakParams->nVirtKey)); + i+=2; + continue; + } } - _MCI_CALL_DRIVER( MCI_BREAK, SEGPTR_GET(breakParams) ); - SEGPTR_FREE(breakParams); + _MCI_CALL_DRIVER( MCI_BREAK, breakParams ); + free(breakParams); return res; } @@ -932,63 +926,63 @@ MCISTR_Break(_MCISTR_PROTO_) */ static DWORD MCISTR_Capability(_MCISTR_PROTO_) { - MCI_GETDEVCAPS_PARMS *gdcParams = SEGPTR_NEW(MCI_GETDEVCAPS_PARMS); - int type=0,i,res; - - gdcParams->dwCallback = hwndCallback; - if (!nrofkeywords) - return MCIERR_MISSING_STRING_ARGUMENT; - /* well , thats default */ - dwFlags |= MCI_GETDEVCAPS_ITEM; - gdcParams->dwItem = 0; - i=0; - while (idwCallback = hwndCallback; + if (!nrofkeywords) + return MCIERR_MISSING_STRING_ARGUMENT; + /* well , thats default */ + dwFlags |= MCI_GETDEVCAPS_ITEM; + gdcParams->dwItem = 0; + i=0; + while (idwReturn, lpstrReturnString, - uReturnLength, uDevTyp, 0 ); - SEGPTR_FREE(gdcParams); - return res; + i++; + } + _MCI_CALL_DRIVER( MCI_GETDEVCAPS, gdcParams ); + /* no timeformat needed */ + if (res==0) + _MCISTR_convreturn( type, gdcParams->dwReturn, lpstrReturnString, + uReturnLength, uDevTyp, 0 ); + free(gdcParams); + return res; } #undef ITEM1 #undef ITEM2 @@ -997,10 +991,10 @@ MCISTR_Capability(_MCISTR_PROTO_) { static DWORD MCISTR_Resume(_MCISTR_PROTO_) { - MCI_GENERIC_PARMS *genParams = SEGPTR_NEW(MCI_GENERIC_PARMS); + MCI_GENERIC_PARMS *genParams = xmalloc(sizeof(MCI_GENERIC_PARMS)); int res; genParams->dwCallback = hwndCallback; - _MCI_CALL_DRIVER( MCI_RESUME, SEGPTR_GET(genParams) ); + _MCI_CALL_DRIVER( MCI_RESUME, genParams ); return res; } @@ -1008,10 +1002,10 @@ MCISTR_Resume(_MCISTR_PROTO_) static DWORD MCISTR_Pause(_MCISTR_PROTO_) { - MCI_GENERIC_PARMS *genParams = SEGPTR_NEW(MCI_GENERIC_PARMS); + MCI_GENERIC_PARMS *genParams = xmalloc(sizeof(MCI_GENERIC_PARMS)); int res; genParams->dwCallback = hwndCallback; - _MCI_CALL_DRIVER( MCI_PAUSE, SEGPTR_GET(genParams) ); + _MCI_CALL_DRIVER( MCI_PAUSE, genParams ); return res; } @@ -1019,10 +1013,10 @@ MCISTR_Pause(_MCISTR_PROTO_) static DWORD MCISTR_Stop(_MCISTR_PROTO_) { - MCI_GENERIC_PARMS *genParams = SEGPTR_NEW(MCI_GENERIC_PARMS); + MCI_GENERIC_PARMS *genParams = xmalloc(sizeof(MCI_GENERIC_PARMS)); int res; genParams->dwCallback = hwndCallback; - _MCI_CALL_DRIVER( MCI_STOP, SEGPTR_GET(genParams) ); + _MCI_CALL_DRIVER( MCI_STOP, genParams ); return res; } @@ -1035,70 +1029,70 @@ MCISTR_Stop(_MCISTR_PROTO_) */ static DWORD MCISTR_Record(_MCISTR_PROTO_) { - int i,res,timef,nrargs,j,k,a[4]; - char *parsestr; - MCI_RECORD_PARMS *recordParams = SEGPTR_NEW(MCI_RECORD_PARMS); - - res = _MCISTR_determine_timeformat(dev,wDevID,uDevTyp,&timef); - if (res) return res; - - switch (timef) { - case MCI_FORMAT_MILLISECONDS: - case MCI_FORMAT_FRAMES: - case MCI_FORMAT_BYTES: - case MCI_FORMAT_SAMPLES: - nrargs=1; - parsestr="%d"; - break; - case MCI_FORMAT_HMS: - case MCI_FORMAT_MSF: - parsestr="%d:%d:%d"; - nrargs=3; - break; - case MCI_FORMAT_TMSF: - parsestr="%d:%d:%d:%d"; - nrargs=4; - break; - default:FIXME(mci,"unknown timeformat %d, please report.\n",timef); - parsestr="%d"; - nrargs=1; - break; + int i,res,timef,nrargs,j,k,a[4]; + char *parsestr; + MCI_RECORD_PARMS *recordParams = xmalloc(sizeof(MCI_RECORD_PARMS)); + + res = _MCISTR_determine_timeformat(dev,wDevID,uDevTyp,&timef); + if (res) return res; + + switch (timef) { + case MCI_FORMAT_MILLISECONDS: + case MCI_FORMAT_FRAMES: + case MCI_FORMAT_BYTES: + case MCI_FORMAT_SAMPLES: + nrargs=1; + parsestr="%d"; + break; + case MCI_FORMAT_HMS: + case MCI_FORMAT_MSF: + parsestr="%d:%d:%d"; + nrargs=3; + break; + case MCI_FORMAT_TMSF: + parsestr="%d:%d:%d:%d"; + nrargs=4; + break; + default:FIXME(mci,"unknown timeformat %d, please report.\n",timef); + parsestr="%d"; + nrargs=1; + break; + } + recordParams->dwCallback = hwndCallback; + i = 0; + while (idwTo=0; + for (k=0;kdwTo+=a[k]<<(8*(nrargs-k)); + i+=2; + continue; } - recordParams->dwCallback = hwndCallback; - i = 0; - while (idwTo=0; - for (k=0;kdwTo+=a[k]<<(8*(nrargs-k)); - i+=2; - continue; - } - if (!strcmp(keywords[i],"from") && (i+1dwFrom=0; - for (k=0;kdwFrom+=a[k]<<(8*(nrargs-k)); - i+=2; - continue; - } - FLAG1("insert",MCI_RECORD_INSERT); - FLAG1("overwrite",MCI_RECORD_OVERWRITE); - i++; + if (!strcmp(keywords[i],"from") && (i+1dwFrom=0; + for (k=0;kdwFrom+=a[k]<<(8*(nrargs-k)); + i+=2; + continue; } - _MCI_CALL_DRIVER( MCI_RECORD, SEGPTR_GET(recordParams) ); - SEGPTR_FREE(recordParams); - return res; + FLAG1("insert",MCI_RECORD_INSERT); + FLAG1("overwrite",MCI_RECORD_OVERWRITE); + i++; + } + _MCI_CALL_DRIVER( MCI_RECORD, recordParams ); + free(recordParams); + return res; } /* play media @@ -1120,98 +1114,98 @@ MCISTR_Record(_MCISTR_PROTO_) { */ static DWORD MCISTR_Play(_MCISTR_PROTO_) { - int i,res,timef,nrargs,j,k,a[4]; - char *parsestr; - union U { - MCI_PLAY_PARMS playParams; - MCI_VD_PLAY_PARMS vdplayParams; - MCI_ANIM_PLAY_PARMS animplayParams; - }; - union U *pU = SEGPTR_NEW(union U); - - res = _MCISTR_determine_timeformat(dev,wDevID,uDevTyp,&timef); - if (res) return res; - switch (timef) { - case MCI_FORMAT_MILLISECONDS: - case MCI_FORMAT_FRAMES: - case MCI_FORMAT_BYTES: - case MCI_FORMAT_SAMPLES: - nrargs=1; - parsestr="%d"; - break; - case MCI_FORMAT_HMS: - case MCI_FORMAT_MSF: - parsestr="%d:%d:%d"; - nrargs=3; - break; - case MCI_FORMAT_TMSF: - parsestr="%d:%d:%d:%d"; - nrargs=4; - break; - default:FIXME(mci,"unknown timeformat %d, please report.\n",timef); - parsestr="%d"; - nrargs=1; - break; + int i,res,timef,nrargs,j,k,a[4]; + char *parsestr; + union U { + MCI_PLAY_PARMS playParams; + MCI_VD_PLAY_PARMS vdplayParams; + MCI_ANIM_PLAY_PARMS animplayParams; + }; + union U *pU = xmalloc(sizeof(union U)); + + res = _MCISTR_determine_timeformat(dev,wDevID,uDevTyp,&timef); + if (res) return res; + switch (timef) { + case MCI_FORMAT_MILLISECONDS: + case MCI_FORMAT_FRAMES: + case MCI_FORMAT_BYTES: + case MCI_FORMAT_SAMPLES: + nrargs=1; + parsestr="%d"; + break; + case MCI_FORMAT_HMS: + case MCI_FORMAT_MSF: + parsestr="%d:%d:%d"; + nrargs=3; + break; + case MCI_FORMAT_TMSF: + parsestr="%d:%d:%d:%d"; + nrargs=4; + break; + default:FIXME(mci,"unknown timeformat %d, please report.\n",timef); + parsestr="%d"; + nrargs=1; + break; + } + pU->playParams.dwCallback=hwndCallback; + i=0; + while (iplayParams.dwTo=0; + for (k=0;kplayParams.dwTo+=a[k]<<(8*(nrargs-k)); + i+=2; + continue; } - pU->playParams.dwCallback=hwndCallback; - i=0; - while (iplayParams.dwTo=0; - for (k=0;kplayParams.dwTo+=a[k]<<(8*(nrargs-k)); - i+=2; - continue; - } - if (!strcmp(keywords[i],"from") && (i+1playParams.dwFrom=0; - for (k=0;kplayParams.dwFrom+=a[k]<<(8*(nrargs-k)); - i+=2; - continue; - } - switch (uDevTyp) { - case MCI_DEVTYPE_VIDEODISC: - FLAG1("slow",MCI_VD_PLAY_SLOW); - FLAG1("fast",MCI_VD_PLAY_FAST); - FLAG1("scan",MCI_VD_PLAY_SCAN); - FLAG1("reverse",MCI_VD_PLAY_REVERSE); - if (!STRCMP(keywords[i],"speed") && (i+1vdplayParams.dwSpeed)); - i+=2; - continue; - } - break; - case MCI_DEVTYPE_ANIMATION: - FLAG1("slow",MCI_ANIM_PLAY_SLOW); - FLAG1("fast",MCI_ANIM_PLAY_FAST); - FLAG1("scan",MCI_ANIM_PLAY_SCAN); - FLAG1("reverse",MCI_ANIM_PLAY_REVERSE); - if (!STRCMP(keywords[i],"speed") && (i+1animplayParams.dwSpeed)); - i+=2; - continue; - } - break; - } - i++; + if (!strcmp(keywords[i],"from") && (i+1playParams.dwFrom=0; + for (k=0;kplayParams.dwFrom+=a[k]<<(8*(nrargs-k)); + i+=2; + continue; } - _MCI_CALL_DRIVER( MCI_PLAY, SEGPTR_GET(pU) ); - SEGPTR_FREE(pU); - return res; + switch (uDevTyp) { + case MCI_DEVTYPE_VIDEODISC: + FLAG1("slow",MCI_VD_PLAY_SLOW); + FLAG1("fast",MCI_VD_PLAY_FAST); + FLAG1("scan",MCI_VD_PLAY_SCAN); + FLAG1("reverse",MCI_VD_PLAY_REVERSE); + if (!STRCMP(keywords[i],"speed") && (i+1vdplayParams.dwSpeed)); + i+=2; + continue; + } + break; + case MCI_DEVTYPE_ANIMATION: + FLAG1("slow",MCI_ANIM_PLAY_SLOW); + FLAG1("fast",MCI_ANIM_PLAY_FAST); + FLAG1("scan",MCI_ANIM_PLAY_SCAN); + FLAG1("reverse",MCI_ANIM_PLAY_REVERSE); + if (!STRCMP(keywords[i],"speed") && (i+1animplayParams.dwSpeed)); + i+=2; + continue; + } + break; + } + i++; + } + _MCI_CALL_DRIVER( MCI_PLAY, pU ); + free(pU); + return res; } /* seek to a specified position @@ -1222,79 +1216,79 @@ MCISTR_Play(_MCISTR_PROTO_) { */ static DWORD MCISTR_Seek(_MCISTR_PROTO_) { - int i,res,timef,nrargs,j,k,a[4]; - char *parsestr; - MCI_SEEK_PARMS *seekParams = SEGPTR_NEW(MCI_SEEK_PARMS); - - res = _MCISTR_determine_timeformat(dev,wDevID,uDevTyp,&timef); - if (res) return res; - switch (timef) { - case MCI_FORMAT_MILLISECONDS: - case MCI_FORMAT_FRAMES: - case MCI_FORMAT_BYTES: - case MCI_FORMAT_SAMPLES: - nrargs=1; - parsestr="%d"; - break; - case MCI_FORMAT_HMS: - case MCI_FORMAT_MSF: - parsestr="%d:%d:%d"; - nrargs=3; - break; - case MCI_FORMAT_TMSF: - parsestr="%d:%d:%d:%d"; - nrargs=4; - break; - default:FIXME(mci,"unknown timeformat %d, please report.\n",timef); - parsestr="%d"; - nrargs=1; - break; + int i,res,timef,nrargs,j,k,a[4]; + char *parsestr; + MCI_SEEK_PARMS *seekParams = xmalloc(sizeof(MCI_SEEK_PARMS)); + + res = _MCISTR_determine_timeformat(dev,wDevID,uDevTyp,&timef); + if (res) return res; + switch (timef) { + case MCI_FORMAT_MILLISECONDS: + case MCI_FORMAT_FRAMES: + case MCI_FORMAT_BYTES: + case MCI_FORMAT_SAMPLES: + nrargs=1; + parsestr="%d"; + break; + case MCI_FORMAT_HMS: + case MCI_FORMAT_MSF: + parsestr="%d:%d:%d"; + nrargs=3; + break; + case MCI_FORMAT_TMSF: + parsestr="%d:%d:%d:%d"; + nrargs=4; + break; + default:FIXME(mci,"unknown timeformat %d, please report.\n",timef); + parsestr="%d"; + nrargs=1; + break; + } + seekParams->dwCallback=hwndCallback; + i=0; + while (idwTo=0; + i+=2; + continue; + } + if (!STRCMP(keywords[i+1],"end")) { + dwFlags|=MCI_SEEK_TO_END; + seekParams->dwTo=0; + i+=2; + continue; + } + dwFlags|=MCI_TO; + i+=2; + a[0]=a[1]=a[2]=a[3]=0; + j=sscanf(keywords[i+1],parsestr,&a[0],&a[1],&a[2],&a[3]); + seekParams->dwTo=0; + for (k=0;kdwTo+=a[k]<<(8*(nrargs-k)); + continue; } - seekParams->dwCallback=hwndCallback; - i=0; - while (idwTo=0; - i+=2; - continue; - } - if (!STRCMP(keywords[i+1],"end")) { - dwFlags|=MCI_SEEK_TO_END; - seekParams->dwTo=0; - i+=2; - continue; - } - dwFlags|=MCI_TO; - i+=2; - a[0]=a[1]=a[2]=a[3]=0; - j=sscanf(keywords[i+1],parsestr,&a[0],&a[1],&a[2],&a[3]); - seekParams->dwTo=0; - for (k=0;kdwTo+=a[k]<<(8*(nrargs-k)); - continue; - } - switch (uDevTyp) { - case MCI_DEVTYPE_VIDEODISC: - FLAG1("reverse",MCI_VD_SEEK_REVERSE); - break; - } - i++; + switch (uDevTyp) { + case MCI_DEVTYPE_VIDEODISC: + FLAG1("reverse",MCI_VD_SEEK_REVERSE); + break; } - _MCI_CALL_DRIVER( MCI_SEEK, SEGPTR_GET(seekParams) ); - SEGPTR_FREE(seekParams); - return res; + i++; + } + _MCI_CALL_DRIVER( MCI_SEEK, seekParams ); + free(seekParams); + return res; } /* close media/driver */ static DWORD MCISTR_Close(_MCISTR_PROTO_) { - MCI_GENERIC_PARMS *closeParams = SEGPTR_NEW(MCI_GENERIC_PARMS); + MCI_GENERIC_PARMS *closeParams = xmalloc(sizeof(MCI_GENERIC_PARMS)); int res; - _MCI_CALL_DRIVER( MCI_CLOSE, SEGPTR_GET(closeParams) ); - SEGPTR_FREE(closeParams); + _MCI_CALL_DRIVER( MCI_CLOSE, closeParams ); + free(closeParams); return res; } @@ -1310,38 +1304,36 @@ MCISTR_Close(_MCISTR_PROTO_) static DWORD MCISTR_Info(_MCISTR_PROTO_) { - MCI_INFO_PARMS16 *infoParams = SEGPTR_NEW(MCI_INFO_PARMS16); - DWORD sflags; - int i,res; - - sflags = dwFlags; - i=0;while (ilpstrReturn); - SEGPTR_FREE(infoParams); - return res; + i++; + } + if (dwFlags == sflags) + return MCIERR_MISSING_STRING_ARGUMENT; + /* MCI driver will fill in lpstrReturn, dwRetSize. + * FIXME: I don't know if this is correct behaviour + */ + _MCI_CALL_DRIVER( MCI_INFO, infoParams ); + if (res==0) + _MCI_STR(infoParams->lpstrReturn); + free(infoParams); + return res; } -DWORD mciSysInfo(DWORD dwFlags,LPMCI_SYSINFO_PARMS16 lpParms); - /* query MCI driver itself for information * Arguments: * "installname" return install name of (system.ini) @@ -1350,38 +1342,37 @@ DWORD mciSysInfo(DWORD dwFlags,LPMCI_SYSINFO_PARMS16 lpParms); * "name " return nr of devices with * "name all" return nr of all devices * - * FIXME: mciSysInfo() is broken I think. + * FIXME: mciSysInfo16() is broken I think. */ static DWORD MCISTR_Sysinfo(_MCISTR_PROTO_) { - MCI_SYSINFO_PARMS16 sysinfoParams; - int i,res; - - sysinfoParams.lpstrReturn = lpstrReturnString; - sysinfoParams.dwRetSize = uReturnLength; - sysinfoParams.wDeviceType = uDevTyp; - i=0; - while (iovlyloadParams.rc.left)); - sscanf(keywords[i+2],"%hd",&(pU->ovlyloadParams.rc.top)); - sscanf(keywords[i+3],"%hd",&(pU->ovlyloadParams.rc.right)); - sscanf(keywords[i+4],"%hd",&(pU->ovlyloadParams.rc.bottom)); - memcpy(keywords+i,keywords+(i+5),nrofkeywords-(i+5)); - continue; - } - break; - } - len+=strlen(keywords[i])+1; - i++; + union U { + MCI_LOAD_PARMS16 loadParams; + MCI_OVLY_LOAD_PARMS16 ovlyloadParams; + }; + union U *pU = xmalloc(sizeof(union U)); + int i,len,res; + char *s; + + i=0;len=0; + while (iovlyloadParams.rc.left)); + sscanf(keywords[i+2],"%hd",&(pU->ovlyloadParams.rc.top)); + sscanf(keywords[i+3],"%hd",&(pU->ovlyloadParams.rc.right)); + sscanf(keywords[i+4],"%hd",&(pU->ovlyloadParams.rc.bottom)); + memcpy(keywords+i,keywords+(i+5),nrofkeywords-(i+5)); + continue; + } + break; } - s=(char*)SEGPTR_ALLOC(len); - *s='\0'; - while (iloadParams.lpfilename=(LPSTR)SEGPTR_GET(s); - dwFlags |= MCI_LOAD_FILE; - _MCI_CALL_DRIVER( MCI_LOAD, SEGPTR_GET(pU) ); - SEGPTR_FREE(s); - SEGPTR_FREE(pU); - return res; + len+=strlen(keywords[i])+1; + i++; + } + s=(char*)xmalloc(len); + *s='\0'; + while (iloadParams.lpfilename=s; + dwFlags |= MCI_LOAD_FILE; + _MCI_CALL_DRIVER( MCI_LOAD, pU ); + free(s); + free(pU); + return res; } /* save to file @@ -1437,45 +1428,45 @@ MCISTR_Load(_MCISTR_PROTO_) { */ static DWORD MCISTR_Save(_MCISTR_PROTO_) { - union U { - MCI_SAVE_PARMS saveParams; - MCI_OVLY_SAVE_PARMS16 ovlysaveParams; - }; - union U *pU = SEGPTR_NEW(union U); - int i,len,res; - char *s; - - i=0;len=0; - while (iovlysaveParams.rc.left)); - sscanf(keywords[i+2],"%hd",&(pU->ovlysaveParams.rc.top)); - sscanf(keywords[i+3],"%hd",&(pU->ovlysaveParams.rc.right)); - sscanf(keywords[i+4],"%hd",&(pU->ovlysaveParams.rc.bottom)); - memcpy(keywords+i,keywords+(i+5),nrofkeywords-(i+5)); - continue; - } - break; - } - len+=strlen(keywords[i])+1; - i++; + union U { + MCI_SAVE_PARMS saveParams; + MCI_OVLY_SAVE_PARMS16 ovlysaveParams; + }; + union U *pU = xmalloc(sizeof(union U)); + int i,len,res; + char *s; + + i=0;len=0; + while (iovlysaveParams.rc.left)); + sscanf(keywords[i+2],"%hd",&(pU->ovlysaveParams.rc.top)); + sscanf(keywords[i+3],"%hd",&(pU->ovlysaveParams.rc.right)); + sscanf(keywords[i+4],"%hd",&(pU->ovlysaveParams.rc.bottom)); + memcpy(keywords+i,keywords+(i+5),nrofkeywords-(i+5)); + continue; + } + break; } - s=(char*)SEGPTR_ALLOC(len); - *s='\0'; - while (isaveParams.lpfilename=(LPSTR)SEGPTR_GET(s); - dwFlags |= MCI_LOAD_FILE; - _MCI_CALL_DRIVER( MCI_SAVE, SEGPTR_GET(pU) ); - SEGPTR_FREE(s); - SEGPTR_FREE(pU); - return res; + len+=strlen(keywords[i])+1; + i++; + } + s=(char*)xmalloc(len); + *s='\0'; + while (isaveParams.lpfilename=s; + dwFlags |= MCI_LOAD_FILE; + _MCI_CALL_DRIVER( MCI_SAVE, pU ); + free(s); + free(pU); + return res; } /* prepare device for input/output @@ -1483,120 +1474,120 @@ MCISTR_Save(_MCISTR_PROTO_) { */ static DWORD MCISTR_Cue(_MCISTR_PROTO_) { - MCI_GENERIC_PARMS *cueParams = SEGPTR_NEW(MCI_GENERIC_PARMS); - int i,res; - - i=0; - while (idwTo=0; + for (k=0;kdwTo+=a[k]<<(8*(nrargs-k)); + i+=2; + continue; } - i=0; - while (idwTo=0; - for (k=0;kdwTo+=a[k]<<(8*(nrargs-k)); - i+=2; - continue; - } - if (!strcmp(keywords[i],"from") && (i+1dwFrom=0; - for (k=0;kdwFrom+=a[k]<<(8*(nrargs-k)); - i+=2; - continue; - } - i++; + if (!strcmp(keywords[i],"from") && (i+1dwFrom=0; + for (k=0;kdwFrom+=a[k]<<(8*(nrargs-k)); + i+=2; + continue; } - _MCI_CALL_DRIVER( MCI_DELETE, SEGPTR_GET(deleteParams) ); - SEGPTR_FREE(deleteParams); - return res; + i++; + } + _MCI_CALL_DRIVER( MCI_DELETE, deleteParams ); + free(deleteParams); + return res; } /* send command to device. only applies to videodisc */ static DWORD MCISTR_Escape(_MCISTR_PROTO_) { - MCI_VD_ESCAPE_PARMS16 *escapeParams = SEGPTR_NEW(MCI_VD_ESCAPE_PARMS16); - int i,len,res; - char *s; - - if (uDevTyp != MCI_DEVTYPE_VIDEODISC) - return MCIERR_UNSUPPORTED_FUNCTION; - i=0;len=0; - while (ilpstrCommand = (LPSTR)SEGPTR_GET(s); - dwFlags |= MCI_VD_ESCAPE_STRING; - _MCI_CALL_DRIVER( MCI_ESCAPE, SEGPTR_GET(escapeParams) ); - SEGPTR_FREE(s); - SEGPTR_FREE(escapeParams); - return res; + MCI_VD_ESCAPE_PARMS16 *escapeParams = xmalloc(sizeof(MCI_VD_ESCAPE_PARMS16)); + int i,len,res; + char *s; + + if (uDevTyp != MCI_DEVTYPE_VIDEODISC) + return MCIERR_UNSUPPORTED_FUNCTION; + i=0;len=0; + while (ilpstrCommand = s; + dwFlags |= MCI_VD_ESCAPE_STRING; + _MCI_CALL_DRIVER( MCI_ESCAPE, escapeParams ); + free(s); + free(escapeParams); + return res; } /* unfreeze [part of] the overlayed video @@ -1605,26 +1596,26 @@ MCISTR_Escape(_MCISTR_PROTO_) static DWORD MCISTR_Unfreeze(_MCISTR_PROTO_) { - MCI_OVLY_RECT_PARMS16 *unfreezeParams = SEGPTR_NEW(MCI_OVLY_RECT_PARMS16); - int i,res; - - if (uDevTyp != MCI_DEVTYPE_OVERLAY) - return MCIERR_UNSUPPORTED_FUNCTION; - i=0;while (irc.left)); - sscanf(keywords[i+2],"%hd",&(unfreezeParams->rc.top)); - sscanf(keywords[i+3],"%hd",&(unfreezeParams->rc.right)); - sscanf(keywords[i+4],"%hd",&(unfreezeParams->rc.bottom)); - dwFlags |= MCI_OVLY_RECT; - i+=5; - continue; - } - i++; + MCI_OVLY_RECT_PARMS16 *unfreezeParams = xmalloc(sizeof(MCI_OVLY_RECT_PARMS16)); + int i,res; + + if (uDevTyp != MCI_DEVTYPE_OVERLAY) + return MCIERR_UNSUPPORTED_FUNCTION; + i=0;while (irc.left)); + sscanf(keywords[i+2],"%hd",&(unfreezeParams->rc.top)); + sscanf(keywords[i+3],"%hd",&(unfreezeParams->rc.right)); + sscanf(keywords[i+4],"%hd",&(unfreezeParams->rc.bottom)); + dwFlags |= MCI_OVLY_RECT; + i+=5; + continue; } - _MCI_CALL_DRIVER( MCI_UNFREEZE, SEGPTR_GET(unfreezeParams) ); - SEGPTR_FREE(unfreezeParams); - return res; + i++; + } + _MCI_CALL_DRIVER( MCI_UNFREEZE, unfreezeParams ); + free(unfreezeParams); + return res; } /* freeze [part of] the overlayed video * only applyable to Overlay devices @@ -1632,26 +1623,26 @@ MCISTR_Unfreeze(_MCISTR_PROTO_) static DWORD MCISTR_Freeze(_MCISTR_PROTO_) { - MCI_OVLY_RECT_PARMS16 *freezeParams = SEGPTR_NEW(MCI_OVLY_RECT_PARMS16); - int i,res; - - if (uDevTyp != MCI_DEVTYPE_OVERLAY) - return MCIERR_UNSUPPORTED_FUNCTION; - i=0;while (irc.left)); - sscanf(keywords[i+2],"%hd",&(freezeParams->rc.top)); - sscanf(keywords[i+3],"%hd",&(freezeParams->rc.right)); - sscanf(keywords[i+4],"%hd",&(freezeParams->rc.bottom)); - dwFlags |= MCI_OVLY_RECT; - i+=5; - continue; - } - i++; + MCI_OVLY_RECT_PARMS16 *freezeParams = xmalloc(sizeof(MCI_OVLY_RECT_PARMS16)); + int i,res; + + if (uDevTyp != MCI_DEVTYPE_OVERLAY) + return MCIERR_UNSUPPORTED_FUNCTION; + i=0;while (irc.left)); + sscanf(keywords[i+2],"%hd",&(freezeParams->rc.top)); + sscanf(keywords[i+3],"%hd",&(freezeParams->rc.right)); + sscanf(keywords[i+4],"%hd",&(freezeParams->rc.bottom)); + dwFlags |= MCI_OVLY_RECT; + i+=5; + continue; } - _MCI_CALL_DRIVER( MCI_FREEZE, SEGPTR_GET(freezeParams) ); - SEGPTR_FREE(freezeParams); - return res; + i++; + } + _MCI_CALL_DRIVER( MCI_FREEZE, freezeParams ); + free(freezeParams); + return res; } /* copy parts of image to somewhere else @@ -1670,48 +1661,48 @@ MCISTR_Freeze(_MCISTR_PROTO_) */ static DWORD MCISTR_Put(_MCISTR_PROTO_) { - union U { - MCI_OVLY_RECT_PARMS16 ovlyputParams; - MCI_ANIM_RECT_PARMS16 animputParams; - }; - union U *pU = SEGPTR_NEW(union U); - int i,res; - i=0;while (ianimputParams.rc.left)); - sscanf(keywords[i+2],"%hd",&(pU->animputParams.rc.top)); - sscanf(keywords[i+3],"%hd",&(pU->animputParams.rc.right)); - sscanf(keywords[i+4],"%hd",&(pU->animputParams.rc.bottom)); - dwFlags |= MCI_ANIM_RECT; - i+=5; - continue; - } - break; - case MCI_DEVTYPE_OVERLAY: - FLAG1("source",MCI_OVLY_PUT_SOURCE); - FLAG1("destination",MCI_OVLY_PUT_DESTINATION); - FLAG1("video",MCI_OVLY_PUT_VIDEO); - FLAG1("frame",MCI_OVLY_PUT_FRAME); - if (!STRCMP(keywords[i],"at") && (i+4ovlyputParams.rc.left)); - sscanf(keywords[i+2],"%hd",&(pU->ovlyputParams.rc.top)); - sscanf(keywords[i+3],"%hd",&(pU->ovlyputParams.rc.right)); - sscanf(keywords[i+4],"%hd",&(pU->ovlyputParams.rc.bottom)); - dwFlags |= MCI_OVLY_RECT; - i+=5; - continue; - } - break; - } - i++; + union U { + MCI_OVLY_RECT_PARMS16 ovlyputParams; + MCI_ANIM_RECT_PARMS16 animputParams; + }; + union U *pU = xmalloc(sizeof(union U)); + int i,res; + i=0;while (ianimputParams.rc.left)); + sscanf(keywords[i+2],"%hd",&(pU->animputParams.rc.top)); + sscanf(keywords[i+3],"%hd",&(pU->animputParams.rc.right)); + sscanf(keywords[i+4],"%hd",&(pU->animputParams.rc.bottom)); + dwFlags |= MCI_ANIM_RECT; + i+=5; + continue; + } + break; + case MCI_DEVTYPE_OVERLAY: + FLAG1("source",MCI_OVLY_PUT_SOURCE); + FLAG1("destination",MCI_OVLY_PUT_DESTINATION); + FLAG1("video",MCI_OVLY_PUT_VIDEO); + FLAG1("frame",MCI_OVLY_PUT_FRAME); + if (!STRCMP(keywords[i],"at") && (i+4ovlyputParams.rc.left)); + sscanf(keywords[i+2],"%hd",&(pU->ovlyputParams.rc.top)); + sscanf(keywords[i+3],"%hd",&(pU->ovlyputParams.rc.right)); + sscanf(keywords[i+4],"%hd",&(pU->ovlyputParams.rc.bottom)); + dwFlags |= MCI_OVLY_RECT; + i+=5; + continue; + } + break; } - _MCI_CALL_DRIVER( MCI_PUT, SEGPTR_GET(pU) ); - SEGPTR_FREE(pU); - return res; + i++; + } + _MCI_CALL_DRIVER( MCI_PUT, pU ); + free(pU); + return res; } /* palette behaviour changing @@ -1722,20 +1713,20 @@ MCISTR_Put(_MCISTR_PROTO_) { static DWORD MCISTR_Realize(_MCISTR_PROTO_) { - MCI_GENERIC_PARMS *realizeParams = SEGPTR_NEW(MCI_GENERIC_PARMS); - int i,res; - - if (uDevTyp != MCI_DEVTYPE_ANIMATION) - return MCIERR_UNSUPPORTED_FUNCTION; - i=0; - while (ianimstepParams.dwFrames)); - dwFlags |= MCI_ANIM_STEP_FRAMES; - i+=2; - continue; - } - break; - case MCI_DEVTYPE_VIDEODISC: - FLAG1("reverse",MCI_VD_STEP_REVERSE); - if (!STRCMP(keywords[i],"by") && (i+1vdstepParams.dwFrames)); - dwFlags |= MCI_VD_STEP_FRAMES; - i+=2; - continue; - } - break; - } - i++; + union U { + MCI_ANIM_STEP_PARMS animstepParams; + MCI_VD_STEP_PARMS vdstepParams; + }; + union U *pU = xmalloc(sizeof(union U)); + int i,res; + + i=0; + while (ianimstepParams.dwFrames)); + dwFlags |= MCI_ANIM_STEP_FRAMES; + i+=2; + continue; + } + break; + case MCI_DEVTYPE_VIDEODISC: + FLAG1("reverse",MCI_VD_STEP_REVERSE); + if (!STRCMP(keywords[i],"by") && (i+1vdstepParams.dwFrames)); + dwFlags |= MCI_VD_STEP_FRAMES; + i+=2; + continue; + } + break; } - _MCI_CALL_DRIVER( MCI_STEP, SEGPTR_GET(pU) ); - SEGPTR_FREE(pU); - return res; + i++; + } + _MCI_CALL_DRIVER( MCI_STEP, pU ); + free(pU); + return res; } /* update animation window @@ -1810,31 +1801,31 @@ MCISTR_Step(_MCISTR_PROTO_) { */ static DWORD MCISTR_Update(_MCISTR_PROTO_) { - int i,res; - MCI_ANIM_UPDATE_PARMS16 *updateParams = SEGPTR_NEW(MCI_ANIM_UPDATE_PARMS16); - - i=0; - while (irc.left)); - sscanf(keywords[i+2],"%hd",&(updateParams->rc.top)); - sscanf(keywords[i+3],"%hd",&(updateParams->rc.right)); - sscanf(keywords[i+4],"%hd",&(updateParams->rc.bottom)); - dwFlags |= MCI_ANIM_RECT; - i+=5; - continue; - } - if (!STRCMP(keywords[i],"hdc") && (i+1hDC)); - i+=2; - continue; - } - i++; + int i,res; + MCI_ANIM_UPDATE_PARMS16 *updateParams = xmalloc(sizeof(MCI_ANIM_UPDATE_PARMS16)); + + i=0; + while (irc.left)); + sscanf(keywords[i+2],"%hd",&(updateParams->rc.top)); + sscanf(keywords[i+3],"%hd",&(updateParams->rc.right)); + sscanf(keywords[i+4],"%hd",&(updateParams->rc.bottom)); + dwFlags |= MCI_ANIM_RECT; + i+=5; + continue; } - _MCI_CALL_DRIVER( MCI_UPDATE, SEGPTR_GET(updateParams) ); - SEGPTR_FREE(updateParams); - return res; + if (!STRCMP(keywords[i],"hdc") && (i+1hDC)); + i+=2; + continue; + } + i++; + } + _MCI_CALL_DRIVER( MCI_UPDATE, updateParams ); + free(updateParams); + return res; } /* where command for animation and overlay drivers. @@ -1848,255 +1839,255 @@ MCISTR_Update(_MCISTR_PROTO_) { */ static DWORD MCISTR_Where(_MCISTR_PROTO_) { - union U { - MCI_ANIM_RECT_PARMS16 animwhereParams; - MCI_OVLY_RECT_PARMS16 ovlywhereParams; - }; - union U *pU = SEGPTR_NEW(union U); - int i,res; - - i=0; - while (ianimwhereParams.rc.left, - pU->animwhereParams.rc.top, - pU->animwhereParams.rc.right, - pU->animwhereParams.rc.bottom - ); - break; - case MCI_DEVTYPE_OVERLAY: - sprintf(buf,"%d %d %d %d", - pU->ovlywhereParams.rc.left, - pU->ovlywhereParams.rc.top, - pU->ovlywhereParams.rc.right, - pU->ovlywhereParams.rc.bottom - ); - break; - default:strcpy(buf,"0 0 0 0");break; - } - _MCI_STR(buf); + i++; + } + _MCI_CALL_DRIVER( MCI_WHERE, pU ); + if (res==0) { + char buf[100]; + switch (uDevTyp) { + case MCI_DEVTYPE_ANIMATION: + sprintf(buf,"%d %d %d %d", + pU->animwhereParams.rc.left, + pU->animwhereParams.rc.top, + pU->animwhereParams.rc.right, + pU->animwhereParams.rc.bottom + ); + break; + case MCI_DEVTYPE_OVERLAY: + sprintf(buf,"%d %d %d %d", + pU->ovlywhereParams.rc.left, + pU->ovlywhereParams.rc.top, + pU->ovlywhereParams.rc.right, + pU->ovlywhereParams.rc.bottom + ); + break; + default:strcpy(buf,"0 0 0 0");break; } - SEGPTR_FREE(pU); - return res; + _MCI_STR(buf); + } + free(pU); + return res; } static DWORD MCISTR_Window(_MCISTR_PROTO_) { - int i,res; - char *s; - union U { - MCI_ANIM_WINDOW_PARMS16 animwindowParams; - MCI_OVLY_WINDOW_PARMS16 ovlywindowParams; - }; - union U *pU = SEGPTR_NEW(union U); - - s=NULL; - i=0; - while (ianimwindowParams.hWnd = MCI_OVLY_WINDOW_DEFAULT; - else - sscanf(keywords[i+1],"%hd",&(pU->animwindowParams.hWnd)); - i+=2; - continue; - } - if (!STRCMP(keywords[i],"state") && (i+1animwindowParams.nCmdShow = SW_HIDE; - if (!STRCMP(keywords[i+1],"iconic")) - pU->animwindowParams.nCmdShow = SW_SHOWMINNOACTIVE; /* correct? */ - if (!STRCMP(keywords[i+1],"minimized")) - pU->animwindowParams.nCmdShow = SW_SHOWMINIMIZED; - if (!STRCMP(keywords[i+1],"maximized")) - pU->animwindowParams.nCmdShow = SW_SHOWMAXIMIZED; - if (!STRCMP(keywords[i+1],"minimize")) - pU->animwindowParams.nCmdShow = SW_MINIMIZE; - if (!STRCMP(keywords[i+1],"normal")) - pU->animwindowParams.nCmdShow = SW_NORMAL; - if (!STRCMP(keywords[i+1],"show")) - pU->animwindowParams.nCmdShow = SW_SHOW; - if (!STRCMP(keywords[i+1],"no") && (i+2animwindowParams.nCmdShow = SW_SHOWNOACTIVATE; - if (!STRCMP(keywords[i+2],"action")) - pU->animwindowParams.nCmdShow = SW_SHOWNA;/* correct?*/ - i++; - } - i+=2; - continue; - } - /* text is enclosed in " ... " as it seems */ - if (!STRCMP(keywords[i],"text")) { - char *t; - int len,j,k; - - if (keywords[i+1][0]!='"') { - i++; - continue; - } - dwFlags |= MCI_ANIM_WINDOW_TEXT; - len = strlen(keywords[i+1])+1; - j = i+2; - while (janimwindowParams.lpstrText = s; - i=k+1; - continue; - } - FLAG1("stretch",MCI_ANIM_WINDOW_ENABLE_STRETCH); - break; - case MCI_DEVTYPE_OVERLAY: - if (!STRCMP(keywords[i],"handle") && (i+1ovlywindowParams.hWnd = MCI_OVLY_WINDOW_DEFAULT; - else - sscanf(keywords[i+1],"%hd",&(pU->ovlywindowParams.hWnd)); - i+=2; - continue; - } - if (!STRCMP(keywords[i],"state") && (i+1ovlywindowParams.nCmdShow = SW_HIDE; - if (!STRCMP(keywords[i+1],"iconic")) - pU->ovlywindowParams.nCmdShow = SW_SHOWMINNOACTIVE; /* correct? */ - if (!STRCMP(keywords[i+1],"minimized")) - pU->ovlywindowParams.nCmdShow = SW_SHOWMINIMIZED; - if (!STRCMP(keywords[i+1],"maximized")) - pU->ovlywindowParams.nCmdShow = SW_SHOWMAXIMIZED; - if (!STRCMP(keywords[i+1],"minimize")) - pU->ovlywindowParams.nCmdShow = SW_MINIMIZE; - if (!STRCMP(keywords[i+1],"normal")) - pU->ovlywindowParams.nCmdShow = SW_NORMAL; - if (!STRCMP(keywords[i+1],"show")) - pU->ovlywindowParams.nCmdShow = SW_SHOW; - if (!STRCMP(keywords[i+1],"no") && (i+2ovlywindowParams.nCmdShow = SW_SHOWNOACTIVATE; - if (!STRCMP(keywords[i+2],"action")) - pU->ovlywindowParams.nCmdShow = SW_SHOWNA;/* correct?*/ - i++; - } - i+=2; - continue; - } - /* text is enclosed in " ... " as it seems */ - if (!STRCMP(keywords[i],"text")) { - char *t; - int len,j,k; - - if (keywords[i+1][0]!='"') { - i++; - continue; - } - dwFlags |= MCI_OVLY_WINDOW_TEXT; - len = strlen(keywords[i+1])+1; - j = i+2; - while (jovlywindowParams.lpstrText = s; - i=k+1; - continue; - } - FLAG1("stretch",MCI_OVLY_WINDOW_ENABLE_STRETCH); - break; + int i,res; + char *s; + union U { + MCI_ANIM_WINDOW_PARMS16 animwindowParams; + MCI_OVLY_WINDOW_PARMS16 ovlywindowParams; + }; + union U *pU = xmalloc(sizeof(union U)); + + s=NULL; + i=0; + while (ianimwindowParams.hWnd = MCI_OVLY_WINDOW_DEFAULT; + else + sscanf(keywords[i+1],"%hd",&(pU->animwindowParams.hWnd)); + i+=2; + continue; + } + if (!STRCMP(keywords[i],"state") && (i+1animwindowParams.nCmdShow = SW_HIDE; + if (!STRCMP(keywords[i+1],"iconic")) + pU->animwindowParams.nCmdShow = SW_SHOWMINNOACTIVE; /* correct? */ + if (!STRCMP(keywords[i+1],"minimized")) + pU->animwindowParams.nCmdShow = SW_SHOWMINIMIZED; + if (!STRCMP(keywords[i+1],"maximized")) + pU->animwindowParams.nCmdShow = SW_SHOWMAXIMIZED; + if (!STRCMP(keywords[i+1],"minimize")) + pU->animwindowParams.nCmdShow = SW_MINIMIZE; + if (!STRCMP(keywords[i+1],"normal")) + pU->animwindowParams.nCmdShow = SW_NORMAL; + if (!STRCMP(keywords[i+1],"show")) + pU->animwindowParams.nCmdShow = SW_SHOW; + if (!STRCMP(keywords[i+1],"no") && (i+2animwindowParams.nCmdShow = SW_SHOWNOACTIVATE; + if (!STRCMP(keywords[i+2],"action")) + pU->animwindowParams.nCmdShow = SW_SHOWNA;/* correct?*/ + i++; } - i++; + i+=2; + continue; + } + /* text is enclosed in " ... " as it seems */ + if (!STRCMP(keywords[i],"text")) { + char *t; + int len,j,k; + + if (keywords[i+1][0]!='"') { + i++; + continue; + } + dwFlags |= MCI_ANIM_WINDOW_TEXT; + len = strlen(keywords[i+1])+1; + j = i+2; + while (janimwindowParams.lpstrText = s; + i=k+1; + continue; + } + FLAG1("stretch",MCI_ANIM_WINDOW_ENABLE_STRETCH); + break; + case MCI_DEVTYPE_OVERLAY: + if (!STRCMP(keywords[i],"handle") && (i+1ovlywindowParams.hWnd = MCI_OVLY_WINDOW_DEFAULT; + else + sscanf(keywords[i+1],"%hd",&(pU->ovlywindowParams.hWnd)); + i+=2; + continue; + } + if (!STRCMP(keywords[i],"state") && (i+1ovlywindowParams.nCmdShow = SW_HIDE; + if (!STRCMP(keywords[i+1],"iconic")) + pU->ovlywindowParams.nCmdShow = SW_SHOWMINNOACTIVE; /* correct? */ + if (!STRCMP(keywords[i+1],"minimized")) + pU->ovlywindowParams.nCmdShow = SW_SHOWMINIMIZED; + if (!STRCMP(keywords[i+1],"maximized")) + pU->ovlywindowParams.nCmdShow = SW_SHOWMAXIMIZED; + if (!STRCMP(keywords[i+1],"minimize")) + pU->ovlywindowParams.nCmdShow = SW_MINIMIZE; + if (!STRCMP(keywords[i+1],"normal")) + pU->ovlywindowParams.nCmdShow = SW_NORMAL; + if (!STRCMP(keywords[i+1],"show")) + pU->ovlywindowParams.nCmdShow = SW_SHOW; + if (!STRCMP(keywords[i+1],"no") && (i+2ovlywindowParams.nCmdShow = SW_SHOWNOACTIVATE; + if (!STRCMP(keywords[i+2],"action")) + pU->ovlywindowParams.nCmdShow = SW_SHOWNA;/* correct?*/ + i++; + } + i+=2; + continue; + } + /* text is enclosed in " ... " as it seems */ + if (!STRCMP(keywords[i],"text")) { + char *t; + int len,j,k; + + if (keywords[i+1][0]!='"') { + i++; + continue; + } + dwFlags |= MCI_OVLY_WINDOW_TEXT; + len = strlen(keywords[i+1])+1; + j = i+2; + while (jovlywindowParams.lpstrText = s; + i=k+1; + continue; + } + FLAG1("stretch",MCI_OVLY_WINDOW_ENABLE_STRETCH); + break; } - _MCI_CALL_DRIVER( MCI_WINDOW, SEGPTR_GET(pU) ); - if (s) free(s); - SEGPTR_FREE(pU); - return res; + i++; + } + _MCI_CALL_DRIVER( MCI_WINDOW, pU ); + if (s) free(s); + free(pU); + return res; } struct _MCISTR_cmdtable { - char *cmd; - DWORD (*fun)(_MCISTR_PROTO_); + char *cmd; + DWORD (*fun)(_MCISTR_PROTO_); } MCISTR_cmdtable[]={ - {"break", MCISTR_Break}, - {"capability", MCISTR_Capability}, - {"close", MCISTR_Close}, - {"cue", MCISTR_Cue}, - {"delete", MCISTR_Delete}, - {"escape", MCISTR_Escape}, - {"freeze", MCISTR_Freeze}, - {"info", MCISTR_Info}, - {"load", MCISTR_Load}, - {"open", MCISTR_Open}, - {"pause", MCISTR_Pause}, - {"play", MCISTR_Play}, - {"put", MCISTR_Put}, - {"realize", MCISTR_Realize}, - {"record", MCISTR_Record}, - {"resume", MCISTR_Resume}, - {"save", MCISTR_Save}, - {"seek", MCISTR_Seek}, - {"set", MCISTR_Set}, - {"spin", MCISTR_Spin}, - {"status", MCISTR_Status}, - {"step", MCISTR_Step}, - {"stop", MCISTR_Stop}, - {"sysinfo", MCISTR_Sysinfo}, - {"unfreeze", MCISTR_Unfreeze}, - {"update", MCISTR_Update}, - {"where", MCISTR_Where}, - {"window", MCISTR_Window}, - {NULL, NULL} + {"break", MCISTR_Break}, + {"capability", MCISTR_Capability}, + {"close", MCISTR_Close}, + {"cue", MCISTR_Cue}, + {"delete", MCISTR_Delete}, + {"escape", MCISTR_Escape}, + {"freeze", MCISTR_Freeze}, + {"info", MCISTR_Info}, + {"load", MCISTR_Load}, + {"open", MCISTR_Open}, + {"pause", MCISTR_Pause}, + {"play", MCISTR_Play}, + {"put", MCISTR_Put}, + {"realize", MCISTR_Realize}, + {"record", MCISTR_Record}, + {"resume", MCISTR_Resume}, + {"save", MCISTR_Save}, + {"seek", MCISTR_Seek}, + {"set", MCISTR_Set}, + {"spin", MCISTR_Spin}, + {"status", MCISTR_Status}, + {"step", MCISTR_Step}, + {"stop", MCISTR_Stop}, + {"sysinfo", MCISTR_Sysinfo}, + {"unfreeze", MCISTR_Unfreeze}, + {"update", MCISTR_Update}, + {"where", MCISTR_Where}, + {"window", MCISTR_Window}, + {NULL, NULL} }; /************************************************************************** -* mciSendString [MMSYSTEM.702] -*/ + * mciSendString [MMSYSTEM.702] + */ /* The usercode sends a string with a command (and flags) expressed in * words in it... We do our best to call aprobiate drivers, * and return a errorcode AND a readable string (if lpstrRS!=NULL) @@ -2108,105 +2099,105 @@ struct _MCISTR_cmdtable { DWORD WINAPI mciSendString (LPCSTR lpstrCommand, LPSTR lpstrReturnString, UINT16 uReturnLength, HWND16 hwndCallback) { - char *cmd,*dev,*args,**keywords,*filename; - WORD uDevTyp=0,wDevID=0; - DWORD dwFlags; - int res=0,i,nrofkeywords; - - TRACE(mci,"('%s', %p, %d, %X)\n", lpstrCommand, - lpstrReturnString, uReturnLength, hwndCallback - ); - /* format is */ - cmd=strdup(lpstrCommand); - dev=strchr(cmd,' '); - if (dev==NULL) { - free(cmd); - return MCIERR_MISSING_DEVICE_NAME; + char *cmd,*dev,*args,**keywords,*filename; + WORD uDevTyp=0,wDevID=0; + DWORD dwFlags; + int res=0,i,nrofkeywords; + + TRACE(mci,"('%s', %p, %d, %X)\n", lpstrCommand, + lpstrReturnString, uReturnLength, hwndCallback + ); + /* format is */ + cmd=strdup(lpstrCommand); + dev=strchr(cmd,' '); + if (dev==NULL) { + free(cmd); + return MCIERR_MISSING_DEVICE_NAME; + } + *dev++='\0'; + args=strchr(dev,' '); + if (args!=NULL) *args++='\0'; + CharUpper32A(dev); + if (args!=NULL) { + char *s; + i=1;/* nrofkeywords = nrofspaces+1 */ + s=args; + while ((s=strchr(s,' '))!=NULL) i++,s++; + keywords=(char**)xmalloc(sizeof(char*)*(i+2)); + nrofkeywords=i; + s=args;i=0; + while (s && ilpstrAlias; - if (dname==(SEGPTR)NULL) - dname=(SEGPTR)GetOpenDrv(wDevID)->lpstrDeviceType; - if ((dname!=(SEGPTR)NULL)&&(!STRCMP(PTR_SEG_TO_LIN(dname),dev))) - break; - wDevID = MMSYSTEM_NextDevID(wDevID); - if (!MMSYSTEM_DevIDValid(wDevID)) { - TRACE(mci, "MAXMCIDRIVERS reached!\n"); - free(keywords);free(cmd); - return MCIERR_INVALID_DEVICE_NAME; - } - } - uDevTyp=GetDrv(wDevID)->modp.wType; + if (!STRCMP(keywords[i],"notify")) { + dwFlags |= MCI_NOTIFY; + memcpy(keywords+i,keywords+(i+1),(nrofkeywords-i-1)*sizeof(char *)); + nrofkeywords--; + continue; } - - for (i=0;MCISTR_cmdtable[i].cmd!=NULL;i++) { - if (!STRCMP(MCISTR_cmdtable[i].cmd,cmd)) { - res=MCISTR_cmdtable[i].fun( - wDevID,uDevTyp,lpstrReturnString, - uReturnLength,dev,(LPSTR*)keywords,nrofkeywords, - dwFlags,hwndCallback - ); - break; - } - } - if (MCISTR_cmdtable[i].cmd!=NULL) { - free(keywords);free(cmd); - return res; - } - FIXME(mci,"('%s', %p, %u, %X): unimplemented, please report.\n", - lpstrCommand, lpstrReturnString, uReturnLength, hwndCallback); + i++; + } + + /* determine wDevID and uDevTyp for all commands except "open" */ + if (STRCMP(cmd,"open")!=0) { + wDevID = MMSYSTEM_FirstDevID(); + while (1) { + LPSTR dname; + + dname=mciGetOpenDrv(wDevID)->lpstrAlias; + if (dname==NULL) + dname=mciGetOpenDrv(wDevID)->lpstrDeviceType; + if (dname != NULL && !STRCMP(dname,dev)) + break; + wDevID = MMSYSTEM_NextDevID(wDevID); + if (!MMSYSTEM_DevIDValid(wDevID)) { + TRACE(mci, "MAXMCIDRIVERS reached!\n"); + free(keywords);free(cmd); + return MCIERR_INVALID_DEVICE_NAME; + } + } + uDevTyp=mciGetDrv(wDevID)->modp.wType; + } + + for (i=0;MCISTR_cmdtable[i].cmd!=NULL;i++) { + if (!STRCMP(MCISTR_cmdtable[i].cmd,cmd)) { + res=MCISTR_cmdtable[i].fun( + wDevID,uDevTyp,lpstrReturnString, + uReturnLength,dev,(LPSTR*)keywords,nrofkeywords, + dwFlags,hwndCallback + ); + break; + } + } + if (MCISTR_cmdtable[i].cmd!=NULL) { free(keywords);free(cmd); - return MCIERR_MISSING_COMMAND_STRING; + return res; + } + FIXME(mci,"('%s', %p, %u, %X): unimplemented, please report.\n", + lpstrCommand, lpstrReturnString, uReturnLength, hwndCallback); + free(keywords);free(cmd); + return MCIERR_MISSING_COMMAND_STRING; } diff --git a/multimedia/midi.c b/multimedia/midi.c index 3200e9e6e2d..bc251cd40c4 100644 --- a/multimedia/midi.c +++ b/multimedia/midi.c @@ -7,8 +7,10 @@ */ /* - * Eric POUECH : 98/7 changes for making this MIDI driver work on OSS - * current support is limited to MIDI ports of OSS systems + * Eric POUECH : + * 98/7 changes for making this MIDI driver work on OSS + * current support is limited to MIDI ports of OSS systems + * 98/9 rewriting MCI code for MIDI */ #include @@ -29,9 +31,74 @@ #include "callback.h" #include "options.h" -static LINUX_MIDIIN MidiInDev [MAX_MIDIINDRV ]; -static LINUX_MIDIOUT MidiOutDev[MAX_MIDIOUTDRV]; -static LINUX_MCIMIDI MCIMidiDev[MAX_MCIMIDIDRV]; +typedef struct { +#ifndef HAVE_OSS + int unixdev; +#endif + int state; + DWORD bufsize; + LPMIDIOPENDESC midiDesc; + WORD wFlags; + LPMIDIHDR lpQueueHdr; + DWORD dwTotalPlayed; +#ifdef HAVE_OSS + unsigned char incoming[3]; + unsigned char incPrev; + char incLen; + DWORD startTime; +#endif +} WINE_MIDIIN; + +typedef struct { +#ifndef HAVE_OSS + int unixdev; +#endif + int state; + DWORD bufsize; + LPMIDIOPENDESC midiDesc; + WORD wFlags; + LPMIDIHDR lpQueueHdr; + DWORD dwTotalPlayed; +#ifdef HAVE_OSS + void* lpExtra; /* according to port type (MIDI, FM...), extra data when needed */ +#endif +} WINE_MIDIOUT; + +typedef struct { + DWORD dwFirst; /* offset in file of track */ + DWORD dwLast; /* number of bytes in file of track */ + DWORD dwIndex; /* current index in file (dwFirst <= dwIndex < dwLast) */ + DWORD dwLength; /* number of pulses in this track */ + DWORD dwEventPulse; /* current pulse # (event) pointed by dwIndex */ + DWORD dwEventData; /* current data (event) pointed by dwIndex */ + WORD wEventLength; /* current length (event) pointed by dwIndex */ + WORD wStatus : 1, /* 1 : playing, 0 : done */ + wTrackNr : 7, + wLastCommand : 8; +} MCI_MIDITRACK; + +typedef struct { + int nUseCount; /* Incremented for each shared open */ + BOOL16 fShareable; /* TRUE if first open was shareable */ + WORD wNotifyDeviceID; /* MCI device ID with a pending notification */ + HANDLE16 hCallback; /* Callback handle for pending notification */ + HMMIO32 hFile; /* mmio file handle open as Element */ + WORD wFormat; + WORD nTracks; + WORD nDivision; + DWORD dwTempo; + MCI_OPEN_PARMS16 openParms; + WORD dwStatus; + MCI_MIDITRACK* tracks; + DWORD dwPulse; + DWORD dwPositionMS; + DWORD dwStartTicks; + HLOCAL16 hMidiHdr; +} WINE_MCIMIDI; + +static WINE_MIDIIN MidiInDev [MAX_MIDIINDRV ]; +static WINE_MIDIOUT MidiOutDev[MAX_MIDIOUTDRV]; +static WINE_MCIMIDI MCIMidiDev[MAX_MCIMIDIDRV]; /* this is the total number of MIDI out devices found */ int MODM_NUMDEVS = 0; @@ -174,28 +241,149 @@ static DWORD MIDI_ReadLong(UINT16 wDevID, LPDWORD lpdw) /************************************************************************** * MIDI_ReadVaryLen [internal] */ -static DWORD MIDI_ReadVaryLen(UINT16 wDevID, LPDWORD lpdw) +static WORD MIDI_ReadVaryLen(UINT16 wDevID, LPDWORD lpdw) { BYTE byte; - DWORD value; + DWORD value = 0; + WORD ret = 0; - if (lpdw == NULL) return MCIERR_INTERNAL; - if (MIDI_ReadByte(wDevID, &byte) != 0) { - WARN(midi, "error reading wDevID=%04X\n", wDevID); + if (lpdw == NULL) return MCIERR_INTERNAL; - } - value = (DWORD)(byte & 0x7F); - while (byte & 0x80) { + + do { if (MIDI_ReadByte(wDevID, &byte) != 0) { WARN(midi, "error reading wDevID=%04X\n", wDevID); - return MCIERR_INTERNAL; + return 0; } value = (value << 7) + (byte & 0x7F); - } + ret++; + } while (byte & 0x80); *lpdw = value; /* TRACE(midi, "val=%08lX \n", value); */ + return ret; +} + +/************************************************************************** + * MIDI_ReadNextEvent [internal] + */ +static DWORD MIDI_ReadNextEvent(UINT16 wDevID, MCI_MIDITRACK* mmt) +{ + BYTE b1, b2 = 0, b3; + WORD hw = 0; + DWORD evtPulse; + DWORD evtLength; + DWORD tmp; + + if (mmioSeek32(MCIMidiDev[wDevID].hFile, mmt->dwIndex, SEEK_SET) != mmt->dwIndex) { + WARN(midi, "can't seek at %08lX \n", mmt->dwIndex); + return MCIERR_INTERNAL; + } + evtLength = MIDI_ReadVaryLen(wDevID, &evtPulse) + 1; /* > 0 */ + MIDI_ReadByte(wDevID, &b1); + switch (b1) { + case 0xF0: + case 0xF7: + evtLength += MIDI_ReadVaryLen(wDevID, &tmp); + evtLength += tmp; + break; + case 0xFF: + MIDI_ReadByte(wDevID, &b2); evtLength++; + + evtLength += MIDI_ReadVaryLen(wDevID, &tmp); + if (evtLength >= 0x10000u) { + /* this limitation shouldn't be a problem */ + WARN(midi, "Ouch !! Implementation limitation to 64k bytes for a MIDI event is overflowed\n"); + hw = 0xFFFF; + } else { + hw = LOWORD(evtLength); + } + evtLength += tmp; + break; + default: + if (b1 & 0x80) { // use running status ? + mmt->wLastCommand = b1; + MIDI_ReadByte(wDevID, &b2); evtLength++; + } else { + b2 = b1; + b1 = mmt->wLastCommand; + } + switch ((b1 >> 4) & 0x07) { + case 0: case 1: case 2: case 3: case 6: + MIDI_ReadByte(wDevID, &b3); evtLength++; + hw = b3; + break; + case 4: case 5: + break; + case 7: + WARN(midi, "Strange indeed b1=0x%02x\n", b1); + } + break; + } + if (mmt->dwIndex + evtLength > mmt->dwLast) + return MCIERR_INTERNAL; + + mmt->dwEventPulse += evtPulse; + mmt->dwEventData = (hw << 16) + (b2 << 8) + b1; + mmt->wEventLength = evtLength; + + /* + TRACE(midi, "[%u] => pulse=%08lx(%08lx), data=%08lx, length=%u\n", + mmt->wTrackNr, mmt->dwEventPulse, evtPulse, + mmt->dwEventData, mmt->wEventLength); + */ + return 0; +} + +/************************************************************************** + * MIDI_ReadMTrk [internal] + */ +static DWORD MIDI_ReadMTrk(UINT16 wDevID, MCI_MIDITRACK* mmt) +{ + DWORD toberead; + FOURCC fourcc; + + if (mmioRead32(MCIMidiDev[wDevID].hFile, (HPSTR)&fourcc, + (long) sizeof(FOURCC)) != (long) sizeof(FOURCC)) { + return MCIERR_INTERNAL; + } + + if (fourcc != mmioFOURCC('M', 'T', 'r', 'k')) { + WARN(midi, "cannot synchronize on MTrk !\n"); + return MCIERR_INTERNAL; + } + + if (MIDI_ReadLong(wDevID, &toberead) != 0) { + return MCIERR_INTERNAL; + } + mmt->dwFirst = mmioSeek32(MCIMidiDev[wDevID].hFile, 0, SEEK_CUR); /* >= 0 */ + mmt->dwLast = mmt->dwFirst + toberead; + + /* compute # of pulses in this track */ + mmt->dwIndex = mmt->dwFirst; + mmt->dwEventPulse = 0; + while (MIDI_ReadNextEvent(wDevID, mmt) == 0 && + LOWORD(mmt->dwEventData) != 0x2FFF) { + mmt->dwIndex += mmt->wEventLength; + } + mmt->dwLength = mmt->dwEventPulse; + + TRACE(midi, "Track %u has %lu bytes and %lu pulses\n", + mmt->wTrackNr, toberead, mmt->dwLength); + + /* reset track data */ + mmt->wStatus = 1; /* ok, playing */ + mmt->dwIndex = mmt->dwFirst; + mmt->dwEventPulse = 0; + + if (mmioSeek32(MCIMidiDev[wDevID].hFile, 0, SEEK_CUR) != mmt->dwLast) { + WARN(midi, "Ouch, out of sync seek=%lu track=%lu\n", + mmioSeek32(MCIMidiDev[wDevID].hFile, 0, SEEK_CUR), mmt->dwLast); + /* position at end of this track, to be ready to read next track */ + mmioSeek32(MCIMidiDev[wDevID].hFile, mmt->dwLast, SEEK_SET); + } + return 0; } @@ -206,6 +394,7 @@ static DWORD MIDI_ReadMThd(UINT16 wDevID, DWORD dwOffset) { DWORD toberead; FOURCC fourcc; + WORD nt; TRACE(midi, "(%04X, %08lX);\n", wDevID, dwOffset); if (mmioSeek32(MCIMidiDev[wDevID].hFile, dwOffset, SEEK_SET) != dwOffset) { @@ -215,60 +404,84 @@ static DWORD MIDI_ReadMThd(UINT16 wDevID, DWORD dwOffset) if (mmioRead32(MCIMidiDev[wDevID].hFile, (HPSTR)&fourcc, (long) sizeof(FOURCC)) != (long) sizeof(FOURCC)) return MCIERR_INTERNAL; - if (MIDI_ReadLong(wDevID, &toberead) != 0) + + if (fourcc != mmioFOURCC('M', 'T', 'h', 'd')) { + WARN(midi, "cannot synchronize on MThd !\n"); + return MCIERR_INTERNAL; + } + + if (MIDI_ReadLong(wDevID, &toberead) != 0 || toberead < 3 * sizeof(WORD)) return MCIERR_INTERNAL; if (MIDI_ReadWord(wDevID, &MCIMidiDev[wDevID].wFormat) != 0) return MCIERR_INTERNAL; if (MIDI_ReadWord(wDevID, &MCIMidiDev[wDevID].nTracks) != 0) return MCIERR_INTERNAL; - if (MIDI_ReadWord(wDevID, &MCIMidiDev[wDevID].nTempo) != 0) + if (MIDI_ReadWord(wDevID, &MCIMidiDev[wDevID].nDivision) != 0) return MCIERR_INTERNAL; - TRACE(midi, "toberead=%08lX, wFormat=%04X nTracks=%04X nTempo=%04X\n", + + TRACE(midi, "toberead=0x%08lX, wFormat=0x%04X nTracks=0x%04X nDivision=0x%04X\n", toberead, MCIMidiDev[wDevID].wFormat, MCIMidiDev[wDevID].nTracks, - MCIMidiDev[wDevID].nTempo); - toberead -= 3 * sizeof(WORD); - /* - ntrks = read16bit (); - Mf_division = division = read16bit (); - */ - return 0; -} + MCIMidiDev[wDevID].nDivision); -static DWORD MIDI_ReadMTrk(UINT16 wDevID, DWORD dwOffset) -{ - DWORD toberead; - FOURCC fourcc; - - if (mmioSeek32(MCIMidiDev[wDevID].hFile, dwOffset, SEEK_SET) != dwOffset) { - WARN(midi, "can't seek at %08lX begin of 'MThd' \n", dwOffset); - } - if (mmioRead32(MCIMidiDev[wDevID].hFile, (HPSTR)&fourcc, - (long) sizeof(FOURCC)) != (long) sizeof(FOURCC)) { + if (MCIMidiDev[wDevID].nDivision > 0x8000) { + WARN(midi, "Handling SMPTE time in MIDI files is not (yet) supported\n" + "Please report with MIDI file !\n"); return MCIERR_INTERNAL; } - if (MIDI_ReadLong(wDevID, &toberead) != 0) { + + switch (MCIMidiDev[wDevID].wFormat) { + case 0: + if (MCIMidiDev[wDevID].nTracks != 1) { + WARN(midi, "Got type 0 file whose number of track is not 1. Setting it to 1\n"); + MCIMidiDev[wDevID].nTracks = 1; + } + break; + case 1: + case 2: + break; + default: + WARN(midi, "Handling MIDI files which format = %d is not (yet) supported\n" + "Please report with MIDI file !\n", MCIMidiDev[wDevID].wFormat); return MCIERR_INTERNAL; } - TRACE(midi, "toberead=%08lX\n", toberead); - toberead -= 3 * sizeof(WORD); - MCIMidiDev[wDevID].dwTotalLen = toberead; + + if (MCIMidiDev[wDevID].nTracks & 0x8000) { + /* this shouldn't be a problem... */ + WARN(midi, "Ouch !! Implementation limitation to 32k tracks per MIDI file is overflowed\n"); + MCIMidiDev[wDevID].nTracks = 0x7FFF; + } + MCIMidiDev[wDevID].tracks = xmalloc(sizeof(MCI_MIDITRACK) * MCIMidiDev[wDevID].nTracks); + + toberead -= 3 * sizeof(WORD); + if (toberead > 0) { + TRACE(midi, "Size of MThd > 6, skipping %ld extra bytes\n", toberead); + mmioSeek32(MCIMidiDev[wDevID].hFile, toberead, SEEK_CUR); + } + + for (nt = 0; nt < MCIMidiDev[wDevID].nTracks; nt++) { + MCIMidiDev[wDevID].tracks[nt].wTrackNr = nt; + if (MIDI_ReadMTrk(wDevID, &MCIMidiDev[wDevID].tracks[nt]) != 0) { + WARN(midi, "can't read 'MTrk' header \n"); + return MCIERR_INTERNAL; + } + } + return 0; } /************************************************************************** * MIDI_mciOpen [internal] */ -static DWORD MIDI_mciOpen(UINT16 wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS16 lpParms) +static DWORD MIDI_mciOpen(UINT16 wDevID, DWORD dwFlags, void* lp, BOOL32 is32) { MIDIOPENDESC MidiDesc; DWORD dwRet; - DWORD dwOffset; - LPSTR lpstrElementName; - char str[128]; - - TRACE(midi, "(%08lX, %p)\n", dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; + DWORD dwDeviceID; + + TRACE(midi, "(%08lX, %p)\n", dwFlags, lp); + + if (lp == NULL) return MCIERR_INTERNAL; if (MCIMidiDev[wDevID].nUseCount > 0) { /* The driver already open on this channel */ @@ -283,61 +496,61 @@ static DWORD MIDI_mciOpen(UINT16 wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS16 lpPar MCIMidiDev[wDevID].fShareable = dwFlags & MCI_OPEN_SHAREABLE; MCIMidiDev[wDevID].hMidiHdr = USER_HEAP_ALLOC(sizeof(MIDIHDR)); } + + if (is32) dwDeviceID = ((LPMCI_OPEN_PARMS32A)lp)->wDeviceID; + else dwDeviceID = ((LPMCI_OPEN_PARMS16)lp)->wDeviceID; - TRACE(midi, "wDevID=%04X\n", wDevID); + TRACE(midi, "wDevID=%04X (lpParams->wDeviceID=%08lX)\n", wDevID, dwDeviceID); /* lpParms->wDeviceID = wDevID;*/ - TRACE(midi, "lpParms->wDevID=%04X\n", lpParms->wDeviceID); TRACE(midi, "before OPEN_ELEMENT\n"); if (dwFlags & MCI_OPEN_ELEMENT) { - lpstrElementName = (LPSTR)PTR_SEG_TO_LIN(lpParms->lpstrElementName); + LPSTR lpstrElementName; + + if (is32) lpstrElementName = ((LPMCI_OPEN_PARMS32A)lp)->lpstrElementName; + else lpstrElementName = (LPSTR)PTR_SEG_TO_LIN(((LPMCI_OPEN_PARMS16)lp)->lpstrElementName); + TRACE(midi, "MCI_OPEN_ELEMENT '%s' !\n", lpstrElementName); if (strlen(lpstrElementName) > 0) { - strcpy(str, lpstrElementName); - CharUpper32A(str); - MCIMidiDev[wDevID].hFile = mmioOpen16(str, NULL, - MMIO_ALLOCBUF | MMIO_READWRITE | MMIO_EXCLUSIVE); + MCIMidiDev[wDevID].hFile = mmioOpen32A(lpstrElementName, NULL, + MMIO_ALLOCBUF | MMIO_READWRITE | MMIO_EXCLUSIVE); if (MCIMidiDev[wDevID].hFile == 0) { - WARN(midi, "can't find file='%s' !\n", str); + WARN(midi, "can't find file='%s' !\n", lpstrElementName); return MCIERR_FILE_NOT_FOUND; } } else MCIMidiDev[wDevID].hFile = 0; } TRACE(midi, "hFile=%u\n", MCIMidiDev[wDevID].hFile); - memcpy(&MCIMidiDev[wDevID].openParms, lpParms, sizeof(MCI_OPEN_PARMS16)); - MCIMidiDev[wDevID].wNotifyDeviceID = lpParms->wDeviceID; + + /* should be of same size in all cases */ + memcpy(&MCIMidiDev[wDevID].openParms, lp, sizeof(MCI_OPEN_PARMS16)); + + MCIMidiDev[wDevID].wNotifyDeviceID = dwDeviceID; MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP; - MCIMidiDev[wDevID].dwBeginData = 0; - MCIMidiDev[wDevID].dwTotalLen = 0; MidiDesc.hMidi = 0; + if (MCIMidiDev[wDevID].hFile != 0) { MMCKINFO ckMainRIFF; + DWORD dwOffset = 0; + if (mmioDescend(MCIMidiDev[wDevID].hFile, &ckMainRIFF, NULL, 0) != 0) { return MCIERR_INTERNAL; } TRACE(midi,"ParentChunk ckid=%.4s fccType=%.4s cksize=%08lX \n", (LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType, ckMainRIFF.cksize); - dwOffset = 0; + if (ckMainRIFF.ckid == mmioFOURCC('R', 'M', 'I', 'D')) { TRACE(midi, "is a 'RMID' file \n"); dwOffset = ckMainRIFF.dwDataOffset; - } - if (ckMainRIFF.ckid != mmioFOURCC('M', 'T', 'h', 'd')) { - WARN(midi, "unknown format !\n"); - return MCIERR_INTERNAL; + FIXME(midi, "Setting #tracks for RMID to 1: is this correct ?\n"); + MCIMidiDev[wDevID].nTracks = 1; } if (MIDI_ReadMThd(wDevID, dwOffset) != 0) { WARN(midi, "can't read 'MThd' header \n"); return MCIERR_INTERNAL; } - dwOffset = mmioSeek32(MCIMidiDev[wDevID].hFile, 0, SEEK_CUR); - if (MIDI_ReadMTrk(wDevID, dwOffset) != 0) { - WARN(midi, "can't read 'MTrk' header \n"); - return MCIERR_INTERNAL; - } - dwOffset = mmioSeek32(MCIMidiDev[wDevID].hFile, 0, SEEK_CUR); - MCIMidiDev[wDevID].dwBeginData = dwOffset; + TRACE(midi, "Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n", (LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType, ckMainRIFF.cksize); @@ -349,30 +562,58 @@ static DWORD MIDI_mciOpen(UINT16 wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS16 lpPar return 0; } +static DWORD MIDI_ConvertPulseToMS(UINT16 wDevID, DWORD pulse) +{ + DWORD ret = (DWORD)((double)pulse * ((double)MCIMidiDev[wDevID].dwTempo / 1000) / + (double)MCIMidiDev[wDevID].nDivision); + + /* + TRACE(midi, "pulse=%lu tempo=%lu division=%u => ms=%lu\n", + pulse, MCIMidiDev[wDevID].dwTempo, MCIMidiDev[wDevID].nDivision, ret); + */ + return ret; +} + /************************************************************************** * MIDI_mciStop [internal] */ static DWORD MIDI_mciStop(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms) { TRACE(midi, "(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; + + if (wDevID >= MAX_MCIMIDIDRV || MCIMidiDev[wDevID].nUseCount == 0) { + WARN(midi, "Invalid wDevID=%u\n", wDevID); + return MCIERR_INVALID_DEVICE_ID; + } + MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP; - TRACE(midi, "MCIMidiDev[wDevID].dwStatus=%p %d\n", - &MCIMidiDev[wDevID].dwStatus, MCIMidiDev[wDevID].dwStatus); + TRACE(midi, "MCIMidiDev[wDevID].dwStatus=%d\n", MCIMidiDev[wDevID].dwStatus); + if (lpParms && (dwFlags & MCI_NOTIFY)) { + TRACE(midi, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + MCIMidiDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); + } return 0; } /************************************************************************** * MIDI_mciClose [internal] */ -static DWORD MIDI_mciClose(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms) +static DWORD MIDI_mciClose(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms) { DWORD dwRet; - TRACE(midi, "(%04X, %08lX, %p);\n", wDevID, dwParam, lpParms); + TRACE(midi, "(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms); + + if (wDevID >= MAX_MCIMIDIDRV || MCIMidiDev[wDevID].nUseCount == 0) { + WARN(midi, "Invalid wDevID=%u\n", wDevID); + return MCIERR_INVALID_DEVICE_ID; + } + if (MCIMidiDev[wDevID].dwStatus != MCI_MODE_STOP) { MIDI_mciStop(wDevID, MCI_WAIT, lpParms); } + MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP; MCIMidiDev[wDevID].nUseCount--; if (MCIMidiDev[wDevID].nUseCount == 0) { @@ -382,6 +623,7 @@ static DWORD MIDI_mciClose(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpP TRACE(midi, "hFile closed !\n"); } USER_HEAP_FREE(MCIMidiDev[wDevID].hMidiHdr); + free(MCIMidiDev[wDevID].tracks); dwRet = modMessage(wDevID, MODM_CLOSE, 0, 0L, 0L); if (dwRet != MMSYSERR_NOERROR) return MCIERR_INTERNAL; /* @@ -389,6 +631,11 @@ static DWORD MIDI_mciClose(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpP if (dwRet != MMSYSERR_NOERROR) return MCIERR_INTERNAL; */ } + if (lpParms && (dwFlags & MCI_NOTIFY)) { + TRACE(midi, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + MCIMidiDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); + } return 0; } @@ -397,103 +644,239 @@ static DWORD MIDI_mciClose(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpP */ static DWORD MIDI_mciPlay(UINT16 wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms) { - int count,start,end; - LPMIDIHDR lpMidiHdr; - DWORD dwData,dwRet; - LPWORD ptr; - + DWORD start = 0, end = 0xFFFFFFFFul; + DWORD dwRet; + WORD nt, cnt; + TRACE(midi, "(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms); + + if (wDevID >= MAX_MCIMIDIDRV || MCIMidiDev[wDevID].nUseCount == 0) { + WARN(midi, "Invalid wDevID=%u\n", wDevID); + return MCIERR_INVALID_DEVICE_ID; + } + if (MCIMidiDev[wDevID].hFile == 0) { - WARN(midi, "can't find file='%08lx' !\n", + WARN(midi, "Cannot play : can't find file='%08lx' !\n", (DWORD)MCIMidiDev[wDevID].openParms.lpstrElementName); return MCIERR_FILE_NOT_FOUND; } - start = 1; end = 99999; - if (dwFlags & MCI_FROM) { + + if (MCIMidiDev[wDevID].dwStatus != MCI_MODE_STOP) { + WARN(midi, "Cannot play : device is not stopped !\n"); + return MCIERR_INTERNAL; + } + + if (lpParms && (dwFlags & MCI_FROM)) { start = lpParms->dwFrom; - TRACE(midi, "MCI_FROM=%d \n", start); + FIXME(midi, "MCI_FROM=%lu \n", start); } - if (dwFlags & MCI_TO) { + if (lpParms && (dwFlags & MCI_TO)) { end = lpParms->dwTo; - TRACE(midi, "MCI_TO=%d \n", end); + FIXME(midi, "MCI_TO=%lu \n", end); } -#if 0 - if (dwFlags & MCI_NOTIFY) { - TRACE(midi, "MCI_NOTIFY %08lX !\n", lpParms->dwCallback); - switch(fork()) { - case -1: - WARN(midi, "Can't 'fork' process !\n"); - break; - case 0: - TRACE(midi, "process started ! play in background ...\n"); - break; - default: - TRACE(midi, "process started ! return to caller...\n"); - return 0; + + if (!(dwFlags & MCI_WAIT)) { + /** FIXME: I'm not 100% sure that wNotifyDeviceID is the right value in all cases ??? */ + return mciSendCommandAsync32(MCIMidiDev[wDevID].wNotifyDeviceID, MCI_PLAY, dwFlags, (DWORD)lpParms); + } + + /* init tracks */ + for (nt = 0; nt < MCIMidiDev[wDevID].nTracks; nt++) { + MCI_MIDITRACK* mmt = &MCIMidiDev[wDevID].tracks[nt]; + + mmt->wStatus = 1; /* ok, playing */ + mmt->dwIndex = mmt->dwFirst; + if (MCIMidiDev[wDevID].wFormat == 2 && nt > 0) { + mmt->dwEventPulse = MCIMidiDev[wDevID].tracks[nt - 1].dwLength; + } else { + mmt->dwEventPulse = 0; } + MIDI_ReadNextEvent(wDevID, mmt); /* FIXME == 0 */ } -#endif - - lpMidiHdr = USER_HEAP_LIN_ADDR(MCIMidiDev[wDevID].hMidiHdr); - - lpMidiHdr->lpData = (LPSTR)xmalloc(1200); - if (lpMidiHdr->lpData == NULL) return MCIERR_INTERNAL; - lpMidiHdr->dwBufferLength = 1024; - lpMidiHdr->dwUser = 0L; - lpMidiHdr->dwFlags = 0L; - dwRet = modMessage(wDevID, MODM_PREPARE, 0, (DWORD)lpMidiHdr, sizeof(MIDIHDR)); - - /* TRACE(midi, "after MODM_PREPARE \n"); */ - + + MCIMidiDev[wDevID].dwPulse = 0; + MCIMidiDev[wDevID].dwPositionMS = 0; + MCIMidiDev[wDevID].dwStartTicks = GetTickCount(); + MCIMidiDev[wDevID].dwTempo = 500000; MCIMidiDev[wDevID].dwStatus = MCI_MODE_PLAY; - while(MCIMidiDev[wDevID].dwStatus != MCI_MODE_STOP) { + + while (MCIMidiDev[wDevID].dwStatus != MCI_MODE_STOP) { + MCI_MIDITRACK* mmt; + DWORD hiPulse; + TRACE(midi, "MCIMidiDev[wDevID].dwStatus=%p %d\n", &MCIMidiDev[wDevID].dwStatus, MCIMidiDev[wDevID].dwStatus); - - ptr = (LPWORD)lpMidiHdr->lpData; - for (count = 0; count < lpMidiHdr->dwBufferLength; count++) { - if (MIDI_ReadVaryLen(wDevID, &dwData) != 0) break; - *ptr = LOWORD(dwData); + + while (MCIMidiDev[wDevID].dwStatus == MCI_MODE_PAUSE); + + /* find first event */ + hiPulse = 0xFFFFFFFFul; + cnt = 0xFFFFu; + for (nt = 0; nt < MCIMidiDev[wDevID].nTracks; nt++) { + mmt = &MCIMidiDev[wDevID].tracks[nt]; + + if (mmt->wStatus == 0) + continue; + if (mmt->dwEventPulse < hiPulse) { + hiPulse = mmt->dwEventPulse; + cnt = nt; + } } - /* - count = mmioRead32(MCIMidiDev[wDevID].hFile, lpMidiHdr->lpData, lpMidiHdr->dwBufferLength); - */ - TRACE(midi, "after read count = %d\n",count); - - if (count < 1) break; - lpMidiHdr->dwBytesRecorded = count; - TRACE(midi, "before MODM_LONGDATA lpMidiHdr=%p dwBytesRecorded=%lu\n", - lpMidiHdr, lpMidiHdr->dwBytesRecorded); - dwRet = modMessage(wDevID, MODM_LONGDATA, 0, (DWORD)lpMidiHdr, sizeof(MIDIHDR)); - if (dwRet != MMSYSERR_NOERROR) { - switch (dwRet) { - case MMSYSERR_NOTENABLED: - return MCIERR_DEVICE_NOT_READY; - - case MIDIERR_NODEVICE: - return MCIERR_INVALID_DEVICE_ID; - - case MIDIERR_UNPREPARED: - return MCIERR_DRIVER_INTERNAL; - - case MIDIERR_STILLPLAYING: - return MCIERR_SEQ_PORT_INUSE; - - case MMSYSERR_INVALPARAM: - return MCIERR_CANNOT_LOAD_DRIVER; + if (cnt == 0xFFFFu) /* no more event on tracks */ + break; + + mmt = &MCIMidiDev[wDevID].tracks[cnt]; + if (hiPulse > MCIMidiDev[wDevID].dwPulse) { + DWORD togo = MCIMidiDev[wDevID].dwStartTicks + + MIDI_ConvertPulseToMS(wDevID, hiPulse); + DWORD tc = GetTickCount(); + + TRACE(midi, "Pulses hi=0x%08lx <> cur=0x%08lx\n", hiPulse, MCIMidiDev[wDevID].dwPulse); + TRACE(midi, "Wait til %08lx -> %08lx ms\n", + tc - MCIMidiDev[wDevID].dwStartTicks, + togo - MCIMidiDev[wDevID].dwStartTicks); + if (tc < togo) Sleep(togo - tc); + MCIMidiDev[wDevID].dwPositionMS += MIDI_ConvertPulseToMS(wDevID, hiPulse - MCIMidiDev[wDevID].dwPulse); + MCIMidiDev[wDevID].dwPulse = hiPulse; + } + + switch (LOBYTE(LOWORD(mmt->dwEventData))) { + case 0xF0: + case 0xF7: /* sysex events */ + FIXME(midi, "Not handling SysEx events (yet)\n"); + break; + case 0xFF: + /* position after meta data header */ + mmioSeek32(MCIMidiDev[wDevID].hFile, mmt->dwIndex + HIWORD(mmt->dwEventData), SEEK_SET); + switch (HIBYTE(LOWORD(mmt->dwEventData))) { + case 0x00: /* 16-bit sequence number */ + if (TRACE_ON(midi)) { + WORD twd; + + MIDI_ReadWord(wDevID, &twd); /* == 0 */ + TRACE(midi, "Got sequence number %u\n", twd); + } + break; + case 0x01: /* any text */ + case 0x02: /* Copyright Message text */ + case 0x03: /* Sequence/Track Name text */ + case 0x04: /* Instrument Name text */ + case 0x05: /* Lyric text */ + case 0x06: /* Marker text */ + case 0x07: /* Cue-point text */ + if (TRACE_ON(midi)) { + char buf[1024]; + WORD len = mmt->wEventLength - HIWORD(mmt->dwEventData); + static char* info[8] = {"", "Text", "Copyright", "Seq/Trk name", + "Instrument", "Lyric", "Marker", "Cue-point"}; + WORD idx = HIBYTE(LOWORD(mmt->dwEventData)); + + if (len >= sizeof(buf)) { + WARN(midi, "Buffer for text is too small (%d bytes, when %u are needed)\n", sizeof(buf) - 1, len); + len = sizeof(buf) - 1; + } + if (mmioRead32(MCIMidiDev[wDevID].hFile, (HPSTR)buf, len) == len) { + buf[len] = 0; /* end string in case */ + TRACE(midi, "%s => \"%s\"\n", (idx < 8 ) ? info[idx] : "", buf); + } else { + WARN(midi, "Couldn't read data for %s\n", (idx < 8 ) ? info[idx] : ""); + } + } + break; + case 0x20: + /* MIDI channel + * cc + */ + if (TRACE_ON(midi)) { + BYTE bt; + + MIDI_ReadByte(wDevID, &bt); /* == 0 */ + FIXME(midi, "NIY: MIDI channel %u\n", bt); + + } else { + FIXME(midi, "NIY: MIDI channel\n"); + } + break; + case 0x21: + /* MIDI port + * pp + */ + if (TRACE_ON(midi)) { + BYTE bt; + + MIDI_ReadByte(wDevID, &bt); /* == 0 */ + FIXME(midi, "NIY: MIDI port %u\n", bt); + } else { + FIXME(midi, "NIY: MIDI port\n"); + } + break; + case 0x2F: /* end of track */ + mmt->wStatus = 0; + break; + case 0x51:/* set tempo */ + /* Tempo is expressed in µ-seconds per midi quarter note + * for format 1 MIDI files, this can only be present on track #0 + */ + if (mmt->wTrackNr != 0 && MCIMidiDev[wDevID].wFormat == 1) { + WARN(midi, "For format #1 MIDI files, tempo can only be changed on track #0 (%u)\n", mmt->wTrackNr); + } else { + BYTE tbt; + + MIDI_ReadByte(wDevID, &tbt); MCIMidiDev[wDevID].dwTempo = ((DWORD)tbt) << 16; + MIDI_ReadByte(wDevID, &tbt); MCIMidiDev[wDevID].dwTempo |= ((DWORD)tbt) << 8; + MIDI_ReadByte(wDevID, &tbt); MCIMidiDev[wDevID].dwTempo |= ((DWORD)tbt) << 0; + TRACE(midi, "Setting tempo to %ld (BPM=%ld)\n", MCIMidiDev[wDevID].dwTempo, 60000000l / MCIMidiDev[wDevID].dwTempo); + } + break; + case 0x54: /* (hour) (min) (second) (frame) (fractional-frame) - SMPTE track start */ + FIXME(midi, "NIY: SMPTE track start\n"); + break; + case 0x58: + if (TRACE_ON(midi)) { + BYTE num, den, cpmc, _32npqn; + + MIDI_ReadByte(wDevID, &num); + MIDI_ReadByte(wDevID, &den); /* to notate e.g. 6/8 */ + MIDI_ReadByte(wDevID, &cpmc); /* number of MIDI clocks per metronome click */ + MIDI_ReadByte(wDevID, &_32npqn); /* number of notated 32nd notes per MIDI quarter note */ + + TRACE(midi, "%u/%u, clock per metronome click=%u, 32nd notes by 1/4 note=%u\n", num, 1 << den, cpmc, _32npqn); + } + break; + case 0x59: + if (TRACE_ON(midi)) { + BYTE sf, mm; + + MIDI_ReadByte(wDevID, &sf); MIDI_ReadByte(wDevID, &mm); + + if (sf >= 0x80) TRACE(midi, "%d flats\n", -(char)sf); + else if (sf > 0) TRACE(midi, "%d sharps\n", (char)sf); + else TRACE(midi, "Key of C\n"); + TRACE(midi, "Mode: %s\n", (mm = 0) ? "major" : "minor"); + } + break; default: - return MCIERR_DRIVER; - } + WARN(midi, "Unknown MIDI meta event %02x. Skipping...\n", HIBYTE(LOWORD(mmt->dwEventData))); + break; + } + break; + default: + dwRet = modMessage(wDevID, MODM_DATA, 0, mmt->dwEventData, 0); + } + mmt->dwIndex += mmt->wEventLength; + if (mmt->dwIndex < mmt->dwFirst || mmt->dwIndex >= mmt->dwLast) { + mmt->wStatus = 0; + } + if (mmt->wStatus) { + MIDI_ReadNextEvent(wDevID, mmt); } } - dwRet = modMessage(wDevID, MODM_UNPREPARE, 0, (DWORD)lpMidiHdr, sizeof(MIDIHDR)); - if (lpMidiHdr->lpData != NULL) { - free(lpMidiHdr->lpData); - lpMidiHdr->lpData = NULL; - } + + /* stop all notes */ + modMessage(wDevID, MODM_DATA, 0, (MIDI_CTL_CHANGE << 8) | 0x78, 0); MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP; - if (dwFlags & MCI_NOTIFY) { + if (lpParms && (dwFlags & MCI_NOTIFY)) { TRACE(midi, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback); mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), MCIMidiDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); @@ -511,17 +894,23 @@ static DWORD MIDI_mciRecord(UINT16 wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpP DWORD dwRet; TRACE(midi, "(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms); + + if (wDevID >= MAX_MCIMIDIDRV || MCIMidiDev[wDevID].nUseCount == 0) { + WARN(midi, "Invalid wDevID=%u\n", wDevID); + return MCIERR_INVALID_DEVICE_ID; + } + if (MCIMidiDev[wDevID].hFile == 0) { WARN(midi, "can't find file='%08lx' !\n", (DWORD)MCIMidiDev[wDevID].openParms.lpstrElementName); return MCIERR_FILE_NOT_FOUND; } start = 1; end = 99999; - if (dwFlags & MCI_FROM) { + if (lpParms && (dwFlags & MCI_FROM)) { start = lpParms->dwFrom; TRACE(midi, "MCI_FROM=%d \n", start); } - if (dwFlags & MCI_TO) { + if (lpParms && (dwFlags & MCI_TO)) { end = lpParms->dwTo; TRACE(midi, "MCI_TO=%d \n", end); } @@ -533,7 +922,7 @@ static DWORD MIDI_mciRecord(UINT16 wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpP dwRet = midMessage(wDevID, MIDM_PREPARE, 0, (DWORD)lpMidiHdr, sizeof(MIDIHDR)); TRACE(midi, "after MIDM_PREPARE \n"); MCIMidiDev[wDevID].dwStatus = MCI_MODE_RECORD; - while(MCIMidiDev[wDevID].dwStatus != MCI_MODE_STOP) { + while (MCIMidiDev[wDevID].dwStatus != MCI_MODE_STOP) { TRACE(midi, "MCIMidiDev[wDevID].dwStatus=%p %d\n", &MCIMidiDev[wDevID].dwStatus, MCIMidiDev[wDevID].dwStatus); lpMidiHdr->dwBytesRecorded = 0; @@ -550,7 +939,7 @@ static DWORD MIDI_mciRecord(UINT16 wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpP lpMidiHdr->lpData = NULL; } MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP; - if (dwFlags & MCI_NOTIFY) { + if (lpParms && (dwFlags & MCI_NOTIFY)) { TRACE(midi, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback); mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), MCIMidiDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); @@ -564,7 +953,21 @@ static DWORD MIDI_mciRecord(UINT16 wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpP static DWORD MIDI_mciPause(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms) { TRACE(midi, "(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; + + if (wDevID >= MAX_MCIMIDIDRV || MCIMidiDev[wDevID].nUseCount == 0) { + WARN(midi, "Invalid wDevID=%u\n", wDevID); + return MCIERR_INVALID_DEVICE_ID; + } + + if (MCIMidiDev[wDevID].dwStatus == MCI_MODE_PLAY) { + MCIMidiDev[wDevID].dwStatus = MCI_MODE_PAUSE; + } + if (lpParms && (dwFlags & MCI_NOTIFY)) { + TRACE(midi, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + MCIMidiDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); + } + return 0; } @@ -574,7 +977,20 @@ static DWORD MIDI_mciPause(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpP static DWORD MIDI_mciResume(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms) { TRACE(midi, "(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms); - if (lpParms == NULL) return MCIERR_INTERNAL; + + if (wDevID >= MAX_MCIMIDIDRV || MCIMidiDev[wDevID].nUseCount == 0) { + WARN(midi, "Invalid wDevID=%u\n", wDevID); + return MCIERR_INVALID_DEVICE_ID; + } + + if (MCIMidiDev[wDevID].dwStatus == MCI_MODE_PAUSE) { + MCIMidiDev[wDevID].dwStatus = MCI_MODE_PLAY; + } + if (lpParms && (dwFlags & MCI_NOTIFY)) { + TRACE(midi, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback); + mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback), + MCIMidiDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL); + } return 0; } @@ -584,9 +1000,17 @@ static DWORD MIDI_mciResume(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lp static DWORD MIDI_mciSet(UINT16 wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms) { TRACE(midi, "(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + + if (wDevID >= MAX_MCIMIDIDRV || MCIMidiDev[wDevID].nUseCount == 0) { + WARN(midi, "Invalid wDevID=%u\n", wDevID); + return MCIERR_INVALID_DEVICE_ID; + } + TRACE(midi, "dwTimeFormat=%08lX\n", lpParms->dwTimeFormat); TRACE(midi, "dwAudio=%08lX\n", lpParms->dwAudio); + if (dwFlags & MCI_SET_TIME_FORMAT) { switch (lpParms->dwTimeFormat) { case MCI_FORMAT_MILLISECONDS: @@ -603,20 +1027,39 @@ static DWORD MIDI_mciSet(UINT16 wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms) return MCIERR_BAD_TIME_FORMAT; } } - if (dwFlags & MCI_SET_VIDEO) return MCIERR_UNSUPPORTED_FUNCTION; - if (dwFlags & MCI_SET_DOOR_OPEN) return MCIERR_UNSUPPORTED_FUNCTION; - if (dwFlags & MCI_SET_DOOR_CLOSED) return MCIERR_UNSUPPORTED_FUNCTION; - if (dwFlags & MCI_SET_AUDIO) - TRACE(midi, "MCI_SET_AUDIO !\n"); + if (dwFlags & MCI_SET_VIDEO) { + TRACE(midi, "No support for video !\n"); + return MCIERR_UNSUPPORTED_FUNCTION; + } + if (dwFlags & MCI_SET_DOOR_OPEN) { + TRACE(midi, "No support for door open !\n"); + return MCIERR_UNSUPPORTED_FUNCTION; + } + if (dwFlags & MCI_SET_DOOR_CLOSED) { + TRACE(midi, "No support for door close !\n"); + return MCIERR_UNSUPPORTED_FUNCTION; + } + if (dwFlags && MCI_SET_ON) { TRACE(midi, "MCI_SET_ON !\n"); + if (dwFlags & MCI_SET_AUDIO) { + TRACE(midi, "MCI_SET_AUDIO !\n"); + } if (dwFlags && MCI_SET_AUDIO_LEFT) TRACE(midi, "MCI_SET_AUDIO_LEFT !\n"); if (dwFlags && MCI_SET_AUDIO_RIGHT) TRACE(midi, "MCI_SET_AUDIO_RIGHT !\n"); } - if (dwFlags & MCI_SET_OFF) + if (dwFlags & MCI_SET_OFF) { TRACE(midi, "MCI_SET_OFF !\n"); + if (dwFlags & MCI_SET_AUDIO) { + TRACE(midi, "MCI_SET_AUDIO !\n"); + } + if (dwFlags && MCI_SET_AUDIO_LEFT) + TRACE(midi, "MCI_SET_AUDIO_LEFT !\n"); + if (dwFlags && MCI_SET_AUDIO_RIGHT) + TRACE(midi, "MCI_SET_AUDIO_RIGHT !\n"); + } if (dwFlags & MCI_SEQ_SET_MASTER) TRACE(midi, "MCI_SEQ_SET_MASTER !\n"); if (dwFlags & MCI_SEQ_SET_SLAVE) @@ -636,36 +1079,55 @@ static DWORD MIDI_mciSet(UINT16 wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms) static DWORD MIDI_mciStatus(UINT16 wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms) { TRACE(midi, "(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + + if (wDevID >= MAX_MCIMIDIDRV || MCIMidiDev[wDevID].nUseCount == 0) { + WARN(midi, "Invalid wDevID=%u\n", wDevID); + return MCIERR_INVALID_DEVICE_ID; + } + if (dwFlags & MCI_STATUS_ITEM) { - switch(lpParms->dwItem) { + switch (lpParms->dwItem) { case MCI_STATUS_CURRENT_TRACK: + TRACE(midi, "MCI_STATUS_CURRENT_TRACK !\n"); lpParms->dwReturn = 1; break; case MCI_STATUS_LENGTH: - lpParms->dwReturn = 5555; - if (dwFlags & MCI_TRACK) { - lpParms->dwTrack = 1; - lpParms->dwReturn = 2222; + TRACE(midi, "MCI_STATUS_LENGTH !\n"); + { + WORD nt; + DWORD ret = 0; + + for (nt = 0; nt < MCIMidiDev[wDevID].nTracks; nt++) { + if (MCIMidiDev[wDevID].wFormat == 2) { + ret += MCIMidiDev[wDevID].tracks[nt].dwLength; + } else { + if (MCIMidiDev[wDevID].tracks[nt].dwLength > ret) + ret = MCIMidiDev[wDevID].tracks[nt].dwLength; + } + } + lpParms->dwReturn = MIDI_ConvertPulseToMS(wDevID, ret); } break; case MCI_STATUS_MODE: - lpParms->dwReturn = MCI_MODE_STOP; + TRACE(midi, "MCI_STATUS_MODE !\n"); + lpParms->dwReturn = MCIMidiDev[wDevID].dwStatus; break; case MCI_STATUS_MEDIA_PRESENT: TRACE(midi, "MCI_STATUS_MEDIA_PRESENT !\n"); lpParms->dwReturn = TRUE; break; case MCI_STATUS_NUMBER_OF_TRACKS: - lpParms->dwReturn = 1; + TRACE(midi, "MCI_STATUS_NUMBER_OF_TRACKS !\n"); + lpParms->dwReturn = 1; /* FIXME: except in format 2 */ break; case MCI_STATUS_POSITION: - lpParms->dwReturn = 3333; - if (dwFlags & MCI_STATUS_START) - lpParms->dwItem = 1; - if (dwFlags & MCI_TRACK) { - lpParms->dwTrack = 1; - lpParms->dwReturn = 777; + TRACE(midi, "MCI_STATUS_POSITION !\n"); + if (dwFlags & MCI_STATUS_START) { + lpParms->dwReturn = 0; + } else { + lpParms->dwReturn = MCIMidiDev[wDevID].dwPositionMS; } break; case MCI_STATUS_READY: @@ -678,7 +1140,7 @@ static DWORD MIDI_mciStatus(UINT16 wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpP break; case MCI_SEQ_STATUS_DIVTYPE: TRACE(midi, "MCI_SEQ_STATUS_DIVTYPE !\n"); - lpParms->dwReturn = 0; + lpParms->dwReturn = MCI_SEQ_DIV_PPQN; break; case MCI_SEQ_STATUS_MASTER: TRACE(midi, "MCI_SEQ_STATUS_MASTER !\n"); @@ -698,12 +1160,15 @@ static DWORD MIDI_mciStatus(UINT16 wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpP break; case MCI_SEQ_STATUS_TEMPO: TRACE(midi, "MCI_SEQ_STATUS_TEMPO !\n"); - lpParms->dwReturn = 0; + lpParms->dwReturn = MCIMidiDev[wDevID].dwTempo; break; default: WARN(midi, "unknowm command %08lX !\n", lpParms->dwItem); return MCIERR_UNRECOGNIZED_COMMAND; } + } else { + WARN(midi, "No Status-Item!\n"); + return MCIERR_UNRECOGNIZED_COMMAND; } if (dwFlags & MCI_NOTIFY) { TRACE(midi, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback); @@ -720,39 +1185,59 @@ static DWORD MIDI_mciGetDevCaps(UINT16 wDevID, DWORD dwFlags, LPMCI_GETDEVCAPS_PARMS lpParms) { TRACE(midi, "(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + + if (wDevID >= MAX_MCIMIDIDRV || MCIMidiDev[wDevID].nUseCount == 0) { + WARN(midi, "Invalid wDevID=%u\n", wDevID); + return MCIERR_INVALID_DEVICE_ID; + } + if (dwFlags & MCI_GETDEVCAPS_ITEM) { - switch(lpParms->dwItem) { + switch (lpParms->dwItem) { case MCI_GETDEVCAPS_CAN_RECORD: + TRACE(midi, "MCI_GETDEVCAPS_CAN_RECORD !\n"); lpParms->dwReturn = TRUE; break; case MCI_GETDEVCAPS_HAS_AUDIO: + TRACE(midi, "MCI_GETDEVCAPS_HAS_AUDIO !\n"); lpParms->dwReturn = TRUE; break; case MCI_GETDEVCAPS_HAS_VIDEO: + TRACE(midi, "MCI_GETDEVCAPS_HAS_VIDEO !\n"); lpParms->dwReturn = FALSE; break; case MCI_GETDEVCAPS_DEVICE_TYPE: + TRACE(midi, "MCI_GETDEVCAPS_DEVICE_TYPE !\n"); lpParms->dwReturn = MCI_DEVTYPE_SEQUENCER; break; case MCI_GETDEVCAPS_USES_FILES: + TRACE(midi, "MCI_GETDEVCAPS_USES_FILES !\n"); lpParms->dwReturn = TRUE; break; case MCI_GETDEVCAPS_COMPOUND_DEVICE: + TRACE(midi, "MCI_GETDEVCAPS_COMPOUND_DEVICE !\n"); lpParms->dwReturn = TRUE; break; case MCI_GETDEVCAPS_CAN_EJECT: + TRACE(midi, "MCI_GETDEVCAPS_CAN_EJECT !\n"); lpParms->dwReturn = FALSE; break; case MCI_GETDEVCAPS_CAN_PLAY: + TRACE(midi, "MCI_GETDEVCAPS_CAN_PLAY !\n"); lpParms->dwReturn = TRUE; break; case MCI_GETDEVCAPS_CAN_SAVE: + TRACE(midi, "MCI_GETDEVCAPS_CAN_SAVE !\n"); lpParms->dwReturn = FALSE; break; default: + TRACE(midi, "Unknown capability (%08lx) !\n", lpParms->dwItem); return MCIERR_UNRECOGNIZED_COMMAND; } + } else { + TRACE(midi, "No GetDevCaps-Item !\n"); + return MCIERR_UNRECOGNIZED_COMMAND; } return 0; } @@ -763,9 +1248,17 @@ static DWORD MIDI_mciGetDevCaps(UINT16 wDevID, DWORD dwFlags, static DWORD MIDI_mciInfo(UINT16 wDevID, DWORD dwFlags, LPMCI_INFO_PARMS16 lpParms) { TRACE(midi, "(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + + if (wDevID >= MAX_MCIMIDIDRV || MCIMidiDev[wDevID].nUseCount == 0) { + WARN(midi, "Invalid wDevID=%u\n", wDevID); + return MCIERR_INVALID_DEVICE_ID; + } + lpParms->lpstrReturn = NULL; - switch(dwFlags) { + + switch (dwFlags) { case MCI_INFO_PRODUCT: lpParms->lpstrReturn = "Linux Sound System 0.5"; break; @@ -775,10 +1268,7 @@ static DWORD MIDI_mciInfo(UINT16 wDevID, DWORD dwFlags, LPMCI_INFO_PARMS16 lpPar default: return MCIERR_UNRECOGNIZED_COMMAND; } - if (lpParms->lpstrReturn != NULL) - lpParms->dwRetSize = strlen(lpParms->lpstrReturn); - else - lpParms->dwRetSize = 0; + lpParms->dwRetSize = (lpParms->lpstrReturn != NULL) ? strlen(lpParms->lpstrReturn) : 0; return 0; } @@ -850,8 +1340,7 @@ static void midReceiveChar(WORD wDevID, unsigned char value, DWORD dwTime) { DWORD toSend = 0; - TRACE(midi, "Adding %02xh to %d[%d]\n", - value, wDevID, MidiInDev[wDevID].incLen); + TRACE(midi, "Adding %02xh to %d[%d]\n", value, wDevID, MidiInDev[wDevID].incLen); if (wDevID >= MAX_MIDIINDRV) { WARN(midi, "bad devID\n"); @@ -957,7 +1446,7 @@ static void midReceiveChar(WORD wDevID, unsigned char value, DWORD dwTime) static VOID midTimeCallback(HWND32 hwnd, UINT32 msg, UINT32 id, DWORD dwTime) { unsigned char buffer[256]; - int len, idx; + int len, idx; TRACE(midi, "(%04X, %d, %d, %lu)\n", hwnd, msg, id, dwTime); @@ -1083,7 +1572,7 @@ static DWORD midOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags) #endif /* HAVE_OSS */ MidiInDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK); - switch(MidiInDev[wDevID].wFlags) { + switch (MidiInDev[wDevID].wFlags) { case DCB_NULL: TRACE(midi,"CALLBACK_NULL !\n"); break; @@ -1294,7 +1783,7 @@ DWORD WINAPI midMessage(WORD wDevID, WORD wMsg, DWORD dwUser, { TRACE(midi, "(%04X, %04X, %08lX, %08lX, %08lX);\n", wDevID, wMsg, dwUser, dwParam1, dwParam2); - switch(wMsg) { + switch (wMsg) { case MIDM_OPEN: return midOpen(wDevID,(LPMIDIOPENDESC)dwParam1, dwParam2); case MIDM_CLOSE: @@ -1556,7 +2045,7 @@ static DWORD modOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags) #endif /* HAVE_OSS */ MidiOutDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK); - switch(MidiOutDev[wDevID].wFlags) { + switch (MidiOutDev[wDevID].wFlags) { case DCB_NULL: TRACE(midi,"CALLBACK_NULL !\n"); break; @@ -1845,7 +2334,7 @@ static DWORD modData(WORD wDevID, DWORD dwParam) } break; default: - WARN(midi, "Internal error, shouldn't happen\n"); + WARN(midi, "Internal error, shouldn't happen (event=%08x)\n", evt & 0xF0); return MMSYSERR_NOTENABLED; } } @@ -1921,7 +2410,6 @@ static DWORD modData(WORD wDevID, DWORD dwParam) } SEQ_DUMPBUF(); - TRACE(midi, "done\n"); #else if (MidiOutDev[wDevID].unixdev == 0) { WARN(midi,"can't play !\n"); @@ -1967,6 +2455,7 @@ static DWORD modLongData(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize) return MIDIERR_STILLPLAYING; lpMidiHdr->dwFlags &= ~MHDR_DONE; lpMidiHdr->dwFlags |= MHDR_INQUEUE; + TRACE(midi, "dwBytesRecorded %lu !\n", lpMidiHdr->dwBytesRecorded); TRACE(midi, " %02X %02X %02X %02X\n", ((LPBYTE)(lpMidiHdr->reserved))[0], @@ -2070,6 +2559,7 @@ static DWORD modPrepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize) static DWORD modUnprepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize) { TRACE(midi, "(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize); + #ifdef HAVE_OSS if (midiSeqFD == -1) { WARN(midi,"can't unprepare !\n"); @@ -2103,14 +2593,15 @@ static DWORD modReset(WORD wDevID) } /************************************************************************** - * modMessage [sample driver] + * modMessage [sample driver] */ DWORD WINAPI modMessage(WORD wDevID, WORD wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2) { TRACE(midi, "(%04X, %04X, %08lX, %08lX, %08lX);\n", wDevID, wMsg, dwUser, dwParam1, dwParam2); - switch(wMsg) { + + switch (wMsg) { case MODM_OPEN: return modOpen(wDevID, (LPMIDIOPENDESC)dwParam1, dwParam2); case MODM_CLOSE: @@ -2140,60 +2631,70 @@ DWORD WINAPI modMessage(WORD wDevID, WORD wMsg, DWORD dwUser, } /************************************************************************** - * MIDI_DriverProc [sample driver] + * MIDI_DriverProc16 [sample driver] */ -LONG MIDI_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, - DWORD dwParam1, DWORD dwParam2) +LONG MIDI_DriverProc16(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, + DWORD dwParam1, DWORD dwParam2) { - switch(wMsg) { - case DRV_LOAD: - return 1; - case DRV_FREE: - return 1; - case DRV_OPEN: - return 1; - case DRV_CLOSE: - return 1; - case DRV_ENABLE: - return 1; - case DRV_DISABLE: - return 1; - case DRV_QUERYCONFIGURE: - return 1; - case DRV_CONFIGURE: - MessageBox16(0, "Sample Midi Linux Driver !", - "MMLinux Driver", MB_OK); - return 1; - case DRV_INSTALL: - return DRVCNF_RESTART; - case DRV_REMOVE: - return DRVCNF_RESTART; - case MCI_OPEN_DRIVER: - case MCI_OPEN: - return MIDI_mciOpen(dwDevID, dwParam1, (LPMCI_OPEN_PARMS16)PTR_SEG_TO_LIN(dwParam2)); - case MCI_CLOSE_DRIVER: - case MCI_CLOSE: - return MIDI_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_PLAY: - return MIDI_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_RECORD: - return MIDI_mciRecord(dwDevID, dwParam1, (LPMCI_RECORD_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_STOP: - return MIDI_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_SET: - return MIDI_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_PAUSE: - return MIDI_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_RESUME: - return MIDI_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_STATUS: - return MIDI_mciStatus(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_GETDEVCAPS: - return MIDI_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2)); - case MCI_INFO: - return MIDI_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS16)PTR_SEG_TO_LIN(dwParam2)); - default: - return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2); + switch (wMsg) { + case DRV_LOAD: return 1; + case DRV_FREE: return 1; + case DRV_OPEN: return 1; + case DRV_CLOSE: return 1; + case DRV_ENABLE: return 1; + case DRV_DISABLE: return 1; + case DRV_QUERYCONFIGURE: return 1; + case DRV_CONFIGURE: MessageBox16(0, "Sample Midi Linux Driver !", "MMLinux Driver", MB_OK); return 1; + case DRV_INSTALL: return DRVCNF_RESTART; + case DRV_REMOVE: return DRVCNF_RESTART; + case MCI_OPEN_DRIVER: + case MCI_OPEN: return MIDI_mciOpen(dwDevID, dwParam1, PTR_SEG_TO_LIN(dwParam2), FALSE); + case MCI_CLOSE_DRIVER: + case MCI_CLOSE: return MIDI_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_PLAY: return MIDI_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_RECORD: return MIDI_mciRecord(dwDevID, dwParam1, (LPMCI_RECORD_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_STOP: return MIDI_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_SET: return MIDI_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_PAUSE: return MIDI_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_RESUME: return MIDI_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_STATUS: return MIDI_mciStatus(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_GETDEVCAPS: return MIDI_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2)); + case MCI_INFO: return MIDI_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS16)PTR_SEG_TO_LIN(dwParam2)); + default: return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2); + } +} + +/************************************************************************** + * MIDI_DriverProc32 [sample driver] + */ +LONG MIDI_DriverProc32(DWORD dwDevID, HDRVR16 hDriv, DWORD wMsg, + DWORD dwParam1, DWORD dwParam2) +{ + switch (wMsg) { + case DRV_LOAD: return 1; + case DRV_FREE: return 1; + case DRV_OPEN: return 1; + case DRV_CLOSE: return 1; + case DRV_ENABLE: return 1; + case DRV_DISABLE: return 1; + case DRV_QUERYCONFIGURE: return 1; + case DRV_CONFIGURE: MessageBox16(0, "Sample Midi Linux Driver !", "MMLinux Driver", MB_OK); return 1; + case DRV_INSTALL: return DRVCNF_RESTART; + case DRV_REMOVE: return DRVCNF_RESTART; + case MCI_OPEN_DRIVER: + case MCI_OPEN: return MIDI_mciOpen(dwDevID, dwParam1, (void*)dwParam2, TRUE); + case MCI_CLOSE_DRIVER: + case MCI_CLOSE: return MIDI_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case MCI_PLAY: return MIDI_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)dwParam2); + case MCI_RECORD: return MIDI_mciRecord(dwDevID, dwParam1, (LPMCI_RECORD_PARMS)dwParam2); + case MCI_STOP: return MIDI_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case MCI_SET: return MIDI_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)dwParam2); + case MCI_PAUSE: return MIDI_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case MCI_RESUME: return MIDI_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case MCI_STATUS: return MIDI_mciStatus(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)dwParam2); + case MCI_GETDEVCAPS: return MIDI_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)dwParam2); + case MCI_INFO: return MIDI_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS16)dwParam2); + default: return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2); } } /*-----------------------------------------------------------------------*/ diff --git a/multimedia/mmsystem.c b/multimedia/mmsystem.c index 3e2f7b3468d..115fbec3659 100644 --- a/multimedia/mmsystem.c +++ b/multimedia/mmsystem.c @@ -5,6 +5,12 @@ * * Copyright 1993 Martin Ayotte */ + +/* + * Eric POUECH : + * 98/9 added support for Win32 MCI + */ + /* FIXME: I think there are some segmented vs. linear pointer weirdnesses * and long term pointers to 16 bit space in here */ @@ -23,42 +29,33 @@ #include "driver.h" #include "file.h" #include "mmsystem.h" +#include "multimedia.h" #include "debug.h" #include "xmalloc.h" #include "callback.h" #include "module.h" #include "selectors.h" -static int InstalledCount; -static int InstalledListLen; -static LPSTR lpInstallNames = NULL; +int mciInstalledCount; +int mciInstalledListLen; +LPSTR lpmciInstallNames = NULL; -struct LINUX_MCIDRIVER mciDrv[MAXMCIDRIVERS]; +struct WINE_MCIDRIVER mciDrv[MAXMCIDRIVERS]; UINT16 WINAPI midiGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize); static UINT16 waveGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize); -LONG WINAPI DrvDefDriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, - DWORD dwParam1, DWORD dwParam2); +LONG WINAPI DrvDefDriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, + DWORD dwParam1, DWORD dwParam2); -LONG WAVE_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, - DWORD dwParam1, DWORD dwParam2); -LONG MIDI_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, - DWORD dwParam1, DWORD dwParam2); -LONG CDAUDIO_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, - DWORD dwParam1, DWORD dwParam2); -LONG ANIM_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, - DWORD dwParam1, DWORD dwParam2); - - -#define GetDrv(wDevID) (&mciDrv[MMSYSTEM_DevIDToIndex(wDevID)]) -#define GetOpenDrv(wDevID) (&(GetDrv(wDevID)->mop)) +#define mciGetDrv(wDevID) (&mciDrv[MMSYSTEM_DevIDToIndex(wDevID)]) +#define mciGetOpenDrv(wDevID) (&(mciGetDrv(wDevID)->mop)) /* The wDevID's returned by wine were originally in the range * 0 - (MAXMCIDRIVERS - 1) and used directly as array indices. * Unfortunately, ms-windows uses wDevID of zero to indicate * errors. Now, multimedia drivers must pass the wDevID through * MMSYSTEM_DevIDToIndex to get an index in that range. An - * aribtrary value, MMSYSTEM_MAGIC is added to the wDevID seen + * arbitrary value, MMSYSTEM_MAGIC is added to the wDevID seen * by the windows programs. */ @@ -89,7 +86,7 @@ UINT16 MMSYSTEM_NextDevID(UINT16 wDevID) } /************************************************************************** - * MMSYSTEM_DevIdValid [internal] + * MMSYSTEM_DevIDValid [internal] */ BOOL32 MMSYSTEM_DevIDValid(UINT16 wDevID) { @@ -102,19 +99,18 @@ BOOL32 MMSYSTEM_DevIDValid(UINT16 wDevID) int WINAPI MMSYSTEM_WEP(HINSTANCE16 hInstance, WORD wDataSeg, WORD cbHeapSize, LPSTR lpCmdLine) { - FIXME(mmsys, "STUB: Unloading MMSystem DLL ... hInst=%04X \n", - hInstance); + FIXME(mmsys, "STUB: Unloading MMSystem DLL ... hInst=%04X \n", hInstance); return(TRUE); } -void MMSYSTEM_MMTIME32to16(LPMMTIME16 mmt16,LPMMTIME32 mmt32) +static void MMSYSTEM_MMTIME32to16(LPMMTIME16 mmt16,LPMMTIME32 mmt32) { mmt16->wType = mmt32->wType; /* layout of rest is the same for 32/16 */ memcpy(&(mmt32->u),&(mmt16->u),sizeof(mmt16->u)); } -void MMSYSTEM_MMTIME16to32(LPMMTIME32 mmt32,LPMMTIME16 mmt16) +static void MMSYSTEM_MMTIME16to32(LPMMTIME32 mmt32,LPMMTIME16 mmt16) { mmt32->wType = mmt16->wType; /* layout of rest is the same for 32/16, @@ -123,142 +119,137 @@ void MMSYSTEM_MMTIME16to32(LPMMTIME32 mmt32,LPMMTIME16 mmt16) memcpy(&(mmt16->u),&(mmt32->u),sizeof(mmt16->u)); } -HANDLE32 PlaySound_hThread = 0; -HANDLE32 PlaySound_hPlayEvent = 0; -HANDLE32 PlaySound_hReadyEvent = 0; -HANDLE32 PlaySound_hMiddleEvent = 0; -BOOL32 PlaySound_Result = FALSE; -int PlaySound_Stop = FALSE; -int PlaySound_Playing = FALSE; +static HANDLE32 PlaySound_hThread = 0; +static HANDLE32 PlaySound_hPlayEvent = 0; +static HANDLE32 PlaySound_hReadyEvent = 0; +static HANDLE32 PlaySound_hMiddleEvent = 0; +static BOOL32 PlaySound_Result = FALSE; +static int PlaySound_Stop = FALSE; +static int PlaySound_Playing = FALSE; -LPCSTR PlaySound_pszSound = NULL; -HMODULE32 PlaySound_hmod = 0; -DWORD PlaySound_fdwSound = 0; -int PlaySound_Loop = FALSE; -int PlaySound_SearchMode = 0; /* 1 - sndPlaySound search order - 2 - PlaySound order */ +static LPCSTR PlaySound_pszSound = NULL; +static HMODULE32 PlaySound_hmod = 0; +static DWORD PlaySound_fdwSound = 0; +static int PlaySound_Loop = FALSE; +static int PlaySound_SearchMode = 0; /* 1 - sndPlaySound search order + 2 - PlaySound order */ -HMMIO16 get_mmioFromFile(LPCSTR lpszName) +static HMMIO16 get_mmioFromFile(LPCSTR lpszName) { - return mmioOpen16((LPSTR)lpszName, NULL, - MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE); + return mmioOpen16((LPSTR)lpszName, NULL, + MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE); } -HMMIO16 get_mmioFromProfile(UINT32 uFlags, LPCSTR lpszName) +static HMMIO16 get_mmioFromProfile(UINT32 uFlags, LPCSTR lpszName) { - char str[128]; - LPSTR ptr; - HMMIO16 hmmio; - TRACE(mmsys, "searching in SystemSound List !\n"); - GetProfileString32A("Sounds", (LPSTR)lpszName, "", str, sizeof(str)); - if (strlen(str) == 0) { - if (uFlags & SND_NODEFAULT) return 0; - GetProfileString32A("Sounds", "Default", "", str, sizeof(str)); - if (strlen(str) == 0) return 0; - } - if ( (ptr = (LPSTR)strchr(str, ',')) != NULL) *ptr = '\0'; - hmmio = get_mmioFromFile(str); - if (hmmio == 0) { - WARN(mmsys, "can't find SystemSound='%s' !\n", str); - return 0; - } - return hmmio; + char str[128]; + LPSTR ptr; + HMMIO16 hmmio; + + TRACE(mmsys, "searching in SystemSound List !\n"); + GetProfileString32A("Sounds", (LPSTR)lpszName, "", str, sizeof(str)); + if (strlen(str) == 0) { + if (uFlags & SND_NODEFAULT) return 0; + GetProfileString32A("Sounds", "Default", "", str, sizeof(str)); + if (strlen(str) == 0) return 0; + } + if ( (ptr = (LPSTR)strchr(str, ',')) != NULL) *ptr = '\0'; + hmmio = get_mmioFromFile(str); + if (hmmio == 0) { + WARN(mmsys, "can't find SystemSound='%s' !\n", str); + return 0; + } + return hmmio; } -BOOL16 WINAPI proc_PlaySound(LPCSTR lpszSoundName, UINT32 uFlags) +static BOOL16 WINAPI proc_PlaySound(LPCSTR lpszSoundName, UINT32 uFlags) { - BOOL16 bRet = FALSE; - HMMIO16 hmmio; - MMCKINFO ckMainRIFF; - - TRACE(mmsys, "SoundName='%s' uFlags=%04X !\n", lpszSoundName, uFlags); - if (lpszSoundName == NULL) { - TRACE(mmsys, "Stop !\n"); - return FALSE; - } - if (uFlags & SND_MEMORY) { - MMIOINFO16 mminfo; - memset(&mminfo, 0, sizeof(mminfo)); - mminfo.fccIOProc = FOURCC_MEM; - mminfo.pchBuffer = (LPSTR)lpszSoundName; - mminfo.cchBuffer = -1; - TRACE(mmsys, "Memory sound %p\n",lpszSoundName); - hmmio = mmioOpen16(NULL, &mminfo, MMIO_READ); - } else { - hmmio = 0; - if (uFlags & SND_ALIAS) + BOOL16 bRet = FALSE; + HMMIO16 hmmio; + MMCKINFO ckMainRIFF; + + TRACE(mmsys, "SoundName='%s' uFlags=%04X !\n", lpszSoundName, uFlags); + if (lpszSoundName == NULL) { + TRACE(mmsys, "Stop !\n"); + return FALSE; + } + if (uFlags & SND_MEMORY) { + MMIOINFO16 mminfo; + memset(&mminfo, 0, sizeof(mminfo)); + mminfo.fccIOProc = FOURCC_MEM; + mminfo.pchBuffer = (LPSTR)lpszSoundName; + mminfo.cchBuffer = -1; + TRACE(mmsys, "Memory sound %p\n",lpszSoundName); + hmmio = mmioOpen16(NULL, &mminfo, MMIO_READ); + } else { + hmmio = 0; + if (uFlags & SND_ALIAS) if ((hmmio=get_mmioFromProfile(uFlags, lpszSoundName)) == 0) - return FALSE; - - if (uFlags & SND_FILENAME) + return FALSE; + + if (uFlags & SND_FILENAME) if ((hmmio=get_mmioFromFile(lpszSoundName)) == 0) return FALSE; - - if (PlaySound_SearchMode == 1) { + + if (PlaySound_SearchMode == 1) { PlaySound_SearchMode = 0; if ((hmmio=get_mmioFromFile(lpszSoundName)) == 0) - if ((hmmio=get_mmioFromProfile(uFlags, lpszSoundName)) == 0) - return FALSE; - } - - if (PlaySound_SearchMode == 2) { - PlaySound_SearchMode = 0; - if ((hmmio=get_mmioFromProfile(uFlags | SND_NODEFAULT, lpszSoundName)) == 0) - if ((hmmio=get_mmioFromFile(lpszSoundName)) == 0) - if ((hmmio=get_mmioFromProfile(uFlags, lpszSoundName)) == 0) return FALSE; - } + if ((hmmio=get_mmioFromProfile(uFlags, lpszSoundName)) == 0) + return FALSE; } - if (mmioDescend(hmmio, &ckMainRIFF, NULL, 0) == 0) + if (PlaySound_SearchMode == 2) { + PlaySound_SearchMode = 0; + if ((hmmio=get_mmioFromProfile(uFlags | SND_NODEFAULT, lpszSoundName)) == 0) + if ((hmmio=get_mmioFromFile(lpszSoundName)) == 0) + if ((hmmio=get_mmioFromProfile(uFlags, lpszSoundName)) == 0) return FALSE; + } + } + + if (mmioDescend(hmmio, &ckMainRIFF, NULL, 0) == 0) do { TRACE(mmsys, "ParentChunk ckid=%.4s fccType=%.4s cksize=%08lX \n", - (LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType, ckMainRIFF.cksize); - + (LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType, ckMainRIFF.cksize); + if ((ckMainRIFF.ckid == FOURCC_RIFF) && - (ckMainRIFF.fccType == mmioFOURCC('W', 'A', 'V', 'E'))) - { + (ckMainRIFF.fccType == mmioFOURCC('W', 'A', 'V', 'E'))) { MMCKINFO mmckInfo; - + mmckInfo.ckid = mmioFOURCC('f', 'm', 't', ' '); - - if (mmioDescend(hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK) == 0) - { + + if (mmioDescend(hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK) == 0) { PCMWAVEFORMAT pcmWaveFormat; - + TRACE(mmsys, "Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n", - (LPSTR)&mmckInfo.ckid, (LPSTR)&mmckInfo.fccType, mmckInfo.cksize); - + (LPSTR)&mmckInfo.ckid, (LPSTR)&mmckInfo.fccType, mmckInfo.cksize); + if (mmioRead32(hmmio,(HPSTR)&pcmWaveFormat, - (long) sizeof(PCMWAVEFORMAT)) == (long) sizeof(PCMWAVEFORMAT)) - { - + (long) sizeof(PCMWAVEFORMAT)) == (long) sizeof(PCMWAVEFORMAT)) { TRACE(mmsys, "wFormatTag=%04X !\n", pcmWaveFormat.wf.wFormatTag); TRACE(mmsys, "nChannels=%d \n", pcmWaveFormat.wf.nChannels); TRACE(mmsys, "nSamplesPerSec=%ld\n", pcmWaveFormat.wf.nSamplesPerSec); TRACE(mmsys, "nAvgBytesPerSec=%ld\n", pcmWaveFormat.wf.nAvgBytesPerSec); TRACE(mmsys, "nBlockAlign=%d \n", pcmWaveFormat.wf.nBlockAlign); TRACE(mmsys, "wBitsPerSample=%u !\n", pcmWaveFormat.wBitsPerSample); - + mmckInfo.ckid = mmioFOURCC('d', 'a', 't', 'a'); - if (mmioDescend(hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK) == 0) - { + if (mmioDescend(hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK) == 0) { WAVEOPENDESC waveDesc; DWORD dwRet; - + TRACE(mmsys, "Chunk Found \ - ckid=%.4s fccType=%.4s cksize=%08lX \n", (LPSTR)&mmckInfo.ckid, (LPSTR)&mmckInfo.fccType, mmckInfo.cksize); - +ckid=%.4s fccType=%.4s cksize=%08lX \n", (LPSTR)&mmckInfo.ckid, (LPSTR)&mmckInfo.fccType, mmckInfo.cksize); + pcmWaveFormat.wf.nAvgBytesPerSec = pcmWaveFormat.wf.nSamplesPerSec * - pcmWaveFormat.wf.nBlockAlign; + pcmWaveFormat.wf.nBlockAlign; waveDesc.hWave = 0; waveDesc.lpFormat = (LPWAVEFORMAT)&pcmWaveFormat; - + dwRet = wodMessage( 0, WODM_OPEN, 0, (DWORD)&waveDesc, CALLBACK_NULL); - if (dwRet == MMSYSERR_NOERROR) - { + if (dwRet == MMSYSERR_NOERROR) { WAVEHDR waveHdr; HGLOBAL16 hData; INT32 count, bufsize, left = mmckInfo.cksize; - + bufsize = 64000; hData = GlobalAlloc16(GMEM_MOVEABLE, bufsize); waveHdr.lpData = (LPSTR)GlobalLock16(hData); @@ -266,16 +257,14 @@ BOOL16 WINAPI proc_PlaySound(LPCSTR lpszSoundName, UINT32 uFlags) waveHdr.dwUser = 0L; waveHdr.dwFlags = 0L; waveHdr.dwLoops = 0L; - + dwRet = wodMessage(0,WODM_PREPARE,0,(DWORD)&waveHdr,sizeof(WAVEHDR)); - if (dwRet == MMSYSERR_NOERROR) - { - while( left ) - { + if (dwRet == MMSYSERR_NOERROR) { + while (left) { if (PlaySound_Stop) { - PlaySound_Stop = FALSE; - PlaySound_Loop = FALSE; - break; + PlaySound_Stop = FALSE; + PlaySound_Loop = FALSE; + break; } if (bufsize > left) bufsize = left; count = mmioRead32(hmmio,waveHdr.lpData,bufsize); @@ -288,11 +277,11 @@ BOOL16 WINAPI proc_PlaySound(LPCSTR lpszSoundName, UINT32 uFlags) } wodMessage( 0, WODM_UNPREPARE, 0, (DWORD)&waveHdr, sizeof(WAVEHDR)); wodMessage( 0, WODM_CLOSE, 0, 0L, 0L); - + bRet = TRUE; - } - else WARN(mmsys, "can't prepare WaveOut device !\n"); - + } else + WARN(mmsys, "can't prepare WaveOut device !\n"); + GlobalUnlock16(hData); GlobalFree16(hData); } @@ -301,51 +290,50 @@ BOOL16 WINAPI proc_PlaySound(LPCSTR lpszSoundName, UINT32 uFlags) } } } while (PlaySound_Loop); - - if (hmmio != 0) mmioClose32(hmmio, 0); - return bRet; + + if (hmmio != 0) mmioClose32(hmmio, 0); + return bRet; } static DWORD PlaySound_Thread(LPVOID arg) { DWORD res; - HRSRC32 hRES; - HGLOBAL32 hGLOB; - void *ptr; + + for (;;) { + PlaySound_Playing = FALSE; + SetEvent(PlaySound_hReadyEvent); + res = WaitForSingleObject(PlaySound_hPlayEvent, INFINITE32); + ResetEvent(PlaySound_hReadyEvent); + SetEvent(PlaySound_hMiddleEvent); + if (res == WAIT_FAILED) ExitThread(2); + if (res != WAIT_OBJECT_0) continue; + PlaySound_Playing = TRUE; + + if ((PlaySound_fdwSound & SND_RESOURCE) == SND_RESOURCE) { + HRSRC32 hRES; + HGLOBAL32 hGLOB; + void *ptr; - while (TRUE) { - PlaySound_Playing=FALSE; - SetEvent(PlaySound_hReadyEvent); - res=WaitForSingleObject(PlaySound_hPlayEvent, INFINITE32); - ResetEvent(PlaySound_hReadyEvent); - SetEvent(PlaySound_hMiddleEvent); - if (res==WAIT_FAILED) ExitThread(2); - if (res!=WAIT_OBJECT_0) continue; - PlaySound_Playing=TRUE; - - if ((PlaySound_fdwSound & SND_RESOURCE) == SND_RESOURCE) { - if ((hRES=FindResource32A(PlaySound_hmod, PlaySound_pszSound, - "WAVE"))==0) { - PlaySound_Result=FALSE; - continue; + if ((hRES = FindResource32A(PlaySound_hmod, PlaySound_pszSound, "WAVE")) == 0) { + PlaySound_Result = FALSE; + continue; + } + if ((hGLOB = LoadResource32(PlaySound_hmod, hRES)) == 0) { + PlaySound_Result = FALSE; + continue; + } + if ((ptr = LockResource32(hGLOB)) == NULL) { + FreeResource32(hGLOB); + PlaySound_Result = FALSE; + continue; + } + PlaySound_Result = proc_PlaySound(ptr, + ((UINT16)PlaySound_fdwSound ^ SND_RESOURCE) | SND_MEMORY); + FreeResource32(hGLOB); + continue; } - if ((hGLOB=LoadResource32(PlaySound_hmod, hRES))==0) { - PlaySound_Result=FALSE; - continue; - } - if ( (ptr=LockResource32(hGLOB)) == NULL ) { - FreeResource32(hGLOB); - PlaySound_Result=FALSE; - continue; - } - PlaySound_Result=proc_PlaySound(ptr, - ((UINT16) PlaySound_fdwSound ^ SND_RESOURCE) | SND_MEMORY); - FreeResource32(hGLOB); - continue; - } - PlaySound_Result=proc_PlaySound(PlaySound_pszSound, - (UINT16) PlaySound_fdwSound); - } + PlaySound_Result=proc_PlaySound(PlaySound_pszSound, (UINT16)PlaySound_fdwSound); + } } /************************************************************************** @@ -353,67 +341,70 @@ static DWORD PlaySound_Thread(LPVOID arg) */ BOOL32 WINAPI PlaySound32A(LPCSTR pszSound, HMODULE32 hmod, DWORD fdwSound) { - static LPSTR StrDup = NULL; - - TRACE(mmsys, "pszSound='%p' hmod=%04X fdwSound=%08lX\n", - pszSound, hmod, fdwSound); - - if (PlaySound_hThread == 0) { /* This is the first time they called us */ - DWORD id; - if ((PlaySound_hThread = CreateThread(NULL, 0, PlaySound_Thread, - 0, 0, &id)) == 0) return FALSE; - if ((PlaySound_hReadyEvent=CreateEvent32A(NULL, TRUE, FALSE, NULL)) == 0) - return FALSE; - if ((PlaySound_hMiddleEvent=CreateEvent32A(NULL, FALSE, FALSE, NULL)) == 0) - return FALSE; - if ((PlaySound_hPlayEvent=CreateEvent32A(NULL, FALSE, FALSE, NULL)) == 0) - return FALSE; - } - -/* FIXME? I see no difference between SND_WAIT and SND_NOSTOP ! */ - if ((fdwSound & (SND_NOWAIT | SND_NOSTOP)) && PlaySound_Playing) return FALSE; - - /* Trying to stop if playing */ - if (PlaySound_Playing) PlaySound_Stop = TRUE; - -/* Waiting playing thread to get ready. I think 10 secs is ok & if not then leave*/ - if (WaitForSingleObject(PlaySound_hReadyEvent, 1000*10) != WAIT_OBJECT_0) - return FALSE; - - if (!pszSound || (fdwSound & SND_PURGE)) return FALSE; /* We stoped playing so leaving */ - - if (PlaySound_SearchMode != 1) PlaySound_SearchMode = 2; - if (!(fdwSound & SND_ASYNC)) { - if (fdwSound & SND_LOOP) return FALSE; - PlaySound_pszSound = pszSound; - PlaySound_hmod = hmod; - PlaySound_fdwSound = fdwSound; - PlaySound_Result = FALSE; - SetEvent(PlaySound_hPlayEvent); - if (WaitForSingleObject(PlaySound_hMiddleEvent, INFINITE32) != - WAIT_OBJECT_0) return FALSE; - if (WaitForSingleObject(PlaySound_hReadyEvent, INFINITE32) != - WAIT_OBJECT_0) return FALSE; - return PlaySound_Result; - } else { - PlaySound_hmod = hmod; - PlaySound_fdwSound = fdwSound; - PlaySound_Result = FALSE; - if (StrDup) { - HeapFree(GetProcessHeap(), 0, StrDup); - StrDup = NULL; + static LPSTR StrDup = NULL; + + TRACE(mmsys, "pszSound='%p' hmod=%04X fdwSound=%08lX\n", + pszSound, hmod, fdwSound); + + if (PlaySound_hThread == 0) { /* This is the first time they called us */ + DWORD id; + if ((PlaySound_hThread = CreateThread(NULL, 0, PlaySound_Thread, 0, 0, &id)) == 0) + return FALSE; + if ((PlaySound_hReadyEvent = CreateEvent32A(NULL, TRUE, FALSE, NULL)) == 0) + return FALSE; + if ((PlaySound_hMiddleEvent = CreateEvent32A(NULL, FALSE, FALSE, NULL)) == 0) + return FALSE; + if ((PlaySound_hPlayEvent = CreateEvent32A(NULL, FALSE, FALSE, NULL)) == 0) + return FALSE; } - if (!((fdwSound & SND_MEMORY) || ((fdwSound & SND_RESOURCE) && - !((DWORD)pszSound >> 16)) || !pszSound)) { - StrDup = HEAP_strdupA(GetProcessHeap(),0,pszSound); - PlaySound_pszSound = StrDup; - } else PlaySound_pszSound = pszSound; - PlaySound_Loop = fdwSound & SND_LOOP; - SetEvent(PlaySound_hPlayEvent); - ResetEvent(PlaySound_hMiddleEvent); - return TRUE; - } - return FALSE; + + /* FIXME? I see no difference between SND_WAIT and SND_NOSTOP ! */ + if ((fdwSound & (SND_NOWAIT | SND_NOSTOP)) && PlaySound_Playing) + return FALSE; + + /* Trying to stop if playing */ + if (PlaySound_Playing) PlaySound_Stop = TRUE; + + /* Waiting playing thread to get ready. I think 10 secs is ok & if not then leave*/ + if (WaitForSingleObject(PlaySound_hReadyEvent, 1000*10) != WAIT_OBJECT_0) + return FALSE; + + if (!pszSound || (fdwSound & SND_PURGE)) + return FALSE; /* We stoped playing so leaving */ + + if (PlaySound_SearchMode != 1) PlaySound_SearchMode = 2; + if (!(fdwSound & SND_ASYNC)) { + if (fdwSound & SND_LOOP) + return FALSE; + PlaySound_pszSound = pszSound; + PlaySound_hmod = hmod; + PlaySound_fdwSound = fdwSound; + PlaySound_Result = FALSE; + SetEvent(PlaySound_hPlayEvent); + if (WaitForSingleObject(PlaySound_hMiddleEvent, INFINITE32) != WAIT_OBJECT_0) + return FALSE; + if (WaitForSingleObject(PlaySound_hReadyEvent, INFINITE32) != WAIT_OBJECT_0) + return FALSE; + return PlaySound_Result; + } else { + PlaySound_hmod = hmod; + PlaySound_fdwSound = fdwSound; + PlaySound_Result = FALSE; + if (StrDup) { + HeapFree(GetProcessHeap(), 0, StrDup); + StrDup = NULL; + } + if (!((fdwSound & SND_MEMORY) || ((fdwSound & SND_RESOURCE) && + !((DWORD)pszSound >> 16)) || !pszSound)) { + StrDup = HEAP_strdupA(GetProcessHeap(),0,pszSound); + PlaySound_pszSound = StrDup; + } else PlaySound_pszSound = pszSound; + PlaySound_Loop = fdwSound & SND_LOOP; + SetEvent(PlaySound_hPlayEvent); + ResetEvent(PlaySound_hMiddleEvent); + return TRUE; + } + return FALSE; } /************************************************************************** @@ -421,23 +412,23 @@ BOOL32 WINAPI PlaySound32A(LPCSTR pszSound, HMODULE32 hmod, DWORD fdwSound) */ BOOL32 WINAPI PlaySound32W(LPCWSTR pszSound, HMODULE32 hmod, DWORD fdwSound) { - LPSTR pszSoundA; - BOOL32 bSound; - - if (!((fdwSound & SND_MEMORY) || ((fdwSound & SND_RESOURCE) && - !((DWORD)pszSound >> 16)) || !pszSound)) { - pszSoundA = HEAP_strdupWtoA(GetProcessHeap(),0,pszSound); - bSound = PlaySound32A(pszSoundA, hmod, fdwSound); - HeapFree(GetProcessHeap(),0,pszSoundA); - } else - bSound = PlaySound32A((LPCSTR)pszSound, hmod, fdwSound); - - return bSound; + LPSTR pszSoundA; + BOOL32 bSound; + + if (!((fdwSound & SND_MEMORY) || ((fdwSound & SND_RESOURCE) && + !((DWORD)pszSound >> 16)) || !pszSound)) { + pszSoundA = HEAP_strdupWtoA(GetProcessHeap(),0,pszSound); + bSound = PlaySound32A(pszSoundA, hmod, fdwSound); + HeapFree(GetProcessHeap(),0,pszSoundA); + } else + bSound = PlaySound32A((LPCSTR)pszSound, hmod, fdwSound); + + return bSound; } /************************************************************************** -* sndPlaySound [MMSYSTEM.2] -*/ + * sndPlaySound [MMSYSTEM.2] + */ BOOL16 WINAPI sndPlaySound(LPCSTR lpszSoundName, UINT16 uFlags) { PlaySound_SearchMode = 1; @@ -479,7 +470,7 @@ BOOL16 WINAPI DriverCallback(DWORD dwCallBack, UINT16 uFlags, HANDLE16 hDev, { TRACE(mmsys, "(%08lX, %04X, %04X, %04X, %08lX, %08lX, %08lX); !\n", dwCallBack, uFlags, hDev, wMsg, dwUser, dwParam1, dwParam2); - switch(uFlags & DCB_TYPEMASK) { + switch (uFlags & DCB_TYPEMASK) { case DCB_NULL: TRACE(mmsys, "CALLBACK_NULL !\n"); break; @@ -624,7 +615,7 @@ UINT16 WINAPI mixerOpen16(LPHMIXER16 lphmix,UINT16 uDeviceID,DWORD dwCallback, lpmod->dwInstance = dwInstance; if (uDeviceID >= MAXMIXERDRIVERS) uDeviceID = 0; - while(uDeviceID < MAXMIXERDRIVERS) { + while (uDeviceID < MAXMIXERDRIVERS) { dwRet=mixMessage(uDeviceID,MXDM_OPEN,dwInstance,(DWORD)lpmod,fdwOpen); if (dwRet == MMSYSERR_NOERROR) break; if (!mapperflag) break; @@ -1032,7 +1023,7 @@ BOOL16 WINAPI mciGetErrorString16(DWORD wError,LPSTR lpstrBuffer,UINT16 uLength) wError, lpstrBuffer, uLength); if ((lpstrBuffer == NULL) || (uLength < 1)) return(FALSE); lpstrBuffer[0] = '\0'; - switch(wError) { + switch (wError) { case MCIERR_INVALID_DEVICE_ID: msgptr = "Invalid MCI device ID. Use the ID returned when opening the MCI device."; break; @@ -1313,10 +1304,9 @@ BOOL16 WINAPI mciDriverNotify(HWND16 hWndCallBack, UINT16 wDevID, UINT16 wStatus } /************************************************************************** - * mciOpen [internal] + * mciOpen16 [internal] */ - -DWORD mciOpen(DWORD dwParam, LPMCI_OPEN_PARMS16 lp16Parms) +static DWORD mciOpen16(DWORD dwParam, LPMCI_OPEN_PARMS16 lp16Parms) { char str[128]; LPMCI_OPEN_PARMS16 lpParms; @@ -1328,7 +1318,7 @@ DWORD mciOpen(DWORD dwParam, LPMCI_OPEN_PARMS16 lp16Parms) TRACE(mmsys, "(%08lX, %p (%p))\n", dwParam, lp16Parms, lpParms); if (lp16Parms == NULL) return MCIERR_INTERNAL; - while(GetDrv(wDevID)->modp.wType != 0) { + while (mciGetDrv(wDevID)->modp.wType != 0) { wDevID = MMSYSTEM_NextDevID(wDevID); if (!MMSYSTEM_DevIDValid(wDevID)) { TRACE(mmsys, "MAXMCIDRIVERS reached !\n"); @@ -1336,7 +1326,7 @@ DWORD mciOpen(DWORD dwParam, LPMCI_OPEN_PARMS16 lp16Parms) } } TRACE(mmsys, "wDevID=%04X \n", wDevID); - memcpy(GetOpenDrv(wDevID),lpParms,sizeof(*lpParms)); + memcpy(mciGetOpenDrv(wDevID), lpParms, sizeof(*lpParms)); if (dwParam & MCI_OPEN_ELEMENT) { char *s,*t; @@ -1344,8 +1334,8 @@ DWORD mciOpen(DWORD dwParam, LPMCI_OPEN_PARMS16 lp16Parms) TRACE(mmsys,"lpstrElementName='%s'\n", (char*)PTR_SEG_TO_LIN(lpParms->lpstrElementName) ); - s=(char*)PTR_SEG_TO_LIN(lpParms->lpstrElementName); - t=strrchr(s,'.'); + s = (char*)PTR_SEG_TO_LIN(lpParms->lpstrElementName); + t = strrchr(s,'.'); if (t) { GetProfileString32A("mci extensions",t+1,"*",str,sizeof(str)); CharUpper32A(str); @@ -1370,8 +1360,8 @@ DWORD mciOpen(DWORD dwParam, LPMCI_OPEN_PARMS16 lp16Parms) HMODULE16 hmod; hmod = GetDriverModuleHandle(hdrv); - GetDrv(wDevID)->hdrv = hdrv; - GetDrv(wDevID)->driverproc = GetProcAddress16(hmod,SEGPTR_GET(SEGPTR_STRDUP("DRIVERPROC"))); + mciGetDrv(wDevID)->hDrv = hdrv; + mciGetDrv(wDevID)->driverProc = GetProcAddress16(hmod,SEGPTR_GET(SEGPTR_STRDUP("DRIVERPROC"))); uDevTyp = MCI_DEVTYPE_OTHER; } else { FIXME(mmsys, "[mci extensions] entry %s for %s not supported.\n",str,t); @@ -1386,20 +1376,19 @@ DWORD mciOpen(DWORD dwParam, LPMCI_OPEN_PARMS16 lp16Parms) if (dwParam & MCI_OPEN_ALIAS) { TRACE(mmsys, "Alias='%s' !\n", (char*)PTR_SEG_TO_LIN(lpParms->lpstrAlias)); - GetOpenDrv(wDevID)->lpstrAlias = (LPSTR)SEGPTR_GET(SEGPTR_STRDUP((char*)PTR_SEG_TO_LIN(lpParms->lpstrAlias))); + mciGetOpenDrv(wDevID)->lpstrAlias = strdup(PTR_SEG_TO_LIN(lpParms->lpstrAlias)); /* mplayer does allocate alias to CDAUDIO */ } if (dwParam & MCI_OPEN_TYPE) { if (dwParam & MCI_OPEN_TYPE_ID) { - TRACE(mmsys, "Dev=%08lx!\n", (DWORD)lpParms->lpstrDeviceType); + TRACE(mmsys, "Dev=%08lx!\n", (DWORD)PTR_SEG_TO_LIN(lpParms->lpstrDeviceType)); uDevTyp = LOWORD((DWORD)lpParms->lpstrDeviceType); - GetOpenDrv(wDevID)->lpstrDeviceType=(LPSTR)lpParms->lpstrDeviceType; + mciGetOpenDrv(wDevID)->lpstrDeviceType=strdup(PTR_SEG_TO_LIN(lpParms->lpstrDeviceType)); } else { if (lpParms->lpstrDeviceType == NULL) return MCIERR_INTERNAL; TRACE(mmsys, "Dev='%s' !\n", (char*)PTR_SEG_TO_LIN(lpParms->lpstrDeviceType)); - GetOpenDrv(wDevID)->lpstrDeviceType=(LPSTR)SEGPTR_GET( - SEGPTR_STRDUP((char*)PTR_SEG_TO_LIN(lpParms->lpstrDeviceType))); + mciGetOpenDrv(wDevID)->lpstrDeviceType=strdup(PTR_SEG_TO_LIN(lpParms->lpstrDeviceType)); strcpy(str, PTR_SEG_TO_LIN(lpParms->lpstrDeviceType)); CharUpper32A(str); if (strcmp(str, "CDAUDIO") == 0) { @@ -1421,8 +1410,8 @@ DWORD mciOpen(DWORD dwParam, LPMCI_OPEN_PARMS16 lp16Parms) HMODULE16 hmod; hmod = GetDriverModuleHandle(hdrv); - GetDrv(wDevID)->hdrv = hdrv; - GetDrv(wDevID)->driverproc = GetProcAddress16(hmod,SEGPTR_GET(SEGPTR_STRDUP("DRIVERPROC"))); + mciGetDrv(wDevID)->hDrv = hdrv; + mciGetDrv(wDevID)->driverProc = GetProcAddress16(hmod,SEGPTR_GET(SEGPTR_STRDUP("DRIVERPROC"))); uDevTyp = MCI_DEVTYPE_OTHER; } else #endif @@ -1430,42 +1419,38 @@ DWORD mciOpen(DWORD dwParam, LPMCI_OPEN_PARMS16 lp16Parms) } } } - GetDrv(wDevID)->modp.wType = uDevTyp; - GetDrv(wDevID)->modp.wDeviceID = 0; /* FIXME? for multiple devices */ + mciGetDrv(wDevID)->modp.wType = uDevTyp; + mciGetDrv(wDevID)->modp.wDeviceID = 0; /* FIXME? for multiple devices */ lpParms->wDeviceID = wDevID; TRACE(mmsys, "mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n", wDevID, uDevTyp, lpParms->wDeviceID); - switch(uDevTyp) { + switch (uDevTyp) { case MCI_DEVTYPE_CD_AUDIO: - dwret = CDAUDIO_DriverProc( 0, 0, MCI_OPEN_DRIVER, - dwParam, (DWORD)lp16Parms); + dwret = CDAUDIO_DriverProc16(0, 0, MCI_OPEN_DRIVER, dwParam, (DWORD)lp16Parms); break; case MCI_DEVTYPE_WAVEFORM_AUDIO: - dwret = WAVE_DriverProc( 0, 0, MCI_OPEN_DRIVER, - dwParam, (DWORD)lp16Parms); + dwret = WAVE_DriverProc16(0, 0, MCI_OPEN_DRIVER, dwParam, (DWORD)lp16Parms); break; case MCI_DEVTYPE_SEQUENCER: - dwret = MIDI_DriverProc( 0, 0, MCI_OPEN_DRIVER, - dwParam, (DWORD)lp16Parms); + dwret = MIDI_DriverProc16(0, 0, MCI_OPEN_DRIVER, dwParam, (DWORD)lp16Parms); break; case MCI_DEVTYPE_ANIMATION: - dwret = ANIM_DriverProc( 0, 0, MCI_OPEN_DRIVER, - dwParam, (DWORD)lp16Parms); + dwret = ANIM_DriverProc16(0, 0, MCI_OPEN_DRIVER, dwParam, (DWORD)lp16Parms); break; case MCI_DEVTYPE_DIGITAL_VIDEO: TRACE(mmsys, "No DIGITAL_VIDEO yet !\n"); return MCIERR_DEVICE_NOT_INSTALLED; default: #if testing16 - dwret = Callbacks->CallDriverProc(GetDrv(wDevID)->driverproc,0,GetDrv(wDevID)->hdrv,MCI_OPEN_DRIVER,dwParam,(DWORD)lp16Parms); + dwret = Callbacks->CallDriverProc(mciGetDrv(wDevID)->driverProc,0,mciGetDrv(wDevID)->hDrv,MCI_OPEN_DRIVER,dwParam,(DWORD)lp16Parms); WARN(mmsys, "Invalid Device Name '%08lx' !\n", (DWORD)lpParms->lpstrDeviceType); #endif return MCIERR_INVALID_DEVICE_NAME; } - if (dwParam&MCI_NOTIFY) - mciDriverNotify(lpParms->dwCallback,wDevID, + if (dwParam & MCI_NOTIFY) + mciDriverNotify(lpParms->dwCallback, wDevID, (dwret==0?MCI_NOTIFY_SUCCESSFUL:MCI_NOTIFY_FAILURE)); /* only handled devices fall through */ @@ -1492,46 +1477,48 @@ DWORD WINAPI mciSetDriverData16(HDRVR16 hdrv,DWORD data) } /************************************************************************** - * mciClose [internal] + * mciClose16 [internal] */ -DWORD mciClose(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms) +static DWORD mciClose16(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms) { DWORD dwRet = MCIERR_INTERNAL; TRACE(mmsys, "(%04x, %08lX, %p)\n", wDevID, dwParam, lpParms); - if(wDevID==MCI_ALL_DEVICE_ID) { + + if(wDevID == MCI_ALL_DEVICE_ID) { FIXME(mmsys, "unhandled MCI_ALL_DEVICE_ID\n"); return MCIERR_CANNOT_USE_ALL; } - switch(GetDrv(wDevID)->modp.wType) { + + switch (mciGetDrv(wDevID)->modp.wType) { case MCI_DEVTYPE_CD_AUDIO: - dwRet = CDAUDIO_DriverProc(GetDrv(wDevID)->modp.wDeviceID,0, + dwRet = CDAUDIO_DriverProc16(mciGetDrv(wDevID)->modp.wDeviceID,0, MCI_CLOSE, dwParam, (DWORD)lpParms); break; case MCI_DEVTYPE_WAVEFORM_AUDIO: - dwRet = WAVE_DriverProc(GetDrv(wDevID)->modp.wDeviceID, 0, + dwRet = WAVE_DriverProc16(mciGetDrv(wDevID)->modp.wDeviceID, 0, MCI_CLOSE, dwParam, (DWORD)lpParms); break; case MCI_DEVTYPE_SEQUENCER: - dwRet = MIDI_DriverProc(GetDrv(wDevID)->modp.wDeviceID, 0, + dwRet = MIDI_DriverProc16(mciGetDrv(wDevID)->modp.wDeviceID, 0, MCI_CLOSE, dwParam, (DWORD)lpParms); break; /* case MCI_DEVTYPE_ANIMATION: - dwRet = ANIM_DriverProc(GetDrv(wDevID)->modp.wDeviceID, 0, + dwRet = ANIM_DriverProc16(mciGetDrv(wDevID)->modp.wDeviceID, 0, MCI_CLOSE, dwParam, (DWORD)lpParms); break; */ default: - dwRet = Callbacks->CallDriverProc(GetDrv(wDevID)->driverproc, - GetDrv(wDevID)->modp.wDeviceID, - GetDrv(wDevID)->hdrv,MCI_CLOSE,dwParam, + dwRet = Callbacks->CallDriverProc(mciGetDrv(wDevID)->driverProc, + mciGetDrv(wDevID)->modp.wDeviceID, + mciGetDrv(wDevID)->hDrv,MCI_CLOSE,dwParam, (DWORD)lpParms); } - GetDrv(wDevID)->modp.wType = 0; + mciGetDrv(wDevID)->modp.wType = 0; if (dwParam&MCI_NOTIFY) mciDriverNotify(lpParms->dwCallback,wDevID, @@ -1543,46 +1530,44 @@ DWORD mciClose(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms) /************************************************************************** - * mciSysinfo [internal] + * mciSysinfo16 [internal] */ -DWORD mciSysInfo(DWORD dwFlags, LPMCI_SYSINFO_PARMS16 lpParms) +static DWORD mciSysInfo16(DWORD dwFlags, LPMCI_SYSINFO_PARMS16 lpParms) { - int len; - LPSTR ptr; LPSTR lpstrReturn; DWORD *lpdwRet; - LPSTR SysFile = "SYSTEM.INI"; TRACE(mci, "(%08lX, %08lX)\n", dwFlags, (DWORD)lpParms); lpstrReturn = PTR_SEG_TO_LIN(lpParms->lpstrReturn); - switch(dwFlags) { + switch (dwFlags) { case MCI_SYSINFO_QUANTITY: TRACE(mci, "MCI_SYSINFO_QUANTITY \n"); lpdwRet = (DWORD *)lpstrReturn; - *(lpdwRet) = InstalledCount; + *(lpdwRet) = mciInstalledCount; return 0; case MCI_SYSINFO_INSTALLNAME: TRACE(mci, "MCI_SYSINFO_INSTALLNAME \n"); - if (lpInstallNames == NULL) { - InstalledCount = 0; - InstalledListLen = 0; - ptr = lpInstallNames = xmalloc(2048); - GetPrivateProfileString32A("mci", NULL, "", lpInstallNames, 2000, SysFile); - while(strlen(ptr) > 0) { - TRACE(mci, "---> '%s' \n", ptr); - len = strlen(ptr) + 1; - ptr += len; - InstalledListLen += len; - InstalledCount++; - } - } - if (lpParms->dwRetSize < InstalledListLen) - lstrcpyn32A(lpstrReturn, lpInstallNames, lpParms->dwRetSize - 1); + if (lpParms->dwRetSize < mciInstalledListLen) + lstrcpyn32A(lpstrReturn, lpmciInstallNames, lpParms->dwRetSize - 1); else - strcpy(lpstrReturn, lpInstallNames); + strcpy(lpstrReturn, lpmciInstallNames); return 0; case MCI_SYSINFO_NAME: - TRACE(mci, "MCI_SYSINFO_NAME \n"); + TRACE(mci, "MCI_SYSINFO_NAME"); + if (lpParms->dwNumber > mciInstalledCount) + return MMSYSERR_INVALPARAM; + { + DWORD count = lpParms->dwNumber; + LPSTR ptr = lpmciInstallNames; + + while (--count > 0) + ptr += strlen(ptr) + 1; + if (lpParms->dwRetSize < strlen(ptr)) + lstrcpyn32A(lpstrReturn, ptr, lpParms->dwRetSize - 1); + else + strcpy(lpstrReturn, ptr); + } + TRACE(mci, "(%ld) => '%s'\n", lpParms->dwNumber, lpParms->lpstrReturn); return 0; case MCI_SYSINFO_OPEN: TRACE(mci, "MCI_SYSINFO_OPEN \n"); @@ -1592,7 +1577,7 @@ DWORD mciSysInfo(DWORD dwFlags, LPMCI_SYSINFO_PARMS16 lpParms) } /************************************************************************** - * mciLoadCommandResource16 + * mciLoadCommandResource16 [MMSYSTEM.705] */ UINT16 WINAPI mciLoadCommandResource16(HANDLE16 hinst,LPCSTR resname,UINT16 type) { @@ -1706,23 +1691,350 @@ static const char *_mciCommandToString(UINT16 wMsg) } /************************************************************************** - * mciSendCommandA [WINMM.49] + * mciOpen32 [internal] */ -DWORD WINAPI mciSendCommand32A(UINT32 wDevID, UINT32 wMsg, DWORD dwParam1, - DWORD dwParam2) + +static DWORD mciOpen32(DWORD dwParam, LPMCI_OPEN_PARMS32A lpParms) { - FIXME(mmsys,"(0x%08x,%s,%08lx,%08lx): stub \n", - wDevID,_mciCommandToString(wMsg),dwParam1,dwParam2); - switch (wMsg) { - case MCI_OPEN: + char str[128]; + UINT16 uDevTyp = 0; + UINT16 wDevID = MMSYSTEM_FirstDevID(); + DWORD dwret; + + TRACE(mmsys, "(%08lX, %p)\n", dwParam, lpParms); + if (lpParms == NULL) return MCIERR_INTERNAL; + + if ((dwParam & ~(MCI_OPEN_ELEMENT|MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID|MCI_NOTIFY)) != 0) { + FIXME(mmsys, "unsupported yet dwFlags=%08lX\n", + (dwParam & ~(MCI_OPEN_ELEMENT|MCI_OPEN_ALIAS|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID|MCI_NOTIFY))); + } + + while (mciGetDrv(wDevID)->modp.wType != 0) { + wDevID = MMSYSTEM_NextDevID(wDevID); + if (!MMSYSTEM_DevIDValid(wDevID)) { + TRACE(mmsys, "MAXMCIDRIVERS reached !\n"); + return MCIERR_INTERNAL; + } + } + TRACE(mmsys, "wDevID=%04X \n", wDevID); + memcpy(mciGetOpenDrv(wDevID), lpParms, sizeof(*lpParms)); + + if (dwParam & MCI_OPEN_ELEMENT) { + char *s,*t; + + TRACE(mmsys,"lpstrElementName='%s'\n", lpParms->lpstrElementName); + s = lpParms->lpstrElementName; + t = strrchr(s, '.'); + if (t) { + GetProfileString32A("mci extensions", t+1, "*", str, sizeof(str)); + CharUpper32A(str); + TRACE(mmsys, "str = %s \n", str); + if (strcmp(str, "CDAUDIO") == 0) { + uDevTyp = MCI_DEVTYPE_CD_AUDIO; + } else if (strcmp(str, "WAVEAUDIO") == 0) { + uDevTyp = MCI_DEVTYPE_WAVEFORM_AUDIO; + } else if (strcmp(str, "SEQUENCER") == 0) { + uDevTyp = MCI_DEVTYPE_SEQUENCER; + } else if (strcmp(str, "ANIMATION1") == 0) { + uDevTyp = MCI_DEVTYPE_ANIMATION; + } else if (strcmp(str, "AVIVIDEO") == 0) { + uDevTyp = MCI_DEVTYPE_DIGITAL_VIDEO; + } else if (strcmp(str,"*") == 0) { + TRACE(mmsys,"No [mci extensions] entry for %s found.\n",t); + return MCIERR_EXTENSION_NOT_FOUND; +#if testing32 + /* FIXME has to written, seems to be experimental 16 bit code anyway */ + } else { + HDRVR16 hdrv = OpenDriver(str, "mci", NULL); + if (hdrv) { + HMODULE16 hmod; + + hmod = GetDriverModuleHandle(hdrv); + mciGetDrv(wDevID)->hDrv = hdrv; + mciGetDrv(wDevID)->driverProc = GetProcAddress16(hmod,oouch SEGPTR_GET(SEGPTR_STRDUP("DRIVERPROC"))); + uDevTyp = MCI_DEVTYPE_OTHER; + } else { + FIXME(mmsys, "[mci extensions] entry %s for %s not supported.\n",str,t); + return MCIERR_DEVICE_NOT_INSTALLED; + } +#endif + } + } else + return MCIERR_EXTENSION_NOT_FOUND; + } + + if (dwParam & MCI_OPEN_ALIAS) { + TRACE(mmsys, "Alias='%s' !\n", lpParms->lpstrAlias); + /* FIXME is there any memory leak here ? */ + mciGetOpenDrv(wDevID)->lpstrAlias = strdup(lpParms->lpstrAlias); + /* mplayer does allocate alias to CDAUDIO */ + } + if (dwParam & MCI_OPEN_TYPE) { + if (dwParam & MCI_OPEN_TYPE_ID) { + TRACE(mmsys, "Dev=%08lx!\n", (DWORD)lpParms->lpstrDeviceType); + uDevTyp = LOWORD((DWORD)lpParms->lpstrDeviceType); + mciGetOpenDrv(wDevID)->lpstrDeviceType = lpParms->lpstrDeviceType; + } else { + if (lpParms->lpstrDeviceType == NULL) + return MCIERR_INTERNAL; + TRACE(mmsys, "Dev='%s' !\n", lpParms->lpstrDeviceType); + /* FIXME is there any memory leak here ? */ + mciGetOpenDrv(wDevID)->lpstrDeviceType = strdup(lpParms->lpstrDeviceType); + strcpy(str, lpParms->lpstrDeviceType); + CharUpper32A(str); + if (strcmp(str, "CDAUDIO") == 0) { + uDevTyp = MCI_DEVTYPE_CD_AUDIO; + } else if (strcmp(str, "WAVEAUDIO") == 0) { + uDevTyp = MCI_DEVTYPE_WAVEFORM_AUDIO; + } else if (strcmp(str, "SEQUENCER") == 0) { + uDevTyp = MCI_DEVTYPE_SEQUENCER; + } else if (strcmp(str, "ANIMATION1") == 0) { + uDevTyp = MCI_DEVTYPE_ANIMATION; + } else if (strcmp(str, "AVIVIDEO") == 0) { + uDevTyp = MCI_DEVTYPE_DIGITAL_VIDEO; + } else { +#if testing32 + /* FIXME has to written, seems to be experimental 16 bit code anyway */ + HDRVR16 hdrv; + TRACE(mmsys,"trying to load driver...\n"); + hdrv = OpenDriver(str,"mci",NULL); + if (hdrv) { + HMODULE16 hmod; + + hmod = GetDriverModuleHandle(hdrv); + mciGetDrv(wDevID)->hDrv = hdrv; + mciGetDrv(wDevID)->driverProc = GetProcAddress16(hmod,oouch SEGPTR_GET(SEGPTR_STRDUP("DRIVERPROC"))); + uDevTyp = MCI_DEVTYPE_OTHER; + } else +#endif + return MCIERR_DEVICE_NOT_INSTALLED; + } + } + } + mciGetDrv(wDevID)->modp.wType = uDevTyp; + mciGetDrv(wDevID)->modp.wDeviceID = 0; /* FIXME? for multiple devices */ + lpParms->wDeviceID = wDevID; + TRACE(mmsys, "mcidev=%d, uDevTyp=%04X wDeviceID=%04X !\n", + wDevID, uDevTyp, lpParms->wDeviceID); + switch (uDevTyp) { + case MCI_DEVTYPE_CD_AUDIO: + dwret = CDAUDIO_DriverProc32( 0, 0, MCI_OPEN_DRIVER, + dwParam, (DWORD)lpParms); + break; + case MCI_DEVTYPE_WAVEFORM_AUDIO: + dwret = WAVE_DriverProc32( 0, 0, MCI_OPEN_DRIVER, + dwParam, (DWORD)lpParms); + break; + case MCI_DEVTYPE_SEQUENCER: + dwret = MIDI_DriverProc32( 0, 0, MCI_OPEN_DRIVER, + dwParam, (DWORD)lpParms); + break; + case MCI_DEVTYPE_ANIMATION: + dwret = ANIM_DriverProc32( 0, 0, MCI_OPEN_DRIVER, + dwParam, (DWORD)lpParms); + break; + case MCI_DEVTYPE_DIGITAL_VIDEO: + TRACE(mmsys, "No DIGITAL_VIDEO yet !\n"); + return MCIERR_DEVICE_NOT_INSTALLED; + default: +#if testing32 + dwret = Callbacks->CallDriverProc(mciGetDrv(wDevID)->driverProc,0,mciGetDrv(wDevID)->hdrv,MCI_OPEN_DRIVER,dwParam,(DWORD)lpParms); + WARN(mmsys, "Invalid Device Name '%08lx' !\n", (DWORD)lpParms->lpstrDeviceType); +#endif + return MCIERR_INVALID_DEVICE_NAME; + } + + + if (dwParam & MCI_NOTIFY) + mciDriverNotify(lpParms->dwCallback,wDevID, + (dwret==0?MCI_NOTIFY_SUCCESSFUL:MCI_NOTIFY_FAILURE)); + + /* only handled devices fall through */ + TRACE(mmsys, "wDevID = %04X wDeviceID = %d dwret = %ld\n",wDevID, lpParms->wDeviceID, dwret); + return dwret; +} + +/************************************************************************** + * mciClose32 [internal] + */ +static DWORD mciClose32(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms) +{ + DWORD dwRet = MCIERR_INTERNAL; + + TRACE(mmsys, "(%04x, %08lX, %p)\n", wDevID, dwParam, lpParms); + + if (wDevID == MCI_ALL_DEVICE_ID) { + FIXME(mmsys, "unhandled MCI_ALL_DEVICE_ID\n"); + return MCIERR_CANNOT_USE_ALL; + } + + switch (mciGetDrv(wDevID)->modp.wType) { + case MCI_DEVTYPE_CD_AUDIO: + dwRet = CDAUDIO_DriverProc32(mciGetDrv(wDevID)->modp.wDeviceID,0, + MCI_CLOSE, dwParam, (DWORD)lpParms); + break; + case MCI_DEVTYPE_WAVEFORM_AUDIO: + dwRet = WAVE_DriverProc32(mciGetDrv(wDevID)->modp.wDeviceID, 0, + MCI_CLOSE, dwParam, + (DWORD)lpParms); + break; + case MCI_DEVTYPE_SEQUENCER: + dwRet = MIDI_DriverProc32(mciGetDrv(wDevID)->modp.wDeviceID, 0, + MCI_CLOSE, dwParam, + (DWORD)lpParms); + break; + /* + case MCI_DEVTYPE_ANIMATION: + dwRet = ANIM_DriverProc32(mciGetDrv(wDevID)->modp.wDeviceID, 0, + MCI_CLOSE, dwParam, + (DWORD)lpParms); + break; + */ + default: + dwRet = Callbacks->CallDriverProc(mciGetDrv(wDevID)->driverProc, + mciGetDrv(wDevID)->modp.wDeviceID, + mciGetDrv(wDevID)->hDrv,MCI_CLOSE,dwParam, + (DWORD)lpParms); + } + mciGetDrv(wDevID)->modp.wType = 0; + + if (dwParam&MCI_NOTIFY) + mciDriverNotify(lpParms->dwCallback,wDevID, + (dwRet==0?MCI_NOTIFY_SUCCESSFUL:MCI_NOTIFY_FAILURE)); + + TRACE(mmsys, "returns %ld\n",dwRet); + return dwRet; +} + +/************************************************************************** + * mciSysinfo32 [internal] + */ +static DWORD mciSysInfo32(DWORD dwFlags, LPMCI_SYSINFO_PARMS32A lpParms) +{ + TRACE(mci, "(%08lX, %08lX)\n", dwFlags, (DWORD)lpParms); + switch (dwFlags) { + case MCI_SYSINFO_QUANTITY: + TRACE(mci, "MCI_SYSINFO_QUANTITY \n"); + *(DWORD*)lpParms->lpstrReturn = mciInstalledCount; + return 0; + case MCI_SYSINFO_INSTALLNAME: + TRACE(mci, "MCI_SYSINFO_INSTALLNAME \n"); + if (lpParms->dwRetSize < mciInstalledListLen) + lstrcpyn32A(lpParms->lpstrReturn, lpmciInstallNames, lpParms->dwRetSize - 1); + else + strcpy(lpParms->lpstrReturn, lpmciInstallNames); + return 0; + case MCI_SYSINFO_NAME: + TRACE(mci, "MCI_SYSINFO_NAME\n"); fflush(stddeb); + if (lpParms->dwNumber > mciInstalledCount) + return MMSYSERR_INVALPARAM; { - LPMCI_OPEN_PARMS32A lpmop = (LPMCI_OPEN_PARMS32A)dwParam2; - TRACE(mmsys," MCI_OPEN(%s,%s,%s)\n", - (dwParam1&MCI_OPEN_TYPE) ?lpmop->lpstrDeviceType:"", - (dwParam1&MCI_OPEN_ELEMENT)?(HIWORD(lpmop->lpstrElementName)?lpmop->lpstrElementName:""):"", - (dwParam1&MCI_OPEN_ALIAS) ?lpmop->lpstrAlias:"" - ); - break; + DWORD count = lpParms->dwNumber; + LPSTR ptr = lpmciInstallNames; + + while (--count > 0) + ptr += strlen(ptr) + 1; + if (lpParms->dwRetSize < strlen(ptr)) + lstrcpyn32A(lpParms->lpstrReturn, ptr, lpParms->dwRetSize - 1); + else + strcpy(lpParms->lpstrReturn, ptr); + } + TRACE(mci, "(%ld) => '%s'\n", lpParms->dwNumber, lpParms->lpstrReturn); + return 0; + case MCI_SYSINFO_OPEN: + TRACE(mci, "MCI_SYSINFO_OPEN \n"); + return 0; + } + return MMSYSERR_INVALPARAM; +} + +struct SCA32 { + UINT32 wDevID; + UINT32 wMsg; + DWORD dwParam1; + DWORD dwParam2; +}; + +DWORD WINAPI mciSendCommand32A(UINT32 wDevID, UINT32 wMsg, DWORD dwParam1, DWORD dwParam2); + +static DWORD mciSCAStarter32(LPVOID arg) +{ + struct SCA32* sca = (struct SCA32*)arg; + DWORD ret; + + TRACE(mci, "In thread for async command (%08x,%s,%08lx,%08lx)\n", + sca->wDevID, _mciCommandToString(sca->wMsg), sca->dwParam1, sca->dwParam2); + ret = mciSendCommand32A(sca->wDevID, sca->wMsg, sca->dwParam1 | MCI_WAIT, sca->dwParam2); + free(sca); + return ret; +} + +/************************************************************************** + * mciSendCommandAsync32 [internal] + */ +DWORD mciSendCommandAsync32(UINT32 wDevID, UINT32 wMsg, DWORD dwParam1, DWORD dwParam2) +{ + struct SCA32* sca = malloc(sizeof(struct SCA32)); + + if (sca == 0) return MCIERR_OUT_OF_MEMORY; + + sca->wDevID = wDevID; + sca->wMsg = wMsg; + sca->dwParam1 = dwParam1; + sca->dwParam2 = dwParam2; + + if (CreateThread(NULL, 0, mciSCAStarter32, sca, 0, NULL) == 0) { + WARN(mci, "Couldn't allocate thread for async command handling, sending synchonously\n"); + return mciSCAStarter32(&sca); + } + return 0; +} + +/************************************************************************** + * mciSendCommand32A [WINMM.49] + */ +DWORD WINAPI mciSendCommand32A(UINT32 wDevID, UINT32 wMsg, DWORD dwParam1, DWORD dwParam2) +{ + TRACE(mci,"(%08x,%s,%08lx,%08lx)\n", + wDevID,_mciCommandToString(wMsg),dwParam1,dwParam2); + + switch (wMsg) { + case MCI_OPEN: + return mciOpen32(dwParam1, (LPMCI_OPEN_PARMS32A)dwParam2); + case MCI_CLOSE: + return mciClose32(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2); + case MCI_SYSINFO: + return mciSysInfo32(dwParam1, (LPMCI_SYSINFO_PARMS32A)dwParam2); + default: + { + DWORD dwRet = MCIERR_INTERNAL; + LONG (*proc)(DWORD, HDRVR16, DWORD, DWORD, DWORD) = 0; + + if (wDevID == MCI_ALL_DEVICE_ID) { + FIXME(mci, "unhandled MCI_ALL_DEVICE_ID\n"); + return MCIERR_CANNOT_USE_ALL; + } + + if (!MMSYSTEM_DevIDValid(wDevID)) + return MMSYSERR_INVALPARAM; + + switch (mciGetDrv(wDevID)->modp.wType) { + case MCI_DEVTYPE_CD_AUDIO: proc = CDAUDIO_DriverProc32; break; + case MCI_DEVTYPE_WAVEFORM_AUDIO: proc = WAVE_DriverProc32; break; + case MCI_DEVTYPE_SEQUENCER: proc = MIDI_DriverProc32; break; + /* case MCI_DEVTYPE_ANIMATION: proc = ANIM_DriverProc32; break;*/ + } + if (proc) { + dwRet = (proc)(mciGetDrv(wDevID)->modp.wDeviceID, mciGetDrv(wDevID)->hDrv, wMsg, dwParam1, dwParam2); + } else if (mciGetDrv(wDevID)->driverProc) { + FIXME(mmsys, "is that correct ?\n"); + dwRet = Callbacks->CallDriverProc(mciGetDrv(wDevID)->driverProc, + mciGetDrv(wDevID)->modp.wDeviceID, + mciGetDrv(wDevID)->hDrv,wMsg, dwParam1, dwParam2); + } else { + WARN(mmsys, "unknown device type=%04X !\n", mciGetDrv(wDevID)->modp.wType); + } + return dwRet; } } return 0x1; /* !ok */ @@ -1733,42 +2045,47 @@ DWORD WINAPI mciSendCommand32A(UINT32 wDevID, UINT32 wMsg, DWORD dwParam1, DWORD WINAPI mciSendCommand(UINT16 wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2) { - HDRVR16 hDrv = 0; - TRACE(mci, "(%04X, %s, %08lX, %08lX)\n", + TRACE(mmsys, "(%04X, %s, %08lX, %08lX)\n", wDevID, _mciCommandToString(wMsg), dwParam1, dwParam2); - switch(wMsg) { + + switch (wMsg) { case MCI_OPEN: - return mciOpen(dwParam1, (LPMCI_OPEN_PARMS16)dwParam2); + return mciOpen16(dwParam1, (LPMCI_OPEN_PARMS16)dwParam2); case MCI_CLOSE: - return mciClose( wDevID, dwParam1, + return mciClose16(wDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2)); case MCI_SYSINFO: - return mciSysInfo( dwParam1, + return mciSysInfo16(dwParam1, (LPMCI_SYSINFO_PARMS16)PTR_SEG_TO_LIN(dwParam2)); default: - switch(GetDrv(wDevID)->modp.wType) { - case MCI_DEVTYPE_CD_AUDIO: - return CDAUDIO_DriverProc(GetDrv(wDevID)->modp.wDeviceID, hDrv, - wMsg, dwParam1, dwParam2); - case MCI_DEVTYPE_WAVEFORM_AUDIO: - return WAVE_DriverProc(GetDrv(wDevID)->modp.wDeviceID, hDrv, - wMsg, dwParam1, dwParam2); - case MCI_DEVTYPE_SEQUENCER: - return MIDI_DriverProc(GetDrv(wDevID)->modp.wDeviceID, hDrv, - wMsg, dwParam1, dwParam2); - /* - case MCI_DEVTYPE_ANIMATION: - return ANIM_DriverProc(GetDrv(wDevID)->modp.wDeviceID, hDrv, - wMsg, dwParam1, dwParam2); - */ - default: - return Callbacks->CallDriverProc(GetDrv(wDevID)->driverproc, - GetDrv(wDevID)->modp.wDeviceID, - GetDrv(wDevID)->hdrv, - MCI_CLOSE,dwParam1,dwParam2); - - WARN(mci, "unknown device type=%04X !\n", - GetDrv(wDevID)->modp.wType); + { + DWORD dwRet = MCIERR_INTERNAL; + LONG (*proc)(DWORD, HDRVR16, WORD, DWORD, DWORD) = 0; + + if (wDevID == MCI_ALL_DEVICE_ID) { + FIXME(mci, "unhandled MCI_ALL_DEVICE_ID\n"); + return MCIERR_CANNOT_USE_ALL; + } + + if (!MMSYSTEM_DevIDValid(wDevID)) + return MMSYSERR_INVALPARAM; + + switch (mciGetDrv(wDevID)->modp.wType) { + case MCI_DEVTYPE_CD_AUDIO: proc = CDAUDIO_DriverProc16; break; + case MCI_DEVTYPE_WAVEFORM_AUDIO: proc = WAVE_DriverProc16; break; + case MCI_DEVTYPE_SEQUENCER: proc = MIDI_DriverProc16; break; + /* case MCI_DEVTYPE_ANIMATION: proc = ANIM_DriverProc16; break;*/ + } + if (proc) { + dwRet = (proc)(mciGetDrv(wDevID)->modp.wDeviceID, mciGetDrv(wDevID)->hDrv, wMsg, dwParam1, dwParam2); + } else if (mciGetDrv(wDevID)->driverProc) { + dwRet = Callbacks->CallDriverProc(mciGetDrv(wDevID)->driverProc, + mciGetDrv(wDevID)->modp.wDeviceID, + mciGetDrv(wDevID)->hDrv,wMsg, dwParam1, dwParam2); + } else { + WARN(mmsys, "unknown device type=%04X !\n", mciGetDrv(wDevID)->modp.wType); + } + return dwRet; } } return MMSYSERR_INVALPARAM; @@ -1777,25 +2094,24 @@ DWORD WINAPI mciSendCommand(UINT16 wDevID, UINT16 wMsg, DWORD dwParam1, /************************************************************************** * mciGetDeviceID [MMSYSTEM.703] */ -UINT16 WINAPI mciGetDeviceID (LPCSTR lpstrName) +UINT16 WINAPI mciGetDeviceID(LPCSTR lpstrName) { UINT16 wDevID; - TRACE(mci, "(\"%s\")\n", lpstrName); - if (lpstrName && !lstrcmpi32A(lpstrName, "ALL")) - return MCI_ALL_DEVICE_ID; - + TRACE(mmsys, "(\"%s\")\n", lpstrName); + if (!lpstrName) return 0; + if (!lstrcmpi32A(lpstrName, "ALL")) + return MCI_ALL_DEVICE_ID; + wDevID = MMSYSTEM_FirstDevID(); - while(MMSYSTEM_DevIDValid(wDevID) && GetDrv(wDevID)->modp.wType) { - if (GetOpenDrv(wDevID)->lpstrDeviceType && - strcmp(PTR_SEG_TO_LIN(GetOpenDrv(wDevID)->lpstrDeviceType), lpstrName) == 0) + while (MMSYSTEM_DevIDValid(wDevID) && mciGetDrv(wDevID)->modp.wType) { + if (mciGetOpenDrv(wDevID)->lpstrDeviceType && strcmp(mciGetOpenDrv(wDevID)->lpstrDeviceType, lpstrName) == 0) return wDevID; - if (GetOpenDrv(wDevID)->lpstrAlias && - strcmp(PTR_SEG_TO_LIN(GetOpenDrv(wDevID)->lpstrAlias), lpstrName) == 0) + if (mciGetOpenDrv(wDevID)->lpstrAlias && strcmp(mciGetOpenDrv(wDevID)->lpstrAlias, lpstrName) == 0) return wDevID; wDevID = MMSYSTEM_NextDevID(wDevID); @@ -1849,10 +2165,8 @@ UINT32 WINAPI midiOutGetNumDevs32(void) */ UINT16 WINAPI midiOutGetNumDevs16(void) { - UINT16 count = 0; - TRACE(mmsys, "midiOutGetNumDevs\n"); - count += modMessage(0, MODM_GETNUMDEVS, 0L, 0L, 0L); - TRACE(mmsys, "midiOutGetNumDevs return %u \n", count); + UINT16 count = modMessage(0, MODM_GETNUMDEVS, 0L, 0L, 0L); + TRACE(mmsys, "returns %u\n", count); return count; } @@ -1947,7 +2261,7 @@ UINT16 WINAPI midiGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize) LPSTR msgptr; if ((lpText == NULL) || (uSize < 1)) return(FALSE); lpText[0] = '\0'; - switch(uError) { + switch (uError) { case MIDIERR_UNPREPARED: msgptr = "The MIDI header was not prepared. Use the Prepare function to prepare the header, and then try again."; break; @@ -2028,7 +2342,7 @@ UINT16 WINAPI midiOutOpen16(HMIDIOUT16 * lphMidiOut, UINT16 uDeviceID, lpDesc->dwCallback = dwCallback; lpDesc->dwInstance = dwInstance; - while(uDeviceID < MAXMIDIDRIVERS) { + while (uDeviceID < MAXMIDIDRIVERS) { dwRet = modMessage(uDeviceID, MODM_OPEN, lpDesc->dwInstance, (DWORD)lpDesc, dwFlags); if (dwRet == MMSYSERR_NOERROR) break; @@ -2887,7 +3201,7 @@ static UINT16 waveGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize) uError, lpText, uSize); if ((lpText == NULL) || (uSize < 1)) return(FALSE); lpText[0] = '\0'; - switch(uError) { + switch (uError) { case MMSYSERR_NOERROR: msgptr = "The specified command was carried out."; break; @@ -2992,7 +3306,7 @@ UINT16 WINAPI waveOutOpen16(HWAVEOUT16 * lphWaveOut, UINT16 uDeviceID, lpDesc->dwInstance = dwInstance; if (uDeviceID >= MAXWAVEDRIVERS) uDeviceID = 0; - while(uDeviceID < MAXWAVEDRIVERS) { + while (uDeviceID < MAXWAVEDRIVERS) { dwRet = wodMessage(uDeviceID, WODM_OPEN, lpDesc->dwInstance, (DWORD)lpDesc, dwFlags); if (dwRet == MMSYSERR_NOERROR) break; @@ -3528,7 +3842,7 @@ UINT16 WINAPI waveInOpen16(HWAVEIN16 * lphWaveIn, UINT16 uDeviceID, lpDesc->lpFormat = lpFormat; lpDesc->dwCallBack = dwCallback; lpDesc->dwInstance = dwInstance; - while(uDeviceID < MAXWAVEDRIVERS) { + while (uDeviceID < MAXWAVEDRIVERS) { dwRet = widMessage(uDeviceID, WIDM_OPEN, lpDesc->dwInstance, (DWORD)lpDesc, 0L); if (dwRet == MMSYSERR_NOERROR) break; @@ -3931,7 +4245,7 @@ LRESULT WINAPI DrvSendMessage(HDRVR16 hDriver, WORD msg, LPARAM lParam1, FIXME(mmsys, "(%04X, %04X, %08lX, %08lX);\n", hDriver, msg, lParam1, lParam2); /* FIXME: wrong ... */ - return CDAUDIO_DriverProc(dwDriverID, hDriver, msg, lParam1, lParam2); + return CDAUDIO_DriverProc16(dwDriverID, hDriver, msg, lParam1, lParam2); } /**************************************************************************