Update wfdconfigmessage for supporting Wi-Fi Display sink side
[platform/core/multimedia/gst-rtsp-server-wfd.git] / src / include / rtsp-media.h
1 /* GStreamer
2  * Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
3
4 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
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., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21
22 * * Modifications by Samsung Electronics Co., Ltd.
23
24 * 1. Applied Miracast WFD Server function
25 */
26
27 #include <gst/gst.h>
28 #include <gst/rtsp/gstrtsprange.h>
29 #include <gst/rtsp/gstrtspurl.h>
30
31 #ifndef __GST_RTSP_MEDIA_H__
32 #define __GST_RTSP_MEDIA_H__
33
34 G_BEGIN_DECLS
35
36 /* types for the media */
37 #define GST_TYPE_RTSP_MEDIA              (gst_rtsp_media_get_type ())
38 #define GST_IS_RTSP_MEDIA(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_MEDIA))
39 #define GST_IS_RTSP_MEDIA_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_MEDIA))
40 #define GST_RTSP_MEDIA_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_MEDIA, GstRTSPMediaClass))
41 #define GST_RTSP_MEDIA(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_MEDIA, GstRTSPMedia))
42 #define GST_RTSP_MEDIA_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_MEDIA, GstRTSPMediaClass))
43 #define GST_RTSP_MEDIA_CAST(obj)         ((GstRTSPMedia*)(obj))
44 #define GST_RTSP_MEDIA_CLASS_CAST(klass) ((GstRTSPMediaClass*)(klass))
45
46 typedef struct _GstRTSPMediaStream GstRTSPMediaStream;
47 typedef struct _GstRTSPMedia GstRTSPMedia;
48 typedef struct _GstRTSPMediaClass GstRTSPMediaClass;
49 typedef struct _GstRTSPMediaTrans GstRTSPMediaTrans;
50
51 typedef gboolean (*GstRTSPSendFunc)      (GstBuffer *buffer, guint8 channel, gpointer user_data);
52 typedef gboolean (*GstRTSPSendListFunc)  (GstBufferList *blist, guint8 channel, gpointer user_data);
53 typedef void     (*GstRTSPKeepAliveFunc) (gpointer user_data);
54
55 /**
56  * GstRTSPMediaTrans:
57  * @idx: a stream index
58  * @send_rtp: callback for sending RTP messages
59  * @send_rtcp: callback for sending RTCP messages
60  * @send_rtp_list: callback for sending RTP messages
61  * @send_rtcp_list: callback for sending RTCP messages
62  * @user_data: user data passed in the callbacks
63  * @notify: free function for the user_data.
64  * @keep_alive: keep alive callback
65  * @ka_user_data: data passed to @keep_alive
66  * @ka_notify: called when @ka_user_data is freed
67  * @active: if we are actively sending
68  * @timeout: if we timed out
69  * @transport: a transport description
70  * @rtpsource: the receiver rtp source object
71  *
72  * A Transport description for stream @idx
73  */
74 struct _GstRTSPMediaTrans {
75   guint idx;
76
77   GstRTSPSendFunc      send_rtp;
78   GstRTSPSendFunc      send_rtcp;
79   GstRTSPSendListFunc  send_rtp_list;
80   GstRTSPSendListFunc  send_rtcp_list;
81   gpointer             user_data;
82   GDestroyNotify       notify;
83
84   GstRTSPKeepAliveFunc keep_alive;
85   gpointer             ka_user_data;
86   GDestroyNotify       ka_notify;
87   gboolean             active;
88   gboolean             timeout;
89
90   GstRTSPTransport    *transport;
91
92   GObject             *rtpsource;
93 };
94
95 #include "rtsp-auth.h"
96
97 /**
98  * GstRTSPMediaStream:
99  * @srcpad: the srcpad of the stream
100  * @payloader: the payloader of the format
101  * @prepared: if the stream is prepared for streaming
102  * @recv_rtp_sink: sinkpad for RTP buffers
103  * @recv_rtcp_sink: sinkpad for RTCP buffers
104  * @send_rtp_src: srcpad for RTP buffers
105  * @send_rtcp_src: srcpad for RTCP buffers
106  * @udpsrc: the udp source elements for RTP/RTCP
107  * @udpsink: the udp sink elements for RTP/RTCP
108  * @appsrc: the app source elements for RTP/RTCP
109  * @appsink: the app sink elements for RTP/RTCP
110  * @server_port: the server ports for this stream
111  * @caps_sig: the signal id for detecting caps
112  * @caps: the caps of the stream
113  * @tranports: the current transports being streamed
114  *
115  * The definition of a media stream. The streams are identified by @id.
116  */
117 struct _GstRTSPMediaStream {
118   GstPad       *srcpad;
119   GstElement   *payloader;
120   gboolean      prepared;
121
122   /* pads on the rtpbin */
123   GstPad       *recv_rtcp_sink;
124   GstPad       *recv_rtp_sink;
125   GstPad       *send_rtp_sink;
126   GstPad       *send_rtp_src;
127   GstPad       *send_rtcp_src;
128
129   /* the RTPSession object */
130   GObject      *session;
131
132   /* sinks used for sending and receiving RTP and RTCP, they share
133    * sockets */
134   GstElement   *udpsrc[2];
135   GstElement   *udpsink[2];
136   /* for TCP transport */
137   GstElement   *appsrc[2];
138   GstElement   *appsink[2];
139
140   GstElement   *tee[2];
141   GstElement   *selector[2];
142
143   /* server ports for sending/receiving */
144   GstRTSPRange  server_port;
145
146   /* the caps of the stream */
147   gulong        caps_sig;
148   GstCaps      *caps;
149
150   /* transports we stream to */
151   GList        *transports;
152
153   /* to filter out duplicate destinations in case multiudpsink is too old to do
154    * this for us */
155   gboolean      filter_duplicates;
156   GList        *destinations;
157 };
158
159 /**
160  * GstRTSPMediaStatus:
161  * @GST_RTSP_MEDIA_STATUS_UNPREPARED: media pipeline not prerolled
162  * @GST_RTSP_MEDIA_STATUS_PREPARING: media pipeline is prerolling
163  * @GST_RTSP_MEDIA_STATUS_PREPARED: media pipeline is prerolled
164  * @GST_RTSP_MEDIA_STATUS_ERROR: media pipeline is in error
165  *
166  * The state of the media pipeline.
167  */
168 typedef enum {
169   GST_RTSP_MEDIA_STATUS_UNPREPARED = 0,
170   GST_RTSP_MEDIA_STATUS_PREPARING  = 1,
171   GST_RTSP_MEDIA_STATUS_PREPARED   = 2,
172   GST_RTSP_MEDIA_STATUS_ERROR      = 3
173 } GstRTSPMediaStatus;
174
175 /**
176  * GstRTSPMedia:
177  * @lock: for protecting the object
178  * @cond: for signaling the object
179  * @shared: if this media can be shared between clients
180  * @reusable: if this media can be reused after an unprepare
181  * @protocols: the allowed lower transport for this stream
182  * @reused: if this media has been reused
183  * @is_ipv6: if this media is using ipv6
184  * @element: the data providing element
185  * @streams: the different streams provided by @element
186  * @dynamic: list of dynamic elements managed by @element
187  * @status: the status of the media pipeline
188  * @active: the number of active connections
189  * @pipeline: the toplevel pipeline
190  * @fakesink: for making state changes async
191  * @source: the bus watch for pipeline messages.
192  * @id: the id of the watch
193  * @is_live: if the pipeline is live
194  * @buffering: if the pipeline is buffering
195  * @target_state: the desired target state of the pipeline
196  * @rtpbin: the rtpbin
197  * @range: the range of the media being streamed
198  *
199  * A class that contains the GStreamer element along with a list of
200  * #GstRTSPMediaStream objects that can produce data.
201  *
202  * This object is usually created from a #GstRTSPMediaFactory.
203  */
204 struct _GstRTSPMedia {
205   GObject            parent;
206
207   GMutex            *lock;
208   GCond             *cond;
209
210   gboolean           shared;
211   gboolean           reusable;
212   GstRTSPLowerTrans  protocols;
213   gboolean           reused;
214   gboolean           is_ipv6;
215   gboolean           eos_shutdown;
216   GstRTSPAuth       *auth;
217
218   GstElement        *element;
219   GArray            *streams;
220   GList             *dynamic;
221   GstRTSPMediaStatus status;
222   gint               active;
223   gboolean           eos_pending;
224   gboolean           adding;
225
226   /* the pipeline for the media */
227   GstElement        *pipeline;
228   GstElement        *fakesink;
229   GSource           *source;
230   guint              id;
231
232   gboolean           is_live;
233   gboolean           buffering;
234   GstState           target_state;
235
236   /* RTP session manager */
237   GstElement        *rtpbin;
238
239   /* the range of media */
240   GstRTSPTimeRange   range;
241 };
242
243 /**
244  * GstRTSPMediaClass:
245  * @context: the main context for dispatching messages
246  * @loop: the mainloop for message.
247  * @thread: the thread dispatching messages.
248  * @handle_message: handle a message
249  * @unprepare: the default implementation sets the pipeline's state
250  *             to GST_STATE_NULL.
251  *
252  * The RTSP media class
253  */
254 struct _GstRTSPMediaClass {
255   GObjectClass  parent_class;
256
257   /* thread for the mainloop */
258   GMainContext *context;
259   GMainLoop    *loop;
260   GThread      *thread;
261
262   /* vmethods */
263   gboolean     (*handle_message)  (GstRTSPMedia *media, GstMessage *message);
264   gboolean     (*unprepare)       (GstRTSPMedia *media);
265
266   /* signals */
267   gboolean     (*prepared)        (GstRTSPMedia *media);
268   gboolean     (*unprepared)      (GstRTSPMedia *media);
269
270   gboolean     (*new_state)       (GstRTSPMedia *media, GstState state);
271 };
272
273 GType                 gst_rtsp_media_get_type         (void);
274
275 /* creating the media */
276 GstRTSPMedia *        gst_rtsp_media_new              (void);
277
278 void                  gst_rtsp_media_set_shared       (GstRTSPMedia *media, gboolean shared);
279 gboolean              gst_rtsp_media_is_shared        (GstRTSPMedia *media);
280
281 void                  gst_rtsp_media_set_reusable     (GstRTSPMedia *media, gboolean reusable);
282 gboolean              gst_rtsp_media_is_reusable      (GstRTSPMedia *media);
283
284 void                  gst_rtsp_media_set_protocols    (GstRTSPMedia *media, GstRTSPLowerTrans protocols);
285 GstRTSPLowerTrans     gst_rtsp_media_get_protocols    (GstRTSPMedia *media);
286
287 void                  gst_rtsp_media_set_eos_shutdown (GstRTSPMedia *media, gboolean eos_shutdown);
288 gboolean              gst_rtsp_media_is_eos_shutdown  (GstRTSPMedia *media);
289
290 void                  gst_rtsp_media_set_auth         (GstRTSPMedia *media, GstRTSPAuth *auth);
291 GstRTSPAuth *         gst_rtsp_media_get_auth         (GstRTSPMedia *media);
292
293 /* prepare the media for playback */
294 gboolean              gst_rtsp_media_prepare          (GstRTSPMedia *media);
295 gboolean              gst_rtsp_media_is_prepared      (GstRTSPMedia *media);
296 gboolean              gst_rtsp_media_unprepare        (GstRTSPMedia *media);
297
298 /* dealing with the media */
299 guint                 gst_rtsp_media_n_streams        (GstRTSPMedia *media);
300 GstRTSPMediaStream *  gst_rtsp_media_get_stream       (GstRTSPMedia *media, guint idx);
301
302 gboolean              gst_rtsp_media_seek             (GstRTSPMedia *media, GstRTSPTimeRange *range);
303 gchar *               gst_rtsp_media_get_range_string (GstRTSPMedia *media, gboolean play);
304
305 GstFlowReturn         gst_rtsp_media_stream_rtp       (GstRTSPMediaStream *stream, GstBuffer *buffer);
306 GstFlowReturn         gst_rtsp_media_stream_rtcp      (GstRTSPMediaStream *stream, GstBuffer *buffer);
307
308 gboolean              gst_rtsp_media_set_state        (GstRTSPMedia *media, GstState state, GArray *transports);
309
310 void                  gst_rtsp_media_remove_elements  (GstRTSPMedia *media);
311
312 void                  gst_rtsp_media_trans_cleanup    (GstRTSPMediaTrans *trans);
313
314 G_END_DECLS
315
316 #endif /* __GST_RTSP_MEDIA_H__ */