mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
pipewire-alsa: Make it MT safe
Make pipewire-alsa MT safe so that multi threaded programs can use it without any extra locks.
This commit is contained in:
parent
0cf6760ee0
commit
f22dd9d781
1 changed files with 14 additions and 4 deletions
|
|
@ -33,6 +33,8 @@
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <alsa/asoundlib.h>
|
#include <alsa/asoundlib.h>
|
||||||
#include <alsa/pcm_external.h>
|
#include <alsa/pcm_external.h>
|
||||||
|
|
||||||
|
|
@ -54,6 +56,8 @@
|
||||||
|
|
||||||
#define MIN_PERIOD 64
|
#define MIN_PERIOD 64
|
||||||
|
|
||||||
|
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
snd_pcm_ioplug_t io;
|
snd_pcm_ioplug_t io;
|
||||||
|
|
||||||
|
|
@ -159,7 +163,9 @@ static int snd_pcm_pipewire_close(snd_pcm_ioplug_t *io)
|
||||||
{
|
{
|
||||||
snd_pcm_pipewire_t *pw = io->private_data;
|
snd_pcm_pipewire_t *pw = io->private_data;
|
||||||
pw_log_debug(NAME" %p:", pw);
|
pw_log_debug(NAME" %p:", pw);
|
||||||
|
pthread_mutex_lock(&lock);
|
||||||
snd_pcm_pipewire_free(pw);
|
snd_pcm_pipewire_free(pw);
|
||||||
|
pthread_mutex_unlock(&lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1112,10 +1118,6 @@ SND_PCM_PLUGIN_DEFINE_FUNC(pipewire)
|
||||||
uint32_t flags = 0;
|
uint32_t flags = 0;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
pw_init(NULL, NULL);
|
|
||||||
if (strstr(pw_get_library_version(), "0.2") != NULL)
|
|
||||||
return -ENOTSUP;
|
|
||||||
|
|
||||||
snd_config_for_each(i, next, conf) {
|
snd_config_for_each(i, next, conf) {
|
||||||
snd_config_t *n = snd_config_iterator_entry(i);
|
snd_config_t *n = snd_config_iterator_entry(i);
|
||||||
const char *id;
|
const char *id;
|
||||||
|
|
@ -1191,9 +1193,17 @@ SND_PCM_PLUGIN_DEFINE_FUNC(pipewire)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_lock(&lock);
|
||||||
|
pw_init(NULL, NULL);
|
||||||
|
if (strstr(pw_get_library_version(), "0.2") != NULL) {
|
||||||
|
pthread_mutex_unlock(&lock);
|
||||||
|
return -ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
err = snd_pcm_pipewire_open(pcmp, name, node_name, server_name, playback_node,
|
err = snd_pcm_pipewire_open(pcmp, name, node_name, server_name, playback_node,
|
||||||
capture_node, role, stream, mode, flags, rate, format,
|
capture_node, role, stream, mode, flags, rate, format,
|
||||||
channels, period_bytes);
|
channels, period_bytes);
|
||||||
|
pthread_mutex_unlock(&lock);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue