gstreamer的plugin注册流程

以jpeg为例:Gstjpeg.c,Gstjpegdec.c,Gstjpegend.c文件,再加上jpeg的解码库(我用的是jpeg-7),最终会生成libjpeg.so。所有的plugin编译生成的库,都在一个目录下。

static gboolean  gst_registry_scan_path_level(GstRegistryScanContext * context, const gchar * path, int level) //path就是plugin库所在的目录

{

         GDir *dir;
         const gchar *dirent;
         gchar *filename;
         GstPlugin *plugin;

         GStatBuf file_status;

 

         dir = g_dir_open(paht,0,NULL);

         while(dirent = g_dir_read_name(dir))

         {

                  filename = g_build_filename(path, dirent, NULL);

                  g_stat (filename, &file_status);

                  /* plug-ins are considered unique by basename; if the given name
                  * was already seen by the registry, we ignore it */

                  plugin = gst_registry_lookup_bn (context->registry, dirent);              

                  if(plugin==NULL)

                  {

                            changed = gst_registry_scan_plugin_file(context, filename, file_status.st_size, file_status.st_mtime);

                  }  

                  g_free (filename);  

         }

          g_dir_close (dir);

}

 

static gboolean gst_registry_scan_plugin_file(GstRegistryScanContext * context,const gchar * filename, off_t file_size, time_t file_mtime) 

{

              GstPlugin *newplugin = NULL;

              newplugin = gst_plugin_load_file(filename, NULL);

}

GstPlugin * gst_plugin_load_file (const gchar * filename, GError ** error)

{

           GstRegistry *registry;

           GModuleFlags flags;

           GModule *module;

           gboolean ret;
           gpointer ptr;

           GstPluginDesc *desc;

          gboolean new_plugin = TRUE;

          GstPlugin *plugin;

 

           registry = gst_registry_get();

           flags = G_MODULE_BIND_LOCAL;

           module = g_module_open(filename, flags);

           ret = g_module_symbol (module, "gst_plugin_desc", &ptr);

          desc = (GstPluginDesc *) ptr;

        

          if (new_plugin) {
                  plugin = g_object_newv(GST_TYPE_PLUGIN, 0, NULL);
                  plugin->file_mtime = file_status.st_mtime;
                  plugin->file_size = file_status.st_size;
                  plugin->filename = g_strdup (filename);
                 plugin->basename = g_path_get_basename (filename);
          }

          plugin->module = module;
          plugin->orig_desc = desc;

         gst_plugin_register_func(plugin, plugin->orig_desc, NULL)

}

 

 

static GstPlugin *gst_plugin_register_func(GstPlugin * plugin, const GstPluginDesc * desc,gpointer user_data)

{

            gst_plugin_check_version(desc->major_version, desc->minor_version)

            gst_plugin_check_license(desc->license)

            gst_plugin_desc_copy (&plugin->desc, desc);

            if (plugin->module)
                              g_module_make_resident(plugin->module);

            (desc->plugin_init) (plugin)               //这个就是每个plugin都会注册的那个函数

}

你可能感兴趣的:(gstreamer)