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 
00073 typedef int (*bg_read_audio_func_t)(void * priv, gavl_audio_frame_t* frame, int stream,
00074                                   int num_samples);
00075 
00087 typedef int (*bg_read_video_func_t)(void * priv, gavl_video_frame_t* frame, int stream);
00088 
00098 #define BG_PLUGIN_REMOVABLE    (1<<0)  
00099 #define BG_PLUGIN_FILE         (1<<1)  
00100 #define BG_PLUGIN_RECORDER     (1<<2)  
00101 
00102 #define BG_PLUGIN_URL          (1<<3)  
00103 #define BG_PLUGIN_PLAYBACK     (1<<4)  
00104 
00105 #define BG_PLUGIN_BYPASS       (1<<5)  
00106 
00107 #define BG_PLUGIN_KEEP_RUNNING (1<<6) 
00108 
00109 #define BG_PLUGIN_INPUT_HAS_SYNC (1<<7) 
00110 
00111 #define BG_PLUGIN_STDIN         (1<<8)  
00112 
00113 #define BG_PLUGIN_TUNER         (1<<9)  
00114 #define BG_PLUGIN_FILTER_1     (1<<10)  
00115 
00116 #define BG_PLUGIN_EMBED_WINDOW (1<<11)  
00117 
00118 #define BG_PLUGIN_VISUALIZE_FRAME (1<<12)  
00119 
00120 #define BG_PLUGIN_VISUALIZE_GL (1<<13)  
00121 
00122 #define BG_PLUGIN_PP  (1<<14)  
00123 
00124 
00125 #define BG_PLUGIN_UNSUPPORTED  (1<<24)  
00126 
00127 
00128 #define BG_PLUGIN_ALL 0xFFFFFFFF 
00129 
00130 
00135 #define BG_PLUGIN_API_VERSION 11
00136 
00137 /* Include this into all plugin modules exactly once
00138    to let the plugin loader obtain the API version */
00139 
00140 #define BG_GET_PLUGIN_API_VERSION \
00141   extern int get_plugin_api_version(); \
00142   extern int get_plugin_api_version() { return BG_PLUGIN_API_VERSION; }
00143 
00144 #define BG_PLUGIN_PRIORITY_MIN 1
00145 #define BG_PLUGIN_PRIORITY_MAX 10
00146 
00159 typedef enum
00160   {
00161     BG_STREAM_ACTION_OFF = 0, 
00162     BG_STREAM_ACTION_DECODE,  
00163     
00164     /*
00165      */
00166     
00167     BG_STREAM_ACTION_BYPASS, 
00168     
00169     /*
00170      *  Future support for compressed frames
00171      *  must go here
00172      */
00173 
00174     /* BG_STREAM_ACTION_READRAW */
00175     
00176   } bg_stream_action_t;
00177 
00178 /***************************************************
00179  * Plugin API
00180  *
00181  * Plugin dlls contain a symbol "the_plugin",
00182  * which points to one of the structures below.
00183  * The member functions are described below.
00184  *
00185  ***************************************************/
00186 
00187 /*
00188  * Plugin types
00189  */
00190 
00195 typedef enum
00196   {
00197     BG_PLUGIN_NONE                       = 0,      
00198     BG_PLUGIN_INPUT                      = (1<<0), 
00199     BG_PLUGIN_OUTPUT_AUDIO               = (1<<1), 
00200     BG_PLUGIN_OUTPUT_VIDEO               = (1<<2), 
00201     BG_PLUGIN_RECORDER_AUDIO             = (1<<3), 
00202     BG_PLUGIN_RECORDER_VIDEO             = (1<<4), 
00203     BG_PLUGIN_ENCODER_AUDIO              = (1<<5), 
00204     BG_PLUGIN_ENCODER_VIDEO              = (1<<6), 
00205     BG_PLUGIN_ENCODER_SUBTITLE_TEXT      = (1<<7), 
00206     BG_PLUGIN_ENCODER_SUBTITLE_OVERLAY   = (1<<8), 
00207     BG_PLUGIN_ENCODER                    = (1<<9), 
00208     BG_PLUGIN_ENCODER_PP                 = (1<<10),
00209     BG_PLUGIN_IMAGE_READER               = (1<<11),
00210     BG_PLUGIN_IMAGE_WRITER               = (1<<12), 
00211     BG_PLUGIN_FILTER_AUDIO               = (1<<13), 
00212     BG_PLUGIN_FILTER_VIDEO               = (1<<14), 
00213     BG_PLUGIN_VISUALIZATION              = (1<<15), 
00214   } bg_plugin_type_t;
00215 
00224 typedef struct
00225   {
00226   char * device; 
00227   char * name;   
00228   } bg_device_info_t;
00229 
00240 bg_device_info_t * bg_device_info_append(bg_device_info_t * arr,
00241                                          const char * device,
00242                                          const char * name);
00243 
00249 void bg_device_info_destroy(bg_device_info_t * arr);
00250 
00251 /* Common part */
00252 
00257 typedef struct bg_plugin_common_s
00258   {
00259   char * gettext_domain; 
00260   char * gettext_directory; 
00261   
00262   char             * name;       
00263   char             * long_name;  
00264   char             * mimetypes;  
00265   char             * extensions;  
00266   bg_plugin_type_t type;  
00267   int              flags;  
00268   
00269   char             * description; 
00270   
00271   /*
00272    *  If there might be more than one plugin for the same
00273    *  job, there is a priority (0..10) which is used for the
00274    *  decision
00275    */
00276   
00277   int              priority; 
00278   
00283   void * (*create)();
00284       
00294   void (*destroy)(void* priv);
00295 
00303   bg_parameter_info_t * (*get_parameters)(void * priv);
00304 
00308   bg_set_parameter_func_t set_parameter;
00309 
00316   bg_get_parameter_func_t get_parameter;
00317   
00327   int (*check_device)(const char * device, char ** name);
00328   
00329 
00337   bg_device_info_t * (*find_devices)();
00338     
00339   } bg_plugin_common_t;
00340 
00341 /*
00342  *  Plugin callbacks: Functions called by the
00343  *  plugin to reflect user input or other changes
00344  *  Applications might pass NULL callbacks,
00345  *  so plugins MUST check for valid callbacks structure
00346  *  before calling any of these functions
00347  */
00348 
00349 /* Input plugin */
00350 
00359 typedef struct bg_input_callbacks_s
00360   {
00368    void (*track_changed)(void * data, int track);
00369 
00378   void (*time_changed)(void * data, gavl_time_t time);
00379   
00385   void (*duration_changed)(void * data, gavl_time_t duration);
00386 
00394   void (*name_changed)(void * data, const char * name);
00395 
00403   void (*metadata_changed)(void * data, const bg_metadata_t * m);
00404 
00413   void (*buffer_notify)(void * data, float percentage);
00414 
00428   int (*user_pass)(void * data, const char * resource,
00429                    char ** username, char ** password);
00430 
00442   void (*aspect_changed)(void * data, int stream,
00443                          int pixel_width, int pixel_height);
00444   
00445   
00446   void * data; 
00447   
00448   } bg_input_callbacks_t;
00449 
00450 /*************************************************
00451  * MEDIA INPUT
00452  *************************************************/
00453 
00463 typedef struct bg_input_plugin_s
00464   {
00465   bg_plugin_common_t common; 
00466   
00467   char * protocols; 
00468 
00478   void (*set_callbacks)(void * priv, bg_input_callbacks_t * callbacks);
00479   
00485   int (*open)(void * priv, const char * arg);
00486 
00495   int (*open_fd)(void * priv, int fd, int64_t total_bytes,
00496                  const char * mimetype);
00497 
00505   const char * (*get_disc_name)(void * priv);
00506 
00515   int (*eject_disc)(const char * device);
00516   
00524   int (*get_num_tracks)(void * priv);
00525   
00542   bg_track_info_t * (*get_track_info)(void * priv, int track);
00543 
00554   int (*set_track)(void * priv, int track);
00555     
00556   /*
00557    *  These functions set the audio- video- and subpicture streams
00558    *  as well as programs (== DVD Angles). All these start with 0
00559    *
00560    *  Arguments for actions are defined in the enum bg_stream_action_t
00561    *  above. Plugins must return FALSE on failure (e.g. no such stream)
00562    *
00563    *  Functions must be defined only, if the corresponding stream
00564    *  type is supported by the plugin and can be switched.
00565    *  Single stream plugins can leave these NULL
00566    *  Gmerlin will never try to call these functions on nonexistent streams
00567    */
00568 
00576   int (*set_audio_stream)(void * priv, int stream, bg_stream_action_t action);
00577 
00585   int (*set_video_stream)(void * priv, int stream, bg_stream_action_t action);
00586   
00594   int (*set_subtitle_stream)(void * priv, int stream, bg_stream_action_t action);
00595   
00607   int (*start)(void * priv);
00608 
00621   bg_read_audio_func_t read_audio_samples;
00622 
00630   bg_read_video_func_t read_video_frame;
00631   
00638   int (*has_subtitle)(void * priv, int stream);
00639     
00651   int (*read_subtitle_overlay)(void * priv,
00652                                gavl_overlay_t*ovl, int stream);
00653 
00672   int (*read_subtitle_text)(void * priv,
00673                             char ** text, int * text_alloc,
00674                             int64_t * start_time,
00675                             int64_t * duration, int stream);
00676   
00677   /* The following 3 functions are only meaningful for plugins, which
00678      have the BG_PLUGIN_BYPASS flag set. */
00679 
00689   int (*bypass)(void * priv);
00690   
00696   void (*bypass_set_pause)(void * priv, int pause);
00697 
00705   void (*bypass_set_volume)(void * priv, float volume);
00706     
00717   void (*seek)(void * priv, gavl_time_t * time);
00718 
00726   void (*stop)(void * priv);
00727   
00734   void (*close)(void * priv);
00735   
00736   } bg_input_plugin_t;
00737 
00749 typedef struct bg_oa_plugin_s
00750   {
00751   bg_plugin_common_t common; 
00752 
00762   int (*open)(void * priv, gavl_audio_format_t* format);
00763 
00770   int (*start)(void * priv);
00771     
00777   void (*write_frame)(void * priv, gavl_audio_frame_t* frame);
00778 
00787   int (*get_delay)(void * priv);
00788   
00796   void (*stop)(void * priv);
00797     
00804   void (*close)(void * priv);
00805   } bg_oa_plugin_t;
00806 
00807 /*******************************************
00808  * AUDIO RECORDER
00809  *******************************************/
00810 
00822 typedef struct bg_ra_plugin_s
00823   {
00824   bg_plugin_common_t common; 
00825 
00835   int (*open)(void * priv, gavl_audio_format_t * format);
00836 
00843   void (*read_frame)(void * priv, gavl_audio_frame_t * frame,int num_samples);
00844 
00849   void (*close)(void * priv);
00850   } bg_ra_plugin_t;
00851 
00852 /*******************************************
00853  * VIDEO OUTPUT
00854  *******************************************/
00855 
00856 /* Callbacks */
00857 
00868 typedef struct bg_ov_callbacks_s
00869   {
00876   const bg_accelerator_map_t * accel_map;
00877   
00883   int (*accel_callback)(void * data, int id);
00884   
00898   int (*key_callback)(void * data, int key, int mask);
00899 
00907   int (*key_release_callback)(void * data, int key, int mask);
00908   
00918   int (*button_callback)(void * data, int x, int y, int button, int mask);
00919 
00929   int (*button_release_callback)(void * data, int x, int y, int button, int mask);
00930   
00939   int (*motion_callback)(void * data, int x, int y, int mask);
00940   
00946   void (*show_window)(void * data, int show);
00947 
00955   void (*brightness_callback)(void * data, float val);
00956 
00964   void (*saturation_callback)(void * data, float val);
00965 
00973   void (*contrast_callback)(void * data, float val);
00974 
00982   void (*hue_callback)(void * data, float val);
00983   
00984   void * data;
00985   } bg_ov_callbacks_t;
00986 
00987 /* Plugin structure */
00988 
00997 typedef struct bg_ov_plugin_s
00998   {
00999   bg_plugin_common_t common; 
01000 
01010   void (*set_window)(void * priv, const char * window_id);
01011   
01017   const char * (*get_window)(void * priv);
01018   
01024   void (*set_window_title)(void * priv, const char * title);
01025   
01026 
01032   void (*set_callbacks)(void * priv, bg_ov_callbacks_t * callbacks);
01033   
01044   int  (*open)(void * priv, gavl_video_format_t * format);
01045   
01057   gavl_video_frame_t * (*create_frame)(void * priv);
01058   
01072   int (*add_overlay_stream)(void * priv, gavl_video_format_t * format);
01073 
01086   gavl_overlay_t * (*create_overlay)(void * priv, int id);
01087   
01094   void (*set_overlay)(void * priv, int stream, gavl_overlay_t * ovl);
01095   
01103   void (*put_video)(void * priv, gavl_video_frame_t*frame);
01104 
01114   void (*put_still)(void * priv, gavl_video_frame_t*frame);
01115 
01124   void (*handle_events)(void * priv);
01125 
01132   void (*update_aspect)(void * priv, int pixel_width, int pixel_height);
01133     
01139   void (*destroy_frame)(void * priv, gavl_video_frame_t * frame);
01140 
01147   void (*destroy_overlay)(void * priv, int id, gavl_overlay_t * ovl);
01148 
01156   void (*close)(void * priv);
01157 
01162   void (*show_window)(void * priv, int show);
01163   } bg_ov_plugin_t;
01164 
01165 /*******************************************
01166  * VIDEO RECORDER
01167  *******************************************/
01168 
01179 typedef struct bg_rv_plugin_s
01180   {
01181   bg_plugin_common_t common; 
01182 
01192   int (*open)(void * priv, gavl_video_format_t * format);
01193 
01205   gavl_video_frame_t * (*alloc_frame)(void * priv);
01206 
01212   int (*read_frame)(void * priv, gavl_video_frame_t * frame);
01213 
01219   void (*free_frame)(void * priv, gavl_video_frame_t * frame);
01220 
01228   void (*close)(void * priv);
01229   
01230   } bg_rv_plugin_t;
01231 
01232 /*******************************************
01233  * ENCODER
01234  *******************************************/
01235 
01245 typedef struct bg_encoder_plugin_s
01246   {
01247   bg_plugin_common_t common; 
01248   
01249   int max_audio_streams;  
01250   int max_video_streams;  
01251   int max_subtitle_text_streams;
01252   int max_subtitle_overlay_streams;
01253 
01263   const char * (*get_extension)(void * priv);
01264   
01272   int (*open)(void * data, const char * filename,
01273               bg_metadata_t * metadata, bg_chapter_list_t * chapter_list);
01274 
01283   const char * (*get_filename)(void*);
01284 
01285   /* Return per stream parameters */
01286 
01294   bg_parameter_info_t * (*get_audio_parameters)(void * priv);
01295 
01303   bg_parameter_info_t * (*get_video_parameters)(void * priv);
01304 
01312   bg_parameter_info_t * (*get_subtitle_text_parameters)(void * priv);
01313 
01321   bg_parameter_info_t * (*get_subtitle_overlay_parameters)(void * priv);
01322   
01323   /* Add streams. The formats can be changed, be sure to get the
01324    * final formats with get_[audio|video]_format after starting the plugin
01325    * Return value is the index of the added stream.
01326    */
01327 
01339   int (*add_audio_stream)(void * priv, const char * language,
01340                           gavl_audio_format_t * format);
01341 
01352   int (*add_video_stream)(void * priv, gavl_video_format_t * format);
01353 
01360   int (*add_subtitle_text_stream)(void * priv, const char * language);
01361 
01374   int (*add_subtitle_overlay_stream)(void * priv, const char * language,
01375                                      gavl_video_format_t * format);
01376   
01377   /* Set parameters for the streams */
01378 
01389   void (*set_audio_parameter)(void * priv, int stream, const char * name,
01390                               const bg_parameter_value_t * v);
01391 
01403   void (*set_video_parameter)(void * priv, int stream, const char * name,
01404                               const bg_parameter_value_t * v);
01405 
01416   void (*set_subtitle_text_parameter)(void * priv, int stream,
01417                                       const char * name,
01418                                       const bg_parameter_value_t * v);
01419 
01430   void (*set_subtitle_overlay_parameter)(void * priv, int stream,
01431                                          const char * name,
01432                                          const bg_parameter_value_t * v);
01433   
01442   int (*set_video_pass)(void * priv, int stream, int pass, int total_passes,
01443                         const char * stats_file);
01444   
01453   int (*start)(void * priv);
01454   
01455   /*
01456    *  After setting the parameters, get the formats, you need to deliver the frames in
01457    */
01458 
01467   void (*get_audio_format)(void * priv, int stream, gavl_audio_format_t*ret);
01468 
01477   void (*get_video_format)(void * priv, int stream, gavl_video_format_t*ret);
01478 
01487   void (*get_subtitle_overlay_format)(void * priv, int stream,
01488                                       gavl_video_format_t*ret);
01489 
01490   /*
01491    *  Encode audio/video
01492    */
01493 
01504   int (*write_audio_frame)(void * data,gavl_audio_frame_t * frame, int stream);
01505 
01513   int (*write_video_frame)(void * data,gavl_video_frame_t * frame, int stream);
01514 
01524   int (*write_subtitle_text)(void * data,const char * text,
01525                              gavl_time_t start,
01526                              gavl_time_t duration, int stream);
01527 
01535   int (*write_subtitle_overlay)(void * data, gavl_overlay_t * ovl, int stream);
01536   
01545   int (*close)(void * data, int do_delete);
01546   } bg_encoder_plugin_t;
01547 
01548 
01549 /*******************************************
01550  * ENCODER Postprocessor
01551  *******************************************/
01552 
01567 typedef struct
01568   {
01575   void (*action_callback)(void * data, char * action);
01576 
01586   void (*progress_callback)(void * data, float perc);
01587 
01588   void * data; 
01589 
01590   } bg_e_pp_callbacks_t;
01591 
01597 typedef struct bg_encoder_pp_plugin_s
01598   {
01599   bg_plugin_common_t common; 
01600   
01601   int max_audio_streams;  
01602 
01603   int max_video_streams;  
01604 
01611   void (*set_callbacks)(void * priv,bg_e_pp_callbacks_t * callbacks);
01612   
01620   int (*init)(void * priv);
01621 
01638   void (*add_track)(void * priv, const char * filename,
01639                     bg_metadata_t * metadata, int pp_only);
01640   
01650   void (*run)(void * priv, const char * directory, int cleanup);
01651 
01661   void (*stop)(void * priv);
01662   } bg_encoder_pp_plugin_t;
01663 
01664 
01678 typedef struct bg_image_reader_plugin_s
01679   {
01680   bg_plugin_common_t common; 
01681 
01689   int (*read_header)(void * priv, const char * filename,
01690                      gavl_video_format_t * format);
01691 
01701   int (*read_image)(void * priv, gavl_video_frame_t * frame);
01702   } bg_image_reader_plugin_t;
01703 
01709 typedef struct bg_image_writer_plugin_s
01710   {
01711   bg_plugin_common_t common; 
01712 
01722   const char * (*get_extension)(void * priv);
01723   
01734   int (*write_header)(void * priv, const char * filename,
01735                       gavl_video_format_t * format);
01736   
01747   int (*write_image)(void * priv, gavl_video_frame_t * frame);
01748   } bg_image_writer_plugin_t;
01749 
01780 /* Filters */
01781 
01786 typedef struct bg_audio_filter_plugin_s
01787   {
01788   bg_plugin_common_t common; 
01789 
01798   void (*connect_input_port)(void * priv, bg_read_audio_func_t func,
01799                              void * data,
01800                              int stream, int port);
01801 
01811   void (*set_input_format)(void * priv, gavl_audio_format_t * format, int port);
01812 
01819   void (*init)(void * priv);
01820 
01827   void (*reset)(void * priv);
01828 
01836   void (*get_output_format)(void * priv, gavl_audio_format_t * format);
01837 
01847   int (*need_restart)(void * priv);
01848 
01852   bg_read_audio_func_t read_audio;
01853     
01854   } bg_fa_plugin_t;
01855 
01860 typedef struct bg_video_filter_plugin_s
01861   {
01862   bg_plugin_common_t common; 
01863 
01872   void (*connect_input_port)(void * priv,
01873                              bg_read_video_func_t func,
01874                              void * data, int stream, int port);
01875 
01882   void (*set_input_format)(void * priv, gavl_video_format_t * format, int port);
01883 
01890   void (*init)(void * priv);
01891 
01898   void (*reset)(void * priv);
01899 
01907   void (*get_output_format)(void * priv, gavl_video_format_t * format);
01908   
01918   int (*need_restart)(void * priv);
01919 
01923   bg_read_video_func_t read_video;
01924     
01925   } bg_fv_plugin_t;
01926 
01927 
01956 typedef struct bg_visualization_plugin_s
01957   {
01958   bg_plugin_common_t common; 
01959 
01965   bg_ov_callbacks_t * (*get_callbacks)(void * priv);
01966 
01978   int (*open_ov)(void * priv, gavl_audio_format_t * audio_format,
01979                  gavl_video_format_t * video_format);
01980   
01991   int (*open_win)(void * priv, gavl_audio_format_t * audio_format,
01992                   const char * window_id);
01993 
02006   void (*update)(void * priv, gavl_audio_frame_t * frame);
02007 
02017   void (*draw_frame)(void * priv, gavl_video_frame_t * frame);
02018   
02027   void (*show_frame)(void * priv);
02028 
02033   void (*close)(void * priv);
02034   
02035   } bg_visualization_plugin_t;
02036 
02037 
02038 
02043 #endif // __BG_PLUGIN_H_

Generated on Wed Jan 9 19:32:52 2008 for gmerlin by  doxygen 1.5.3