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
|
2012-11-04 00:14:25 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-10-09 12:29:12 +00:00
|
|
|
*/
|
2013-07-11 14:57:14 +00:00
|
|
|
/**
|
|
|
|
* SECTION:rtsp-media
|
|
|
|
* @short_description: The media pipeline
|
2013-07-16 10:32:51 +00:00
|
|
|
* @see_also: #GstRTSPMediaFactory, #GstRTSPStream, #GstRTSPSession,
|
|
|
|
* #GstRTSPSessionMedia
|
|
|
|
*
|
|
|
|
* a #GstRTSPMedia contains the complete GStreamer pipeline to manage the
|
|
|
|
* streaming to the clients. The actual data transfer is done by the
|
|
|
|
* #GstRTSPStream objects that are created and exposed by the #GstRTSPMedia.
|
|
|
|
*
|
|
|
|
* The #GstRTSPMedia is usually created from a #GstRTSPMediaFactory when the
|
|
|
|
* client does a DESCRIBE or SETUP of a resource.
|
|
|
|
*
|
|
|
|
* A media is created with gst_rtsp_media_new() that takes the element that will
|
|
|
|
* provide the streaming elements. For each of the streams, a new #GstRTSPStream
|
|
|
|
* object needs to be made with the gst_rtsp_media_create_stream() which takes
|
|
|
|
* the payloader element and the source pad that produces the RTP stream.
|
|
|
|
*
|
|
|
|
* The pipeline of the media is set to PAUSED with gst_rtsp_media_prepare(). The
|
|
|
|
* prepare method will add rtpbin and sinks and sources to send and receive RTP
|
|
|
|
* and RTCP packets from the clients. Each stream srcpad is connected to an
|
|
|
|
* input into the internal rtpbin.
|
|
|
|
*
|
|
|
|
* It is also possible to dynamically create #GstRTSPStream objects during the
|
|
|
|
* prepare phase. With gst_rtsp_media_get_status() you can check the status of
|
|
|
|
* the prepare phase.
|
|
|
|
*
|
|
|
|
* After the media is prepared, it is ready for streaming. It will usually be
|
|
|
|
* managed in a session with gst_rtsp_session_manage_media(). See
|
|
|
|
* #GstRTSPSession and #GstRTSPSessionMedia.
|
|
|
|
*
|
|
|
|
* The state of the media can be controlled with gst_rtsp_media_set_state ().
|
|
|
|
* Seeking can be done with gst_rtsp_media_seek().
|
|
|
|
*
|
|
|
|
* With gst_rtsp_media_unprepare() the pipeline is stopped and shut down. When
|
|
|
|
* gst_rtsp_media_set_eos_shutdown() an EOS will be sent to the pipeline to
|
|
|
|
* cleanly shut down.
|
|
|
|
*
|
|
|
|
* With gst_rtsp_media_set_shared(), the media can be shared between multiple
|
|
|
|
* clients. With gst_rtsp_media_set_reusable() you can control if the pipeline
|
|
|
|
* can be prepared again after an unprepare.
|
2013-07-11 14:57:14 +00:00
|
|
|
*
|
|
|
|
* Last reviewed on 2013-07-11 (1.0.0)
|
|
|
|
*/
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
#include <string.h>
|
2010-08-09 19:56:23 +00:00
|
|
|
#include <stdlib.h>
|
2009-05-26 17:01:10 +00:00
|
|
|
|
2009-04-14 21:38:58 +00:00
|
|
|
#include <gst/app/gstappsrc.h>
|
|
|
|
#include <gst/app/gstappsink.h>
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
#include "rtsp-media.h"
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
#define GST_RTSP_MEDIA_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTSP_MEDIA, GstRTSPMediaPrivate))
|
|
|
|
|
|
|
|
struct _GstRTSPMediaPrivate
|
|
|
|
{
|
|
|
|
GMutex lock;
|
|
|
|
GCond cond;
|
|
|
|
|
2013-02-18 19:59:58 +00:00
|
|
|
/* protected by lock */
|
2013-07-09 12:33:43 +00:00
|
|
|
GstRTSPPermissions *permissions;
|
2012-11-29 10:11:05 +00:00
|
|
|
gboolean shared;
|
2013-11-28 13:10:19 +00:00
|
|
|
gboolean suspend_mode;
|
2012-11-29 10:11:05 +00:00
|
|
|
gboolean reusable;
|
2014-01-07 11:21:09 +00:00
|
|
|
GstRTSPProfile profiles;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPLowerTrans protocols;
|
|
|
|
gboolean reused;
|
|
|
|
gboolean eos_shutdown;
|
|
|
|
guint buffer_size;
|
|
|
|
GstRTSPAddressPool *pool;
|
2013-11-28 13:06:53 +00:00
|
|
|
gboolean blocked;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
|
|
|
GstElement *element;
|
2013-02-18 19:59:58 +00:00
|
|
|
GRecMutex state_lock; /* locking order: state lock, lock */
|
|
|
|
GPtrArray *streams; /* protected by lock */
|
|
|
|
GList *dynamic; /* protected by lock */
|
|
|
|
GstRTSPMediaStatus status; /* protected by lock */
|
2012-11-30 14:03:15 +00:00
|
|
|
gint prepare_count;
|
2012-11-29 10:11:05 +00:00
|
|
|
gint n_active;
|
|
|
|
gboolean adding;
|
|
|
|
|
|
|
|
/* the pipeline for the media */
|
|
|
|
GstElement *pipeline;
|
2013-02-18 19:59:58 +00:00
|
|
|
GstElement *fakesink; /* protected by lock */
|
2012-11-29 10:11:05 +00:00
|
|
|
GSource *source;
|
|
|
|
guint id;
|
2013-07-10 15:08:14 +00:00
|
|
|
GstRTSPThread *thread;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2013-04-09 20:35:28 +00:00
|
|
|
gboolean time_provider;
|
|
|
|
GstNetTimeProvider *nettime;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
gboolean is_live;
|
|
|
|
gboolean seekable;
|
|
|
|
gboolean buffering;
|
|
|
|
GstState target_state;
|
|
|
|
|
|
|
|
/* RTP session manager */
|
|
|
|
GstElement *rtpbin;
|
|
|
|
|
|
|
|
/* the range of media */
|
2013-02-18 19:59:58 +00:00
|
|
|
GstRTSPTimeRange range; /* protected by lock */
|
2012-11-29 10:11:05 +00:00
|
|
|
GstClockTime range_start;
|
|
|
|
GstClockTime range_stop;
|
|
|
|
};
|
|
|
|
|
2011-08-16 11:25:16 +00:00
|
|
|
#define DEFAULT_SHARED FALSE
|
2013-11-28 13:10:19 +00:00
|
|
|
#define DEFAULT_SUSPEND_MODE GST_RTSP_SUSPEND_MODE_NONE
|
2011-08-16 11:25:16 +00:00
|
|
|
#define DEFAULT_REUSABLE FALSE
|
2014-01-07 11:21:09 +00:00
|
|
|
#define DEFAULT_PROFILES GST_RTSP_PROFILE_AVP
|
2013-08-16 14:16:00 +00:00
|
|
|
#define DEFAULT_PROTOCOLS GST_RTSP_LOWER_TRANS_UDP | GST_RTSP_LOWER_TRANS_UDP_MCAST | \
|
|
|
|
GST_RTSP_LOWER_TRANS_TCP
|
2011-08-16 11:25:16 +00:00
|
|
|
#define DEFAULT_EOS_SHUTDOWN FALSE
|
|
|
|
#define DEFAULT_BUFFER_SIZE 0x80000
|
2013-04-09 20:35:28 +00:00
|
|
|
#define DEFAULT_TIME_PROVIDER FALSE
|
2009-01-29 16:20:27 +00:00
|
|
|
|
2009-05-27 09:15:22 +00:00
|
|
|
/* define to dump received RTCP packets */
|
|
|
|
#undef DUMP_STATS
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_SHARED,
|
2013-11-28 13:10:19 +00:00
|
|
|
PROP_SUSPEND_MODE,
|
2009-04-03 20:22:30 +00:00
|
|
|
PROP_REUSABLE,
|
2014-01-07 11:21:09 +00:00
|
|
|
PROP_PROFILES,
|
2010-03-19 14:15:29 +00:00
|
|
|
PROP_PROTOCOLS,
|
2010-08-20 16:17:08 +00:00
|
|
|
PROP_EOS_SHUTDOWN,
|
2011-01-31 16:28:22 +00:00
|
|
|
PROP_BUFFER_SIZE,
|
2012-12-04 08:47:35 +00:00
|
|
|
PROP_ELEMENT,
|
2013-04-09 20:35:28 +00:00
|
|
|
PROP_TIME_PROVIDER,
|
2009-01-29 16:20:27 +00:00
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
2009-04-03 20:45:57 +00:00
|
|
|
enum
|
|
|
|
{
|
2012-11-15 14:41:42 +00:00
|
|
|
SIGNAL_NEW_STREAM,
|
2013-04-22 15:34:37 +00:00
|
|
|
SIGNAL_REMOVED_STREAM,
|
2010-12-13 15:58:36 +00:00
|
|
|
SIGNAL_PREPARED,
|
2009-04-03 20:45:57 +00:00
|
|
|
SIGNAL_UNPREPARED,
|
2014-01-21 11:01:25 +00:00
|
|
|
SIGNAL_TARGET_STATE,
|
2010-12-28 17:34:10 +00:00
|
|
|
SIGNAL_NEW_STATE,
|
2009-04-03 20:45:57 +00:00
|
|
|
SIGNAL_LAST
|
|
|
|
};
|
|
|
|
|
2011-01-12 17:14:48 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (rtsp_media_debug);
|
2009-11-21 18:20:23 +00:00
|
|
|
#define GST_CAT_DEFAULT rtsp_media_debug
|
|
|
|
|
2010-03-05 15:20:08 +00:00
|
|
|
static void gst_rtsp_media_get_property (GObject * object, guint propid,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_rtsp_media_set_property (GObject * object, guint propid,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
2009-01-22 16:58:19 +00:00
|
|
|
static void gst_rtsp_media_finalize (GObject * obj);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2010-03-05 15:20:08 +00:00
|
|
|
static gboolean default_handle_message (GstRTSPMedia * media,
|
|
|
|
GstMessage * message);
|
2012-10-25 19:29:58 +00:00
|
|
|
static void finish_unprepare (GstRTSPMedia * media);
|
2014-04-09 14:44:21 +00:00
|
|
|
static gboolean default_prepare (GstRTSPMedia * media, GstRTSPThread * thread);
|
2010-03-05 15:20:08 +00:00
|
|
|
static gboolean default_unprepare (GstRTSPMedia * media);
|
2014-05-14 07:31:31 +00:00
|
|
|
static gboolean default_suspend (GstRTSPMedia * media);
|
|
|
|
static gboolean default_unsuspend (GstRTSPMedia * media);
|
2013-11-26 16:23:04 +00:00
|
|
|
static gboolean default_convert_range (GstRTSPMedia * media,
|
|
|
|
GstRTSPTimeRange * range, GstRTSPRangeUnit unit);
|
2013-06-10 21:32:40 +00:00
|
|
|
static gboolean default_query_position (GstRTSPMedia * media,
|
|
|
|
gint64 * position);
|
|
|
|
static gboolean default_query_stop (GstRTSPMedia * media, gint64 * stop);
|
2013-12-03 19:54:42 +00:00
|
|
|
static GstElement *default_create_rtpbin (GstRTSPMedia * media);
|
2013-12-18 15:37:27 +00:00
|
|
|
static gboolean default_setup_sdp (GstRTSPMedia * media, GstSDPMessage * sdp,
|
|
|
|
GstSDPInfo * info);
|
2009-02-13 15:39:36 +00:00
|
|
|
|
2013-11-28 12:58:05 +00:00
|
|
|
static gboolean wait_preroll (GstRTSPMedia * media);
|
|
|
|
|
2009-04-03 20:45:57 +00:00
|
|
|
static guint gst_rtsp_media_signals[SIGNAL_LAST] = { 0 };
|
|
|
|
|
2013-11-28 13:10:19 +00:00
|
|
|
#define C_ENUM(v) ((gint) v)
|
|
|
|
|
|
|
|
#define GST_TYPE_RTSP_SUSPEND_MODE (gst_rtsp_suspend_mode_get_type())
|
|
|
|
GType
|
|
|
|
gst_rtsp_suspend_mode_get_type (void)
|
|
|
|
{
|
|
|
|
static gsize id = 0;
|
|
|
|
static const GEnumValue values[] = {
|
|
|
|
{C_ENUM (GST_RTSP_SUSPEND_MODE_NONE), "GST_RTSP_SUSPEND_MODE_NONE", "none"},
|
|
|
|
{C_ENUM (GST_RTSP_SUSPEND_MODE_PAUSE), "GST_RTSP_SUSPEND_MODE_PAUSE",
|
|
|
|
"pause"},
|
|
|
|
{C_ENUM (GST_RTSP_SUSPEND_MODE_RESET), "GST_RTSP_SUSPEND_MODE_RESET",
|
|
|
|
"reset"},
|
|
|
|
{0, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (g_once_init_enter (&id)) {
|
|
|
|
GType tmp = g_enum_register_static ("GstRTSPSuspendMode", values);
|
|
|
|
g_once_init_leave (&id, tmp);
|
|
|
|
}
|
|
|
|
return (GType) id;
|
|
|
|
}
|
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
G_DEFINE_TYPE (GstRTSPMedia, gst_rtsp_media, G_TYPE_OBJECT);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
static void
|
2009-01-22 16:58:19 +00:00
|
|
|
gst_rtsp_media_class_init (GstRTSPMediaClass * klass)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstRTSPMediaPrivate));
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
gobject_class->get_property = gst_rtsp_media_get_property;
|
|
|
|
gobject_class->set_property = gst_rtsp_media_set_property;
|
2009-01-22 16:58:19 +00:00
|
|
|
gobject_class->finalize = gst_rtsp_media_finalize;
|
2009-01-29 16:20:27 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SHARED,
|
2010-03-05 15:20:08 +00:00
|
|
|
g_param_spec_boolean ("shared", "Shared",
|
|
|
|
"If this media pipeline can be shared", DEFAULT_SHARED,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-02-13 15:39:36 +00:00
|
|
|
|
2013-11-28 13:10:19 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SUSPEND_MODE,
|
|
|
|
g_param_spec_enum ("suspend-mode", "Suspend Mode",
|
|
|
|
"How to suspend the media in PAUSED", GST_TYPE_RTSP_SUSPEND_MODE,
|
|
|
|
DEFAULT_SUSPEND_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2009-04-03 20:22:30 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_REUSABLE,
|
|
|
|
g_param_spec_boolean ("reusable", "Reusable",
|
|
|
|
"If this media pipeline can be reused after an unprepare",
|
|
|
|
DEFAULT_REUSABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2014-01-07 11:21:09 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_PROFILES,
|
|
|
|
g_param_spec_flags ("profiles", "Profiles",
|
|
|
|
"Allowed transfer profiles", GST_TYPE_RTSP_PROFILE,
|
|
|
|
DEFAULT_PROFILES, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2010-03-19 14:15:29 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_PROTOCOLS,
|
|
|
|
g_param_spec_flags ("protocols", "Protocols",
|
|
|
|
"Allowed lower transport protocols", GST_TYPE_RTSP_LOWER_TRANS,
|
|
|
|
DEFAULT_PROTOCOLS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2010-08-20 16:17:08 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_EOS_SHUTDOWN,
|
|
|
|
g_param_spec_boolean ("eos-shutdown", "EOS Shutdown",
|
|
|
|
"Send an EOS event to the pipeline before unpreparing",
|
|
|
|
DEFAULT_EOS_SHUTDOWN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-01-31 16:28:22 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_BUFFER_SIZE,
|
|
|
|
g_param_spec_uint ("buffer-size", "Buffer Size",
|
|
|
|
"The kernel UDP buffer size to use", 0, G_MAXUINT,
|
|
|
|
DEFAULT_BUFFER_SIZE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2012-12-04 08:47:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_ELEMENT,
|
|
|
|
g_param_spec_object ("element", "The Element",
|
|
|
|
"The GstBin to use for streaming the media", GST_TYPE_ELEMENT,
|
|
|
|
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
|
|
|
|
|
2013-06-10 21:33:01 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_TIME_PROVIDER,
|
2013-04-09 20:35:28 +00:00
|
|
|
g_param_spec_boolean ("time-provider", "Time Provider",
|
|
|
|
"Use a NetTimeProvider for clients",
|
|
|
|
DEFAULT_TIME_PROVIDER, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2012-11-15 14:41:42 +00:00
|
|
|
gst_rtsp_media_signals[SIGNAL_NEW_STREAM] =
|
|
|
|
g_signal_new ("new-stream", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstRTSPMediaClass, new_stream), NULL, NULL,
|
|
|
|
g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_RTSP_STREAM);
|
|
|
|
|
2013-04-22 15:34:37 +00:00
|
|
|
gst_rtsp_media_signals[SIGNAL_REMOVED_STREAM] =
|
|
|
|
g_signal_new ("removed-stream", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPMediaClass, removed_stream),
|
|
|
|
NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1,
|
|
|
|
GST_TYPE_RTSP_STREAM);
|
|
|
|
|
2010-12-13 15:58:36 +00:00
|
|
|
gst_rtsp_media_signals[SIGNAL_PREPARED] =
|
|
|
|
g_signal_new ("prepared", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstRTSPMediaClass, prepared), NULL, NULL,
|
2014-06-24 07:43:44 +00:00
|
|
|
g_cclosure_marshal_generic, G_TYPE_NONE, 0, G_TYPE_NONE);
|
2010-12-13 15:58:36 +00:00
|
|
|
|
2009-04-03 20:45:57 +00:00
|
|
|
gst_rtsp_media_signals[SIGNAL_UNPREPARED] =
|
|
|
|
g_signal_new ("unprepared", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstRTSPMediaClass, unprepared), NULL, NULL,
|
2014-06-24 07:43:44 +00:00
|
|
|
g_cclosure_marshal_generic, G_TYPE_NONE, 0, G_TYPE_NONE);
|
2009-04-03 20:45:57 +00:00
|
|
|
|
2014-01-21 11:01:25 +00:00
|
|
|
gst_rtsp_media_signals[SIGNAL_TARGET_STATE] =
|
|
|
|
g_signal_new ("target-state", G_TYPE_FROM_CLASS (klass),
|
2014-07-02 17:15:07 +00:00
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPMediaClass, target_state),
|
|
|
|
NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, G_TYPE_INT);
|
2014-01-21 11:01:25 +00:00
|
|
|
|
2010-12-28 17:34:10 +00:00
|
|
|
gst_rtsp_media_signals[SIGNAL_NEW_STATE] =
|
|
|
|
g_signal_new ("new-state", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstRTSPMediaClass, new_state), NULL, NULL,
|
2014-06-24 07:43:44 +00:00
|
|
|
g_cclosure_marshal_generic, G_TYPE_NONE, 1, G_TYPE_INT);
|
2010-12-28 17:34:10 +00:00
|
|
|
|
2011-01-13 17:57:15 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (rtsp_media_debug, "rtspmedia", 0, "GstRTSPMedia");
|
|
|
|
|
2009-02-13 15:39:36 +00:00
|
|
|
klass->handle_message = default_handle_message;
|
2014-04-09 14:44:21 +00:00
|
|
|
klass->prepare = default_prepare;
|
2009-06-12 16:05:30 +00:00
|
|
|
klass->unprepare = default_unprepare;
|
2014-05-14 07:31:31 +00:00
|
|
|
klass->suspend = default_suspend;
|
|
|
|
klass->unsuspend = default_unsuspend;
|
2013-06-05 13:49:45 +00:00
|
|
|
klass->convert_range = default_convert_range;
|
2013-06-10 21:32:40 +00:00
|
|
|
klass->query_position = default_query_position;
|
|
|
|
klass->query_stop = default_query_stop;
|
2013-12-03 19:54:42 +00:00
|
|
|
klass->create_rtpbin = default_create_rtpbin;
|
2013-12-18 15:37:27 +00:00
|
|
|
klass->setup_sdp = default_setup_sdp;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-01-22 16:58:19 +00:00
|
|
|
gst_rtsp_media_init (GstRTSPMedia * media)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv = GST_RTSP_MEDIA_GET_PRIVATE (media);
|
|
|
|
|
|
|
|
media->priv = priv;
|
|
|
|
|
|
|
|
priv->streams = g_ptr_array_new_with_free_func (g_object_unref);
|
|
|
|
g_mutex_init (&priv->lock);
|
|
|
|
g_cond_init (&priv->cond);
|
|
|
|
g_rec_mutex_init (&priv->state_lock);
|
|
|
|
|
|
|
|
priv->shared = DEFAULT_SHARED;
|
2013-11-28 13:10:19 +00:00
|
|
|
priv->suspend_mode = DEFAULT_SUSPEND_MODE;
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->reusable = DEFAULT_REUSABLE;
|
2014-01-07 11:21:09 +00:00
|
|
|
priv->profiles = DEFAULT_PROFILES;
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->protocols = DEFAULT_PROTOCOLS;
|
|
|
|
priv->eos_shutdown = DEFAULT_EOS_SHUTDOWN;
|
|
|
|
priv->buffer_size = DEFAULT_BUFFER_SIZE;
|
2013-04-09 20:35:28 +00:00
|
|
|
priv->time_provider = DEFAULT_TIME_PROVIDER;
|
2010-08-20 11:19:56 +00:00
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
static void
|
2009-01-22 16:58:19 +00:00
|
|
|
gst_rtsp_media_finalize (GObject * obj)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
2009-01-22 16:58:19 +00:00
|
|
|
GstRTSPMedia *media;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
media = GST_RTSP_MEDIA (obj);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("finalize media %p", media);
|
2009-06-14 21:12:13 +00:00
|
|
|
|
2013-09-05 06:53:55 +00:00
|
|
|
if (priv->permissions)
|
|
|
|
gst_rtsp_permissions_unref (priv->permissions);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_ptr_array_unref (priv->streams);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_list_free_full (priv->dynamic, gst_object_unref);
|
2009-05-24 17:34:52 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->pipeline)
|
|
|
|
gst_object_unref (priv->pipeline);
|
2013-04-09 20:35:28 +00:00
|
|
|
if (priv->nettime)
|
|
|
|
gst_object_unref (priv->nettime);
|
2012-11-29 16:20:56 +00:00
|
|
|
gst_object_unref (priv->element);
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->pool)
|
|
|
|
g_object_unref (priv->pool);
|
|
|
|
g_mutex_clear (&priv->lock);
|
|
|
|
g_cond_clear (&priv->cond);
|
|
|
|
g_rec_mutex_clear (&priv->state_lock);
|
2009-02-13 15:39:36 +00:00
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
G_OBJECT_CLASS (gst_rtsp_media_parent_class)->finalize (obj);
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_get_property (GObject * object, guint propid,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2009-01-29 16:20:27 +00:00
|
|
|
{
|
|
|
|
GstRTSPMedia *media = GST_RTSP_MEDIA (object);
|
|
|
|
|
|
|
|
switch (propid) {
|
2012-12-04 08:47:35 +00:00
|
|
|
case PROP_ELEMENT:
|
|
|
|
g_value_set_object (value, media->priv->element);
|
|
|
|
break;
|
2009-01-29 16:20:27 +00:00
|
|
|
case PROP_SHARED:
|
|
|
|
g_value_set_boolean (value, gst_rtsp_media_is_shared (media));
|
|
|
|
break;
|
2013-11-28 13:10:19 +00:00
|
|
|
case PROP_SUSPEND_MODE:
|
|
|
|
g_value_set_enum (value, gst_rtsp_media_get_suspend_mode (media));
|
|
|
|
break;
|
2009-04-03 20:22:30 +00:00
|
|
|
case PROP_REUSABLE:
|
|
|
|
g_value_set_boolean (value, gst_rtsp_media_is_reusable (media));
|
|
|
|
break;
|
2014-01-07 11:21:09 +00:00
|
|
|
case PROP_PROFILES:
|
|
|
|
g_value_set_flags (value, gst_rtsp_media_get_profiles (media));
|
|
|
|
break;
|
2010-03-19 14:15:29 +00:00
|
|
|
case PROP_PROTOCOLS:
|
|
|
|
g_value_set_flags (value, gst_rtsp_media_get_protocols (media));
|
|
|
|
break;
|
2010-08-20 16:17:08 +00:00
|
|
|
case PROP_EOS_SHUTDOWN:
|
|
|
|
g_value_set_boolean (value, gst_rtsp_media_is_eos_shutdown (media));
|
|
|
|
break;
|
2011-01-31 16:28:22 +00:00
|
|
|
case PROP_BUFFER_SIZE:
|
|
|
|
g_value_set_uint (value, gst_rtsp_media_get_buffer_size (media));
|
|
|
|
break;
|
2013-04-09 20:35:28 +00:00
|
|
|
case PROP_TIME_PROVIDER:
|
|
|
|
g_value_set_boolean (value, gst_rtsp_media_is_time_provider (media));
|
|
|
|
break;
|
2009-01-29 16:20:27 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_set_property (GObject * object, guint propid,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2009-01-29 16:20:27 +00:00
|
|
|
{
|
|
|
|
GstRTSPMedia *media = GST_RTSP_MEDIA (object);
|
|
|
|
|
|
|
|
switch (propid) {
|
2012-12-04 08:47:35 +00:00
|
|
|
case PROP_ELEMENT:
|
|
|
|
media->priv->element = g_value_get_object (value);
|
2013-06-17 14:47:56 +00:00
|
|
|
gst_object_ref_sink (media->priv->element);
|
2012-12-04 08:47:35 +00:00
|
|
|
break;
|
2009-01-29 16:20:27 +00:00
|
|
|
case PROP_SHARED:
|
|
|
|
gst_rtsp_media_set_shared (media, g_value_get_boolean (value));
|
|
|
|
break;
|
2013-11-28 13:10:19 +00:00
|
|
|
case PROP_SUSPEND_MODE:
|
|
|
|
gst_rtsp_media_set_suspend_mode (media, g_value_get_enum (value));
|
|
|
|
break;
|
2009-04-03 20:22:30 +00:00
|
|
|
case PROP_REUSABLE:
|
|
|
|
gst_rtsp_media_set_reusable (media, g_value_get_boolean (value));
|
|
|
|
break;
|
2014-01-07 11:21:09 +00:00
|
|
|
case PROP_PROFILES:
|
|
|
|
gst_rtsp_media_set_profiles (media, g_value_get_flags (value));
|
|
|
|
break;
|
2010-03-19 14:15:29 +00:00
|
|
|
case PROP_PROTOCOLS:
|
|
|
|
gst_rtsp_media_set_protocols (media, g_value_get_flags (value));
|
|
|
|
break;
|
2010-08-20 16:17:08 +00:00
|
|
|
case PROP_EOS_SHUTDOWN:
|
|
|
|
gst_rtsp_media_set_eos_shutdown (media, g_value_get_boolean (value));
|
|
|
|
break;
|
2011-01-31 16:28:22 +00:00
|
|
|
case PROP_BUFFER_SIZE:
|
|
|
|
gst_rtsp_media_set_buffer_size (media, g_value_get_uint (value));
|
|
|
|
break;
|
2013-04-09 20:35:28 +00:00
|
|
|
case PROP_TIME_PROVIDER:
|
|
|
|
gst_rtsp_media_use_time_provider (media, g_value_get_boolean (value));
|
|
|
|
break;
|
2009-01-29 16:20:27 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-05 14:12:19 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gint64 position;
|
|
|
|
gboolean ret;
|
|
|
|
} DoQueryPositionData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_query_position (GstRTSPStream * stream, DoQueryPositionData * data)
|
|
|
|
{
|
|
|
|
gint64 tmp;
|
|
|
|
|
|
|
|
if (gst_rtsp_stream_query_position (stream, &tmp)) {
|
|
|
|
data->position = MAX (data->position, tmp);
|
|
|
|
data->ret = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-26 16:23:04 +00:00
|
|
|
static gboolean
|
|
|
|
default_query_position (GstRTSPMedia * media, gint64 * position)
|
|
|
|
{
|
2014-08-05 14:12:19 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
DoQueryPositionData data;
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
data.position = -1;
|
|
|
|
data.ret = FALSE;
|
|
|
|
|
|
|
|
g_ptr_array_foreach (priv->streams, (GFunc) do_query_position, &data);
|
|
|
|
|
|
|
|
*position = data.position;
|
|
|
|
|
|
|
|
return data.ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gint64 stop;
|
|
|
|
gboolean ret;
|
|
|
|
} DoQueryStopData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_query_stop (GstRTSPStream * stream, DoQueryStopData * data)
|
|
|
|
{
|
|
|
|
gint64 tmp;
|
|
|
|
|
|
|
|
if (gst_rtsp_stream_query_stop (stream, &tmp)) {
|
|
|
|
data->stop = MAX (data->stop, tmp);
|
|
|
|
data->ret = TRUE;
|
|
|
|
}
|
2013-11-26 16:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
default_query_stop (GstRTSPMedia * media, gint64 * stop)
|
|
|
|
{
|
2014-08-05 14:12:19 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
DoQueryStopData data;
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
data.stop = -1;
|
|
|
|
data.ret = FALSE;
|
|
|
|
|
|
|
|
g_ptr_array_foreach (priv->streams, (GFunc) do_query_stop, &data);
|
|
|
|
|
|
|
|
*stop = data.stop;
|
|
|
|
|
|
|
|
return data.ret;
|
2013-11-26 16:23:04 +00:00
|
|
|
}
|
|
|
|
|
2013-12-03 19:54:42 +00:00
|
|
|
static GstElement *
|
|
|
|
default_create_rtpbin (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
GstElement *rtpbin;
|
|
|
|
|
|
|
|
rtpbin = gst_element_factory_make ("rtpbin", NULL);
|
|
|
|
|
|
|
|
return rtpbin;
|
|
|
|
}
|
|
|
|
|
2012-11-13 10:15:35 +00:00
|
|
|
/* must be called with state lock */
|
2009-03-12 19:32:14 +00:00
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
collect_media_stats (GstRTSPMedia * media)
|
2009-03-12 19:32:14 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
2014-08-05 14:12:19 +00:00
|
|
|
gint64 position = 0, stop = -1;
|
2009-03-12 19:32:14 +00:00
|
|
|
|
2012-11-30 11:53:02 +00:00
|
|
|
if (priv->status != GST_RTSP_MEDIA_STATUS_PREPARED &&
|
|
|
|
priv->status != GST_RTSP_MEDIA_STATUS_PREPARING)
|
|
|
|
return;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->range.unit = GST_RTSP_RANGE_NPT;
|
2009-03-12 19:32:14 +00:00
|
|
|
|
2012-10-27 09:53:51 +00:00
|
|
|
GST_INFO ("collect media stats");
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->is_live) {
|
|
|
|
priv->range.min.type = GST_RTSP_TIME_NOW;
|
|
|
|
priv->range.min.seconds = -1;
|
|
|
|
priv->range_start = -1;
|
|
|
|
priv->range.max.type = GST_RTSP_TIME_END;
|
|
|
|
priv->range.max.seconds = -1;
|
|
|
|
priv->range_stop = -1;
|
2010-03-05 15:20:08 +00:00
|
|
|
} else {
|
2013-06-10 21:32:40 +00:00
|
|
|
GstRTSPMediaClass *klass;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
klass = GST_RTSP_MEDIA_GET_CLASS (media);
|
|
|
|
|
2009-03-12 19:32:14 +00:00
|
|
|
/* get the position */
|
2013-06-10 21:32:40 +00:00
|
|
|
ret = FALSE;
|
|
|
|
if (klass->query_position)
|
|
|
|
ret = klass->query_position (media, &position);
|
|
|
|
|
|
|
|
if (!ret) {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("position query failed");
|
2009-03-12 19:32:14 +00:00
|
|
|
position = 0;
|
2009-03-13 14:57:42 +00:00
|
|
|
}
|
2009-03-12 19:32:14 +00:00
|
|
|
|
2013-06-11 13:28:32 +00:00
|
|
|
/* get the current segment stop */
|
2013-06-10 21:32:40 +00:00
|
|
|
ret = FALSE;
|
|
|
|
if (klass->query_stop)
|
|
|
|
ret = klass->query_stop (media, &stop);
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
GST_INFO ("stop query failed");
|
2013-06-11 13:28:32 +00:00
|
|
|
stop = -1;
|
2009-03-13 14:57:42 +00:00
|
|
|
}
|
|
|
|
|
2013-06-11 13:28:32 +00:00
|
|
|
GST_INFO ("stats: position %" GST_TIME_FORMAT ", stop %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (position), GST_TIME_ARGS (stop));
|
2009-03-12 19:32:14 +00:00
|
|
|
|
2010-12-28 17:35:01 +00:00
|
|
|
if (position == -1) {
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->range.min.type = GST_RTSP_TIME_NOW;
|
|
|
|
priv->range.min.seconds = -1;
|
|
|
|
priv->range_start = -1;
|
2010-03-05 15:20:08 +00:00
|
|
|
} else {
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->range.min.type = GST_RTSP_TIME_SECONDS;
|
|
|
|
priv->range.min.seconds = ((gdouble) position) / GST_SECOND;
|
|
|
|
priv->range_start = position;
|
2009-03-12 19:32:14 +00:00
|
|
|
}
|
2013-06-11 13:28:32 +00:00
|
|
|
if (stop == -1) {
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->range.max.type = GST_RTSP_TIME_END;
|
|
|
|
priv->range.max.seconds = -1;
|
|
|
|
priv->range_stop = -1;
|
2010-03-05 15:20:08 +00:00
|
|
|
} else {
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->range.max.type = GST_RTSP_TIME_SECONDS;
|
2013-06-11 13:28:32 +00:00
|
|
|
priv->range.max.seconds = ((gdouble) stop) / GST_SECOND;
|
|
|
|
priv->range_stop = stop;
|
2009-03-12 19:32:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_new:
|
2012-11-29 10:11:05 +00:00
|
|
|
* @element: (transfer full): a #GstElement
|
2009-01-29 12:31:27 +00:00
|
|
|
*
|
2012-11-29 10:11:05 +00:00
|
|
|
* Create a new #GstRTSPMedia instance. @element is the bin element that
|
|
|
|
* provides the different streams. The #GstRTSPMedia object contains the
|
2012-09-04 00:33:17 +00:00
|
|
|
* element to produce RTP data for one or more related (audio/video/..)
|
2009-01-29 12:31:27 +00:00
|
|
|
* streams.
|
|
|
|
*
|
2012-11-29 10:11:05 +00:00
|
|
|
* Ownership is taken of @element.
|
|
|
|
*
|
2014-03-23 20:24:48 +00:00
|
|
|
* Returns: (transfer full): a new #GstRTSPMedia object.
|
2009-01-29 12:31:27 +00:00
|
|
|
*/
|
|
|
|
GstRTSPMedia *
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_media_new (GstElement * element)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
|
|
|
GstRTSPMedia *result;
|
|
|
|
|
2012-11-29 16:20:26 +00:00
|
|
|
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
|
|
|
|
|
2012-12-04 08:47:35 +00:00
|
|
|
result = g_object_new (GST_TYPE_RTSP_MEDIA, "element", element, NULL);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-06-24 21:56:57 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_get_element:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Get the element that was used when constructing @media.
|
|
|
|
*
|
2013-10-12 21:56:00 +00:00
|
|
|
* Returns: (transfer full): a #GstElement. Unref after usage.
|
2013-06-24 21:56:57 +00:00
|
|
|
*/
|
|
|
|
GstElement *
|
|
|
|
gst_rtsp_media_get_element (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
|
|
|
|
|
|
|
|
return gst_object_ref (media->priv->element);
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/**
|
2013-06-24 21:51:38 +00:00
|
|
|
* gst_rtsp_media_take_pipeline:
|
2012-11-29 10:11:05 +00:00
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @pipeline: (transfer full): a #GstPipeline
|
|
|
|
*
|
|
|
|
* Set @pipeline as the #GstPipeline for @media. Ownership is
|
|
|
|
* taken of @pipeline.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_media_take_pipeline (GstRTSPMedia * media, GstPipeline * pipeline)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
GstElement *old;
|
2013-04-09 20:35:28 +00:00
|
|
|
GstNetTimeProvider *nettime;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
g_return_if_fail (GST_IS_PIPELINE (pipeline));
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
old = priv->pipeline;
|
|
|
|
priv->pipeline = GST_ELEMENT_CAST (pipeline);
|
2013-04-09 20:35:28 +00:00
|
|
|
nettime = priv->nettime;
|
|
|
|
priv->nettime = NULL;
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
if (old)
|
|
|
|
gst_object_unref (old);
|
|
|
|
|
2013-04-09 20:35:28 +00:00
|
|
|
if (nettime)
|
|
|
|
gst_object_unref (nettime);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_bin_add (GST_BIN_CAST (pipeline), priv->element);
|
|
|
|
}
|
|
|
|
|
2013-07-09 12:33:43 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_set_permissions:
|
|
|
|
* @media: a #GstRTSPMedia
|
2014-03-23 20:24:48 +00:00
|
|
|
* @permissions: (transfer none): a #GstRTSPPermissions
|
2013-07-09 12:33:43 +00:00
|
|
|
*
|
|
|
|
* Set @permissions on @media.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_media_set_permissions (GstRTSPMedia * media,
|
|
|
|
GstRTSPPermissions * permissions)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if (priv->permissions)
|
|
|
|
gst_rtsp_permissions_unref (priv->permissions);
|
|
|
|
if ((priv->permissions = permissions))
|
|
|
|
gst_rtsp_permissions_ref (permissions);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_get_permissions:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Get the permissions object from @media.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a #GstRTSPPermissions object, unref after usage.
|
|
|
|
*/
|
|
|
|
GstRTSPPermissions *
|
|
|
|
gst_rtsp_media_get_permissions (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
GstRTSPPermissions *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((result = priv->permissions))
|
|
|
|
gst_rtsp_permissions_ref (result);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-11-28 13:10:19 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_set_suspend_mode:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @mode: the new #GstRTSPSuspendMode
|
|
|
|
*
|
|
|
|
* Control how @ media will be suspended after the SDP has been generated and
|
|
|
|
* after a PAUSE request has been performed.
|
|
|
|
*
|
|
|
|
* Media must be unprepared when setting the suspend mode.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_media_set_suspend_mode (GstRTSPMedia * media, GstRTSPSuspendMode mode)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
|
|
|
if (priv->status == GST_RTSP_MEDIA_STATUS_PREPARED)
|
|
|
|
goto was_prepared;
|
|
|
|
priv->suspend_mode = mode;
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
was_prepared:
|
|
|
|
{
|
|
|
|
GST_WARNING ("media %p was prepared", media);
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_get_suspend_mode:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Get how @media will be suspended.
|
|
|
|
*
|
|
|
|
* Returns: #GstRTSPSuspendMode.
|
|
|
|
*/
|
|
|
|
GstRTSPSuspendMode
|
|
|
|
gst_rtsp_media_get_suspend_mode (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
GstRTSPSuspendMode res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), GST_RTSP_SUSPEND_MODE_NONE);
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
|
|
|
res = priv->suspend_mode;
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_set_shared:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @shared: the new value
|
|
|
|
*
|
|
|
|
* Set or unset if the pipeline for @media can be shared will multiple clients.
|
|
|
|
* When @shared is %TRUE, client requests for this media will share the media
|
|
|
|
* pipeline.
|
|
|
|
*/
|
|
|
|
void
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_set_shared (GstRTSPMedia * media, gboolean shared)
|
2009-01-29 16:20:27 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->shared = shared;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2009-01-29 16:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_is_shared:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Check if the pipeline for @media can be shared between multiple clients.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the media can be shared between clients.
|
|
|
|
*/
|
|
|
|
gboolean
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_is_shared (GstRTSPMedia * media)
|
2009-01-29 16:20:27 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
2012-11-13 10:15:35 +00:00
|
|
|
gboolean res;
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
res = priv->shared;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:15:35 +00:00
|
|
|
|
|
|
|
return res;
|
2009-01-29 16:20:27 +00:00
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-04-03 20:22:30 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_set_reusable:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @reusable: the new value
|
|
|
|
*
|
|
|
|
* Set or unset if the pipeline for @media can be reused after the pipeline has
|
|
|
|
* been unprepared.
|
|
|
|
*/
|
|
|
|
void
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_set_reusable (GstRTSPMedia * media, gboolean reusable)
|
2009-04-03 20:22:30 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
|
2009-04-03 20:22:30 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->reusable = reusable;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2009-04-03 20:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_is_reusable:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Check if the pipeline for @media can be reused after an unprepare.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the media can be reused
|
|
|
|
*/
|
|
|
|
gboolean
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_is_reusable (GstRTSPMedia * media)
|
2009-04-03 20:22:30 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
2012-11-13 10:15:35 +00:00
|
|
|
gboolean res;
|
|
|
|
|
2009-04-03 20:22:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
res = priv->reusable;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:15:35 +00:00
|
|
|
|
|
|
|
return res;
|
2009-04-03 20:22:30 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 11:21:09 +00:00
|
|
|
static void
|
|
|
|
do_set_profiles (GstRTSPStream * stream, GstRTSPProfile * profiles)
|
|
|
|
{
|
|
|
|
gst_rtsp_stream_set_profiles (stream, *profiles);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_set_profiles:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @profiles: the new flags
|
|
|
|
*
|
|
|
|
* Configure the allowed lower transport for @media.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_media_set_profiles (GstRTSPMedia * media, GstRTSPProfile profiles)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->profiles = profiles;
|
|
|
|
g_ptr_array_foreach (priv->streams, (GFunc) do_set_profiles, &profiles);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_get_profiles:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Get the allowed profiles of @media.
|
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPProfile
|
|
|
|
*/
|
|
|
|
GstRTSPProfile
|
|
|
|
gst_rtsp_media_get_profiles (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
GstRTSPProfile res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), GST_RTSP_PROFILE_UNKNOWN);
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
res = priv->profiles;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-08-16 14:34:56 +00:00
|
|
|
static void
|
|
|
|
do_set_protocols (GstRTSPStream * stream, GstRTSPLowerTrans * protocols)
|
|
|
|
{
|
|
|
|
gst_rtsp_stream_set_protocols (stream, *protocols);
|
|
|
|
}
|
|
|
|
|
2010-03-19 14:15:29 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_set_protocols:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @protocols: the new flags
|
|
|
|
*
|
|
|
|
* Configure the allowed lower transport for @media.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_media_set_protocols (GstRTSPMedia * media, GstRTSPLowerTrans protocols)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
|
2010-03-19 14:15:29 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->protocols = protocols;
|
2013-08-16 14:34:56 +00:00
|
|
|
g_ptr_array_foreach (priv->streams, (GFunc) do_set_protocols, &protocols);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2010-03-19 14:15:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_get_protocols:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Get the allowed protocols of @media.
|
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPLowerTrans
|
|
|
|
*/
|
|
|
|
GstRTSPLowerTrans
|
|
|
|
gst_rtsp_media_get_protocols (GstRTSPMedia * media)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
2012-11-13 10:15:35 +00:00
|
|
|
GstRTSPLowerTrans res;
|
|
|
|
|
2010-12-11 09:48:42 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media),
|
|
|
|
GST_RTSP_LOWER_TRANS_UNKNOWN);
|
2010-03-19 14:15:29 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
res = priv->protocols;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:15:35 +00:00
|
|
|
|
|
|
|
return res;
|
2010-03-19 14:15:29 +00:00
|
|
|
}
|
|
|
|
|
2010-08-20 16:17:08 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_set_eos_shutdown:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @eos_shutdown: the new value
|
|
|
|
*
|
|
|
|
* Set or unset if an EOS event will be sent to the pipeline for @media before
|
|
|
|
* it is unprepared.
|
|
|
|
*/
|
|
|
|
void
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_media_set_eos_shutdown (GstRTSPMedia * media, gboolean eos_shutdown)
|
2010-08-20 16:17:08 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
|
2010-08-20 16:17:08 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->eos_shutdown = eos_shutdown;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2010-08-20 16:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_is_eos_shutdown:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Check if the pipeline for @media will send an EOS down the pipeline before
|
|
|
|
* unpreparing.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the media will send EOS before unpreparing.
|
|
|
|
*/
|
|
|
|
gboolean
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_media_is_eos_shutdown (GstRTSPMedia * media)
|
2010-08-20 16:17:08 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
2012-11-13 10:15:35 +00:00
|
|
|
gboolean res;
|
|
|
|
|
2010-08-20 16:17:08 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
res = priv->eos_shutdown;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:15:35 +00:00
|
|
|
|
|
|
|
return res;
|
2010-08-20 16:17:08 +00:00
|
|
|
}
|
|
|
|
|
2011-01-31 16:28:22 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_set_buffer_size:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @size: the new value
|
|
|
|
*
|
|
|
|
* Set the kernel UDP buffer size.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_media_set_buffer_size (GstRTSPMedia * media, guint size)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
|
2011-01-31 16:28:22 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
2012-11-15 15:15:20 +00:00
|
|
|
GST_LOG_OBJECT (media, "set buffer size %u", size);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->buffer_size = size;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2011-01-31 16:28:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_get_buffer_size:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Get the kernel UDP buffer size.
|
|
|
|
*
|
|
|
|
* Returns: the kernel UDP buffer size.
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gst_rtsp_media_get_buffer_size (GstRTSPMedia * media)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
2012-11-13 10:15:35 +00:00
|
|
|
guint res;
|
|
|
|
|
2011-01-31 16:28:22 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
res = priv->buffer_size;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:15:35 +00:00
|
|
|
|
|
|
|
return res;
|
2011-01-31 16:28:22 +00:00
|
|
|
}
|
|
|
|
|
2013-04-09 20:35:28 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_use_time_provider:
|
|
|
|
* @media: a #GstRTSPMedia
|
2013-07-11 10:18:26 +00:00
|
|
|
* @time_provider: if a #GstNetTimeProvider should be used
|
2013-04-09 20:35:28 +00:00
|
|
|
*
|
2013-07-11 10:18:26 +00:00
|
|
|
* Set @media to provide a #GstNetTimeProvider.
|
2013-04-09 20:35:28 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_media_use_time_provider (GstRTSPMedia * media, gboolean time_provider)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->time_provider = time_provider;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_is_time_provider:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Check if @media can provide a #GstNetTimeProvider for its pipeline clock.
|
|
|
|
*
|
|
|
|
* Use gst_rtsp_media_get_time_provider() to get the network clock.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @media can provide a #GstNetTimeProvider.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_media_is_time_provider (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
res = priv->time_provider;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-01-12 12:57:09 +00:00
|
|
|
/**
|
2012-11-14 16:23:59 +00:00
|
|
|
* gst_rtsp_media_set_address_pool:
|
2011-01-12 12:57:09 +00:00
|
|
|
* @media: a #GstRTSPMedia
|
2014-03-23 20:24:48 +00:00
|
|
|
* @pool: (transfer none): a #GstRTSPAddressPool
|
2011-01-12 12:57:09 +00:00
|
|
|
*
|
2012-11-14 16:23:59 +00:00
|
|
|
* configure @pool to be used as the address pool of @media.
|
2011-01-12 12:57:09 +00:00
|
|
|
*/
|
|
|
|
void
|
2012-11-14 16:23:59 +00:00
|
|
|
gst_rtsp_media_set_address_pool (GstRTSPMedia * media,
|
|
|
|
GstRTSPAddressPool * pool)
|
2011-01-12 12:57:09 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
2012-11-14 16:23:59 +00:00
|
|
|
GstRTSPAddressPool *old;
|
2011-01-12 12:57:09 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
2012-11-15 15:15:20 +00:00
|
|
|
GST_LOG_OBJECT (media, "set address pool %p", pool);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((old = priv->pool) != pool)
|
|
|
|
priv->pool = pool ? g_object_ref (pool) : NULL;
|
2012-11-13 10:15:35 +00:00
|
|
|
else
|
|
|
|
old = NULL;
|
2012-11-29 10:11:05 +00:00
|
|
|
g_ptr_array_foreach (priv->streams, (GFunc) gst_rtsp_stream_set_address_pool,
|
2012-11-15 15:18:29 +00:00
|
|
|
pool);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2011-01-12 12:57:09 +00:00
|
|
|
|
2012-11-13 10:15:35 +00:00
|
|
|
if (old)
|
|
|
|
g_object_unref (old);
|
2011-01-12 12:57:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-14 16:23:59 +00:00
|
|
|
* gst_rtsp_media_get_address_pool:
|
2011-01-12 12:57:09 +00:00
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
2012-11-14 16:23:59 +00:00
|
|
|
* Get the #GstRTSPAddressPool used as the address pool of @media.
|
2011-01-12 12:57:09 +00:00
|
|
|
*
|
2012-11-14 16:23:59 +00:00
|
|
|
* Returns: (transfer full): the #GstRTSPAddressPool of @media. g_object_unref() after
|
2011-01-12 12:57:09 +00:00
|
|
|
* usage.
|
|
|
|
*/
|
2012-11-14 16:23:59 +00:00
|
|
|
GstRTSPAddressPool *
|
|
|
|
gst_rtsp_media_get_address_pool (GstRTSPMedia * media)
|
2011-01-12 12:57:09 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
2012-11-14 16:23:59 +00:00
|
|
|
GstRTSPAddressPool *result;
|
2011-01-12 12:57:09 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((result = priv->pool))
|
2011-01-12 12:57:09 +00:00
|
|
|
g_object_ref (result);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2011-01-12 12:57:09 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_collect_streams:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
2013-11-22 00:30:53 +00:00
|
|
|
* Find all payloader elements, they should be named pay\%d in the
|
2012-10-25 19:29:58 +00:00
|
|
|
* element of @media, and create #GstRTSPStreams for them.
|
|
|
|
*
|
2013-11-22 00:30:53 +00:00
|
|
|
* Collect all dynamic elements, named dynpay\%d, and add them to
|
2012-10-25 19:29:58 +00:00
|
|
|
* the list of dynamic elements.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_media_collect_streams (GstRTSPMedia * media)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstElement *element, *elem;
|
|
|
|
GstPad *pad;
|
|
|
|
gint i;
|
|
|
|
gboolean have_elem;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
element = priv->element;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
have_elem = TRUE;
|
|
|
|
for (i = 0; have_elem; i++) {
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
have_elem = FALSE;
|
|
|
|
|
|
|
|
name = g_strdup_printf ("pay%d", i);
|
|
|
|
if ((elem = gst_bin_get_by_name (GST_BIN (element), name))) {
|
|
|
|
GST_INFO ("found stream %d with payloader %p", i, elem);
|
|
|
|
|
|
|
|
/* take the pad of the payloader */
|
|
|
|
pad = gst_element_get_static_pad (elem, "src");
|
|
|
|
/* create the stream */
|
|
|
|
gst_rtsp_media_create_stream (media, elem, pad);
|
2012-11-28 11:10:47 +00:00
|
|
|
gst_object_unref (pad);
|
2012-10-25 19:29:58 +00:00
|
|
|
gst_object_unref (elem);
|
|
|
|
|
|
|
|
have_elem = TRUE;
|
|
|
|
}
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
name = g_strdup_printf ("dynpay%d", i);
|
|
|
|
if ((elem = gst_bin_get_by_name (GST_BIN (element), name))) {
|
|
|
|
/* a stream that will dynamically create pads to provide RTP packets */
|
|
|
|
GST_INFO ("found dynamic element %d, %p", i, elem);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->dynamic = g_list_prepend (priv->dynamic, elem);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
have_elem = TRUE;
|
|
|
|
}
|
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_create_stream:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @payloader: a #GstElement
|
|
|
|
* @srcpad: a source #GstPad
|
|
|
|
*
|
|
|
|
* Create a new stream in @media that provides RTP data on @srcpad.
|
|
|
|
* @srcpad should be a pad of an element inside @media->element.
|
|
|
|
*
|
2012-10-28 12:48:44 +00:00
|
|
|
* Returns: (transfer none): a new #GstRTSPStream that remains valid for as long
|
2014-03-23 20:24:48 +00:00
|
|
|
* as @media exists.
|
2012-10-25 19:29:58 +00:00
|
|
|
*/
|
|
|
|
GstRTSPStream *
|
|
|
|
gst_rtsp_media_create_stream (GstRTSPMedia * media, GstElement * payloader,
|
|
|
|
GstPad * pad)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStream *stream;
|
|
|
|
GstPad *srcpad;
|
|
|
|
gchar *name;
|
|
|
|
gint idx;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
|
|
|
|
g_return_val_if_fail (GST_IS_ELEMENT (payloader), NULL);
|
|
|
|
g_return_val_if_fail (GST_IS_PAD (pad), NULL);
|
|
|
|
g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
idx = priv->streams->len;
|
|
|
|
|
|
|
|
GST_DEBUG ("media %p: creating stream with index %d", media, idx);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
name = g_strdup_printf ("src_%u", idx);
|
|
|
|
srcpad = gst_ghost_pad_new (name, pad);
|
|
|
|
gst_pad_set_active (srcpad, TRUE);
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_element_add_pad (priv->element, srcpad);
|
2012-10-25 19:29:58 +00:00
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
stream = gst_rtsp_stream_new (idx, payloader, srcpad);
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->pool)
|
|
|
|
gst_rtsp_stream_set_address_pool (stream, priv->pool);
|
2014-03-03 15:55:48 +00:00
|
|
|
gst_rtsp_stream_set_profiles (stream, priv->profiles);
|
2013-08-16 14:10:43 +00:00
|
|
|
gst_rtsp_stream_set_protocols (stream, priv->protocols);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_ptr_array_add (priv->streams, stream);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-15 14:41:42 +00:00
|
|
|
g_signal_emit (media, gst_rtsp_media_signals[SIGNAL_NEW_STREAM], 0, stream,
|
|
|
|
NULL);
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
return stream;
|
|
|
|
}
|
2011-01-12 12:57:09 +00:00
|
|
|
|
2013-04-22 15:34:37 +00:00
|
|
|
static void
|
|
|
|
gst_rtsp_media_remove_stream (GstRTSPMedia * media, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
GstPad *srcpad;
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
/* remove the ghostpad */
|
|
|
|
srcpad = gst_rtsp_stream_get_srcpad (stream);
|
|
|
|
gst_element_remove_pad (priv->element, srcpad);
|
|
|
|
gst_object_unref (srcpad);
|
|
|
|
/* now remove the stream */
|
|
|
|
g_object_ref (stream);
|
|
|
|
g_ptr_array_remove (priv->streams, stream);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
g_signal_emit (media, gst_rtsp_media_signals[SIGNAL_REMOVED_STREAM], 0,
|
|
|
|
stream, NULL);
|
|
|
|
|
|
|
|
g_object_unref (stream);
|
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/**
|
2009-01-22 16:58:19 +00:00
|
|
|
* gst_rtsp_media_n_streams:
|
|
|
|
* @media: a #GstRTSPMedia
|
2008-10-09 12:29:12 +00:00
|
|
|
*
|
2009-01-22 16:58:19 +00:00
|
|
|
* Get the number of streams in this media.
|
2008-10-09 12:29:12 +00:00
|
|
|
*
|
|
|
|
* Returns: The number of streams.
|
|
|
|
*/
|
|
|
|
guint
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_n_streams (GstRTSPMedia * media)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
2012-11-13 10:15:35 +00:00
|
|
|
guint res;
|
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), 0);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
res = priv->streams->len;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:15:35 +00:00
|
|
|
|
|
|
|
return res;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-22 16:58:19 +00:00
|
|
|
* gst_rtsp_media_get_stream:
|
|
|
|
* @media: a #GstRTSPMedia
|
2008-10-09 12:29:12 +00:00
|
|
|
* @idx: the stream index
|
|
|
|
*
|
2009-01-22 16:58:19 +00:00
|
|
|
* Retrieve the stream with index @idx from @media.
|
2008-10-09 12:29:12 +00:00
|
|
|
*
|
2014-06-11 23:38:36 +00:00
|
|
|
* Returns: (nullable) (transfer none): the #GstRTSPStream at index
|
|
|
|
* @idx or %NULL when a stream with that index did not exist.
|
2008-10-09 12:29:12 +00:00
|
|
|
*/
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStream *
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_get_stream (GstRTSPMedia * media, guint idx)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStream *res;
|
2010-03-05 15:20:08 +00:00
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if (idx < priv->streams->len)
|
|
|
|
res = g_ptr_array_index (priv->streams, idx);
|
2009-01-30 15:24:10 +00:00
|
|
|
else
|
|
|
|
res = NULL;
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-07-03 13:14:39 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_find_stream:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @control: the control of the stream
|
|
|
|
*
|
|
|
|
* Find a stream in @media with @control as the control uri.
|
|
|
|
*
|
2014-06-11 23:38:36 +00:00
|
|
|
* Returns: (nullable) (transfer none): the #GstRTSPStream with
|
|
|
|
* control uri @control or %NULL when a stream with that control did
|
|
|
|
* not exist.
|
2013-07-03 13:14:39 +00:00
|
|
|
*/
|
|
|
|
GstRTSPStream *
|
|
|
|
gst_rtsp_media_find_stream (GstRTSPMedia * media, const gchar * control)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
GstRTSPStream *res;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
|
|
|
|
g_return_val_if_fail (control != NULL, NULL);
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
res = NULL;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
for (i = 0; i < priv->streams->len; i++) {
|
|
|
|
GstRTSPStream *test;
|
|
|
|
|
|
|
|
test = g_ptr_array_index (priv->streams, i);
|
|
|
|
if (gst_rtsp_stream_has_control (test, control)) {
|
|
|
|
res = test;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-11-26 16:23:04 +00:00
|
|
|
/* called with state-lock */
|
|
|
|
static gboolean
|
|
|
|
default_convert_range (GstRTSPMedia * media, GstRTSPTimeRange * range,
|
|
|
|
GstRTSPRangeUnit unit)
|
|
|
|
{
|
|
|
|
return gst_rtsp_range_convert_units (range, unit);
|
|
|
|
}
|
|
|
|
|
2010-12-28 17:35:01 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_get_range_string:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @play: for the PLAY request
|
2013-02-22 19:17:29 +00:00
|
|
|
* @unit: the unit to use for the string
|
2010-12-28 17:35:01 +00:00
|
|
|
*
|
2012-11-28 13:45:30 +00:00
|
|
|
* Get the current range as a string. @media must be prepared with
|
|
|
|
* gst_rtsp_media_prepare ().
|
2010-12-28 17:35:01 +00:00
|
|
|
*
|
2014-03-23 20:24:48 +00:00
|
|
|
* Returns: (transfer full): The range as a string, g_free() after usage.
|
2010-12-28 17:35:01 +00:00
|
|
|
*/
|
|
|
|
gchar *
|
2013-02-22 19:17:29 +00:00
|
|
|
gst_rtsp_media_get_range_string (GstRTSPMedia * media, gboolean play,
|
|
|
|
GstRTSPRangeUnit unit)
|
2010-12-28 17:35:01 +00:00
|
|
|
{
|
2013-06-05 13:49:45 +00:00
|
|
|
GstRTSPMediaClass *klass;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
2010-12-28 17:35:01 +00:00
|
|
|
gchar *result;
|
|
|
|
GstRTSPTimeRange range;
|
|
|
|
|
2013-06-05 13:49:45 +00:00
|
|
|
klass = GST_RTSP_MEDIA_GET_CLASS (media);
|
2012-11-28 13:45:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
|
2013-06-05 13:49:45 +00:00
|
|
|
g_return_val_if_fail (klass->convert_range != NULL, FALSE);
|
2012-11-28 13:45:30 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
2013-11-29 09:53:08 +00:00
|
|
|
if (priv->status != GST_RTSP_MEDIA_STATUS_PREPARED &&
|
|
|
|
priv->status != GST_RTSP_MEDIA_STATUS_SUSPENDED)
|
2012-11-28 13:45:30 +00:00
|
|
|
goto not_prepared;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2013-06-11 23:09:42 +00:00
|
|
|
|
|
|
|
/* Update the range value with current position/duration */
|
|
|
|
collect_media_stats (media);
|
|
|
|
|
2010-12-28 17:35:01 +00:00
|
|
|
/* make copy */
|
2012-11-29 10:11:05 +00:00
|
|
|
range = priv->range;
|
2010-12-28 17:35:01 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (!play && priv->n_active > 0) {
|
2010-12-28 17:35:01 +00:00
|
|
|
range.min.type = GST_RTSP_TIME_NOW;
|
|
|
|
range.min.seconds = -1;
|
|
|
|
}
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2010-12-28 17:35:01 +00:00
|
|
|
|
2013-06-25 13:46:41 +00:00
|
|
|
if (!klass->convert_range (media, &range, unit))
|
2013-06-05 13:49:45 +00:00
|
|
|
goto conversion_failed;
|
2013-02-22 19:17:29 +00:00
|
|
|
|
2010-12-28 17:35:01 +00:00
|
|
|
result = gst_rtsp_range_to_string (&range);
|
|
|
|
|
|
|
|
return result;
|
2012-11-28 13:45:30 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
not_prepared:
|
|
|
|
{
|
|
|
|
GST_WARNING ("media %p was not prepared", media);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2012-11-28 13:45:30 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2013-06-05 13:49:45 +00:00
|
|
|
conversion_failed:
|
|
|
|
{
|
|
|
|
GST_WARNING ("range conversion to unit %d failed", unit);
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-12-28 17:35:01 +00:00
|
|
|
}
|
|
|
|
|
2013-11-28 13:06:53 +00:00
|
|
|
static void
|
|
|
|
stream_update_blocked (GstRTSPStream * stream, GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
gst_rtsp_stream_set_blocked (stream, media->priv->blocked);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
media_streams_set_blocked (GstRTSPMedia * media, gboolean blocked)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
|
|
|
|
|
|
|
GST_DEBUG ("media %p set blocked %d", media, blocked);
|
|
|
|
priv->blocked = blocked;
|
|
|
|
g_ptr_array_foreach (priv->streams, (GFunc) stream_update_blocked, media);
|
|
|
|
}
|
|
|
|
|
2014-04-08 10:08:17 +00:00
|
|
|
static void
|
|
|
|
gst_rtsp_media_set_status (GstRTSPMedia * media, GstRTSPMediaStatus status)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->status = status;
|
|
|
|
GST_DEBUG ("setting new status to %d", status);
|
|
|
|
g_cond_broadcast (&priv->cond);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_get_status:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Get the status of @media. When @media is busy preparing, this function waits
|
|
|
|
* until @media is prepared or in error.
|
|
|
|
*
|
|
|
|
* Returns: the status of @media.
|
|
|
|
*/
|
|
|
|
GstRTSPMediaStatus
|
|
|
|
gst_rtsp_media_get_status (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
|
|
|
GstRTSPMediaStatus result;
|
|
|
|
gint64 end_time;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
end_time = g_get_monotonic_time () + 20 * G_TIME_SPAN_SECOND;
|
|
|
|
/* while we are preparing, wait */
|
|
|
|
while (priv->status == GST_RTSP_MEDIA_STATUS_PREPARING) {
|
|
|
|
GST_DEBUG ("waiting for status change");
|
|
|
|
if (!g_cond_wait_until (&priv->cond, &priv->lock, end_time)) {
|
|
|
|
GST_DEBUG ("timeout, assuming error status");
|
|
|
|
priv->status = GST_RTSP_MEDIA_STATUS_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* could be success or error */
|
|
|
|
result = priv->status;
|
|
|
|
GST_DEBUG ("got status %d", result);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-03-12 19:32:14 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_seek:
|
2010-12-11 09:48:25 +00:00
|
|
|
* @media: a #GstRTSPMedia
|
2014-03-23 20:24:48 +00:00
|
|
|
* @range: (transfer none): a #GstRTSPTimeRange
|
2009-03-12 19:32:14 +00:00
|
|
|
*
|
2012-11-28 13:45:30 +00:00
|
|
|
* Seek the pipeline of @media to @range. @media must be prepared with
|
|
|
|
* gst_rtsp_media_prepare().
|
2009-03-12 19:32:14 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_seek (GstRTSPMedia * media, GstRTSPTimeRange * range)
|
2009-03-12 19:32:14 +00:00
|
|
|
{
|
2013-05-29 11:45:00 +00:00
|
|
|
GstRTSPMediaClass *klass;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
2009-03-12 19:32:14 +00:00
|
|
|
gboolean res;
|
2012-11-21 15:41:56 +00:00
|
|
|
GstClockTime start, stop;
|
2009-03-12 19:32:14 +00:00
|
|
|
GstSeekType start_type, stop_type;
|
2013-09-10 01:51:44 +00:00
|
|
|
GstQuery *query;
|
2009-03-12 19:32:14 +00:00
|
|
|
|
2013-05-29 11:45:00 +00:00
|
|
|
klass = GST_RTSP_MEDIA_GET_CLASS (media);
|
|
|
|
|
2009-03-12 19:32:14 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
g_return_val_if_fail (range != NULL, FALSE);
|
2013-06-05 13:49:45 +00:00
|
|
|
g_return_val_if_fail (klass->convert_range != NULL, FALSE);
|
2009-03-12 19:32:14 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
|
|
|
if (priv->status != GST_RTSP_MEDIA_STATUS_PREPARED)
|
2012-11-28 13:45:30 +00:00
|
|
|
goto not_prepared;
|
|
|
|
|
2013-09-10 01:51:44 +00:00
|
|
|
/* Update the seekable state of the pipeline in case it changed */
|
|
|
|
query = gst_query_new_seeking (GST_FORMAT_TIME);
|
|
|
|
if (gst_element_query (priv->pipeline, query)) {
|
|
|
|
GstFormat format;
|
|
|
|
gboolean seekable;
|
|
|
|
gint64 start, end;
|
|
|
|
|
|
|
|
gst_query_parse_seeking (query, &format, &seekable, &start, &end);
|
|
|
|
priv->seekable = seekable;
|
|
|
|
}
|
|
|
|
gst_query_unref (query);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (!priv->seekable)
|
2012-11-13 10:15:35 +00:00
|
|
|
goto not_seekable;
|
2011-09-16 15:31:17 +00:00
|
|
|
|
2009-03-12 19:32:14 +00:00
|
|
|
start_type = stop_type = GST_SEEK_TYPE_NONE;
|
|
|
|
|
2013-06-05 13:49:45 +00:00
|
|
|
if (!klass->convert_range (media, range, GST_RTSP_RANGE_NPT))
|
2012-11-21 15:41:56 +00:00
|
|
|
goto not_supported;
|
2013-06-05 13:49:45 +00:00
|
|
|
gst_rtsp_range_get_times (range, &start, &stop);
|
2012-11-21 15:41:56 +00:00
|
|
|
|
2012-11-21 16:21:28 +00:00
|
|
|
GST_INFO ("got %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (start), GST_TIME_ARGS (stop));
|
|
|
|
GST_INFO ("current %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT,
|
2012-11-29 10:11:05 +00:00
|
|
|
GST_TIME_ARGS (priv->range_start), GST_TIME_ARGS (priv->range_stop));
|
2012-11-21 16:21:28 +00:00
|
|
|
|
2014-02-18 08:44:34 +00:00
|
|
|
if (start != GST_CLOCK_TIME_NONE)
|
2012-11-21 15:41:56 +00:00
|
|
|
start_type = GST_SEEK_TYPE_SET;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->range_stop == stop)
|
2012-11-21 15:41:56 +00:00
|
|
|
stop = GST_CLOCK_TIME_NONE;
|
|
|
|
else if (stop != GST_CLOCK_TIME_NONE)
|
|
|
|
stop_type = GST_SEEK_TYPE_SET;
|
2010-03-05 15:20:08 +00:00
|
|
|
|
2012-11-21 15:41:56 +00:00
|
|
|
if (start != GST_CLOCK_TIME_NONE || stop != GST_CLOCK_TIME_NONE) {
|
2014-02-06 08:48:05 +00:00
|
|
|
GstSeekFlags flags;
|
|
|
|
|
2010-03-05 15:20:08 +00:00
|
|
|
GST_INFO ("seeking to %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (start), GST_TIME_ARGS (stop));
|
2009-03-12 19:32:14 +00:00
|
|
|
|
2014-04-08 10:08:17 +00:00
|
|
|
gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_PREPARING);
|
2013-11-28 13:06:53 +00:00
|
|
|
if (priv->blocked)
|
|
|
|
media_streams_set_blocked (media, TRUE);
|
|
|
|
|
2014-02-18 15:58:45 +00:00
|
|
|
/* depends on the current playing state of the pipeline. We might need to
|
|
|
|
* queue this until we get EOS. */
|
|
|
|
flags = GST_SEEK_FLAG_FLUSH;
|
2014-02-06 08:48:05 +00:00
|
|
|
|
2014-02-18 08:44:34 +00:00
|
|
|
/* if range start was not supplied we must continue from current position.
|
|
|
|
* but since we're doing a flushing seek, let us query the current position
|
|
|
|
* so we end up at exactly the same position after the seek. */
|
|
|
|
if (range->min.type == GST_RTSP_TIME_END) { /* Yepp, that's right! */
|
|
|
|
gint64 position;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
if (klass->query_position)
|
|
|
|
ret = klass->query_position (media, &position);
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
GST_WARNING ("position query failed");
|
|
|
|
} else {
|
|
|
|
GST_DEBUG ("doing accurate seek to %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (position));
|
|
|
|
start = position;
|
|
|
|
start_type = GST_SEEK_TYPE_SET;
|
|
|
|
flags |= GST_SEEK_FLAG_ACCURATE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* only set keyframe flag when modifying start */
|
|
|
|
if (start_type != GST_SEEK_TYPE_NONE)
|
|
|
|
flags |= GST_SEEK_FLAG_KEY_UNIT;
|
|
|
|
}
|
2014-02-06 08:48:05 +00:00
|
|
|
|
2014-06-13 14:46:06 +00:00
|
|
|
/* FIXME, we only do forwards playback, no trick modes yet */
|
2012-11-29 10:11:05 +00:00
|
|
|
res = gst_element_seek (priv->pipeline, 1.0, GST_FORMAT_TIME,
|
2010-03-05 12:28:58 +00:00
|
|
|
flags, start_type, start, stop_type, stop);
|
2009-03-12 19:32:14 +00:00
|
|
|
|
|
|
|
/* and block for the seek to complete */
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("done seeking %d", res);
|
2013-11-28 12:58:05 +00:00
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
|
|
|
|
/* wait until pipeline is prerolled again, this will also collect stats */
|
|
|
|
if (!wait_preroll (media))
|
|
|
|
goto preroll_failed;
|
2010-03-05 18:08:08 +00:00
|
|
|
|
2013-11-28 12:58:05 +00:00
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
|
|
|
GST_INFO ("prerolled again");
|
2010-03-05 15:20:08 +00:00
|
|
|
} else {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("no seek needed");
|
2009-03-12 19:32:14 +00:00
|
|
|
res = TRUE;
|
|
|
|
}
|
2012-11-29 10:11:05 +00:00
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2009-03-12 19:32:14 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2012-11-28 13:45:30 +00:00
|
|
|
not_prepared:
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2012-11-28 13:45:30 +00:00
|
|
|
GST_INFO ("media %p is not prepared", media);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-11-13 10:15:35 +00:00
|
|
|
not_seekable:
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2012-11-13 10:15:35 +00:00
|
|
|
GST_INFO ("pipeline is not seekable");
|
2013-09-10 01:51:23 +00:00
|
|
|
return FALSE;
|
2012-11-13 10:15:35 +00:00
|
|
|
}
|
2009-03-12 19:32:14 +00:00
|
|
|
not_supported:
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2013-06-05 13:49:45 +00:00
|
|
|
GST_WARNING ("conversion to npt not supported");
|
2009-03-12 19:32:14 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-11-28 12:58:05 +00:00
|
|
|
preroll_failed:
|
|
|
|
{
|
|
|
|
GST_WARNING ("failed to preroll after seek");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-03-12 19:32:14 +00:00
|
|
|
}
|
|
|
|
|
2013-11-28 13:06:53 +00:00
|
|
|
static void
|
|
|
|
stream_collect_blocking (GstRTSPStream * stream, gboolean * blocked)
|
|
|
|
{
|
|
|
|
*blocked &= gst_rtsp_stream_is_blocking (stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
media_streams_blocking (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
gboolean blocking = TRUE;
|
|
|
|
|
|
|
|
g_ptr_array_foreach (media->priv->streams, (GFunc) stream_collect_blocking,
|
|
|
|
&blocking);
|
|
|
|
|
|
|
|
return blocking;
|
|
|
|
}
|
|
|
|
|
2014-01-21 13:46:47 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
set_state (GstRTSPMedia * media, GstState state)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
|
|
|
GST_INFO ("set state to %s for media %p", gst_element_state_get_name (state),
|
|
|
|
media);
|
|
|
|
ret = gst_element_set_state (priv->pipeline, state);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
set_target_state (GstRTSPMedia * media, GstState state, gboolean do_state)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
|
|
|
GST_INFO ("set target state to %s for media %p",
|
|
|
|
gst_element_state_get_name (state), media);
|
|
|
|
priv->target_state = state;
|
|
|
|
|
|
|
|
g_signal_emit (media, gst_rtsp_media_signals[SIGNAL_TARGET_STATE], 0,
|
|
|
|
priv->target_state, NULL);
|
|
|
|
|
|
|
|
if (do_state)
|
|
|
|
ret = set_state (media, state);
|
|
|
|
else
|
|
|
|
ret = GST_STATE_CHANGE_SUCCESS;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-13 10:49:08 +00:00
|
|
|
/* called with state-lock */
|
2009-02-13 15:39:36 +00:00
|
|
|
static gboolean
|
2010-03-05 15:20:08 +00:00
|
|
|
default_handle_message (GstRTSPMedia * media, GstMessage * message)
|
2009-02-13 15:39:36 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
2009-02-13 15:39:36 +00:00
|
|
|
GstMessageType type;
|
|
|
|
|
|
|
|
type = GST_MESSAGE_TYPE (message);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case GST_MESSAGE_STATE_CHANGED:
|
|
|
|
break;
|
|
|
|
case GST_MESSAGE_BUFFERING:
|
|
|
|
{
|
|
|
|
gint percent;
|
|
|
|
|
|
|
|
gst_message_parse_buffering (message, &percent);
|
|
|
|
|
|
|
|
/* no state management needed for live pipelines */
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->is_live)
|
2009-02-13 15:39:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (percent == 100) {
|
|
|
|
/* a 100% message means buffering is done */
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->buffering = FALSE;
|
2009-02-13 15:39:36 +00:00
|
|
|
/* if the desired state is playing, go back */
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->target_state == GST_STATE_PLAYING) {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("Buffering done, setting pipeline to PLAYING");
|
2014-01-21 13:46:47 +00:00
|
|
|
set_state (media, GST_STATE_PLAYING);
|
2010-03-05 15:20:08 +00:00
|
|
|
} else {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("Buffering done");
|
2010-03-05 12:28:58 +00:00
|
|
|
}
|
2009-02-13 15:39:36 +00:00
|
|
|
} else {
|
|
|
|
/* buffering busy */
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->buffering == FALSE) {
|
|
|
|
if (priv->target_state == GST_STATE_PLAYING) {
|
2009-02-13 15:39:36 +00:00
|
|
|
/* we were not buffering but PLAYING, PAUSE the pipeline. */
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("Buffering, setting pipeline to PAUSED ...");
|
2014-01-21 13:46:47 +00:00
|
|
|
set_state (media, GST_STATE_PAUSED);
|
2010-03-05 15:20:08 +00:00
|
|
|
} else {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("Buffering ...");
|
2010-03-05 12:28:58 +00:00
|
|
|
}
|
2009-02-13 15:39:36 +00:00
|
|
|
}
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->buffering = TRUE;
|
2009-02-13 15:39:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_MESSAGE_LATENCY:
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_bin_recalculate_latency (GST_BIN_CAST (priv->pipeline));
|
2009-02-13 15:39:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_MESSAGE_ERROR:
|
|
|
|
{
|
|
|
|
GError *gerror;
|
|
|
|
gchar *debug;
|
|
|
|
|
|
|
|
gst_message_parse_error (message, &gerror, &debug);
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_WARNING ("%p: got error %s (%s)", media, gerror->message, debug);
|
2009-02-13 15:39:36 +00:00
|
|
|
g_error_free (gerror);
|
|
|
|
g_free (debug);
|
2010-03-05 16:51:26 +00:00
|
|
|
|
|
|
|
gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_ERROR);
|
2009-02-13 15:39:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-03-11 15:45:12 +00:00
|
|
|
case GST_MESSAGE_WARNING:
|
|
|
|
{
|
|
|
|
GError *gerror;
|
|
|
|
gchar *debug;
|
|
|
|
|
|
|
|
gst_message_parse_warning (message, &gerror, &debug);
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_WARNING ("%p: got warning %s (%s)", media, gerror->message, debug);
|
2009-03-11 15:45:12 +00:00
|
|
|
g_error_free (gerror);
|
|
|
|
g_free (debug);
|
|
|
|
break;
|
|
|
|
}
|
2009-05-26 09:42:41 +00:00
|
|
|
case GST_MESSAGE_ELEMENT:
|
2013-11-28 13:06:53 +00:00
|
|
|
{
|
|
|
|
const GstStructure *s;
|
|
|
|
|
|
|
|
s = gst_message_get_structure (message);
|
|
|
|
if (gst_structure_has_name (s, "GstRTSPStreamBlocking")) {
|
|
|
|
GST_DEBUG ("media received blocking message");
|
|
|
|
if (priv->blocked && media_streams_blocking (media)) {
|
|
|
|
GST_DEBUG ("media is blocking");
|
|
|
|
collect_media_stats (media);
|
|
|
|
|
|
|
|
if (priv->status == GST_RTSP_MEDIA_STATUS_PREPARING)
|
|
|
|
gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_PREPARED);
|
|
|
|
}
|
|
|
|
}
|
2009-05-26 09:42:41 +00:00
|
|
|
break;
|
2013-11-28 13:06:53 +00:00
|
|
|
}
|
2009-06-04 16:32:15 +00:00
|
|
|
case GST_MESSAGE_STREAM_STATUS:
|
|
|
|
break;
|
2010-03-05 16:51:26 +00:00
|
|
|
case GST_MESSAGE_ASYNC_DONE:
|
2013-04-09 18:11:35 +00:00
|
|
|
if (priv->adding) {
|
2010-12-11 16:31:44 +00:00
|
|
|
/* when we are dynamically adding pads, the addition of the udpsrc will
|
|
|
|
* temporarily produce ASYNC_DONE messages. We have to ignore them and
|
|
|
|
* wait for the final ASYNC_DONE after everything prerolled */
|
2013-04-09 18:11:35 +00:00
|
|
|
GST_INFO ("%p: ignoring ASYNC_DONE", media);
|
|
|
|
} else {
|
2010-12-11 16:31:44 +00:00
|
|
|
GST_INFO ("%p: got ASYNC_DONE", media);
|
|
|
|
collect_media_stats (media);
|
|
|
|
|
2012-11-30 11:53:02 +00:00
|
|
|
if (priv->status == GST_RTSP_MEDIA_STATUS_PREPARING)
|
|
|
|
gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_PREPARED);
|
2010-12-11 16:31:44 +00:00
|
|
|
}
|
2010-03-05 16:51:26 +00:00
|
|
|
break;
|
2010-08-20 16:17:08 +00:00
|
|
|
case GST_MESSAGE_EOS:
|
|
|
|
GST_INFO ("%p: got EOS", media);
|
2012-11-13 10:15:35 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->status == GST_RTSP_MEDIA_STATUS_UNPREPARING) {
|
2010-08-20 16:17:08 +00:00
|
|
|
GST_DEBUG ("shutting down after EOS");
|
2012-10-25 19:29:58 +00:00
|
|
|
finish_unprepare (media);
|
2010-08-20 16:17:08 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-02-13 15:39:36 +00:00
|
|
|
default:
|
2012-11-30 11:54:10 +00:00
|
|
|
GST_INFO ("%p: got message type %d (%s)", media, type,
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_message_type_get_name (type));
|
2009-02-13 15:39:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-03-05 15:20:08 +00:00
|
|
|
bus_message (GstBus * bus, GstMessage * message, GstRTSPMedia * media)
|
2009-02-13 15:39:36 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
2009-02-13 15:39:36 +00:00
|
|
|
GstRTSPMediaClass *klass;
|
|
|
|
gboolean ret;
|
2010-03-05 15:20:08 +00:00
|
|
|
|
2009-02-13 15:39:36 +00:00
|
|
|
klass = GST_RTSP_MEDIA_GET_CLASS (media);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
2009-02-13 15:39:36 +00:00
|
|
|
if (klass->handle_message)
|
|
|
|
ret = klass->handle_message (media, message);
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
2012-11-29 10:11:05 +00:00
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2009-02-13 15:39:36 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-19 14:47:08 +00:00
|
|
|
static void
|
|
|
|
watch_destroyed (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (media, "source destroyed");
|
2012-11-30 09:05:48 +00:00
|
|
|
g_object_unref (media);
|
2012-11-19 14:47:08 +00:00
|
|
|
}
|
|
|
|
|
2013-11-15 20:14:32 +00:00
|
|
|
static GstElement *
|
|
|
|
find_payload_element (GstElement * payloader)
|
|
|
|
{
|
|
|
|
GstElement *pay = NULL;
|
|
|
|
|
2013-11-26 15:24:35 +00:00
|
|
|
if (GST_IS_BIN (payloader)) {
|
|
|
|
GstIterator *iter;
|
|
|
|
GValue item = { 0 };
|
2013-11-22 10:16:20 +00:00
|
|
|
|
2013-11-26 15:24:35 +00:00
|
|
|
iter = gst_bin_iterate_recurse (GST_BIN (payloader));
|
|
|
|
while (gst_iterator_next (iter, &item) == GST_ITERATOR_OK) {
|
|
|
|
GstElement *element = (GstElement *) g_value_get_object (&item);
|
|
|
|
GstElementClass *eclass = GST_ELEMENT_GET_CLASS (element);
|
|
|
|
const gchar *klass;
|
2013-11-22 10:16:20 +00:00
|
|
|
|
2013-11-26 15:24:35 +00:00
|
|
|
klass =
|
|
|
|
gst_element_class_get_metadata (eclass, GST_ELEMENT_METADATA_KLASS);
|
|
|
|
if (klass == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (strstr (klass, "Payloader") && strstr (klass, "RTP")) {
|
|
|
|
pay = gst_object_ref (element);
|
|
|
|
g_value_unset (&item);
|
|
|
|
break;
|
|
|
|
}
|
2013-11-15 20:14:32 +00:00
|
|
|
g_value_unset (&item);
|
|
|
|
}
|
2013-11-26 15:24:35 +00:00
|
|
|
gst_iterator_free (iter);
|
|
|
|
} else {
|
|
|
|
pay = g_object_ref (payloader);
|
2013-11-15 20:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pay;
|
|
|
|
}
|
|
|
|
|
2010-08-24 14:47:30 +00:00
|
|
|
/* called from streaming threads */
|
2009-05-24 17:34:52 +00:00
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
pad_added_cb (GstElement * element, GstPad * pad, GstRTSPMedia * media)
|
2009-05-24 17:34:52 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStream *stream;
|
2013-11-15 20:14:32 +00:00
|
|
|
GstElement *pay;
|
2009-05-24 17:34:52 +00:00
|
|
|
|
2013-11-15 20:14:32 +00:00
|
|
|
/* find the real payload element */
|
|
|
|
pay = find_payload_element (element);
|
|
|
|
stream = gst_rtsp_media_create_stream (media, pay, pad);
|
|
|
|
gst_object_unref (pay);
|
2012-10-26 15:28:10 +00:00
|
|
|
|
2012-11-30 05:17:46 +00:00
|
|
|
GST_INFO ("pad added %s:%s, stream %p", GST_DEBUG_PAD_NAME (pad), stream);
|
2009-05-24 17:34:52 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
2014-04-08 12:49:41 +00:00
|
|
|
if (priv->status != GST_RTSP_MEDIA_STATUS_PREPARING)
|
|
|
|
goto not_preparing;
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (pad), "gst-rtsp-dynpad-stream", stream);
|
|
|
|
|
2012-10-26 15:28:10 +00:00
|
|
|
/* we will be adding elements below that will cause ASYNC_DONE to be
|
|
|
|
* posted in the bus. We want to ignore those messages until the
|
|
|
|
* pipeline really prerolled. */
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->adding = TRUE;
|
2010-12-11 16:31:44 +00:00
|
|
|
|
2012-10-26 15:28:10 +00:00
|
|
|
/* join the element in the PAUSED state because this callback is
|
|
|
|
* called from the streaming thread and it is PAUSED */
|
2014-03-31 09:00:11 +00:00
|
|
|
if (!gst_rtsp_stream_join_bin (stream, GST_BIN (priv->pipeline),
|
2014-04-01 11:04:21 +00:00
|
|
|
priv->rtpbin, GST_STATE_PAUSED)) {
|
2014-03-31 09:00:11 +00:00
|
|
|
GST_WARNING ("failed to join bin element");
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->adding = FALSE;
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2014-04-08 12:49:41 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
not_preparing:
|
|
|
|
{
|
|
|
|
gst_rtsp_media_remove_stream (media, stream);
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
GST_INFO ("ignore pad because we are not preparing");
|
|
|
|
return;
|
|
|
|
}
|
2009-05-24 17:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-22 15:34:37 +00:00
|
|
|
pad_removed_cb (GstElement * element, GstPad * pad, GstRTSPMedia * media)
|
2009-05-24 17:34:52 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
2013-04-22 15:34:37 +00:00
|
|
|
GstRTSPStream *stream;
|
|
|
|
|
|
|
|
stream = g_object_get_data (G_OBJECT (pad), "gst-rtsp-dynpad-stream");
|
|
|
|
if (stream == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GST_INFO ("pad removed %s:%s, stream %p", GST_DEBUG_PAD_NAME (pad), stream);
|
|
|
|
|
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
|
|
|
gst_rtsp_stream_leave_bin (stream, GST_BIN (priv->pipeline), priv->rtpbin);
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
|
|
|
|
gst_rtsp_media_remove_stream (media, stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_fakesink (GstRTSPMediaPrivate * priv)
|
|
|
|
{
|
2012-11-13 10:15:35 +00:00
|
|
|
GstElement *fakesink;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2013-04-23 08:27:35 +00:00
|
|
|
if ((fakesink = priv->fakesink))
|
2012-11-13 10:15:35 +00:00
|
|
|
gst_object_ref (fakesink);
|
2013-04-23 08:27:35 +00:00
|
|
|
priv->fakesink = NULL;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:15:35 +00:00
|
|
|
|
2013-04-23 08:27:35 +00:00
|
|
|
if (fakesink) {
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
|
2012-11-13 10:15:35 +00:00
|
|
|
gst_element_set_state (fakesink, GST_STATE_NULL);
|
|
|
|
gst_object_unref (fakesink);
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("removed fakesink");
|
2009-05-24 17:34:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-22 15:34:37 +00:00
|
|
|
static void
|
|
|
|
no_more_pads_cb (GstElement * element, GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
|
|
|
|
|
|
|
GST_INFO ("no more pads");
|
|
|
|
remove_fakesink (priv);
|
|
|
|
}
|
|
|
|
|
2013-04-22 14:40:48 +00:00
|
|
|
typedef struct _DynPaySignalHandlers DynPaySignalHandlers;
|
|
|
|
|
|
|
|
struct _DynPaySignalHandlers
|
|
|
|
{
|
|
|
|
gulong pad_added_handler;
|
2013-04-22 15:34:37 +00:00
|
|
|
gulong pad_removed_handler;
|
2013-04-22 14:40:48 +00:00
|
|
|
gulong no_more_pads_handler;
|
|
|
|
};
|
|
|
|
|
2013-07-09 18:44:51 +00:00
|
|
|
static gboolean
|
2013-11-28 12:58:05 +00:00
|
|
|
start_preroll (GstRTSPMedia * media)
|
2013-07-09 18:44:51 +00:00
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
|
|
|
GstStateChangeReturn ret;
|
2013-11-28 12:58:05 +00:00
|
|
|
|
|
|
|
GST_INFO ("setting pipeline to PAUSED for media %p", media);
|
|
|
|
/* first go to PAUSED */
|
2014-01-21 13:46:47 +00:00
|
|
|
ret = set_target_state (media, GST_STATE_PAUSED, TRUE);
|
2013-11-28 12:58:05 +00:00
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case GST_STATE_CHANGE_SUCCESS:
|
|
|
|
GST_INFO ("SUCCESS state change for media %p", media);
|
|
|
|
priv->seekable = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_ASYNC:
|
|
|
|
GST_INFO ("ASYNC state change for media %p", media);
|
|
|
|
priv->seekable = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_NO_PREROLL:
|
|
|
|
/* we need to go to PLAYING */
|
|
|
|
GST_INFO ("NO_PREROLL state change: live media %p", media);
|
|
|
|
/* FIXME we disable seeking for live streams for now. We should perform a
|
|
|
|
* seeking query in preroll instead */
|
|
|
|
priv->seekable = FALSE;
|
|
|
|
priv->is_live = TRUE;
|
2013-11-28 13:06:53 +00:00
|
|
|
/* start blocked to make sure nothing goes to the sink */
|
|
|
|
media_streams_set_blocked (media, TRUE);
|
2014-01-21 13:46:47 +00:00
|
|
|
ret = set_state (media, GST_STATE_PLAYING);
|
2013-11-28 12:58:05 +00:00
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
goto state_failed;
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_FAILURE:
|
|
|
|
goto state_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
state_failed:
|
|
|
|
{
|
|
|
|
GST_WARNING ("failed to preroll pipeline");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
wait_preroll (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
GstRTSPMediaStatus status;
|
|
|
|
|
|
|
|
GST_DEBUG ("wait to preroll pipeline");
|
|
|
|
|
|
|
|
/* wait until pipeline is prerolled */
|
|
|
|
status = gst_rtsp_media_get_status (media);
|
|
|
|
if (status == GST_RTSP_MEDIA_STATUS_ERROR)
|
|
|
|
goto preroll_failed;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
preroll_failed:
|
|
|
|
{
|
|
|
|
GST_WARNING ("failed to preroll pipeline");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
start_prepare (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
2013-07-09 18:44:51 +00:00
|
|
|
guint i;
|
|
|
|
GList *walk;
|
|
|
|
|
|
|
|
/* link streams we already have, other streams might appear when we have
|
|
|
|
* dynamic elements */
|
|
|
|
for (i = 0; i < priv->streams->len; i++) {
|
|
|
|
GstRTSPStream *stream;
|
|
|
|
|
|
|
|
stream = g_ptr_array_index (priv->streams, i);
|
|
|
|
|
2014-03-31 09:00:11 +00:00
|
|
|
if (!gst_rtsp_stream_join_bin (stream, GST_BIN (priv->pipeline),
|
2014-04-01 11:04:21 +00:00
|
|
|
priv->rtpbin, GST_STATE_NULL)) {
|
2014-03-31 09:00:11 +00:00
|
|
|
goto join_bin_failed;
|
|
|
|
}
|
2013-07-09 18:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (walk = priv->dynamic; walk; walk = g_list_next (walk)) {
|
|
|
|
GstElement *elem = walk->data;
|
|
|
|
DynPaySignalHandlers *handlers = g_slice_new (DynPaySignalHandlers);
|
|
|
|
|
|
|
|
GST_INFO ("adding callbacks for dynamic element %p", elem);
|
|
|
|
|
|
|
|
handlers->pad_added_handler = g_signal_connect (elem, "pad-added",
|
|
|
|
(GCallback) pad_added_cb, media);
|
|
|
|
handlers->pad_removed_handler = g_signal_connect (elem, "pad-removed",
|
|
|
|
(GCallback) pad_removed_cb, media);
|
|
|
|
handlers->no_more_pads_handler = g_signal_connect (elem, "no-more-pads",
|
|
|
|
(GCallback) no_more_pads_cb, media);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (elem), "gst-rtsp-dynpay-handlers", handlers);
|
|
|
|
|
|
|
|
/* we add a fakesink here in order to make the state change async. We remove
|
|
|
|
* the fakesink again in the no-more-pads callback. */
|
|
|
|
priv->fakesink = gst_element_factory_make ("fakesink", "fakesink");
|
|
|
|
gst_bin_add (GST_BIN (priv->pipeline), priv->fakesink);
|
|
|
|
}
|
|
|
|
|
2013-11-28 12:58:05 +00:00
|
|
|
if (!start_preroll (media))
|
|
|
|
goto preroll_failed;
|
2013-07-09 18:44:51 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
2014-03-31 09:00:11 +00:00
|
|
|
join_bin_failed:
|
|
|
|
{
|
|
|
|
GST_WARNING ("failed to join bin element");
|
|
|
|
gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_ERROR);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-11-28 12:58:05 +00:00
|
|
|
preroll_failed:
|
2013-07-09 18:44:51 +00:00
|
|
|
{
|
|
|
|
GST_WARNING ("failed to preroll pipeline");
|
|
|
|
gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_ERROR);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-09 14:44:21 +00:00
|
|
|
static gboolean
|
|
|
|
default_prepare (GstRTSPMedia * media, GstRTSPThread * thread)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
2013-12-03 19:54:42 +00:00
|
|
|
GstRTSPMediaClass *klass;
|
2014-04-09 14:44:21 +00:00
|
|
|
GstBus *bus;
|
2014-04-12 03:53:15 +00:00
|
|
|
GMainContext *context;
|
2014-04-09 14:44:21 +00:00
|
|
|
GSource *source;
|
2012-11-28 13:45:30 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
2013-12-03 19:54:42 +00:00
|
|
|
klass = GST_RTSP_MEDIA_GET_CLASS (media);
|
|
|
|
|
|
|
|
if (!klass->create_rtpbin)
|
|
|
|
goto no_create_rtpbin;
|
|
|
|
|
|
|
|
priv->rtpbin = klass->create_rtpbin (media);
|
2013-06-11 23:10:01 +00:00
|
|
|
if (priv->rtpbin != NULL) {
|
|
|
|
gboolean success = TRUE;
|
|
|
|
|
|
|
|
if (klass->setup_rtpbin)
|
|
|
|
success = klass->setup_rtpbin (media, priv->rtpbin);
|
|
|
|
|
|
|
|
if (success == FALSE) {
|
|
|
|
gst_object_unref (priv->rtpbin);
|
|
|
|
priv->rtpbin = NULL;
|
|
|
|
}
|
|
|
|
}
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->rtpbin == NULL)
|
2011-12-09 09:53:30 +00:00
|
|
|
goto no_rtpbin;
|
2010-12-06 18:29:53 +00:00
|
|
|
|
2013-07-10 15:08:14 +00:00
|
|
|
priv->thread = thread;
|
2014-04-12 03:53:15 +00:00
|
|
|
context = (thread != NULL) ? (thread->context) : NULL;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
bus = gst_pipeline_get_bus (GST_PIPELINE_CAST (priv->pipeline));
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-03-04 15:33:59 +00:00
|
|
|
/* add the pipeline bus to our custom mainloop */
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->source = gst_bus_create_watch (bus);
|
2009-03-04 15:33:59 +00:00
|
|
|
gst_object_unref (bus);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_source_set_callback (priv->source, (GSourceFunc) bus_message,
|
2012-11-30 09:05:48 +00:00
|
|
|
g_object_ref (media), (GDestroyNotify) watch_destroyed);
|
2009-03-04 15:33:59 +00:00
|
|
|
|
2014-04-12 03:53:15 +00:00
|
|
|
priv->id = g_source_attach (priv->source, context);
|
2009-03-04 15:33:59 +00:00
|
|
|
|
2009-05-24 17:34:52 +00:00
|
|
|
/* add stuff to the bin */
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_bin_add (GST_BIN (priv->pipeline), priv->rtpbin);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2013-07-09 18:44:51 +00:00
|
|
|
/* do remainder in context */
|
|
|
|
source = g_idle_source_new ();
|
|
|
|
g_source_set_callback (source, (GSourceFunc) start_prepare, media, NULL);
|
2014-04-12 03:53:15 +00:00
|
|
|
g_source_attach (source, context);
|
2013-07-09 18:44:51 +00:00
|
|
|
g_source_unref (source);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2014-04-09 14:44:21 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_create_rtpbin:
|
|
|
|
{
|
|
|
|
GST_ERROR ("no create_rtpbin function");
|
|
|
|
g_critical ("no create_rtpbin vmethod function set");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_rtpbin:
|
|
|
|
{
|
|
|
|
GST_WARNING ("no rtpbin element");
|
|
|
|
g_warning ("failed to create element 'rtpbin', check your installation");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_prepare:
|
|
|
|
* @media: a #GstRTSPMedia
|
2014-06-11 23:42:08 +00:00
|
|
|
* @thread: (transfer full) (allow-none): a #GstRTSPThread to run the
|
|
|
|
* bus handler or %NULL
|
2014-04-09 14:44:21 +00:00
|
|
|
*
|
|
|
|
* Prepare @media for streaming. This function will create the objects
|
|
|
|
* to manage the streaming. A pipeline must have been set on @media with
|
|
|
|
* gst_rtsp_media_take_pipeline().
|
|
|
|
*
|
|
|
|
* It will preroll the pipeline and collect vital information about the streams
|
|
|
|
* such as the duration.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_media_prepare (GstRTSPMedia * media, GstRTSPThread * thread)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
GstRTSPMediaClass *klass;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
|
|
|
priv->prepare_count++;
|
|
|
|
|
|
|
|
if (priv->status == GST_RTSP_MEDIA_STATUS_PREPARED ||
|
|
|
|
priv->status == GST_RTSP_MEDIA_STATUS_SUSPENDED)
|
|
|
|
goto was_prepared;
|
|
|
|
|
|
|
|
if (priv->status == GST_RTSP_MEDIA_STATUS_PREPARING)
|
|
|
|
goto is_preparing;
|
|
|
|
|
|
|
|
if (priv->status != GST_RTSP_MEDIA_STATUS_UNPREPARED)
|
|
|
|
goto not_unprepared;
|
|
|
|
|
|
|
|
if (!priv->reusable && priv->reused)
|
|
|
|
goto is_reused;
|
|
|
|
|
|
|
|
GST_INFO ("preparing media %p", media);
|
|
|
|
|
|
|
|
/* reset some variables */
|
|
|
|
priv->is_live = FALSE;
|
|
|
|
priv->seekable = FALSE;
|
|
|
|
priv->buffering = FALSE;
|
|
|
|
|
|
|
|
/* we're preparing now */
|
|
|
|
gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_PREPARING);
|
|
|
|
|
|
|
|
klass = GST_RTSP_MEDIA_GET_CLASS (media);
|
|
|
|
if (klass->prepare) {
|
|
|
|
if (!klass->prepare (media, thread))
|
|
|
|
goto prepare_failed;
|
|
|
|
}
|
|
|
|
|
2012-11-13 10:54:17 +00:00
|
|
|
wait_status:
|
2012-11-29 10:11:05 +00:00
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2012-10-26 15:28:10 +00:00
|
|
|
/* now wait for all pads to be prerolled, FIXME, we should somehow be
|
|
|
|
* able to do this async so that we don't block the server thread. */
|
2013-11-28 12:58:05 +00:00
|
|
|
if (!wait_preroll (media))
|
|
|
|
goto preroll_failed;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2010-12-13 15:58:36 +00:00
|
|
|
g_signal_emit (media, gst_rtsp_media_signals[SIGNAL_PREPARED], 0, NULL);
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("object %p is prerolled", media);
|
2009-01-30 10:06:31 +00:00
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* OK */
|
2014-04-09 14:44:21 +00:00
|
|
|
is_preparing:
|
|
|
|
{
|
|
|
|
/* we are not going to use the giving thread, so stop it. */
|
|
|
|
if (thread)
|
|
|
|
gst_rtsp_thread_stop (thread);
|
|
|
|
goto wait_status;
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
was_prepared:
|
|
|
|
{
|
2012-11-13 10:49:08 +00:00
|
|
|
GST_LOG ("media %p was prepared", media);
|
2014-02-11 22:20:39 +00:00
|
|
|
/* we are not going to use the giving thread, so stop it. */
|
2014-04-12 03:53:15 +00:00
|
|
|
if (thread)
|
|
|
|
gst_rtsp_thread_stop (thread);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2009-01-29 12:31:27 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/* ERRORS */
|
2012-11-13 10:49:08 +00:00
|
|
|
not_unprepared:
|
|
|
|
{
|
2014-04-12 03:57:00 +00:00
|
|
|
/* we are not going to use the giving thread, so stop it. */
|
|
|
|
if (thread)
|
|
|
|
gst_rtsp_thread_stop (thread);
|
2012-11-13 10:49:08 +00:00
|
|
|
GST_WARNING ("media %p was not unprepared", media);
|
2012-11-30 14:03:15 +00:00
|
|
|
priv->prepare_count--;
|
2012-11-29 10:11:05 +00:00
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2012-11-13 10:49:08 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-03-09 09:27:38 +00:00
|
|
|
is_reused:
|
|
|
|
{
|
2014-04-12 03:57:00 +00:00
|
|
|
/* we are not going to use the giving thread, so stop it. */
|
|
|
|
if (thread)
|
|
|
|
gst_rtsp_thread_stop (thread);
|
2012-11-30 14:03:15 +00:00
|
|
|
priv->prepare_count--;
|
2012-11-29 10:11:05 +00:00
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2010-03-09 09:27:38 +00:00
|
|
|
GST_WARNING ("can not reuse media %p", media);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-04-09 14:44:21 +00:00
|
|
|
prepare_failed:
|
2013-12-03 19:54:42 +00:00
|
|
|
{
|
2014-04-12 03:57:00 +00:00
|
|
|
/* we are not going to use the giving thread, so stop it. */
|
|
|
|
if (thread)
|
|
|
|
gst_rtsp_thread_stop (thread);
|
2013-12-03 19:54:42 +00:00
|
|
|
priv->prepare_count--;
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2014-04-09 14:44:21 +00:00
|
|
|
GST_ERROR ("failed to prepare media");
|
2010-12-06 18:29:53 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-11-28 12:58:05 +00:00
|
|
|
preroll_failed:
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_WARNING ("failed to preroll pipeline");
|
2010-03-09 09:27:38 +00:00
|
|
|
gst_rtsp_media_unprepare (media);
|
2009-04-03 20:22:30 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-13 10:15:35 +00:00
|
|
|
/* must be called with state-lock */
|
2012-10-25 19:29:58 +00:00
|
|
|
static void
|
|
|
|
finish_unprepare (GstRTSPMedia * media)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
gint i;
|
2013-04-22 14:40:48 +00:00
|
|
|
GList *walk;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("shutting down");
|
|
|
|
|
2014-04-08 12:49:41 +00:00
|
|
|
/* release the lock on shutdown, otherwise pad_added_cb might try to
|
|
|
|
* acquire the lock and then we deadlock */
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2014-01-21 13:46:47 +00:00
|
|
|
set_state (media, GST_STATE_NULL);
|
2014-04-08 12:49:41 +00:00
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
2013-04-22 15:34:37 +00:00
|
|
|
remove_fakesink (priv);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
for (i = 0; i < priv->streams->len; i++) {
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStream *stream;
|
|
|
|
|
|
|
|
GST_INFO ("Removing elements of stream %d from pipeline", i);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
stream = g_ptr_array_index (priv->streams, i);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_stream_leave_bin (stream, GST_BIN (priv->pipeline), priv->rtpbin);
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
|
2013-04-22 14:40:48 +00:00
|
|
|
/* remove the pad signal handlers */
|
|
|
|
for (walk = priv->dynamic; walk; walk = g_list_next (walk)) {
|
|
|
|
GstElement *elem = walk->data;
|
|
|
|
DynPaySignalHandlers *handlers;
|
|
|
|
|
2013-04-22 15:34:37 +00:00
|
|
|
handlers =
|
|
|
|
g_object_steal_data (G_OBJECT (elem), "gst-rtsp-dynpay-handlers");
|
2013-04-22 14:40:48 +00:00
|
|
|
g_assert (handlers != NULL);
|
|
|
|
|
|
|
|
g_signal_handler_disconnect (G_OBJECT (elem), handlers->pad_added_handler);
|
2013-04-22 15:34:37 +00:00
|
|
|
g_signal_handler_disconnect (G_OBJECT (elem),
|
|
|
|
handlers->pad_removed_handler);
|
2013-04-22 14:40:48 +00:00
|
|
|
g_signal_handler_disconnect (G_OBJECT (elem),
|
|
|
|
handlers->no_more_pads_handler);
|
|
|
|
|
|
|
|
g_slice_free (DynPaySignalHandlers, handlers);
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_bin_remove (GST_BIN (priv->pipeline), priv->rtpbin);
|
|
|
|
priv->rtpbin = NULL;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2013-04-09 20:35:28 +00:00
|
|
|
if (priv->nettime)
|
|
|
|
gst_object_unref (priv->nettime);
|
|
|
|
priv->nettime = NULL;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->reused = TRUE;
|
2014-04-08 10:08:17 +00:00
|
|
|
gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_UNPREPARED);
|
2012-10-26 13:21:50 +00:00
|
|
|
|
2012-11-30 12:35:05 +00:00
|
|
|
/* when the media is not reusable, this will effectively unref the media and
|
|
|
|
* recreate it */
|
|
|
|
g_signal_emit (media, gst_rtsp_media_signals[SIGNAL_UNPREPARED], 0, NULL);
|
|
|
|
|
|
|
|
/* the source has the last ref to the media */
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->source) {
|
2012-11-30 12:35:05 +00:00
|
|
|
GST_DEBUG ("destroy source");
|
2012-11-29 10:11:05 +00:00
|
|
|
g_source_destroy (priv->source);
|
|
|
|
g_source_unref (priv->source);
|
2012-11-20 08:42:51 +00:00
|
|
|
}
|
2013-07-10 15:08:14 +00:00
|
|
|
if (priv->thread) {
|
|
|
|
GST_DEBUG ("stop thread");
|
|
|
|
gst_rtsp_thread_stop (priv->thread);
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
|
2012-11-13 10:15:35 +00:00
|
|
|
/* called with state-lock */
|
2009-06-12 16:05:30 +00:00
|
|
|
static gboolean
|
2010-03-05 15:20:08 +00:00
|
|
|
default_unprepare (GstRTSPMedia * media)
|
2009-06-18 14:05:18 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
|
|
|
|
2014-09-30 20:22:45 +00:00
|
|
|
gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_UNPREPARING);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->eos_shutdown) {
|
2010-08-20 16:17:08 +00:00
|
|
|
GST_DEBUG ("sending EOS for shutdown");
|
|
|
|
/* ref so that we don't disappear */
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_element_send_event (priv->pipeline, gst_event_new_eos ());
|
2010-08-20 16:17:08 +00:00
|
|
|
/* we need to go to playing again for the EOS to propagate, normally in this
|
|
|
|
* state, nothing is receiving data from us anymore so this is ok. */
|
2014-01-21 13:46:47 +00:00
|
|
|
set_state (media, GST_STATE_PLAYING);
|
2010-08-20 16:17:08 +00:00
|
|
|
} else {
|
2012-10-25 19:29:58 +00:00
|
|
|
finish_unprepare (media);
|
2010-08-20 16:17:08 +00:00
|
|
|
}
|
2009-04-03 20:22:30 +00:00
|
|
|
return TRUE;
|
2009-01-29 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2012-10-26 13:23:16 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_unprepare:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Unprepare @media. After this call, the media should be prepared again before
|
|
|
|
* it can be used again. If the media is set to be non-reusable, a new instance
|
|
|
|
* must be created.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_media_unprepare (GstRTSPMedia * media)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
2012-10-26 13:23:16 +00:00
|
|
|
gboolean success;
|
|
|
|
|
2012-11-28 13:45:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
|
|
|
if (priv->status == GST_RTSP_MEDIA_STATUS_UNPREPARED)
|
2012-11-13 10:15:35 +00:00
|
|
|
goto was_unprepared;
|
2012-10-26 13:23:16 +00:00
|
|
|
|
2012-11-30 14:03:15 +00:00
|
|
|
priv->prepare_count--;
|
|
|
|
if (priv->prepare_count > 0)
|
|
|
|
goto is_busy;
|
|
|
|
|
2012-10-26 13:23:16 +00:00
|
|
|
GST_INFO ("unprepare media %p", media);
|
2014-04-01 11:16:26 +00:00
|
|
|
if (priv->blocked)
|
|
|
|
media_streams_set_blocked (media, FALSE);
|
2014-01-21 13:46:47 +00:00
|
|
|
set_target_state (media, GST_STATE_NULL, FALSE);
|
2012-10-26 13:23:16 +00:00
|
|
|
success = TRUE;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->status == GST_RTSP_MEDIA_STATUS_PREPARED) {
|
2012-10-26 13:23:16 +00:00
|
|
|
GstRTSPMediaClass *klass;
|
|
|
|
|
|
|
|
klass = GST_RTSP_MEDIA_GET_CLASS (media);
|
|
|
|
if (klass->unprepare)
|
|
|
|
success = klass->unprepare (media);
|
|
|
|
} else {
|
|
|
|
finish_unprepare (media);
|
|
|
|
}
|
2012-11-29 10:11:05 +00:00
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2012-10-26 13:23:16 +00:00
|
|
|
|
|
|
|
return success;
|
2012-11-13 10:15:35 +00:00
|
|
|
|
|
|
|
was_unprepared:
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2012-11-13 10:15:35 +00:00
|
|
|
GST_INFO ("media %p was already unprepared", media);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2012-11-30 14:03:15 +00:00
|
|
|
is_busy:
|
|
|
|
{
|
|
|
|
GST_INFO ("media %p still prepared %d times", media, priv->prepare_count);
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2012-10-26 13:23:16 +00:00
|
|
|
}
|
|
|
|
|
2013-04-09 20:35:28 +00:00
|
|
|
/* should be called with state-lock */
|
|
|
|
static GstClock *
|
|
|
|
get_clock_unlocked (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
if (media->priv->status != GST_RTSP_MEDIA_STATUS_PREPARED) {
|
|
|
|
GST_DEBUG_OBJECT (media, "media was not prepared");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return gst_pipeline_get_clock (GST_PIPELINE_CAST (media->priv->pipeline));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_get_clock:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Get the clock that is used by the pipeline in @media.
|
|
|
|
*
|
|
|
|
* @media must be prepared before this method returns a valid clock object.
|
|
|
|
*
|
2013-10-12 21:56:00 +00:00
|
|
|
* Returns: (transfer full): the #GstClock used by @media. unref after usage.
|
2013-04-09 20:35:28 +00:00
|
|
|
*/
|
|
|
|
GstClock *
|
|
|
|
gst_rtsp_media_get_clock (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
GstClock *clock;
|
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
|
|
|
clock = get_clock_unlocked (media);
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
|
|
|
|
return clock;
|
2013-04-12 10:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_get_base_time:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Get the base_time that is used by the pipeline in @media.
|
|
|
|
*
|
|
|
|
* @media must be prepared before this method returns a valid base_time.
|
|
|
|
*
|
|
|
|
* Returns: the base_time used by @media.
|
|
|
|
*/
|
|
|
|
GstClockTime
|
|
|
|
gst_rtsp_media_get_base_time (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
GstClockTime result;
|
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), GST_CLOCK_TIME_NONE);
|
|
|
|
|
|
|
|
priv = media->priv;
|
2013-04-09 20:35:28 +00:00
|
|
|
|
2013-04-12 10:34:38 +00:00
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
|
|
|
if (media->priv->status != GST_RTSP_MEDIA_STATUS_PREPARED)
|
|
|
|
goto not_prepared;
|
|
|
|
|
|
|
|
result = gst_element_get_base_time (media->priv->pipeline);
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
not_prepared:
|
|
|
|
{
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
GST_DEBUG_OBJECT (media, "media was not prepared");
|
|
|
|
return GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
2013-04-09 20:35:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_get_time_provider:
|
|
|
|
* @media: a #GstRTSPMedia
|
2014-06-11 23:42:08 +00:00
|
|
|
* @address: (allow-none): an address or %NULL
|
2013-04-09 20:35:28 +00:00
|
|
|
* @port: a port or 0
|
|
|
|
*
|
|
|
|
* Get the #GstNetTimeProvider for the clock used by @media. The time provider
|
|
|
|
* will listen on @address and @port for client time requests.
|
|
|
|
*
|
2013-10-12 21:56:00 +00:00
|
|
|
* Returns: (transfer full): the #GstNetTimeProvider of @media.
|
2013-04-09 20:35:28 +00:00
|
|
|
*/
|
|
|
|
GstNetTimeProvider *
|
|
|
|
gst_rtsp_media_get_time_provider (GstRTSPMedia * media, const gchar * address,
|
|
|
|
guint16 port)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
GstNetTimeProvider *provider = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
|
|
|
if (priv->time_provider) {
|
|
|
|
if ((provider = priv->nettime) == NULL) {
|
|
|
|
GstClock *clock;
|
|
|
|
|
|
|
|
if (priv->time_provider && (clock = get_clock_unlocked (media))) {
|
|
|
|
provider = gst_net_time_provider_new (clock, address, port);
|
|
|
|
gst_object_unref (clock);
|
|
|
|
|
|
|
|
priv->nettime = provider;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
|
|
|
|
if (provider)
|
|
|
|
gst_object_ref (provider);
|
|
|
|
|
|
|
|
return provider;
|
|
|
|
}
|
|
|
|
|
2013-12-18 15:37:27 +00:00
|
|
|
static gboolean
|
|
|
|
default_setup_sdp (GstRTSPMedia * media, GstSDPMessage * sdp, GstSDPInfo * info)
|
|
|
|
{
|
|
|
|
return gst_rtsp_sdp_from_media (sdp, info, media);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_setup_sdp:
|
|
|
|
* @media: a #GstRTSPMedia
|
2014-03-23 20:24:48 +00:00
|
|
|
* @sdp: (transfer none): a #GstSDPMessage
|
|
|
|
* @info: (transfer none): a #GstSDPInfo
|
2013-12-18 15:37:27 +00:00
|
|
|
*
|
|
|
|
* Add @media specific info to @sdp. @info is used to configure the connection
|
|
|
|
* information in the SDP.
|
|
|
|
*
|
|
|
|
* Returns: TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_media_setup_sdp (GstRTSPMedia * media, GstSDPMessage * sdp,
|
|
|
|
GstSDPInfo * info)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv;
|
|
|
|
GstRTSPMediaClass *klass;
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
g_return_val_if_fail (sdp != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
|
|
|
|
|
|
|
klass = GST_RTSP_MEDIA_GET_CLASS (media);
|
|
|
|
|
|
|
|
if (!klass->setup_sdp)
|
|
|
|
goto no_setup_sdp;
|
|
|
|
|
|
|
|
res = klass->setup_sdp (media, sdp, info);
|
|
|
|
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_setup_sdp:
|
|
|
|
{
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
GST_ERROR ("no setup_sdp function");
|
|
|
|
g_critical ("no setup_sdp vmethod function set");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-08 07:26:23 +00:00
|
|
|
static void
|
|
|
|
do_set_seqnum (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
guint16 seq_num;
|
|
|
|
seq_num = gst_rtsp_stream_get_current_seqnum (stream);
|
|
|
|
gst_rtsp_stream_set_seqnum_offset (stream, seq_num + 1);
|
|
|
|
}
|
|
|
|
|
2014-05-14 07:31:31 +00:00
|
|
|
/* call with state_lock */
|
|
|
|
gboolean
|
|
|
|
default_suspend (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
|
|
|
switch (priv->suspend_mode) {
|
|
|
|
case GST_RTSP_SUSPEND_MODE_NONE:
|
|
|
|
GST_DEBUG ("media %p no suspend", media);
|
|
|
|
break;
|
|
|
|
case GST_RTSP_SUSPEND_MODE_PAUSE:
|
|
|
|
GST_DEBUG ("media %p suspend to PAUSED", media);
|
|
|
|
ret = set_target_state (media, GST_STATE_PAUSED, TRUE);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
goto state_failed;
|
|
|
|
break;
|
|
|
|
case GST_RTSP_SUSPEND_MODE_RESET:
|
|
|
|
GST_DEBUG ("media %p suspend to NULL", media);
|
|
|
|
ret = set_target_state (media, GST_STATE_NULL, TRUE);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
goto state_failed;
|
2014-09-08 07:26:23 +00:00
|
|
|
/* Because payloader needs to set the sequence number as
|
|
|
|
* monotonic, we need to preserve the sequence number
|
|
|
|
* after pause. (otherwise going from pause to play, which
|
|
|
|
* is actually from NULL to PLAY will create a new sequence
|
|
|
|
* number. */
|
|
|
|
g_ptr_array_foreach (priv->streams, (GFunc) do_set_seqnum, NULL);
|
2014-05-14 07:31:31 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* let the streams do the state changes freely, if any */
|
|
|
|
media_streams_set_blocked (media, FALSE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
state_failed:
|
|
|
|
{
|
|
|
|
GST_WARNING ("failed changing pipeline's state for media %p", media);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-28 13:10:19 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_suspend:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Suspend @media. The state of the pipeline managed by @media is set to
|
|
|
|
* GST_STATE_NULL but all streams are kept. @media can be prepared again
|
2014-04-02 10:27:24 +00:00
|
|
|
* with gst_rtsp_media_unsuspend()
|
2013-11-28 13:10:19 +00:00
|
|
|
*
|
|
|
|
* @media must be prepared with gst_rtsp_media_prepare();
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_media_suspend (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
2014-05-14 07:31:31 +00:00
|
|
|
GstRTSPMediaClass *klass;
|
2013-11-28 13:10:19 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
|
|
|
|
GST_FIXME ("suspend for dynamic pipelines needs fixing");
|
|
|
|
|
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
|
|
|
if (priv->status != GST_RTSP_MEDIA_STATUS_PREPARED)
|
|
|
|
goto not_prepared;
|
|
|
|
|
|
|
|
/* don't attempt to suspend when something is busy */
|
|
|
|
if (priv->n_active > 0)
|
|
|
|
goto done;
|
|
|
|
|
2014-05-14 07:31:31 +00:00
|
|
|
klass = GST_RTSP_MEDIA_GET_CLASS (media);
|
|
|
|
if (klass->suspend) {
|
|
|
|
if (!klass->suspend (media))
|
|
|
|
goto suspend_failed;
|
2013-11-28 13:10:19 +00:00
|
|
|
}
|
2014-05-14 07:31:31 +00:00
|
|
|
|
2014-04-08 10:08:17 +00:00
|
|
|
gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_SUSPENDED);
|
2013-11-28 13:10:19 +00:00
|
|
|
done:
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
not_prepared:
|
|
|
|
{
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
GST_WARNING ("media %p was not prepared", media);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-05-14 07:31:31 +00:00
|
|
|
suspend_failed:
|
2013-11-28 13:10:19 +00:00
|
|
|
{
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_ERROR);
|
2014-05-14 07:31:31 +00:00
|
|
|
GST_WARNING ("failed to suspend media %p", media);
|
2013-11-28 13:10:19 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 07:31:31 +00:00
|
|
|
/* call with state_lock */
|
2013-11-28 13:10:19 +00:00
|
|
|
gboolean
|
2014-05-14 07:31:31 +00:00
|
|
|
default_unsuspend (GstRTSPMedia * media)
|
2013-11-28 13:10:19 +00:00
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
|
|
|
|
|
|
|
switch (priv->suspend_mode) {
|
|
|
|
case GST_RTSP_SUSPEND_MODE_NONE:
|
2014-04-08 10:08:17 +00:00
|
|
|
gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_PREPARED);
|
2013-11-28 13:10:19 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_SUSPEND_MODE_PAUSE:
|
2014-04-08 10:08:17 +00:00
|
|
|
gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_PREPARED);
|
2013-11-28 13:10:19 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_SUSPEND_MODE_RESET:
|
|
|
|
{
|
2014-04-08 10:08:17 +00:00
|
|
|
gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_PREPARING);
|
2013-11-28 13:10:19 +00:00
|
|
|
if (!start_preroll (media))
|
|
|
|
goto start_failed;
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
|
|
|
|
if (!wait_preroll (media))
|
|
|
|
goto preroll_failed;
|
|
|
|
|
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
start_failed:
|
|
|
|
{
|
|
|
|
GST_WARNING ("failed to preroll pipeline");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
preroll_failed:
|
|
|
|
{
|
|
|
|
GST_WARNING ("failed to preroll pipeline");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 07:31:31 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_unsuspend:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Unsuspend @media if it was in a suspended state. This method does nothing
|
|
|
|
* when the media was not in the suspended state.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_media_unsuspend (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
|
|
|
GstRTSPMediaClass *klass;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
|
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
|
|
|
if (priv->status != GST_RTSP_MEDIA_STATUS_SUSPENDED)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
klass = GST_RTSP_MEDIA_GET_CLASS (media);
|
|
|
|
if (klass->unsuspend) {
|
|
|
|
if (!klass->unsuspend (media))
|
|
|
|
goto unsuspend_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
unsuspend_failed:
|
|
|
|
{
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
GST_WARNING ("failed to unsuspend media %p", media);
|
|
|
|
gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_ERROR);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-28 13:10:19 +00:00
|
|
|
/* must be called with state-lock */
|
2013-11-26 15:25:37 +00:00
|
|
|
static void
|
|
|
|
media_set_pipeline_state_locked (GstRTSPMedia * media, GstState state)
|
2013-07-02 22:55:28 +00:00
|
|
|
{
|
|
|
|
GstRTSPMediaPrivate *priv = media->priv;
|
|
|
|
|
|
|
|
if (state == GST_STATE_NULL) {
|
|
|
|
gst_rtsp_media_unprepare (media);
|
|
|
|
} else {
|
|
|
|
GST_INFO ("state %s media %p", gst_element_state_get_name (state), media);
|
2014-01-21 13:46:47 +00:00
|
|
|
set_target_state (media, state, FALSE);
|
2013-07-02 22:55:28 +00:00
|
|
|
/* when we are buffering, don't update the state yet, this will be done
|
|
|
|
* when buffering finishes */
|
|
|
|
if (priv->buffering) {
|
|
|
|
GST_INFO ("Buffering busy, delay state change");
|
|
|
|
} else {
|
2013-11-28 13:06:53 +00:00
|
|
|
if (state == GST_STATE_PLAYING)
|
|
|
|
/* make sure pads are not blocking anymore when going to PLAYING */
|
|
|
|
media_streams_set_blocked (media, FALSE);
|
|
|
|
|
2014-01-21 13:46:47 +00:00
|
|
|
set_state (media, state);
|
2013-11-28 13:10:19 +00:00
|
|
|
|
|
|
|
/* and suspend after pause */
|
|
|
|
if (state == GST_STATE_PAUSED)
|
|
|
|
gst_rtsp_media_suspend (media);
|
2013-07-02 22:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-26 15:25:37 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_set_pipeline_state:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @state: the target state of the pipeline
|
|
|
|
*
|
|
|
|
* Set the state of the pipeline managed by @media to @state
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_media_set_pipeline_state (GstRTSPMedia * media, GstState state)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
|
|
|
g_rec_mutex_lock (&media->priv->state_lock);
|
|
|
|
media_set_pipeline_state_locked (media, state);
|
|
|
|
g_rec_mutex_unlock (&media->priv->state_lock);
|
|
|
|
}
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/**
|
2009-03-11 15:45:12 +00:00
|
|
|
* gst_rtsp_media_set_state:
|
2009-01-29 12:31:27 +00:00
|
|
|
* @media: a #GstRTSPMedia
|
2009-03-11 15:45:12 +00:00
|
|
|
* @state: the target state of the media
|
2014-03-23 20:24:48 +00:00
|
|
|
* @transports: (transfer none) (element-type GstRtspServer.RTSPStreamTransport):
|
|
|
|
* a #GPtrArray of #GstRTSPStreamTransport pointers
|
2009-01-29 12:31:27 +00:00
|
|
|
*
|
2009-03-11 15:45:12 +00:00
|
|
|
* Set the state of @media to @state and for the transports in @transports.
|
2009-01-29 12:31:27 +00:00
|
|
|
*
|
2012-11-28 13:45:30 +00:00
|
|
|
* @media must be prepared with gst_rtsp_media_prepare();
|
|
|
|
*
|
2009-02-03 18:32:38 +00:00
|
|
|
* Returns: %TRUE on success.
|
2009-01-29 12:31:27 +00:00
|
|
|
*/
|
2009-02-03 18:32:38 +00:00
|
|
|
gboolean
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_set_state (GstRTSPMedia * media, GstState state,
|
2012-10-25 19:29:58 +00:00
|
|
|
GPtrArray * transports)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaPrivate *priv;
|
2009-02-03 18:32:38 +00:00
|
|
|
gint i;
|
2012-11-29 10:11:05 +00:00
|
|
|
gboolean activate, deactivate, do_state;
|
2009-04-03 20:22:30 +00:00
|
|
|
gint old_active;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-02-03 18:32:38 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
g_return_val_if_fail (transports != NULL, FALSE);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_rec_mutex_lock (&priv->state_lock);
|
2013-11-20 23:51:54 +00:00
|
|
|
if (priv->status == GST_RTSP_MEDIA_STATUS_ERROR)
|
|
|
|
goto error_status;
|
2013-11-29 14:50:23 +00:00
|
|
|
if (priv->status != GST_RTSP_MEDIA_STATUS_PREPARED &&
|
|
|
|
priv->status != GST_RTSP_MEDIA_STATUS_SUSPENDED)
|
2012-11-28 13:45:30 +00:00
|
|
|
goto not_prepared;
|
2012-11-13 10:15:35 +00:00
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
/* NULL and READY are the same */
|
|
|
|
if (state == GST_STATE_READY)
|
|
|
|
state = GST_STATE_NULL;
|
2009-02-13 18:54:18 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
activate = deactivate = FALSE;
|
2009-02-03 18:32:38 +00:00
|
|
|
|
2014-10-01 11:12:30 +00:00
|
|
|
GST_INFO ("going to state %s media %p, target state %s",
|
|
|
|
gst_element_state_get_name (state), media,
|
|
|
|
gst_element_state_get_name (priv->target_state));
|
2009-05-26 09:42:41 +00:00
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
switch (state) {
|
|
|
|
case GST_STATE_NULL:
|
2014-10-01 11:12:30 +00:00
|
|
|
/* we're going from PLAYING or PAUSED to READY or NULL, deactivate */
|
|
|
|
if (priv->target_state >= GST_STATE_PAUSED)
|
|
|
|
deactivate = TRUE;
|
|
|
|
break;
|
2009-03-11 15:45:12 +00:00
|
|
|
case GST_STATE_PAUSED:
|
2012-11-29 10:11:05 +00:00
|
|
|
/* we're going from PLAYING to PAUSED, READY or NULL, deactivate */
|
|
|
|
if (priv->target_state == GST_STATE_PLAYING)
|
|
|
|
deactivate = TRUE;
|
2009-03-11 15:45:12 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING:
|
2012-11-29 10:11:05 +00:00
|
|
|
/* we're going to PLAYING, activate */
|
|
|
|
activate = TRUE;
|
2009-03-11 15:45:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2009-02-03 18:32:38 +00:00
|
|
|
}
|
2012-11-29 10:11:05 +00:00
|
|
|
old_active = priv->n_active;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2014-10-01 11:12:30 +00:00
|
|
|
GST_DEBUG ("%d transports, activate %d, deactivate %d", transports->len,
|
|
|
|
activate, deactivate);
|
2009-02-03 18:32:38 +00:00
|
|
|
for (i = 0; i < transports->len; i++) {
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStreamTransport *trans;
|
2009-02-03 18:32:38 +00:00
|
|
|
|
|
|
|
/* we need a non-NULL entry in the array */
|
2012-10-25 19:29:58 +00:00
|
|
|
trans = g_ptr_array_index (transports, i);
|
|
|
|
if (trans == NULL)
|
2009-02-03 18:32:38 +00:00
|
|
|
continue;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (activate) {
|
|
|
|
if (gst_rtsp_stream_transport_set_active (trans, TRUE))
|
|
|
|
priv->n_active++;
|
|
|
|
} else if (deactivate) {
|
|
|
|
if (gst_rtsp_stream_transport_set_active (trans, FALSE))
|
|
|
|
priv->n_active--;
|
2009-03-06 18:34:14 +00:00
|
|
|
}
|
2009-02-03 18:32:38 +00:00
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/* we just activated the first media, do the playing state change */
|
|
|
|
if (old_active == 0 && activate)
|
2009-04-03 17:44:37 +00:00
|
|
|
do_state = TRUE;
|
|
|
|
/* if we have no more active media, do the downward state changes */
|
2012-11-29 10:11:05 +00:00
|
|
|
else if (priv->n_active == 0)
|
2009-04-03 17:44:37 +00:00
|
|
|
do_state = TRUE;
|
|
|
|
else
|
|
|
|
do_state = FALSE;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
GST_INFO ("state %d active %d media %p do_state %d", state, priv->n_active,
|
2010-12-28 17:34:10 +00:00
|
|
|
media, do_state);
|
2009-04-03 17:44:37 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->target_state != state) {
|
2013-07-02 22:55:28 +00:00
|
|
|
if (do_state)
|
2013-11-26 15:25:37 +00:00
|
|
|
media_set_pipeline_state_locked (media, state);
|
2013-07-02 22:55:28 +00:00
|
|
|
|
2010-12-28 17:34:10 +00:00
|
|
|
g_signal_emit (media, gst_rtsp_media_signals[SIGNAL_NEW_STATE], 0, state,
|
|
|
|
NULL);
|
2009-04-03 17:44:37 +00:00
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-03-13 14:57:42 +00:00
|
|
|
/* remember where we are */
|
2012-06-13 09:43:17 +00:00
|
|
|
if (state != GST_STATE_NULL && (state == GST_STATE_PAUSED ||
|
2012-11-29 10:11:05 +00:00
|
|
|
old_active != priv->n_active))
|
2009-03-13 14:57:42 +00:00
|
|
|
collect_media_stats (media);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2012-11-13 10:15:35 +00:00
|
|
|
|
2009-02-03 18:32:38 +00:00
|
|
|
return TRUE;
|
2012-11-28 13:45:30 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
not_prepared:
|
|
|
|
{
|
|
|
|
GST_WARNING ("media %p was not prepared", media);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
2012-11-28 13:45:30 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-11-20 23:51:54 +00:00
|
|
|
error_status:
|
|
|
|
{
|
|
|
|
GST_WARNING ("media %p in error status while changing to state %d",
|
|
|
|
media, state);
|
|
|
|
if (state == GST_STATE_NULL) {
|
|
|
|
for (i = 0; i < transports->len; i++) {
|
|
|
|
GstRTSPStreamTransport *trans;
|
|
|
|
|
|
|
|
/* we need a non-NULL entry in the array */
|
|
|
|
trans = g_ptr_array_index (transports, i);
|
|
|
|
if (trans == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gst_rtsp_stream_transport_set_active (trans, FALSE);
|
|
|
|
}
|
|
|
|
priv->n_active = 0;
|
|
|
|
}
|
|
|
|
g_rec_mutex_unlock (&priv->state_lock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
}
|