plugin: importers: Support different template and actual caps

Make a template caps during class_init. It will be used for e.g. gst-inspect-1.0, while do and use an actual caps that current HW can handle.
This commit is contained in:
Rafał Dzięgiel
2022-05-25 20:30:56 +02:00
parent 5b89879031
commit 3f7ba0674f
7 changed files with 47 additions and 30 deletions

View File

@@ -36,7 +36,8 @@ G_BEGIN_DECLS
#define GST_CLAPPER_IMPORTER_DEFINE(camel,lower,type) \ #define GST_CLAPPER_IMPORTER_DEFINE(camel,lower,type) \
G_DEFINE_TYPE (camel, lower, type) \ G_DEFINE_TYPE (camel, lower, type) \
G_MODULE_EXPORT GstClapperImporter *make_importer (void); \ G_MODULE_EXPORT GstClapperImporter *make_importer (void); \
G_MODULE_EXPORT GstCaps *make_caps (GstRank *rank, GStrv *context_types); G_MODULE_EXPORT GstCaps *make_caps (gboolean is_template, \
GstRank *rank, GStrv *context_types);
typedef struct _GstClapperImporter GstClapperImporter; typedef struct _GstClapperImporter GstClapperImporter;
typedef struct _GstClapperImporterClass GstClapperImporterClass; typedef struct _GstClapperImporterClass GstClapperImporterClass;

View File

@@ -33,7 +33,7 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
G_DEFINE_TYPE (GstClapperImporterLoader, gst_clapper_importer_loader, GST_TYPE_OBJECT); G_DEFINE_TYPE (GstClapperImporterLoader, gst_clapper_importer_loader, GST_TYPE_OBJECT);
typedef GstClapperImporter* (* MakeImporter) (void); typedef GstClapperImporter* (* MakeImporter) (void);
typedef GstCaps* (* MakeCaps) (GstRank *rank, GStrv *context_types); typedef GstCaps* (* MakeCaps) (gboolean is_template, GstRank *rank, GStrv *context_types);
typedef struct typedef struct
{ {
@@ -54,7 +54,7 @@ gst_clapper_importer_data_free (GstClapperImporterData *data)
} }
static GstClapperImporterData * static GstClapperImporterData *
_obtain_importer_data (GModule *module) _obtain_importer_data (GModule *module, gboolean is_template)
{ {
MakeCaps make_caps; MakeCaps make_caps;
GstClapperImporterData *data; GstClapperImporterData *data;
@@ -67,7 +67,7 @@ _obtain_importer_data (GModule *module)
data = g_new0 (GstClapperImporterData, 1); data = g_new0 (GstClapperImporterData, 1);
data->module = module; data->module = module;
data->caps = make_caps (&data->rank, &data->context_types); data->caps = make_caps (is_template, &data->rank, &data->context_types);
GST_TRACE ("Created importer data: %" GST_PTR_FORMAT, data); GST_TRACE ("Created importer data: %" GST_PTR_FORMAT, data);
@@ -183,7 +183,7 @@ _sort_importers_cb (gconstpointer a, gconstpointer b)
} }
static GPtrArray * static GPtrArray *
gst_clapper_importer_loader_obtain_available_importers (void) _obtain_available_importers (gboolean is_template)
{ {
const GPtrArray *modules; const GPtrArray *modules;
GPtrArray *importers; GPtrArray *importers;
@@ -199,7 +199,7 @@ gst_clapper_importer_loader_obtain_available_importers (void)
GModule *module = g_ptr_array_index (modules, i); GModule *module = g_ptr_array_index (modules, i);
GstClapperImporterData *data; GstClapperImporterData *data;
if ((data = _obtain_importer_data (module))) if ((data = _obtain_importer_data (module, is_template)))
g_ptr_array_add (importers, data); g_ptr_array_add (importers, data);
} }
@@ -210,13 +210,33 @@ gst_clapper_importer_loader_obtain_available_importers (void)
return importers; return importers;
} }
GstClapperImporterLoader *
gst_clapper_importer_loader_new (void)
{
return g_object_new (GST_TYPE_CLAPPER_IMPORTER_LOADER, NULL);
}
static GstCaps *
_make_caps_for_importers (const GPtrArray *importers)
{
GstCaps *caps = gst_caps_new_empty ();
guint i;
for (i = 0; i < importers->len; i++) {
GstClapperImporterData *data = g_ptr_array_index (importers, i);
gst_caps_append (caps, gst_caps_ref (data->caps));
}
return caps;
}
GstPadTemplate * GstPadTemplate *
gst_clapper_importer_loader_make_sink_pad_template (void) gst_clapper_importer_loader_make_sink_pad_template (void)
{ {
GPtrArray *importers; GPtrArray *importers;
GstCaps *sink_caps; GstCaps *caps;
GstPadTemplate *templ; GstPadTemplate *templ;
guint i;
/* This is only called once from sink class init function */ /* This is only called once from sink class init function */
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "clapperimporterloader", 0, GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "clapperimporterloader", 0,
@@ -224,32 +244,25 @@ gst_clapper_importer_loader_make_sink_pad_template (void)
GST_DEBUG ("Making sink pad template"); GST_DEBUG ("Making sink pad template");
importers = gst_clapper_importer_loader_obtain_available_importers (); importers = _obtain_available_importers (TRUE);
sink_caps = gst_caps_new_empty (); caps = _make_caps_for_importers (importers);
for (i = 0; i < importers->len; i++) {
GstClapperImporterData *data = g_ptr_array_index (importers, i);
gst_caps_append (sink_caps, gst_caps_ref (data->caps));
}
g_ptr_array_unref (importers); g_ptr_array_unref (importers);
if (G_UNLIKELY (gst_caps_is_empty (sink_caps))) if (G_UNLIKELY (gst_caps_is_empty (caps)))
gst_caps_append (sink_caps, gst_caps_new_any ()); gst_caps_append (caps, gst_caps_new_any ());
templ = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, sink_caps); templ = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps);
gst_caps_unref (sink_caps); gst_caps_unref (caps);
GST_TRACE ("Created sink pad template"); GST_TRACE ("Created sink pad template");
return templ; return templ;
} }
GstClapperImporterLoader * GstCaps *
gst_clapper_importer_loader_new (void) gst_clapper_importer_loader_make_actual_caps (GstClapperImporterLoader *self)
{ {
return g_object_new (GST_TYPE_CLAPPER_IMPORTER_LOADER, NULL); return _make_caps_for_importers (self->importers);
} }
static const GstClapperImporterData * static const GstClapperImporterData *
@@ -389,7 +402,7 @@ gst_clapper_importer_loader_constructed (GObject *object)
{ {
GstClapperImporterLoader *self = GST_CLAPPER_IMPORTER_LOADER_CAST (object); GstClapperImporterLoader *self = GST_CLAPPER_IMPORTER_LOADER_CAST (object);
self->importers = gst_clapper_importer_loader_obtain_available_importers (); self->importers = _obtain_available_importers (FALSE);
GST_CALL_PARENT (G_OBJECT_CLASS, constructed, (object)); GST_CALL_PARENT (G_OBJECT_CLASS, constructed, (object));
} }

View File

@@ -42,6 +42,8 @@ GstClapperImporterLoader * gst_clapper_importer_loader_new
GstPadTemplate * gst_clapper_importer_loader_make_sink_pad_template (void); GstPadTemplate * gst_clapper_importer_loader_make_sink_pad_template (void);
GstCaps * gst_clapper_importer_loader_make_actual_caps (GstClapperImporterLoader *loader);
gboolean gst_clapper_importer_loader_find_importer_for_caps (GstClapperImporterLoader *loader, GstCaps *caps, GstClapperImporter **importer); gboolean gst_clapper_importer_loader_find_importer_for_caps (GstClapperImporterLoader *loader, GstCaps *caps, GstClapperImporter **importer);
gboolean gst_clapper_importer_loader_find_importer_for_context_query (GstClapperImporterLoader *loader, GstQuery *query, GstClapperImporter **importer); gboolean gst_clapper_importer_loader_find_importer_for_context_query (GstClapperImporterLoader *loader, GstQuery *query, GstClapperImporter **importer);

View File

@@ -695,9 +695,10 @@ gst_clapper_sink_get_times (GstBaseSink *bsink, GstBuffer *buffer,
static GstCaps * static GstCaps *
gst_clapper_sink_get_caps (GstBaseSink *bsink, GstCaps *filter) gst_clapper_sink_get_caps (GstBaseSink *bsink, GstCaps *filter)
{ {
GstClapperSink *self = GST_CLAPPER_SINK_CAST (bsink);
GstCaps *result, *tmp; GstCaps *result, *tmp;
tmp = gst_pad_get_pad_template_caps (GST_BASE_SINK_PAD (bsink)); tmp = gst_clapper_importer_loader_make_actual_caps (self->loader);
if (filter) { if (filter) {
GST_DEBUG ("Intersecting with filter caps: %" GST_PTR_FORMAT, filter); GST_DEBUG ("Intersecting with filter caps: %" GST_PTR_FORMAT, filter);

View File

@@ -61,7 +61,7 @@ make_importer (void)
} }
GstCaps * GstCaps *
make_caps (GstRank *rank, GStrv *context_types) make_caps (gboolean is_template, GstRank *rank, GStrv *context_types)
{ {
*rank = GST_RANK_SECONDARY; *rank = GST_RANK_SECONDARY;
*context_types = gst_clapper_gl_base_importer_make_gl_context_types (); *context_types = gst_clapper_gl_base_importer_make_gl_context_types ();

View File

@@ -265,12 +265,12 @@ _update_glx_caps_on_main (GstCaps *caps)
#endif #endif
GstCaps * GstCaps *
make_caps (GstRank *rank, GStrv *context_types) make_caps (gboolean is_template, GstRank *rank, GStrv *context_types)
{ {
GstCaps *caps = gst_gl_upload_get_input_template_caps (); GstCaps *caps = gst_gl_upload_get_input_template_caps ();
#if GST_CLAPPER_GL_BASE_IMPORTER_HAVE_X11_GLX #if GST_CLAPPER_GL_BASE_IMPORTER_HAVE_X11_GLX
if (!(! !gst_gtk_invoke_on_main ((GThreadFunc) (GCallback) if (!is_template && !(! !gst_gtk_invoke_on_main ((GThreadFunc) (GCallback)
_update_glx_caps_on_main, caps))) _update_glx_caps_on_main, caps)))
gst_clear_caps (&caps); gst_clear_caps (&caps);
#endif #endif

View File

@@ -97,7 +97,7 @@ make_importer (void)
} }
GstCaps * GstCaps *
make_caps (GstRank *rank, GStrv *context_types) make_caps (gboolean is_template, GstRank *rank, GStrv *context_types)
{ {
*rank = GST_RANK_MARGINAL; *rank = GST_RANK_MARGINAL;