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