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