summaryrefslogtreecommitdiffstats
path: root/libao2
diff options
context:
space:
mode:
authorulion <ulion@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-11-10 02:07:34 +0000
committerulion <ulion@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-11-10 02:07:34 +0000
commit894000c434d060651e7cb533a942f06ced3937c0 (patch)
tree4435dc84b26bb585ce69124df1de4f35ae52094e /libao2
parent4ab4cd3dcdae578409d6be3a8d3bbaaa775f4fc3 (diff)
downloadmpv-894000c434d060651e7cb533a942f06ced3937c0.tar.bz2
mpv-894000c434d060651e7cb533a942f06ced3937c0.tar.xz
Fix dead lock when changing and restoring stream format for digital output,
replaced with lockless code. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@25008 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libao2')
-rw-r--r--libao2/ao_macosx.c45
1 files changed, 14 insertions, 31 deletions
diff --git a/libao2/ao_macosx.c b/libao2/ao_macosx.c
index 39813528ee..e22b648938 100644
--- a/libao2/ao_macosx.c
+++ b/libao2/ao_macosx.c
@@ -44,9 +44,7 @@
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
-#include <pthread.h>
#include <sys/types.h>
-#include <sys/time.h>
#include <unistd.h>
#include "config.h"
@@ -857,21 +855,16 @@ static int AudioStreamChangeFormat( AudioStreamID i_stream_id, AudioStreamBasicD
UInt32 i_param_size = 0;
int i;
- struct timeval now;
- struct timespec timeout;
- struct { pthread_mutex_t lock; pthread_cond_t cond; } w;
+ static volatile int stream_format_changed;
+ stream_format_changed = 0;
print_format(MSGL_V, "setting stream format:", &change_format);
- /* Condition because SetProperty is asynchronious. */
- pthread_cond_init(&w.cond, NULL);
- pthread_mutex_init(&w.lock, NULL);
- pthread_mutex_lock(&w.lock);
-
/* Install the callback. */
err = AudioStreamAddPropertyListener(i_stream_id, 0,
kAudioStreamPropertyPhysicalFormat,
- StreamListener, (void *)&w);
+ StreamListener,
+ (void *)&stream_format_changed);
if (err != noErr)
{
ao_msg(MSGT_AO, MSGL_WARN, "AudioStreamAddPropertyListener failed: [%4.4s]\n", (char *)&err);
@@ -889,19 +882,19 @@ static int AudioStreamChangeFormat( AudioStreamID i_stream_id, AudioStreamBasicD
return CONTROL_FALSE;
}
- /* The AudioStreamSetProperty is not only asynchronious (requiring the locks),
+ /* The AudioStreamSetProperty is not only asynchronious,
* it is also not Atomic, in its behaviour.
* Therefore we check 5 times before we really give up.
* FIXME: failing isn't actually implemented yet. */
for (i = 0; i < 5; ++i)
{
AudioStreamBasicDescription actual_format;
-
- gettimeofday(&now, NULL);
- timeout.tv_sec = now.tv_sec;
- timeout.tv_nsec = (now.tv_usec + 500000) * 1000;
-
- if (pthread_cond_timedwait(&w.cond, &w.lock, &timeout))
+ int j;
+ for (j = 0; !stream_format_changed && j < 50; ++j)
+ usec_sleep(10000);
+ if (stream_format_changed)
+ stream_format_changed = 0;
+ else
ao_msg(MSGT_AO, MSGL_V, "reached timeout\n" );
i_param_size = sizeof(AudioStreamBasicDescription);
@@ -931,11 +924,6 @@ static int AudioStreamChangeFormat( AudioStreamID i_stream_id, AudioStreamBasicD
return CONTROL_FALSE;
}
- /* Destroy the lock and condition. */
- pthread_mutex_unlock(&w.lock);
- pthread_mutex_destroy(&w.lock);
- pthread_cond_destroy(&w.cond);
-
return CONTROL_TRUE;
}
@@ -1144,17 +1132,12 @@ static OSStatus StreamListener( AudioStreamID inStream,
AudioDevicePropertyID inPropertyID,
void * inClientData )
{
- struct { pthread_mutex_t lock; pthread_cond_t cond; } * w = inClientData;
-
switch (inPropertyID)
{
case kAudioStreamPropertyPhysicalFormat:
- if (NULL!=w)
- {
- pthread_mutex_lock(&w->lock);
- pthread_cond_signal(&w->cond);
- pthread_mutex_unlock(&w->lock);
- }
+ ao_msg(MSGT_AO, MSGL_V, "got notify kAudioStreamPropertyPhysicalFormat changed.\n");
+ if (inClientData)
+ *(volatile int *)inClientData = 1;
default:
break;
}