1 /* GStreamer
2 * Copyright (C) 2017 Matthew Waters <matthew@centricular.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #endif
23
24 #include "utils.h"
25 #include "gstwebrtcbin.h"
26
27 GQuark
gst_webrtc_bin_error_quark(void)28 gst_webrtc_bin_error_quark (void)
29 {
30 return g_quark_from_static_string ("gst-webrtc-bin-error-quark");
31 }
32
33 GstPadTemplate *
_find_pad_template(GstElement * element,GstPadDirection direction,GstPadPresence presence,const gchar * name)34 _find_pad_template (GstElement * element, GstPadDirection direction,
35 GstPadPresence presence, const gchar * name)
36 {
37 GstElementClass *element_class = GST_ELEMENT_GET_CLASS (element);
38 const GList *l = gst_element_class_get_pad_template_list (element_class);
39 GstPadTemplate *templ = NULL;
40
41 for (; l; l = l->next) {
42 templ = l->data;
43 if (templ->direction != direction)
44 continue;
45 if (templ->presence != presence)
46 continue;
47 if (g_strcmp0 (templ->name_template, name) == 0) {
48 return templ;
49 }
50 }
51
52 return NULL;
53 }
54
55 GstSDPMessage *
_get_latest_sdp(GstWebRTCBin * webrtc)56 _get_latest_sdp (GstWebRTCBin * webrtc)
57 {
58 if (webrtc->current_local_description &&
59 webrtc->current_local_description->type == GST_WEBRTC_SDP_TYPE_ANSWER) {
60 return webrtc->current_local_description->sdp;
61 }
62 if (webrtc->current_remote_description &&
63 webrtc->current_remote_description->type == GST_WEBRTC_SDP_TYPE_ANSWER) {
64 return webrtc->current_remote_description->sdp;
65 }
66 if (webrtc->current_local_description &&
67 webrtc->current_local_description->type == GST_WEBRTC_SDP_TYPE_OFFER) {
68 return webrtc->current_local_description->sdp;
69 }
70 if (webrtc->current_remote_description &&
71 webrtc->current_remote_description->type == GST_WEBRTC_SDP_TYPE_OFFER) {
72 return webrtc->current_remote_description->sdp;
73 }
74
75 return NULL;
76 }
77
78 struct pad_block *
_create_pad_block(GstElement * element,GstPad * pad,gulong block_id,gpointer user_data,GDestroyNotify notify)79 _create_pad_block (GstElement * element, GstPad * pad, gulong block_id,
80 gpointer user_data, GDestroyNotify notify)
81 {
82 struct pad_block *ret = g_new0 (struct pad_block, 1);
83
84 ret->element = gst_object_ref (element);
85 ret->pad = gst_object_ref (pad);
86 ret->block_id = block_id;
87 ret->user_data = user_data;
88 ret->notify = notify;
89
90 return ret;
91 }
92
93 void
_free_pad_block(struct pad_block * block)94 _free_pad_block (struct pad_block *block)
95 {
96 if (!block)
97 return;
98
99 if (block->block_id)
100 gst_pad_remove_probe (block->pad, block->block_id);
101 gst_object_unref (block->element);
102 gst_object_unref (block->pad);
103 if (block->notify)
104 block->notify (block->user_data);
105 g_free (block);
106 }
107
108 gchar *
_enum_value_to_string(GType type,guint value)109 _enum_value_to_string (GType type, guint value)
110 {
111 GEnumClass *enum_class;
112 GEnumValue *enum_value;
113 gchar *str = NULL;
114
115 enum_class = g_type_class_ref (type);
116 enum_value = g_enum_get_value (enum_class, value);
117
118 if (enum_value)
119 str = g_strdup (enum_value->value_nick);
120
121 g_type_class_unref (enum_class);
122
123 return str;
124 }
125
126 const gchar *
_g_checksum_to_webrtc_string(GChecksumType type)127 _g_checksum_to_webrtc_string (GChecksumType type)
128 {
129 switch (type) {
130 case G_CHECKSUM_SHA1:
131 return "sha-1";
132 case G_CHECKSUM_SHA256:
133 return "sha-256";
134 #ifdef G_CHECKSUM_SHA384
135 case G_CHECKSUM_SHA384:
136 return "sha-384";
137 #endif
138 case G_CHECKSUM_SHA512:
139 return "sha-512";
140 default:
141 g_warning ("unknown GChecksumType!");
142 return NULL;
143 }
144 }
145