[05/16] winecoreaudio: Specialize wodHelper_BeginWaveHdr for its two callers and simplify.

Ken Thomases ken at codeweavers.com
Thu Dec 21 03:48:38 CST 2006


wodHelper_BeginWaveHdr is called by two callers, wodHelper_PlayPtrNext and
wodWrite.  They establish preconditions such that large chunks of it are only
used for one caller, and other chunks only used by the other caller.  This
patch duplicates wodHelper_BeginWaveHdr to wodHelper_BeginWaveHdrPlay and
wodHelper_BeginWaveHdrWrite, and then specializes each for its caller.  This
actually simplifies things a bit.  It also prepares the ground for further
refactorings.

wodHelper_PlayPtrNext is only called when state == WINE_WS_PLAYING.  Also, it
clears dwPartialOffset itself.

wodWrite only calls wodHelper_BeginWaveHdr[Write] with a non-NULL lpWaveHdr
parameter.  wodWrite is not called from the Audio Unit render callback, so it
can use Wine debug channels.
---
  dlls/winmm/winecoreaudio/audio.c |   46 ++++++++++++++++++++++----------------
  1 files changed, 27 insertions(+), 19 deletions(-)
-------------- next part --------------
diff --git a/dlls/winmm/winecoreaudio/audio.c b/dlls/winmm/winecoreaudio/audio.c
index 9e26c31..e24374f 100644
--- a/dlls/winmm/winecoreaudio/audio.c
+++ b/dlls/winmm/winecoreaudio/audio.c
@@ -883,39 +883,47 @@ static void wodHelper_CheckForLoopBegin(
 
 
 /**************************************************************************
-* 				wodHelper_BeginWaveHdr          [internal]
+* 				wodHelper_BeginWaveHdrPlay          [internal]
 *
 * Makes the specified lpWaveHdr the currently playing wave header.
 * If the specified wave header is a begin loop and we're not already in
 * a loop, setup the loop.
 * Call from AudioUnit IO thread can't use Wine debug channels.
 */
-static void wodHelper_BeginWaveHdr(WINE_WAVEOUT* wwo, LPWAVEHDR lpWaveHdr)
+static void wodHelper_BeginWaveHdrPlay(WINE_WAVEOUT* wwo, LPWAVEHDR lpWaveHdr)
 {
-    OSStatus status;
-
     wwo->lpPlayPtr = lpWaveHdr;
     
     if (!lpWaveHdr)
     {
-        if (wwo->state == WINE_WS_PLAYING)
-        {
-            wwo->state = WINE_WS_STOPPED;
-            status = AudioOutputUnitStop(wwo->audioUnit);
-            if (status && wwo->err_on)
-                fprintf(stderr, "err:winecoreaudio:wodHelper_BeginWaveHdr AudioOutputUnitStop return %c%c%c%c\n",
-                        (char) (status >> 24), (char) (status >> 16), (char) (status >> 8), (char) status);
-        }
-        return;
+        OSStatus status;
+        wwo->state = WINE_WS_STOPPED;
+        status = AudioOutputUnitStop(wwo->audioUnit);
+        if (status && wwo->err_on)
+            fprintf(stderr, "err:winecoreaudio:wodHelper_BeginWaveHdrPlay AudioOutputUnitStop return %c%c%c%c\n",
+                    (char) (status >> 24), (char) (status >> 16), (char) (status >> 8), (char) status);
     }
+    else
+        wodHelper_CheckForLoopBegin(wwo);
+}
+
 
+/**************************************************************************
+* 				wodHelper_BeginWaveHdrWrite          [internal]
+*
+* Makes the specified lpWaveHdr the currently playing wave header.
+* If the specified wave header is a begin loop and we're not already in
+* a loop, setup the loop.
+*/
+static void wodHelper_BeginWaveHdrWrite(WINE_WAVEOUT* wwo, LPWAVEHDR lpWaveHdr)
+{
+    wwo->lpPlayPtr = lpWaveHdr;
+    
     if (wwo->state == WINE_WS_STOPPED)
     {
-        status = AudioOutputUnitStart(wwo->audioUnit);
+        OSStatus status = AudioOutputUnitStart(wwo->audioUnit);
         if (status) {
-            if (wwo->err_on)
-                fprintf(stderr, "err:winecoreaudio:AudioOutputUnitStart return %c%c%c%c\n",
-                        (char) (status >> 24), (char) (status >> 16), (char) (status >> 8), (char) status);
+            ERR("AudioOutputUnitStart return %c%c%c%c\n", (char) (status >> 24), (char) (status >> 16), (char) (status >> 8), (char) status);
         }
         else wwo->state = WINE_WS_PLAYING;
     }
@@ -965,7 +973,7 @@ static LPWAVEHDR wodHelper_PlayPtrNext(W
     if (!didLoopBack)
     {
         /* We didn't loop back.  Advance to the next wave header */
-        wodHelper_BeginWaveHdr(wwo, lpWaveHdr = lpWaveHdr->lpNext);
+        wodHelper_BeginWaveHdrPlay(wwo, lpWaveHdr = lpWaveHdr->lpNext);
     }
     
     pthread_mutex_unlock(&wwo->lock);
@@ -1122,7 +1130,7 @@ static DWORD wodWrite(WORD wDevID, LPWAV
     *wh = lpWaveHdr;
     
     if (!wwo->lpPlayPtr)
-        wodHelper_BeginWaveHdr(wwo,lpWaveHdr);
+        wodHelper_BeginWaveHdrWrite(wwo,lpWaveHdr);
     pthread_mutex_unlock(&wwo->lock);
     
     return MMSYSERR_NOERROR;


More information about the wine-patches mailing list