From 28b65778f6d4f323ae30da89133be36297b3e31f Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 22 Jan 2009 16:51:08 +0100 Subject: [PATCH] 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. --- gst/rtsp-server/rtsp-media-factory.c | 60 ++++++++++++++++++++++++++---------- gst/rtsp-server/rtsp-media-factory.h | 11 +++++-- 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/gst/rtsp-server/rtsp-media-factory.c b/gst/rtsp-server/rtsp-media-factory.c index 1412d6a..eb9c459 100644 --- a/gst/rtsp-server/rtsp-media-factory.c +++ b/gst/rtsp-server/rtsp-media-factory.c @@ -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: - { - g_critical ("no launch line specified"); - return NULL; - } -parse_error: +no_element: { - 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; } } diff --git a/gst/rtsp-server/rtsp-media-factory.h b/gst/rtsp-server/rtsp-media-factory.h index 5a98a96..b624eb1 100644 --- a/gst/rtsp-server/rtsp-media-factory.h +++ b/gst/rtsp-server/rtsp-media-factory.h @@ -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); -- 2.7.4