Commit 956f6b50 authored by Sam Lantinga's avatar Sam Lantinga

Fixed playback problems with MacOSX 10.1

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40776
parent e95a3dbb
...@@ -306,7 +306,7 @@ void AudioFileManager::DoConnect () ...@@ -306,7 +306,7 @@ void AudioFileManager::DoConnect ()
//mReadFilePosition = 0; //mReadFilePosition = 0;
mFinishedReadingData = false; mFinishedReadingData = false;
mNumTimesAskedSinceFinished = -1; mNumTimesAskedSinceFinished = 0;
mLockUnsuccessful = false; mLockUnsuccessful = false;
OSStatus result; OSStatus result;
...@@ -417,4 +417,4 @@ void AudioFileManager::SetEndOfFile (SInt64 pos) ...@@ -417,4 +417,4 @@ void AudioFileManager::SetEndOfFile (SInt64 pos)
} }
mFileLength = pos; mFileLength = pos;
} }
\ No newline at end of file
...@@ -56,11 +56,8 @@ static bool playBackWasInit = false; ...@@ -56,11 +56,8 @@ static bool playBackWasInit = false;
static AudioUnit theUnit; static AudioUnit theUnit;
static AudioFilePlayer* thePlayer = NULL; static AudioFilePlayer* thePlayer = NULL;
static CDPlayerCompletionProc completionProc = NULL; static CDPlayerCompletionProc completionProc = NULL;
static pthread_mutex_t apiMutex; static SDL_mutex *apiMutex = NULL;
static pthread_t callbackThread; static SDL_sem *callbackSem;
static pthread_mutex_t callbackMutex;
static volatile int runCallBackThread;
static int initMutex = SDL_TRUE;
static SDL_CD* theCDROM; static SDL_CD* theCDROM;
// //
...@@ -69,36 +66,28 @@ static SDL_CD* theCDROM; ...@@ -69,36 +66,28 @@ static SDL_CD* theCDROM;
#pragma mark -- Prototypes -- #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 -- #pragma mark -- Public Functions --
void Lock () void Lock ()
{ {
if (initMutex) { if (!apiMutex) {
apiMutex = SDL_CreateMutex();
pthread_mutexattr_t attr;
pthread_mutexattr_init (&attr);
pthread_mutex_init (&apiMutex, &attr);
pthread_mutexattr_destroy (&attr);
initMutex = SDL_FALSE;
} }
SDL_mutexP(apiMutex);
pthread_mutex_lock (&apiMutex);
} }
void Unlock () void Unlock ()
{ {
pthread_mutex_unlock (&apiMutex); SDL_mutexV(apiMutex);
} }
// //
...@@ -355,7 +344,7 @@ int ListTrackFiles (FSVolumeRefNum theVolume, FSRef *trackFiles, int numTracks) ...@@ -355,7 +344,7 @@ int ListTrackFiles (FSVolumeRefNum theVolume, FSRef *trackFiles, int numTracks)
if (result != noErr) { if (result != noErr) {
SDL_SetError ("ListTrackFiles: FSGetVolumeInfo returned %d", result); SDL_SetError ("ListTrackFiles: FSGetVolumeInfo returned %d", result);
goto bail; return result;
} }
result = FSOpenIterator (&rootDirectory, kFSIterateFlat, &iterator); result = FSOpenIterator (&rootDirectory, kFSIterateFlat, &iterator);
...@@ -402,9 +391,7 @@ int ListTrackFiles (FSVolumeRefNum theVolume, FSRef *trackFiles, int numTracks) ...@@ -402,9 +391,7 @@ int ListTrackFiles (FSVolumeRefNum theVolume, FSRef *trackFiles, int numTracks)
FSCloseIterator (iterator); FSCloseIterator (iterator);
} }
result = 0; return 0;
bail:
return result;
} }
// //
...@@ -563,6 +550,9 @@ void SetCompletionProc (CDPlayerCompletionProc proc, SDL_CD *cdrom) ...@@ -563,6 +550,9 @@ void SetCompletionProc (CDPlayerCompletionProc proc, SDL_CD *cdrom)
thePlayer->SetNotifier (FilePlayNotificationHandler, cdrom); thePlayer->SetNotifier (FilePlayNotificationHandler, cdrom);
} }
//
// GetCurrentFrame
//
int GetCurrentFrame () int GetCurrentFrame ()
{ {
...@@ -579,26 +569,18 @@ int GetCurrentFrame () ...@@ -579,26 +569,18 @@ int GetCurrentFrame ()
#pragma mark -- Private Functions -- #pragma mark -- Private Functions --
OSStatus CheckInit () static OSStatus CheckInit ()
{ {
if (playBackWasInit) if (playBackWasInit)
return 0; return 0;
OSStatus result = noErr; OSStatus result = noErr;
// Create the callback semaphore
// Create the callback mutex callbackSem = SDL_CreateSemaphore(0);
pthread_mutexattr_t attr;
pthread_mutexattr_init (&attr);
pthread_mutex_init (&callbackMutex, &attr);
pthread_mutexattr_destroy (&attr);
pthread_mutex_lock (&callbackMutex);
// Start callback thread // Start callback thread
pthread_attr_t attr1; SDL_CreateThread(RunCallBackThread, NULL);
pthread_attr_init (&attr1);
pthread_create (&callbackThread, &attr1, RunCallBackThread, NULL);
pthread_attr_destroy (&attr1);
try { try {
ComponentDescription desc; ComponentDescription desc;
...@@ -644,7 +626,7 @@ OSStatus CheckInit () ...@@ -644,7 +626,7 @@ OSStatus CheckInit ()
} }
OSStatus MatchAUFormats (AudioUnit theUnit, UInt32 theInputBus) static OSStatus MatchAUFormats (AudioUnit theUnit, UInt32 theInputBus)
{ {
AudioStreamBasicDescription theDesc; AudioStreamBasicDescription theDesc;
UInt32 size = sizeof (theDesc); UInt32 size = sizeof (theDesc);
...@@ -666,12 +648,12 @@ OSStatus MatchAUFormats (AudioUnit theUnit, UInt32 theInputBus) ...@@ -666,12 +648,12 @@ OSStatus MatchAUFormats (AudioUnit theUnit, UInt32 theInputBus)
return result; return result;
} }
void FilePlayNotificationHandler(void * inRefCon, OSStatus inStatus) static void FilePlayNotificationHandler(void * inRefCon, OSStatus inStatus)
{ {
if (inStatus == kAudioFilePlay_FileIsFinished) { if (inStatus == kAudioFilePlay_FileIsFinished) {
// notify non-CA thread to perform the callback // notify non-CA thread to perform the callback
pthread_mutex_unlock (&callbackMutex); SDL_SemPost(callbackSem);
} else if (inStatus == kAudioFilePlayErr_FilePlayUnderrun) { } else if (inStatus == kAudioFilePlayErr_FilePlayUnderrun) {
...@@ -685,13 +667,11 @@ void FilePlayNotificationHandler(void * inRefCon, OSStatus inStatus) ...@@ -685,13 +667,11 @@ void FilePlayNotificationHandler(void * inRefCon, OSStatus inStatus)
} }
} }
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 (completionProc && theCDROM) {
#if DEBUG_CDROM #if DEBUG_CDROM
...@@ -705,13 +685,11 @@ void* RunCallBackThread (void *param) ...@@ -705,13 +685,11 @@ void* RunCallBackThread (void *param)
} }
} }
runCallBackThread = -1;
#if DEBUG_CDROM #if DEBUG_CDROM
printf ("thread dying now...\n"); printf ("thread dying now...\n");
#endif #endif
return NULL; return 0;
} }
}; // extern "C" }; // extern "C"
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include <AudioUnit/AudioUnit.h> #include <AudioUnit/AudioUnit.h>
#include "SDL.h" #include "SDL.h"
#include "SDL_thread.h"
#include "SDL_mutex.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment