srt: Remove use of closures for signal emission

It seems overly complicated.
This commit is contained in:
Jan Alexander Steffens (heftig) 2020-03-18 18:06:59 +01:00
parent d2d00e07ac
commit 132e3a1af9
No known key found for this signature in database
GPG key ID: DE5E0C5F25941CA5
4 changed files with 9 additions and 118 deletions

View file

@ -90,24 +90,10 @@ srt_caller_free (SRTCaller * caller)
/* called with sock_lock */
static void
srt_caller_invoke_removed_closure (SRTCaller * caller, GstSRTObject * srtobject)
srt_caller_signal_removed (SRTCaller * caller, GstSRTObject * srtobject)
{
GValue values[2] = { G_VALUE_INIT };
if (srtobject->caller_removed_closure == NULL) {
return;
}
g_value_init (&values[0], G_TYPE_INT);
g_value_set_int (&values[0], caller->sock);
g_value_init (&values[1], G_TYPE_SOCKET_ADDRESS);
g_value_set_object (&values[1], caller->sockaddr);
g_closure_invoke (srtobject->caller_removed_closure, NULL, 2, values, NULL);
g_value_unset (&values[0]);
g_value_unset (&values[1]);
g_signal_emit_by_name (srtobject->element, "caller-removed", caller->sock,
caller->sockaddr);
}
struct srt_constant_params
@ -733,20 +719,8 @@ thread_func (gpointer data)
g_mutex_unlock (&srtobject->sock_lock);
/* notifying caller-added */
if (srtobject->caller_added_closure != NULL) {
GValue values[2] = { G_VALUE_INIT, G_VALUE_INIT };
g_value_init (&values[0], G_TYPE_INT);
g_value_set_int (&values[0], caller->sock);
g_value_init (&values[1], G_TYPE_SOCKET_ADDRESS);
g_value_set_object (&values[1], caller->sockaddr);
g_closure_invoke (srtobject->caller_added_closure, NULL, 2, values,
NULL);
g_value_unset (&values[1]);
}
g_signal_emit_by_name (srtobject->element, "caller-added", caller->sock,
caller->sockaddr);
GST_DEBUG_OBJECT (srtobject->element, "Accept to connect");
@ -995,15 +969,6 @@ gst_srt_object_open_connection (GstSRTObject * srtobject,
gboolean
gst_srt_object_open (GstSRTObject * srtobject, GCancellable * cancellable,
GError ** error)
{
return gst_srt_object_open_full (srtobject, NULL, NULL, cancellable, error);
}
gboolean
gst_srt_object_open_full (GstSRTObject * srtobject,
GstSRTObjectCallerAdded caller_added_func,
GstSRTObjectCallerRemoved caller_removed_func,
GCancellable * cancellable, GError ** error)
{
GSocketAddress *socket_address = NULL;
GstSRTConnectionMode connection_mode = GST_SRT_CONNECTION_MODE_NONE;
@ -1018,20 +983,6 @@ gst_srt_object_open_full (GstSRTObject * srtobject,
srtobject->opened = FALSE;
if (caller_added_func != NULL) {
srtobject->caller_added_closure =
g_cclosure_new (G_CALLBACK (caller_added_func), srtobject, NULL);
g_closure_set_marshal (srtobject->caller_added_closure,
g_cclosure_marshal_generic);
}
if (caller_removed_func != NULL) {
srtobject->caller_removed_closure =
g_cclosure_new (G_CALLBACK (caller_removed_func), srtobject, NULL);
g_closure_set_marshal (srtobject->caller_removed_closure,
g_cclosure_marshal_generic);
}
addr_str = gst_uri_get_host (srtobject->uri);
if (addr_str == NULL) {
addr_str = GST_SRT_DEFAULT_LOCALADDRESS;
@ -1132,14 +1083,10 @@ gst_srt_object_close (GstSRTObject * srtobject)
if (srtobject->callers) {
GList *callers = g_steal_pointer (&srtobject->callers);
g_list_foreach (callers, (GFunc) srt_caller_invoke_removed_closure,
srtobject);
g_list_foreach (callers, (GFunc) srt_caller_signal_removed, srtobject);
g_list_free_full (callers, (GDestroyNotify) srt_caller_free);
}
g_clear_pointer (&srtobject->caller_added_closure, g_closure_unref);
g_clear_pointer (&srtobject->caller_removed_closure, g_closure_unref);
g_mutex_unlock (&srtobject->sock_lock);
GST_OBJECT_LOCK (srtobject->element);
@ -1388,7 +1335,7 @@ gst_srt_object_write_to_callers (GstSRTObject * srtobject,
err:
srtobject->callers = g_list_remove (srtobject->callers, caller);
srt_caller_invoke_removed_closure (caller, srtobject);
srt_caller_signal_removed (caller, srtobject);
srt_caller_free (caller);
}

View file

@ -68,19 +68,11 @@ struct _GstSRTObject
GList *callers;
GClosure *caller_added_closure;
GClosure *caller_removed_closure;
gchar *passphrase;
gboolean wait_for_connection;
};
typedef void (*GstSRTObjectCallerAdded) (int sock, GSocketAddress *addr, GstSRTObject * srtobject);
typedef void (*GstSRTObjectCallerRemoved) (int sock, GSocketAddress *addr, GstSRTObject * srtobject);
GstSRTObject *gst_srt_object_new (GstElement *element);
void gst_srt_object_destroy (GstSRTObject *srtobject);
@ -89,12 +81,6 @@ gboolean gst_srt_object_open (GstSRTObject *srtobject,
GCancellable *cancellable,
GError **error);
gboolean gst_srt_object_open_full (GstSRTObject *srtobject,
GstSRTObjectCallerAdded caller_added_func,
GstSRTObjectCallerRemoved caller_removed_func,
GCancellable *cancellable,
GError **error);
void gst_srt_object_close (GstSRTObject *srtobject);
gboolean gst_srt_object_set_property_helper (GstSRTObject *srtobject,

View file

@ -118,21 +118,6 @@ gst_srt_sink_init (GstSRTSink * self)
gst_srt_object_set_uri (self->srtobject, GST_SRT_DEFAULT_URI, NULL);
}
static void
gst_srt_sink_caller_added_cb (int sock, GSocketAddress * addr,
GstSRTObject * srtobject)
{
g_signal_emit (srtobject->element, signals[SIG_CALLER_ADDED], 0, sock, addr);
}
static void
gst_srt_sink_caller_removed_cb (int sock, GSocketAddress * addr,
GstSRTObject * srtobject)
{
g_signal_emit (srtobject->element, signals[SIG_CALLER_REMOVED], 0, sock,
addr);
}
static gboolean
gst_srt_sink_start (GstBaseSink * bsink)
{
@ -145,13 +130,7 @@ gst_srt_sink_start (GstBaseSink * bsink)
gst_structure_get_enum (self->srtobject->parameters, "mode",
GST_TYPE_SRT_CONNECTION_MODE, (gint *) & connection_mode);
if (connection_mode == GST_SRT_CONNECTION_MODE_LISTENER) {
ret =
gst_srt_object_open_full (self->srtobject, gst_srt_sink_caller_added_cb,
gst_srt_sink_caller_removed_cb, self->cancellable, &error);
} else {
ret = gst_srt_object_open (self->srtobject, self->cancellable, &error);
}
ret = gst_srt_object_open (self->srtobject, self->cancellable, &error);
if (!ret) {
/* ensure error is posted since state change will fail */

View file

@ -77,21 +77,6 @@ G_DEFINE_TYPE_WITH_CODE (GstSRTSrc, gst_srt_src,
G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_srt_src_uri_handler_init)
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "srtsrc", 0, "SRT Source"));
static void
gst_srt_src_caller_added_cb (int sock, GSocketAddress * addr,
GstSRTObject * srtobject)
{
g_signal_emit (srtobject->element, signals[SIG_CALLER_ADDED], 0, sock, addr);
}
static void
gst_srt_src_caller_removed_cb (int sock, GSocketAddress * addr,
GstSRTObject * srtobject)
{
g_signal_emit (srtobject->element, signals[SIG_CALLER_REMOVED], 0, sock,
addr);
}
static gboolean
gst_srt_src_start (GstBaseSrc * bsrc)
{
@ -103,13 +88,7 @@ gst_srt_src_start (GstBaseSrc * bsrc)
gst_structure_get_enum (self->srtobject->parameters, "mode",
GST_TYPE_SRT_CONNECTION_MODE, (gint *) & connection_mode);
if (connection_mode == GST_SRT_CONNECTION_MODE_LISTENER) {
ret =
gst_srt_object_open_full (self->srtobject, gst_srt_src_caller_added_cb,
gst_srt_src_caller_removed_cb, self->cancellable, &error);
} else {
ret = gst_srt_object_open (self->srtobject, self->cancellable, &error);
}
ret = gst_srt_object_open (self->srtobject, self->cancellable, &error);
if (!ret) {
/* ensure error is posted since state change will fail */