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 #ifndef __GST_WEBRTC_BIN_H__ 21 #define __GST_WEBRTC_BIN_H__ 22 23 #include <gst/sdp/sdp.h> 24 #include "fwd.h" 25 #include "gstwebrtcice.h" 26 #include "transportstream.h" 27 #include "webrtcsctptransport.h" 28 29 G_BEGIN_DECLS 30 31 GType gst_webrtc_bin_pad_get_type(void); 32 #define GST_TYPE_WEBRTC_BIN_PAD (gst_webrtc_bin_pad_get_type()) 33 #define GST_WEBRTC_BIN_PAD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_WEBRTC_BIN_PAD,GstWebRTCBinPad)) 34 #define GST_IS_WEBRTC_BIN_PAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_WEBRTC_BIN_PAD)) 35 #define GST_WEBRTC_BIN_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass) ,GST_TYPE_WEBRTC_BIN_PAD,GstWebRTCBinPadClass)) 36 #define GST_IS_WEBRTC_BIN_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) ,GST_TYPE_WEBRTC_BIN_PAD)) 37 #define GST_WEBRTC_BIN_PAD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_WEBRTC_BIN_PAD,GstWebRTCBinPadClass)) 38 39 typedef struct _GstWebRTCBinPad GstWebRTCBinPad; 40 typedef struct _GstWebRTCBinPadClass GstWebRTCBinPadClass; 41 42 struct _GstWebRTCBinPad 43 { 44 GstGhostPad parent; 45 46 GstWebRTCRTPTransceiver *trans; 47 gulong block_id; 48 49 guint32 last_ssrc; 50 51 GstCaps *received_caps; 52 }; 53 54 struct _GstWebRTCBinPadClass 55 { 56 GstGhostPadClass parent_class; 57 }; 58 59 GType gst_webrtc_bin_get_type(void); 60 #define GST_TYPE_WEBRTC_BIN (gst_webrtc_bin_get_type()) 61 #define GST_WEBRTC_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_WEBRTC_BIN,GstWebRTCBin)) 62 #define GST_IS_WEBRTC_BIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_WEBRTC_BIN)) 63 #define GST_WEBRTC_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass) ,GST_TYPE_WEBRTC_BIN,GstWebRTCBinClass)) 64 #define GST_IS_WEBRTC_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) ,GST_TYPE_WEBRTC_BIN)) 65 #define GST_WEBRTC_BIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_WEBRTC_BIN,GstWebRTCBinClass)) 66 67 struct _GstWebRTCBin 68 { 69 GstBin parent; 70 71 GstElement *rtpbin; 72 GstElement *rtpfunnel; 73 74 GstWebRTCSignalingState signaling_state; 75 GstWebRTCICEGatheringState ice_gathering_state; 76 GstWebRTCICEConnectionState ice_connection_state; 77 GstWebRTCPeerConnectionState peer_connection_state; 78 79 GstWebRTCSessionDescription *current_local_description; 80 GstWebRTCSessionDescription *pending_local_description; 81 GstWebRTCSessionDescription *current_remote_description; 82 GstWebRTCSessionDescription *pending_remote_description; 83 84 GstWebRTCBundlePolicy bundle_policy; 85 GstWebRTCICETransportPolicy ice_transport_policy; 86 87 GstWebRTCBinPrivate *priv; 88 }; 89 90 struct _GstWebRTCBinClass 91 { 92 GstBinClass parent_class; 93 }; 94 95 struct _GstWebRTCBinPrivate 96 { 97 guint max_sink_pad_serial; 98 99 gboolean bundle; 100 GPtrArray *transceivers; 101 GPtrArray *transports; 102 GPtrArray *data_channels; 103 /* list of data channels we've received a sctp stream for but no data 104 * channel protocol for */ 105 GPtrArray *pending_data_channels; 106 /* dc_lock protects data_channels and pending_data_channels */ 107 /* lock ordering is pc_lock first, then dc_lock */ 108 GMutex dc_lock; 109 110 guint jb_latency; 111 112 WebRTCSCTPTransport *sctp_transport; 113 TransportStream *data_channel_transport; 114 115 GstWebRTCICE *ice; 116 GArray *ice_stream_map; 117 GMutex ice_lock; 118 GArray *pending_remote_ice_candidates; 119 GArray *pending_local_ice_candidates; 120 121 /* peerconnection variables */ 122 gboolean is_closed; 123 gboolean need_negotiation; 124 125 /* peerconnection helper thread for promises */ 126 GMainContext *main_context; 127 GMainLoop *loop; 128 GThread *thread; 129 GMutex pc_lock; 130 GCond pc_cond; 131 132 gboolean running; 133 gboolean async_pending; 134 135 GList *pending_pads; 136 GList *pending_sink_transceivers; 137 138 /* count of the number of media streams we've offered for uniqueness */ 139 /* FIXME: overflow? */ 140 guint media_counter; 141 /* the number of times create_offer has been called for the version field */ 142 guint offer_count; 143 GstWebRTCSessionDescription *last_generated_offer; 144 GstWebRTCSessionDescription *last_generated_answer; 145 146 gboolean tos_attached; 147 }; 148 149 typedef GstStructure *(*GstWebRTCBinFunc) (GstWebRTCBin * webrtc, gpointer data); 150 151 typedef struct 152 { 153 GstWebRTCBin *webrtc; 154 GstWebRTCBinFunc op; 155 gpointer data; 156 GDestroyNotify notify; 157 GstPromise *promise; 158 } GstWebRTCBinTask; 159 160 gboolean gst_webrtc_bin_enqueue_task (GstWebRTCBin * pc, 161 GstWebRTCBinFunc func, 162 gpointer data, 163 GDestroyNotify notify, 164 GstPromise *promise); 165 166 G_END_DECLS 167 168 #endif /* __GST_WEBRTC_BIN_H__ */ 169