Fixed playback problems with MacOSX 10.1
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40776
This commit is contained in:
parent
e95a3dbbbe
commit
956f6b50f8
3 changed files with 31 additions and 51 deletions
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
#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)
|
||||||
|
|
||||||
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)
|
||||||
FSCloseIterator (iterator);
|
FSCloseIterator (iterator);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = 0;
|
return 0;
|
||||||
bail:
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
|
//ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
|
||||||
|
@ -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 ()
|
||||||
|
|
||||||
#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 ()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void* RunCallBackThread (void *param)
|
static int RunCallBackThread (void *param)
|
||||||
{
|
{
|
||||||
runCallBackThread = 1;
|
for (;;) {
|
||||||
|
|
||||||
while (runCallBackThread) {
|
SDL_SemWait(callbackSem);
|
||||||
|
|
||||||
pthread_mutex_lock (&callbackMutex);
|
|
||||||
|
|
||||||
if (completionProc && theCDROM) {
|
if (completionProc && theCDROM) {
|
||||||
#if DEBUG_CDROM
|
#if DEBUG_CDROM
|
||||||
|
@ -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 @@
|
||||||
#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" {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue