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
4341typedef struct
4442{
45- GModule * module ;
43+ const gchar * loader ;
4644 GstCaps * caps ;
4745 GstRank rank ;
46+ MakeImporter make_importer ;
4847} GstClapperImporterData ;
4948
5049static void
@@ -57,29 +56,22 @@ gst_clapper_importer_data_free (GstClapperImporterData *data)
5756}
5857
5958static 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-
20989static gint
21090_sort_importers_cb (gconstpointer a , gconstpointer b )
21191{
@@ -220,24 +100,33 @@ _sort_importers_cb (gconstpointer a, gconstpointer b)
220100static 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
376265finish :
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 );
0 commit comments