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