2010-12-11 17:01:53 +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.
|
2010-12-11 17:01:53 +00:00
|
|
|
*/
|
2013-07-11 14:57:14 +00:00
|
|
|
/**
|
|
|
|
* SECTION:rtsp-media-factory-uri
|
|
|
|
* @short_description: A factory for URI sources
|
|
|
|
* @see_also: #GstRTSPMediaFactory, #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* This specialized #GstRTSPMediaFactory constructs media pipelines from a URI,
|
|
|
|
* given with gst_rtsp_media_factory_uri_set_uri().
|
|
|
|
*
|
|
|
|
* It will automatically demux and payload the different streams found in the
|
|
|
|
* media at URL.
|
|
|
|
*
|
|
|
|
* Last reviewed on 2013-07-11 (1.0.0)
|
|
|
|
*/
|
2018-09-24 08:36:21 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2010-12-11 17:01:53 +00:00
|
|
|
|
2010-12-21 16:37:26 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-12-11 17:01:53 +00:00
|
|
|
#include "rtsp-media-factory-uri.h"
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
struct _GstRTSPMediaFactoryURIPrivate
|
|
|
|
{
|
|
|
|
GMutex lock;
|
2013-02-18 19:59:58 +00:00
|
|
|
gchar *uri; /* protected by lock */
|
2012-11-29 10:11:05 +00:00
|
|
|
gboolean use_gstpay;
|
|
|
|
|
|
|
|
GstCaps *raw_vcaps;
|
|
|
|
GstCaps *raw_acaps;
|
|
|
|
GList *demuxers;
|
|
|
|
GList *payloaders;
|
|
|
|
GList *decoders;
|
|
|
|
};
|
|
|
|
|
2010-12-23 17:53:01 +00:00
|
|
|
#define DEFAULT_URI NULL
|
|
|
|
#define DEFAULT_USE_GSTPAY FALSE
|
2010-12-11 17:01:53 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_URI,
|
2010-12-23 17:53:01 +00:00
|
|
|
PROP_USE_GSTPAY,
|
2010-12-11 17:01:53 +00:00
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
2010-12-12 03:06:41 +00:00
|
|
|
|
|
|
|
#define RAW_VIDEO_CAPS \
|
2012-03-13 15:02:47 +00:00
|
|
|
"video/x-raw"
|
2010-12-12 03:06:41 +00:00
|
|
|
|
|
|
|
#define RAW_AUDIO_CAPS \
|
2012-03-13 15:02:47 +00:00
|
|
|
"audio/x-raw"
|
2010-12-12 03:06:41 +00:00
|
|
|
|
|
|
|
static GstStaticCaps raw_video_caps = GST_STATIC_CAPS (RAW_VIDEO_CAPS);
|
|
|
|
static GstStaticCaps raw_audio_caps = GST_STATIC_CAPS (RAW_AUDIO_CAPS);
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstRTSPMediaFactoryURI *factory;
|
|
|
|
guint pt;
|
|
|
|
} FactoryData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_data (FactoryData * data)
|
|
|
|
{
|
|
|
|
g_object_unref (data->factory);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
2010-12-11 17:01:53 +00:00
|
|
|
static const gchar *factory_key = "GstRTSPMediaFactoryURI";
|
|
|
|
|
2011-01-12 17:14:48 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (rtsp_media_factory_uri_debug);
|
2010-12-11 17:01:53 +00:00
|
|
|
#define GST_CAT_DEFAULT rtsp_media_factory_uri_debug
|
|
|
|
|
|
|
|
static void gst_rtsp_media_factory_uri_get_property (GObject * object,
|
|
|
|
guint propid, GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_rtsp_media_factory_uri_set_property (GObject * object,
|
|
|
|
guint propid, const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_rtsp_media_factory_uri_finalize (GObject * obj);
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
static GstElement *rtsp_media_factory_uri_create_element (GstRTSPMediaFactory *
|
2010-12-11 17:01:53 +00:00
|
|
|
factory, const GstRTSPUrl * url);
|
|
|
|
|
2018-06-24 10:44:26 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GstRTSPMediaFactoryURI, gst_rtsp_media_factory_uri,
|
2010-12-11 17:01:53 +00:00
|
|
|
GST_TYPE_RTSP_MEDIA_FACTORY);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_media_factory_uri_class_init (GstRTSPMediaFactoryURIClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstRTSPMediaFactoryClass *mediafactory_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
mediafactory_class = GST_RTSP_MEDIA_FACTORY_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->get_property = gst_rtsp_media_factory_uri_get_property;
|
|
|
|
gobject_class->set_property = gst_rtsp_media_factory_uri_set_property;
|
|
|
|
gobject_class->finalize = gst_rtsp_media_factory_uri_finalize;
|
|
|
|
|
|
|
|
/**
|
2012-10-01 17:46:15 +00:00
|
|
|
* GstRTSPMediaFactoryURI::uri:
|
2010-12-11 17:01:53 +00:00
|
|
|
*
|
|
|
|
* The uri of the resource that will be served by this factory.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_URI,
|
|
|
|
g_param_spec_string ("uri", "URI",
|
|
|
|
"The URI of the resource to stream", DEFAULT_URI,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-12-23 17:53:01 +00:00
|
|
|
/**
|
2012-10-01 17:46:15 +00:00
|
|
|
* GstRTSPMediaFactoryURI::use-gstpay:
|
2010-12-23 17:53:01 +00:00
|
|
|
*
|
|
|
|
* Allow the usage of gstpay in order to avoid decoding of compressed formats
|
|
|
|
* without a payloader.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_USE_GSTPAY,
|
2011-01-07 10:24:39 +00:00
|
|
|
g_param_spec_boolean ("use-gstpay", "Use gstpay",
|
2010-12-23 17:53:01 +00:00
|
|
|
"Use the gstpay payloader to avoid decoding", DEFAULT_USE_GSTPAY,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-12-11 17:01:53 +00:00
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
mediafactory_class->create_element = rtsp_media_factory_uri_create_element;
|
2010-12-11 17:01:53 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (rtsp_media_factory_uri_debug, "rtspmediafactoryuri",
|
|
|
|
0, "GstRTSPMediaFactoryUri");
|
|
|
|
}
|
|
|
|
|
2010-12-23 14:58:14 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GList *demux;
|
|
|
|
GList *payload;
|
|
|
|
GList *decode;
|
|
|
|
} FilterData;
|
|
|
|
|
2010-12-21 16:37:26 +00:00
|
|
|
static gboolean
|
2010-12-23 14:58:14 +00:00
|
|
|
payloader_filter (GstPluginFeature * feature, FilterData * data)
|
2010-12-21 16:37:26 +00:00
|
|
|
{
|
|
|
|
const gchar *klass;
|
2010-12-23 14:58:14 +00:00
|
|
|
GstElementFactory *fact;
|
|
|
|
GList **list = NULL;
|
2010-12-21 16:37:26 +00:00
|
|
|
|
|
|
|
/* we only care about element factories */
|
|
|
|
if (G_UNLIKELY (!GST_IS_ELEMENT_FACTORY (feature)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (gst_plugin_feature_get_rank (feature) < GST_RANK_MARGINAL)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-12-23 14:58:14 +00:00
|
|
|
fact = GST_ELEMENT_FACTORY_CAST (feature);
|
2010-12-21 16:37:26 +00:00
|
|
|
|
2012-11-17 00:11:27 +00:00
|
|
|
klass = gst_element_factory_get_metadata (fact, GST_ELEMENT_METADATA_KLASS);
|
2010-12-21 16:37:26 +00:00
|
|
|
|
2010-12-23 14:58:14 +00:00
|
|
|
if (strstr (klass, "Decoder"))
|
|
|
|
list = &data->decode;
|
|
|
|
else if (strstr (klass, "Demux"))
|
|
|
|
list = &data->demux;
|
|
|
|
else if (strstr (klass, "Parser") && strstr (klass, "Codec"))
|
|
|
|
list = &data->demux;
|
|
|
|
else if (strstr (klass, "Payloader") && strstr (klass, "RTP"))
|
|
|
|
list = &data->payload;
|
|
|
|
|
|
|
|
if (list) {
|
2011-06-07 08:59:16 +00:00
|
|
|
GST_DEBUG ("adding %s", GST_OBJECT_NAME (fact));
|
2012-11-20 11:10:16 +00:00
|
|
|
*list = g_list_prepend (*list, gst_object_ref (fact));
|
2010-12-23 14:58:14 +00:00
|
|
|
}
|
2010-12-21 16:37:26 +00:00
|
|
|
|
2010-12-23 14:58:14 +00:00
|
|
|
return FALSE;
|
2010-12-21 16:37:26 +00:00
|
|
|
}
|
|
|
|
|
2010-12-11 17:01:53 +00:00
|
|
|
static void
|
|
|
|
gst_rtsp_media_factory_uri_init (GstRTSPMediaFactoryURI * factory)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaFactoryURIPrivate *priv =
|
2018-06-24 10:44:26 +00:00
|
|
|
gst_rtsp_media_factory_uri_get_instance_private (factory);
|
2010-12-23 14:58:14 +00:00
|
|
|
FilterData data = { NULL, NULL, NULL };
|
|
|
|
|
2012-11-20 11:29:26 +00:00
|
|
|
GST_DEBUG_OBJECT (factory, "new");
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
factory->priv = priv;
|
|
|
|
|
|
|
|
priv->uri = g_strdup (DEFAULT_URI);
|
|
|
|
priv->use_gstpay = DEFAULT_USE_GSTPAY;
|
|
|
|
g_mutex_init (&priv->lock);
|
2010-12-23 17:53:01 +00:00
|
|
|
|
2010-12-21 16:37:26 +00:00
|
|
|
/* get the feature list using the filter */
|
2012-03-07 14:03:55 +00:00
|
|
|
gst_registry_feature_filter (gst_registry_get (), (GstPluginFeatureFilter)
|
2010-12-23 14:58:14 +00:00
|
|
|
payloader_filter, FALSE, &data);
|
|
|
|
/* sort */
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->demuxers =
|
2010-12-23 14:58:14 +00:00
|
|
|
g_list_sort (data.demux, gst_plugin_feature_rank_compare_func);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->payloaders =
|
2010-12-23 14:58:14 +00:00
|
|
|
g_list_sort (data.payload, gst_plugin_feature_rank_compare_func);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->decoders =
|
2010-12-23 14:58:14 +00:00
|
|
|
g_list_sort (data.decode, gst_plugin_feature_rank_compare_func);
|
2010-12-21 16:37:26 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->raw_vcaps = gst_static_caps_get (&raw_video_caps);
|
|
|
|
priv->raw_acaps = gst_static_caps_get (&raw_audio_caps);
|
2010-12-11 17:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_media_factory_uri_finalize (GObject * obj)
|
|
|
|
{
|
|
|
|
GstRTSPMediaFactoryURI *factory = GST_RTSP_MEDIA_FACTORY_URI (obj);
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaFactoryURIPrivate *priv = factory->priv;
|
2010-12-11 17:01:53 +00:00
|
|
|
|
2012-11-20 11:29:26 +00:00
|
|
|
GST_DEBUG_OBJECT (factory, "finalize");
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_free (priv->uri);
|
|
|
|
gst_plugin_feature_list_free (priv->demuxers);
|
|
|
|
gst_plugin_feature_list_free (priv->payloaders);
|
|
|
|
gst_plugin_feature_list_free (priv->decoders);
|
|
|
|
gst_caps_unref (priv->raw_vcaps);
|
|
|
|
gst_caps_unref (priv->raw_acaps);
|
|
|
|
g_mutex_clear (&priv->lock);
|
2010-12-11 17:01:53 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gst_rtsp_media_factory_uri_parent_class)->finalize (obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_media_factory_uri_get_property (GObject * object, guint propid,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstRTSPMediaFactoryURI *factory = GST_RTSP_MEDIA_FACTORY_URI (object);
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaFactoryURIPrivate *priv = factory->priv;
|
2010-12-11 17:01:53 +00:00
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_URI:
|
|
|
|
g_value_take_string (value, gst_rtsp_media_factory_uri_get_uri (factory));
|
|
|
|
break;
|
2010-12-23 17:53:01 +00:00
|
|
|
case PROP_USE_GSTPAY:
|
2012-11-29 10:11:05 +00:00
|
|
|
g_value_set_boolean (value, priv->use_gstpay);
|
2010-12-23 17:53:01 +00:00
|
|
|
break;
|
2010-12-11 17:01:53 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_media_factory_uri_set_property (GObject * object, guint propid,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstRTSPMediaFactoryURI *factory = GST_RTSP_MEDIA_FACTORY_URI (object);
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaFactoryURIPrivate *priv = factory->priv;
|
2010-12-11 17:01:53 +00:00
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_URI:
|
|
|
|
gst_rtsp_media_factory_uri_set_uri (factory, g_value_get_string (value));
|
|
|
|
break;
|
2010-12-23 17:53:01 +00:00
|
|
|
case PROP_USE_GSTPAY:
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->use_gstpay = g_value_get_boolean (value);
|
2010-12-23 17:53:01 +00:00
|
|
|
break;
|
2010-12-11 17:01:53 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_factory_uri_new:
|
|
|
|
*
|
|
|
|
* Create a new #GstRTSPMediaFactoryURI instance.
|
|
|
|
*
|
2014-03-23 20:24:48 +00:00
|
|
|
* Returns: (transfer full): a new #GstRTSPMediaFactoryURI object.
|
2010-12-11 17:01:53 +00:00
|
|
|
*/
|
|
|
|
GstRTSPMediaFactoryURI *
|
|
|
|
gst_rtsp_media_factory_uri_new (void)
|
|
|
|
{
|
|
|
|
GstRTSPMediaFactoryURI *result;
|
|
|
|
|
|
|
|
result = g_object_new (GST_TYPE_RTSP_MEDIA_FACTORY_URI, NULL);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_factory_uri_set_uri:
|
|
|
|
* @factory: a #GstRTSPMediaFactory
|
|
|
|
* @uri: the uri the stream
|
|
|
|
*
|
|
|
|
* Set the URI of the resource that will be streamed by this factory.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_media_factory_uri_set_uri (GstRTSPMediaFactoryURI * factory,
|
|
|
|
const gchar * uri)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaFactoryURIPrivate *priv;
|
|
|
|
|
2010-12-11 17:01:53 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY_URI (factory));
|
|
|
|
g_return_if_fail (uri != NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = factory->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
g_free (priv->uri);
|
|
|
|
priv->uri = g_strdup (uri);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2010-12-11 17:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_factory_uri_get_uri:
|
|
|
|
* @factory: a #GstRTSPMediaFactory
|
|
|
|
*
|
|
|
|
* Get the URI that will provide media for this factory.
|
|
|
|
*
|
2014-03-23 20:24:48 +00:00
|
|
|
* Returns: (transfer full): the configured URI. g_free() after usage.
|
2010-12-11 17:01:53 +00:00
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
gst_rtsp_media_factory_uri_get_uri (GstRTSPMediaFactoryURI * factory)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaFactoryURIPrivate *priv;
|
2010-12-11 17:01:53 +00:00
|
|
|
gchar *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY_URI (factory), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = factory->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
result = g_strdup (priv->uri);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2010-12-11 17:01:53 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementFactory *
|
|
|
|
find_payloader (GstRTSPMediaFactoryURI * urifact, GstCaps * caps)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaFactoryURIPrivate *priv = urifact->priv;
|
2012-05-22 13:37:25 +00:00
|
|
|
GList *list;
|
2010-12-11 17:01:53 +00:00
|
|
|
GstElementFactory *factory = NULL;
|
2012-10-12 04:07:07 +00:00
|
|
|
gboolean autoplug_more = FALSE;
|
2010-12-11 17:01:53 +00:00
|
|
|
|
2010-12-23 14:58:14 +00:00
|
|
|
/* first find a demuxer that can link */
|
2012-11-29 10:11:05 +00:00
|
|
|
list = gst_element_factory_list_filter (priv->demuxers, caps,
|
2010-12-11 17:01:53 +00:00
|
|
|
GST_PAD_SINK, FALSE);
|
|
|
|
|
2012-10-12 04:07:07 +00:00
|
|
|
if (list) {
|
|
|
|
GstStructure *structure = gst_caps_get_structure (caps, 0);
|
|
|
|
gboolean parsed = FALSE;
|
2013-08-22 17:39:59 +00:00
|
|
|
gint mpegversion = 0;
|
|
|
|
|
|
|
|
if (!gst_structure_get_boolean (structure, "parsed", &parsed) &&
|
|
|
|
gst_structure_has_name (structure, "audio/mpeg") &&
|
|
|
|
gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
|
|
|
|
(mpegversion == 2 || mpegversion == 4)) {
|
|
|
|
/* for AAC it's framed=true instead of parsed=true */
|
|
|
|
gst_structure_get_boolean (structure, "framed", &parsed);
|
|
|
|
}
|
2012-10-12 04:07:07 +00:00
|
|
|
|
|
|
|
/* Avoid plugging parsers in a loop. This is not 100% correct, as some
|
|
|
|
* parsers don't set parsed=true in caps. We should do something like
|
|
|
|
* decodebin does and track decode chains and elements plugged in those
|
|
|
|
* chains...
|
|
|
|
*/
|
|
|
|
if (parsed) {
|
|
|
|
GList *walk;
|
|
|
|
const gchar *klass;
|
|
|
|
|
|
|
|
for (walk = list; walk; walk = walk->next) {
|
|
|
|
factory = GST_ELEMENT_FACTORY (walk->data);
|
2012-11-17 00:11:27 +00:00
|
|
|
klass = gst_element_factory_get_metadata (factory,
|
|
|
|
GST_ELEMENT_METADATA_KLASS);
|
2012-10-12 04:07:07 +00:00
|
|
|
if (strstr (klass, "Parser"))
|
|
|
|
/* caps have parsed=true, so skip this parser to avoid loops */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
autoplug_more = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* caps don't have parsed=true set and we have a demuxer/parser */
|
|
|
|
autoplug_more = TRUE;
|
|
|
|
}
|
|
|
|
|
2010-12-23 14:58:14 +00:00
|
|
|
gst_plugin_feature_list_free (list);
|
|
|
|
}
|
2010-12-11 17:01:53 +00:00
|
|
|
|
2012-10-12 04:07:07 +00:00
|
|
|
if (autoplug_more)
|
|
|
|
/* we have a demuxer, try that one first */
|
|
|
|
return NULL;
|
|
|
|
|
2010-12-23 14:58:14 +00:00
|
|
|
/* no demuxer try a depayloader */
|
2012-11-29 10:11:05 +00:00
|
|
|
list = gst_element_factory_list_filter (priv->payloaders, caps,
|
2010-12-23 14:58:14 +00:00
|
|
|
GST_PAD_SINK, FALSE);
|
2010-12-11 17:01:53 +00:00
|
|
|
|
2010-12-23 14:58:14 +00:00
|
|
|
if (list == NULL) {
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->use_gstpay) {
|
2010-12-23 17:53:01 +00:00
|
|
|
/* no depayloader or parser/demuxer, use gstpay when allowed */
|
|
|
|
factory = gst_element_factory_find ("rtpgstpay");
|
|
|
|
} else {
|
|
|
|
/* no depayloader, try a decoder, we'll get to a payloader for a decoded
|
|
|
|
* video or audio format, worst case. */
|
2012-11-29 10:11:05 +00:00
|
|
|
list = gst_element_factory_list_filter (priv->decoders, caps,
|
2010-12-23 17:53:01 +00:00
|
|
|
GST_PAD_SINK, FALSE);
|
|
|
|
|
|
|
|
if (list != NULL) {
|
|
|
|
/* we have a decoder, try that one first */
|
|
|
|
gst_plugin_feature_list_free (list);
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-12-23 14:58:14 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-11 17:01:53 +00:00
|
|
|
|
2010-12-23 14:58:14 +00:00
|
|
|
if (list != NULL) {
|
|
|
|
factory = GST_ELEMENT_FACTORY_CAST (list->data);
|
|
|
|
g_object_ref (factory);
|
|
|
|
gst_plugin_feature_list_free (list);
|
|
|
|
}
|
2010-12-11 17:01:53 +00:00
|
|
|
return factory;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
autoplug_continue_cb (GstElement * uribin, GstPad * pad, GstCaps * caps,
|
|
|
|
GstElement * element)
|
|
|
|
{
|
2010-12-12 03:06:41 +00:00
|
|
|
FactoryData *data;
|
2010-12-11 17:01:53 +00:00
|
|
|
GstElementFactory *factory;
|
|
|
|
|
|
|
|
GST_DEBUG ("found pad %s:%s of caps %" GST_PTR_FORMAT,
|
|
|
|
GST_DEBUG_PAD_NAME (pad), caps);
|
|
|
|
|
2010-12-12 03:06:41 +00:00
|
|
|
data = g_object_get_data (G_OBJECT (element), factory_key);
|
2010-12-11 17:01:53 +00:00
|
|
|
|
2010-12-12 03:06:41 +00:00
|
|
|
if (!(factory = find_payloader (data->factory, caps)))
|
2010-12-11 17:01:53 +00:00
|
|
|
goto no_factory;
|
|
|
|
|
2010-12-23 14:58:14 +00:00
|
|
|
/* we found a payloader, stop autoplugging so we can plug the
|
|
|
|
* payloader. */
|
|
|
|
GST_DEBUG ("found factory %s",
|
2010-12-11 17:01:53 +00:00
|
|
|
gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
|
|
|
|
gst_object_unref (factory);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_factory:
|
|
|
|
{
|
|
|
|
/* no payloader, continue autoplugging */
|
|
|
|
GST_DEBUG ("no payloader found");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pad_added_cb (GstElement * uribin, GstPad * pad, GstElement * element)
|
|
|
|
{
|
|
|
|
GstRTSPMediaFactoryURI *urifact;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaFactoryURIPrivate *priv;
|
2010-12-12 03:06:41 +00:00
|
|
|
FactoryData *data;
|
2010-12-11 17:01:53 +00:00
|
|
|
GstElementFactory *factory;
|
|
|
|
GstElement *payloader;
|
|
|
|
GstCaps *caps;
|
|
|
|
GstPad *sinkpad, *srcpad, *ghostpad;
|
2010-12-12 03:06:41 +00:00
|
|
|
GstElement *convert;
|
2019-07-22 16:32:43 +00:00
|
|
|
gchar *padname, *payloader_name;
|
2010-12-11 17:01:53 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("added pad %s:%s", GST_DEBUG_PAD_NAME (pad));
|
|
|
|
|
|
|
|
/* link the element now and expose the pad */
|
2010-12-12 03:06:41 +00:00
|
|
|
data = g_object_get_data (G_OBJECT (element), factory_key);
|
|
|
|
urifact = data->factory;
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = urifact->priv;
|
2010-12-11 17:01:53 +00:00
|
|
|
|
2010-12-12 03:06:41 +00:00
|
|
|
/* ref to make refcounting easier later */
|
|
|
|
gst_object_ref (pad);
|
|
|
|
padname = gst_pad_get_name (pad);
|
|
|
|
|
|
|
|
/* get pad caps first, then call get_caps, then fail */
|
2011-05-17 07:48:13 +00:00
|
|
|
if ((caps = gst_pad_get_current_caps (pad)) == NULL)
|
2011-12-09 09:53:30 +00:00
|
|
|
if ((caps = gst_pad_query_caps (pad, NULL)) == NULL)
|
2011-05-17 07:48:13 +00:00
|
|
|
goto no_caps;
|
2010-12-11 17:01:53 +00:00
|
|
|
|
2010-12-12 03:06:41 +00:00
|
|
|
/* check for raw caps */
|
2012-11-29 10:11:05 +00:00
|
|
|
if (gst_caps_can_intersect (caps, priv->raw_vcaps)) {
|
2010-12-12 03:06:41 +00:00
|
|
|
/* we have raw video caps, insert converter */
|
2012-03-13 15:06:50 +00:00
|
|
|
convert = gst_element_factory_make ("videoconvert", NULL);
|
2012-11-29 10:11:05 +00:00
|
|
|
} else if (gst_caps_can_intersect (caps, priv->raw_acaps)) {
|
2010-12-12 03:06:41 +00:00
|
|
|
/* we have raw audio caps, insert converter */
|
|
|
|
convert = gst_element_factory_make ("audioconvert", NULL);
|
|
|
|
} else {
|
|
|
|
convert = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (convert) {
|
|
|
|
gst_bin_add (GST_BIN_CAST (element), convert);
|
|
|
|
gst_element_set_state (convert, GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
sinkpad = gst_element_get_static_pad (convert, "sink");
|
|
|
|
gst_pad_link (pad, sinkpad);
|
|
|
|
gst_object_unref (sinkpad);
|
|
|
|
|
|
|
|
/* unref old pad, we reffed before */
|
|
|
|
gst_object_unref (pad);
|
2021-05-05 00:47:18 +00:00
|
|
|
gst_caps_unref (caps);
|
2010-12-12 03:06:41 +00:00
|
|
|
|
|
|
|
/* continue with new pad and caps */
|
|
|
|
pad = gst_element_get_static_pad (convert, "src");
|
2011-05-17 07:48:13 +00:00
|
|
|
if ((caps = gst_pad_get_current_caps (pad)) == NULL)
|
2011-12-09 09:53:30 +00:00
|
|
|
if ((caps = gst_pad_query_caps (pad, NULL)) == NULL)
|
2011-05-17 07:48:13 +00:00
|
|
|
goto no_caps;
|
2010-12-12 03:06:41 +00:00
|
|
|
}
|
|
|
|
|
2010-12-11 17:01:53 +00:00
|
|
|
if (!(factory = find_payloader (urifact, caps)))
|
|
|
|
goto no_factory;
|
|
|
|
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
/* we have a payloader now */
|
|
|
|
GST_DEBUG ("found payloader factory %s",
|
|
|
|
gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
|
|
|
|
|
2019-07-22 16:32:43 +00:00
|
|
|
payloader_name = g_strdup_printf ("pay_%s", padname);
|
|
|
|
payloader = gst_element_factory_create (factory, payloader_name);
|
|
|
|
g_free (payloader_name);
|
2010-12-11 17:01:53 +00:00
|
|
|
if (payloader == NULL)
|
|
|
|
goto no_payloader;
|
|
|
|
|
2010-12-12 03:06:41 +00:00
|
|
|
g_object_set (payloader, "pt", data->pt, NULL);
|
|
|
|
data->pt++;
|
|
|
|
|
2011-01-05 11:07:42 +00:00
|
|
|
if (g_object_class_find_property (G_OBJECT_GET_CLASS (payloader),
|
|
|
|
"buffer-list"))
|
|
|
|
g_object_set (payloader, "buffer-list", TRUE, NULL);
|
|
|
|
|
2010-12-11 17:01:53 +00:00
|
|
|
/* add the payloader to the pipeline */
|
|
|
|
gst_bin_add (GST_BIN_CAST (element), payloader);
|
|
|
|
gst_element_set_state (payloader, GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
/* link the pad to the sinkpad of the payloader */
|
|
|
|
sinkpad = gst_element_get_static_pad (payloader, "sink");
|
|
|
|
gst_pad_link (pad, sinkpad);
|
|
|
|
gst_object_unref (sinkpad);
|
2010-12-12 03:06:41 +00:00
|
|
|
gst_object_unref (pad);
|
2010-12-11 17:01:53 +00:00
|
|
|
|
|
|
|
/* now expose the srcpad of the payloader as a ghostpad with the same name
|
|
|
|
* as the uridecodebin pad name. */
|
|
|
|
srcpad = gst_element_get_static_pad (payloader, "src");
|
2010-12-12 03:06:41 +00:00
|
|
|
ghostpad = gst_ghost_pad_new (padname, srcpad);
|
2010-12-11 17:01:53 +00:00
|
|
|
gst_object_unref (srcpad);
|
2010-12-12 03:06:41 +00:00
|
|
|
g_free (padname);
|
2010-12-11 17:01:53 +00:00
|
|
|
|
|
|
|
gst_pad_set_active (ghostpad, TRUE);
|
|
|
|
gst_element_add_pad (element, ghostpad);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_caps:
|
|
|
|
{
|
|
|
|
GST_WARNING ("could not get caps from pad");
|
2010-12-12 03:06:41 +00:00
|
|
|
g_free (padname);
|
|
|
|
gst_object_unref (pad);
|
2010-12-11 17:01:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
no_factory:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("no payloader found");
|
2010-12-12 03:06:41 +00:00
|
|
|
g_free (padname);
|
2010-12-11 17:01:53 +00:00
|
|
|
gst_caps_unref (caps);
|
2010-12-12 03:06:41 +00:00
|
|
|
gst_object_unref (pad);
|
2010-12-11 17:01:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
no_payloader:
|
|
|
|
{
|
|
|
|
GST_ERROR ("could not create payloader from factory");
|
2010-12-12 03:06:41 +00:00
|
|
|
g_free (padname);
|
2010-12-11 17:01:53 +00:00
|
|
|
gst_caps_unref (caps);
|
2010-12-12 03:06:41 +00:00
|
|
|
gst_object_unref (pad);
|
2010-12-11 17:01:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
no_more_pads_cb (GstElement * uribin, GstElement * element)
|
|
|
|
{
|
|
|
|
GST_DEBUG ("no-more-pads");
|
|
|
|
gst_element_no_more_pads (element);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElement *
|
2012-10-25 19:29:58 +00:00
|
|
|
rtsp_media_factory_uri_create_element (GstRTSPMediaFactory * factory,
|
2010-12-11 17:01:53 +00:00
|
|
|
const GstRTSPUrl * url)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMediaFactoryURIPrivate *priv;
|
2010-12-11 17:01:53 +00:00
|
|
|
GstElement *topbin, *element, *uribin;
|
|
|
|
GstRTSPMediaFactoryURI *urifact;
|
2010-12-12 03:06:41 +00:00
|
|
|
FactoryData *data;
|
2010-12-11 17:01:53 +00:00
|
|
|
|
|
|
|
urifact = GST_RTSP_MEDIA_FACTORY_URI_CAST (factory);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = urifact->priv;
|
2010-12-11 17:01:53 +00:00
|
|
|
|
|
|
|
GST_LOG ("creating element");
|
|
|
|
|
|
|
|
topbin = gst_bin_new ("GstRTSPMediaFactoryURI");
|
|
|
|
g_assert (topbin != NULL);
|
|
|
|
|
|
|
|
/* our bin will dynamically expose payloaded pads */
|
|
|
|
element = gst_bin_new ("dynpay0");
|
|
|
|
g_assert (element != NULL);
|
|
|
|
|
|
|
|
uribin = gst_element_factory_make ("uridecodebin", "uribin");
|
|
|
|
if (uribin == NULL)
|
|
|
|
goto no_uridecodebin;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_object_set (uribin, "uri", priv->uri, NULL);
|
2010-12-11 17:01:53 +00:00
|
|
|
|
2010-12-12 03:06:41 +00:00
|
|
|
/* keep factory data around */
|
|
|
|
data = g_new0 (FactoryData, 1);
|
2018-03-20 14:21:37 +00:00
|
|
|
data->factory = g_object_ref (urifact);
|
2010-12-12 03:06:41 +00:00
|
|
|
data->pt = 96;
|
|
|
|
|
2010-12-11 17:01:53 +00:00
|
|
|
g_object_set_data_full (G_OBJECT (element), factory_key,
|
2010-12-12 03:06:41 +00:00
|
|
|
data, (GDestroyNotify) free_data);
|
2010-12-11 17:01:53 +00:00
|
|
|
|
|
|
|
/* connect to the signals */
|
|
|
|
g_signal_connect (uribin, "autoplug-continue",
|
|
|
|
(GCallback) autoplug_continue_cb, element);
|
|
|
|
g_signal_connect (uribin, "pad-added", (GCallback) pad_added_cb, element);
|
|
|
|
g_signal_connect (uribin, "no-more-pads", (GCallback) no_more_pads_cb,
|
|
|
|
element);
|
|
|
|
|
|
|
|
gst_bin_add (GST_BIN_CAST (element), uribin);
|
|
|
|
gst_bin_add (GST_BIN_CAST (topbin), element);
|
|
|
|
|
|
|
|
return topbin;
|
|
|
|
|
|
|
|
no_uridecodebin:
|
|
|
|
{
|
|
|
|
g_critical ("can't create uridecodebin element");
|
2012-11-28 11:10:47 +00:00
|
|
|
gst_object_unref (element);
|
2010-12-11 17:01:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|