2009-01-20 18:44:45 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "rtsp-media-factory.h"
|
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
#define DEFAULT_LAUNCH NULL
|
2009-01-29 16:20:27 +00:00
|
|
|
#define DEFAULT_SHARED FALSE
|
2009-01-22 14:33:29 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_LAUNCH,
|
2009-01-29 16:20:27 +00:00
|
|
|
PROP_SHARED,
|
2009-01-22 14:33:29 +00:00
|
|
|
PROP_LAST
|
|
|
|
};
|
2009-01-20 18:44:45 +00:00
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
static void gst_rtsp_media_factory_get_property (GObject *object, guint propid,
|
|
|
|
GValue *value, GParamSpec *pspec);
|
|
|
|
static void gst_rtsp_media_factory_set_property (GObject *object, guint propid,
|
|
|
|
const GValue *value, GParamSpec *pspec);
|
2009-01-20 18:44:45 +00:00
|
|
|
static void gst_rtsp_media_factory_finalize (GObject * obj);
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
static gchar * default_gen_key (GstRTSPMediaFactory *factory, const GstRTSPUrl *url);
|
2009-01-22 16:58:19 +00:00
|
|
|
static GstElement * default_get_element (GstRTSPMediaFactory *factory, const GstRTSPUrl *url);
|
2009-01-29 16:20:27 +00:00
|
|
|
static GstRTSPMedia * default_construct (GstRTSPMediaFactory *factory, const GstRTSPUrl *url);
|
|
|
|
static void default_configure (GstRTSPMediaFactory *factory, GstRTSPMedia *media);
|
2009-01-22 14:33:29 +00:00
|
|
|
|
|
|
|
G_DEFINE_TYPE (GstRTSPMediaFactory, gst_rtsp_media_factory, G_TYPE_OBJECT);
|
2009-01-20 18:44:45 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_media_factory_class_init (GstRTSPMediaFactoryClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
gobject_class->get_property = gst_rtsp_media_factory_get_property;
|
|
|
|
gobject_class->set_property = gst_rtsp_media_factory_set_property;
|
2009-01-20 18:44:45 +00:00
|
|
|
gobject_class->finalize = gst_rtsp_media_factory_finalize;
|
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPMediaFactory::launch
|
|
|
|
*
|
|
|
|
* The gst_parse_launch() line to use for constructing the pipeline in the
|
|
|
|
* default prepare vmethod.
|
|
|
|
*
|
|
|
|
* The pipeline description should return a GstBin as the toplevel element
|
|
|
|
* which can be accomplished by enclosing the dscription with brackets '('
|
|
|
|
* ')'.
|
|
|
|
*
|
|
|
|
* The description should return a pipeline with payloaders named pay0, pay1,
|
|
|
|
* etc.. Each of the payloaders will result in a stream.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_LAUNCH,
|
|
|
|
g_param_spec_string ("launch", "Launch", "A launch description of the pipeline",
|
|
|
|
DEFAULT_LAUNCH, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SHARED,
|
|
|
|
g_param_spec_boolean ("shared", "Shared", "If media from this factory is shared",
|
|
|
|
DEFAULT_SHARED, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
klass->gen_key = default_gen_key;
|
2009-01-22 15:51:08 +00:00
|
|
|
klass->get_element = default_get_element;
|
2009-01-29 16:20:27 +00:00
|
|
|
klass->construct = default_construct;
|
|
|
|
klass->configure = default_configure;
|
2009-01-20 18:44:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_media_factory_init (GstRTSPMediaFactory * factory)
|
|
|
|
{
|
2009-01-29 16:20:27 +00:00
|
|
|
factory->launch = g_strdup (DEFAULT_LAUNCH);
|
|
|
|
factory->shared = DEFAULT_SHARED;
|
|
|
|
|
|
|
|
factory->lock = g_mutex_new ();
|
|
|
|
factory->medias_lock = g_mutex_new ();
|
|
|
|
factory->medias = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
g_free, g_object_unref);
|
2009-01-20 18:44:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_media_factory_finalize (GObject * obj)
|
|
|
|
{
|
2009-01-22 14:33:29 +00:00
|
|
|
GstRTSPMediaFactory *factory = GST_RTSP_MEDIA_FACTORY (obj);
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
g_hash_table_unref (factory->medias);
|
|
|
|
g_mutex_free (factory->medias_lock);
|
2009-01-22 14:33:29 +00:00
|
|
|
g_free (factory->launch);
|
2009-01-29 16:20:27 +00:00
|
|
|
g_mutex_free (factory->lock);
|
2009-01-22 14:33:29 +00:00
|
|
|
|
2009-01-20 18:44:45 +00:00
|
|
|
G_OBJECT_CLASS (gst_rtsp_media_factory_parent_class)->finalize (obj);
|
|
|
|
}
|
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
static void
|
|
|
|
gst_rtsp_media_factory_get_property (GObject *object, guint propid,
|
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstRTSPMediaFactory *factory = GST_RTSP_MEDIA_FACTORY (object);
|
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_LAUNCH:
|
|
|
|
g_value_take_string (value, gst_rtsp_media_factory_get_launch (factory));
|
|
|
|
break;
|
2009-01-29 16:20:27 +00:00
|
|
|
case PROP_SHARED:
|
|
|
|
g_value_set_boolean (value, gst_rtsp_media_factory_is_shared (factory));
|
|
|
|
break;
|
2009-01-22 14:33:29 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_media_factory_set_property (GObject *object, guint propid,
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstRTSPMediaFactory *factory = GST_RTSP_MEDIA_FACTORY (object);
|
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_LAUNCH:
|
|
|
|
gst_rtsp_media_factory_set_launch (factory, g_value_get_string (value));
|
|
|
|
break;
|
2009-01-29 16:20:27 +00:00
|
|
|
case PROP_SHARED:
|
|
|
|
gst_rtsp_media_factory_set_shared (factory, g_value_get_boolean (value));
|
|
|
|
break;
|
2009-01-22 14:33:29 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_factory_new:
|
|
|
|
*
|
|
|
|
* Create a new #GstRTSPMediaFactory instance.
|
|
|
|
*
|
2009-01-22 16:58:19 +00:00
|
|
|
* Returns: a new #GstRTSPMediaFactory object.
|
2009-01-22 14:33:29 +00:00
|
|
|
*/
|
2009-01-20 18:44:45 +00:00
|
|
|
GstRTSPMediaFactory *
|
|
|
|
gst_rtsp_media_factory_new (void)
|
|
|
|
{
|
|
|
|
GstRTSPMediaFactory *result;
|
|
|
|
|
|
|
|
result = g_object_new (GST_TYPE_RTSP_MEDIA_FACTORY, NULL);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_factory_set_launch:
|
|
|
|
* @factory: a #GstRTSPMediaFactory
|
|
|
|
* @launch: the launch description
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* The gst_parse_launch() line to use for constructing the pipeline in the
|
|
|
|
* default prepare vmethod.
|
|
|
|
*
|
|
|
|
* The pipeline description should return a GstBin as the toplevel element
|
|
|
|
* which can be accomplished by enclosing the dscription with brackets '('
|
|
|
|
* ')'.
|
|
|
|
*
|
|
|
|
* The description should return a pipeline with payloaders named pay0, pay1,
|
|
|
|
* etc.. Each of the payloaders will result in a stream.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_media_factory_set_launch (GstRTSPMediaFactory *factory, const gchar *launch)
|
2009-01-20 18:44:45 +00:00
|
|
|
{
|
2009-01-22 14:33:29 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
|
|
|
|
g_return_if_fail (launch != NULL);
|
2009-01-20 18:44:45 +00:00
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
g_mutex_lock (factory->lock);
|
|
|
|
g_free (factory->launch);
|
2009-01-22 14:33:29 +00:00
|
|
|
factory->launch = g_strdup (launch);
|
2009-01-29 16:20:27 +00:00
|
|
|
g_mutex_unlock (factory->lock);
|
2009-01-22 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_factory_get_launch:
|
|
|
|
* @factory: a #GstRTSPMediaFactory
|
|
|
|
*
|
|
|
|
* Get the gst_parse_launch() pipeline description that will be used in the
|
|
|
|
* default prepare vmethod.
|
|
|
|
*
|
|
|
|
* Returns: the configured launch description. g_free() after usage.
|
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
gst_rtsp_media_factory_get_launch (GstRTSPMediaFactory *factory)
|
|
|
|
{
|
|
|
|
gchar *result;
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), NULL);
|
|
|
|
|
|
|
|
g_mutex_lock (factory->lock);
|
2009-01-22 14:33:29 +00:00
|
|
|
result = g_strdup (factory->launch);
|
2009-01-29 16:20:27 +00:00
|
|
|
g_mutex_unlock (factory->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_factory_set_shared:
|
|
|
|
* @factory: a #GstRTSPMediaFactory
|
|
|
|
* @shared: the new value
|
|
|
|
*
|
|
|
|
* Configure if media created from this factory can be shared between clients.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_media_factory_set_shared (GstRTSPMediaFactory *factory,
|
|
|
|
gboolean shared)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
|
|
|
|
|
|
|
|
g_mutex_lock (factory->lock);
|
|
|
|
factory->shared = shared;
|
|
|
|
g_mutex_unlock (factory->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_factory_is_shared:
|
|
|
|
* @factory: a #GstRTSPMediaFactory
|
|
|
|
*
|
|
|
|
* Get if media created from this factory can be shared between clients.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the media will be shared between clients.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_media_factory_is_shared (GstRTSPMediaFactory *factory)
|
|
|
|
{
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), FALSE);
|
|
|
|
|
|
|
|
g_mutex_lock (factory->lock);
|
|
|
|
result = factory->shared;
|
|
|
|
g_mutex_unlock (factory->lock);
|
2009-01-20 18:44:45 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-04-03 20:46:22 +00:00
|
|
|
static gboolean
|
|
|
|
compare_media (gpointer key, GstRTSPMedia *media1, GstRTSPMedia *media2)
|
|
|
|
{
|
|
|
|
return (media1 == media2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
media_unprepared (GstRTSPMedia *media, GstRTSPMediaFactory *factory)
|
|
|
|
{
|
|
|
|
g_mutex_lock (factory->medias_lock);
|
|
|
|
g_hash_table_foreach_remove (factory->medias, (GHRFunc) compare_media,
|
|
|
|
media);
|
|
|
|
g_mutex_unlock (factory->medias_lock);
|
|
|
|
}
|
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_factory_construct:
|
|
|
|
* @factory: a #GstRTSPMediaFactory
|
2009-01-22 16:58:19 +00:00
|
|
|
* @url: the url used
|
2009-01-22 14:33:29 +00:00
|
|
|
*
|
2009-01-22 16:58:19 +00:00
|
|
|
* Prepare the media object and create its streams. Implementations
|
2009-01-22 14:33:29 +00:00
|
|
|
* should create the needed gstreamer elements and add them to the result
|
|
|
|
* object. No state changes should be performed on them yet.
|
|
|
|
*
|
|
|
|
* One or more GstRTSPMediaStream objects should be added to the result with
|
|
|
|
* the srcpad member set to a source pad that produces buffer of type
|
|
|
|
* application/x-rtp.
|
|
|
|
*
|
2009-01-22 16:58:19 +00:00
|
|
|
* Returns: a new #GstRTSPMedia if the media could be prepared.
|
2009-01-22 14:33:29 +00:00
|
|
|
*/
|
2009-01-22 16:58:19 +00:00
|
|
|
GstRTSPMedia *
|
|
|
|
gst_rtsp_media_factory_construct (GstRTSPMediaFactory *factory, const GstRTSPUrl *url)
|
2009-01-20 18:44:45 +00:00
|
|
|
{
|
2009-01-29 16:20:27 +00:00
|
|
|
gchar *key;
|
|
|
|
GstRTSPMedia *media;
|
2009-01-20 18:44:45 +00:00
|
|
|
GstRTSPMediaFactoryClass *klass;
|
|
|
|
|
|
|
|
klass = GST_RTSP_MEDIA_FACTORY_GET_CLASS (factory);
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
/* convert the url to a key for the hashtable. NULL return or a NULL function
|
|
|
|
* will not cache anything for this factory. */
|
|
|
|
if (klass->gen_key)
|
|
|
|
key = klass->gen_key (factory, url);
|
|
|
|
else
|
|
|
|
key = NULL;
|
|
|
|
|
|
|
|
g_mutex_lock (factory->medias_lock);
|
|
|
|
if (key) {
|
|
|
|
/* we have a key, see if we find a cached media */
|
|
|
|
media = g_hash_table_lookup (factory->medias, key);
|
|
|
|
if (media)
|
|
|
|
g_object_ref (media);
|
|
|
|
}
|
2009-01-22 14:33:29 +00:00
|
|
|
else
|
2009-01-29 16:20:27 +00:00
|
|
|
media = NULL;
|
|
|
|
|
|
|
|
if (media == NULL) {
|
|
|
|
/* nothing cached found, try to create one */
|
|
|
|
if (klass->construct)
|
|
|
|
media = klass->construct (factory, url);
|
|
|
|
else
|
|
|
|
media = NULL;
|
|
|
|
|
|
|
|
if (media) {
|
|
|
|
/* configure the media */
|
|
|
|
if (klass->configure)
|
|
|
|
klass->configure (factory, media);
|
|
|
|
|
|
|
|
/* check if we can cache this media */
|
|
|
|
if (gst_rtsp_media_is_shared (media)) {
|
|
|
|
/* insert in the hashtable, takes ownership of the key */
|
|
|
|
g_object_ref (media);
|
|
|
|
g_hash_table_insert (factory->medias, key, media);
|
|
|
|
key = NULL;
|
|
|
|
}
|
2009-04-03 20:46:22 +00:00
|
|
|
if (!gst_rtsp_media_is_reusable (media)) {
|
|
|
|
/* when not reusable, connect to the unprepare signal to remove the item
|
|
|
|
* from our cache when it gets unprepared */
|
|
|
|
g_signal_connect (media, "unprepared", (GCallback) media_unprepared,
|
|
|
|
factory);
|
|
|
|
}
|
2009-01-29 16:20:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
g_mutex_unlock (factory->medias_lock);
|
|
|
|
|
|
|
|
if (key)
|
|
|
|
g_free (key);
|
2009-01-20 18:44:45 +00:00
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
g_message ("constructed media %p for url %s", media, url->abspath);
|
2009-01-22 14:33:29 +00:00
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
return media;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
default_gen_key (GstRTSPMediaFactory *factory, const GstRTSPUrl *url)
|
|
|
|
{
|
|
|
|
gchar *result;
|
|
|
|
|
2009-01-31 18:50:33 +00:00
|
|
|
result = gst_rtsp_url_get_request_uri ((GstRTSPUrl *)url);
|
2009-01-29 16:20:27 +00:00
|
|
|
|
|
|
|
return result;
|
2009-01-20 18:44:45 +00:00
|
|
|
}
|
|
|
|
|
2009-01-22 15:51:08 +00:00
|
|
|
static GstElement *
|
2009-01-22 16:58:19 +00:00
|
|
|
default_get_element (GstRTSPMediaFactory *factory, const GstRTSPUrl *url)
|
2009-01-20 18:44:45 +00:00
|
|
|
{
|
2009-01-22 15:51:08 +00:00
|
|
|
GstElement *element;
|
2009-01-22 14:33:29 +00:00
|
|
|
GError *error = NULL;
|
2009-01-20 18:44:45 +00:00
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
g_mutex_lock (factory->lock);
|
2009-01-22 14:33:29 +00:00
|
|
|
/* we need a parse syntax */
|
|
|
|
if (factory->launch == NULL)
|
|
|
|
goto no_launch;
|
|
|
|
|
|
|
|
/* parse the user provided launch line */
|
|
|
|
element = gst_parse_launch (factory->launch, &error);
|
|
|
|
if (element == NULL)
|
|
|
|
goto parse_error;
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
g_mutex_unlock (factory->lock);
|
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
if (error != NULL) {
|
|
|
|
/* a recoverable error was encountered */
|
|
|
|
g_warning ("recoverable parsing error: %s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
2009-01-22 15:51:08 +00:00
|
|
|
return element;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_launch:
|
|
|
|
{
|
2009-01-29 16:20:27 +00:00
|
|
|
g_mutex_unlock (factory->lock);
|
2009-01-22 15:51:08 +00:00
|
|
|
g_critical ("no launch line specified");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
parse_error:
|
|
|
|
{
|
2009-01-29 16:20:27 +00:00
|
|
|
g_mutex_unlock (factory->lock);
|
2009-01-22 15:51:08 +00:00
|
|
|
g_critical ("could not parse launch syntax (%s): %s", factory->launch,
|
|
|
|
(error ? error->message : "unknown reason"));
|
|
|
|
if (error)
|
|
|
|
g_error_free (error);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-23 14:18:04 +00:00
|
|
|
/* try to find all the payloader elements, they should be named 'pay%d'. for
|
|
|
|
* each of the payloaders we will create a stream and collect the source pad. */
|
|
|
|
static void
|
|
|
|
collect_streams (GstRTSPMediaFactory *factory, const GstRTSPUrl *url,
|
|
|
|
GstRTSPMedia *media)
|
2009-01-22 15:51:08 +00:00
|
|
|
{
|
2009-05-23 14:18:04 +00:00
|
|
|
GstElement *element, *pay;
|
2009-01-22 15:51:08 +00:00
|
|
|
GstPad * pad;
|
|
|
|
gint i;
|
2009-05-23 14:18:04 +00:00
|
|
|
GstRTSPMediaStream *stream;
|
2009-01-22 14:33:29 +00:00
|
|
|
|
2009-05-23 14:18:04 +00:00
|
|
|
element = media->element;
|
2009-01-22 14:33:29 +00:00
|
|
|
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
name = g_strdup_printf ("pay%d", i);
|
|
|
|
if (!(pay = gst_bin_get_by_name (GST_BIN (element), name))) {
|
|
|
|
/* no more payloaders found, we have found all the streams and we can
|
|
|
|
* end the loop */
|
|
|
|
g_free (name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* create the stream */
|
|
|
|
stream = g_new0 (GstRTSPMediaStream, 1);
|
|
|
|
stream->payloader = pay;
|
|
|
|
|
2009-05-23 14:18:04 +00:00
|
|
|
g_message ("found stream %d with payloader %p", i, pay);
|
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
pad = gst_element_get_static_pad (pay, "src");
|
|
|
|
|
|
|
|
/* ghost the pad of the payloader to the element */
|
|
|
|
stream->srcpad = gst_ghost_pad_new (name, pad);
|
2009-01-29 12:31:27 +00:00
|
|
|
gst_element_add_pad (media->element, stream->srcpad);
|
|
|
|
gst_object_unref (pay);
|
|
|
|
g_free (name);
|
2009-01-22 14:33:29 +00:00
|
|
|
|
|
|
|
/* add stream now */
|
2009-01-22 16:58:19 +00:00
|
|
|
g_array_append_val (media->streams, stream);
|
2009-01-22 14:33:29 +00:00
|
|
|
}
|
2009-05-23 14:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPMedia *
|
|
|
|
default_construct (GstRTSPMediaFactory *factory, const GstRTSPUrl *url)
|
|
|
|
{
|
|
|
|
GstRTSPMedia *media;
|
|
|
|
GstElement *element;
|
|
|
|
GstRTSPMediaFactoryClass *klass;
|
|
|
|
|
|
|
|
klass = GST_RTSP_MEDIA_FACTORY_GET_CLASS (factory);
|
|
|
|
|
|
|
|
if (klass->get_element)
|
|
|
|
element = klass->get_element (factory, url);
|
|
|
|
else
|
|
|
|
element = NULL;
|
|
|
|
if (element == NULL)
|
|
|
|
goto no_element;
|
|
|
|
|
|
|
|
/* create a new empty media */
|
|
|
|
media = gst_rtsp_media_new ();
|
|
|
|
media->element = element;
|
|
|
|
|
|
|
|
collect_streams (factory, url, media);
|
2009-01-22 14:33:29 +00:00
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
return media;
|
2009-01-22 14:33:29 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2009-01-22 15:51:08 +00:00
|
|
|
no_element:
|
2009-01-22 14:33:29 +00:00
|
|
|
{
|
2009-01-22 15:51:08 +00:00
|
|
|
g_critical ("could not create element");
|
2009-01-22 14:33:29 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2009-01-29 16:20:27 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
default_configure (GstRTSPMediaFactory *factory, GstRTSPMedia *media)
|
|
|
|
{
|
|
|
|
gboolean shared;
|
|
|
|
|
|
|
|
/* configure the sharedness */
|
|
|
|
g_mutex_lock (factory->lock);
|
|
|
|
shared = factory->shared;
|
|
|
|
g_mutex_unlock (factory->lock);
|
|
|
|
|
|
|
|
gst_rtsp_media_set_shared (media, shared);
|
|
|
|
}
|