49d95c38a9ec42168827f8a200171e7ec0ecc606
[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
111   /* for interleaved mode */
112   guint8        channel[2];
113   GstPad       *channelpad[2];
114
115   /* our udp sources */
116   GstElement   *udpsrc[2];
117   GstPad       *blockedpad;
118   gulong        blockid;
119   gboolean      is_ipv6;
120
121   /* our udp sinks back to the server */
122   GstElement   *udpsink[2];
123   GstPad       *rtcppad;
124
125   /* fakesrc for sending dummy data */
126   GstElement   *fakesrc;
127
128   /* state */
129   guint         port;
130   gboolean      container;
131   gboolean      is_real;
132   guint8        default_pt;
133   GstRTSPProfile profile;
134   GArray       *ptmap;
135   /* original control url */
136   gchar        *control_url;
137   guint32       ssrc;
138   guint32       seqbase;
139   guint64       timebase;
140   GstElement   *srtpdec;
141   GstCaps      *srtcpparams;
142   GstElement   *srtpenc;
143   guint32       send_ssrc;
144
145   /* per stream connection */
146   GstRTSPConnInfo  conninfo;
147
148   /* session */
149   GObject      *session;
150
151   /* srtp key management */
152   GstMIKEYMessage *mikey;
153
154   /* bandwidth */
155   guint         as_bandwidth;
156   guint         rs_bandwidth;
157   guint         rr_bandwidth;
158
159   /* destination */
160   gchar        *destination;
161   gboolean      is_multicast;
162   guint         ttl;
163
164   GstStructure     *rtx_pt_map;
165 };
166
167 /**
168  * GstRTSPNatMethod:
169  * @GST_RTSP_NAT_NONE: none
170  * @GST_RTSP_NAT_DUMMY: send dummy packets
171  *
172  * Different methods for trying to traverse firewalls.
173  */
174 typedef enum
175 {
176   GST_RTSP_NAT_NONE,
177   GST_RTSP_NAT_DUMMY
178 } GstRTSPNatMethod;
179
180 struct _GstRTSPSrc {
181   GstBin           parent;
182
183   /* task and mutex for interleaved mode */
184   gboolean         interleaved;
185   GstTask         *task;
186   GRecMutex        stream_rec_lock;
187   GstSegment       segment;
188   gboolean         running;
189   gboolean         need_range;
190   gboolean         skip;
191   gint             free_channel;
192   gboolean         need_segment;
193   GstClockTime     base_time;
194
195   /* UDP mode loop */
196   gint             pending_cmd;
197   gint             busy_cmd;
198   gboolean         ignore_timeout;
199   gboolean         open_error;
200
201   /* mutex for protecting state changes */
202   GRecMutex        state_rec_lock;
203
204   GstSDPMessage   *sdp;
205   gboolean         from_sdp;
206   GList           *streams;
207   GstStructure    *props;
208   gboolean         need_activate;
209
210   /* properties */
211   GstRTSPLowerTrans protocols;
212   gboolean          debug;
213   guint             retry;
214   guint64           udp_timeout;
215   GTimeVal          tcp_timeout;
216   GTimeVal         *ptcp_timeout;
217   guint             latency;
218   gboolean          drop_on_latency;
219   guint64           connection_speed;
220   GstRTSPNatMethod  nat_method;
221   gboolean          do_rtcp;
222   gboolean          do_rtsp_keep_alive;
223   gchar            *proxy_host;
224   guint             proxy_port;
225   gchar            *proxy_user;        /* from url or property */
226   gchar            *proxy_passwd;      /* from url or property */
227   gchar            *prop_proxy_id;     /* set via property */
228   gchar            *prop_proxy_pw;     /* set via property */
229   guint             rtp_blocksize;
230   gchar            *user_id;
231   gchar            *user_pw;
232   gint              buffer_mode;
233   GstRTSPRange      client_port_range;
234   gint              udp_buffer_size;
235   gboolean          short_header;
236   guint             probation;
237   gboolean          udp_reconnect;
238   gchar            *multi_iface;
239   gboolean          ntp_sync;
240   gboolean          use_pipeline_clock;
241   GstStructure     *sdes;
242   GTlsCertificateFlags tls_validation_flags;
243   GTlsDatabase     *tls_database;
244   GTlsInteraction  *tls_interaction;
245   gboolean          do_retransmission;
246   gint              ntp_time_source;
247   gchar            *user_agent;
248   GstClockTime      max_rtcp_rtp_time_diff;
249   gboolean          rfc7273_sync;
250
251   /* state */
252   GstRTSPState       state;
253   gchar             *content_base;
254   GstRTSPLowerTrans  cur_protocols;
255   gboolean           tried_url_auth;
256   gchar             *addr;
257   gboolean           need_redirect;
258   GstRTSPTimeRange  *range;
259   gchar             *control;
260   guint              next_port_num;
261   GstClock          *provided_clock;
262
263   /* supported methods */
264   gint               methods;
265
266   gboolean           seekable;
267   GstClockTime       last_pos;
268
269   /* session management */
270   GstElement      *manager;
271   gulong           manager_sig_id;
272   gulong           manager_ptmap_id;
273   gboolean         use_buffering;
274
275   GstRTSPConnInfo  conninfo;
276
277   /* a list of RTSP extensions as GstElement */
278   GstRTSPExtensionList  *extensions;
279 };
280
281 struct _GstRTSPSrcClass {
282   GstBinClass parent_class;
283 };
284
285 GType gst_rtspsrc_get_type(void);
286
287 G_END_DECLS
288
289 #endif /* __GST_RTSPSRC_H__ */