mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-25 09:40:37 +00:00
dtls: Use a plain function pointer instead of a GClosure for the send callback
There's not point in using GClosure and going through all the GValue/libffi infrastructure for each DTLS packet.
This commit is contained in:
parent
47ce34d32c
commit
ee55dac8d4
3 changed files with 30 additions and 43 deletions
|
@ -93,7 +93,9 @@ struct _GstDtlsConnectionPrivate
|
||||||
gint bio_buffer_len;
|
gint bio_buffer_len;
|
||||||
gint bio_buffer_offset;
|
gint bio_buffer_offset;
|
||||||
|
|
||||||
GClosure *send_closure;
|
GstDtlsConnectionSendCallback send_callback;
|
||||||
|
gpointer send_callback_user_data;
|
||||||
|
GDestroyNotify send_callback_destroy_notify;
|
||||||
|
|
||||||
gboolean timeout_pending;
|
gboolean timeout_pending;
|
||||||
GThreadPool *thread_pool;
|
GThreadPool *thread_pool;
|
||||||
|
@ -170,8 +172,6 @@ gst_dtls_connection_init (GstDtlsConnection * self)
|
||||||
priv->ssl = NULL;
|
priv->ssl = NULL;
|
||||||
priv->bio = NULL;
|
priv->bio = NULL;
|
||||||
|
|
||||||
priv->send_closure = NULL;
|
|
||||||
|
|
||||||
priv->is_client = FALSE;
|
priv->is_client = FALSE;
|
||||||
priv->is_alive = TRUE;
|
priv->is_alive = TRUE;
|
||||||
priv->keys_exported = FALSE;
|
priv->keys_exported = FALSE;
|
||||||
|
@ -203,10 +203,8 @@ gst_dtls_connection_finalize (GObject * gobject)
|
||||||
SSL_free (priv->ssl);
|
SSL_free (priv->ssl);
|
||||||
priv->ssl = NULL;
|
priv->ssl = NULL;
|
||||||
|
|
||||||
if (priv->send_closure) {
|
if (priv->send_callback_destroy_notify)
|
||||||
g_closure_unref (priv->send_closure);
|
priv->send_callback_destroy_notify (priv->send_callback_user_data);
|
||||||
priv->send_closure = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_mutex_clear (&priv->mutex);
|
g_mutex_clear (&priv->mutex);
|
||||||
g_cond_clear (&priv->condition);
|
g_cond_clear (&priv->condition);
|
||||||
|
@ -293,7 +291,7 @@ gst_dtls_connection_start (GstDtlsConnection * self, gboolean is_client)
|
||||||
|
|
||||||
priv = self->priv;
|
priv = self->priv;
|
||||||
|
|
||||||
g_return_if_fail (priv->send_closure);
|
g_return_if_fail (priv->send_callback);
|
||||||
g_return_if_fail (priv->ssl);
|
g_return_if_fail (priv->ssl);
|
||||||
g_return_if_fail (priv->bio);
|
g_return_if_fail (priv->bio);
|
||||||
|
|
||||||
|
@ -486,26 +484,27 @@ gst_dtls_connection_close (GstDtlsConnection * self)
|
||||||
|
|
||||||
void
|
void
|
||||||
gst_dtls_connection_set_send_callback (GstDtlsConnection * self,
|
gst_dtls_connection_set_send_callback (GstDtlsConnection * self,
|
||||||
GClosure * closure)
|
GstDtlsConnectionSendCallback callback, gpointer user_data,
|
||||||
|
GDestroyNotify destroy_notify)
|
||||||
{
|
{
|
||||||
|
GstDtlsConnectionPrivate *priv;
|
||||||
|
|
||||||
g_return_if_fail (GST_IS_DTLS_CONNECTION (self));
|
g_return_if_fail (GST_IS_DTLS_CONNECTION (self));
|
||||||
|
|
||||||
|
priv = self->priv;
|
||||||
|
|
||||||
GST_TRACE_OBJECT (self, "locking @ set_send_callback");
|
GST_TRACE_OBJECT (self, "locking @ set_send_callback");
|
||||||
g_mutex_lock (&self->priv->mutex);
|
g_mutex_lock (&priv->mutex);
|
||||||
GST_TRACE_OBJECT (self, "locked @ set_send_callback");
|
GST_TRACE_OBJECT (self, "locked @ set_send_callback");
|
||||||
|
|
||||||
if (self->priv->send_closure) {
|
if (priv->send_callback_destroy_notify)
|
||||||
g_closure_unref (self->priv->send_closure);
|
priv->send_callback_destroy_notify (priv->send_callback_user_data);
|
||||||
self->priv->send_closure = NULL;
|
priv->send_callback = callback;
|
||||||
}
|
priv->send_callback_user_data = user_data;
|
||||||
self->priv->send_closure = closure;
|
priv->send_callback_destroy_notify = destroy_notify;
|
||||||
|
|
||||||
if (closure && G_CLOSURE_NEEDS_MARSHAL (closure)) {
|
|
||||||
g_closure_set_marshal (closure, g_cclosure_marshal_generic);
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_TRACE_OBJECT (self, "unlocking @ set_send_callback");
|
GST_TRACE_OBJECT (self, "unlocking @ set_send_callback");
|
||||||
g_mutex_unlock (&self->priv->mutex);
|
g_mutex_unlock (&priv->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
gint
|
gint
|
||||||
|
@ -903,22 +902,9 @@ bio_method_write (BIO * bio, const char *data, int size)
|
||||||
|
|
||||||
GST_LOG_OBJECT (self, "BIO: writing %d", size);
|
GST_LOG_OBJECT (self, "BIO: writing %d", size);
|
||||||
|
|
||||||
if (self->priv->send_closure) {
|
if (self->priv->send_callback)
|
||||||
GValue values[3] = { G_VALUE_INIT };
|
self->priv->send_callback (self, data, size,
|
||||||
|
self->priv->send_callback_user_data);
|
||||||
g_value_init (&values[0], GST_TYPE_DTLS_CONNECTION);
|
|
||||||
g_value_set_object (&values[0], self);
|
|
||||||
|
|
||||||
g_value_init (&values[1], G_TYPE_POINTER);
|
|
||||||
g_value_set_pointer (&values[1], (gpointer) data);
|
|
||||||
|
|
||||||
g_value_init (&values[2], G_TYPE_INT);
|
|
||||||
g_value_set_int (&values[2], size);
|
|
||||||
|
|
||||||
g_closure_invoke (self->priv->send_closure, NULL, 3, values, NULL);
|
|
||||||
|
|
||||||
g_value_unset (&values[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,13 +98,13 @@ void gst_dtls_connection_stop(GstDtlsConnection *);
|
||||||
*/
|
*/
|
||||||
void gst_dtls_connection_close(GstDtlsConnection *);
|
void gst_dtls_connection_close(GstDtlsConnection *);
|
||||||
|
|
||||||
|
|
||||||
|
typedef void (*GstDtlsConnectionSendCallback) (GstDtlsConnection * connection, gconstpointer data, gsize length, gpointer user_data);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sets the closure that will be called whenever data needs to be sent.
|
* Sets the callback that will be called whenever data needs to be sent.
|
||||||
*
|
|
||||||
* The closure will get called with the following arguments:
|
|
||||||
* void cb(GstDtlsConnection *, gpointer data, gint length, gpointer user_data)
|
|
||||||
*/
|
*/
|
||||||
void gst_dtls_connection_set_send_callback(GstDtlsConnection *, GClosure *);
|
void gst_dtls_connection_set_send_callback(GstDtlsConnection *, GstDtlsConnectionSendCallback, gpointer, GDestroyNotify);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Processes data that has been received, the transformation is done in-place.
|
* Processes data that has been received, the transformation is done in-place.
|
||||||
|
|
|
@ -296,7 +296,7 @@ gst_dtls_enc_change_state (GstElement * element, GstStateChange transition)
|
||||||
"on-encoder-key", G_CALLBACK (on_key_received), self, 0);
|
"on-encoder-key", G_CALLBACK (on_key_received), self, 0);
|
||||||
|
|
||||||
gst_dtls_connection_set_send_callback (self->connection,
|
gst_dtls_connection_set_send_callback (self->connection,
|
||||||
g_cclosure_new (G_CALLBACK (on_send_data), self, NULL));
|
(GstDtlsConnectionSendCallback) on_send_data, self, NULL);
|
||||||
} else {
|
} else {
|
||||||
GST_WARNING_OBJECT (self,
|
GST_WARNING_OBJECT (self,
|
||||||
"trying to change state to ready without connection id");
|
"trying to change state to ready without connection id");
|
||||||
|
@ -313,7 +313,8 @@ gst_dtls_enc_change_state (GstElement * element, GstStateChange transition)
|
||||||
|
|
||||||
if (self->connection) {
|
if (self->connection) {
|
||||||
gst_dtls_connection_close (self->connection);
|
gst_dtls_connection_close (self->connection);
|
||||||
gst_dtls_connection_set_send_callback (self->connection, NULL);
|
gst_dtls_connection_set_send_callback (self->connection, NULL, NULL,
|
||||||
|
NULL);
|
||||||
g_object_unref (self->connection);
|
g_object_unref (self->connection);
|
||||||
self->connection = NULL;
|
self->connection = NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue