-
- /* get the mainloop api and create a context */
- GST_LOG_OBJECT (psink, "new context with name %s", GST_STR_NULL (name));
- api = pa_threaded_mainloop_get_api (psink->mainloop);
- if (!(pbuf->context = pa_context_new (api, name)))
- goto create_failed;
-
- /* register some essential callbacks */
- pa_context_set_state_callback (pbuf->context,
- gst_pulsering_context_state_cb, pbuf);
+ g_mutex_lock (pa_ring_buffer_mutex);
+
+ pctx = g_hash_table_lookup (gst_pulse_shared_contexts, pbuf->context_name);
+ if (pctx == NULL) {
+ pctx = g_slice_new0 (GstPulseContext);
+ /* get the mainloop api and create a context */
+ GST_LOG_OBJECT (psink, "new context with name %s",
+ GST_STR_NULL (pbuf->context_name));
+ api = pa_threaded_mainloop_get_api (psink->mainloop);
+ if (!(pctx->context = pa_context_new (api, pbuf->context_name)))
+ goto create_failed;
+
+ pctx->ring_buffers = g_slist_append (pctx->ring_buffers, pbuf);
+ g_hash_table_insert (gst_pulse_shared_contexts, pbuf->context_name,
+ (gpointer) pctx);
+ /* register some essential callbacks */
+ pa_context_set_state_callback (pctx->context,
+ gst_pulsering_context_state_cb, pctx);