plugin.h

00001 /*****************************************************************
00002  * gmerlin - a general purpose multimedia framework and applications
00003  *
00004  * Copyright (c) 2001 - 2008 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_PLUGIN_H_
00023 #define __BG_PLUGIN_H_
00024 
00025 #include <gavl/gavl.h>
00026 #include "parameter.h"
00027 #include "streaminfo.h"
00028 #include "accelerator.h"
00029 #include "edl.h"
00030 
00074 typedef int (*bg_read_audio_func_t)(void * priv, gavl_audio_frame_t* frame, int stream,
00075                                   int num_samples);
00076 
00088 typedef int (*bg_read_video_func_t)(void * priv, gavl_video_frame_t* frame, int stream);
00089 
00099 #define BG_PLUGIN_REMOVABLE    (1<<0)  
00100 #define BG_PLUGIN_FILE         (1<<1)  
00101 #define BG_PLUGIN_RECORDER     (1<<2)  
00102 
00103 #define BG_PLUGIN_URL          (1<<3)  
00104 #define BG_PLUGIN_PLAYBACK     (1<<4)  
00105 
00106 #define BG_PLUGIN_BYPASS       (1<<5)  
00107 
00108 #define BG_PLUGIN_KEEP_RUNNING (1<<6) 
00109 
00110 #define BG_PLUGIN_INPUT_HAS_SYNC (1<<7) 
00111 
00112 #define BG_PLUGIN_STDIN         (1<<8)  
00113 
00114 #define BG_PLUGIN_TUNER         (1<<9)  
00115 #define BG_PLUGIN_FILTER_1     (1<<10)  
00116 
00117 #define BG_PLUGIN_EMBED_WINDOW (1<<11)  
00118 
00119 #define BG_PLUGIN_VISUALIZE_FRAME (1<<12)  
00120 
00121 #define BG_PLUGIN_VISUALIZE_GL (1<<13)  
00122 
00123 #define BG_PLUGIN_PP  (1<<14)  
00124 
00125 
00126 #define BG_PLUGIN_UNSUPPORTED  (1<<24)  
00127 
00128 
00129 #define BG_PLUGIN_ALL 0xFFFFFFFF 
00130 
00131 
00136 #define BG_PLUGIN_API_VERSION 14
00137 
00138 /* Include this into all plugin modules exactly once
00139    to let the plugin loader obtain the API version */
00140 
00141 #define BG_GET_PLUGIN_API_VERSION \
00142   extern int get_plugin_api_version(); \
00143   extern int get_plugin_api_version() { return BG_PLUGIN_API_VERSION; }
00144 
00145 #define BG_PLUGIN_PRIORITY_MIN 1
00146 #define BG_PLUGIN_PRIORITY_MAX 10
00147 
00160 typedef enum
00161   {
00162     BG_STREAM_ACTION_OFF = 0, 
00163     BG_STREAM_ACTION_DECODE,  
00164     
00165     /*
00166      */
00167     
00168     BG_STREAM_ACTION_BYPASS, 
00169     
00170     /*
00171      *  Future support for compressed frames
00172      *  must go here
00173      */
00174 
00175     /* BG_STREAM_ACTION_READRAW */
00176     
00177   } bg_stream_action_t;
00178 
00179 /***************************************************
00180  * Plugin API
00181  *
00182  * Plugin dlls contain a symbol "the_plugin",
00183  * which points to one of the structures below.
00184  * The member functions are described below.
00185  *
00186  ***************************************************/
00187 
00188 /*
00189  * Plugin types
00190  */
00191 
00196 typedef enum
00197   {
00198     BG_PLUGIN_NONE                       = 0,      
00199     BG_PLUGIN_INPUT                      = (1<<0), 
00200     BG_PLUGIN_OUTPUT_AUDIO               = (1<<1), 
00201     BG_PLUGIN_OUTPUT_VIDEO               = (1<<2), 
00202     BG_PLUGIN_RECORDER_AUDIO             = (1<<3), 
00203     BG_PLUGIN_RECORDER_VIDEO             = (1<<4), 
00204     BG_PLUGIN_ENCODER_AUDIO              = (1<<5), 
00205     BG_PLUGIN_ENCODER_VIDEO              = (1<<6), 
00206     BG_PLUGIN_ENCODER_SUBTITLE_TEXT      = (1<<7), 
00207     BG_PLUGIN_ENCODER_SUBTITLE_OVERLAY   = (1<<8), 
00208     BG_PLUGIN_ENCODER                    = (1<<9), 
00209     BG_PLUGIN_ENCODER_PP                 = (1<<10),
00210     BG_PLUGIN_IMAGE_READER               = (1<<11),
00211     BG_PLUGIN_IMAGE_WRITER               = (1<<12), 
00212     BG_PLUGIN_FILTER_AUDIO               = (1<<13), 
00213     BG_PLUGIN_FILTER_VIDEO               = (1<<14), 
00214     BG_PLUGIN_VISUALIZATION              = (1<<15), 
00215     BG_PLUGIN_AV_RECORDER                = (1<<16),  
00216   } bg_plugin_type_t;
00217 
00226 typedef struct
00227   {
00228   char * device; 
00229   char * name;   
00230   } bg_device_info_t;
00231 
00242 bg_device_info_t * bg_device_info_append(bg_device_info_t * arr,
00243                                          const char * device,
00244                                          const char * name);
00245 
00251 void bg_device_info_destroy(bg_device_info_t * arr);
00252 
00253 /* Common part */
00254 
00259 typedef struct bg_plugin_common_s bg_plugin_common_t;
00260 
00265 struct bg_plugin_common_s
00266   {
00267   char * gettext_domain; 
00268   char * gettext_directory; 
00269   
00270   char             * name;       
00271   char             * long_name;  
00272   bg_plugin_type_t type;  
00273   int              flags;  
00274   
00275   char             * description; 
00276   
00277   /*
00278    *  If there might be more than one plugin for the same
00279    *  job, there is a priority (0..10) which is used for the
00280    *  decision
00281    */
00282   
00283   int              priority; 
00284   
00289   void * (*create)();
00290       
00300   void (*destroy)(void* priv);
00301 
00309   const bg_parameter_info_t * (*get_parameters)(void * priv);
00310 
00314   bg_set_parameter_func_t set_parameter;
00315 
00322   bg_get_parameter_func_t get_parameter;
00323   
00333   int (*check_device)(const char * device, char ** name);
00334   
00335 
00343   bg_device_info_t * (*find_devices)();
00344     
00345   };
00346 
00347 /*
00348  *  Plugin callbacks: Functions called by the
00349  *  plugin to reflect user input or other changes
00350  *  Applications might pass NULL callbacks,
00351  *  so plugins MUST check for valid callbacks structure
00352  *  before calling any of these functions
00353  */
00354 
00355 /* Input plugin */
00356 
00362 typedef struct bg_input_callbacks_s bg_input_callbacks_t;
00363 
00372 struct bg_input_callbacks_s
00373   {
00381    void (*track_changed)(void * data, int track);
00382 
00391   void (*time_changed)(void * data, gavl_time_t time);
00392   
00398   void (*duration_changed)(void * data, gavl_time_t duration);
00399 
00407   void (*name_changed)(void * data, const char * name);
00408 
00416   void (*metadata_changed)(void * data, const bg_metadata_t * m);
00417 
00426   void (*buffer_notify)(void * data, float percentage);
00427 
00441   int (*user_pass)(void * data, const char * resource,
00442                    char ** username, char ** password);
00443 
00455   void (*aspect_changed)(void * data, int stream,
00456                          int pixel_width, int pixel_height);
00457   
00458   
00459   void * data; 
00460   
00461   };
00462 
00463 /*************************************************
00464  * MEDIA INPUT
00465  *************************************************/
00466 
00471 typedef struct bg_input_plugin_s bg_input_plugin_t;
00472 
00473 
00483 struct bg_input_plugin_s
00484   {
00485   bg_plugin_common_t common; 
00486 
00492   const char * (*get_protocols)(void * priv);
00497   const char * (*get_mimetypes)(void * priv);
00498 
00503   const char * (*get_extensions)(void * priv);
00504   
00514   void (*set_callbacks)(void * priv, bg_input_callbacks_t * callbacks);
00515   
00521   int (*open)(void * priv, const char * arg);
00522 
00531   int (*open_fd)(void * priv, int fd, int64_t total_bytes,
00532                  const char * mimetype);
00533 
00539   const bg_edl_t * (*get_edl)(void * priv);
00540     
00548   const char * (*get_disc_name)(void * priv);
00549 
00558   int (*eject_disc)(const char * device);
00559   
00567   int (*get_num_tracks)(void * priv);
00568   
00585   bg_track_info_t * (*get_track_info)(void * priv, int track);
00586 
00597   int (*set_track)(void * priv, int track);
00598     
00599   /*
00600    *  These functions set the audio- video- and subpicture streams
00601    *  as well as programs (== DVD Angles). All these start with 0
00602    *
00603    *  Arguments for actions are defined in the enum bg_stream_action_t
00604    *  above. Plugins must return FALSE on failure (e.g. no such stream)
00605    *
00606    *  Functions must be defined only, if the corresponding stream
00607    *  type is supported by the plugin and can be switched.
00608    *  Single stream plugins can leave these NULL
00609    *  Gmerlin will never try to call these functions on nonexistent streams
00610    */
00611 
00619   int (*set_audio_stream)(void * priv, int stream, bg_stream_action_t action);
00620 
00628   int (*set_video_stream)(void * priv, int stream, bg_stream_action_t action);
00629   
00637   int (*set_subtitle_stream)(void * priv, int stream, bg_stream_action_t action);
00638   
00650   int (*start)(void * priv);
00651 
00664   bg_read_audio_func_t read_audio;
00665 
00673   bg_read_video_func_t read_video;
00674   
00681   int (*has_subtitle)(void * priv, int stream);
00682     
00694   int (*read_subtitle_overlay)(void * priv,
00695                                gavl_overlay_t*ovl, int stream);
00696 
00715   int (*read_subtitle_text)(void * priv,
00716                             char ** text, int * text_alloc,
00717                             int64_t * start_time,
00718                             int64_t * duration, int stream);
00719   
00720   /* The following 3 functions are only meaningful for plugins, which
00721      have the BG_PLUGIN_BYPASS flag set. */
00722 
00732   int (*bypass)(void * priv);
00733   
00739   void (*bypass_set_pause)(void * priv, int pause);
00740 
00748   void (*bypass_set_volume)(void * priv, float volume);
00749     
00761   void (*seek)(void * priv, int64_t * time, int scale);
00762   
00770   void (*stop)(void * priv);
00771   
00778   void (*close)(void * priv);
00779   
00780   };
00781 
00791 typedef struct bg_oa_plugin_s bg_oa_plugin_t;
00792 
00799 struct bg_oa_plugin_s
00800   {
00801   bg_plugin_common_t common; 
00802 
00812   int (*open)(void * priv, gavl_audio_format_t* format);
00813 
00820   int (*start)(void * priv);
00821     
00827   void (*write_audio)(void * priv, gavl_audio_frame_t* frame);
00828 
00837   int (*get_delay)(void * priv);
00838   
00846   void (*stop)(void * priv);
00847     
00854   void (*close)(void * priv);
00855   };
00856 
00857 /*******************************************
00858  * AUDIO RECORDER
00859  *******************************************/
00860 
00870 typedef struct bg_recorder_plugin_s bg_recorder_plugin_t;
00871 
00878 struct bg_recorder_plugin_s
00879   {
00880   bg_plugin_common_t common; 
00881 
00891   int (*open)(void * priv, gavl_audio_format_t * audio_format, gavl_video_format_t * video_format);
00892   
00895   bg_read_audio_func_t read_audio;
00896 
00899   bg_read_video_func_t read_video;
00900   
00905   void (*close)(void * priv);
00906   };
00907 
00908 /*******************************************
00909  * VIDEO OUTPUT
00910  *******************************************/
00911 
00912 /* Callbacks */
00913 
00924 typedef struct bg_ov_callbacks_s bg_ov_callbacks_t;
00925 
00931 struct bg_ov_callbacks_s
00932   {
00939   const bg_accelerator_map_t * accel_map;
00940   
00946   int (*accel_callback)(void * data, int id);
00947   
00961   int (*key_callback)(void * data, int key, int mask);
00962 
00970   int (*key_release_callback)(void * data, int key, int mask);
00971   
00981   int (*button_callback)(void * data, int x, int y, int button, int mask);
00982 
00992   int (*button_release_callback)(void * data, int x, int y, int button, int mask);
00993   
01002   int (*motion_callback)(void * data, int x, int y, int mask);
01003   
01009   void (*show_window)(void * data, int show);
01010 
01018   void (*brightness_callback)(void * data, float val);
01019 
01027   void (*saturation_callback)(void * data, float val);
01028 
01036   void (*contrast_callback)(void * data, float val);
01037 
01045   void (*hue_callback)(void * data, float val);
01046   
01047   void * data;
01048   };
01049 
01050 /* Plugin structure */
01051 
01056 typedef struct bg_ov_plugin_s bg_ov_plugin_t;
01057 
01066 struct bg_ov_plugin_s
01067   {
01068   bg_plugin_common_t common; 
01069 
01079   void (*set_window)(void * priv, const char * window_id);
01080   
01086   const char * (*get_window)(void * priv);
01087   
01093   void (*set_window_title)(void * priv, const char * title);
01094   
01095 
01101   void (*set_callbacks)(void * priv, bg_ov_callbacks_t * callbacks);
01102   
01113   int  (*open)(void * priv, gavl_video_format_t * format);
01114   
01126   gavl_video_frame_t * (*create_frame)(void * priv);
01127   
01141   int (*add_overlay_stream)(void * priv, gavl_video_format_t * format);
01142 
01155   gavl_overlay_t * (*create_overlay)(void * priv, int id);
01156   
01163   void (*set_overlay)(void * priv, int stream, gavl_overlay_t * ovl);
01164   
01172   void (*put_video)(void * priv, gavl_video_frame_t*frame);
01173 
01183   void (*put_still)(void * priv, gavl_video_frame_t*frame);
01184 
01193   void (*handle_events)(void * priv);
01194 
01201   void (*update_aspect)(void * priv, int pixel_width, int pixel_height);
01202     
01208   void (*destroy_frame)(void * priv, gavl_video_frame_t * frame);
01209 
01216   void (*destroy_overlay)(void * priv, int id, gavl_overlay_t * ovl);
01217 
01225   void (*close)(void * priv);
01226 
01231   void (*show_window)(void * priv, int show);
01232   };
01233 
01234 /*******************************************
01235  * ENCODER
01236  *******************************************/
01237 
01247 typedef struct bg_encoder_plugin_s bg_encoder_plugin_t;
01248 
01249 
01254 struct bg_encoder_plugin_s
01255   {
01256   bg_plugin_common_t common; 
01257   
01258   int max_audio_streams;  
01259   int max_video_streams;  
01260   int max_subtitle_text_streams;
01261   int max_subtitle_overlay_streams;
01262 
01272   const char * (*get_extension)(void * priv);
01273   
01281   int (*open)(void * data, const char * filename,
01282               bg_metadata_t * metadata, bg_chapter_list_t * chapter_list);
01283 
01292   const char * (*get_filename)(void*);
01293 
01294   /* Return per stream parameters */
01295 
01303   const bg_parameter_info_t * (*get_audio_parameters)(void * priv);
01304 
01312   const bg_parameter_info_t * (*get_video_parameters)(void * priv);
01313 
01321   const bg_parameter_info_t * (*get_subtitle_text_parameters)(void * priv);
01322 
01330   const bg_parameter_info_t * (*get_subtitle_overlay_parameters)(void * priv);
01331   
01332   /* Add streams. The formats can be changed, be sure to get the
01333    * final formats with get_[audio|video]_format after starting the plugin
01334    * Return value is the index of the added stream.
01335    */
01336 
01348   int (*add_audio_stream)(void * priv, const char * language,
01349                           gavl_audio_format_t * format);
01350 
01361   int (*add_video_stream)(void * priv, gavl_video_format_t * format);
01362 
01369   int (*add_subtitle_text_stream)(void * priv, const char * language, int * timescale);
01370   
01383   int (*add_subtitle_overlay_stream)(void * priv, const char * language,
01384                                      gavl_video_format_t * format);
01385   
01386   /* Set parameters for the streams */
01387 
01398   void (*set_audio_parameter)(void * priv, int stream, const char * name,
01399                               const bg_parameter_value_t * v);
01400 
01412   void (*set_video_parameter)(void * priv, int stream, const char * name,
01413                               const bg_parameter_value_t * v);
01414 
01425   void (*set_subtitle_text_parameter)(void * priv, int stream,
01426                                       const char * name,
01427                                       const bg_parameter_value_t * v);
01428 
01439   void (*set_subtitle_overlay_parameter)(void * priv, int stream,
01440                                          const char * name,
01441                                          const bg_parameter_value_t * v);
01442   
01451   int (*set_video_pass)(void * priv, int stream, int pass, int total_passes,
01452                         const char * stats_file);
01453   
01462   int (*start)(void * priv);
01463   
01464   /*
01465    *  After setting the parameters, get the formats, you need to deliver the frames in
01466    */
01467 
01476   void (*get_audio_format)(void * priv, int stream, gavl_audio_format_t*ret);
01477 
01486   void (*get_video_format)(void * priv, int stream, gavl_video_format_t*ret);
01487 
01496   void (*get_subtitle_overlay_format)(void * priv, int stream,
01497                                       gavl_video_format_t*ret);
01498 
01499   /*
01500    *  Encode audio/video
01501    */
01502 
01513   int (*write_audio_frame)(void * data,gavl_audio_frame_t * frame, int stream);
01514 
01522   int (*write_video_frame)(void * data,gavl_video_frame_t * frame, int stream);
01523 
01533   int (*write_subtitle_text)(void * data,const char * text,
01534                              int64_t start,
01535                              int64_t duration, int stream);
01536   
01544   int (*write_subtitle_overlay)(void * data, gavl_overlay_t * ovl, int stream);
01545   
01554   int (*close)(void * data, int do_delete);
01555   };
01556 
01557 
01558 /*******************************************
01559  * ENCODER Postprocessor
01560  *******************************************/
01561 
01576 typedef struct
01577   {
01584   void (*action_callback)(void * data, char * action);
01585 
01595   void (*progress_callback)(void * data, float perc);
01596 
01597   void * data; 
01598 
01599   } bg_e_pp_callbacks_t;
01600 
01606 typedef struct bg_encoder_pp_plugin_s bg_encoder_pp_plugin_t;
01607 
01613 struct bg_encoder_pp_plugin_s
01614   {
01615   bg_plugin_common_t common; 
01616   
01617   int max_audio_streams;  
01618   int max_video_streams;  
01619 
01620   char * supported_extensions; 
01621   
01628   void (*set_callbacks)(void * priv,bg_e_pp_callbacks_t * callbacks);
01629   
01637   int (*init)(void * priv);
01638 
01655   void (*add_track)(void * priv, const char * filename,
01656                     bg_metadata_t * metadata, int pp_only);
01657   
01667   void (*run)(void * priv, const char * directory, int cleanup);
01668 
01678   void (*stop)(void * priv);
01679   };
01680 
01681 
01695 typedef struct bg_image_reader_plugin_s bg_image_reader_plugin_t;
01696 
01700 struct bg_image_reader_plugin_s
01701   {
01702   bg_plugin_common_t common; 
01703   const char * extensions; 
01704   
01712   int (*read_header)(void * priv, const char * filename,
01713                      gavl_video_format_t * format);
01714 
01724   int (*read_image)(void * priv, gavl_video_frame_t * frame);
01725   };
01726 
01731 typedef struct bg_image_writer_plugin_s bg_image_writer_plugin_t;
01732 
01737 struct bg_image_writer_plugin_s
01738   {
01739   bg_plugin_common_t common; 
01740 
01750   const char * (*get_extension)(void * priv);
01751   
01762   int (*write_header)(void * priv, const char * filename,
01763                       gavl_video_format_t * format);
01764   
01775   int (*write_image)(void * priv, gavl_video_frame_t * frame);
01776   } ;
01777 
01808 /* Filters */
01809 
01814 typedef struct bg_fa_plugin_s bg_fa_plugin_t;
01815 
01820 struct bg_fa_plugin_s
01821   {
01822   bg_plugin_common_t common; 
01823 
01832   void (*connect_input_port)(void * priv, bg_read_audio_func_t func,
01833                              void * data,
01834                              int stream, int port);
01835 
01845   void (*set_input_format)(void * priv, gavl_audio_format_t * format, int port);
01846 
01847 
01854   void (*reset)(void * priv);
01855 
01863   void (*get_output_format)(void * priv, gavl_audio_format_t * format);
01864 
01874   int (*need_restart)(void * priv);
01875 
01879   bg_read_audio_func_t read_audio;
01880     
01881   };
01882 
01887 typedef struct bg_fv_plugin_s bg_fv_plugin_t;
01888 
01893 struct bg_fv_plugin_s
01894   {
01895   bg_plugin_common_t common; 
01896 
01905   void (*connect_input_port)(void * priv,
01906                              bg_read_video_func_t func,
01907                              void * data, int stream, int port);
01908 
01915   void (*set_input_format)(void * priv, gavl_video_format_t * format, int port);
01916   
01923   void (*reset)(void * priv);
01924 
01932   void (*get_output_format)(void * priv, gavl_video_format_t * format);
01933   
01943   int (*need_restart)(void * priv);
01944 
01948   bg_read_video_func_t read_video;
01949     
01950   };
01951 
01952 
01971 typedef struct bg_visualization_plugin_s bg_visualization_plugin_t;
01972 
01973 
01988 struct bg_visualization_plugin_s
01989   {
01990   bg_plugin_common_t common; 
01991 
01997   bg_ov_callbacks_t * (*get_callbacks)(void * priv);
01998 
02010   int (*open_ov)(void * priv, gavl_audio_format_t * audio_format,
02011                  gavl_video_format_t * video_format);
02012   
02023   int (*open_win)(void * priv, gavl_audio_format_t * audio_format,
02024                   const char * window_id);
02025 
02038   void (*update)(void * priv, gavl_audio_frame_t * frame);
02039 
02049   void (*draw_frame)(void * priv, gavl_video_frame_t * frame);
02050   
02059   void (*show_frame)(void * priv);
02060 
02065   void (*close)(void * priv);
02066   
02067   };
02068 
02069 
02070 
02075 #endif // __BG_PLUGIN_H_

Generated on Sat Aug 9 12:12:42 2008 for gmerlin by  doxygen 1.5.6