Skip to content

Commit 1f3d616

Browse files
committed
gst-plugin: Always include importers statically
I don't see the point of being able to load them dynamically.
1 parent daadabb commit 1f3d616

File tree

9 files changed

+73
-234
lines changed

9 files changed

+73
-234
lines changed

src/lib/gst/plugin/gstclapperimporterloader.c

Lines changed: 32 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#include "config.h"
2121
#endif
2222

23-
#include <gmodule.h>
24-
2523
#include "gstclapperimporterloader.h"
2624
#include "gstclapperimporter.h"
2725
#include "gstclappercontexthandler.h"
@@ -42,9 +40,10 @@ typedef GstCaps* (* MakeCaps) (gboolean is_template, GstRank *rank, GPtrArray *c
4240

4341
typedef struct
4442
{
45-
GModule *module;
43+
const gchar *loader;
4644
GstCaps *caps;
4745
GstRank rank;
46+
MakeImporter make_importer;
4847
} GstClapperImporterData;
4948

5049
static void
@@ -57,29 +56,22 @@ gst_clapper_importer_data_free (GstClapperImporterData *data)
5756
}
5857

5958
static GstClapperImporterData *
60-
_obtain_importer_data (GModule *module, gboolean is_template, GPtrArray *context_handlers)
59+
_obtain_importer_data (const gchar *name, MakeCaps make_caps, MakeImporter make_importer, gboolean is_template, GPtrArray *context_handlers)
6160
{
62-
MakeCaps make_caps;
6361
GstClapperImporterData *data;
6462

65-
GST_DEBUG ("Found importer: %s", g_module_name (module));
66-
67-
if (!g_module_symbol (module, "make_caps", (gpointer *) &make_caps)
68-
|| make_caps == NULL) {
69-
GST_WARNING ("Make caps function missing in importer");
70-
return NULL;
71-
}
63+
GST_DEBUG ("Found importer: %s", name);
7264

7365
data = g_new0 (GstClapperImporterData, 1);
74-
data->module = module;
66+
data->loader = name;
7567
data->caps = make_caps (is_template, &data->rank, context_handlers);
68+
data->make_importer = make_importer;
7669

7770
GST_TRACE ("Created importer data: %" GST_PTR_FORMAT, data);
7871

7972
if (G_UNLIKELY (!data->caps)) {
8073
if (!is_template) {
81-
GST_ERROR ("Invalid importer without caps: %s",
82-
g_module_name (data->module));
74+
GST_ERROR ("Invalid importer without caps: %s", name);
8375
} else {
8476
/* When importer cannot be actually used, due to e.g. unsupported HW */
8577
GST_DEBUG ("No actual caps returned from importer");
@@ -94,118 +86,6 @@ _obtain_importer_data (GModule *module, gboolean is_template, GPtrArray *context
9486
return data;
9587
}
9688

97-
static GstClapperImporter *
98-
_obtain_importer_internal (GModule *module, GPtrArray *context_handlers)
99-
{
100-
MakeImporter make_importer;
101-
GstClapperImporter *importer;
102-
103-
if (!g_module_symbol (module, "make_importer", (gpointer *) &make_importer)
104-
|| make_importer == NULL) {
105-
GST_WARNING ("Make function missing in importer");
106-
return NULL;
107-
}
108-
109-
importer = make_importer (context_handlers);
110-
GST_TRACE ("Created importer: %" GST_PTR_FORMAT, importer);
111-
112-
return importer;
113-
}
114-
115-
static gpointer
116-
_obtain_available_modules_once (G_GNUC_UNUSED gpointer data)
117-
{
118-
GPtrArray *modules;
119-
GFile *dir = NULL;
120-
GFileEnumerator *dir_enum;
121-
GError *error = NULL;
122-
const gchar *env_path = g_getenv ("CLAPPER_SINK_IMPORTER_PATH");
123-
124-
GST_INFO ("Preparing modules");
125-
126-
modules = g_ptr_array_new ();
127-
128-
#ifdef G_OS_WIN32
129-
if (!env_path || env_path[0] == '\0') {
130-
gchar *win_base_dir, *dir_path;
131-
132-
win_base_dir = g_win32_get_package_installation_directory_of_module (
133-
_importer_dll_handle);
134-
dir_path = g_build_filename (win_base_dir,
135-
"lib", "clapper-0.0", "gst", "plugin", "importers", NULL);
136-
GST_INFO ("Win32 importers path: %s", dir_path);
137-
138-
dir = g_file_new_for_path (dir_path);
139-
140-
g_free (win_base_dir);
141-
g_free (dir_path);
142-
}
143-
#endif
144-
145-
if (!dir) {
146-
const gchar *imp_path = (env_path && env_path[0] != '\0')
147-
? env_path : CLAPPER_SINK_IMPORTER_PATH;
148-
dir = g_file_new_for_path (imp_path);
149-
}
150-
151-
if ((dir_enum = g_file_enumerate_children (dir,
152-
G_FILE_ATTRIBUTE_STANDARD_NAME,
153-
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error))) {
154-
gchar *dir_path = g_file_get_path (dir);
155-
156-
while (TRUE) {
157-
GFileInfo *info = NULL;
158-
GModule *module;
159-
gchar *module_path;
160-
const gchar *module_name;
161-
162-
if (!g_file_enumerator_iterate (dir_enum, &info,
163-
NULL, NULL, &error) || !info)
164-
break;
165-
166-
module_name = g_file_info_get_name (info);
167-
168-
if (!g_str_has_suffix (module_name, G_MODULE_SUFFIX))
169-
continue;
170-
171-
module_path = g_module_build_path (dir_path, module_name);
172-
module = g_module_open (module_path, G_MODULE_BIND_LAZY);
173-
g_free (module_path);
174-
175-
if (!module) {
176-
GST_WARNING ("Could not read module: %s, reason: %s",
177-
module_name, g_module_error ());
178-
continue;
179-
}
180-
181-
GST_INFO ("Found module: %s", module_name);
182-
g_ptr_array_add (modules, module);
183-
}
184-
185-
g_object_unref (dir_enum);
186-
g_free (dir_path);
187-
}
188-
189-
g_object_unref (dir);
190-
191-
if (error) {
192-
GST_ERROR ("Could not load module, reason: %s",
193-
(error->message) ? error->message : "unknown");
194-
g_error_free (error);
195-
}
196-
197-
return modules;
198-
}
199-
200-
static const GPtrArray *
201-
gst_clapper_importer_loader_get_available_modules (void)
202-
{
203-
static GOnce once = G_ONCE_INIT;
204-
205-
g_once (&once, _obtain_available_modules_once, NULL);
206-
return (const GPtrArray *) once.retval;
207-
}
208-
20989
static gint
21090
_sort_importers_cb (gconstpointer a, gconstpointer b)
21191
{
@@ -220,24 +100,33 @@ _sort_importers_cb (gconstpointer a, gconstpointer b)
220100
static GPtrArray *
221101
_obtain_importers (gboolean is_template, GPtrArray *context_handlers)
222102
{
223-
const GPtrArray *modules;
224103
GPtrArray *importers;
225-
guint i;
226104

227105
GST_DEBUG ("Checking %s importers",
228106
(is_template) ? "available" : "usable");
229107

230-
modules = gst_clapper_importer_loader_get_available_modules ();
231108
importers = g_ptr_array_new_with_free_func (
232109
(GDestroyNotify) gst_clapper_importer_data_free);
233110

234-
for (i = 0; i < modules->len; i++) {
235-
GModule *module = g_ptr_array_index (modules, i);
236-
GstClapperImporterData *data;
111+
#define _append_importer_data(importer) \
112+
{ \
113+
GstClapperImporterData *data; \
114+
extern GstClapperImporter* gst_clapper_##importer##_make_importer (GPtrArray *context_handlers); \
115+
extern GstCaps* gst_clapper_##importer##_make_caps (gboolean is_template, GstRank *rank, GPtrArray *context_handlers); \
116+
data = _obtain_importer_data (#importer, gst_clapper_##importer##_make_caps, gst_clapper_##importer##_make_importer, is_template, context_handlers); \
117+
if (data) \
118+
g_ptr_array_add (importers, data); \
119+
}
237120

238-
if ((data = _obtain_importer_data (module, is_template, context_handlers)))
239-
g_ptr_array_add (importers, data);
240-
}
121+
#ifdef CLAPPER_GST_HAS_GLIMPORTER
122+
_append_importer_data (glimporter)
123+
#endif
124+
#ifdef CLAPPER_GST_HAS_GLUPLOADER
125+
_append_importer_data (gluploader)
126+
#endif
127+
#ifdef CLAPPER_GST_HAS_RAWIMPORTER
128+
_append_importer_data (rawimporter)
129+
#endif
241130

242131
g_ptr_array_sort (importers, (GCompareFunc) _sort_importers_cb);
243132

@@ -347,23 +236,23 @@ gst_clapper_importer_loader_find_importer_for_caps (GstClapperImporterLoader *se
347236
GST_DEBUG_OBJECT (self, "Requested importer for caps: %" GST_PTR_FORMAT, caps);
348237
data = _get_importer_data_for_caps (self->importers, caps);
349238

350-
GST_LOG_OBJECT (self, "Old importer path: %s, new path: %s",
351-
(self->last_module) ? g_module_name (self->last_module) : NULL,
352-
(data) ? g_module_name (data->module) : NULL);
239+
GST_LOG_OBJECT (self, "Old importer: %s, new: %s",
240+
self->last_loader ? self->last_loader : NULL,
241+
data ? data->loader : NULL);
353242

354243
if (G_UNLIKELY (!data)) {
355244
gst_clear_object (importer);
356245
goto finish;
357246
}
358247

359-
if (*importer && (self->last_module == data->module)) {
248+
if (*importer && (self->last_loader == data->loader)) {
360249
GST_DEBUG_OBJECT (self, "No importer change");
361250

362251
gst_clapper_importer_set_caps (*importer, caps);
363252
goto finish;
364253
}
365254

366-
found_importer = _obtain_importer_internal (data->module, self->context_handlers);
255+
found_importer = data->make_importer (self->context_handlers);
367256
gst_clear_object (importer);
368257

369258
if (!found_importer)
@@ -374,8 +263,8 @@ gst_clapper_importer_loader_find_importer_for_caps (GstClapperImporterLoader *se
374263
*importer = found_importer;
375264

376265
finish:
377-
self->last_module = (*importer && data)
378-
? data->module
266+
self->last_loader = (*importer && data)
267+
? data->loader
379268
: NULL;
380269

381270
GST_OBJECT_UNLOCK (self);

src/lib/gst/plugin/gstclapperimporterloader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct _GstClapperImporterLoader
3434
{
3535
GstObject parent;
3636

37-
GModule *last_module;
37+
const gchar *last_loader;
3838

3939
GPtrArray *importers;
4040
GPtrArray *context_handlers;

src/lib/gst/plugin/gstplugin.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,11 @@
2020
#include "config.h"
2121
#endif
2222

23-
#include <gmodule.h>
24-
2523
#include "gstclappersink.h"
2624

2725
static gboolean
2826
plugin_init (GstPlugin *plugin)
2927
{
30-
if (!g_module_supported ())
31-
return FALSE;
32-
33-
gst_plugin_add_dependency_simple (plugin,
34-
NULL, CLAPPER_SINK_IMPORTER_PATH, NULL,
35-
GST_PLUGIN_DEPENDENCY_FLAG_NONE);
36-
3728
return GST_ELEMENT_REGISTER (clappersink, plugin);
3829
}
3930

src/lib/gst/plugin/handlers/gl/meson.build

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,11 @@ endforeach
126126

127127
if build_gl_ch
128128
gst_clapper_gl_ch_dep = declare_dependency(
129-
link_with: library('gstclapperglcontexthandler',
129+
link_with: static_library('gstclapperglcontexthandler',
130130
'gstclapperglcontexthandler.c',
131131
c_args: gst_clapper_plugin_args,
132132
include_directories: gst_plugin_conf_inc,
133133
dependencies: gst_plugin_gl_ch_deps,
134-
version: meson.project_version(),
135-
install: true,
136134
),
137135
include_directories: gst_plugin_conf_inc,
138136
dependencies: gst_plugin_gl_ch_deps,

src/lib/gst/plugin/importers/gstclapperglimporter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ gst_clapper_gl_importer_class_init (GstClapperGLImporterClass *klass)
9999
}
100100

101101
GstClapperImporter *
102-
make_importer (GPtrArray *context_handlers)
102+
gst_clapper_glimporter_make_importer (GPtrArray *context_handlers)
103103
{
104104
GstClapperGLImporter *self;
105105
GstClapperContextHandler *handler;
@@ -117,7 +117,7 @@ make_importer (GPtrArray *context_handlers)
117117
}
118118

119119
GstCaps *
120-
make_caps (gboolean is_template, GstRank *rank, GPtrArray *context_handlers)
120+
gst_clapper_glimporter_make_caps (gboolean is_template, GstRank *rank, GPtrArray *context_handlers)
121121
{
122122
*rank = GST_RANK_SECONDARY;
123123

src/lib/gst/plugin/importers/gstclappergluploader.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ gst_clapper_gl_uploader_class_init (GstClapperGLUploaderClass *klass)
234234
}
235235

236236
GstClapperImporter *
237-
make_importer (GPtrArray *context_handlers)
237+
gst_clapper_gluploader_make_importer (GPtrArray *context_handlers)
238238
{
239239
GstClapperGLUploader *self;
240240
GstClapperContextHandler *handler;
@@ -300,7 +300,7 @@ _make_actual_caps (GstClapperGLContextHandler *gl_handler)
300300
}
301301

302302
GstCaps *
303-
make_caps (gboolean is_template, GstRank *rank, GPtrArray *context_handlers)
303+
gst_clapper_gluploader_make_caps (gboolean is_template, GstRank *rank, GPtrArray *context_handlers)
304304
{
305305
GstCaps *caps = NULL;
306306

src/lib/gst/plugin/importers/gstclapperrawimporter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ gst_clapper_raw_importer_class_init (GstClapperRawImporterClass *klass)
8282
}
8383

8484
GstClapperImporter *
85-
make_importer (GPtrArray *context_handlers)
85+
gst_clapper_rawimporter_make_importer (GPtrArray *context_handlers)
8686
{
8787
return g_object_new (GST_TYPE_CLAPPER_RAW_IMPORTER, NULL);
8888
}
8989

9090
GstCaps *
91-
make_caps (gboolean is_template, GstRank *rank, GPtrArray *context_handlers)
91+
gst_clapper_rawimporter_make_caps (gboolean is_template, GstRank *rank, GPtrArray *context_handlers)
9292
{
9393
*rank = GST_RANK_MARGINAL;
9494

0 commit comments

Comments
 (0)