webrtcbin: an element that handles the transport aspects of webrtc connections
[platform/upstream/gst-plugins-bad.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
27 G_BEGIN_DECLS
28
29 #define GST_WEBRTC_BIN_ERROR gst_webrtc_bin_error_quark ()
30 GQuark gst_webrtc_bin_error_quark (void);
31
32 typedef enum
33 {
34   GST_WEBRTC_BIN_ERROR_FAILED,
35   GST_WEBRTC_BIN_ERROR_INVALID_SYNTAX,
36   GST_WEBRTC_BIN_ERROR_INVALID_MODIFICATION,
37   GST_WEBRTC_BIN_ERROR_INVALID_STATE,
38   GST_WEBRTC_BIN_ERROR_BAD_SDP,
39   GST_WEBRTC_BIN_ERROR_FINGERPRINT,
40 } GstWebRTCJSEPSDPError;
41
42 GType gst_webrtc_bin_pad_get_type(void);
43 #define GST_TYPE_WEBRTC_BIN_PAD            (gst_webrtc_bin_pad_get_type())
44 #define GST_WEBRTC_BIN_PAD(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_WEBRTC_BIN_PAD,GstWebRTCBinPad))
45 #define GST_IS_WEBRTC_BIN_PAD(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_WEBRTC_BIN_PAD))
46 #define GST_WEBRTC_BIN_PAD_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass) ,GST_TYPE_WEBRTC_BIN_PAD,GstWebRTCBinPadClass))
47 #define GST_IS_WEBRTC_BIN_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) ,GST_TYPE_WEBRTC_BIN_PAD))
48 #define GST_WEBRTC_BIN_PAD_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_WEBRTC_BIN_PAD,GstWebRTCBinPadClass))
49
50 typedef struct _GstWebRTCBinPad GstWebRTCBinPad;
51 typedef struct _GstWebRTCBinPadClass GstWebRTCBinPadClass;
52
53 struct _GstWebRTCBinPad
54 {
55   GstGhostPad           parent;
56
57   guint                 mlineindex;
58
59   GstWebRTCRTPTransceiver *trans;
60 };
61
62 struct _GstWebRTCBinPadClass
63 {
64   GstGhostPadClass      parent_class;
65 };
66
67 GType gst_webrtc_bin_get_type(void);
68 #define GST_TYPE_WEBRTC_BIN            (gst_webrtc_bin_get_type())
69 #define GST_WEBRTC_BIN(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_WEBRTC_BIN,GstWebRTCBin))
70 #define GST_IS_WEBRTC_BIN(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_WEBRTC_BIN))
71 #define GST_WEBRTC_BIN_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass) ,GST_TYPE_WEBRTC_BIN,GstWebRTCBinClass))
72 #define GST_IS_WEBRTC_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) ,GST_TYPE_WEBRTC_BIN))
73 #define GST_WEBRTC_BIN_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_WEBRTC_BIN,GstWebRTCBinClass))
74
75 struct _GstWebRTCBin
76 {
77   GstBin                            parent;
78
79   GstElement                       *rtpbin;
80
81   GstWebRTCSignalingState           signaling_state;
82   GstWebRTCICEGatheringState        ice_gathering_state;
83   GstWebRTCICEConnectionState       ice_connection_state;
84   GstWebRTCPeerConnectionState      peer_connection_state;
85
86   GstWebRTCSessionDescription      *current_local_description;
87   GstWebRTCSessionDescription      *pending_local_description;
88   GstWebRTCSessionDescription      *current_remote_description;
89   GstWebRTCSessionDescription      *pending_remote_description;
90
91   GstWebRTCBinPrivate              *priv;
92 };
93
94 struct _GstWebRTCBinClass
95 {
96   GstBinClass           parent_class;
97 };
98
99 struct _GstWebRTCBinPrivate
100 {
101   guint max_sink_pad_serial;
102
103   gboolean bundle;
104   GArray *transceivers;
105   GArray *session_mid_map;
106   GArray *transports;
107
108   GstWebRTCICE *ice;
109   GArray *ice_stream_map;
110   GArray *pending_ice_candidates;
111
112   /* peerconnection variables */
113   gboolean is_closed;
114   gboolean need_negotiation;
115   gpointer sctp_transport;      /* FIXME */
116
117   /* peerconnection helper thread for promises */
118   GMainContext *main_context;
119   GMainLoop *loop;
120   GThread *thread;
121   GMutex pc_lock;
122   GCond pc_cond;
123
124   gboolean running;
125   gboolean async_pending;
126
127   GList *pending_pads;
128
129   /* count of the number of media streams we've offered for uniqueness */
130   /* FIXME: overflow? */
131   guint media_counter;
132
133   GstStructure *stats;
134 };
135
136 typedef void (*GstWebRTCBinFunc) (GstWebRTCBin * webrtc, gpointer data);
137
138 typedef struct
139 {
140   GstWebRTCBin *webrtc;
141   GstWebRTCBinFunc op;
142   gpointer data;
143   GDestroyNotify notify;
144 //  GstPromise *promise;      /* FIXME */
145 } GstWebRTCBinTask;
146
147 void            gst_webrtc_bin_enqueue_task             (GstWebRTCBin * pc,
148                                                          GstWebRTCBinFunc func,
149                                                          gpointer data,
150                                                          GDestroyNotify notify);
151
152 G_END_DECLS
153
154 #endif /* __GST_WEBRTC_BIN_H__ */