# HG changeset patch # User Sam Lantinga # Date 1073304518 0 # Node ID 08b7fc2b52256bd4fe7ceb4a064abad14f1ab5b4 # Parent 0c3e00cc95802d1d4b55af0eb548bf32d5dde55e Fixed playback problems with MacOSX 10.1 diff -r 0c3e00cc9580 -r 08b7fc2b5225 src/cdrom/macosx/AudioFileReaderThread.cpp --- a/src/cdrom/macosx/AudioFileReaderThread.cpp Mon Jan 05 01:34:34 2004 +0000 +++ b/src/cdrom/macosx/AudioFileReaderThread.cpp Mon Jan 05 12:08:38 2004 +0000 @@ -306,7 +306,7 @@ //mReadFilePosition = 0; mFinishedReadingData = false; - mNumTimesAskedSinceFinished = -1; + mNumTimesAskedSinceFinished = 0; mLockUnsuccessful = false; OSStatus result; @@ -417,4 +417,4 @@ } mFileLength = pos; -} \ No newline at end of file +} diff -r 0c3e00cc9580 -r 08b7fc2b5225 src/cdrom/macosx/CDPlayer.cpp --- a/src/cdrom/macosx/CDPlayer.cpp Mon Jan 05 01:34:34 2004 +0000 +++ b/src/cdrom/macosx/CDPlayer.cpp Mon Jan 05 12:08:38 2004 +0000 @@ -56,11 +56,8 @@ static AudioUnit theUnit; static AudioFilePlayer* thePlayer = NULL; static CDPlayerCompletionProc completionProc = NULL; -static pthread_mutex_t apiMutex; -static pthread_t callbackThread; -static pthread_mutex_t callbackMutex; -static volatile int runCallBackThread; -static int initMutex = SDL_TRUE; +static SDL_mutex *apiMutex = NULL; +static SDL_sem *callbackSem; static SDL_CD* theCDROM; //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ @@ -69,36 +66,28 @@ #pragma mark -- Prototypes -- -OSStatus CheckInit (); +static OSStatus CheckInit (); -OSStatus MatchAUFormats (AudioUnit theUnit, UInt32 theInputBus); +static OSStatus MatchAUFormats (AudioUnit theUnit, UInt32 theInputBus); -void FilePlayNotificationHandler (void* inRefCon, OSStatus inStatus); +static void FilePlayNotificationHandler (void* inRefCon, OSStatus inStatus); -void* RunCallBackThread (void* inRefCon); +static int RunCallBackThread (void* inRefCon); #pragma mark -- Public Functions -- void Lock () { - if (initMutex) { - - pthread_mutexattr_t attr; - - pthread_mutexattr_init (&attr); - pthread_mutex_init (&apiMutex, &attr); - pthread_mutexattr_destroy (&attr); - - initMutex = SDL_FALSE; + if (!apiMutex) { + apiMutex = SDL_CreateMutex(); } - - pthread_mutex_lock (&apiMutex); + SDL_mutexP(apiMutex); } void Unlock () { - pthread_mutex_unlock (&apiMutex); + SDL_mutexV(apiMutex); } //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ @@ -355,7 +344,7 @@ if (result != noErr) { SDL_SetError ("ListTrackFiles: FSGetVolumeInfo returned %d", result); - goto bail; + return result; } result = FSOpenIterator (&rootDirectory, kFSIterateFlat, &iterator); @@ -402,9 +391,7 @@ FSCloseIterator (iterator); } - result = 0; - bail: - return result; + return 0; } //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ @@ -563,6 +550,9 @@ thePlayer->SetNotifier (FilePlayNotificationHandler, cdrom); } +//ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ +// GetCurrentFrame +//ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ int GetCurrentFrame () { @@ -579,26 +569,18 @@ #pragma mark -- Private Functions -- -OSStatus CheckInit () +static OSStatus CheckInit () { if (playBackWasInit) return 0; OSStatus result = noErr; - - // Create the callback mutex - pthread_mutexattr_t attr; - pthread_mutexattr_init (&attr); - pthread_mutex_init (&callbackMutex, &attr); - pthread_mutexattr_destroy (&attr); - pthread_mutex_lock (&callbackMutex); - + // Create the callback semaphore + callbackSem = SDL_CreateSemaphore(0); + // Start callback thread - pthread_attr_t attr1; - pthread_attr_init (&attr1); - pthread_create (&callbackThread, &attr1, RunCallBackThread, NULL); - pthread_attr_destroy (&attr1); + SDL_CreateThread(RunCallBackThread, NULL); try { ComponentDescription desc; @@ -644,7 +626,7 @@ } -OSStatus MatchAUFormats (AudioUnit theUnit, UInt32 theInputBus) +static OSStatus MatchAUFormats (AudioUnit theUnit, UInt32 theInputBus) { AudioStreamBasicDescription theDesc; UInt32 size = sizeof (theDesc); @@ -666,12 +648,12 @@ return result; } -void FilePlayNotificationHandler(void * inRefCon, OSStatus inStatus) +static void FilePlayNotificationHandler(void * inRefCon, OSStatus inStatus) { if (inStatus == kAudioFilePlay_FileIsFinished) { // notify non-CA thread to perform the callback - pthread_mutex_unlock (&callbackMutex); + SDL_SemPost(callbackSem); } else if (inStatus == kAudioFilePlayErr_FilePlayUnderrun) { @@ -685,13 +667,11 @@ } } -void* RunCallBackThread (void *param) +static int RunCallBackThread (void *param) { - runCallBackThread = 1; + for (;;) { - while (runCallBackThread) { - - pthread_mutex_lock (&callbackMutex); + SDL_SemWait(callbackSem); if (completionProc && theCDROM) { #if DEBUG_CDROM @@ -705,13 +685,11 @@ } } - runCallBackThread = -1; - #if DEBUG_CDROM printf ("thread dying now...\n"); #endif - return NULL; + return 0; } }; // extern "C" diff -r 0c3e00cc9580 -r 08b7fc2b5225 src/cdrom/macosx/CDPlayer.h --- a/src/cdrom/macosx/CDPlayer.h Mon Jan 05 01:34:34 2004 +0000 +++ b/src/cdrom/macosx/CDPlayer.h Mon Jan 05 12:08:38 2004 +0000 @@ -30,6 +30,8 @@ #include #include "SDL.h" +#include "SDL_thread.h" +#include "SDL_mutex.h" #ifdef __cplusplus extern "C" {