]> git.sesse.net Git - vlc/blob - include/vlc_picture.h
Merge commit 'origin/1.0-bugfix'
[vlc] / include / vlc_picture.h
1 /*****************************************************************************
2  * vlc_picture.h: picture definitions
3  *****************************************************************************
4  * Copyright (C) 1999 - 2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Vincent Seguin <seguin@via.ecp.fr>
8  *          Samuel Hocevar <sam@via.ecp.fr>
9  *          Olivier Aubert <oaubert 47 videolan d07 org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #ifndef VLC_PICTURE_H
27 #define VLC_PICTURE_H 1
28
29 /**
30  * \file
31  * This file defines picture structures and functions in vlc
32  */
33
34 #include <vlc_es.h>
35
36 /** Description of a planar graphic field */
37 typedef struct plane_t
38 {
39     uint8_t *p_pixels;                        /**< Start of the plane's data */
40
41     /* Variables used for fast memcpy operations */
42     int i_lines;           /**< Number of lines, including margins */
43     int i_pitch;           /**< Number of bytes in a line, including margins */
44
45     /** Size of a macropixel, defaults to 1 */
46     int i_pixel_pitch;
47
48     /* Variables used for pictures with margins */
49     int i_visible_lines;            /**< How many visible lines are there ? */
50     int i_visible_pitch;            /**< How many visible pixels are there ? */
51
52 } plane_t;
53
54 /**
55  * A private definition to help overloading picture release
56  */
57 typedef struct picture_release_sys_t picture_release_sys_t;
58
59 /**
60  * Video picture
61  *
62  * Any picture destined to be displayed by a video output thread should be
63  * stored in this structure from it's creation to it's effective display.
64  * Picture type and flags should only be modified by the output thread. Note
65  * that an empty picture MUST have its flags set to 0.
66  */
67 struct picture_t
68 {
69     /**
70      * The properties of the picture
71      */
72     video_frame_format_t format;
73
74     /** Picture data - data can always be freely modified, but p_data may
75      * NEVER be modified. A direct buffer can be handled as the plugin
76      * wishes, it can even swap p_pixels buffers. */
77     uint8_t        *p_data;
78     void           *p_data_orig;                /**< pointer before memalign */
79     plane_t         p[ VOUT_MAX_PLANES ];     /**< description of the planes */
80     int             i_planes;                /**< number of allocated planes */
81
82     /** \name Type and flags
83      * Should NOT be modified except by the vout thread
84      * @{*/
85     int             i_status;                             /**< picture flags */
86     int             i_type;                /**< is picture a direct buffer ? */
87     bool            b_slow;                 /**< is picture in slow memory ? */
88     /**@}*/
89
90     /** \name Picture management properties
91      * These properties can be modified using the video output thread API,
92      * but should never be written directly */
93     /**@{*/
94     unsigned        i_refcount;                  /**< link reference counter */
95     mtime_t         date;                                  /**< display date */
96     bool            b_force;
97     /**@}*/
98
99     /** \name Picture dynamic properties
100      * Those properties can be changed by the decoder
101      * @{
102      */
103     bool            b_progressive;          /**< is it a progressive frame ? */
104     unsigned int    i_nb_fields;                  /**< # of displayed fields */
105     bool            b_top_field_first;             /**< which field is first */
106     uint8_t        *p_q;                           /**< quantification table */
107     int             i_qstride;                    /**< quantification stride */
108     int             i_qtype;                       /**< quantification style */
109     /**@}*/
110
111     /* Some vouts require the picture to be locked before it can be modified */
112     int (* pf_lock) ( vout_thread_t *, picture_t * );
113     int (* pf_unlock) ( vout_thread_t *, picture_t * );
114
115     /** Private data - the video output plugin might want to put stuff here to
116      * keep track of the picture */
117     picture_sys_t * p_sys;
118
119     /** This way the picture_Release can be overloaded */
120     void (*pf_release)( picture_t * );
121     picture_release_sys_t *p_release_sys;
122
123     /** Next picture in a FIFO a pictures */
124     struct picture_t *p_next;
125 };
126
127 /**
128  * This function will create a new picture.
129  * The picture created will implement a default release management compatible
130  * with picture_Hold and picture_Release. This default management will release
131  * p_sys, p_q, p_data_orig fields if non NULL.
132  */
133 VLC_EXPORT( picture_t *, picture_New, ( vlc_fourcc_t i_chroma, int i_width, int i_height, int i_aspect ) );
134
135 /**
136  * This function will force the destruction a picture.
137  * The value of the picture reference count should be 0 before entering this
138  * function.
139  * Unless used for reimplementing pf_release, you should not use this
140  * function but picture_Release.
141  */
142 VLC_EXPORT( void, picture_Delete, ( picture_t * ) );
143
144 /**
145  * This function will increase the picture reference count.
146  * It will not have any effect on picture obtained from vout
147  */
148 static inline void picture_Hold( picture_t *p_picture )
149 {
150     if( p_picture->pf_release )
151         p_picture->i_refcount++;
152 }
153 /**
154  * This function will release a picture.
155  * It will not have any effect on picture obtained from vout
156  */
157 static inline void picture_Release( picture_t *p_picture )
158 {
159     /* FIXME why do we let pf_release handle the i_refcount ? */
160     if( p_picture->pf_release )
161         p_picture->pf_release( p_picture );
162 }
163
164 /**
165  * This function will return true if you are not the only owner of the
166  * picture.
167  *
168  * It is only valid if it is created using picture_New.
169  */
170 static inline bool picture_IsReferenced( picture_t *p_picture )
171 {
172     return p_picture->i_refcount > 1;
173 }
174
175 /**
176  * Cleanup quantization matrix data and set to 0
177  */
178 static inline void picture_CleanupQuant( picture_t *p_pic )
179 {
180     free( p_pic->p_q );
181     p_pic->p_q = NULL;
182     p_pic->i_qstride = 0;
183     p_pic->i_qtype = 0;
184 }
185
186 /**
187  * This function will copy all picture dynamic properties.
188  */
189 static inline void picture_CopyProperties( picture_t *p_dst, const picture_t *p_src )
190 {
191     p_dst->date = p_src->date;
192     p_dst->b_force = p_src->b_force;
193
194     p_dst->b_progressive = p_src->b_progressive;
195     p_dst->i_nb_fields = p_src->i_nb_fields;
196     p_dst->b_top_field_first = p_src->b_top_field_first;
197
198     /* FIXME: copy ->p_q and ->p_qstride */
199 }
200
201 /**
202  * This function will copy the picture pixels.
203  * You can safely copy between pictures that do not have the same size,
204  * only the compatible(smaller) part will be copied.
205  */
206 VLC_EXPORT( void, picture_CopyPixels, ( picture_t *p_dst, const picture_t *p_src ) );
207 VLC_EXPORT( void, plane_CopyPixels, ( plane_t *p_dst, const plane_t *p_src ) );
208
209 /**
210  * This function will copy both picture dynamic properties and pixels.
211  * You have to notice that sometime a simple picture_Hold may do what
212  * you want without the copy overhead.
213  * Provided for convenience.
214  *
215  * \param p_dst pointer to the destination picture.
216  * \param p_src pointer to the source picture.
217  */
218 static inline void picture_Copy( picture_t *p_dst, const picture_t *p_src )
219 {
220     picture_CopyPixels( p_dst, p_src );
221     picture_CopyProperties( p_dst, p_src );
222 }
223
224 /**
225  * This function will export a picture to an encoded bitstream.
226  *
227  * pp_image will contain the encoded bitstream in psz_format format.
228  *
229  * p_fmt can be NULL otherwise it will be set with the format used for the
230  * picture before encoding.
231  *
232  * i_override_width/height allow to override the width and/or the height of the
233  * picture to be encoded. If at most one of them is > 0 then the picture aspect
234  * ratio will be kept.
235  */
236 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 ) );
237
238 /**
239  * This function will setup all fields of a picture_t without allocating any
240  * memory.
241  * XXX The memory must already be initialized.
242  * It does not need to be released.
243  *
244  * It will return VLC_EGENERIC if the core does not understand the requested
245  * format.
246  *
247  * It can be usefull to get the properties of planes.
248  */
249 VLC_EXPORT( int, picture_Setup, ( picture_t *, vlc_fourcc_t i_chroma, int i_width, int i_height, int i_aspect ) );
250
251 /*****************************************************************************
252  * Flags used to describe the status of a picture
253  *****************************************************************************/
254
255 /* Picture type
256  * FIXME are the values meaningfull ? */
257 enum
258 {
259     EMPTY_PICTURE = 0,                             /* empty buffer */
260     MEMORY_PICTURE = 100,                 /* heap-allocated buffer */
261     DIRECT_PICTURE = 200,                         /* direct buffer */
262 };
263
264 /* Picture status */
265 enum
266 {
267     FREE_PICTURE,                              /* free and not allocated */
268     RESERVED_PICTURE,                          /* allocated and reserved */
269     READY_PICTURE,                                  /* ready for display */
270     DISPLAYED_PICTURE,                   /* been displayed but is linked */
271     DESTROYED_PICTURE,                     /* allocated but no more used */
272 };
273
274 /* Quantification type */
275 enum
276 {
277     QTYPE_NONE,
278
279     QTYPE_MPEG1,
280     QTYPE_MPEG2,
281     QTYPE_H264,
282 };
283
284 /*****************************************************************************
285  * Shortcuts to access image components
286  *****************************************************************************/
287
288 /* Plane indices */
289 enum
290 {
291     Y_PLANE = 0,
292     U_PLANE = 1,
293     V_PLANE = 2,
294     A_PLANE = 3,
295 };
296
297 /* Shortcuts */
298 #define Y_PIXELS     p[Y_PLANE].p_pixels
299 #define Y_PITCH      p[Y_PLANE].i_pitch
300 #define U_PIXELS     p[U_PLANE].p_pixels
301 #define U_PITCH      p[U_PLANE].i_pitch
302 #define V_PIXELS     p[V_PLANE].p_pixels
303 #define V_PITCH      p[V_PLANE].i_pitch
304 #define A_PIXELS     p[A_PLANE].p_pixels
305 #define A_PITCH      p[A_PLANE].i_pitch
306
307 /**@}*/
308
309 #endif /* VLC_PICTURE_H */