2 * Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
4 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 * * Modifications by Samsung Electronics Co., Ltd.
24 * 1. Applied Miracast WFD Server function
28 #include <gst/rtsp/gstrtsprange.h>
29 #include <gst/rtsp/gstrtspurl.h>
31 #ifndef __GST_RTSP_MEDIA_H__
32 #define __GST_RTSP_MEDIA_H__
36 /* types for the media */
37 #define GST_TYPE_RTSP_MEDIA (gst_rtsp_media_get_type ())
38 #define GST_IS_RTSP_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_MEDIA))
39 #define GST_IS_RTSP_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_MEDIA))
40 #define GST_RTSP_MEDIA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_MEDIA, GstRTSPMediaClass))
41 #define GST_RTSP_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_MEDIA, GstRTSPMedia))
42 #define GST_RTSP_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_MEDIA, GstRTSPMediaClass))
43 #define GST_RTSP_MEDIA_CAST(obj) ((GstRTSPMedia*)(obj))
44 #define GST_RTSP_MEDIA_CLASS_CAST(klass) ((GstRTSPMediaClass*)(klass))
46 typedef struct _GstRTSPMediaStream GstRTSPMediaStream;
47 typedef struct _GstRTSPMedia GstRTSPMedia;
48 typedef struct _GstRTSPMediaClass GstRTSPMediaClass;
49 typedef struct _GstRTSPMediaTrans GstRTSPMediaTrans;
51 typedef gboolean (*GstRTSPSendFunc) (GstBuffer *buffer, guint8 channel, gpointer user_data);
52 typedef gboolean (*GstRTSPSendListFunc) (GstBufferList *blist, guint8 channel, gpointer user_data);
53 typedef void (*GstRTSPKeepAliveFunc) (gpointer user_data);
57 * @idx: a stream index
58 * @send_rtp: callback for sending RTP messages
59 * @send_rtcp: callback for sending RTCP messages
60 * @send_rtp_list: callback for sending RTP messages
61 * @send_rtcp_list: callback for sending RTCP messages
62 * @user_data: user data passed in the callbacks
63 * @notify: free function for the user_data.
64 * @keep_alive: keep alive callback
65 * @ka_user_data: data passed to @keep_alive
66 * @ka_notify: called when @ka_user_data is freed
67 * @active: if we are actively sending
68 * @timeout: if we timed out
69 * @transport: a transport description
70 * @rtpsource: the receiver rtp source object
72 * A Transport description for stream @idx
74 struct _GstRTSPMediaTrans {
77 GstRTSPSendFunc send_rtp;
78 GstRTSPSendFunc send_rtcp;
79 GstRTSPSendListFunc send_rtp_list;
80 GstRTSPSendListFunc send_rtcp_list;
82 GDestroyNotify notify;
84 GstRTSPKeepAliveFunc keep_alive;
85 gpointer ka_user_data;
86 GDestroyNotify ka_notify;
90 GstRTSPTransport *transport;
95 #include "rtsp-auth.h"
99 * @srcpad: the srcpad of the stream
100 * @payloader: the payloader of the format
101 * @prepared: if the stream is prepared for streaming
102 * @recv_rtp_sink: sinkpad for RTP buffers
103 * @recv_rtcp_sink: sinkpad for RTCP buffers
104 * @send_rtp_src: srcpad for RTP buffers
105 * @send_rtcp_src: srcpad for RTCP buffers
106 * @udpsrc: the udp source elements for RTP/RTCP
107 * @udpsink: the udp sink elements for RTP/RTCP
108 * @appsrc: the app source elements for RTP/RTCP
109 * @appsink: the app sink elements for RTP/RTCP
110 * @server_port: the server ports for this stream
111 * @caps_sig: the signal id for detecting caps
112 * @caps: the caps of the stream
113 * @tranports: the current transports being streamed
115 * The definition of a media stream. The streams are identified by @id.
117 struct _GstRTSPMediaStream {
119 GstElement *payloader;
122 /* pads on the rtpbin */
123 GstPad *recv_rtcp_sink;
124 GstPad *recv_rtp_sink;
125 GstPad *send_rtp_sink;
126 GstPad *send_rtp_src;
127 GstPad *send_rtcp_src;
129 /* the RTPSession object */
132 /* sinks used for sending and receiving RTP and RTCP, they share
134 GstElement *udpsrc[2];
135 GstElement *udpsink[2];
136 /* for TCP transport */
137 GstElement *appsrc[2];
138 GstElement *appsink[2];
141 GstElement *selector[2];
143 /* server ports for sending/receiving */
144 GstRTSPRange server_port;
146 /* the caps of the stream */
150 /* transports we stream to */
153 /* to filter out duplicate destinations in case multiudpsink is too old to do
155 gboolean filter_duplicates;
160 * GstRTSPMediaStatus:
161 * @GST_RTSP_MEDIA_STATUS_UNPREPARED: media pipeline not prerolled
162 * @GST_RTSP_MEDIA_STATUS_PREPARING: media pipeline is prerolling
163 * @GST_RTSP_MEDIA_STATUS_PREPARED: media pipeline is prerolled
164 * @GST_RTSP_MEDIA_STATUS_ERROR: media pipeline is in error
166 * The state of the media pipeline.
169 GST_RTSP_MEDIA_STATUS_UNPREPARED = 0,
170 GST_RTSP_MEDIA_STATUS_PREPARING = 1,
171 GST_RTSP_MEDIA_STATUS_PREPARED = 2,
172 GST_RTSP_MEDIA_STATUS_ERROR = 3
173 } GstRTSPMediaStatus;
177 * @lock: for protecting the object
178 * @cond: for signaling the object
179 * @shared: if this media can be shared between clients
180 * @reusable: if this media can be reused after an unprepare
181 * @protocols: the allowed lower transport for this stream
182 * @reused: if this media has been reused
183 * @is_ipv6: if this media is using ipv6
184 * @element: the data providing element
185 * @streams: the different streams provided by @element
186 * @dynamic: list of dynamic elements managed by @element
187 * @status: the status of the media pipeline
188 * @active: the number of active connections
189 * @pipeline: the toplevel pipeline
190 * @fakesink: for making state changes async
191 * @source: the bus watch for pipeline messages.
192 * @id: the id of the watch
193 * @is_live: if the pipeline is live
194 * @buffering: if the pipeline is buffering
195 * @target_state: the desired target state of the pipeline
196 * @rtpbin: the rtpbin
197 * @range: the range of the media being streamed
199 * A class that contains the GStreamer element along with a list of
200 * #GstRTSPMediaStream objects that can produce data.
202 * This object is usually created from a #GstRTSPMediaFactory.
204 struct _GstRTSPMedia {
212 GstRTSPLowerTrans protocols;
215 gboolean eos_shutdown;
221 GstRTSPMediaStatus status;
223 gboolean eos_pending;
226 /* the pipeline for the media */
227 GstElement *pipeline;
228 GstElement *fakesink;
234 GstState target_state;
236 /* RTP session manager */
239 /* the range of media */
240 GstRTSPTimeRange range;
245 * @context: the main context for dispatching messages
246 * @loop: the mainloop for message.
247 * @thread: the thread dispatching messages.
248 * @handle_message: handle a message
249 * @unprepare: the default implementation sets the pipeline's state
252 * The RTSP media class
254 struct _GstRTSPMediaClass {
255 GObjectClass parent_class;
257 /* thread for the mainloop */
258 GMainContext *context;
263 gboolean (*handle_message) (GstRTSPMedia *media, GstMessage *message);
264 gboolean (*unprepare) (GstRTSPMedia *media);
267 gboolean (*prepared) (GstRTSPMedia *media);
268 gboolean (*unprepared) (GstRTSPMedia *media);
270 gboolean (*new_state) (GstRTSPMedia *media, GstState state);
273 GType gst_rtsp_media_get_type (void);
275 /* creating the media */
276 GstRTSPMedia * gst_rtsp_media_new (void);
278 void gst_rtsp_media_set_shared (GstRTSPMedia *media, gboolean shared);
279 gboolean gst_rtsp_media_is_shared (GstRTSPMedia *media);
281 void gst_rtsp_media_set_reusable (GstRTSPMedia *media, gboolean reusable);
282 gboolean gst_rtsp_media_is_reusable (GstRTSPMedia *media);
284 void gst_rtsp_media_set_protocols (GstRTSPMedia *media, GstRTSPLowerTrans protocols);
285 GstRTSPLowerTrans gst_rtsp_media_get_protocols (GstRTSPMedia *media);
287 void gst_rtsp_media_set_eos_shutdown (GstRTSPMedia *media, gboolean eos_shutdown);
288 gboolean gst_rtsp_media_is_eos_shutdown (GstRTSPMedia *media);
290 void gst_rtsp_media_set_auth (GstRTSPMedia *media, GstRTSPAuth *auth);
291 GstRTSPAuth * gst_rtsp_media_get_auth (GstRTSPMedia *media);
293 /* prepare the media for playback */
294 gboolean gst_rtsp_media_prepare (GstRTSPMedia *media);
295 gboolean gst_rtsp_media_is_prepared (GstRTSPMedia *media);
296 gboolean gst_rtsp_media_unprepare (GstRTSPMedia *media);
298 /* dealing with the media */
299 guint gst_rtsp_media_n_streams (GstRTSPMedia *media);
300 GstRTSPMediaStream * gst_rtsp_media_get_stream (GstRTSPMedia *media, guint idx);
302 gboolean gst_rtsp_media_seek (GstRTSPMedia *media, GstRTSPTimeRange *range);
303 gchar * gst_rtsp_media_get_range_string (GstRTSPMedia *media, gboolean play);
305 GstFlowReturn gst_rtsp_media_stream_rtp (GstRTSPMediaStream *stream, GstBuffer *buffer);
306 GstFlowReturn gst_rtsp_media_stream_rtcp (GstRTSPMediaStream *stream, GstBuffer *buffer);
308 gboolean gst_rtsp_media_set_state (GstRTSPMedia *media, GstState state, GArray *transports);
310 void gst_rtsp_media_remove_elements (GstRTSPMedia *media);
312 void gst_rtsp_media_trans_cleanup (GstRTSPMediaTrans *trans);
316 #endif /* __GST_RTSP_MEDIA_H__ */