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