1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *               <2006> Wim Taymans <wim@fluendo.com>
4  *               <2015> Jan Schmidt <jan at centricular dot com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 /*
22  * Unless otherwise indicated, Source Code is licensed under MIT license.
23  * See further explanation attached in License Statement (distributed in the file
24  * LICENSE).
25  *
26  * Permission is hereby granted, free of charge, to any person obtaining a copy of
27  * this software and associated documentation files (the "Software"), to deal in
28  * the Software without restriction, including without limitation the rights to
29  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
30  * of the Software, and to permit persons to whom the Software is furnished to do
31  * so, subject to the following conditions:
32  *
33  * The above copyright notice and this permission notice shall be included in all
34  * copies or substantial portions of the Software.
35  *
36  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
39  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
41  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
42  * SOFTWARE.
43  */
44 
45 #ifndef __GST_RTSP_CLIENT_SINK_H__
46 #define __GST_RTSP_CLIENT_SINK_H__
47 
48 #include <gst/gst.h>
49 
50 G_BEGIN_DECLS
51 
52 #include <gst/rtsp-server/rtsp-stream.h>
53 #include <gst/rtsp/rtsp.h>
54 #include <gio/gio.h>
55 
56 #define GST_TYPE_RTSP_CLIENT_SINK \
57   (gst_rtsp_client_sink_get_type())
58 #define GST_RTSP_CLIENT_SINK(obj) \
59   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RTSP_CLIENT_SINK,GstRTSPClientSink))
60 #define GST_RTSP_CLIENT_SINK_CLASS(klass) \
61   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RTSP_CLIENT_SINK,GstRTSPClientSinkClass))
62 #define GST_IS_RTSP_CLIENT_SINK(obj) \
63   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTSP_CLIENT_SINK))
64 #define GST_IS_RTSP_CLIENT_SINK_CLASS(klass) \
65   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTSP_CLIENT_SINK))
66 #define GST_RTSP_CLIENT_SINK_CAST(obj) \
67   ((GstRTSPClientSink *)(obj))
68 
69 typedef struct _GstRTSPClientSink GstRTSPClientSink;
70 typedef struct _GstRTSPClientSinkClass GstRTSPClientSinkClass;
71 
72 #define GST_RTSP_STATE_GET_LOCK(rtsp)    (&GST_RTSP_CLIENT_SINK_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_RTSP_CLIENT_SINK_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 _GstRTSPStreamInfo GstRTSPStreamInfo;
95 typedef struct _GstRTSPStreamContext GstRTSPStreamContext;
96 
97 struct _GstRTSPStreamContext {
98   GstRTSPClientSink *parent;
99 
100   guint index;
101   /* Index of the SDPMedia in the stored SDP */
102   guint sdp_index;
103 
104   GstElement *payloader;
105   guint payloader_block_id;
106   gboolean prerolled;
107 
108   /* Stream management object */
109   GstRTSPStream *stream;
110   gboolean joined;
111 
112   /* Secure profile key mgmt */
113   GstCaps      *srtcpparams;
114 
115   /* per stream connection */
116   GstRTSPConnInfo  conninfo;
117   /* For interleaved mode */
118   guint8        channel[2];
119 
120   GstRTSPStreamTransport *stream_transport;
121 
122   guint ulpfec_percentage;
123 };
124 
125 /**
126  * GstRTSPNatMethod:
127  * @GST_RTSP_NAT_NONE: none
128  * @GST_RTSP_NAT_DUMMY: send dummy packets
129  *
130  * Different methods for trying to traverse firewalls.
131  */
132 typedef enum
133 {
134   GST_RTSP_NAT_NONE,
135   GST_RTSP_NAT_DUMMY
136 } GstRTSPNatMethod;
137 
138 struct _GstRTSPClientSink {
139   GstBin           parent;
140 
141   /* task and mutex for interleaved mode */
142   gboolean         interleaved;
143   GstTask         *task;
144   GRecMutex        stream_rec_lock;
145   GstSegment       segment;
146   gint             free_channel;
147 
148   /* UDP mode loop */
149   gint             pending_cmd;
150   gint             busy_cmd;
151   gboolean         ignore_timeout;
152   gboolean         open_error;
153 
154   /* mutex for protecting state changes */
155   GRecMutex        state_rec_lock;
156 
157   GstSDPMessage    *uri_sdp;
158   gboolean         from_sdp;
159 
160   /* properties */
161   GstRTSPLowerTrans protocols;
162   gboolean          debug;
163   guint             retry;
164   guint64           udp_timeout;
165   GTimeVal          tcp_timeout;
166   GTimeVal         *ptcp_timeout;
167   guint             latency;
168   gboolean          do_rtsp_keep_alive;
169   gchar            *proxy_host;
170   guint             proxy_port;
171   gchar            *proxy_user;        /* from url or property */
172   gchar            *proxy_passwd;      /* from url or property */
173   gchar            *prop_proxy_id;     /* set via property */
174   gchar            *prop_proxy_pw;     /* set via property */
175   guint             rtp_blocksize;
176   gchar            *user_id;
177   gchar            *user_pw;
178   GstRTSPRange      client_port_range;
179   gint              udp_buffer_size;
180   gboolean          udp_reconnect;
181   gchar            *multi_iface;
182   gboolean          ntp_sync;
183   gboolean          use_pipeline_clock;
184   GstStructure     *sdes;
185   GTlsCertificateFlags tls_validation_flags;
186   GTlsDatabase     *tls_database;
187   GTlsInteraction  *tls_interaction;
188   gint              ntp_time_source;
189   gchar            *user_agent;
190 
191   /* state */
192   GstRTSPState       state;
193   gchar             *content_base;
194   GstRTSPLowerTrans  cur_protocols;
195   gboolean           tried_url_auth;
196   gchar             *addr;
197   gboolean           need_redirect;
198   GstRTSPTimeRange  *range;
199   gchar             *control;
200   guint              next_port_num;
201   GstClock          *provided_clock;
202 
203   /* supported methods */
204   gint               methods;
205 
206   /* session management */
207   GstRTSPConnInfo  conninfo;
208 
209   /* Everything goes in an internal
210    * locked-state bin */
211   GstBin          *internal_bin;
212   /* Set to true when internal bin state
213    * >= PAUSED */
214   gboolean        prerolled;
215 
216   /* TRUE if we posted async-start */
217   gboolean         in_async;
218 
219   /* TRUE when stream info has been collected */
220   gboolean         streams_collected;
221 
222   /* TRUE when streams have been blocked */
223   guint            n_streams_blocked;
224   GMutex           block_streams_lock;
225   GCond            block_streams_cond;
226 
227   guint            next_pad_id;
228   gint             next_dyn_pt;
229 
230   GstElement      *rtpbin;
231 
232   GList           *contexts;
233   GstSDPMessage   cursdp;
234 
235   GMutex          send_lock;
236 
237   GMutex          preroll_lock;
238   GCond           preroll_cond;
239 
240   /* TRUE if connection to server has been scheduled */
241   gboolean        open_conn_start;
242   GMutex          open_conn_lock;
243   GCond           open_conn_cond;
244 
245   GstClockTime    rtx_time;
246 
247   GstRTSPProfile profiles;
248   gchar          *server_ip;
249 };
250 
251 struct _GstRTSPClientSinkClass {
252   GstBinClass parent_class;
253 };
254 
255 GType gst_rtsp_client_sink_get_type(void);
256 
257 G_END_DECLS
258 
259 #endif /* __GST_RTSP_CLIENT_SINK_H__ */
260