{
gint refcount;
GMutex *lock;
+ GCond *flush_cond;
/* id/server pair and the connection */
gchar *id;
GstJackClientType type;
gboolean active;
+ gboolean deactivate;
void (*shutdown) (void *arg);
JackProcessCallback process;
GstJackAudioClient *client = (GstJackAudioClient *) walk->data;
/* only call active clients */
- if (client->active && client->process)
+ if ((client->active || client->deactivate) && client->process) {
res = client->process (nframes, client->user_data);
+ if (client->deactivate) {
+ client->deactivate = FALSE;
+ g_cond_signal (conn->flush_cond);
+ }
+ }
}
for (walk = conn->sink_clients; walk; walk = g_list_next (walk)) {
GstJackAudioClient *client = (GstJackAudioClient *) walk->data;
/* only call active clients */
- if (client->active && client->process)
+ if ((client->active || client->deactivate) && client->process) {
res = client->process (nframes, client->user_data);
+ if (client->deactivate) {
+ client->deactivate = FALSE;
+ g_cond_signal (conn->flush_cond);
+ }
+ }
}
g_mutex_unlock (conn->lock);
conn = g_new (GstJackAudioConnection, 1);
conn->refcount = 1;
conn->lock = g_mutex_new ();
+ conn->flush_cond = g_cond_new ();
conn->id = g_strdup (id);
conn->server = g_strdup (server);
conn->client = jclient;
/* free resources */
g_mutex_free (conn->lock);
+ g_cond_free (conn->flush_cond);
g_free (conn->id);
g_free (conn->server);
g_free (conn);
if (conn == NULL)
goto no_connection;
+ GST_INFO ("new client %s", id);
+
/* make new client using the connection */
client = g_new (GstJackAudioClient, 1);
- client->active = FALSE;
+ client->active = client->deactivate = FALSE;
client->conn = conn;
client->type = type;
client->shutdown = shutdown;
g_return_if_fail (client != NULL);
+ GST_INFO ("free client");
+
conn = client->conn;
/* remove from connection first so that it's not scheduled anymore after this
/* make sure that we are not dispatching the client */
g_mutex_lock (client->conn->lock);
+ if (client->active && !active) {
+ /* we need to process once more to flush the port */
+ client->deactivate = TRUE;
+
+ /* need to wait for process_cb run once more */
+ while (client->deactivate)
+ g_cond_wait (client->conn->flush_cond, client->conn->lock);
+ }
client->active = active;
g_mutex_unlock (client->conn->lock);
if (nframes * sizeof (sample_t) != flen)
goto wrong_size;
- GST_DEBUG ("copy %d frames: %p, %d bytes, %d channels", nframes, readptr,
- flen, channels);
+ GST_DEBUG_OBJECT (sink, "copy %d frames: %p, %d bytes, %d channels",
+ nframes, readptr, flen, channels);
data = (sample_t *) readptr;
/* the samples in the ringbuffer have the channels interleaved, we need to
/* we wrote one segment */
gst_ring_buffer_advance (buf, 1);
} else {
+ GST_DEBUG_OBJECT (sink, "write %d frames silence", nframes);
/* We are not allowed to read from the ringbuffer, write silence to all
* jack output buffers */
for (i = 0; i < channels; i++) {
res = latency;
}
- GST_DEBUG_OBJECT (sink, "delay %u", res);
+ GST_LOG_OBJECT (sink, "delay %u", res);
return res;
}