Commit 7fcfb6c6 authored by Sebastian Dröge's avatar Sebastian Dröge 🍵 Committed by GStreamer Merge Bot

dtls: Keep track of the connection state and signal it through all the layers

This allows the application to keep track of the underlying DTLS
connection state and act accordingly.
parent d66aa872
This diff is collapsed.
......@@ -65,6 +65,18 @@ typedef enum {
#define GST_DTLS_SRTP_MASTER_KEY_LENGTH 30
typedef enum
{
GST_DTLS_CONNECTION_STATE_NEW,
GST_DTLS_CONNECTION_STATE_CLOSED,
GST_DTLS_CONNECTION_STATE_FAILED,
GST_DTLS_CONNECTION_STATE_CONNECTING,
GST_DTLS_CONNECTION_STATE_CONNECTED,
} GstDtlsConnectionState;
GType gst_dtls_connection_state_get_type (void);
#define GST_DTLS_TYPE_CONNECTION_STATE (gst_dtls_connection_state_get_type ())
/*
* GstDtlsConnection:
*
......
......@@ -63,10 +63,10 @@ enum
PROP_CONNECTION_ID,
PROP_PEM,
PROP_PEER_PEM,
PROP_DECODER_KEY,
PROP_SRTP_CIPHER,
PROP_SRTP_AUTH,
PROP_CONNECTION_STATE,
NUM_PROPERTIES
};
......@@ -171,6 +171,13 @@ gst_dtls_dec_class_init (GstDtlsDecClass * klass)
0, GST_DTLS_SRTP_AUTH_HMAC_SHA1_80, DEFAULT_SRTP_AUTH,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
properties[PROP_CONNECTION_STATE] =
g_param_spec_enum ("connection-state",
"Connection State",
"Current connection state",
GST_DTLS_TYPE_CONNECTION_STATE,
GST_DTLS_CONNECTION_STATE_NEW, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
gst_element_class_add_static_pad_template (element_class, &src_template);
......@@ -301,6 +308,13 @@ gst_dtls_dec_get_property (GObject * object, guint prop_id, GValue * value,
case PROP_SRTP_AUTH:
g_value_set_uint (value, self->srtp_auth);
break;
case PROP_CONNECTION_STATE:
if (self->connection)
g_object_get_property (G_OBJECT (self->connection), "connection-state",
value);
else
g_value_set_enum (value, GST_DTLS_CONNECTION_STATE_CLOSED);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
}
......@@ -743,6 +757,15 @@ gst_dtls_dec_fetch_connection (gchar * id)
return connection;
}
static void
on_connection_state_changed (GObject * object, GParamSpec * pspec,
gpointer user_data)
{
GstDtlsDec *self = GST_DTLS_DEC (user_data);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CONNECTION_STATE]);
}
static void
create_connection (GstDtlsDec * self, gchar * id)
{
......@@ -750,6 +773,8 @@ create_connection (GstDtlsDec * self, gchar * id)
g_return_if_fail (GST_IS_DTLS_AGENT (self->agent));
if (self->connection) {
g_signal_handlers_disconnect_by_func (self->connection,
on_connection_state_changed, self);
g_object_unref (self->connection);
self->connection = NULL;
}
......@@ -769,6 +794,10 @@ create_connection (GstDtlsDec * self, gchar * id)
self->connection =
g_object_new (GST_TYPE_DTLS_CONNECTION, "agent", self->agent, NULL);
g_signal_connect_object (self->connection,
"notify::connection-state", G_CALLBACK (on_connection_state_changed),
self, 0);
on_connection_state_changed (NULL, NULL, self);
g_object_weak_ref (G_OBJECT (self->connection),
(GWeakNotify) connection_weak_ref_notify, g_strdup (id));
......
......@@ -62,10 +62,10 @@ enum
PROP_0,
PROP_CONNECTION_ID,
PROP_IS_CLIENT,
PROP_ENCODER_KEY,
PROP_SRTP_CIPHER,
PROP_SRTP_AUTH,
PROP_CONNECTION_STATE,
NUM_PROPERTIES
};
......@@ -160,6 +160,13 @@ gst_dtls_enc_class_init (GstDtlsEncClass * klass)
0, GST_DTLS_SRTP_AUTH_HMAC_SHA1_80, DEFAULT_SRTP_AUTH,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
properties[PROP_CONNECTION_STATE] =
g_param_spec_enum ("connection-state",
"Connection State",
"Current connection state",
GST_DTLS_TYPE_CONNECTION_STATE,
GST_DTLS_CONNECTION_STATE_NEW, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
gst_element_class_add_static_pad_template (element_class, &src_template);
......@@ -269,11 +276,27 @@ gst_dtls_enc_get_property (GObject * object, guint prop_id, GValue * value,
case PROP_SRTP_AUTH:
g_value_set_uint (value, self->srtp_auth);
break;
case PROP_CONNECTION_STATE:
if (self->connection)
g_object_get_property (G_OBJECT (self->connection), "connection-state",
value);
else
g_value_set_enum (value, GST_DTLS_CONNECTION_STATE_CLOSED);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
}
}
static void
on_connection_state_changed (GObject * object, GParamSpec * pspec,
gpointer user_data)
{
GstDtlsEnc *self = GST_DTLS_ENC (user_data);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CONNECTION_STATE]);
}
static GstStateChangeReturn
gst_dtls_enc_change_state (GstElement * element, GstStateChange transition)
{
......@@ -294,6 +317,10 @@ gst_dtls_enc_change_state (GstElement * element, GstStateChange transition)
g_signal_connect_object (self->connection,
"on-encoder-key", G_CALLBACK (on_key_received), self, 0);
g_signal_connect_object (self->connection,
"notify::connection-state",
G_CALLBACK (on_connection_state_changed), self, 0);
on_connection_state_changed (NULL, NULL, self);
gst_dtls_connection_set_send_callback (self->connection,
(GstDtlsConnectionSendCallback) on_send_data, self, NULL);
......
......@@ -28,7 +28,6 @@
#endif
#include "gstdtlssrtpdec.h"
#include "gstdtlsconnection.h"
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
......@@ -69,6 +68,7 @@ enum
PROP_0,
PROP_PEM,
PROP_PEER_PEM,
PROP_CONNECTION_STATE,
NUM_PROPERTIES
};
......@@ -132,6 +132,13 @@ gst_dtls_srtp_dec_class_init (GstDtlsSrtpDecClass * klass)
"The X509 certificate received in the DTLS handshake, in PEM format",
DEFAULT_PEER_PEM, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
properties[PROP_CONNECTION_STATE] =
g_param_spec_enum ("connection-state",
"Connection State",
"Current connection state",
GST_DTLS_TYPE_CONNECTION_STATE,
GST_DTLS_CONNECTION_STATE_NEW, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
gst_element_class_add_static_pad_template (element_class, &sink_template);
......@@ -146,6 +153,15 @@ gst_dtls_srtp_dec_class_init (GstDtlsSrtpDecClass * klass)
"Patrik Oldsberg patrik.oldsberg@ericsson.com");
}
static void
on_connection_state_changed (GObject * object, GParamSpec * pspec,
gpointer user_data)
{
GstDtlsSrtpDec *self = GST_DTLS_SRTP_DEC (user_data);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CONNECTION_STATE]);
}
static void
gst_dtls_srtp_dec_init (GstDtlsSrtpDec * self)
{
......@@ -226,6 +242,8 @@ gst_dtls_srtp_dec_init (GstDtlsSrtpDec * self)
G_CALLBACK (on_decoder_request_key), self);
g_signal_connect (self->bin.dtls_element, "notify::peer-pem",
G_CALLBACK (on_peer_pem), self);
g_signal_connect (self->bin.dtls_element, "notify::connection-state",
G_CALLBACK (on_connection_state_changed), self);
}
static void
......@@ -269,6 +287,10 @@ gst_dtls_srtp_dec_get_property (GObject * object,
GST_WARNING_OBJECT (self, "tried to get peer-pem after disabling DTLS");
}
break;
case PROP_CONNECTION_STATE:
g_object_get_property (G_OBJECT (self->bin.dtls_element),
"connection-state", value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
}
......
......@@ -28,6 +28,7 @@
#endif
#include "gstdtlssrtpenc.h"
#include "gstdtlsconnection.h"
#include <stdio.h>
......@@ -76,6 +77,7 @@ enum
{
PROP_0,
PROP_IS_CLIENT,
PROP_CONNECTION_STATE,
NUM_PROPERTIES
};
......@@ -136,6 +138,13 @@ gst_dtls_srtp_enc_class_init (GstDtlsSrtpEncClass * klass)
DEFAULT_IS_CLIENT,
GST_PARAM_MUTABLE_READY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
properties[PROP_CONNECTION_STATE] =
g_param_spec_enum ("connection-state",
"Connection State",
"Current connection state",
GST_DTLS_TYPE_CONNECTION_STATE,
GST_DTLS_CONNECTION_STATE_NEW, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
gst_element_class_add_static_pad_template (element_class, &rtp_sink_template);
......@@ -152,6 +161,15 @@ gst_dtls_srtp_enc_class_init (GstDtlsSrtpEncClass * klass)
"Patrik Oldsberg patrik.oldsberg@ericsson.com");
}
static void
on_connection_state_changed (GObject * object, GParamSpec * pspec,
gpointer user_data)
{
GstDtlsSrtpEnc *self = GST_DTLS_SRTP_ENC (user_data);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CONNECTION_STATE]);
}
static void
gst_dtls_srtp_enc_init (GstDtlsSrtpEnc * self)
{
......@@ -215,6 +233,9 @@ gst_dtls_srtp_enc_init (GstDtlsSrtpEnc * self)
g_object_set (self->srtp_enc, "random-key", TRUE, NULL);
g_signal_connect (self->bin.dtls_element, "notify::connection-state",
G_CALLBACK (on_connection_state_changed), self);
g_object_bind_property (G_OBJECT (self), "key", self->srtp_enc, "key",
G_BINDING_DEFAULT);
g_object_bind_property_full (G_OBJECT (self), "srtp-cipher", self->srtp_enc,
......@@ -289,6 +310,10 @@ gst_dtls_srtp_enc_get_property (GObject * object,
"tried to get is-client after disabling DTLS");
}
break;
case PROP_CONNECTION_STATE:
g_object_get_property (G_OBJECT (self->bin.dtls_element),
"connection-state", value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment