2008-10-09 12:29:12 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2009-02-04 16:00:42 +00:00
|
|
|
#include <gst/rtsp/gstrtsprange.h>
|
2008-10-09 12:29:12 +00:00
|
|
|
#include <gst/rtsp/gstrtspurl.h>
|
|
|
|
|
|
|
|
#ifndef __GST_RTSP_MEDIA_H__
|
|
|
|
#define __GST_RTSP_MEDIA_H__
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
/* types for the media */
|
|
|
|
#define GST_TYPE_RTSP_MEDIA (gst_rtsp_media_get_type ())
|
|
|
|
#define GST_IS_RTSP_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_MEDIA))
|
|
|
|
#define GST_IS_RTSP_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_MEDIA))
|
|
|
|
#define GST_RTSP_MEDIA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_MEDIA, GstRTSPMediaClass))
|
|
|
|
#define GST_RTSP_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_MEDIA, GstRTSPMedia))
|
|
|
|
#define GST_RTSP_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_MEDIA, GstRTSPMediaClass))
|
|
|
|
#define GST_RTSP_MEDIA_CAST(obj) ((GstRTSPMedia*)(obj))
|
|
|
|
#define GST_RTSP_MEDIA_CLASS_CAST(klass) ((GstRTSPMediaClass*)(klass))
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
typedef struct _GstRTSPMediaStream GstRTSPMediaStream;
|
2009-01-22 16:58:19 +00:00
|
|
|
typedef struct _GstRTSPMedia GstRTSPMedia;
|
|
|
|
typedef struct _GstRTSPMediaClass GstRTSPMediaClass;
|
2009-02-03 18:32:38 +00:00
|
|
|
typedef struct _GstRTSPMediaTrans GstRTSPMediaTrans;
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
typedef gboolean (*GstRTSPSendFunc) (GstBuffer *buffer, guint8 channel, gpointer user_data);
|
|
|
|
typedef void (*GstRTSPKeepAliveFunc) (gpointer user_data);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2009-02-03 18:32:38 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPMediaTrans:
|
|
|
|
* @idx: a stream index
|
2009-03-11 15:45:12 +00:00
|
|
|
* @send_rtp: callback for sending RTP messages
|
|
|
|
* @send_rtcp: callback for sending RTCP messages
|
2010-12-30 11:41:31 +00:00
|
|
|
* @send_rtp_list: callback for sending RTP messages
|
|
|
|
* @send_rtcp_list: callback for sending RTCP messages
|
2009-03-11 15:45:12 +00:00
|
|
|
* @user_data: user data passed in the callbacks
|
|
|
|
* @notify: free function for the user_data.
|
2009-05-26 17:01:10 +00:00
|
|
|
* @keep_alive: keep alive callback
|
|
|
|
* @ka_user_data: data passed to @keep_alive
|
|
|
|
* @ka_notify: called when @ka_user_data is freed
|
|
|
|
* @active: if we are actively sending
|
|
|
|
* @timeout: if we timed out
|
2009-02-03 18:32:38 +00:00
|
|
|
* @transport: a transport description
|
2009-05-26 17:01:10 +00:00
|
|
|
* @rtpsource: the receiver rtp source object
|
2009-02-03 18:32:38 +00:00
|
|
|
*
|
|
|
|
* A Transport description for stream @idx
|
|
|
|
*/
|
|
|
|
struct _GstRTSPMediaTrans {
|
|
|
|
guint idx;
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
GstRTSPSendFunc send_rtp;
|
|
|
|
GstRTSPSendFunc send_rtcp;
|
|
|
|
gpointer user_data;
|
|
|
|
GDestroyNotify notify;
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
GstRTSPKeepAliveFunc keep_alive;
|
|
|
|
gpointer ka_user_data;
|
|
|
|
GDestroyNotify ka_notify;
|
|
|
|
gboolean active;
|
|
|
|
gboolean timeout;
|
|
|
|
|
|
|
|
GstRTSPTransport *transport;
|
|
|
|
|
|
|
|
GObject *rtpsource;
|
2009-02-03 18:32:38 +00:00
|
|
|
};
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2011-01-12 12:57:09 +00:00
|
|
|
#include "rtsp-auth.h"
|
|
|
|
|
2009-01-20 18:43:47 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPMediaStream:
|
|
|
|
* @srcpad: the srcpad of the stream
|
2009-01-22 16:58:19 +00:00
|
|
|
* @payloader: the payloader of the format
|
2009-01-29 12:31:27 +00:00
|
|
|
* @prepared: if the stream is prepared for streaming
|
|
|
|
* @recv_rtp_sink: sinkpad for RTP buffers
|
|
|
|
* @recv_rtcp_sink: sinkpad for RTCP buffers
|
2011-01-07 21:45:32 +00:00
|
|
|
* @send_rtp_src: srcpad for RTP buffers
|
|
|
|
* @send_rtcp_src: srcpad for RTCP buffers
|
2009-01-29 12:31:27 +00:00
|
|
|
* @udpsrc: the udp source elements for RTP/RTCP
|
|
|
|
* @udpsink: the udp sink elements for RTP/RTCP
|
2009-03-11 15:45:12 +00:00
|
|
|
* @appsrc: the app source elements for RTP/RTCP
|
|
|
|
* @appsink: the app sink elements for RTP/RTCP
|
|
|
|
* @server_port: the server ports for this stream
|
2009-01-20 18:43:47 +00:00
|
|
|
* @caps_sig: the signal id for detecting caps
|
|
|
|
* @caps: the caps of the stream
|
2009-03-11 15:45:12 +00:00
|
|
|
* @tranports: the current transports being streamed
|
2009-01-20 18:43:47 +00:00
|
|
|
*
|
|
|
|
* The definition of a media stream. The streams are identified by @id.
|
|
|
|
*/
|
2008-10-09 12:29:12 +00:00
|
|
|
struct _GstRTSPMediaStream {
|
2009-01-29 12:31:27 +00:00
|
|
|
GstPad *srcpad;
|
|
|
|
GstElement *payloader;
|
|
|
|
gboolean prepared;
|
|
|
|
|
|
|
|
/* pads on the rtpbin */
|
|
|
|
GstPad *recv_rtcp_sink;
|
2009-05-15 15:58:44 +00:00
|
|
|
GstPad *recv_rtp_sink;
|
2009-01-29 12:31:27 +00:00
|
|
|
GstPad *send_rtp_sink;
|
|
|
|
GstPad *send_rtp_src;
|
|
|
|
GstPad *send_rtcp_src;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-13 18:54:18 +00:00
|
|
|
/* the RTPSession object */
|
|
|
|
GObject *session;
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/* sinks used for sending and receiving RTP and RTCP, they share
|
|
|
|
* sockets */
|
|
|
|
GstElement *udpsrc[2];
|
|
|
|
GstElement *udpsink[2];
|
2009-03-11 15:45:12 +00:00
|
|
|
/* for TCP transport */
|
2009-03-06 18:34:14 +00:00
|
|
|
GstElement *appsrc[2];
|
2011-12-09 09:53:30 +00:00
|
|
|
GstElement *appqueue[2];
|
2009-03-11 15:45:12 +00:00
|
|
|
GstElement *appsink[2];
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-05-24 17:34:52 +00:00
|
|
|
GstElement *tee[2];
|
2009-05-15 15:58:44 +00:00
|
|
|
GstElement *selector[2];
|
|
|
|
|
2009-01-30 15:24:10 +00:00
|
|
|
/* server ports for sending/receiving */
|
|
|
|
GstRTSPRange server_port;
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/* the caps of the stream */
|
|
|
|
gulong caps_sig;
|
|
|
|
GstCaps *caps;
|
2009-03-11 15:45:12 +00:00
|
|
|
|
|
|
|
/* transports we stream to */
|
|
|
|
GList *transports;
|
2008-10-09 12:29:12 +00:00
|
|
|
};
|
|
|
|
|
2010-03-05 16:51:26 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPMediaStatus:
|
|
|
|
* @GST_RTSP_MEDIA_STATUS_UNPREPARED: media pipeline not prerolled
|
|
|
|
* @GST_RTSP_MEDIA_STATUS_PREPARING: media pipeline is prerolling
|
|
|
|
* @GST_RTSP_MEDIA_STATUS_PREPARED: media pipeline is prerolled
|
|
|
|
* @GST_RTSP_MEDIA_STATUS_ERROR: media pipeline is in error
|
|
|
|
*
|
|
|
|
* The state of the media pipeline.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
GST_RTSP_MEDIA_STATUS_UNPREPARED = 0,
|
|
|
|
GST_RTSP_MEDIA_STATUS_PREPARING = 1,
|
|
|
|
GST_RTSP_MEDIA_STATUS_PREPARED = 2,
|
|
|
|
GST_RTSP_MEDIA_STATUS_ERROR = 3
|
|
|
|
} GstRTSPMediaStatus;
|
|
|
|
|
2009-01-20 18:43:47 +00:00
|
|
|
/**
|
2009-01-22 16:58:19 +00:00
|
|
|
* GstRTSPMedia:
|
2010-03-09 12:44:20 +00:00
|
|
|
* @lock: for protecting the object
|
|
|
|
* @cond: for signaling the object
|
2009-01-29 16:20:27 +00:00
|
|
|
* @shared: if this media can be shared between clients
|
2009-04-03 20:22:30 +00:00
|
|
|
* @reusable: if this media can be reused after an unprepare
|
2010-03-19 14:15:29 +00:00
|
|
|
* @protocols: the allowed lower transport for this stream
|
2010-03-09 12:44:20 +00:00
|
|
|
* @reused: if this media has been reused
|
2010-03-19 14:15:29 +00:00
|
|
|
* @is_ipv6: if this media is using ipv6
|
2009-01-29 12:31:27 +00:00
|
|
|
* @element: the data providing element
|
2009-03-11 15:45:12 +00:00
|
|
|
* @streams: the different streams provided by @element
|
2010-03-09 12:44:20 +00:00
|
|
|
* @dynamic: list of dynamic elements managed by @element
|
2010-03-05 16:51:26 +00:00
|
|
|
* @status: the status of the media pipeline
|
2010-03-09 12:44:20 +00:00
|
|
|
* @active: the number of active connections
|
2009-01-29 12:31:27 +00:00
|
|
|
* @pipeline: the toplevel pipeline
|
2010-03-09 12:44:20 +00:00
|
|
|
* @fakesink: for making state changes async
|
2009-03-11 15:45:12 +00:00
|
|
|
* @source: the bus watch for pipeline messages.
|
|
|
|
* @id: the id of the watch
|
|
|
|
* @is_live: if the pipeline is live
|
2011-11-03 11:55:24 +00:00
|
|
|
* @seekable: if the pipeline can perform a seek
|
2009-03-11 15:45:12 +00:00
|
|
|
* @buffering: if the pipeline is buffering
|
|
|
|
* @target_state: the desired target state of the pipeline
|
2009-01-29 12:31:27 +00:00
|
|
|
* @rtpbin: the rtpbin
|
2009-03-11 15:45:12 +00:00
|
|
|
* @range: the range of the media being streamed
|
2009-01-20 18:43:47 +00:00
|
|
|
*
|
2009-01-22 17:35:17 +00:00
|
|
|
* A class that contains the GStreamer element along with a list of
|
2010-12-11 09:48:25 +00:00
|
|
|
* #GstRTSPMediaStream objects that can produce data.
|
2009-01-22 17:35:17 +00:00
|
|
|
*
|
|
|
|
* This object is usually created from a #GstRTSPMediaFactory.
|
2009-01-20 18:43:47 +00:00
|
|
|
*/
|
2009-01-22 16:58:19 +00:00
|
|
|
struct _GstRTSPMedia {
|
2010-03-05 16:51:26 +00:00
|
|
|
GObject parent;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-05-11 07:42:47 +00:00
|
|
|
GMutex lock;
|
|
|
|
GCond cond;
|
2009-01-29 16:20:27 +00:00
|
|
|
|
2010-03-05 16:51:26 +00:00
|
|
|
gboolean shared;
|
|
|
|
gboolean reusable;
|
2010-03-19 14:15:29 +00:00
|
|
|
GstRTSPLowerTrans protocols;
|
2010-03-05 16:51:26 +00:00
|
|
|
gboolean reused;
|
2010-03-16 17:37:18 +00:00
|
|
|
gboolean is_ipv6;
|
2010-08-20 16:17:08 +00:00
|
|
|
gboolean eos_shutdown;
|
2011-01-31 16:28:22 +00:00
|
|
|
guint buffer_size;
|
2011-01-12 12:57:09 +00:00
|
|
|
GstRTSPAuth *auth;
|
2011-08-16 11:25:16 +00:00
|
|
|
gchar *multicast_group;
|
2010-03-05 16:51:26 +00:00
|
|
|
|
|
|
|
GstElement *element;
|
|
|
|
GArray *streams;
|
|
|
|
GList *dynamic;
|
|
|
|
GstRTSPMediaStatus status;
|
|
|
|
gint active;
|
2010-08-20 16:17:08 +00:00
|
|
|
gboolean eos_pending;
|
2010-12-11 16:31:44 +00:00
|
|
|
gboolean adding;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
|
|
|
/* the pipeline for the media */
|
2010-03-05 16:51:26 +00:00
|
|
|
GstElement *pipeline;
|
|
|
|
GstElement *fakesink;
|
|
|
|
GSource *source;
|
|
|
|
guint id;
|
2009-02-13 15:39:36 +00:00
|
|
|
|
2010-03-05 16:51:26 +00:00
|
|
|
gboolean is_live;
|
2011-11-03 11:55:24 +00:00
|
|
|
gboolean seekable;
|
2010-03-05 16:51:26 +00:00
|
|
|
gboolean buffering;
|
|
|
|
GstState target_state;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
|
|
|
/* RTP session manager */
|
2010-03-05 16:51:26 +00:00
|
|
|
GstElement *rtpbin;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-02-04 16:00:42 +00:00
|
|
|
/* the range of media */
|
2010-03-05 16:51:26 +00:00
|
|
|
GstRTSPTimeRange range;
|
2008-10-09 12:29:12 +00:00
|
|
|
};
|
|
|
|
|
2009-02-13 15:39:36 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPMediaClass:
|
|
|
|
* @context: the main context for dispatching messages
|
|
|
|
* @loop: the mainloop for message.
|
|
|
|
* @thread: the thread dispatching messages.
|
|
|
|
* @handle_message: handle a message
|
2009-06-12 16:05:30 +00:00
|
|
|
* @unprepare: the default implementation sets the pipeline's state
|
|
|
|
* to GST_STATE_NULL.
|
2009-02-13 15:39:36 +00:00
|
|
|
*
|
|
|
|
* The RTSP media class
|
|
|
|
*/
|
2009-01-22 16:58:19 +00:00
|
|
|
struct _GstRTSPMediaClass {
|
2008-10-09 12:29:12 +00:00
|
|
|
GObjectClass parent_class;
|
2009-02-13 15:39:36 +00:00
|
|
|
|
|
|
|
/* thread for the mainloop */
|
|
|
|
GMainContext *context;
|
|
|
|
GMainLoop *loop;
|
|
|
|
GThread *thread;
|
|
|
|
|
2009-04-03 20:45:57 +00:00
|
|
|
/* vmethods */
|
2009-02-13 15:39:36 +00:00
|
|
|
gboolean (*handle_message) (GstRTSPMedia *media, GstMessage *message);
|
2009-06-12 16:05:30 +00:00
|
|
|
gboolean (*unprepare) (GstRTSPMedia *media);
|
2009-04-03 20:45:57 +00:00
|
|
|
|
|
|
|
/* signals */
|
2010-12-13 15:58:36 +00:00
|
|
|
gboolean (*prepared) (GstRTSPMedia *media);
|
2009-04-03 20:45:57 +00:00
|
|
|
gboolean (*unprepared) (GstRTSPMedia *media);
|
2010-12-28 17:34:10 +00:00
|
|
|
|
|
|
|
gboolean (*new_state) (GstRTSPMedia *media, GstState state);
|
2008-10-09 12:29:12 +00:00
|
|
|
};
|
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
GType gst_rtsp_media_get_type (void);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/* creating the media */
|
|
|
|
GstRTSPMedia * gst_rtsp_media_new (void);
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
void gst_rtsp_media_set_shared (GstRTSPMedia *media, gboolean shared);
|
|
|
|
gboolean gst_rtsp_media_is_shared (GstRTSPMedia *media);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-04-03 20:22:30 +00:00
|
|
|
void gst_rtsp_media_set_reusable (GstRTSPMedia *media, gboolean reusable);
|
|
|
|
gboolean gst_rtsp_media_is_reusable (GstRTSPMedia *media);
|
2010-03-19 14:15:29 +00:00
|
|
|
|
|
|
|
void gst_rtsp_media_set_protocols (GstRTSPMedia *media, GstRTSPLowerTrans protocols);
|
|
|
|
GstRTSPLowerTrans gst_rtsp_media_get_protocols (GstRTSPMedia *media);
|
2010-08-20 16:17:08 +00:00
|
|
|
|
|
|
|
void gst_rtsp_media_set_eos_shutdown (GstRTSPMedia *media, gboolean eos_shutdown);
|
|
|
|
gboolean gst_rtsp_media_is_eos_shutdown (GstRTSPMedia *media);
|
2009-04-03 20:22:30 +00:00
|
|
|
|
2011-01-12 12:57:09 +00:00
|
|
|
void gst_rtsp_media_set_auth (GstRTSPMedia *media, GstRTSPAuth *auth);
|
|
|
|
GstRTSPAuth * gst_rtsp_media_get_auth (GstRTSPMedia *media);
|
|
|
|
|
2011-01-31 16:28:22 +00:00
|
|
|
void gst_rtsp_media_set_buffer_size (GstRTSPMedia *media, guint size);
|
|
|
|
guint gst_rtsp_media_get_buffer_size (GstRTSPMedia *media);
|
|
|
|
|
2011-08-16 11:25:16 +00:00
|
|
|
void gst_rtsp_media_set_multicast_group (GstRTSPMedia *media, const gchar * mc);
|
|
|
|
gchar * gst_rtsp_media_get_multicast_group (GstRTSPMedia *media);
|
|
|
|
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/* prepare the media for playback */
|
|
|
|
gboolean gst_rtsp_media_prepare (GstRTSPMedia *media);
|
2009-04-03 20:22:30 +00:00
|
|
|
gboolean gst_rtsp_media_is_prepared (GstRTSPMedia *media);
|
|
|
|
gboolean gst_rtsp_media_unprepare (GstRTSPMedia *media);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
/* dealing with the media */
|
|
|
|
guint gst_rtsp_media_n_streams (GstRTSPMedia *media);
|
|
|
|
GstRTSPMediaStream * gst_rtsp_media_get_stream (GstRTSPMedia *media, guint idx);
|
|
|
|
|
2009-03-12 19:32:14 +00:00
|
|
|
gboolean gst_rtsp_media_seek (GstRTSPMedia *media, GstRTSPTimeRange *range);
|
2010-12-28 17:35:01 +00:00
|
|
|
gchar * gst_rtsp_media_get_range_string (GstRTSPMedia *media, gboolean play);
|
2009-03-12 19:32:14 +00:00
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
GstFlowReturn gst_rtsp_media_stream_rtp (GstRTSPMediaStream *stream, GstBuffer *buffer);
|
|
|
|
GstFlowReturn gst_rtsp_media_stream_rtcp (GstRTSPMediaStream *stream, GstBuffer *buffer);
|
|
|
|
|
2010-12-11 09:48:25 +00:00
|
|
|
gboolean gst_rtsp_media_set_state (GstRTSPMedia *media, GstState state, GArray *transports);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-06-13 12:38:20 +00:00
|
|
|
void gst_rtsp_media_remove_elements (GstRTSPMedia *media);
|
|
|
|
|
2010-08-24 14:47:30 +00:00
|
|
|
void gst_rtsp_media_trans_cleanup (GstRTSPMediaTrans *trans);
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif /* __GST_RTSP_MEDIA_H__ */
|