MciWave: some small cleanups

Eric Pouech eric.pouech at wanadoo.fr
Sat Jan 11 11:02:24 CST 2003


see changelog for the details
A+
-- 
Eric Pouech
-------------- next part --------------
Name:          mciwave
ChangeLog:     
License:       X11
GenDate:       2003/01/11 17:00:33 UTC
ModifiedFiles: dlls/winmm/mciwave/mciwave.c
AddedFiles:    
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/dlls/winmm/mciwave/mciwave.c,v
retrieving revision 1.26
diff -u -u -r1.26 mciwave.c
--- dlls/winmm/mciwave/mciwave.c	19 Oct 2002 17:20:03 -0000	1.26
+++ dlls/winmm/mciwave/mciwave.c	11 Jan 2003 16:55:16 -0000
@@ -45,7 +45,6 @@
     BOOL			fInput;		/* FALSE = Output, TRUE = Input */
     volatile WORD		dwStatus;	/* one from MCI_MODE_xxxx */
     DWORD			dwMciTimeFormat;/* One of the supported MCI_FORMAT_xxxx */
-    DWORD                      	dwRemaining;    /* remaining bytes to play or record */
     DWORD			dwPosition;	/* position in bytes in chunk */
     HANDLE			hEvent;		/* for synchronization */
     DWORD			dwEventCount;	/* for synchronization */
@@ -251,6 +250,7 @@
 	  (LPSTR)&mmckInfo.ckid, (LPSTR)&mmckInfo.fccType, mmckInfo.cksize);
 
     wmw->lpWaveFormat = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
+    if (!wmw->lpWaveFormat) return MMSYSERR_NOMEM;
     r = mmioRead(wmw->hFile, (HPSTR)wmw->lpWaveFormat, mmckInfo.cksize);
     if (r < sizeof(WAVEFORMAT))
 	return MCIERR_INVALID_FILE;
@@ -284,45 +284,41 @@
 static DWORD WAVE_mciCreateRIFFSkeleton(WINE_MCIWAVE* wmw)
 {
    MMCKINFO     ckWaveFormat;
-
-   LPMMCKINFO     lpckRIFF     = &(wmw->ckMainRIFF);
-   LPMMCKINFO     lpckWaveData = &(wmw->ckWaveData);
-   LPWAVEFORMATEX lpWaveFormat = wmw->lpWaveFormat;
-
-
-   HMMIO     hmmio      = wmw->hFile;
+   LPMMCKINFO   lpckRIFF     = &(wmw->ckMainRIFF);
+   LPMMCKINFO   lpckWaveData = &(wmw->ckWaveData);
 
    lpckRIFF->ckid    = FOURCC_RIFF;
    lpckRIFF->fccType = mmioFOURCC('W', 'A', 'V', 'E');
    lpckRIFF->cksize  = 0;
 
-   if (MMSYSERR_NOERROR != mmioCreateChunk(hmmio, lpckRIFF, MMIO_CREATERIFF))
+   if (MMSYSERR_NOERROR != mmioCreateChunk(wmw->hFile, lpckRIFF, MMIO_CREATERIFF))
 	goto err;
 
    ckWaveFormat.fccType = 0;
    ckWaveFormat.ckid    = mmioFOURCC('f', 'm', 't', ' ');
-   ckWaveFormat.cksize  = 16;
+   ckWaveFormat.cksize  = sizeof(PCMWAVEFORMAT);
 
-   if (!lpWaveFormat)
+   if (!wmw->lpWaveFormat)
    {
-       /* FIXME: for non PCM formats, the size of the waveFormat has to be
-	* gotten
-	*/
-	lpWaveFormat = wmw->lpWaveFormat = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*lpWaveFormat));
-
-	memcpy(lpWaveFormat, &wmw->wfxRef, sizeof(wmw->wfxRef));
+       wmw->lpWaveFormat = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wmw->lpWaveFormat));
+       if (!wmw->lpWaveFormat) return MMSYSERR_NOMEM;
+       memcpy(wmw->lpWaveFormat, &wmw->wfxRef, sizeof(wmw->wfxRef));
    }
 
-   if (MMSYSERR_NOERROR != mmioCreateChunk(hmmio, &ckWaveFormat, 0))
+   /* we can only record PCM files... there is no way in the MCI API to specify
+    * the necessary data to initialize the extra bytes of the WAVEFORMATEX
+    * structure
+    */
+   if (wmw->lpWaveFormat->wFormatTag != WAVE_FORMAT_PCM)
+       goto err;
+
+   if (MMSYSERR_NOERROR != mmioCreateChunk(wmw->hFile, &ckWaveFormat, 0))
 	goto err;
 
-   /* only the first 16 bytes are serialized */
-   /* wrong... for non PCM, the whole waveFormat is stored
-    */
-   if (-1 == mmioWrite(hmmio, (HPCSTR) lpWaveFormat, 16))
+   if (-1 == mmioWrite(wmw->hFile, (HPCSTR)wmw->lpWaveFormat, sizeof(PCMWAVEFORMAT)))
 	goto err;
 
-   if (MMSYSERR_NOERROR != mmioAscend(hmmio, &ckWaveFormat, 0))
+   if (MMSYSERR_NOERROR != mmioAscend(wmw->hFile, &ckWaveFormat, 0))
 	goto err;
 
    lpckWaveData->cksize  = 0;
@@ -330,13 +326,15 @@
    lpckWaveData->ckid    = mmioFOURCC('d', 'a', 't', 'a');
 
    /* create data chunk */
-   if (MMSYSERR_NOERROR != mmioCreateChunk(hmmio, lpckWaveData, 0))
+   if (MMSYSERR_NOERROR != mmioCreateChunk(wmw->hFile, lpckWaveData, 0))
 	goto err;
 
    return 0;
 
 err:
-   HeapFree(GetProcessHeap(), 0, wmw->lpWaveFormat);
+   if (wmw->lpWaveFormat)
+       HeapFree(GetProcessHeap(), 0, wmw->lpWaveFormat);
+   wmw->lpWaveFormat = NULL;
    return MCIERR_INVALID_FILE;
 }
 
@@ -616,7 +614,7 @@
      */
     if (wmw->bTemporaryFile)
     {
-	HeapFree(GetProcessHeap(), 0, (CHAR*) wmw->openParms.lpstrElementName);
+	HeapFree(GetProcessHeap(), 0, (char*)wmw->openParms.lpstrElementName);
 	wmw->openParms.lpstrElementName = NULL;
     }
 
@@ -655,6 +653,11 @@
     }
 }
 
+/******************************************************************
+ *		WAVE_mciPlayWaitDone
+ *
+ *
+ */
 static void WAVE_mciPlayWaitDone(WINE_MCIWAVE* wmw)
 {
     for (;;) {
@@ -865,12 +868,13 @@
  * 				WAVE_mciPlayCallback		[internal]
  */
 static	void	CALLBACK WAVE_mciRecordCallback(HWAVEOUT hwo, UINT uMsg,
-					      DWORD dwInstance,
-					      DWORD dwParam1, DWORD dwParam2)
+                                                DWORD dwInstance,
+                                                DWORD dwParam1, DWORD dwParam2)
 {
     WINE_MCIWAVE*	wmw = (WINE_MCIWAVE*)dwInstance;
-    LPWAVEHDR           lpWaveHdr = NULL;
+    LPWAVEHDR           lpWaveHdr;
     LONG                count = 0;
+
     switch (uMsg) {
     case WIM_OPEN:
     case WIM_CLOSE:
@@ -883,9 +887,9 @@
 	count = mmioWrite(wmw->hFile, lpWaveHdr->lpData, lpWaveHdr->dwBytesRecorded);
 
 	lpWaveHdr->dwFlags &= ~WHDR_DONE;
-	wmw->dwPosition  += count;
-        wmw->dwRemaining -= count;
-
+        if (count > 0)
+            wmw->dwPosition  += count;
+        /* else error reporting ?? */
         if (wmw->dwStatus == MCI_MODE_RECORD)
         {
            /* Only queue up another buffer if we are recording.  We could receive this
@@ -903,6 +907,10 @@
     }
 }
 
+/******************************************************************
+ *		bWAVE_mciRecordWaitDone
+ *
+ */
 static void WAVE_mciRecordWaitDone(WINE_MCIWAVE* wmw)
 {
     for (;;) {
@@ -922,7 +930,7 @@
 static DWORD WAVE_mciRecord(UINT wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpParms)
 {
     DWORD		end;
-    DWORD		dwRet = 0;
+    DWORD		dwRet = MMSYSERR_NOERROR;
     LONG		bufsize;
     LPWAVEHDR		waveHdr = NULL;
     WINE_MCIWAVE*	wmw = WAVE_mciGetOpenDev(wDevID);
@@ -963,12 +971,10 @@
 				    (DWORD)lpParms, sizeof(MCI_RECORD_PARMS));
     }
 
-    if (!wmw->lpWaveFormat)
-    {
-  	    /* new RIFF file */
-	    dwRet = WAVE_mciCreateRIFFSkeleton(wmw);
-    } else
-    {
+    if (!wmw->lpWaveFormat) {
+        /* new RIFF file */
+        dwRet = WAVE_mciCreateRIFFSkeleton(wmw);
+    } else {
 	FIXME("Should descend into data chunk. Please report.\n");
     }
 
@@ -1009,7 +1015,7 @@
     dwRet = waveInOpen((HWAVEIN*)&wmw->hWave, WAVE_MAPPER, wmw->lpWaveFormat,
 			(DWORD)WAVE_mciRecordCallback, (DWORD)wmw, CALLBACK_FUNCTION);
 
-    if (dwRet != 0) {
+    if (dwRet != MMSYSERR_NOERROR) {
 	TRACE("Can't open low level audio device %ld\n", dwRet);
 	dwRet = MCIERR_DEVICE_OPEN;
 	wmw->hWave = 0;
@@ -1042,13 +1048,11 @@
     wmw->hEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
     wmw->dwEventCount = 1L; /* for first buffer */
 
-    wmw->dwRemaining = end - wmw->dwPosition;
-
-    TRACE("Recording (normalized) from byte=%lu for %lu bytes\n", wmw->dwPosition, wmw->dwRemaining);
+    TRACE("Recording (normalized) from byte=%lu for %lu bytes\n", wmw->dwPosition, end - wmw->dwPosition);
 
     dwRet = waveInStart(wmw->hWave);
 
-    while ( wmw->dwRemaining > 0 && wmw->dwStatus != MCI_MODE_STOP && wmw->dwStatus != MCI_MODE_NOT_READY) {
+    while (wmw->dwPosition < end && wmw->dwStatus != MCI_MODE_STOP && wmw->dwStatus != MCI_MODE_NOT_READY) {
 	WAVE_mciRecordWaitDone(wmw);
     }
 


More information about the wine-patches mailing list