Merge branch 'upstream/1.16' into tizen_gst_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 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
81 typedef enum {
82         GST_RTSPSRC_ERROR_NONE = 0,
83         GST_RTSPSRC_ERROR_UNSUPPORTED_AUDIO,
84         GST_RTSPSRC_ERROR_UNSUPPORTED_VIDEO,
85         GST_RTSPSRC_ERROR_CONNECTION_FAIL,
86         GST_RTSPSRC_ERROR_DNS_FAIL,
87         GST_RTSPSRC_ERROR_SERVER_DISCONNECTED,
88         GST_RTSPSRC_ERROR_BAD_SERVER,
89         GST_RTSPSRC_ERROR_INVALID_PROTOCOL,
90         GST_RTSPSRC_ERROR_INVALID_URL,
91         GST_RTSPSRC_ERROR_UNEXPECTED_MSG,
92         GST_RTSPSRC_ERROR_OUT_OF_MEMORIES,
93         GST_RTSPSRC_ERROR_RTSP_TIMEOUT,
94         GST_RTSPSRC_ERROR_BAD_REQUEST,
95         GST_RTSPSRC_ERROR_NOT_AUTHORIZED,
96         GST_RTSPSRC_ERROR_PAYMENT_REQUIRED,
97         GST_RTSPSRC_ERROR_FORBIDDEN,
98         GST_RTSPSRC_ERROR_CONTENT_NOT_FOUND,
99         GST_RTSPSRC_ERROR_METHOD_NOT_ALLOWED,
100         GST_RTSPSRC_ERROR_NOT_ACCEPTABLE,
101         GST_RTSPSRC_ERROR_PROXY_AUTHENTICATION_REQUIRED,
102         GST_RTSPSRC_ERROR_SERVER_TIMEOUT,
103         GST_RTSPSRC_ERROR_GONE,
104         GST_RTSPSRC_ERROR_LENGTH_REQUIRED,
105         GST_RTSPSRC_ERROR_PRECONDITION_FAILED,
106         GST_RTSPSRC_ERROR_REQUEST_ENTITY_TOO_LARGE,
107         GST_RTSPSRC_ERROR_REQUEST_URI_TOO_LARGE,
108         GST_RTSPSRC_ERROR_UNSUPPORTED_MEDIA_TYPE,
109         GST_RTSPSRC_ERROR_PARAMETER_NOT_UNDERSTOOD,
110         GST_RTSPSRC_ERROR_CONFERENCE_NOT_FOUND,
111         GST_RTSPSRC_ERROR_NOT_ENOUGH_BANDWIDTH,
112         GST_RTSPSRC_ERROR_NO_SESSION_ID,
113         GST_RTSPSRC_ERROR_METHOD_NOT_VALID_IN_THIS_STATE,
114         GST_RTSPSRC_ERROR_HEADER_FIELD_NOT_VALID_FOR_SOURCE,
115         GST_RTSPSRC_ERROR_INVALID_RANGE,
116         GST_RTSPSRC_ERROR_PARAMETER_IS_READONLY,
117         GST_RTSPSRC_ERROR_AGGREGATE_OP_NOT_ALLOWED,
118         GST_RTSPSRC_ERROR_ONLY_AGGREGATE_OP_ALLOWED,
119         GST_RTSPSRC_ERROR_BAD_TRANSPORT,
120         GST_RTSPSRC_ERROR_DESTINATION_UNREACHABLE,
121         GST_RTSPSRC_ERROR_INTERNAL_SERVER_ERROR,
122         GST_RTSPSRC_ERROR_NOT_IMPLEMENTED,
123         GST_RTSPSRC_ERROR_BAD_GATEWAY,
124         GST_RTSPSRC_ERROR_SERVICE_UNAVAILABLE,
125         GST_RTSPSRC_ERROR_GATEWAY_TIME_OUT      ,
126         GST_RTSPSRC_ERROR_RTSP_VERSION_NOT_SUPPORTED,
127         GST_RTSPSRC_ERROR_OPTION_NOT_SUPPORTED,
128 }_GstRTSPSrcError;
129 typedef _GstRTSPSrcError        GstRTSPSrcError;
130 #endif
131
132 typedef struct _GstRTSPConnInfo GstRTSPConnInfo;
133
134 struct _GstRTSPConnInfo {
135   gchar              *location;
136   GstRTSPUrl         *url;
137   gchar              *url_str;
138   GstRTSPConnection  *connection;
139   gboolean            connected;
140   gboolean            flushing;
141
142   GMutex              send_lock;
143   GMutex              recv_lock;
144 };
145
146 typedef struct _GstRTSPStream GstRTSPStream;
147
148 struct _GstRTSPStream {
149   gint          id;
150
151   GstRTSPSrc   *parent; /* parent, no extra ref to parent is taken */
152
153   /* pad we expose or NULL when it does not have an actual pad */
154   GstPad       *srcpad;
155   GstFlowReturn last_ret;
156   gboolean      added;
157   gboolean      setup;
158   gboolean      skipped;
159   gboolean      eos;
160   gboolean      discont;
161   gboolean      need_caps;
162   gboolean      waiting_setup_response;
163
164   /* for interleaved mode */
165   guint8        channel[2];
166   GstPad       *channelpad[2];
167
168   /* our udp sources */
169   GstElement   *udpsrc[2];
170   GstPad       *blockedpad;
171   gulong        blockid;
172   gboolean      is_ipv6;
173
174   /* our udp sinks back to the server */
175   GstElement   *udpsink[2];
176   GstPad       *rtcppad;
177
178   /* fakesrc for sending dummy data or appsrc for sending backchannel data */
179   GstElement   *rtpsrc;
180
181   /* state */
182   guint         port;
183   gboolean      container;
184   gboolean      is_real;
185   guint8        default_pt;
186   GstRTSPProfile profile;
187   GArray       *ptmap;
188   /* original control url */
189   gchar        *control_url;
190   guint32       ssrc;
191   guint32       seqbase;
192   guint64       timebase;
193   GstElement   *srtpdec;
194   GstCaps      *srtcpparams;
195   GstElement   *srtpenc;
196   guint32       send_ssrc;
197
198   /* per stream connection */
199   GstRTSPConnInfo  conninfo;
200
201   /* session */
202   GObject      *session;
203
204   /* srtp key management */
205   GstMIKEYMessage *mikey;
206
207   /* bandwidth */
208   guint         as_bandwidth;
209   guint         rs_bandwidth;
210   guint         rr_bandwidth;
211
212   /* destination */
213   gchar        *destination;
214   gboolean      is_multicast;
215   guint         ttl;
216   gboolean      is_backchannel;
217
218   /* A unique and stable id we will use for the stream start event */
219   gchar *stream_id;
220
221   GstStructure     *rtx_pt_map;
222
223   guint32       segment_seqnum[2];
224 };
225
226 /**
227  * GstRTSPSrcTimeoutCause:
228  * @GST_RTSP_SRC_TIMEOUT_CAUSE_RTCP: timeout triggered by RTCP
229  *
230  * Different causes to why the rtspsrc generated the GstRTSPSrcTimeout
231  * message.
232  */
233 typedef enum
234 {
235   GST_RTSP_SRC_TIMEOUT_CAUSE_RTCP
236 } GstRTSPSrcTimeoutCause;
237
238 /**
239  * GstRTSPNatMethod:
240  * @GST_RTSP_NAT_NONE: none
241  * @GST_RTSP_NAT_DUMMY: send dummy packets
242  *
243  * Different methods for trying to traverse firewalls.
244  */
245 typedef enum
246 {
247   GST_RTSP_NAT_NONE,
248   GST_RTSP_NAT_DUMMY
249 } GstRTSPNatMethod;
250
251
252 struct _GstRTSPSrc {
253   GstBin           parent;
254
255   /* task and mutex for interleaved mode */
256   gboolean         interleaved;
257   GstTask         *task;
258   GRecMutex        stream_rec_lock;
259   GstSegment       segment;
260   gboolean         running;
261   gboolean         need_range;
262   gboolean         skip;
263   gint             free_channel;
264   gboolean         need_segment;
265   GstClockTime     base_time;
266
267   /* UDP mode loop */
268   gint             pending_cmd;
269   gint             busy_cmd;
270   GCond            cmd_cond;
271   gboolean         ignore_timeout;
272   gboolean         open_error;
273
274   /* mutex for protecting state changes */
275   GRecMutex        state_rec_lock;
276
277   GstSDPMessage   *sdp;
278   gboolean         from_sdp;
279   GList           *streams;
280   GstStructure    *props;
281   gboolean         need_activate;
282
283   /* properties */
284   GstRTSPLowerTrans protocols;
285   gboolean          debug;
286   guint             retry;
287   guint64           udp_timeout;
288   GTimeVal          tcp_timeout;
289   GTimeVal         *ptcp_timeout;
290   guint             latency;
291   gboolean          drop_on_latency;
292   guint64           connection_speed;
293   GstRTSPNatMethod  nat_method;
294   gboolean          do_rtcp;
295   gboolean          do_rtsp_keep_alive;
296   gchar            *proxy_host;
297   guint             proxy_port;
298   gchar            *proxy_user;        /* from url or property */
299   gchar            *proxy_passwd;      /* from url or property */
300   gchar            *prop_proxy_id;     /* set via property */
301   gchar            *prop_proxy_pw;     /* set via property */
302   guint             rtp_blocksize;
303   gchar            *user_id;
304   gchar            *user_pw;
305   gint              buffer_mode;
306   GstRTSPRange      client_port_range;
307   gint              udp_buffer_size;
308   gboolean          short_header;
309   guint             probation;
310   gboolean          udp_reconnect;
311   gchar            *multi_iface;
312   gboolean          ntp_sync;
313   gboolean          use_pipeline_clock;
314   GstStructure     *sdes;
315   GTlsCertificateFlags tls_validation_flags;
316   GTlsDatabase     *tls_database;
317   GTlsInteraction  *tls_interaction;
318   gboolean          do_retransmission;
319   gint              ntp_time_source;
320   gchar            *user_agent;
321   GstClockTime      max_rtcp_rtp_time_diff;
322   gboolean          rfc7273_sync;
323   guint64           max_ts_offset_adjustment;
324   gint64            max_ts_offset;
325   gboolean          max_ts_offset_is_set;
326   gint              backchannel;
327   GstClockTime      teardown_timeout;
328
329   /* state */
330   GstRTSPState       state;
331   gchar             *content_base;
332   GstRTSPLowerTrans  cur_protocols;
333   gboolean           tried_url_auth;
334   gchar             *addr;
335   gboolean           need_redirect;
336   GstRTSPTimeRange  *range;
337   gchar             *control;
338   guint              next_port_num;
339   GstClock          *provided_clock;
340
341   /* supported methods */
342   gint               methods;
343
344   /* seekability
345    * -1.0 : Stream is not seekable
346    *  0.0 : seekable only to the beginning
347    * G_MAXFLOAT : Any value is possible
348    *
349    * Any other positive value indicates the longest duration
350    * between any two random access points
351    *  */
352   gfloat             seekable;
353   GstClockTime       last_pos;
354
355   /* session management */
356   GstElement      *manager;
357   gulong           manager_sig_id;
358   gulong           manager_ptmap_id;
359   gboolean         use_buffering;
360
361 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
362   /* media type */
363   gboolean  is_audio_codec_supported;
364   gboolean      is_video_codec_supported;
365   gchar         *audio_codec;
366   gchar         *video_codec;
367   gchar         *video_frame_size;
368 #endif
369
370   GstRTSPConnInfo  conninfo;
371
372   /* SET/GET PARAMETER requests queue */
373   GQueue set_get_param_q;
374
375   /* a list of RTSP extensions as GstElement */
376   GstRTSPExtensionList  *extensions;
377
378   GstRTSPVersion default_version;
379   GstRTSPVersion version;
380
381 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
382   GCond open_end;
383   GMutex pause_lock;
384   guint64 start_position;
385 #endif  
386 };
387
388 struct _GstRTSPSrcClass {
389   GstBinClass parent_class;
390
391  /* action signals */
392   gboolean (*get_parameter) (GstRTSPSrc *rtsp, const gchar *parameter, const gchar *content_type, GstPromise *promise);
393   gboolean (*get_parameters) (GstRTSPSrc *rtsp, gchar **parameters, const gchar *content_type, GstPromise *promise);
394   gboolean (*set_parameter) (GstRTSPSrc *rtsp, const gchar *name, const gchar *value, const gchar *content_type, GstPromise *promise);
395   GstFlowReturn (*push_backchannel_buffer) (GstRTSPSrc *src, guint id, GstSample *sample);
396 };
397
398 GType gst_rtspsrc_get_type(void);
399
400 G_END_DECLS
401
402 #endif /* __GST_RTSPSRC_H__ */