vlc_picture.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * vlc_picture.h: picture definitions
00003  *****************************************************************************
00004  * Copyright (C) 1999 - 2009 VLC authors and VideoLAN
00005  * $Id: b58fbed3578725d5a6c90bbfe608f03505ff97f0 $
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 it
00012  * under the terms of the GNU Lesser General Public License as published by
00013  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public License
00022  * along with this program; if not, write to the Free Software Foundation,
00023  * 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 /**
00061  * A private definition to help overloading picture release
00062  */
00063 typedef struct picture_gc_sys_t picture_gc_sys_t;
00064 
00065 /**
00066  * Video picture
00067  */
00068 struct picture_t
00069 {
00070     /**
00071      * The properties of the picture
00072      */
00073     video_frame_format_t format;
00074 
00075     void           *p_data_orig;                /**< pointer before memalign */
00076     plane_t         p[PICTURE_PLANE_MAX];     /**< description of the planes */
00077     int             i_planes;                /**< number of allocated planes */
00078 
00079     /** \name Picture management properties
00080      * These properties can be modified using the video output thread API,
00081      * but should never be written directly */
00082     /**@{*/
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     struct
00105     {
00106         vlc_atomic_t refcount;
00107         void (*pf_destroy)( picture_t * );
00108         picture_gc_sys_t *p_sys;
00109     } gc;
00110 
00111     /** Next picture in a FIFO a pictures */
00112     struct picture_t *p_next;
00113 };
00114 
00115 /**
00116  * This function will create a new picture.
00117  * The picture created will implement a default release management compatible
00118  * with picture_Hold and picture_Release. This default management will release
00119  * p_sys, p_q, p_data_orig fields if non NULL.
00120  */
00121 VLC_API picture_t * picture_New( vlc_fourcc_t i_chroma, int i_width, int i_height, int i_sar_num, int i_sar_den ) VLC_USED;
00122 
00123 /**
00124  * This function will create a new picture using the given format.
00125  *
00126  * When possible, it is preferred to use this function over picture_New
00127  * as more information about the format is kept.
00128  */
00129 VLC_API picture_t * picture_NewFromFormat( const video_format_t *p_fmt ) VLC_USED;
00130 
00131 /**
00132  * Resource for a picture.
00133  */
00134 typedef struct
00135 {
00136     picture_sys_t *p_sys;
00137 
00138     /* Plane resources
00139      * XXX all fields MUST be set to the right value.
00140      */
00141     struct
00142     {
00143         uint8_t *p_pixels;  /**< Start of the plane's data */
00144         int i_lines;        /**< Number of lines, including margins */
00145         int i_pitch;        /**< Number of bytes in a line, including margins */
00146     } p[PICTURE_PLANE_MAX];
00147 
00148 } picture_resource_t;
00149 
00150 /**
00151  * This function will create a new picture using the provided resource.
00152  *
00153  * If the resource is NULL then a plain picture_NewFromFormat is returned.
00154  */
00155 VLC_API picture_t * picture_NewFromResource( const video_format_t *, const picture_resource_t * ) VLC_USED;
00156 
00157 /**
00158  * This function will increase the picture reference count.
00159  * It will not have any effect on picture obtained from vout
00160  *
00161  * It returns the given picture for convenience.
00162  */
00163 VLC_API picture_t *picture_Hold( picture_t *p_picture );
00164 
00165 /**
00166  * This function will release a picture.
00167  * It will not have any effect on picture obtained from vout
00168  */
00169 VLC_API void picture_Release( picture_t *p_picture );
00170 
00171 /**
00172  * This function will return true if you are not the only owner of the
00173  * picture.
00174  *
00175  * It is only valid if it is created using picture_New.
00176  */
00177 VLC_API bool picture_IsReferenced( picture_t *p_picture );
00178 
00179 /**
00180  * This function will copy all picture dynamic properties.
00181  */
00182 VLC_API void picture_CopyProperties( picture_t *p_dst, const picture_t *p_src );
00183 
00184 /**
00185  * This function will reset a picture information (properties and quantizers).
00186  * It is sometimes useful for reusing pictures (like from a pool).
00187  */
00188 VLC_API void picture_Reset( picture_t * );
00189 
00190 /**
00191  * This function will copy the picture pixels.
00192  * You can safely copy between pictures that do not have the same size,
00193  * only the compatible(smaller) part will be copied.
00194  */
00195 VLC_API void picture_CopyPixels( picture_t *p_dst, const picture_t *p_src );
00196 VLC_API void plane_CopyPixels( plane_t *p_dst, const plane_t *p_src );
00197 
00198 /**
00199  * This function will copy both picture dynamic properties and pixels.
00200  * You have to notice that sometime a simple picture_Hold may do what
00201  * you want without the copy overhead.
00202  * Provided for convenience.
00203  *
00204  * \param p_dst pointer to the destination picture.
00205  * \param p_src pointer to the source picture.
00206  */
00207 VLC_API void picture_Copy( picture_t *p_dst, const picture_t *p_src );
00208 
00209 /**
00210  * This function will export a picture to an encoded bitstream.
00211  *
00212  * pp_image will contain the encoded bitstream in psz_format format.
00213  *
00214  * p_fmt can be NULL otherwise it will be set with the format used for the
00215  * picture before encoding.
00216  *
00217  * i_override_width/height allow to override the width and/or the height of the
00218  * picture to be encoded:
00219  *  - if strictly lower than 0, the original dimension will be used.
00220  *  - if equal to 0, it will be deduced from the other dimension which must be
00221  *  different to 0.
00222  *  - if strictly higher than 0, it will override the dimension.
00223  * If at most one of them is > 0 then the picture aspect ratio will be kept.
00224  */
00225 VLC_API 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 );
00226 
00227 /**
00228  * This function will setup all fields of a picture_t without allocating any
00229  * memory.
00230  * XXX The memory must already be initialized.
00231  * It does not need to be released.
00232  *
00233  * It will return VLC_EGENERIC if the core does not understand the requested
00234  * format.
00235  *
00236  * It can be useful to get the properties of planes.
00237  */
00238 VLC_API int picture_Setup( picture_t *, vlc_fourcc_t i_chroma, int i_width, int i_height, int i_sar_num, int i_sar_den );
00239 
00240 
00241 /**
00242  * This function will blend a given subpicture onto a picture.
00243  *
00244  * The subpicture and all its region must:
00245  *  - be absolute.
00246  *  - not be ephemere.
00247  *  - not have the fade flag.
00248  *  - contains only picture (no text rendering).
00249  */
00250 VLC_API void picture_BlendSubpicture( picture_t *, filter_t *p_blend, subpicture_t * );
00251 
00252 
00253 /*****************************************************************************
00254  * Flags used to describe the status of a picture
00255  *****************************************************************************/
00256 
00257 /* Quantification type */
00258 enum
00259 {
00260     QTYPE_NONE,
00261 
00262     QTYPE_MPEG1,
00263     QTYPE_MPEG2,
00264     QTYPE_H264,
00265 };
00266 
00267 /*****************************************************************************
00268  * Shortcuts to access image components
00269  *****************************************************************************/
00270 
00271 /* Plane indices */
00272 enum
00273 {
00274     Y_PLANE = 0,
00275     U_PLANE = 1,
00276     V_PLANE = 2,
00277     A_PLANE = 3,
00278 };
00279 
00280 /* Shortcuts */
00281 #define Y_PIXELS     p[Y_PLANE].p_pixels
00282 #define Y_PITCH      p[Y_PLANE].i_pitch
00283 #define U_PIXELS     p[U_PLANE].p_pixels
00284 #define U_PITCH      p[U_PLANE].i_pitch
00285 #define V_PIXELS     p[V_PLANE].p_pixels
00286 #define V_PITCH      p[V_PLANE].i_pitch
00287 #define A_PIXELS     p[A_PLANE].p_pixels
00288 #define A_PITCH      p[A_PLANE].i_pitch
00289 
00290 /**@}*/
00291 
00292 #endif /* VLC_PICTURE_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines