Handle media bus messages
[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 /**
45  * GstRTSPMediaTrans:
46  * @idx: a stream index
47  * @transport: a transport description
48  *
49  * A Transport description for stream @idx
50  */
51 struct _GstRTSPMediaTrans {
52   guint idx;
53
54   GstRTSPTransport *transport;
55 };
56
57 /**
58  * GstRTSPMediaStream:
59  *
60  * @media: the owner #GstRTSPMedia
61  * @srcpad: the srcpad of the stream
62  * @payloader: the payloader of the format
63  * @prepared: if the stream is prepared for streaming
64  * @server_port: the server udp ports
65  * @recv_rtp_sink: sinkpad for RTP buffers
66  * @recv_rtcp_sink: sinkpad for RTCP buffers
67  * @recv_rtp_src: srcpad for RTP buffers
68  * @recv_rtcp_src: srcpad for RTCP buffers
69  * @udpsrc: the udp source elements for RTP/RTCP
70  * @udpsink: the udp sink elements for RTP/RTCP
71  * @caps_sig: the signal id for detecting caps
72  * @caps: the caps of the stream
73  *
74  * The definition of a media stream. The streams are identified by @id.
75  */
76 struct _GstRTSPMediaStream {
77   GstPad       *srcpad;
78   GstElement   *payloader;
79   gboolean      prepared;
80
81   /* pads on the rtpbin */
82   GstPad       *recv_rtcp_sink;
83   GstPad       *send_rtp_sink;
84   GstPad       *send_rtp_src;
85   GstPad       *send_rtcp_src;
86
87   /* sinks used for sending and receiving RTP and RTCP, they share
88    * sockets */
89   GstElement   *udpsrc[2];
90   GstElement   *udpsink[2];
91
92   /* server ports for sending/receiving */
93   GstRTSPRange  server_port;
94
95   /* the caps of the stream */
96   gulong        caps_sig;
97   GstCaps      *caps;
98 };
99
100 /**
101  * GstRTSPMedia:
102  * @shared: if this media can be shared between clients
103  * @element: the data providing element
104  * @stream: the different streams provided by @element
105  * @prepared: if the media is prepared for streaming
106  * @pipeline: the toplevel pipeline
107  * @rtpbin: the rtpbin
108  * @multifdsink: multifdsink element for TCP transport
109  *
110  * A class that contains the GStreamer element along with a list of
111  * #GstRTSPediaStream objects that can produce data.
112  *
113  * This object is usually created from a #GstRTSPMediaFactory.
114  */
115 struct _GstRTSPMedia {
116   GObject       parent;
117
118   gboolean      shared;
119   gboolean      complete;
120
121   GstElement   *element;
122   GArray       *streams;
123   gboolean      prepared;
124
125   /* the pipeline for the media */
126   GstElement   *pipeline;
127   GSource      *source;
128   guint         id;
129
130   gboolean      is_live;
131   gboolean      buffering;
132   GstState      target_state;
133
134   /* RTP session manager */
135   GstElement   *rtpbin;
136
137   /* for TCP transport */
138   GstElement   *multifdsink;
139
140   /* the range of media */
141   GstRTSPTimeRange range;
142 };
143
144 /**
145  * GstRTSPMediaClass:
146  * @context: the main context for dispatching messages
147  * @loop: the mainloop for message.
148  * @thread: the thread dispatching messages.
149  * @handle_message: handle a message
150  *
151  * The RTSP media class
152  */
153 struct _GstRTSPMediaClass {
154   GObjectClass  parent_class;
155
156   /* thread for the mainloop */
157   GMainContext *context;
158   GMainLoop    *loop;
159   GThread      *thread;
160
161   gboolean     (*handle_message)  (GstRTSPMedia *media, GstMessage *message);
162 };
163
164 GType                 gst_rtsp_media_get_type         (void);
165
166 /* creating the media */
167 GstRTSPMedia *        gst_rtsp_media_new              (void);
168
169 void                  gst_rtsp_media_set_shared       (GstRTSPMedia *media, gboolean shared);
170 gboolean              gst_rtsp_media_is_shared        (GstRTSPMedia *media);
171
172 /* prepare the media for playback */
173 gboolean              gst_rtsp_media_prepare          (GstRTSPMedia *media);
174
175 /* dealing with the media */
176 guint                 gst_rtsp_media_n_streams        (GstRTSPMedia *media);
177 GstRTSPMediaStream *  gst_rtsp_media_get_stream       (GstRTSPMedia *media, guint idx);
178
179 gboolean              gst_rtsp_media_play             (GstRTSPMedia *media, GArray *trans);
180 gboolean              gst_rtsp_media_pause            (GstRTSPMedia *media, GArray *trans);
181 gboolean              gst_rtsp_media_stop             (GstRTSPMedia *media, GArray *trans);
182
183 G_END_DECLS
184
185 #endif /* __GST_RTSP_MEDIA_H__ */