media: keep track of active transports
[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
46 /**
47  * GstRTSPMediaTrans:
48  * @idx: a stream index
49  * @send_rtp: callback for sending RTP messages
50  * @send_rtcp: callback for sending RTCP messages
51  * @user_data: user data passed in the callbacks
52  * @notify: free function for the user_data.
53  * @transport: a transport description
54  *
55  * A Transport description for stream @idx
56  */
57 struct _GstRTSPMediaTrans {
58   guint idx;
59
60   GstRTSPSendFunc send_rtp;
61   GstRTSPSendFunc send_rtcp;
62   gpointer        user_data;
63   GDestroyNotify  notify;
64   gboolean        active;
65
66   GstRTSPTransport *transport;
67 };
68
69 /**
70  * GstRTSPMediaStream:
71  *
72  * @srcpad: the srcpad of the stream
73  * @payloader: the payloader of the format
74  * @prepared: if the stream is prepared for streaming
75  * @server_port: the server udp ports
76  * @recv_rtp_sink: sinkpad for RTP buffers
77  * @recv_rtcp_sink: sinkpad for RTCP buffers
78  * @recv_rtp_src: srcpad for RTP buffers
79  * @recv_rtcp_src: srcpad for RTCP buffers
80  * @udpsrc: the udp source elements for RTP/RTCP
81  * @udpsink: the udp sink elements for RTP/RTCP
82  * @appsrc: the app source elements for RTP/RTCP
83  * @appsink: the app sink elements for RTP/RTCP
84  * @server_port: the server ports for this stream
85  * @caps_sig: the signal id for detecting caps
86  * @caps: the caps of the stream
87  * @tranports: the current transports being streamed
88  *
89  * The definition of a media stream. The streams are identified by @id.
90  */
91 struct _GstRTSPMediaStream {
92   GstPad       *srcpad;
93   GstElement   *payloader;
94   gboolean      prepared;
95
96   /* pads on the rtpbin */
97   GstPad       *recv_rtcp_sink;
98   GstPad       *recv_rtp_sink;
99   GstPad       *send_rtp_sink;
100   GstPad       *send_rtp_src;
101   GstPad       *send_rtcp_src;
102
103   /* the RTPSession object */
104   GObject      *session;
105
106   /* sinks used for sending and receiving RTP and RTCP, they share
107    * sockets */
108   GstElement   *udpsrc[2];
109   GstElement   *udpsink[2];
110   /* for TCP transport */
111   GstElement   *appsrc[2];
112   GstElement   *appsink[2];
113
114   GstElement   *tee[2];
115   GstElement   *selector[2];
116
117   /* server ports for sending/receiving */
118   GstRTSPRange  server_port;
119
120   /* the caps of the stream */
121   gulong        caps_sig;
122   GstCaps      *caps;
123
124   /* transports we stream to */
125   GList        *transports;
126 };
127
128 /**
129  * GstRTSPMedia:
130  * @shared: if this media can be shared between clients
131  * @reusable: if this media can be reused after an unprepare
132  * @element: the data providing element
133  * @streams: the different streams provided by @element
134  * @prepared: if the media is prepared for streaming
135  * @pipeline: the toplevel pipeline
136  * @source: the bus watch for pipeline messages.
137  * @id: the id of the watch
138  * @is_live: if the pipeline is live
139  * @buffering: if the pipeline is buffering
140  * @target_state: the desired target state of the pipeline
141  * @rtpbin: the rtpbin
142  * @range: the range of the media being streamed
143  *
144  * A class that contains the GStreamer element along with a list of
145  * #GstRTSPediaStream objects that can produce data.
146  *
147  * This object is usually created from a #GstRTSPMediaFactory.
148  */
149 struct _GstRTSPMedia {
150   GObject       parent;
151
152   gboolean      shared;
153   gboolean      reusable;
154   gboolean      reused;
155
156   GstElement   *element;
157   GArray       *streams;
158   GList        *dynamic;
159   gboolean      prepared;
160   gint          active;
161
162   /* the pipeline for the media */
163   GstElement   *pipeline;
164   GstElement   *fakesink;
165   GSource      *source;
166   guint         id;
167
168   gboolean      is_live;
169   gboolean      buffering;
170   GstState      target_state;
171
172   /* RTP session manager */
173   GstElement   *rtpbin;
174
175   /* the range of media */
176   GstRTSPTimeRange range;
177 };
178
179 /**
180  * GstRTSPMediaClass:
181  * @context: the main context for dispatching messages
182  * @loop: the mainloop for message.
183  * @thread: the thread dispatching messages.
184  * @handle_message: handle a message
185  *
186  * The RTSP media class
187  */
188 struct _GstRTSPMediaClass {
189   GObjectClass  parent_class;
190
191   /* thread for the mainloop */
192   GMainContext *context;
193   GMainLoop    *loop;
194   GThread      *thread;
195
196   /* vmethods */
197   gboolean     (*handle_message)  (GstRTSPMedia *media, GstMessage *message);
198
199   /* signals */
200   gboolean     (*unprepared)      (GstRTSPMedia *media);
201 };
202
203 GType                 gst_rtsp_media_get_type         (void);
204
205 /* creating the media */
206 GstRTSPMedia *        gst_rtsp_media_new              (void);
207
208 void                  gst_rtsp_media_set_shared       (GstRTSPMedia *media, gboolean shared);
209 gboolean              gst_rtsp_media_is_shared        (GstRTSPMedia *media);
210
211 void                  gst_rtsp_media_set_reusable     (GstRTSPMedia *media, gboolean reusable);
212 gboolean              gst_rtsp_media_is_reusable      (GstRTSPMedia *media);
213
214 /* prepare the media for playback */
215 gboolean              gst_rtsp_media_prepare          (GstRTSPMedia *media);
216 gboolean              gst_rtsp_media_is_prepared      (GstRTSPMedia *media);
217 gboolean              gst_rtsp_media_unprepare        (GstRTSPMedia *media);
218
219 /* dealing with the media */
220 guint                 gst_rtsp_media_n_streams        (GstRTSPMedia *media);
221 GstRTSPMediaStream *  gst_rtsp_media_get_stream       (GstRTSPMedia *media, guint idx);
222
223 gboolean              gst_rtsp_media_seek             (GstRTSPMedia *media, GstRTSPTimeRange *range);
224
225 GstFlowReturn         gst_rtsp_media_stream_rtp       (GstRTSPMediaStream *stream, GstBuffer *buffer);
226 GstFlowReturn         gst_rtsp_media_stream_rtcp      (GstRTSPMediaStream *stream, GstBuffer *buffer);
227
228 gboolean              gst_rtsp_media_set_state        (GstRTSPMedia *media, GstState state, GArray *trans);
229
230 G_END_DECLS
231
232 #endif /* __GST_RTSP_MEDIA_H__ */