rtsp-media.h: Minor corrections in comments.
[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 /**
89  * GstRTSPMediaStream:
90  * @srcpad: the srcpad of the stream
91  * @payloader: the payloader of the format
92  * @prepared: if the stream is prepared for streaming
93  * @recv_rtp_sink: sinkpad for RTP buffers
94  * @recv_rtcp_sink: sinkpad for RTCP buffers
95  * @send_rtp_src: srcpad for RTP buffers
96  * @send_rtcp_src: srcpad for RTCP buffers
97  * @udpsrc: the udp source elements for RTP/RTCP
98  * @udpsink: the udp sink elements for RTP/RTCP
99  * @appsrc: the app source elements for RTP/RTCP
100  * @appsink: the app sink elements for RTP/RTCP
101  * @server_port: the server ports for this stream
102  * @caps_sig: the signal id for detecting caps
103  * @caps: the caps of the stream
104  * @tranports: the current transports being streamed
105  *
106  * The definition of a media stream. The streams are identified by @id.
107  */
108 struct _GstRTSPMediaStream {
109   GstPad       *srcpad;
110   GstElement   *payloader;
111   gboolean      prepared;
112
113   /* pads on the rtpbin */
114   GstPad       *recv_rtcp_sink;
115   GstPad       *recv_rtp_sink;
116   GstPad       *send_rtp_sink;
117   GstPad       *send_rtp_src;
118   GstPad       *send_rtcp_src;
119
120   /* the RTPSession object */
121   GObject      *session;
122
123   /* sinks used for sending and receiving RTP and RTCP, they share
124    * sockets */
125   GstElement   *udpsrc[2];
126   GstElement   *udpsink[2];
127   /* for TCP transport */
128   GstElement   *appsrc[2];
129   GstElement   *appsink[2];
130
131   GstElement   *tee[2];
132   GstElement   *selector[2];
133
134   /* server ports for sending/receiving */
135   GstRTSPRange  server_port;
136
137   /* the caps of the stream */
138   gulong        caps_sig;
139   GstCaps      *caps;
140
141   /* transports we stream to */
142   GList        *transports;
143
144   /* to filter out duplicate destinations in case multiudpsink is too old to do
145    * this for us */
146   gboolean      filter_duplicates;
147   GList        *destinations;
148 };
149
150 /**
151  * GstRTSPMediaStatus:
152  * @GST_RTSP_MEDIA_STATUS_UNPREPARED: media pipeline not prerolled
153  * @GST_RTSP_MEDIA_STATUS_PREPARING: media pipeline is prerolling
154  * @GST_RTSP_MEDIA_STATUS_PREPARED: media pipeline is prerolled
155  * @GST_RTSP_MEDIA_STATUS_ERROR: media pipeline is in error
156  *
157  * The state of the media pipeline.
158  */
159 typedef enum {
160   GST_RTSP_MEDIA_STATUS_UNPREPARED = 0,
161   GST_RTSP_MEDIA_STATUS_PREPARING  = 1,
162   GST_RTSP_MEDIA_STATUS_PREPARED   = 2,
163   GST_RTSP_MEDIA_STATUS_ERROR      = 3
164 } GstRTSPMediaStatus;
165
166 /**
167  * GstRTSPMedia:
168  * @lock: for protecting the object
169  * @cond: for signaling the object
170  * @shared: if this media can be shared between clients
171  * @reusable: if this media can be reused after an unprepare
172  * @protocols: the allowed lower transport for this stream
173  * @reused: if this media has been reused
174  * @is_ipv6: if this media is using ipv6
175  * @element: the data providing element
176  * @streams: the different streams provided by @element
177  * @dynamic: list of dynamic elements managed by @element
178  * @status: the status of the media pipeline
179  * @active: the number of active connections
180  * @pipeline: the toplevel pipeline
181  * @fakesink: for making state changes async
182  * @source: the bus watch for pipeline messages.
183  * @id: the id of the watch
184  * @is_live: if the pipeline is live
185  * @buffering: if the pipeline is buffering
186  * @target_state: the desired target state of the pipeline
187  * @rtpbin: the rtpbin
188  * @range: the range of the media being streamed
189  *
190  * A class that contains the GStreamer element along with a list of
191  * #GstRTSPMediaStream objects that can produce data.
192  *
193  * This object is usually created from a #GstRTSPMediaFactory.
194  */
195 struct _GstRTSPMedia {
196   GObject            parent;
197
198   GMutex            *lock;
199   GCond             *cond;
200
201   gboolean           shared;
202   gboolean           reusable;
203   GstRTSPLowerTrans  protocols;
204   gboolean           reused;
205   gboolean           is_ipv6;
206   gboolean           eos_shutdown;
207
208   GstElement        *element;
209   GArray            *streams;
210   GList             *dynamic;
211   GstRTSPMediaStatus status;
212   gint               active;
213   gboolean           eos_pending;
214   gboolean           adding;
215
216   /* the pipeline for the media */
217   GstElement        *pipeline;
218   GstElement        *fakesink;
219   GSource           *source;
220   guint              id;
221
222   gboolean           is_live;
223   gboolean           buffering;
224   GstState           target_state;
225
226   /* RTP session manager */
227   GstElement        *rtpbin;
228
229   /* the range of media */
230   GstRTSPTimeRange   range;
231 };
232
233 /**
234  * GstRTSPMediaClass:
235  * @context: the main context for dispatching messages
236  * @loop: the mainloop for message.
237  * @thread: the thread dispatching messages.
238  * @handle_message: handle a message
239  * @unprepare: the default implementation sets the pipeline's state
240  *             to GST_STATE_NULL.
241  *
242  * The RTSP media class
243  */
244 struct _GstRTSPMediaClass {
245   GObjectClass  parent_class;
246
247   /* thread for the mainloop */
248   GMainContext *context;
249   GMainLoop    *loop;
250   GThread      *thread;
251
252   /* vmethods */
253   gboolean     (*handle_message)  (GstRTSPMedia *media, GstMessage *message);
254   gboolean     (*unprepare)       (GstRTSPMedia *media);
255
256   /* signals */
257   gboolean     (*prepared)        (GstRTSPMedia *media);
258   gboolean     (*unprepared)      (GstRTSPMedia *media);
259
260   gboolean     (*new_state)       (GstRTSPMedia *media, GstState state);
261 };
262
263 GType                 gst_rtsp_media_get_type         (void);
264
265 /* creating the media */
266 GstRTSPMedia *        gst_rtsp_media_new              (void);
267
268 void                  gst_rtsp_media_set_shared       (GstRTSPMedia *media, gboolean shared);
269 gboolean              gst_rtsp_media_is_shared        (GstRTSPMedia *media);
270
271 void                  gst_rtsp_media_set_reusable     (GstRTSPMedia *media, gboolean reusable);
272 gboolean              gst_rtsp_media_is_reusable      (GstRTSPMedia *media);
273
274 void                  gst_rtsp_media_set_protocols    (GstRTSPMedia *media, GstRTSPLowerTrans protocols);
275 GstRTSPLowerTrans     gst_rtsp_media_get_protocols    (GstRTSPMedia *media);
276
277 void                  gst_rtsp_media_set_eos_shutdown (GstRTSPMedia *media, gboolean eos_shutdown);
278 gboolean              gst_rtsp_media_is_eos_shutdown  (GstRTSPMedia *media);
279
280 /* prepare the media for playback */
281 gboolean              gst_rtsp_media_prepare          (GstRTSPMedia *media);
282 gboolean              gst_rtsp_media_is_prepared      (GstRTSPMedia *media);
283 gboolean              gst_rtsp_media_unprepare        (GstRTSPMedia *media);
284
285 /* dealing with the media */
286 guint                 gst_rtsp_media_n_streams        (GstRTSPMedia *media);
287 GstRTSPMediaStream *  gst_rtsp_media_get_stream       (GstRTSPMedia *media, guint idx);
288
289 gboolean              gst_rtsp_media_seek             (GstRTSPMedia *media, GstRTSPTimeRange *range);
290 gchar *               gst_rtsp_media_get_range_string (GstRTSPMedia *media, gboolean play);
291
292 GstFlowReturn         gst_rtsp_media_stream_rtp       (GstRTSPMediaStream *stream, GstBuffer *buffer);
293 GstFlowReturn         gst_rtsp_media_stream_rtcp      (GstRTSPMediaStream *stream, GstBuffer *buffer);
294
295 gboolean              gst_rtsp_media_set_state        (GstRTSPMedia *media, GstState state, GArray *transports);
296
297 void                  gst_rtsp_media_remove_elements  (GstRTSPMedia *media);
298
299 void                  gst_rtsp_media_trans_cleanup    (GstRTSPMediaTrans *trans);
300
301 G_END_DECLS
302
303 #endif /* __GST_RTSP_MEDIA_H__ */