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 server_side_trickmode; 211 GstClockTime trickmode_interval; 212 gint free_channel; 213 gboolean need_segment; 214 gboolean clip_out_segment; 215 GstSegment out_segment; 216 GstClockTime base_time; 217 218 /* UDP mode loop */ 219 gint pending_cmd; 220 gint busy_cmd; 221 GCond cmd_cond; 222 gboolean ignore_timeout; 223 gboolean open_error; 224 225 /* mutex for protecting state changes */ 226 GRecMutex state_rec_lock; 227 228 GstSDPMessage *sdp; 229 gboolean from_sdp; 230 GList *streams; 231 GstStructure *props; 232 gboolean need_activate; 233 234 /* properties */ 235 GstRTSPLowerTrans protocols; 236 gboolean debug; 237 guint retry; 238 guint64 udp_timeout; 239 gint64 tcp_timeout; 240 guint latency; 241 gboolean drop_on_latency; 242 guint64 connection_speed; 243 GstRTSPNatMethod nat_method; 244 gboolean do_rtcp; 245 gboolean do_rtsp_keep_alive; 246 gchar *proxy_host; 247 guint proxy_port; 248 gchar *proxy_user; /* from url or property */ 249 gchar *proxy_passwd; /* from url or property */ 250 gchar *prop_proxy_id; /* set via property */ 251 gchar *prop_proxy_pw; /* set via property */ 252 guint rtp_blocksize; 253 gchar *user_id; 254 gchar *user_pw; 255 gint buffer_mode; 256 GstRTSPRange client_port_range; 257 gint udp_buffer_size; 258 gboolean short_header; 259 guint probation; 260 gboolean udp_reconnect; 261 gchar *multi_iface; 262 gboolean ntp_sync; 263 gboolean use_pipeline_clock; 264 GstStructure *sdes; 265 GTlsCertificateFlags tls_validation_flags; 266 GTlsDatabase *tls_database; 267 GTlsInteraction *tls_interaction; 268 gboolean do_retransmission; 269 gint ntp_time_source; 270 gchar *user_agent; 271 gint max_rtcp_rtp_time_diff; 272 gboolean rfc7273_sync; 273 guint64 max_ts_offset_adjustment; 274 gint64 max_ts_offset; 275 gboolean max_ts_offset_is_set; 276 gint backchannel; 277 GstClockTime teardown_timeout; 278 gboolean onvif_mode; 279 gboolean onvif_rate_control; 280 gboolean is_live; 281 gboolean ignore_x_server_reply; 282 283 /* state */ 284 GstRTSPState state; 285 gchar *content_base; 286 GstRTSPLowerTrans cur_protocols; 287 gboolean tried_url_auth; 288 gchar *addr; 289 gboolean need_redirect; 290 GstRTSPTimeRange *range; 291 gchar *control; 292 guint next_port_num; 293 GstClock *provided_clock; 294 295 /* supported methods */ 296 gint methods; 297 298 /* seekability 299 * -1.0 : Stream is not seekable 300 * 0.0 : seekable only to the beginning 301 * G_MAXFLOAT : Any value is possible 302 * 303 * Any other positive value indicates the longest duration 304 * between any two random access points 305 * */ 306 gfloat seekable; 307 guint32 seek_seqnum; 308 GstClockTime last_pos; 309 310 /* session management */ 311 GstElement *manager; 312 gulong manager_sig_id; 313 gulong manager_ptmap_id; 314 gboolean use_buffering; 315 316 GstRTSPConnInfo conninfo; 317 318 /* SET/GET PARAMETER requests queue */ 319 GQueue set_get_param_q; 320 321 /* a list of RTSP extensions as GstElement */ 322 GstRTSPExtensionList *extensions; 323 324 GstRTSPVersion default_version; 325 GstRTSPVersion version; 326 327 GstEvent *initial_seek; 328 329 guint group_id; 330 GMutex group_lock; 331 }; 332 333 struct _GstRTSPSrcClass { 334 GstBinClass parent_class; 335 336 /* action signals */ 337 gboolean (*get_parameter) (GstRTSPSrc *rtsp, const gchar *parameter, const gchar *content_type, GstPromise *promise); 338 gboolean (*get_parameters) (GstRTSPSrc *rtsp, gchar **parameters, const gchar *content_type, GstPromise *promise); 339 gboolean (*set_parameter) (GstRTSPSrc *rtsp, const gchar *name, const gchar *value, const gchar *content_type, GstPromise *promise); 340 GstFlowReturn (*push_backchannel_buffer) (GstRTSPSrc *src, guint id, GstSample *sample); 341 }; 342 343 GType gst_rtspsrc_get_type(void); 344 345 G_END_DECLS 346 347 #endif /* __GST_RTSPSRC_H__ */ 348