vlc_picture.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * vlc_picture.h: picture definitions
00003  *****************************************************************************
00004  * Copyright (C) 1999 - 2009 the VideoLAN team
00005  * $Id: b0fe6e4d7ac397c37af6417af73d78de80e6a59c $
00006  *
00007  * Authors: Vincent Seguin <seguin@via.ecp.fr>
00008  *          Samuel Hocevar <sam@via.ecp.fr>
00009  *          Olivier Aubert <oaubert 47 videolan d07 org>
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00024  *****************************************************************************/
00025 
00026 #ifndef VLC_PICTURE_H
00027 #define VLC_PICTURE_H 1
00028 
00029 /**
00030  * \file
00031  * This file defines picture structures and functions in vlc
00032  */
00033 
00034 #include <vlc_es.h>
00035 
00036 /** Description of a planar graphic field */
00037 typedef struct plane_t
00038 {
00039     uint8_t *p_pixels;                        /**< Start of the plane's data */
00040 
00041     /* Variables used for fast memcpy operations */
00042     int i_lines;           /**< Number of lines, including margins */
00043     int i_pitch;           /**< Number of bytes in a line, including margins */
00044 
00045     /** Size of a macropixel, defaults to 1 */
00046     int i_pixel_pitch;
00047 
00048     /* Variables used for pictures with margins */
00049     int i_visible_lines;            /**< How many visible lines are there ? */
00050     int i_visible_pitch;            /**< How many visible pixels are there ? */
00051 
00052 } plane_t;
00053 
00054 /**
00055  * Maximum number of plane for a picture
00056  */
00057 #define PICTURE_PLANE_MAX (VOUT_MAX_PLANES)
00058 
00059 /**
00060  * A private definition to help overloading picture release
00061  */
00062 typedef struct picture_release_sys_t picture_release_sys_t;
00063 
00064 /**
00065  * Video picture
00066  */
00067 struct picture_t
00068 {
00069     /**
00070      * The properties of the picture
00071      */
00072     video_frame_format_t format;
00073 
00074     void           *p_data_orig;                /**< pointer before memalign */
00075     plane_t         p[PICTURE_PLANE_MAX];     /**< description of the planes */
00076     int             i_planes;                /**< number of allocated planes */
00077 
00078     /** \name Picture management properties
00079      * These properties can be modified using the video output thread API,
00080      * but should never be written directly */
00081     /**@{*/
00082     unsigned        i_refcount;                  /**< link reference counter */
00083     mtime_t         date;                                  /**< display date */
00084     bool            b_force;
00085     /**@}*/
00086 
00087     /** \name Picture dynamic properties
00088      * Those properties can be changed by the decoder
00089      * @{
00090      */
00091     bool            b_progressive;          /**< is it a progressive frame ? */
00092     bool            b_top_field_first;             /**< which field is first */
00093     unsigned int    i_nb_fields;                  /**< # of displayed fields */
00094     int8_t         *p_q;                           /**< quantification table */
00095     int             i_qstride;                    /**< quantification stride */
00096     int             i_qtype;                       /**< quantification style */
00097     /**@}*/
00098 
00099     /** Private data - the video output plugin might want to put stuff here to
00100      * keep track of the picture */
00101     picture_sys_t * p_sys;
00102 
00103     /** This way the picture_Release can be overloaded */
00104     void (*pf_release)( picture_t * );
00105     picture_release_sys_t *p_release_sys;
00106 
00107     /** Next picture in a FIFO a pictures */
00108     struct picture_t *p_next;
00109 };
00110 
00111 /**
00112  * This function will create a new picture.
00113  * The picture created will implement a default release management compatible
00114  * with picture_Hold and picture_Release. This default management will release
00115  * p_sys, p_q, p_data_orig fields if non NULL.
00116  */
00117 VLC_EXPORT( picture_t *, picture_New, ( vlc_fourcc_t i_chroma, int i_width, int i_height, int i_sar_num, int i_sar_den ) LIBVLC_USED );
00118 
00119 /**
00120  * This function will create a new picture using the given format.
00121  *
00122  * When possible, it is preferred to use this function over picture_New
00123  * as more information about the format is kept.
00124  */
00125 VLC_EXPORT( picture_t *, picture_NewFromFormat, ( const video_format_t *p_fmt ) LIBVLC_USED );
00126 
00127 /**
00128  * Resource for a picture.
00129  */
00130 typedef struct
00131 {
00132     picture_sys_t *p_sys;
00133 
00134     /* Plane resources
00135      * XXX all fields MUST be set to the right value.
00136      */
00137     struct
00138     {
00139         uint8_t *p_pixels;  /**< Start of the plane's data */
00140         int i_lines;        /**< Number of lines, including margins */
00141         int i_pitch;        /**< Number of bytes in a line, including margins */
00142     } p[PICTURE_PLANE_MAX];
00143 
00144 } picture_resource_t;
00145 
00146 /**
00147  * This function will create a new picture using the provided resource.
00148  *
00149  * If the resource is NULL then a plain picture_NewFromFormat is returned.
00150  */
00151 VLC_EXPORT( picture_t *, picture_NewFromResource, ( const video_format_t *, const picture_resource_t * ) LIBVLC_USED );
00152 
00153 /**
00154  * This function will force the destruction a picture.
00155  * The value of the picture reference count should be 0 before entering this
00156  * function.
00157  * Unless used for reimplementing pf_release, you should not use this
00158  * function but picture_Release.
00159  */
00160 VLC_EXPORT( void, picture_Delete, ( picture_t * ) );
00161 
00162 /**
00163  * This function will increase the picture reference count.
00164  * It will not have any effect on picture obtained from vout
00165  *
00166  * It returns the given picture for convenience.
00167  */
00168 static inline picture_t *picture_Hold( picture_t *p_picture )
00169 {
00170     if( p_picture->pf_release )
00171         p_picture->i_refcount++;
00172     return p_picture;
00173 }
00174 /**
00175  * This function will release a picture.
00176  * It will not have any effect on picture obtained from vout
00177  */
00178 static inline void picture_Release( picture_t *p_picture )
00179 {
00180     /* FIXME why do we let pf_release handle the i_refcount ? */
00181     if( p_picture->pf_release )
00182         p_picture->pf_release( p_picture );
00183 }
00184 
00185 /**
00186  * This function will return true if you are not the only owner of the
00187  * picture.
00188  *
00189  * It is only valid if it is created using picture_New.
00190  */
00191 static inline bool picture_IsReferenced( picture_t *p_picture )
00192 {
00193     return p_picture->i_refcount > 1;
00194 }
00195 
00196 /**
00197  * Cleanup quantization matrix data and set to 0
00198  */
00199 static inline void picture_CleanupQuant( picture_t *p_pic )
00200 {
00201     free( p_pic->p_q );
00202     p_pic->p_q = NULL;
00203     p_pic->i_qstride = 0;
00204     p_pic->i_qtype = 0;
00205 }
00206 
00207 /**
00208  * This function will copy all picture dynamic properties.
00209  */
00210 static inline void picture_CopyProperties( picture_t *p_dst, const picture_t *p_src )
00211 {
00212     p_dst->date = p_src->date;
00213     p_dst->b_force = p_src->b_force;
00214 
00215     p_dst->b_progressive = p_src->b_progressive;
00216     p_dst->i_nb_fields = p_src->i_nb_fields;
00217     p_dst->b_top_field_first = p_src->b_top_field_first;
00218 
00219     /* FIXME: copy ->p_q and ->p_qstride */
00220 }
00221 
00222 /**
00223  * This function will reset a picture information (properties and quantizers).
00224  * It is sometimes useful for reusing pictures (like from a pool).
00225  */
00226 VLC_EXPORT( void, picture_Reset, ( picture_t * ) );
00227 
00228 /**
00229  * This function will copy the picture pixels.
00230  * You can safely copy between pictures that do not have the same size,
00231  * only the compatible(smaller) part will be copied.
00232  */
00233 VLC_EXPORT( void, picture_CopyPixels, ( picture_t *p_dst, const picture_t *p_src ) );
00234 VLC_EXPORT( void, plane_CopyPixels, ( plane_t *p_dst, const plane_t *p_src ) );
00235 
00236 /**
00237  * This function will copy both picture dynamic properties and pixels.
00238  * You have to notice that sometime a simple picture_Hold may do what
00239  * you want without the copy overhead.
00240  * Provided for convenience.
00241  *
00242  * \param p_dst pointer to the destination picture.
00243  * \param p_src pointer to the source picture.
00244  */
00245 static inline void picture_Copy( picture_t *p_dst, const picture_t *p_src )
00246 {
00247     picture_CopyPixels( p_dst, p_src );
00248     picture_CopyProperties( p_dst, p_src );
00249 }
00250 
00251 /**
00252  * This function will export a picture to an encoded bitstream.
00253  *
00254  * pp_image will contain the encoded bitstream in psz_format format.
00255  *
00256  * p_fmt can be NULL otherwise it will be set with the format used for the
00257  * picture before encoding.
00258  *
00259  * i_override_width/height allow to override the width and/or the height of the
00260  * picture to be encoded:
00261  *  - if strictly lower than 0, the original dimension will be used.
00262  *  - if equal to 0, it will be deduced from the other dimension which must be
00263  *  different to 0.
00264  *  - if strictly higher than 0, it will override the dimension.
00265  * If at most one of them is > 0 then the picture aspect ratio will be kept.
00266  */
00267 VLC_EXPORT( int, picture_Export, ( vlc_object_t *p_obj, block_t **pp_image, video_format_t *p_fmt, picture_t *p_picture, vlc_fourcc_t i_format, int i_override_width, int i_override_height ) );
00268 
00269 /**
00270  * This function will setup all fields of a picture_t without allocating any
00271  * memory.
00272  * XXX The memory must already be initialized.
00273  * It does not need to be released.
00274  *
00275  * It will return VLC_EGENERIC if the core does not understand the requested
00276  * format.
00277  *
00278  * It can be useful to get the properties of planes.
00279  */
00280 VLC_EXPORT( int, picture_Setup, ( picture_t *, vlc_fourcc_t i_chroma, int i_width, int i_height, int i_sar_num, int i_sar_den ) );
00281 
00282 /*****************************************************************************
00283  * Flags used to describe the status of a picture
00284  *****************************************************************************/
00285 
00286 /* Quantification type */
00287 enum
00288 {
00289     QTYPE_NONE,
00290 
00291     QTYPE_MPEG1,
00292     QTYPE_MPEG2,
00293     QTYPE_H264,
00294 };
00295 
00296 /*****************************************************************************
00297  * Shortcuts to access image components
00298  *****************************************************************************/
00299 
00300 /* Plane indices */
00301 enum
00302 {
00303     Y_PLANE = 0,
00304     U_PLANE = 1,
00305     V_PLANE = 2,
00306     A_PLANE = 3,
00307 };
00308 
00309 /* Shortcuts */
00310 #define Y_PIXELS     p[Y_PLANE].p_pixels
00311 #define Y_PITCH      p[Y_PLANE].i_pitch
00312 #define U_PIXELS     p[U_PLANE].p_pixels
00313 #define U_PITCH      p[U_PLANE].i_pitch
00314 #define V_PIXELS     p[V_PLANE].p_pixels
00315 #define V_PITCH      p[V_PLANE].i_pitch
00316 #define A_PIXELS     p[A_PLANE].p_pixels
00317 #define A_PITCH      p[A_PLANE].i_pitch
00318 
00319 /**@}*/
00320 
00321 #endif /* VLC_PICTURE_H */

Generated on Mon Nov 22 07:55:20 2010 for VLC by  doxygen 1.5.6