gavl.h

Go to the documentation of this file.
00001 /*****************************************************************
00002  * gavl - a general purpose audio/video processing library
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 
00027 #ifndef GAVL_H_INCLUDED
00028 #define GAVL_H_INCLUDED
00029 
00030 #include <inttypes.h>
00031 
00032 #include <gavl/gavltime.h>
00033 
00034 #ifdef __cplusplus
00035 extern "C" {
00036 #endif
00037 
00042 typedef struct gavl_video_format_s gavl_video_format_t;
00043 
00044 #include <gavl/timecode.h>
00045 
00046 #pragma GCC visibility push(default)
00047   
00048 /* Quality levels */
00049   
00073 #define GAVL_QUALITY_FASTEST 1
00074 
00081 #define GAVL_QUALITY_BEST    5 
00082 
00089 #define GAVL_QUALITY_DEFAULT 2 
00090 
00102 #define GAVL_ACCEL_MMX      (1<<0) 
00103 #define GAVL_ACCEL_MMXEXT   (1<<1) 
00104 #define GAVL_ACCEL_SSE      (1<<2) 
00105 #define GAVL_ACCEL_SSE2     (1<<3) 
00106 #define GAVL_ACCEL_SSE3     (1<<4) 
00107 #define GAVL_ACCEL_3DNOW    (1<<5) 
00108 #define GAVL_ACCEL_3DNOWEXT (1<<6) 
00109 #define GAVL_ACCEL_SSSE3    (1<<7) 
00110 
00111 
00115 int gavl_accel_supported();
00116 
00125 /* Sample formats: all multibyte numbers are native endian */
00126 
00139 #define GAVL_MAX_CHANNELS 128
00140   
00147 typedef enum
00148   {
00149     GAVL_SAMPLE_NONE   = 0, 
00150     GAVL_SAMPLE_U8     = 1, 
00151     GAVL_SAMPLE_S8     = 2, 
00152     GAVL_SAMPLE_U16    = 3, 
00153     GAVL_SAMPLE_S16    = 4, 
00154     GAVL_SAMPLE_S32    = 5, 
00155     GAVL_SAMPLE_FLOAT  = 6,  
00156     GAVL_SAMPLE_DOUBLE = 7  
00157   } gavl_sample_format_t;
00158 
00164 typedef enum
00165   {
00166     GAVL_INTERLEAVE_NONE = 0, 
00167     GAVL_INTERLEAVE_2    = 1, 
00168     GAVL_INTERLEAVE_ALL  = 2  
00169   } gavl_interleave_mode_t;
00170 
00178 typedef enum
00179   {
00180     GAVL_CHID_NONE         = 0,   
00181     GAVL_CHID_FRONT_CENTER,       
00182     GAVL_CHID_FRONT_LEFT,         
00183     GAVL_CHID_FRONT_RIGHT,        
00184     GAVL_CHID_FRONT_CENTER_LEFT,  
00185     GAVL_CHID_FRONT_CENTER_RIGHT, 
00186     GAVL_CHID_REAR_LEFT,          
00187     GAVL_CHID_REAR_RIGHT,         
00188     GAVL_CHID_REAR_CENTER,        
00189     GAVL_CHID_SIDE_LEFT,          
00190     GAVL_CHID_SIDE_RIGHT,         
00191     GAVL_CHID_LFE,                
00192     GAVL_CHID_AUX,                
00193   } gavl_channel_id_t;
00194 
00203 typedef struct 
00204   {
00205   int samples_per_frame;  
00206   int samplerate;         
00207   int num_channels;         
00208   gavl_sample_format_t   sample_format; 
00209   gavl_interleave_mode_t interleave_mode; 
00211   float center_level; 
00212   float rear_level;   
00214   gavl_channel_id_t channel_locations[GAVL_MAX_CHANNELS];   
00216   } gavl_audio_format_t;
00217 
00218   
00219 /* Audio format -> string conversions */
00220 
00228 const char * gavl_sample_format_to_string(gavl_sample_format_t format);
00229 
00238 gavl_sample_format_t gavl_string_to_sample_format(const char * str);
00239 
00245 int gavl_num_sample_formats();
00246 
00253 gavl_sample_format_t gavl_get_sample_format(int index);
00254   
00261 const char * gavl_channel_id_to_string(gavl_channel_id_t id);
00262 
00263 
00270 const char * gavl_interleave_mode_to_string(gavl_interleave_mode_t mode);
00271 
00278 void gavl_audio_format_dump(const gavl_audio_format_t * format);
00279 
00288 int gavl_channel_index(const gavl_audio_format_t * format, gavl_channel_id_t id);
00289 
00296 int gavl_front_channels(const gavl_audio_format_t * format);
00297 
00304 int gavl_rear_channels(const gavl_audio_format_t * format);
00305 
00312 int gavl_side_channels(const gavl_audio_format_t * format);
00313 
00320 int gavl_aux_channels(const gavl_audio_format_t * format);
00321 
00322   
00323   
00330 int gavl_lfe_channels(const gavl_audio_format_t * format);
00331 
00339 void gavl_audio_format_copy(gavl_audio_format_t * dst,
00340                             const gavl_audio_format_t * src);
00341 
00350 int gavl_audio_formats_equal(const gavl_audio_format_t * format_1,
00351                               const gavl_audio_format_t * format_2);
00352 
00364 void gavl_set_channel_setup(gavl_audio_format_t * format);
00365 
00372 int gavl_bytes_per_sample(gavl_sample_format_t format);
00373 
00388 typedef union 
00389   {
00390   uint8_t * u_8; 
00391   int8_t *  s_8; 
00393   uint16_t * u_16; 
00394   int16_t  * s_16; 
00396   uint32_t * u_32; 
00397   int32_t  * s_32; 
00399   float * f; 
00400   double * d; 
00401   } gavl_audio_samples_t;
00402 
00408 typedef union
00409   {
00410   uint8_t * u_8[GAVL_MAX_CHANNELS];
00411   int8_t *  s_8[GAVL_MAX_CHANNELS];
00413   uint16_t * u_16[GAVL_MAX_CHANNELS];
00414   int16_t  * s_16[GAVL_MAX_CHANNELS];
00416   uint32_t * u_32[GAVL_MAX_CHANNELS];
00417   int32_t  * s_32[GAVL_MAX_CHANNELS];
00419   float * f[GAVL_MAX_CHANNELS];
00420   double * d[GAVL_MAX_CHANNELS];
00422   } gavl_audio_channels_t;
00423 
00440 typedef struct 
00441   {
00442   gavl_audio_samples_t  samples; 
00443   gavl_audio_channels_t channels;
00444   int valid_samples;             
00445   int64_t timestamp;             
00446   int channel_stride;            
00447   } gavl_audio_frame_t;
00448 
00460 gavl_audio_frame_t * gavl_audio_frame_create(const gavl_audio_format_t* format);
00461 
00473 void gavl_audio_frame_null(gavl_audio_frame_t * frame);
00474 
00484 void gavl_audio_frame_destroy(gavl_audio_frame_t * frame);
00485 
00495 void gavl_audio_frame_mute(gavl_audio_frame_t * frame,
00496                            const gavl_audio_format_t * format);
00497 
00508 void gavl_audio_frame_mute_samples(gavl_audio_frame_t * frame,
00509                                    const gavl_audio_format_t * format,
00510                                    int num_samples);
00511 
00512   
00513   
00524 void gavl_audio_frame_mute_channel(gavl_audio_frame_t * frame,
00525                                    const gavl_audio_format_t * format,
00526                                    int channel);
00527   
00548 int gavl_audio_frame_copy(const gavl_audio_format_t * format,
00549                           gavl_audio_frame_t * dst,
00550                           const gavl_audio_frame_t * src,
00551                           int dst_pos,
00552                           int src_pos,
00553                           int dst_size,
00554                           int src_size);
00555 
00570 #define GAVL_AUDIO_FRONT_TO_REAR_COPY (1<<0) 
00575 #define GAVL_AUDIO_FRONT_TO_REAR_MUTE (1<<1) 
00580 #define GAVL_AUDIO_FRONT_TO_REAR_DIFF (1<<2) 
00585 #define GAVL_AUDIO_FRONT_TO_REAR_MASK           \
00586 (GAVL_AUDIO_FRONT_TO_REAR_COPY | \
00587 GAVL_AUDIO_FRONT_TO_REAR_MUTE | \
00588  GAVL_AUDIO_FRONT_TO_REAR_DIFF) 
00590 /* Options for mixing stereo to mono */
00591   
00594 #define GAVL_AUDIO_STEREO_TO_MONO_LEFT  (1<<3) 
00597 #define GAVL_AUDIO_STEREO_TO_MONO_RIGHT (1<<4) 
00600 #define GAVL_AUDIO_STEREO_TO_MONO_MIX   (1<<5) 
00604 #define GAVL_AUDIO_STEREO_TO_MONO_MASK \
00605 (GAVL_AUDIO_STEREO_TO_MONO_LEFT | \
00606 GAVL_AUDIO_STEREO_TO_MONO_RIGHT | \
00607 GAVL_AUDIO_STEREO_TO_MONO_MIX) 
00613 typedef enum
00614   {
00615     GAVL_AUDIO_DITHER_NONE   = 0,
00616     GAVL_AUDIO_DITHER_AUTO   = 1,
00617     GAVL_AUDIO_DITHER_RECT   = 2,
00618     GAVL_AUDIO_DITHER_TRI    = 3,
00619     GAVL_AUDIO_DITHER_SHAPED = 4,
00620   } gavl_audio_dither_mode_t;
00621 
00626 typedef enum
00627   {
00628     GAVL_RESAMPLE_AUTO        = 0, 
00629     GAVL_RESAMPLE_ZOH         = 1, 
00630     GAVL_RESAMPLE_LINEAR      = 2, 
00631     GAVL_RESAMPLE_SINC_FAST   = 3, 
00632     GAVL_RESAMPLE_SINC_MEDIUM = 4, 
00633     GAVL_RESAMPLE_SINC_BEST   = 5  
00634   } gavl_resample_mode_t;
00635   
00642 typedef struct gavl_audio_options_s gavl_audio_options_t;
00643 
00650 void gavl_audio_options_set_quality(gavl_audio_options_t * opt, int quality);
00651 
00658 int gavl_audio_options_get_quality(gavl_audio_options_t * opt);
00659   
00666 void gavl_audio_options_set_dither_mode(gavl_audio_options_t * opt, gavl_audio_dither_mode_t mode);
00667 
00674 gavl_audio_dither_mode_t gavl_audio_options_get_dither_mode(gavl_audio_options_t * opt);
00675 
00676   
00683 void gavl_audio_options_set_resample_mode(gavl_audio_options_t * opt, gavl_resample_mode_t mode);
00684 
00691 gavl_resample_mode_t gavl_audio_options_get_resample_mode(gavl_audio_options_t * opt);
00692   
00699 void gavl_audio_options_set_conversion_flags(gavl_audio_options_t * opt,
00700                                              int flags);
00701   
00708 int gavl_audio_options_get_conversion_flags(gavl_audio_options_t * opt);
00709 
00715 void gavl_audio_options_set_defaults(gavl_audio_options_t * opt);
00716 
00726 gavl_audio_options_t * gavl_audio_options_create();
00727 
00734 void gavl_audio_options_copy(gavl_audio_options_t * dst,
00735                              const gavl_audio_options_t * src);
00736 
00742 void gavl_audio_options_destroy(gavl_audio_options_t * opt);
00743   
00744   
00745   
00746 /* Audio converter */
00747 
00781 typedef struct gavl_audio_converter_s gavl_audio_converter_t;
00782   
00788 gavl_audio_converter_t * gavl_audio_converter_create();
00789 
00795 void gavl_audio_converter_destroy(gavl_audio_converter_t* cnv);
00796 
00805 gavl_audio_options_t * gavl_audio_converter_get_options(gavl_audio_converter_t*cnv);
00806 
00807 
00821 int gavl_audio_converter_init(gavl_audio_converter_t* cnv,
00822                               const gavl_audio_format_t * input_format,
00823                               const gavl_audio_format_t * output_format);
00824 
00839 int gavl_audio_converter_init_resample(gavl_audio_converter_t * cnv,
00840                                    const gavl_audio_format_t * format);
00841 
00855 int gavl_audio_converter_reinit(gavl_audio_converter_t* cnv);
00856 
00857   
00871 void gavl_audio_convert(gavl_audio_converter_t * cnv,
00872                         const gavl_audio_frame_t * input_frame,
00873                         gavl_audio_frame_t * output_frame);
00874 
00875 
00894 int gavl_audio_converter_set_resample_ratio(gavl_audio_converter_t * cnv, 
00895                 double ratio ) ;
00896 
00897 
00913 void gavl_audio_converter_resample(gavl_audio_converter_t * cnv,
00914                               gavl_audio_frame_t * input_frame,
00915                               gavl_audio_frame_t * output_frame,
00916                               double ratio);
00917 
00918 
00932 typedef struct gavl_volume_control_s gavl_volume_control_t;
00933   
00934 /* Create / destroy */
00935 
00941 gavl_volume_control_t * gavl_volume_control_create();
00942 
00948 void gavl_volume_control_destroy(gavl_volume_control_t *ctrl);
00949 
00957 void gavl_volume_control_set_format(gavl_volume_control_t *ctrl,
00958                                     const gavl_audio_format_t * format);
00959 
00966 void gavl_volume_control_set_volume(gavl_volume_control_t * ctrl,
00967                                     float volume);
00968 
00975 void gavl_volume_control_apply(gavl_volume_control_t *ctrl,
00976                                gavl_audio_frame_t * frame);
00977 
00993 typedef struct gavl_peak_detector_s gavl_peak_detector_t;
00994   
00995 /* Create / destroy */
00996 
01002 gavl_peak_detector_t * gavl_peak_detector_create();
01003 
01009 void gavl_peak_detector_destroy(gavl_peak_detector_t *pd);
01010 
01020 void gavl_peak_detector_set_format(gavl_peak_detector_t *pd,
01021                                    const gavl_audio_format_t * format);
01022 
01029 void gavl_peak_detector_update(gavl_peak_detector_t *pd,
01030                               gavl_audio_frame_t * frame);
01031   
01044 void gavl_peak_detector_get_peak(gavl_peak_detector_t * pd,
01045                                  double * min, double * max,
01046                                  double * abs);
01047 
01060 void gavl_peak_detector_get_peaks(gavl_peak_detector_t * pd,
01061                                   double * min, double * max,
01062                                   double * abs);
01063   
01069 void gavl_peak_detector_reset(gavl_peak_detector_t * pd);
01070   
01080 #define GAVL_MAX_PLANES 4 
01092 typedef struct
01093   {
01094   int x; 
01095   int y; 
01096   int w; 
01097   int h; 
01098   } gavl_rectangle_i_t;
01099 
01104 typedef struct
01105   {
01106   double x; 
01107   double y; 
01108   double w; 
01109   double h; 
01110   } gavl_rectangle_f_t;
01111 
01118 void gavl_rectangle_i_crop_to_format(gavl_rectangle_i_t * r,
01119                                    const gavl_video_format_t * format);
01120 
01127 void gavl_rectangle_f_crop_to_format(gavl_rectangle_f_t * r,
01128                                      const gavl_video_format_t * format);
01129 
01144 void gavl_rectangle_crop_to_format_noscale(gavl_rectangle_i_t * src_rect,
01145                                            gavl_rectangle_i_t * dst_rect,
01146                                            const gavl_video_format_t * src_format,
01147                                            const gavl_video_format_t * dst_format);
01148 
01160 void gavl_rectangle_crop_to_format_scale(gavl_rectangle_f_t * src_rect,
01161                                          gavl_rectangle_i_t * dst_rect,
01162                                          const gavl_video_format_t * src_format,
01163                                          const gavl_video_format_t * dst_format);
01164 
01165   
01166 
01173 void gavl_rectangle_i_set_all(gavl_rectangle_i_t * r, const gavl_video_format_t * format);
01174 
01181 void gavl_rectangle_f_set_all(gavl_rectangle_f_t * r, const gavl_video_format_t * format);
01182 
01189 void gavl_rectangle_i_crop_left(gavl_rectangle_i_t * r,   int num_pixels);
01190 
01197 void gavl_rectangle_i_crop_right(gavl_rectangle_i_t * r,  int num_pixels);
01198 
01205 void gavl_rectangle_i_crop_top(gavl_rectangle_i_t * r,    int num_pixels);
01206 
01213 void gavl_rectangle_i_crop_bottom(gavl_rectangle_i_t * r, int num_pixels);
01214 
01221 void gavl_rectangle_f_crop_left(gavl_rectangle_f_t * r,   double num_pixels);
01222 
01229 void gavl_rectangle_f_crop_right(gavl_rectangle_f_t * r,  double num_pixels);
01230 
01237 void gavl_rectangle_f_crop_top(gavl_rectangle_f_t * r,    double num_pixels);
01238 
01245 void gavl_rectangle_f_crop_bottom(gavl_rectangle_f_t * r, double num_pixels);
01246 
01260 void gavl_rectangle_i_align(gavl_rectangle_i_t * r, int h_align, int v_align);
01261 
01271 void gavl_rectangle_i_align_to_format(gavl_rectangle_i_t * r,
01272                                       const gavl_video_format_t * format);
01273 
01274   
01281 void gavl_rectangle_i_copy(gavl_rectangle_i_t * dst, const gavl_rectangle_i_t * src);
01282 
01289 void gavl_rectangle_f_copy(gavl_rectangle_f_t * dst, const gavl_rectangle_f_t * src);
01290 
01291 
01292 
01299 void gavl_rectangle_i_to_f(gavl_rectangle_f_t * dst, const gavl_rectangle_i_t * src);
01300 
01307 void gavl_rectangle_f_to_i(gavl_rectangle_i_t * dst, const gavl_rectangle_f_t * src);
01308   
01317 int gavl_rectangle_i_is_empty(const gavl_rectangle_i_t * r);
01318 
01327 int gavl_rectangle_f_is_empty(const gavl_rectangle_f_t * r);
01328 
01356 void gavl_rectangle_fit_aspect(gavl_rectangle_i_t * dst_rect,
01357                                const gavl_video_format_t * src_format,
01358                                const gavl_rectangle_f_t * src_rect,
01359                                const gavl_video_format_t * dst_format,
01360                                float zoom, float squeeze);
01361 
01366 void gavl_rectangle_i_dump(const gavl_rectangle_i_t * r);
01367 
01372 void gavl_rectangle_f_dump(const gavl_rectangle_f_t * r);
01373 
01374   
01384 #define GAVL_PIXFMT_PLANAR (1<<8)
01385 
01389 #define GAVL_PIXFMT_RGB    (1<<9)
01390 
01394 #define GAVL_PIXFMT_YUV    (1<<10)
01395 
01399 #define GAVL_PIXFMT_YUVJ   (1<<11)
01400 
01404 #define GAVL_PIXFMT_ALPHA  (1<<12)
01405 
01409 #define GAVL_PIXFMT_GRAY   (1<<13)
01410   
01415 typedef enum 
01416   {
01419     GAVL_PIXELFORMAT_NONE =  0, 
01420 
01423     GAVL_GRAY_8          =  1 | GAVL_PIXFMT_GRAY,
01424 
01427     GAVL_GRAY_16          =  2 | GAVL_PIXFMT_GRAY,
01428     
01431     GAVL_GRAY_FLOAT       =  3 | GAVL_PIXFMT_GRAY,
01432     
01435     GAVL_GRAYA_16          =  1 | GAVL_PIXFMT_GRAY | GAVL_PIXFMT_ALPHA,
01436 
01439     GAVL_GRAYA_32          =  2 | GAVL_PIXFMT_GRAY | GAVL_PIXFMT_ALPHA,
01440     
01443     GAVL_GRAYA_FLOAT       =  3 | GAVL_PIXFMT_GRAY | GAVL_PIXFMT_ALPHA,
01444     
01448     GAVL_RGB_15          =  1 | GAVL_PIXFMT_RGB,
01452     GAVL_BGR_15          =  2 | GAVL_PIXFMT_RGB,
01456     GAVL_RGB_16          =  3 | GAVL_PIXFMT_RGB,
01460     GAVL_BGR_16          =  4 | GAVL_PIXFMT_RGB,
01463     GAVL_RGB_24          =  5 | GAVL_PIXFMT_RGB,
01466     GAVL_BGR_24          =  6 | GAVL_PIXFMT_RGB,
01469     GAVL_RGB_32          =  7 | GAVL_PIXFMT_RGB,
01472     GAVL_BGR_32          =  8 | GAVL_PIXFMT_RGB,
01475     GAVL_RGBA_32         =  9 | GAVL_PIXFMT_RGB | GAVL_PIXFMT_ALPHA,
01476 
01479     GAVL_RGB_48       = 10 | GAVL_PIXFMT_RGB,
01482     GAVL_RGBA_64      = 11 | GAVL_PIXFMT_RGB | GAVL_PIXFMT_ALPHA,
01483         
01486     GAVL_RGB_FLOAT    = 12 | GAVL_PIXFMT_RGB,
01489     GAVL_RGBA_FLOAT   = 13 | GAVL_PIXFMT_RGB  | GAVL_PIXFMT_ALPHA,
01490 
01493     GAVL_YUY2            = 1 | GAVL_PIXFMT_YUV,
01496     GAVL_UYVY            = 2 | GAVL_PIXFMT_YUV,
01499     GAVL_YUVA_32         = 3 | GAVL_PIXFMT_YUV | GAVL_PIXFMT_ALPHA,
01502     GAVL_YUVA_64         = 4 | GAVL_PIXFMT_YUV | GAVL_PIXFMT_ALPHA,
01505     GAVL_YUV_FLOAT       = 5 | GAVL_PIXFMT_YUV,
01506 
01509     GAVL_YUVA_FLOAT       = 6 | GAVL_PIXFMT_YUV | GAVL_PIXFMT_ALPHA,
01510     
01514     GAVL_YUV_420_P       = 1 | GAVL_PIXFMT_PLANAR | GAVL_PIXFMT_YUV,
01517     GAVL_YUV_422_P       = 2 | GAVL_PIXFMT_PLANAR | GAVL_PIXFMT_YUV,
01520     GAVL_YUV_444_P       = 3 | GAVL_PIXFMT_PLANAR | GAVL_PIXFMT_YUV,
01523     GAVL_YUV_411_P       = 4 | GAVL_PIXFMT_PLANAR | GAVL_PIXFMT_YUV,
01526     GAVL_YUV_410_P       = 5 | GAVL_PIXFMT_PLANAR | GAVL_PIXFMT_YUV,
01527     
01530     GAVL_YUVJ_420_P      = 6 | GAVL_PIXFMT_PLANAR | GAVL_PIXFMT_YUV | GAVL_PIXFMT_YUVJ,
01533     GAVL_YUVJ_422_P      = 7 | GAVL_PIXFMT_PLANAR | GAVL_PIXFMT_YUV | GAVL_PIXFMT_YUVJ,
01536     GAVL_YUVJ_444_P      = 8 | GAVL_PIXFMT_PLANAR | GAVL_PIXFMT_YUV | GAVL_PIXFMT_YUVJ,
01537 
01540     GAVL_YUV_444_P_16 = 9 | GAVL_PIXFMT_PLANAR | GAVL_PIXFMT_YUV,
01543     GAVL_YUV_422_P_16 = 10 | GAVL_PIXFMT_PLANAR | GAVL_PIXFMT_YUV,
01544     
01545   } gavl_pixelformat_t;
01546 
01549 #define GAVL_PIXELFORMAT_1D_8 GAVL_GRAY_8
01550 
01552 #define GAVL_PIXELFORMAT_2D_8 GAVL_GRAYA_16
01553 
01555 #define GAVL_PIXELFORMAT_3D_8 GAVL_RGB_24
01556 
01558 #define GAVL_PIXELFORMAT_4D_8 GAVL_RGBA_32
01559 
01562 #define GAVL_PIXELFORMAT_1D_16 GAVL_GRAY_16
01563 
01565 #define GAVL_PIXELFORMAT_2D_16 GAVL_GRAYA_32
01566 
01568 #define GAVL_PIXELFORMAT_3D_16 GAVL_RGB_48
01569 
01571 #define GAVL_PIXELFORMAT_4D_16 GAVL_RGBA_64
01572 
01575 #define GAVL_PIXELFORMAT_1D_FLOAT GAVL_GRAY_FLOAT
01576 
01578 #define GAVL_PIXELFORMAT_2D_FLOAT GAVL_GRAYA_FLOAT
01579 
01581 #define GAVL_PIXELFORMAT_3D_FLOAT GAVL_RGB_FLOAT
01582 
01584 #define GAVL_PIXELFORMAT_4D_FLOAT GAVL_RGBA_FLOAT
01585 
01586   
01587 /*
01588  *  Colormodel related functions
01589  */
01590 
01597 #define gavl_pixelformat_is_gray(fmt) ((fmt) & GAVL_PIXFMT_GRAY)
01598 
01599   
01606 #define gavl_pixelformat_is_rgb(fmt) ((fmt) & GAVL_PIXFMT_RGB)
01607 
01614 #define gavl_pixelformat_is_yuv(fmt) ((fmt) & GAVL_PIXFMT_YUV)
01615 
01622 #define gavl_pixelformat_is_jpeg_scaled(fmt) ((fmt) & GAVL_PIXFMT_YUVJ)
01623 
01630 #define gavl_pixelformat_has_alpha(fmt) ((fmt) & GAVL_PIXFMT_ALPHA)
01631 
01638 #define  gavl_pixelformat_is_planar(fmt) ((fmt) & GAVL_PIXFMT_PLANAR)
01639 
01646 int gavl_pixelformat_num_planes(gavl_pixelformat_t pixelformat);
01647 
01657 void gavl_pixelformat_chroma_sub(gavl_pixelformat_t pixelformat, int * sub_h, int * sub_v);
01658 
01665 int gavl_pixelformat_bytes_per_component(gavl_pixelformat_t pixelformat);
01666 
01673 int gavl_pixelformat_bytes_per_pixel(gavl_pixelformat_t pixelformat);
01674   
01681 int gavl_pixelformat_bits_per_pixel(gavl_pixelformat_t pixelformat);
01682 
01697 int gavl_pixelformat_conversion_penalty(gavl_pixelformat_t src,
01698                                         gavl_pixelformat_t dst);
01699 
01713 gavl_pixelformat_t 
01714 gavl_pixelformat_get_best(gavl_pixelformat_t src,
01715                           const gavl_pixelformat_t * dst_supported,
01716                           int * penalty);
01717   
01718 
01719 
01726 const char * gavl_pixelformat_to_string(gavl_pixelformat_t pixelformat);
01727 
01734 gavl_pixelformat_t gavl_string_to_pixelformat(const char * name);
01735 
01741 int gavl_num_pixelformats();
01742 
01749 gavl_pixelformat_t gavl_get_pixelformat(int index);
01750 
01751 /*  */
01752 
01761 typedef enum
01762   {
01763     GAVL_CHROMA_PLACEMENT_DEFAULT = 0, 
01764     GAVL_CHROMA_PLACEMENT_MPEG2,       
01765     GAVL_CHROMA_PLACEMENT_DVPAL        
01766   } gavl_chroma_placement_t;
01767 
01774 const char * gavl_chroma_placement_to_string(gavl_chroma_placement_t mode);
01775   
01780 typedef enum
01781   {
01782     GAVL_FRAMERATE_CONSTANT    = 0, 
01783     GAVL_FRAMERATE_VARIABLE    = 1, 
01784     GAVL_FRAMERATE_STILL       = 2, 
01785   } gavl_framerate_mode_t;
01786 
01791 typedef enum
01792   {
01793     GAVL_INTERLACE_NONE = 0,    
01794     GAVL_INTERLACE_TOP_FIRST,   
01795     GAVL_INTERLACE_BOTTOM_FIRST,
01796     GAVL_INTERLACE_MIXED        
01797   } gavl_interlace_mode_t;
01798 
01805 const char * gavl_interlace_mode_to_string(gavl_interlace_mode_t mode);
01806   
01807   
01808 /* Video format structure */
01809   
01814 struct gavl_video_format_s
01815   {
01816   int frame_width;
01817   int frame_height;
01819   int image_width;
01820   int image_height;
01822   /* Support for nonsquare pixels */
01823     
01824   int pixel_width;
01825   int pixel_height;
01827   gavl_pixelformat_t pixelformat;
01829   int frame_duration;
01831   int timescale;
01833   gavl_framerate_mode_t   framerate_mode;
01834   gavl_chroma_placement_t chroma_placement;
01836   gavl_interlace_mode_t   interlace_mode;
01838   gavl_timecode_format_t  timecode_format;
01839   };
01840 
01848 void gavl_video_format_copy(gavl_video_format_t * dst,
01849                             const gavl_video_format_t * src);
01850 
01859 int gavl_video_formats_equal(const gavl_video_format_t * format_1,
01860                              const gavl_video_format_t * format_2);
01861 
01862   
01873 void gavl_video_format_get_chroma_offset(const gavl_video_format_t * format, int field, int plane,
01874                                          float * off_x, float * off_y);
01875   
01876 
01877   
01884 void gavl_video_format_dump(const gavl_video_format_t * format);
01885 
01898 void gavl_video_format_fit_to_source(gavl_video_format_t * dst,
01899                                      const gavl_video_format_t * src);
01900 
01901   
01924 typedef struct
01925   {
01926   uint8_t * planes[GAVL_MAX_PLANES]; 
01927   int strides[GAVL_MAX_PLANES];      
01929   void * user_data;    
01930   int64_t timestamp; 
01931   int64_t duration; 
01932   gavl_interlace_mode_t   interlace_mode;
01933   gavl_timecode_t timecode; 
01934   } gavl_video_frame_t;
01935 
01936 
01948 gavl_video_frame_t * gavl_video_frame_create(const gavl_video_format_t*format);
01949 
01960 gavl_video_frame_t * gavl_video_frame_create_nopad(const gavl_video_format_t*format);
01961 
01962   
01963 
01973 void gavl_video_frame_destroy(gavl_video_frame_t*frame);
01974 
01986 void gavl_video_frame_null(gavl_video_frame_t*frame);
01987   
01996 void gavl_video_frame_clear(gavl_video_frame_t * frame,
01997                             const gavl_video_format_t * format);
01998 
02008 void gavl_video_frame_fill(gavl_video_frame_t * frame,
02009                            const gavl_video_format_t * format,
02010                            float * color);
02011 
02012   
02026 void gavl_video_frame_copy(const gavl_video_format_t * format,
02027                            gavl_video_frame_t * dst,
02028                            const gavl_video_frame_t * src);
02029 
02042 void gavl_video_frame_copy_plane(const gavl_video_format_t * format,
02043                                  gavl_video_frame_t * dst,
02044                                  const gavl_video_frame_t * src, int plane);
02045 
02057 void gavl_video_frame_copy_flip_x(const gavl_video_format_t * format,
02058                                   gavl_video_frame_t * dst,
02059                                   const gavl_video_frame_t * src);
02060 
02072 void gavl_video_frame_copy_flip_y(const gavl_video_format_t * format,
02073                                   gavl_video_frame_t * dst,
02074                                   const gavl_video_frame_t * src);
02075 
02087 void gavl_video_frame_copy_flip_xy(const gavl_video_format_t * format,
02088                                    gavl_video_frame_t * dst,
02089                                   const gavl_video_frame_t * src);
02090 
02103 void gavl_video_frame_copy_metadata(gavl_video_frame_t * dst,
02104                                     const gavl_video_frame_t * src);
02105 
02106   
02124 void gavl_video_frame_get_subframe(gavl_pixelformat_t pixelformat,
02125                                    const gavl_video_frame_t * src,
02126                                    gavl_video_frame_t * dst,
02127                                    gavl_rectangle_i_t * src_rect);
02128 
02144 void gavl_video_frame_get_field(gavl_pixelformat_t pixelformat,
02145                                 const gavl_video_frame_t * src,
02146                                 gavl_video_frame_t * dst,
02147                                 int field);
02148 
02149   
02150 
02163 void gavl_video_frame_dump(gavl_video_frame_t * frame,
02164                            const gavl_video_format_t * format,
02165                            const char * namebase);
02166 
02177 void gavl_video_frame_set_strides(gavl_video_frame_t * frame,
02178                                   const gavl_video_format_t * format);
02179 
02192 void gavl_video_frame_set_planes(gavl_video_frame_t * frame,
02193                                  const gavl_video_format_t * format,
02194                                  uint8_t * buffer);
02195 
02196   
02197 /*****************************
02198  Conversion options
02199 ******************************/
02200 
02216 #define GAVL_FORCE_DEINTERLACE (1<<0)
02217 
02222 #define GAVL_CONVOLVE_CHROMA   (1<<1)
02223 
02228 #define GAVL_CONVOLVE_NORMALIZE (1<<2)
02229 
02237 #define GAVL_RESAMPLE_CHROMA    (1<<3)
02238   
02246 typedef enum
02247   {
02248     GAVL_ALPHA_IGNORE      = 0, 
02249     GAVL_ALPHA_BLEND_COLOR      
02250   } gavl_alpha_mode_t;
02251 
02258 typedef enum
02259   {
02260     GAVL_DEINTERLACE_NONE      = 0, 
02261     GAVL_DEINTERLACE_COPY      = 1, 
02262     GAVL_DEINTERLACE_SCALE     = 2, 
02263     GAVL_DEINTERLACE_BLEND     = 3  
02264   } gavl_deinterlace_mode_t;
02265 
02272 typedef enum
02273   {
02274     GAVL_DEINTERLACE_DROP_TOP,    
02275     GAVL_DEINTERLACE_DROP_BOTTOM, 
02276   } gavl_deinterlace_drop_mode_t;
02277   
02282 typedef enum
02283   {
02284     GAVL_SCALE_AUTO,          
02285     GAVL_SCALE_NEAREST,       
02286     GAVL_SCALE_BILINEAR,      
02287     GAVL_SCALE_QUADRATIC,     
02288     GAVL_SCALE_CUBIC_BSPLINE, 
02289     GAVL_SCALE_CUBIC_MITCHELL,
02290     GAVL_SCALE_CUBIC_CATMULL, 
02291     GAVL_SCALE_SINC_LANCZOS,  
02292     GAVL_SCALE_NONE,          
02293   } gavl_scale_mode_t;
02294 
02304 typedef enum
02305   {
02306     GAVL_DOWNSCALE_FILTER_AUTO = 0, 
02307     GAVL_DOWNSCALE_FILTER_NONE, 
02308     GAVL_DOWNSCALE_FILTER_WIDE, 
02309     GAVL_DOWNSCALE_FILTER_GAUSS, 
02310   } gavl_downscale_filter_t;
02311   
02318 typedef struct gavl_video_options_s gavl_video_options_t;
02319 
02320 /* Default Options */
02321 
02327 void gavl_video_options_set_defaults(gavl_video_options_t * opt);
02328 
02338 gavl_video_options_t * gavl_video_options_create();
02339 
02346 void gavl_video_options_copy(gavl_video_options_t * dst,
02347                              const gavl_video_options_t * src);
02348 
02354 void gavl_video_options_destroy(gavl_video_options_t * opt);
02355   
02356   
02371 void gavl_video_options_set_rectangles(gavl_video_options_t * opt,
02372                                        const gavl_rectangle_f_t * src_rect,
02373                                        const gavl_rectangle_i_t * dst_rect);
02374 
02381 void gavl_video_options_get_rectangles(gavl_video_options_t * opt,
02382                                        gavl_rectangle_f_t * src_rect,
02383                                        gavl_rectangle_i_t * dst_rect);
02384   
02391 void gavl_video_options_set_quality(gavl_video_options_t * opt, int quality);
02392 
02399 int gavl_video_options_get_quality(gavl_video_options_t * opt);
02400 
02401   
02408 void gavl_video_options_set_conversion_flags(gavl_video_options_t * opt,
02409                                              int conversion_flags);
02410 
02417 int gavl_video_options_get_conversion_flags(gavl_video_options_t * opt);
02418   
02425 void gavl_video_options_set_alpha_mode(gavl_video_options_t * opt,
02426                                        gavl_alpha_mode_t alpha_mode);
02427 
02434 gavl_alpha_mode_t
02435 gavl_video_options_get_alpha_mode(gavl_video_options_t * opt);
02436 
02437   
02444 void gavl_video_options_set_scale_mode(gavl_video_options_t * opt,
02445                                        gavl_scale_mode_t scale_mode);
02446 
02453 gavl_scale_mode_t
02454 gavl_video_options_get_scale_mode(gavl_video_options_t * opt);
02455 
02456   
02463 void gavl_video_options_set_scale_order(gavl_video_options_t * opt,
02464                                         int order);
02465 
02472 int gavl_video_options_get_scale_order(gavl_video_options_t * opt);
02473 
02474   
02481 void gavl_video_options_set_background_color(gavl_video_options_t * opt,
02482                                              const float * color);
02483 
02490 void gavl_video_options_get_background_color(gavl_video_options_t * opt,
02491                                              float * color);
02492   
02499 void gavl_video_options_set_deinterlace_mode(gavl_video_options_t * opt,
02500                                              gavl_deinterlace_mode_t deinterlace_mode);
02501 
02508 gavl_deinterlace_mode_t
02509 gavl_video_options_get_deinterlace_mode(gavl_video_options_t * opt);
02510 
02517 void gavl_video_options_set_deinterlace_drop_mode(gavl_video_options_t * opt,
02518                                                   gavl_deinterlace_drop_mode_t deinterlace_drop_mode);
02519 
02526 gavl_deinterlace_drop_mode_t
02527 gavl_video_options_get_deinterlace_drop_mode(gavl_video_options_t * opt);
02528 
02537 void gavl_video_options_set_downscale_filter(gavl_video_options_t * opt,
02538                                              gavl_downscale_filter_t f);
02539   
02540 
02549 gavl_downscale_filter_t
02550 gavl_video_options_get_downscale_filter(gavl_video_options_t * opt);
02551 
02569 void gavl_video_options_set_downscale_blur(gavl_video_options_t * opt,
02570                                            float f);
02571 
02580 float gavl_video_options_get_downscale_blur(gavl_video_options_t * opt);
02581   
02582 /***************************************************
02583  * Create and destroy video converters
02584  ***************************************************/
02585   
02618 typedef struct gavl_video_converter_s gavl_video_converter_t;
02619 
02625 gavl_video_converter_t * gavl_video_converter_create();
02626 
02632 void gavl_video_converter_destroy(gavl_video_converter_t*cnv);
02633 
02634 /**************************************************
02635  * Get options. Change the options with the gavl_video_options_set_*
02636  * functions above
02637  **************************************************/
02638 
02647 gavl_video_options_t *
02648 gavl_video_converter_get_options(gavl_video_converter_t*cnv);
02649 
02650 
02664 int gavl_video_converter_init(gavl_video_converter_t* cnv,
02665                               const gavl_video_format_t * input_format,
02666                               const gavl_video_format_t * output_format);
02667 
02680 int gavl_video_converter_reinit(gavl_video_converter_t* cnv);
02681  
02682   
02683 /***************************************************
02684  * Convert a frame
02685  ***************************************************/
02686 
02694 void gavl_video_convert(gavl_video_converter_t * cnv,
02695                         const gavl_video_frame_t * input_frame,
02696                         gavl_video_frame_t * output_frame);
02697 
02729 typedef struct gavl_video_scaler_s gavl_video_scaler_t;
02730 
02736 gavl_video_scaler_t * gavl_video_scaler_create();
02737 
02743 void gavl_video_scaler_destroy(gavl_video_scaler_t * scaler);
02744 
02753 gavl_video_options_t *
02754 gavl_video_scaler_get_options(gavl_video_scaler_t * scaler);
02755 
02768 int gavl_video_scaler_init(gavl_video_scaler_t * scaler,
02769                            const gavl_video_format_t * src_format,
02770                            const gavl_video_format_t * dst_format);
02771 
02793 int gavl_video_scaler_init_convolve(gavl_video_scaler_t * scaler,
02794                                     const gavl_video_format_t * format,
02795                                     int h_radius, float * h_coeffs,
02796                                     int v_radius, float * v_coeffs);
02797   
02805 void gavl_video_scaler_scale(gavl_video_scaler_t * scaler,
02806                              const gavl_video_frame_t * input_frame,
02807                              gavl_video_frame_t * output_frame);
02808 
02824 typedef struct gavl_video_deinterlacer_s gavl_video_deinterlacer_t;
02825 
02831 gavl_video_deinterlacer_t * gavl_video_deinterlacer_create();
02832 
02838 void gavl_video_deinterlacer_destroy(gavl_video_deinterlacer_t * deinterlacer);
02839 
02848 gavl_video_options_t *
02849 gavl_video_deinterlacer_get_options(gavl_video_deinterlacer_t * deinterlacer);
02850 
02861 int gavl_video_deinterlacer_init(gavl_video_deinterlacer_t * deinterlacer,
02862                                  const gavl_video_format_t * src_format);
02863 
02864   
02872 void gavl_video_deinterlacer_deinterlace(gavl_video_deinterlacer_t * deinterlacer,
02873                                          const gavl_video_frame_t * input_frame,
02874                                          gavl_video_frame_t * output_frame);
02875 
02876   
02877   
02878 /**************************************************
02879  * Transparent overlays 
02880  **************************************************/
02881 
02882 /* Overlay struct */
02883 
02911 typedef struct
02912   {
02913   gavl_video_frame_t * frame;    
02914   gavl_rectangle_i_t ovl_rect;   
02915   int dst_x;                     
02916   int dst_y;                     
02917   } gavl_overlay_t;
02918 
02925 typedef struct gavl_overlay_blend_context_s gavl_overlay_blend_context_t;
02926 
02932 gavl_overlay_blend_context_t * gavl_overlay_blend_context_create();
02933 
02939 void gavl_overlay_blend_context_destroy(gavl_overlay_blend_context_t * ctx);
02940 
02947 gavl_video_options_t *
02948 gavl_overlay_blend_context_get_options(gavl_overlay_blend_context_t * ctx);
02949 
02965 int gavl_overlay_blend_context_init(gavl_overlay_blend_context_t * ctx,
02966                                     const gavl_video_format_t * frame_format,
02967                                     gavl_video_format_t * overlay_format);
02968 
02978 void gavl_overlay_blend_context_set_overlay(gavl_overlay_blend_context_t * ctx,
02979                                             gavl_overlay_t * ovl);
02980 
02987 void gavl_overlay_blend(gavl_overlay_blend_context_t * ctx,
02988                         gavl_video_frame_t * dst_frame);
02989 
03011 typedef struct gavl_image_transform_s gavl_image_transform_t;
03012 
03026 typedef void (*gavl_image_transform_func)(void * priv,
03027                                           double xdst,
03028                                           double ydst,
03029                                           double * xsrc,
03030                                           double * ysrc);
03031 
03032 
03039 gavl_image_transform_t * gavl_image_transform_create();
03040 
03046 void gavl_image_transform_destroy(gavl_image_transform_t * t);
03047 
03057 void gavl_image_transform_init(gavl_image_transform_t * t,
03058                                gavl_video_format_t * format,
03059                                gavl_image_transform_func func, void * priv);
03060 
03068 void gavl_image_transform_transform(gavl_image_transform_t * t,
03069                                     gavl_video_frame_t * in_frame,
03070                                     gavl_video_frame_t * out_frame);
03071 
03082 gavl_video_options_t *
03083 gavl_image_transform_get_options(gavl_image_transform_t * t);
03084   
03089 #pragma GCC visibility pop
03090   
03091 #ifdef __cplusplus
03092 }
03093 #endif
03094 
03095 #endif /* GAVL_H_INCLUDED */

Generated on Wed Apr 8 07:12:50 2009 for gavl by  doxygen 1.5.8