• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2014, Ericsson AB. All rights reserved.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
19  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
24  * OF SUCH DAMAGE.
25  */
26 
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30 
31 #include "gstdtlssrtpbin.h"
32 
33 #define gst_dtls_srtp_bin_parent_class parent_class
34 G_DEFINE_ABSTRACT_TYPE (GstDtlsSrtpBin, gst_dtls_srtp_bin, GST_TYPE_BIN);
35 
36 enum
37 {
38   PROP_0,
39   PROP_CONNECTION_ID,
40   PROP_KEY,
41   PROP_SRTP_AUTH,
42   PROP_SRTP_CIPHER,
43   PROP_SRTCP_AUTH,
44   PROP_SRTCP_CIPHER,
45   NUM_PROPERTIES
46 };
47 
48 static GParamSpec *properties[NUM_PROPERTIES];
49 
50 #define DEFAULT_CONNECTION_ID NULL
51 #define DEFAULT_KEY NULL
52 #define DEFAULT_SRTP_AUTH NULL
53 #define DEFAULT_SRTP_CIPHER NULL
54 #define DEFAULT_SRTCP_AUTH NULL
55 #define DEFAULT_SRTCP_CIPHER NULL
56 
57 static void gst_dtls_srtp_bin_finalize (GObject *);
58 static void gst_dtls_srtp_bin_set_property (GObject *, guint prop_id,
59     const GValue *, GParamSpec *);
60 static void gst_dtls_srtp_bin_get_property (GObject *, guint prop_id,
61     GValue *, GParamSpec *);
62 
63 static void
gst_dtls_srtp_bin_class_init(GstDtlsSrtpBinClass * klass)64 gst_dtls_srtp_bin_class_init (GstDtlsSrtpBinClass * klass)
65 {
66   GObjectClass *gobject_class;
67 
68   gobject_class = (GObjectClass *) klass;
69 
70   gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_dtls_srtp_bin_finalize);
71   gobject_class->set_property =
72       GST_DEBUG_FUNCPTR (gst_dtls_srtp_bin_set_property);
73   gobject_class->get_property =
74       GST_DEBUG_FUNCPTR (gst_dtls_srtp_bin_get_property);
75 
76   klass->remove_dtls_element = NULL;
77 
78   properties[PROP_CONNECTION_ID] =
79       g_param_spec_string ("connection-id",
80       "Connection id",
81       "Every encoder/decoder pair should have the same, unique, connection-id",
82       DEFAULT_CONNECTION_ID, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
83 
84   properties[PROP_KEY] =
85       g_param_spec_boxed ("key",
86       "Key",
87       "SRTP master key, if this property is set, DTLS will be disabled",
88       GST_TYPE_BUFFER,
89       G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_STATIC_STRINGS);
90 
91   properties[PROP_SRTP_CIPHER] =
92       g_param_spec_string ("srtp-cipher",
93       "SRTP Cipher",
94       "SRTP cipher name, should be 'null' or 'aes-128-icm', "
95       "if this property is set, DTLS will be disabled",
96       DEFAULT_SRTP_CIPHER,
97       G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_STATIC_STRINGS);
98 
99   properties[PROP_SRTCP_CIPHER] =
100       g_param_spec_string ("srtcp-cipher",
101       "SRTCP Cipher",
102       "SRTCP cipher name, should be 'null' or 'aes-128-icm', "
103       "if this property is set, DTLS will be disabled",
104       DEFAULT_SRTCP_CIPHER,
105       G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_STATIC_STRINGS);
106 
107   properties[PROP_SRTP_AUTH] =
108       g_param_spec_string ("srtp-auth",
109       "SRTP Auth",
110       "SRTP auth name, should be 'null', 'hmac-sha1-32' or 'hmac-sha1-80', "
111       "if this property is set, DTLS will be disabled",
112       DEFAULT_SRTP_AUTH,
113       G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_STATIC_STRINGS);
114 
115   properties[PROP_SRTCP_AUTH] =
116       g_param_spec_string ("srtcp-auth",
117       "SRTCP Auth",
118       "SRTCP auth name, should be 'null', 'hmac-sha1-32' or 'hmac-sha1-80', "
119       "if this property is set, DTLS will be disabled",
120       DEFAULT_SRTCP_AUTH,
121       G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_STATIC_STRINGS);
122 
123   g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
124 }
125 
126 static void
gst_dtls_srtp_bin_init(GstDtlsSrtpBin * self)127 gst_dtls_srtp_bin_init (GstDtlsSrtpBin * self)
128 {
129   self->key = NULL;
130   self->key_is_set = FALSE;
131   self->srtp_auth = NULL;
132   self->srtp_cipher = NULL;
133   self->srtcp_auth = NULL;
134   self->srtcp_cipher = NULL;
135 }
136 
137 static void
gst_dtls_srtp_bin_finalize(GObject * object)138 gst_dtls_srtp_bin_finalize (GObject * object)
139 {
140   GstDtlsSrtpBin *self = GST_DTLS_SRTP_BIN (object);
141 
142   if (self->key) {
143     gst_buffer_unref (self->key);
144     self->key = NULL;
145   }
146   g_free (self->srtp_auth);
147   self->srtp_auth = NULL;
148   g_free (self->srtp_cipher);
149   self->srtp_cipher = NULL;
150   g_free (self->srtcp_auth);
151   self->srtcp_auth = NULL;
152   g_free (self->srtcp_cipher);
153   self->srtcp_cipher = NULL;
154 
155   G_OBJECT_CLASS (parent_class)->finalize (object);
156 }
157 
158 static void
gst_dtls_srtp_bin_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)159 gst_dtls_srtp_bin_set_property (GObject * object,
160     guint prop_id, const GValue * value, GParamSpec * pspec)
161 {
162   GstDtlsSrtpBin *self = GST_DTLS_SRTP_BIN (object);
163   GstDtlsSrtpBinClass *klass = GST_DTLS_SRTP_BIN_GET_CLASS (self);
164 
165   switch (prop_id) {
166     case PROP_CONNECTION_ID:
167       if (self->dtls_element) {
168         g_object_set_property (G_OBJECT (self->dtls_element), "connection-id",
169             value);
170       } else {
171         g_warning ("tried to set connection-id after disabling DTLS");
172       }
173       break;
174     case PROP_KEY:
175       if (self->key) {
176         gst_buffer_unref (self->key);
177       }
178       self->key = g_value_dup_boxed (value);
179       self->key_is_set = TRUE;
180       klass->remove_dtls_element (self);
181       break;
182     case PROP_SRTP_AUTH:
183       g_free (self->srtp_auth);
184       self->srtp_auth = g_value_dup_string (value);
185       klass->remove_dtls_element (self);
186       break;
187     case PROP_SRTP_CIPHER:
188       g_free (self->srtp_cipher);
189       self->srtp_cipher = g_value_dup_string (value);
190       klass->remove_dtls_element (self);
191       break;
192     case PROP_SRTCP_AUTH:
193       g_free (self->srtcp_auth);
194       self->srtcp_auth = g_value_dup_string (value);
195       klass->remove_dtls_element (self);
196       break;
197     case PROP_SRTCP_CIPHER:
198       g_free (self->srtcp_cipher);
199       self->srtcp_cipher = g_value_dup_string (value);
200       klass->remove_dtls_element (self);
201       break;
202     default:
203       G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
204   }
205 }
206 
207 static void
gst_dtls_srtp_bin_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)208 gst_dtls_srtp_bin_get_property (GObject * object,
209     guint prop_id, GValue * value, GParamSpec * pspec)
210 {
211   GstDtlsSrtpBin *self = GST_DTLS_SRTP_BIN (object);
212 
213   switch (prop_id) {
214     case PROP_CONNECTION_ID:
215       if (self->dtls_element) {
216         g_object_get_property (G_OBJECT (self->dtls_element), "connection-id",
217             value);
218       } else {
219         g_warning ("tried to get connection-id after disabling DTLS");
220       }
221       break;
222     case PROP_KEY:
223       if (self->key) {
224         g_value_set_boxed (value, self->key);
225       }
226       break;
227     case PROP_SRTP_AUTH:
228       g_value_set_string (value, self->srtp_auth);
229       break;
230     case PROP_SRTP_CIPHER:
231       g_value_set_string (value, self->srtp_cipher);
232       break;
233     case PROP_SRTCP_AUTH:
234       g_value_set_string (value, self->srtcp_auth);
235       break;
236     case PROP_SRTCP_CIPHER:
237       g_value_set_string (value, self->srtcp_cipher);
238       break;
239     default:
240       G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
241   }
242 }
243