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 /**
21 * SECTION:gstwebrtc-sessiondescription
22 * @short_description: RTCSessionDescription object
23 * @title: GstWebRTCSessionDescription
24 *
25 * <https://www.w3.org/TR/webrtc/#rtcsessiondescription-class>
26 */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include "rtcsessiondescription.h"
33
34 #define GST_CAT_DEFAULT gst_webrtc_peerconnection_debug
35 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
36
37 /**
38 * gst_webrtc_sdp_type_to_string:
39 * @type: a #GstWebRTCSDPType
40 *
41 * Returns: the string representation of @type or "unknown" when @type is not
42 * recognized.
43 */
44 const gchar *
gst_webrtc_sdp_type_to_string(GstWebRTCSDPType type)45 gst_webrtc_sdp_type_to_string (GstWebRTCSDPType type)
46 {
47 switch (type) {
48 case GST_WEBRTC_SDP_TYPE_OFFER:
49 return "offer";
50 case GST_WEBRTC_SDP_TYPE_PRANSWER:
51 return "pranswer";
52 case GST_WEBRTC_SDP_TYPE_ANSWER:
53 return "answer";
54 case GST_WEBRTC_SDP_TYPE_ROLLBACK:
55 return "rollback";
56 default:
57 return "unknown";
58 }
59 }
60
61 /**
62 * gst_webrtc_session_description_copy:
63 * @src: (transfer none): a #GstWebRTCSessionDescription
64 *
65 * Returns: (transfer full): a new copy of @src
66 */
67 GstWebRTCSessionDescription *
gst_webrtc_session_description_copy(const GstWebRTCSessionDescription * src)68 gst_webrtc_session_description_copy (const GstWebRTCSessionDescription * src)
69 {
70 GstWebRTCSessionDescription *ret;
71
72 if (!src)
73 return NULL;
74
75 ret = g_new0 (GstWebRTCSessionDescription, 1);
76
77 ret->type = src->type;
78 gst_sdp_message_copy (src->sdp, &ret->sdp);
79
80 return ret;
81 }
82
83 /**
84 * gst_webrtc_session_description_free:
85 * @desc: (transfer full): a #GstWebRTCSessionDescription
86 *
87 * Free @desc and all associated resources
88 */
89 void
gst_webrtc_session_description_free(GstWebRTCSessionDescription * desc)90 gst_webrtc_session_description_free (GstWebRTCSessionDescription * desc)
91 {
92 g_return_if_fail (desc != NULL);
93
94 gst_sdp_message_free (desc->sdp);
95 g_free (desc);
96 }
97
98 /**
99 * gst_webrtc_session_description_new:
100 * @type: a #GstWebRTCSDPType
101 * @sdp: (transfer full): a #GstSDPMessage
102 *
103 * Returns: (transfer full): a new #GstWebRTCSessionDescription from @type
104 * and @sdp
105 */
106 GstWebRTCSessionDescription *
gst_webrtc_session_description_new(GstWebRTCSDPType type,GstSDPMessage * sdp)107 gst_webrtc_session_description_new (GstWebRTCSDPType type, GstSDPMessage * sdp)
108 {
109 GstWebRTCSessionDescription *ret;
110
111 ret = g_new0 (GstWebRTCSessionDescription, 1);
112
113 ret->type = type;
114 ret->sdp = sdp;
115
116 return ret;
117 }
118
119 G_DEFINE_BOXED_TYPE_WITH_CODE (GstWebRTCSessionDescription,
120 gst_webrtc_session_description, gst_webrtc_session_description_copy,
121 gst_webrtc_session_description_free,
122 GST_DEBUG_CATEGORY_INIT (gst_webrtc_peerconnection_debug,
123 "webrtcsessiondescription", 0, "webrtcsessiondescription"));
124