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