]> git.sesse.net Git - vlc/blob - include/vlc_picture.h
Split vlc_vout.h into vlc_picture.h and vlc_subpicture.h
[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  * Video picture
56  *
57  * Any picture destined to be displayed by a video output thread should be
58  * stored in this structure from it's creation to it's effective display.
59  * Picture type and flags should only be modified by the output thread. Note
60  * that an empty picture MUST have its flags set to 0.
61  */
62 struct picture_t
63 {
64     /**
65      * The properties of the picture
66      */
67     video_frame_format_t format;
68
69     /** Picture data - data can always be freely modified, but p_data may
70      * NEVER be modified. A direct buffer can be handled as the plugin
71      * wishes, it can even swap p_pixels buffers. */
72     uint8_t        *p_data;
73     void           *p_data_orig;                /**< pointer before memalign */
74     plane_t         p[ VOUT_MAX_PLANES ];     /**< description of the planes */
75     int             i_planes;                /**< number of allocated planes */
76
77     /** \name Type and flags
78      * Should NOT be modified except by the vout thread
79      * @{*/
80     int             i_status;                             /**< picture flags */
81     int             i_type;                /**< is picture a direct buffer ? */
82     bool            b_slow;                 /**< is picture in slow memory ? */
83     /**@}*/
84
85     /** \name Picture management properties
86      * These properties can be modified using the video output thread API,
87      * but should never be written directly */
88     /**@{*/
89     unsigned        i_refcount;                  /**< link reference counter */
90     mtime_t         date;                                  /**< display date */
91     bool            b_force;
92     /**@}*/
93
94     /** \name Picture dynamic properties
95      * Those properties can be changed by the decoder
96      * @{
97      */
98     bool            b_progressive;          /**< is it a progressive frame ? */
99     unsigned int    i_nb_fields;                  /**< # of displayed fields */
100     bool            b_top_field_first;             /**< which field is first */
101     uint8_t        *p_q;                           /**< quantification table */
102     int             i_qstride;                    /**< quantification stride */
103     int             i_qtype;                       /**< quantification style */
104     /**@}*/
105
106     /** The picture heap we are attached to */
107     picture_heap_t* p_heap;
108
109     /* Some vouts require the picture to be locked before it can be modified */
110     int (* pf_lock) ( vout_thread_t *, picture_t * );
111     int (* pf_unlock) ( vout_thread_t *, picture_t * );
112
113     /** Private data - the video output plugin might want to put stuff here to
114      * keep track of the picture */
115     picture_sys_t * p_sys;
116
117     /** This way the picture_Release can be overloaded */
118     void (*pf_release)( picture_t * );
119
120     /** Next picture in a FIFO a pictures */
121     struct picture_t *p_next;
122 };
123
124 /**
125  * This function will create a new picture.
126  * The picture created will implement a default release management compatible
127  * with picture_Hold and picture_Release. This default management will release
128  * picture_sys_t *p_sys field if non NULL.
129  */
130 VLC_EXPORT( picture_t *, picture_New, ( vlc_fourcc_t i_chroma, int i_width, int i_height, int i_aspect ) );
131
132 /**
133  * This function will force the destruction a picture.
134  * The value of the picture reference count should be 0 before entering this
135  * function.
136  * Unless used for reimplementing pf_release, you should not use this
137  * function but picture_Release.
138  */
139 VLC_EXPORT( void, picture_Delete, ( picture_t * ) );
140
141 /**
142  * This function will increase the picture reference count.
143  * It will not have any effect on picture obtained from vout
144  */
145 static inline void picture_Hold( picture_t *p_picture )
146 {
147     if( p_picture->pf_release )
148         p_picture->i_refcount++;
149 }
150 /**
151  * This function will release a picture.
152  * It will not have any effect on picture obtained from vout
153  */
154 static inline void picture_Release( picture_t *p_picture )
155 {
156     /* FIXME why do we let pf_release handle the i_refcount ? */
157     if( p_picture->pf_release )
158         p_picture->pf_release( p_picture );
159 }
160
161 /**
162  * Cleanup quantization matrix data and set to 0
163  */
164 static inline void picture_CleanupQuant( picture_t *p_pic )
165 {
166     free( p_pic->p_q );
167     p_pic->p_q = NULL;
168     p_pic->i_qstride = 0;
169     p_pic->i_qtype = 0;
170 }
171
172 /**
173  * This function will copy all picture dynamic properties.
174  */
175 static inline void picture_CopyProperties( picture_t *p_dst, const picture_t *p_src )
176 {
177     p_dst->date = p_src->date;
178     p_dst->b_force = p_src->b_force;
179
180     p_dst->b_progressive = p_src->b_progressive;
181     p_dst->i_nb_fields = p_src->i_nb_fields;
182     p_dst->b_top_field_first = p_src->b_top_field_first;
183
184     /* FIXME: copy ->p_q and ->p_qstride */
185 }
186
187 /**
188  * This function will copy the picture pixels.
189  * You can safely copy between pictures that do not have the same size,
190  * only the compatible(smaller) part will be copied.
191  */
192 VLC_EXPORT( void, picture_CopyPixels, ( picture_t *p_dst, const picture_t *p_src ) );
193 VLC_EXPORT( void, plane_CopyPixels, ( plane_t *p_dst, const plane_t *p_src ) );
194
195 /**
196  * This function will copy both picture dynamic properties and pixels.
197  * You have to notice that sometime a simple picture_Hold may do what
198  * you want without the copy overhead.
199  * Provided for convenience.
200  *
201  * \param p_dst pointer to the destination picture.
202  * \param p_src pointer to the source picture.
203  */
204 static inline void picture_Copy( picture_t *p_dst, const picture_t *p_src )
205 {
206     picture_CopyPixels( p_dst, p_src );
207     picture_CopyProperties( p_dst, p_src );
208 }
209
210 /**
211  * This function will export a picture to an encoded bitstream.
212  *
213  * pp_image will contain the encoded bitstream in psz_format format.
214  *
215  * p_fmt can be NULL otherwise it will be set with the format used for the
216  * picture before encoding.
217  *
218  * i_override_width/height allow to override the width and/or the height of the
219  * picture to be encoded. If at most one of them is > 0 then the picture aspect
220  * ratio will be kept.
221  */
222 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 ) );
223
224 /*****************************************************************************
225  * Flags used to describe the status of a picture
226  *****************************************************************************/
227
228 /* Picture type
229  * FIXME are the values meaningfull ? */
230 enum
231 {
232     EMPTY_PICTURE = 0,                             /* empty buffer */
233     MEMORY_PICTURE = 100,                 /* heap-allocated buffer */
234     DIRECT_PICTURE = 200,                         /* direct buffer */
235 };
236
237 /* Picture status */
238 enum
239 {
240     FREE_PICTURE,                              /* free and not allocated */
241     RESERVED_PICTURE,                          /* allocated and reserved */
242     READY_PICTURE,                                  /* ready for display */
243     DISPLAYED_PICTURE,                   /* been displayed but is linked */
244     DESTROYED_PICTURE,                     /* allocated but no more used */
245 };
246
247 /* Quantification type */
248 enum
249 {
250     QTYPE_NONE,
251
252     QTYPE_MPEG1,
253     QTYPE_MPEG2,
254     QTYPE_H264,
255 };
256
257 /*****************************************************************************
258  * Shortcuts to access image components
259  *****************************************************************************/
260
261 /* Plane indices */
262 enum
263 {
264     Y_PLANE = 0,
265     U_PLANE = 1,
266     V_PLANE = 2,
267     A_PLANE = 3,
268 };
269
270 /* Shortcuts */
271 #define Y_PIXELS     p[Y_PLANE].p_pixels
272 #define Y_PITCH      p[Y_PLANE].i_pitch
273 #define U_PIXELS     p[U_PLANE].p_pixels
274 #define U_PITCH      p[U_PLANE].i_pitch
275 #define V_PIXELS     p[V_PLANE].p_pixels
276 #define V_PITCH      p[V_PLANE].i_pitch
277 #define A_PIXELS     p[A_PLANE].p_pixels
278 #define A_PITCH      p[A_PLANE].i_pitch
279
280 /**@}*/
281
282 #endif /* VLC_PICTURE_H */