gmerlin

pluginregistry.h

00001 /*****************************************************************
00002  * gmerlin - a general purpose multimedia framework and applications
00003  *
00004  * Copyright (c) 2001 - 2012 Members of the Gmerlin project
00005  * gmerlin-general@lists.sourceforge.net
00006  * http://gmerlin.sourceforge.net
00007  *
00008  * This program is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020  * *****************************************************************/
00021 
00022 #ifndef __BG_PLUGINREGISTRY_H_
00023 #define __BG_PLUGINREGISTRY_H_
00024 
00025 /* Plugin registry */
00026 #include <pthread.h>
00027 
00028 #include <gmerlin/plugin.h>
00029 #include <gmerlin/cfg_registry.h>
00030 
00049 typedef enum
00050   {
00051     BG_PLUGIN_API_GMERLIN = 0, 
00052     BG_PLUGIN_API_LADSPA,      
00053     BG_PLUGIN_API_LV,          
00054     BG_PLUGIN_API_FREI0R,      
00055   } bg_plugin_api_t;
00056 
00061 typedef enum
00062   {
00063     BG_STREAM_AUDIO    = (1<<0),
00064     BG_STREAM_TEXT     = (1<<1),
00065     BG_STREAM_OVERLAY  = (1<<2),
00066     BG_STREAM_VIDEO    = (1<<3),
00067   } bg_stream_type_t;
00068 
00073 typedef struct bg_plugin_info_s  bg_plugin_info_t;
00074 
00079 struct bg_plugin_info_s
00080   {
00081   char * gettext_domain; 
00082   char * gettext_directory; 
00083   
00084   char * name;            
00085   char * long_name;       
00086   char * mimetypes;       
00087   char * extensions;      
00088   char * protocols;       
00089   gavl_codec_id_t * compressions; 
00090 
00091   char * description;     
00092 
00093   char * module_filename; 
00094   long   module_time;     
00095 
00096   bg_plugin_api_t api;    
00097   int index;              
00098   
00099   bg_plugin_type_t type; 
00100   int flags;             
00101   int priority;          
00102   
00103   bg_device_info_t * devices; 
00104   
00105   bg_plugin_info_t * next; 
00106 
00107   bg_parameter_info_t * parameters; 
00108 
00109   
00110   int max_audio_streams; 
00111   int max_video_streams; 
00112   int max_text_streams;
00113   int max_overlay_streams;
00114 
00115   bg_parameter_info_t * audio_parameters; 
00116   bg_parameter_info_t * video_parameters; 
00117 
00118   bg_parameter_info_t * text_parameters; 
00119   bg_parameter_info_t * overlay_parameters; 
00120   
00121   char * cmp_name; 
00122   
00123   };
00124 
00131 typedef struct
00132   {
00133   char ** blacklist; 
00134   int dont_save;            
00135   } bg_plugin_registry_options_t;
00136 
00143 typedef struct bg_plugin_registry_s bg_plugin_registry_t;
00144 
00149 typedef struct bg_plugin_handle_s bg_plugin_handle_t;
00150 
00159 struct bg_plugin_handle_s
00160   {
00161   /* Private members, should not be accessed! */
00162     
00163   void * dll_handle; 
00164   pthread_mutex_t mutex; 
00165   int refcount;          
00166   bg_plugin_registry_t * plugin_reg; 
00167   
00168   /* These are for use by applications */
00169   
00170   const bg_plugin_common_t * plugin; 
00171   bg_plugin_common_t * plugin_nc; 
00172   const bg_plugin_info_t * info; 
00173   void * priv; 
00174 
00175   //  char * location; //!< Applications can save the argument of an open call here
00176   gavl_edl_t * edl; 
00177   };
00178 
00179 /*
00180  *  pluginregistry.c
00181  */
00182 
00191 bg_plugin_registry_t *
00192 bg_plugin_registry_create(bg_cfg_section_t * section);
00193 
00203 bg_plugin_registry_t *
00204 bg_plugin_registry_create_with_options(bg_cfg_section_t * section,
00205                                        const bg_plugin_registry_options_t * opt);
00206 
00207 
00208 
00220 void bg_plugin_registry_scan_devices(bg_plugin_registry_t * plugin_reg,
00221                                      uint32_t type_mask, uint32_t flag_mask);
00222 
00223 
00229 void bg_plugin_registry_destroy(bg_plugin_registry_t * reg);
00230 
00239 int bg_plugin_registry_get_num_plugins(bg_plugin_registry_t * reg,
00240                                        uint32_t type_mask, uint32_t flag_mask);
00253 const bg_plugin_info_t *
00254 bg_plugin_find_by_index(bg_plugin_registry_t * reg, int index,
00255                         uint32_t type_mask, uint32_t flag_mask);
00256 
00264 const bg_plugin_info_t *
00265 bg_plugin_find_by_name(bg_plugin_registry_t * reg, const char * name);
00266 
00277 const bg_plugin_info_t *
00278 bg_plugin_find_by_filename(bg_plugin_registry_t * reg,
00279                            const char * filename, int type_mask);
00280 
00291 const bg_plugin_info_t *
00292 bg_plugin_find_by_mimetype(bg_plugin_registry_t * reg,
00293                            const char * mimetype, int type_mask);
00294 
00295 
00296 
00305 const bg_plugin_info_t *
00306 bg_plugin_find_by_compression(bg_plugin_registry_t * reg,
00307                               gavl_codec_id_t id,
00308                               int typemask, int flagmask);
00309 
00310 
00317 const bg_plugin_info_t *
00318 bg_plugin_find_by_protocol(bg_plugin_registry_t * reg,
00319                            const char * protocol);
00320 
00321 
00322 /* Another method: Return long names as strings (NULL terminated) */
00323 
00338 char ** bg_plugin_registry_get_plugins(bg_plugin_registry_t*reg,
00339                                        uint32_t type_mask,
00340                                        uint32_t flag_mask);
00341 
00346 void bg_plugin_registry_free_plugins(char ** plugins);
00347 
00348 
00349 /*  Finally a version for finding/loading plugins */
00350 
00351 /*
00352  *  info can be NULL
00353  *  If ret is non NULL before the call, the plugin will be unrefed
00354  *
00355  *  Return values are 0 for error, 1 on success
00356  */
00357 
00373 int bg_input_plugin_load(bg_plugin_registry_t * reg,
00374                          const char * location,
00375                          const bg_plugin_info_t * info,
00376                          bg_plugin_handle_t ** ret,
00377                          bg_input_callbacks_t * callbacks, int prefer_edl);
00378 
00395 int bg_input_plugin_load_full(bg_plugin_registry_t * reg,
00396                               const char * location,
00397                               const bg_plugin_info_t * info,
00398                               bg_plugin_handle_t ** ret,
00399                               bg_input_callbacks_t * callbacks, int prefer_edl,
00400                               int * track);
00401 
00402 
00417 int bg_input_plugin_load_edl(bg_plugin_registry_t * reg,
00418                              const gavl_edl_t * edl,
00419                              const bg_plugin_info_t * info,
00420                              bg_plugin_handle_t ** ret,
00421                              bg_input_callbacks_t * callbacks);
00422 
00423 /* Set the supported extensions and mimetypes for a plugin */
00424 
00434 void bg_plugin_registry_set_extensions(bg_plugin_registry_t * reg,
00435                                        const char * plugin_name,
00436                                        const char * extensions);
00437 
00447 void bg_plugin_registry_set_protocols(bg_plugin_registry_t * reg,
00448                                       const char * plugin_name,
00449                                       const char * protocols);
00450 
00460 void bg_plugin_registry_set_priority(bg_plugin_registry_t * reg,
00461                                      const char * plugin_name,
00462                                      int priority);
00463 
00464 
00471 bg_cfg_section_t *
00472 bg_plugin_registry_get_section(bg_plugin_registry_t * reg,
00473                                const char * plugin_name);
00474 
00484 void bg_plugin_registry_set_parameter_info(bg_plugin_registry_t * reg,
00485                                            uint32_t type_mask,
00486                                            uint32_t flag_mask,
00487                                            bg_parameter_info_t * ret);
00488 
00498 void bg_plugin_registry_set_parameter_info_input(bg_plugin_registry_t * reg,
00499                                                  uint32_t type_mask,
00500                                                  uint32_t flag_mask,
00501                                                  bg_parameter_info_t * ret);
00502 
00503 
00512 void bg_plugin_registry_set_parameter_input(void * data, const char * name,
00513                                             const bg_parameter_value_t * val);
00514 
00515 int bg_plugin_registry_get_parameter_input(void * data, const char * name,
00516                                             bg_parameter_value_t * val);
00517 
00518 
00535 bg_parameter_info_t *
00536 bg_plugin_registry_create_encoder_parameters(bg_plugin_registry_t * reg,
00537                                              uint32_t stream_type_mask,
00538                                              uint32_t flag_mask,
00539                                              int stream_params);
00540 
00552 bg_parameter_info_t *
00553 bg_plugin_registry_create_compressor_parameters(bg_plugin_registry_t * reg,
00554                                                 uint32_t flag_mask);
00555 
00568 void
00569 bg_plugin_registry_set_compressor_parameter(bg_plugin_registry_t * plugin_reg,
00570                                             bg_plugin_handle_t ** plugin,
00571                                             const char * name,
00572                                             const bg_parameter_value_t * val);
00573 
00584 gavl_codec_id_t
00585 bg_plugin_registry_get_compressor_id(bg_plugin_registry_t * plugin_reg,
00586                                      bg_cfg_section_t * section);
00587   
00588 
00598 const char * 
00599 bg_encoder_section_get_plugin(bg_plugin_registry_t * plugin_reg,
00600                               bg_cfg_section_t * s,
00601                               bg_stream_type_t stream_type,
00602                               int stream_mask);
00603 
00615 void
00616 bg_encoder_section_get_plugin_config(bg_plugin_registry_t * plugin_reg,
00617                                      bg_cfg_section_t * s,
00618                                      bg_stream_type_t stream_type,
00619                                      int stream_mask,
00620                                      bg_cfg_section_t ** section_ret,
00621                                      const bg_parameter_info_t ** params_ret);
00622 
00633 void
00634 bg_encoder_section_get_stream_config(bg_plugin_registry_t * plugin_reg,
00635                                      bg_cfg_section_t * s,
00636                                      bg_stream_type_t stream_type,
00637                                      int stream_mask,
00638                                      bg_cfg_section_t ** section_ret,
00639                                      const bg_parameter_info_t ** params_ret);
00640 
00641 
00651 bg_cfg_section_t *
00652 bg_encoder_section_get_from_registry(bg_plugin_registry_t * plugin_reg,
00653                                      const bg_parameter_info_t * parameters,
00654                                      uint32_t type_mask,
00655                                      uint32_t flag_mask);
00656 
00667 void
00668 bg_encoder_section_store_in_registry(bg_plugin_registry_t * plugin_reg,
00669                                      bg_cfg_section_t * s,
00670                                      const bg_parameter_info_t * parameters,
00671                                      uint32_t type_mask,
00672                                      uint32_t flag_mask);
00673 
00674 
00686 void bg_plugin_registry_set_default(bg_plugin_registry_t * reg,
00687                                     bg_plugin_type_t type, uint32_t flag_mask,
00688                                     const char * plugin_name);
00689 
00699 const bg_plugin_info_t * bg_plugin_registry_get_default(bg_plugin_registry_t * reg,
00700                                                         bg_plugin_type_t type, uint32_t flag_mask);
00701 
00702 
00725 void bg_plugin_registry_set_encode_audio_to_video(bg_plugin_registry_t * reg,
00726                                                   int audio_to_video);
00727 
00734 int bg_plugin_registry_get_encode_audio_to_video(bg_plugin_registry_t * reg);
00735 
00742 void bg_plugin_registry_set_encode_text_to_video(bg_plugin_registry_t * reg,
00743                                                           int text_to_video);
00744 
00751 int bg_plugin_registry_get_encode_text_to_video(bg_plugin_registry_t * reg);
00752 
00759 void bg_plugin_registry_set_encode_overlay_to_video(bg_plugin_registry_t * reg,
00760                                                              int overlay_to_video);
00761 
00767 int bg_plugin_registry_get_encode_overlay_to_video(bg_plugin_registry_t * reg);
00768 
00775 void bg_plugin_registry_set_encode_pp(bg_plugin_registry_t * reg,
00776                                       int encode_pp);
00777 
00783 int bg_plugin_registry_get_encode_pp(bg_plugin_registry_t * reg);
00784 
00791 void bg_plugin_registry_set_visualize(bg_plugin_registry_t * reg,
00792                                        int enable);
00793 
00800 int bg_plugin_registry_get_visualize(bg_plugin_registry_t * reg);
00801 
00802 
00811 void bg_plugin_registry_add_device(bg_plugin_registry_t * reg,
00812                                    const char * plugin_name,
00813                                    const char * device,
00814                                    const char * name);
00815 
00828 void bg_plugin_registry_set_device_name(bg_plugin_registry_t * reg,
00829                                         const char * plugin_name,
00830                                         const char * device,
00831                                         const char * name);
00832 
00833 /* Rescan the available devices */
00834 
00844 void bg_plugin_registry_find_devices(bg_plugin_registry_t * reg,
00845                                      const char * plugin_name);
00846 
00858 void bg_plugin_registry_remove_device(bg_plugin_registry_t * reg,
00859                                       const char * plugin_name,
00860                                       const char * device,
00861                                       const char * name);
00862 
00875 gavl_video_frame_t * bg_plugin_registry_load_image(bg_plugin_registry_t * reg,
00876                                                    const char * filename,
00877                                                    gavl_video_format_t * format,
00878                                                    gavl_metadata_t * m);
00879 
00880 /* Same as above for writing. Does implicit pixelformat conversion */
00881 
00891 void
00892 bg_plugin_registry_save_image(bg_plugin_registry_t * reg,
00893                               const char * filename,
00894                               gavl_video_frame_t * frame,
00895                               const gavl_video_format_t * format,
00896                               const gavl_metadata_t * m);
00897 
00898 
00910 int bg_get_thumbnail(const char * gml,
00911                      bg_plugin_registry_t * plugin_reg,
00912                      char ** thumbnail_filename_ret,
00913                      gavl_video_frame_t ** frame_ret,
00914                      gavl_video_format_t * format_ret);
00915 
00927 char * bg_make_thumbnail(bg_plugin_registry_t * plugin_reg,
00928                          gavl_video_frame_t * in_frame,
00929                          gavl_video_format_t * input_format,
00930                          int max_width, int max_height,
00931                          const char * out_file_base,
00932                          const char * mimetype);
00933 
00934 
00935 /*
00936  *  These are the actual loading/unloading functions
00937  *  (loader.c)
00938  */
00939 
00940 /* Load a plugin and return handle with reference count of 1 */
00941 
00950 bg_plugin_handle_t * bg_plugin_load(bg_plugin_registry_t * reg,
00951                                     const bg_plugin_info_t * info);
00952 
00963 bg_plugin_handle_t * bg_ov_plugin_load(bg_plugin_registry_t * reg,
00964                                        const bg_plugin_info_t * info,
00965                                        const char * window_id);
00966 
00971 void bg_plugin_lock(void * h);
00972 
00977 void bg_plugin_unlock(void * h);
00978 
00979 /* Reference counting for input plugins */
00980 
00985 void bg_plugin_ref(bg_plugin_handle_t * h);
00986 
00987 /* Plugin will be unloaded when refcount is zero */
00988 
00996 void bg_plugin_unref(bg_plugin_handle_t * h);
00997 
01009 void bg_plugin_unref_nolock(bg_plugin_handle_t * h);
01010 
01019 bg_plugin_info_t * bg_plugin_info_create(const bg_plugin_common_t * plugin);
01020 
01029 bg_plugin_handle_t * bg_plugin_handle_create();
01030 
01039 int bg_plugin_registry_changed(bg_plugin_registry_t * reg);
01040 
01045 void bg_plugin_save_metadata(bg_plugin_handle_t * h);
01046 
01047 #endif // __BG_PLUGINREGISTRY_H_