mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
jack-tunnel: use cycle_wait/cycle_signal
Use cycle_wait and cycle_signal so that we can avoid using a semaphore and resume the jack graph right after we finish the pipewire graph.
This commit is contained in:
parent
bcbb6e42e7
commit
ea1385ffe0
1 changed files with 50 additions and 63 deletions
|
|
@ -116,8 +116,6 @@ struct impl {
|
|||
struct pw_loop *main_loop;
|
||||
struct spa_system *system;
|
||||
|
||||
sem_t sem;
|
||||
|
||||
#define MODE_SINK (1<<0)
|
||||
#define MODE_SOURCE (1<<1)
|
||||
#define MODE_DUPLEX (MODE_SINK|MODE_SOURCE)
|
||||
|
|
@ -231,7 +229,7 @@ static void sink_stream_process(void *d)
|
|||
done:
|
||||
pw_log_trace_fp("done %u", impl->frames);
|
||||
impl->done = true;
|
||||
sem_post(&impl->sem);
|
||||
jack_cycle_signal(impl->client, 0);
|
||||
}
|
||||
|
||||
static void source_stream_process(void *d)
|
||||
|
|
@ -420,10 +418,14 @@ static int create_streams(struct impl *impl)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int jack_process(jack_nframes_t nframes, void *arg)
|
||||
static void *jack_process_thread(void *arg)
|
||||
{
|
||||
struct impl *impl = arg;
|
||||
bool source_running, sink_running;
|
||||
jack_nframes_t nframes;
|
||||
|
||||
while (true) {
|
||||
nframes = jack_cycle_wait (impl->client);
|
||||
|
||||
source_running = impl->source_running;
|
||||
sink_running = impl->sink_running;
|
||||
|
|
@ -433,6 +435,11 @@ static int jack_process(jack_nframes_t nframes, void *arg)
|
|||
pw_log_trace_fp("process %d %u %u %p %d", nframes, source_running,
|
||||
sink_running, impl->position, impl->frames);
|
||||
|
||||
if (impl->new_xrun) {
|
||||
pw_log_warn("Xrun JACK:%u PipeWire:%u", impl->jack_xrun, impl->pw_xrun);
|
||||
impl->new_xrun = false;
|
||||
}
|
||||
|
||||
if (impl->position) {
|
||||
struct spa_io_clock *c = &impl->position->clock;
|
||||
jack_nframes_t current_frames;
|
||||
|
|
@ -461,35 +468,23 @@ static int jack_process(jack_nframes_t nframes, void *arg)
|
|||
impl->nframes = nframes;
|
||||
|
||||
if (sink_running && source_running) {
|
||||
|
||||
while (sem_trywait(&impl->sem) == 0);
|
||||
|
||||
impl->done = false;
|
||||
pw_stream_trigger_process(impl->sink);
|
||||
|
||||
sem_wait(&impl->sem);
|
||||
if (!impl->done) {
|
||||
impl->pw_xrun++;
|
||||
impl->new_xrun = true;
|
||||
}
|
||||
if (impl->new_xrun) {
|
||||
pw_log_warn("Xrun JACK:%u PipeWire:%u", impl->jack_xrun, impl->pw_xrun);
|
||||
impl->new_xrun = false;
|
||||
} else {
|
||||
jack_cycle_signal(impl->client, 0);
|
||||
}
|
||||
}
|
||||
pw_log_trace_fp("done %u", impl->frames);
|
||||
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int jack_xrun(void *arg)
|
||||
{
|
||||
struct impl *impl = arg;
|
||||
if (impl->done) {
|
||||
if (impl->done)
|
||||
impl->jack_xrun++;
|
||||
else
|
||||
impl->pw_xrun++;
|
||||
impl->new_xrun = true;
|
||||
}
|
||||
sem_post(&impl->sem);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -639,7 +634,7 @@ static int create_jack_client(struct impl *impl)
|
|||
return -EIO;
|
||||
}
|
||||
jack_on_info_shutdown(impl->client, jack_info_shutdown, impl);
|
||||
jack_set_process_callback(impl->client, jack_process, impl);
|
||||
jack_set_process_thread(impl->client, jack_process_thread, impl);
|
||||
jack_set_xrun_callback(impl->client, jack_xrun, impl);
|
||||
jack_set_latency_callback(impl->client, jack_latency, impl);
|
||||
|
||||
|
|
@ -747,8 +742,6 @@ static void impl_destroy(struct impl *impl)
|
|||
pw_properties_free(impl->source_props);
|
||||
pw_properties_free(impl->props);
|
||||
|
||||
sem_destroy(&impl->sem);
|
||||
|
||||
free(impl);
|
||||
}
|
||||
|
||||
|
|
@ -833,12 +826,6 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
|||
|
||||
pw_log_debug("module %p: new %s", impl, args);
|
||||
|
||||
if (sem_init(&impl->sem, 0, 0) < 0) {
|
||||
res = -errno;
|
||||
pw_log_error( "can't create semaphore: %m");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (args == NULL)
|
||||
args = "";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue