mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
v4l2codecs: Factor out plugin registration
This introduce a common place for generic functions and factor out the plugin registration code. This code is nearly identical between implementation. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1216>
This commit is contained in:
parent
de2cccaa47
commit
bf9f82c8c3
5 changed files with 59 additions and 72 deletions
|
@ -978,39 +978,8 @@ void
|
||||||
gst_v4l2_codec_h264_dec_register (GstPlugin * plugin,
|
gst_v4l2_codec_h264_dec_register (GstPlugin * plugin,
|
||||||
GstV4l2CodecDevice * device, guint rank)
|
GstV4l2CodecDevice * device, guint rank)
|
||||||
{
|
{
|
||||||
GTypeQuery type_query;
|
gst_v4l2_decoder_register (plugin, GST_TYPE_V4L2_CODEC_H264_DEC,
|
||||||
GTypeInfo type_info = { 0, };
|
(GClassInitFunc) gst_v4l2_codec_h264_dec_subclass_init,
|
||||||
GType subtype;
|
(GInstanceInitFunc) gst_v4l2_codec_h264_dec_subinit,
|
||||||
gchar *type_name;
|
"v4l2sl%sh264dec", device, rank);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "gstv4l2codecallocator.h"
|
#include "gstv4l2codecallocator.h"
|
||||||
#include "gstv4l2codecvp8dec.h"
|
|
||||||
#include "gstv4l2codecpool.h"
|
#include "gstv4l2codecpool.h"
|
||||||
|
#include "gstv4l2codecvp8dec.h"
|
||||||
#include "linux/vp8-ctrls.h"
|
#include "linux/vp8-ctrls.h"
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (v4l2_vp8dec_debug);
|
GST_DEBUG_CATEGORY_STATIC (v4l2_vp8dec_debug);
|
||||||
|
@ -871,39 +871,8 @@ void
|
||||||
gst_v4l2_codec_vp8_dec_register (GstPlugin * plugin,
|
gst_v4l2_codec_vp8_dec_register (GstPlugin * plugin,
|
||||||
GstV4l2CodecDevice * device, guint rank)
|
GstV4l2CodecDevice * device, guint rank)
|
||||||
{
|
{
|
||||||
GTypeQuery type_query;
|
gst_v4l2_decoder_register (plugin, GST_TYPE_V4L2_CODEC_VP8_DEC,
|
||||||
GTypeInfo type_info = { 0, };
|
(GClassInitFunc) gst_v4l2_codec_vp8_dec_subclass_init,
|
||||||
GType subtype;
|
(GInstanceInitFunc) gst_v4l2_codec_vp8_dec_subinit,
|
||||||
gchar *type_name;
|
"v4l2sl%svp8dec", device, rank);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 *
|
GstV4l2Request *
|
||||||
gst_v4l2_decoder_alloc_request (GstV4l2Decoder * self)
|
gst_v4l2_decoder_alloc_request (GstV4l2Decoder * self)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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,
|
void gst_v4l2_decoder_get_property (GObject * object, guint prop_id,
|
||||||
GValue * value, GParamSpec * pspec);
|
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);
|
GstV4l2Request *gst_v4l2_decoder_alloc_request (GstV4l2Decoder * self);
|
||||||
|
|
||||||
void gst_v4l2_request_free (GstV4l2Request * request);
|
void gst_v4l2_request_free (GstV4l2Request * request);
|
||||||
|
|
|
@ -3,8 +3,8 @@ v4l2codecs_sources = [
|
||||||
'gstv4l2codecallocator.c',
|
'gstv4l2codecallocator.c',
|
||||||
'gstv4l2codecdevice.c',
|
'gstv4l2codecdevice.c',
|
||||||
'gstv4l2codech264dec.c',
|
'gstv4l2codech264dec.c',
|
||||||
'gstv4l2codecvp8dec.c',
|
|
||||||
'gstv4l2codecpool.c',
|
'gstv4l2codecpool.c',
|
||||||
|
'gstv4l2codecvp8dec.c',
|
||||||
'gstv4l2decoder.c',
|
'gstv4l2decoder.c',
|
||||||
'gstv4l2format.c',
|
'gstv4l2format.c',
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue