Release 1.16.2
[platform/upstream/gst-plugins-good.git] / gst / rtsp / gstrtspsrc.h
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *               <2006> Wim Taymans <wim@fluendo.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 /*
21  * Unless otherwise indicated, Source Code is licensed under MIT license.
22  * See further explanation attached in License Statement (distributed in the file
23  * LICENSE).
24  *
25  * Permission is hereby granted, free of charge, to any person obtaining a copy of
26  * this software and associated documentation files (the "Software"), to deal in
27  * the Software without restriction, including without limitation the rights to
28  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
29  * of the Software, and to permit persons to whom the Software is furnished to do
30  * so, subject to the following conditions:
31  *
32  * The above copyright notice and this permission notice shall be included in all
33  * copies or substantial portions of the Software.
34  *
35  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41  * SOFTWARE.
42  */
43
44 #ifndef __GST_RTSPSRC_H__
45 #define __GST_RTSPSRC_H__
46
47 #include <gst/gst.h>
48
49 G_BEGIN_DECLS
50
51 #include <gst/rtsp/rtsp.h>
52 #include <gio/gio.h>
53
54 #include "gstrtspext.h"
55
56 #define GST_TYPE_RTSPSRC \
57   (gst_rtspsrc_get_type())
58 #define GST_RTSPSRC(obj) \
59   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RTSPSRC,GstRTSPSrc))
60 #define GST_RTSPSRC_CLASS(klass) \
61   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RTSPSRC,GstRTSPSrcClass))
62 #define GST_IS_RTSPSRC(obj) \
63   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTSPSRC))
64 #define GST_IS_RTSPSRC_CLASS(klass) \
65   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTSPSRC))
66 #define GST_RTSPSRC_CAST(obj) \
67   ((GstRTSPSrc *)(obj))
68
69 typedef struct _GstRTSPSrc GstRTSPSrc;
70 typedef struct _GstRTSPSrcClass GstRTSPSrcClass;
71
72 #define GST_RTSP_STATE_GET_LOCK(rtsp)    (&GST_RTSPSRC_CAST(rtsp)->state_rec_lock)
73 #define GST_RTSP_STATE_LOCK(rtsp)        (g_rec_mutex_lock (GST_RTSP_STATE_GET_LOCK(rtsp)))
74 #define GST_RTSP_STATE_UNLOCK(rtsp)      (g_rec_mutex_unlock (GST_RTSP_STATE_GET_LOCK(rtsp)))
75
76 #define GST_RTSP_STREAM_GET_LOCK(rtsp)   (&GST_RTSPSRC_CAST(rtsp)->stream_rec_lock)
77 #define GST_RTSP_STREAM_LOCK(rtsp)       (g_rec_mutex_lock (GST_RTSP_STREAM_GET_LOCK(rtsp)))
78 #define GST_RTSP_STREAM_UNLOCK(rtsp)     (g_rec_mutex_unlock (GST_RTSP_STREAM_GET_LOCK(rtsp)))
79
80 typedef struct _GstRTSPConnInfo GstRTSPConnInfo;
81
82 struct _GstRTSPConnInfo {
83   gchar              *location;
84   GstRTSPUrl         *url;
85   gchar              *url_str;
86   GstRTSPConnection  *connection;
87   gboolean            connected;
88   gboolean            flushing;
89
90   GMutex              send_lock;
91   GMutex              recv_lock;
92 };
93
94 typedef struct _GstRTSPStream GstRTSPStream;
95
96 struct _GstRTSPStream {
97   gint          id;
98
99   GstRTSPSrc   *parent; /* parent, no extra ref to parent is taken */
100
101   /* pad we expose or NULL when it does not have an actual pad */
102   GstPad       *srcpad;
103   GstFlowReturn last_ret;
104   gboolean      added;
105   gboolean      setup;
106   gboolean      skipped;
107   gboolean      eos;
108   gboolean      discont;
109   gboolean      need_caps;
110   gboolean      waiting_setup_response;
111
112   /* for interleaved mode */
113   guint8        channel[2];
114   GstPad       *channelpad[2];
115
116   /* our udp sources */
117   GstElement   *udpsrc[2];
118   GstPad       *blockedpad;
119   gulong        blockid;
120   gboolean      is_ipv6;
121
122   /* our udp sinks back to the server */
123   GstElement   *udpsink[2];
124   GstPad       *rtcppad;
125
126   /* fakesrc for sending dummy data or appsrc for sending backchannel data */
127   GstElement   *rtpsrc;
128
129   /* state */
130   guint         port;
131   gboolean      container;
132   gboolean      is_real;
133   guint8        default_pt;
134   GstRTSPProfile profile;
135   GArray       *ptmap;
136   /* original control url */
137   gchar        *control_url;
138   guint32       ssrc;
139   guint32       seqbase;
140   guint64       timebase;
141   GstElement   *srtpdec;
142   GstCaps      *srtcpparams;
143   GstElement   *srtpenc;
144   guint32       send_ssrc;
145
146   /* per stream connection */
147   GstRTSPConnInfo  conninfo;
148
149   /* session */
150   GObject      *session;
151
152   /* srtp key management */
153   GstMIKEYMessage *mikey;
154
155   /* bandwidth */
156   guint         as_bandwidth;
157   guint         rs_bandwidth;
158   guint         rr_bandwidth;
159
160   /* destination */
161   gchar        *destination;
162   gboolean      is_multicast;
163   guint         ttl;
164   gboolean      is_backchannel;
165
166   /* A unique and stable id we will use for the stream start event */
167   gchar *stream_id;
168
169   GstStructure     *rtx_pt_map;
170
171   guint32       segment_seqnum[2];
172 };
173
174 /**
175  * GstRTSPSrcTimeoutCause:
176  * @GST_RTSP_SRC_TIMEOUT_CAUSE_RTCP: timeout triggered by RTCP
177  *
178  * Different causes to why the rtspsrc generated the GstRTSPSrcTimeout
179  * message.
180  */
181 typedef enum
182 {
183   GST_RTSP_SRC_TIMEOUT_CAUSE_RTCP
184 } GstRTSPSrcTimeoutCause;
185
186 /**
187  * GstRTSPNatMethod:
188  * @GST_RTSP_NAT_NONE: none
189  * @GST_RTSP_NAT_DUMMY: send dummy packets
190  *
191  * Different methods for trying to traverse firewalls.
192  */
193 typedef enum
194 {
195   GST_RTSP_NAT_NONE,
196   GST_RTSP_NAT_DUMMY
197 } GstRTSPNatMethod;
198
199
200 struct _GstRTSPSrc {
201   GstBin           parent;
202
203   /* task and mutex for interleaved mode */
204   gboolean         interleaved;
205   GstTask         *task;
206   GRecMutex        stream_rec_lock;
207   GstSegment       segment;
208   gboolean         running;
209   gboolean         need_range;
210   gboolean         skip;
211   gint             free_channel;
212   gboolean         need_segment;
213   GstClockTime     base_time;
214
215   /* UDP mode loop */
216   gint             pending_cmd;
217   gint             busy_cmd;
218   GCond            cmd_cond;
219   gboolean         ignore_timeout;
220   gboolean         open_error;
221
222   /* mutex for protecting state changes */
223   GRecMutex        state_rec_lock;
224
225   GstSDPMessage   *sdp;
226   gboolean         from_sdp;
227   GList           *streams;
228   GstStructure    *props;
229   gboolean         need_activate;
230
231   /* properties */
232   GstRTSPLowerTrans protocols;
233   gboolean          debug;
234   guint             retry;
235   guint64           udp_timeout;
236   GTimeVal          tcp_timeout;
237   GTimeVal         *ptcp_timeout;
238   guint             latency;
239   gboolean          drop_on_latency;
240   guint64           connection_speed;
241   GstRTSPNatMethod  nat_method;
242   gboolean          do_rtcp;
243   gboolean          do_rtsp_keep_alive;
244   gchar            *proxy_host;
245   guint             proxy_port;
246   gchar            *proxy_user;        /* from url or property */
247   gchar            *proxy_passwd;      /* from url or property */
248   gchar            *prop_proxy_id;     /* set via property */
249   gchar            *prop_proxy_pw;     /* set via property */
250   guint             rtp_blocksize;
251   gchar            *user_id;
252   gchar            *user_pw;
253   gint              buffer_mode;
254   GstRTSPRange      client_port_range;
255   gint              udp_buffer_size;
256   gboolean          short_header;
257   guint             probation;
258   gboolean          udp_reconnect;
259   gchar            *multi_iface;
260   gboolean          ntp_sync;
261   gboolean          use_pipeline_clock;
262   GstStructure     *sdes;
263   GTlsCertificateFlags tls_validation_flags;
264   GTlsDatabase     *tls_database;
265   GTlsInteraction  *tls_interaction;
266   gboolean          do_retransmission;
267   gint              ntp_time_source;
268   gchar            *user_agent;
269   GstClockTime      max_rtcp_rtp_time_diff;
270   gboolean          rfc7273_sync;
271   guint64           max_ts_offset_adjustment;
272   gint64            max_ts_offset;
273   gboolean          max_ts_offset_is_set;
274   gint              backchannel;
275   GstClockTime      teardown_timeout;
276
277   /* state */
278   GstRTSPState       state;
279   gchar             *content_base;
280   GstRTSPLowerTrans  cur_protocols;
281   gboolean           tried_url_auth;
282   gchar             *addr;
283   gboolean           need_redirect;
284   GstRTSPTimeRange  *range;
285   gchar             *control;
286   guint              next_port_num;
287   GstClock          *provided_clock;
288
289   /* supported methods */
290   gint               methods;
291
292   /* seekability
293    * -1.0 : Stream is not seekable
294    *  0.0 : seekable only to the beginning
295    * G_MAXFLOAT : Any value is possible
296    *
297    * Any other positive value indicates the longest duration
298    * between any two random access points
299    *  */
300   gfloat             seekable;
301   GstClockTime       last_pos;
302
303   /* session management */
304   GstElement      *manager;
305   gulong           manager_sig_id;
306   gulong           manager_ptmap_id;
307   gboolean         use_buffering;
308
309   GstRTSPConnInfo  conninfo;
310
311   /* SET/GET PARAMETER requests queue */
312   GQueue set_get_param_q;
313
314   /* a list of RTSP extensions as GstElement */
315   GstRTSPExtensionList  *extensions;
316
317   GstRTSPVersion default_version;
318   GstRTSPVersion version;
319 };
320
321 struct _GstRTSPSrcClass {
322   GstBinClass parent_class;
323
324  /* action signals */
325   gboolean (*get_parameter) (GstRTSPSrc *rtsp, const gchar *parameter, const gchar *content_type, GstPromise *promise);
326   gboolean (*get_parameters) (GstRTSPSrc *rtsp, gchar **parameters, const gchar *content_type, GstPromise *promise);
327   gboolean (*set_parameter) (GstRTSPSrc *rtsp, const gchar *name, const gchar *value, const gchar *content_type, GstPromise *promise);
328   GstFlowReturn (*push_backchannel_buffer) (GstRTSPSrc *src, guint id, GstSample *sample);
329 };
330
331 GType gst_rtspsrc_get_type(void);
332
333 G_END_DECLS
334
335 #endif /* __GST_RTSPSRC_H__ */