rtsp: massive refactoring
[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 _GstRTSPMedia GstRTSPMedia;
40 typedef struct _GstRTSPMediaClass GstRTSPMediaClass;
41
42 #include "rtsp-stream.h"
43 #include "rtsp-auth.h"
44
45 /**
46  * GstRTSPMediaStatus:
47  * @GST_RTSP_MEDIA_STATUS_UNPREPARED: media pipeline not prerolled
48  * @GST_RTSP_MEDIA_STATUS_UNPREPARING: media pipeline is busy doing a clean
49  *                                     shutdown.
50  * @GST_RTSP_MEDIA_STATUS_PREPARING: media pipeline is prerolling
51  * @GST_RTSP_MEDIA_STATUS_PREPARED: media pipeline is prerolled
52  * @GST_RTSP_MEDIA_STATUS_ERROR: media pipeline is in error
53  *
54  * The state of the media pipeline.
55  */
56 typedef enum {
57   GST_RTSP_MEDIA_STATUS_UNPREPARED  = 0,
58   GST_RTSP_MEDIA_STATUS_UNPREPARING = 1,
59   GST_RTSP_MEDIA_STATUS_PREPARING   = 2,
60   GST_RTSP_MEDIA_STATUS_PREPARED    = 3,
61   GST_RTSP_MEDIA_STATUS_ERROR       = 4
62 } GstRTSPMediaStatus;
63
64 /**
65  * GstRTSPMedia:
66  * @lock: for protecting the object
67  * @cond: for signaling the object
68  * @shared: if this media can be shared between clients
69  * @reusable: if this media can be reused after an unprepare
70  * @protocols: the allowed lower transport for this stream
71  * @reused: if this media has been reused
72  * @is_ipv6: if this media is using ipv6
73  * @element: the data providing element
74  * @streams: the different #GstRTSPStream provided by @element
75  * @dynamic: list of dynamic elements managed by @element
76  * @status: the status of the media pipeline
77  * @n_active: the number of active connections
78  * @pipeline: the toplevel pipeline
79  * @fakesink: for making state changes async
80  * @source: the bus watch for pipeline messages.
81  * @id: the id of the watch
82  * @is_live: if the pipeline is live
83  * @seekable: if the pipeline can perform a seek
84  * @buffering: if the pipeline is buffering
85  * @target_state: the desired target state of the pipeline
86  * @rtpbin: the rtpbin
87  * @range: the range of the media being streamed
88  *
89  * A class that contains the GStreamer element along with a list of
90  * #GstRTSPStream objects that can produce data.
91  *
92  * This object is usually created from a #GstRTSPMediaFactory.
93  */
94 struct _GstRTSPMedia {
95   GObject            parent;
96
97   GMutex             lock;
98   GCond              cond;
99
100   gboolean           shared;
101   gboolean           reusable;
102   GstRTSPLowerTrans  protocols;
103   gboolean           reused;
104   gboolean           is_ipv6;
105   gboolean           eos_shutdown;
106   guint              buffer_size;
107   GstRTSPAuth       *auth;
108   gchar             *multicast_group;
109
110   GstElement        *element;
111   GPtrArray         *streams;
112   GList             *dynamic;
113   GstRTSPMediaStatus status;
114   gint               n_active;
115   gboolean           adding;
116
117   /* the pipeline for the media */
118   GstElement        *pipeline;
119   GstElement        *fakesink;
120   GSource           *source;
121   guint              id;
122
123   gboolean           is_live;
124   gboolean           seekable;
125   gboolean           buffering;
126   GstState           target_state;
127
128   /* RTP session manager */
129   GstElement        *rtpbin;
130
131   /* the range of media */
132   GstRTSPTimeRange   range;
133 };
134
135 /**
136  * GstRTSPMediaClass:
137  * @context: the main context for dispatching messages
138  * @loop: the mainloop for message.
139  * @thread: the thread dispatching messages.
140  * @handle_message: handle a message
141  * @unprepare: the default implementation sets the pipeline's state
142  *             to GST_STATE_NULL.
143  * @handle_mtu: handle a mtu
144  *
145  * The RTSP media class
146  */
147 struct _GstRTSPMediaClass {
148   GObjectClass  parent_class;
149
150   /* thread for the mainloop */
151   GMainContext *context;
152   GMainLoop    *loop;
153   GThread      *thread;
154
155   /* vmethods */
156   gboolean        (*handle_message)  (GstRTSPMedia *media, GstMessage *message);
157   gboolean        (*unprepare)       (GstRTSPMedia *media);
158   void            (*handle_mtu)      (GstRTSPMedia *media, guint mtu);
159
160   /* signals */
161   gboolean        (*prepared)        (GstRTSPMedia *media);
162   gboolean        (*unprepared)      (GstRTSPMedia *media);
163
164   gboolean        (*new_state)       (GstRTSPMedia *media, GstState state);
165 };
166
167 GType                 gst_rtsp_media_get_type         (void);
168
169 /* creating the media */
170 GstRTSPMedia *        gst_rtsp_media_new              (void);
171
172 void                  gst_rtsp_media_set_shared       (GstRTSPMedia *media, gboolean shared);
173 gboolean              gst_rtsp_media_is_shared        (GstRTSPMedia *media);
174
175 void                  gst_rtsp_media_set_reusable     (GstRTSPMedia *media, gboolean reusable);
176 gboolean              gst_rtsp_media_is_reusable      (GstRTSPMedia *media);
177
178 void                  gst_rtsp_media_set_protocols    (GstRTSPMedia *media, GstRTSPLowerTrans protocols);
179 GstRTSPLowerTrans     gst_rtsp_media_get_protocols    (GstRTSPMedia *media);
180
181 void                  gst_rtsp_media_set_eos_shutdown (GstRTSPMedia *media, gboolean eos_shutdown);
182 gboolean              gst_rtsp_media_is_eos_shutdown  (GstRTSPMedia *media);
183
184 void                  gst_rtsp_media_set_auth         (GstRTSPMedia *media, GstRTSPAuth *auth);
185 GstRTSPAuth *         gst_rtsp_media_get_auth         (GstRTSPMedia *media);
186
187 void                  gst_rtsp_media_set_buffer_size  (GstRTSPMedia *media, guint size);
188 guint                 gst_rtsp_media_get_buffer_size  (GstRTSPMedia *media);
189
190 void                  gst_rtsp_media_set_multicast_group (GstRTSPMedia *media, const gchar * mc);
191 gchar *               gst_rtsp_media_get_multicast_group (GstRTSPMedia *media);
192
193
194 /* prepare the media for playback */
195 gboolean              gst_rtsp_media_prepare          (GstRTSPMedia *media);
196 gboolean              gst_rtsp_media_is_prepared      (GstRTSPMedia *media);
197 gboolean              gst_rtsp_media_unprepare        (GstRTSPMedia *media);
198
199 /* creating streams */
200 void                  gst_rtsp_media_collect_streams  (GstRTSPMedia *media);
201 GstRTSPStream *       gst_rtsp_media_create_stream    (GstRTSPMedia *media,
202                                                        GstElement *payloader,
203                                                        GstPad *srcpad);
204
205 /* dealing with the media */
206 guint                 gst_rtsp_media_n_streams        (GstRTSPMedia *media);
207 GstRTSPStream *       gst_rtsp_media_get_stream       (GstRTSPMedia *media, guint idx);
208
209 gboolean              gst_rtsp_media_seek             (GstRTSPMedia *media, GstRTSPTimeRange *range);
210 gchar *               gst_rtsp_media_get_range_string (GstRTSPMedia *media, gboolean play);
211
212 gboolean              gst_rtsp_media_set_state        (GstRTSPMedia *media, GstState state,
213                                                        GPtrArray *transports);
214
215 void                  gst_rtsp_media_handle_mtu       (GstRTSPMedia *media, guint mtu);
216
217 G_END_DECLS
218
219 #endif /* __GST_RTSP_MEDIA_H__ */