Make element creation more extendible

Add get_element vmethod to the default MediaFactory so that subclasses can just
override that method and still use the default logic for making a MediaBin from
that.
This commit is contained in:
Wim Taymans 2009-01-22 16:51:08 +01:00 committed by Wim Taymans
parent 4b1c190a5f
commit 28b65778f6
2 changed files with 52 additions and 19 deletions

View file

@ -35,6 +35,7 @@ static void gst_rtsp_media_factory_set_property (GObject *object, guint propid,
static void gst_rtsp_media_factory_finalize (GObject * obj);
static GstRTSPMediaBin * default_construct (GstRTSPMediaFactory *factory, const gchar *location);
static GstElement * default_get_element (GstRTSPMediaFactory *factory, const gchar *location);
G_DEFINE_TYPE (GstRTSPMediaFactory, gst_rtsp_media_factory, G_TYPE_OBJECT);
@ -67,6 +68,7 @@ gst_rtsp_media_factory_class_init (GstRTSPMediaFactoryClass * klass)
DEFAULT_LAUNCH, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
klass->construct = default_construct;
klass->get_element = default_get_element;
}
static void
@ -218,14 +220,10 @@ caps_notify (GstPad * pad, GParamSpec * unused, GstRTSPMediaStream * stream)
gst_caps_ref (stream->caps);
}
static GstRTSPMediaBin *
default_construct (GstRTSPMediaFactory *factory, const gchar *location)
static GstElement *
default_get_element (GstRTSPMediaFactory *factory, const gchar *location)
{
GstRTSPMediaBin *bin;
GstRTSPMediaStream *stream;
GstElement *pay, *element;
GstPad * pad;
gint i;
GstElement *element;
GError *error = NULL;
/* we need a parse syntax */
@ -242,6 +240,42 @@ default_construct (GstRTSPMediaFactory *factory, const gchar *location)
g_warning ("recoverable parsing error: %s", error->message);
g_error_free (error);
}
return element;
/* ERRORS */
no_launch:
{
g_critical ("no launch line specified");
return NULL;
}
parse_error:
{
g_critical ("could not parse launch syntax (%s): %s", factory->launch,
(error ? error->message : "unknown reason"));
if (error)
g_error_free (error);
return NULL;
}
}
static GstRTSPMediaBin *
default_construct (GstRTSPMediaFactory *factory, const gchar *location)
{
GstRTSPMediaBin *bin;
GstRTSPMediaStream *stream;
GstElement *pay, *element;
GstPad * pad;
gint i;
GstRTSPMediaFactoryClass *klass;
klass = GST_RTSP_MEDIA_FACTORY_GET_CLASS (factory);
if (klass->get_element)
element = klass->get_element (factory, location);
else
element = NULL;
if (element == NULL)
goto no_element;
bin = g_object_new (GST_TYPE_RTSP_MEDIA_BIN, NULL);
bin->element = element;
@ -287,17 +321,9 @@ default_construct (GstRTSPMediaFactory *factory, const gchar *location)
return bin;
/* ERRORS */
no_launch:
no_element:
{
g_critical ("no launch line specified");
return NULL;
}
parse_error:
{
g_critical ("could not parse launch syntax (%s): %s", factory->launch,
(error ? error->message : "unknown reason"));
if (error)
g_error_free (error);
g_critical ("could not create element");
return NULL;
}
}

View file

@ -56,15 +56,22 @@ struct _GstRTSPMediaFactory {
/**
* GstRTSPMediaFactoryClass:
* @get_element: Construct an return a #GstElement thast is a #GstBin containing
* the pipeline to use for the media. The bin should contain elements
* pay%d for each stream. The default implementation of this functions
* returns the bin created from the launch parameter.
* @construct: the vmethod that will be called when the factory has to create the
* #GstRTSPMediaBin for @location.
* #GstRTSPMediaBin for @location. The default implementation of this
* function calls get_element to retrieve an element and then looks for
* pay%d to create the streams.
*
* the #GstRTSPMediaFactory class structure.
*/
struct _GstRTSPMediaFactoryClass {
GObjectClass parent_class;
GstRTSPMediaBin * (*construct) (GstRTSPMediaFactory *factory, const gchar *location);
GstElement * (*get_element) (GstRTSPMediaFactory *factory, const gchar *location);
GstRTSPMediaBin * (*construct) (GstRTSPMediaFactory *factory, const gchar *location);
};
GType gst_rtsp_media_factory_get_type (void);