Rework the way we handle transports for streams
[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/gstrtspurl.h>
22
23 #ifndef __GST_RTSP_MEDIA_H__
24 #define __GST_RTSP_MEDIA_H__
25
26 G_BEGIN_DECLS
27
28 /* types for the media */
29 #define GST_TYPE_RTSP_MEDIA              (gst_rtsp_media_get_type ())
30 #define GST_IS_RTSP_MEDIA(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_MEDIA))
31 #define GST_IS_RTSP_MEDIA_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_MEDIA))
32 #define GST_RTSP_MEDIA_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_MEDIA, GstRTSPMediaClass))
33 #define GST_RTSP_MEDIA(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_MEDIA, GstRTSPMedia))
34 #define GST_RTSP_MEDIA_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_MEDIA, GstRTSPMediaClass))
35 #define GST_RTSP_MEDIA_CAST(obj)         ((GstRTSPMedia*)(obj))
36 #define GST_RTSP_MEDIA_CLASS_CAST(klass) ((GstRTSPMediaClass*)(klass))
37
38 typedef struct _GstRTSPMediaStream GstRTSPMediaStream;
39 typedef struct _GstRTSPMedia GstRTSPMedia;
40 typedef struct _GstRTSPMediaClass GstRTSPMediaClass;
41 typedef struct _GstRTSPMediaTrans GstRTSPMediaTrans;
42
43 /**
44  * GstRTSPMediaTrans:
45  * @idx: a stream index
46  * @transport: a transport description
47  *
48  * A Transport description for stream @idx
49  */
50 struct _GstRTSPMediaTrans {
51   guint idx;
52
53   GstRTSPTransport *transport;
54 };
55
56 /**
57  * GstRTSPMediaStream:
58  *
59  * @media: the owner #GstRTSPMedia
60  * @srcpad: the srcpad of the stream
61  * @payloader: the payloader of the format
62  * @prepared: if the stream is prepared for streaming
63  * @server_port: the server udp ports
64  * @recv_rtp_sink: sinkpad for RTP buffers
65  * @recv_rtcp_sink: sinkpad for RTCP buffers
66  * @recv_rtp_src: srcpad for RTP buffers
67  * @recv_rtcp_src: srcpad for RTCP buffers
68  * @udpsrc: the udp source elements for RTP/RTCP
69  * @udpsink: the udp sink elements for RTP/RTCP
70  * @caps_sig: the signal id for detecting caps
71  * @caps: the caps of the stream
72  *
73  * The definition of a media stream. The streams are identified by @id.
74  */
75 struct _GstRTSPMediaStream {
76   GstPad       *srcpad;
77   GstElement   *payloader;
78   gboolean      prepared;
79
80   /* pads on the rtpbin */
81   GstPad       *recv_rtcp_sink;
82   GstPad       *send_rtp_sink;
83   GstPad       *send_rtp_src;
84   GstPad       *send_rtcp_src;
85
86   /* sinks used for sending and receiving RTP and RTCP, they share
87    * sockets */
88   GstElement   *udpsrc[2];
89   GstElement   *udpsink[2];
90
91   /* server ports for sending/receiving */
92   GstRTSPRange  server_port;
93
94   /* the caps of the stream */
95   gulong        caps_sig;
96   GstCaps      *caps;
97 };
98
99 /**
100  * GstRTSPMedia:
101  * @shared: if this media can be shared between clients
102  * @element: the data providing element
103  * @stream: the different streams provided by @element
104  * @prepared: if the media is prepared for streaming
105  * @pipeline: the toplevel pipeline
106  * @rtpbin: the rtpbin
107  * @multifdsink: multifdsink element for TCP transport
108  *
109  * A class that contains the GStreamer element along with a list of
110  * #GstRTSPediaStream objects that can produce data.
111  *
112  * This object is usually created from a #GstRTSPMediaFactory.
113  */
114 struct _GstRTSPMedia {
115   GObject       parent;
116
117   gboolean      shared;
118   gboolean      complete;
119
120   GstElement   *element;
121   GArray       *streams;
122   gboolean      prepared;
123
124   /* the pipeline for the media */
125   GstElement   *pipeline;
126
127   /* RTP session manager */
128   GstElement   *rtpbin;
129
130   /* for TCP transport */
131   GstElement   *multifdsink;
132 };
133
134 struct _GstRTSPMediaClass {
135   GObjectClass  parent_class;
136 };
137
138 GType                 gst_rtsp_media_get_type         (void);
139
140 /* creating the media */
141 GstRTSPMedia *        gst_rtsp_media_new              (void);
142
143 void                  gst_rtsp_media_set_shared       (GstRTSPMedia *media, gboolean shared);
144 gboolean              gst_rtsp_media_is_shared        (GstRTSPMedia *media);
145
146 /* prepare the media for playback */
147 gboolean              gst_rtsp_media_prepare          (GstRTSPMedia *media);
148
149 /* dealing with the media */
150 guint                 gst_rtsp_media_n_streams        (GstRTSPMedia *media);
151 GstRTSPMediaStream *  gst_rtsp_media_get_stream       (GstRTSPMedia *media, guint idx);
152
153 gboolean              gst_rtsp_media_play             (GstRTSPMedia *media, GArray *trans);
154 gboolean              gst_rtsp_media_pause            (GstRTSPMedia *media, GArray *trans);
155 gboolean              gst_rtsp_media_stop             (GstRTSPMedia *media, GArray *trans);
156
157 G_END_DECLS
158
159 #endif /* __GST_RTSP_MEDIA_H__ */