diff --git a/sys/v4l2codecs/gstv4l2codech264dec.c b/sys/v4l2codecs/gstv4l2codech264dec.c index 7cdaf27179..93b4d9379e 100644 --- a/sys/v4l2codecs/gstv4l2codech264dec.c +++ b/sys/v4l2codecs/gstv4l2codech264dec.c @@ -978,39 +978,8 @@ void gst_v4l2_codec_h264_dec_register (GstPlugin * plugin, GstV4l2CodecDevice * device, guint rank) { - GTypeQuery type_query; - GTypeInfo type_info = { 0, }; - GType subtype; - gchar *type_name; - - g_type_query (GST_TYPE_V4L2_CODEC_H264_DEC, &type_query); - memset (&type_info, 0, sizeof (type_info)); - type_info.class_size = type_query.class_size; - type_info.instance_size = type_query.instance_size; - type_info.class_init = (GClassInitFunc) gst_v4l2_codec_h264_dec_subclass_init; - type_info.class_data = gst_mini_object_ref (GST_MINI_OBJECT (device)); - type_info.instance_init = (GInstanceInitFunc) gst_v4l2_codec_h264_dec_subinit; - GST_MINI_OBJECT_FLAG_SET (device, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); - - /* The first decoder to be registered should use a constant name, like - * v4l2slh264dec, for any additional decoders, we create unique names. Decoder - * names may change between boots, so this should help gain stable names for - * the most common use cases. SL stands for state-less, we differentiate - * with v4l2h264dec as this element may not have the same properties */ - type_name = g_strdup ("v4l2slh264dec"); - - if (g_type_from_name (type_name) != 0) { - gchar *basename = g_path_get_basename (device->video_device_path); - g_free (type_name); - type_name = g_strdup_printf ("v4l2sl%sh264dec", basename); - g_free (basename); - } - - subtype = g_type_register_static (GST_TYPE_V4L2_CODEC_H264_DEC, type_name, - &type_info, 0); - - if (!gst_element_register (plugin, type_name, rank, subtype)) - GST_WARNING ("Failed to register plugin '%s'", type_name); - - g_free (type_name); + gst_v4l2_decoder_register (plugin, GST_TYPE_V4L2_CODEC_H264_DEC, + (GClassInitFunc) gst_v4l2_codec_h264_dec_subclass_init, + (GInstanceInitFunc) gst_v4l2_codec_h264_dec_subinit, + "v4l2sl%sh264dec", device, rank); } diff --git a/sys/v4l2codecs/gstv4l2codecvp8dec.c b/sys/v4l2codecs/gstv4l2codecvp8dec.c index 475e700f77..8e7edcbe2e 100644 --- a/sys/v4l2codecs/gstv4l2codecvp8dec.c +++ b/sys/v4l2codecs/gstv4l2codecvp8dec.c @@ -22,8 +22,8 @@ #endif #include "gstv4l2codecallocator.h" -#include "gstv4l2codecvp8dec.h" #include "gstv4l2codecpool.h" +#include "gstv4l2codecvp8dec.h" #include "linux/vp8-ctrls.h" GST_DEBUG_CATEGORY_STATIC (v4l2_vp8dec_debug); @@ -871,39 +871,8 @@ void gst_v4l2_codec_vp8_dec_register (GstPlugin * plugin, GstV4l2CodecDevice * device, guint rank) { - GTypeQuery type_query; - GTypeInfo type_info = { 0, }; - GType subtype; - gchar *type_name; - - g_type_query (GST_TYPE_V4L2_CODEC_VP8_DEC, &type_query); - memset (&type_info, 0, sizeof (type_info)); - type_info.class_size = type_query.class_size; - type_info.instance_size = type_query.instance_size; - type_info.class_init = (GClassInitFunc) gst_v4l2_codec_vp8_dec_subclass_init; - type_info.class_data = gst_mini_object_ref (GST_MINI_OBJECT (device)); - type_info.instance_init = (GInstanceInitFunc) gst_v4l2_codec_vp8_dec_subinit; - GST_MINI_OBJECT_FLAG_SET (device, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); - - /* The first decoder to be registered should use a constant name, like - * v4l2slvp8dec, for any additional decoders, we create unique names. Decoder - * names may change between boots, so this should help gain stable names for - * the most common use cases. SL stands for state-less, we differentiate - * with v4l2vp8dec as this element may not have the same properties */ - type_name = g_strdup ("v4l2slvp8dec"); - - if (g_type_from_name (type_name) != 0) { - gchar *basename = g_path_get_basename (device->video_device_path); - g_free (type_name); - type_name = g_strdup_printf ("v4l2sl%svp8dec", basename); - g_free (basename); - } - - subtype = g_type_register_static (GST_TYPE_V4L2_CODEC_VP8_DEC, type_name, - &type_info, 0); - - if (!gst_element_register (plugin, type_name, rank, subtype)) - GST_WARNING ("Failed to register plugin '%s'", type_name); - - g_free (type_name); + gst_v4l2_decoder_register (plugin, GST_TYPE_V4L2_CODEC_VP8_DEC, + (GClassInitFunc) gst_v4l2_codec_vp8_dec_subclass_init, + (GInstanceInitFunc) gst_v4l2_codec_vp8_dec_subinit, + "v4l2sl%svp8dec", device, rank); } diff --git a/sys/v4l2codecs/gstv4l2decoder.c b/sys/v4l2codecs/gstv4l2decoder.c index 6423e60b6c..43581c8ccd 100644 --- a/sys/v4l2codecs/gstv4l2decoder.c +++ b/sys/v4l2codecs/gstv4l2decoder.c @@ -643,6 +643,47 @@ gst_v4l2_decoder_get_property (GObject * object, guint prop_id, } } +void +gst_v4l2_decoder_register (GstPlugin * plugin, + GType dec_type, GClassInitFunc class_init, GInstanceInitFunc instance_init, + const gchar * element_name_tmpl, GstV4l2CodecDevice * device, guint rank) +{ + GTypeQuery type_query; + GTypeInfo type_info = { 0, }; + GType subtype; + gchar *type_name; + + g_type_query (dec_type, &type_query); + memset (&type_info, 0, sizeof (type_info)); + type_info.class_size = type_query.class_size; + type_info.instance_size = type_query.instance_size; + type_info.class_init = class_init; + type_info.class_data = gst_mini_object_ref (GST_MINI_OBJECT (device)); + type_info.instance_init = instance_init; + GST_MINI_OBJECT_FLAG_SET (device, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); + + /* The first decoder to be registered should use a constant name, like + * v4l2slvp8dec, for any additional decoders, we create unique names. Decoder + * names may change between boots, so this should help gain stable names for + * the most common use cases. SL stands for state-less, we differentiate + * with v4l2vp8dec as this element may not have the same properties */ + type_name = g_strdup_printf (element_name_tmpl, ""); + + if (g_type_from_name (type_name) != 0) { + gchar *basename = g_path_get_basename (device->video_device_path); + g_free (type_name); + type_name = g_strdup_printf (element_name_tmpl, basename); + g_free (basename); + } + + subtype = g_type_register_static (dec_type, type_name, &type_info, 0); + + if (!gst_element_register (plugin, type_name, rank, subtype)) + GST_WARNING ("Failed to register plugin '%s'", type_name); + + g_free (type_name); +} + GstV4l2Request * gst_v4l2_decoder_alloc_request (GstV4l2Decoder * self) { diff --git a/sys/v4l2codecs/gstv4l2decoder.h b/sys/v4l2codecs/gstv4l2decoder.h index 72ecb23d03..d5c9a54693 100644 --- a/sys/v4l2codecs/gstv4l2decoder.h +++ b/sys/v4l2codecs/gstv4l2decoder.h @@ -101,6 +101,14 @@ void gst_v4l2_decoder_set_property (GObject * object, guint prop_id void gst_v4l2_decoder_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); +void gst_v4l2_decoder_register (GstPlugin * plugin, + GType dec_type, + GClassInitFunc class_init, + GInstanceInitFunc instance_init, + const gchar *element_name_tmpl, + GstV4l2CodecDevice * device, + guint rank); + GstV4l2Request *gst_v4l2_decoder_alloc_request (GstV4l2Decoder * self); void gst_v4l2_request_free (GstV4l2Request * request); diff --git a/sys/v4l2codecs/meson.build b/sys/v4l2codecs/meson.build index 155710be2a..d87628592e 100644 --- a/sys/v4l2codecs/meson.build +++ b/sys/v4l2codecs/meson.build @@ -3,8 +3,8 @@ v4l2codecs_sources = [ 'gstv4l2codecallocator.c', 'gstv4l2codecdevice.c', 'gstv4l2codech264dec.c', - 'gstv4l2codecvp8dec.c', 'gstv4l2codecpool.c', + 'gstv4l2codecvp8dec.c', 'gstv4l2decoder.c', 'gstv4l2format.c', ]