]> git.sesse.net Git - vlc/blob - include/vlc_vout_display.h
Build fix
[vlc] / include / vlc_vout_display.h
1 /*****************************************************************************
2  * vlc_vout_display.h: vout_display_t definitions
3  *****************************************************************************
4  * Copyright (C) 2009 Laurent Aimar
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifndef VLC_VOUT_DISPLAY_H
25 #define VLC_VOUT_DISPLAY_H 1
26
27 /**
28  * \file
29  * This file defines vout display structures and functions in vlc
30  */
31
32 #include <vlc_es.h>
33 #include <vlc_picture.h>
34 #include <vlc_picture_pool.h>
35 #include <vlc_subpicture.h>
36 #include <vlc_keys.h>
37 #include <vlc_mouse.h>
38 #include <vlc_vout_window.h>
39
40 /* XXX
41  * Do NOT use video_format_t::i_aspect but i_sar_num/den everywhere. i_aspect
42  * will be removed as soon as possible.
43  *
44  */
45 typedef struct vout_display_t vout_display_t;
46 typedef struct vout_display_sys_t vout_display_sys_t;
47 typedef struct vout_display_owner_t vout_display_owner_t;
48 typedef struct vout_display_owner_sys_t vout_display_owner_sys_t;
49
50 /**
51  * Possible alignments for vout_display.
52  */
53 typedef enum
54 {
55     VOUT_DISPLAY_ALIGN_CENTER,
56     /* */
57     VOUT_DISPLAY_ALIGN_LEFT,
58     VOUT_DISPLAY_ALIGN_RIGHT,
59     /* */
60     VOUT_DISPLAY_ALIGN_TOP,
61     VOUT_DISPLAY_ALIGN_BOTTOM,
62 } vout_display_align_t;
63
64 /**
65  * Initial/Current configuration for a vout_display_t
66  */
67 typedef struct {
68     bool is_fullscreen;  /* Is the display fullscreen */
69
70     /* Display properties */
71     struct {
72         /* Window title (may be NULL) */
73         const char *title;
74
75         /* Display size */
76         unsigned  width;
77         unsigned  height;
78
79         /* Display SAR */
80         struct {
81             unsigned num;
82             unsigned den;
83         } sar;
84     } display;
85
86     /* Alignment of the picture inside the display */
87     struct {
88         int horizontal;
89         int vertical;
90     } align;
91
92     /* Do we fill up the display with the video */
93     bool is_display_filled;
94
95     /* Zoom to use
96      * It will be applied to the whole display if b_display_filled is set, otherwise
97      * only on the video source */
98     struct {
99         int num;
100         int den;
101     } zoom;
102
103 } vout_display_cfg_t;
104
105 /**
106  * Informations from a vout_display_t to configure
107  * the core behaviour.
108  *
109  * By default they are all false.
110  *
111  */
112 typedef struct {
113     bool is_slow;            /* The picture memory has slow read/write */
114     bool has_double_click;    /* Is double-click generated */
115     bool has_hide_mouse;      /* Is mouse automatically hidden */
116     bool has_pictures_invalid;/* Will VOUT_DISPLAY_EVENT_PICTURES_INVALID be used */
117 } vout_display_info_t;
118
119 /**
120  * Control query for vout_display_t
121  */
122 enum {
123     /* Hide the mouse. It will be sent when
124      * vout_display_t::info.b_hide_mouse is false */
125     VOUT_DISPLAY_HIDE_MOUSE,
126
127     /* Ask to reset the internal buffers after a VOUT_DISPLAY_EVENT_PICTURES_INVALID
128      * request.
129      */
130     VOUT_DISPLAY_RESET_PICTURES,
131
132     /* Ask the module to acknowledge/refuse the fullscreen state change after
133      * being requested (externally or by VOUT_DISPLAY_EVENT_FULLSCREEN */
134     VOUT_DISPLAY_CHANGE_FULLSCREEN,     /* const vout_display_cfg_t *p_cfg */
135
136     /* Ask the module to acknowledge/refuse the "always on top" state change
137      * after being requested externally or by VOUT_DISPLAY_EVENT_ON_TOP */
138     VOUT_DISPLAY_CHANGE_ON_TOP,         /* int b_on_top */
139
140     /* Ask the module to acknowledge/refuse the display size change requested
141      * (externally or by VOUT_DISPLAY_EVENT_DISPLAY_SIZE) */
142     VOUT_DISPLAY_CHANGE_DISPLAY_SIZE,   /* const vout_display_cfg_t *p_cfg, int is_forced */
143
144     /* Ask the module to acknowledge/refuse fill display state change after
145      * being requested externally */
146     VOUT_DISPLAY_CHANGE_DISPLAY_FILLED, /* const vout_display_cfg_t *p_cfg */
147
148     /* Ask the module to acknowledge/refuse zoom change after being requested
149      * externally */
150     VOUT_DISPLAY_CHANGE_ZOOM, /* const vout_display_cfg_t *p_cfg */
151
152     /* Ask the module to acknowledge/refuse source aspect ratio after being
153      * requested externally */
154     VOUT_DISPLAY_CHANGE_SOURCE_ASPECT, /* const video_format_t *p_source */
155
156     /* Ask the module to acknowledge/refuse source crop change after being
157      * requested externally.
158      * The cropping requested is stored by video_format_t::i_x/y_offset and
159      * video_format_t::i_visible_width/height */
160     VOUT_DISPLAY_CHANGE_SOURCE_CROP,   /* const video_format_t *p_source */
161
162     /* Ask an opengl interface if available. */
163     VOUT_DISPLAY_GET_OPENGL,           /* vout_opengl_t ** */
164 };
165
166 /**
167  * Event from vout_display_t
168  *
169  * Events modifiying the state may be sent multiple times.
170  * Only the transition will be retained and acted upon.
171  */
172 enum {
173     /* TODO:
174      * ZOOM ? DISPLAY_FILLED ? ON_TOP ?
175      */
176     /* */
177     VOUT_DISPLAY_EVENT_PICTURES_INVALID,    /* The buffer are now invalid and need to be changed */
178
179     VOUT_DISPLAY_EVENT_FULLSCREEN,
180     VOUT_DISPLAY_EVENT_ON_TOP,
181
182     VOUT_DISPLAY_EVENT_DISPLAY_SIZE,        /* The display size need to change : int i_width, int i_height, bool is_fullscreen */
183
184     /* */
185     VOUT_DISPLAY_EVENT_CLOSE,
186     VOUT_DISPLAY_EVENT_KEY,
187
188     /* Full mouse state.
189      * You can use it OR use the other mouse events. The core will do
190      * the conversion.
191      */
192     VOUT_DISPLAY_EVENT_MOUSE_STATE,
193
194     /* Mouse event */
195     VOUT_DISPLAY_EVENT_MOUSE_MOVED,
196     VOUT_DISPLAY_EVENT_MOUSE_PRESSED,
197     VOUT_DISPLAY_EVENT_MOUSE_RELEASED,
198     VOUT_DISPLAY_EVENT_MOUSE_DOUBLE_CLICK,
199 };
200
201 /**
202  * Vout owner structures
203  */
204 struct vout_display_owner_t {
205     /* Private place holder for the vout_display_t creator
206      */
207     vout_display_owner_sys_t *sys;
208
209     /* Event coming from the module
210      *
211      * This function is set prior to the module instantiation and must not
212      * be overwritten nor used directly (use the vout_display_SendEvent*
213      * wrapper.
214      *
215      * You can send it at any time i.e. from any vout_display_t functions or
216      * from another thread.
217      * Becarefull, it does not ensure correct serialization if it is used
218      * from multiple threads.
219      */
220     void            (*event)(vout_display_t *, int, va_list);
221
222     /* Window management
223      *
224      * These functions are set prior to the module instantiation and must not
225      * be overwritten nor used directly (use the vout_display_*Window
226      * wrapper */
227     vout_window_t *(*window_new)(vout_display_t *, const vout_window_cfg_t *);
228     void           (*window_del)(vout_display_t *, vout_window_t *);
229 };
230
231 struct vout_display_t {
232     VLC_COMMON_MEMBERS
233
234     /* Module */
235     module_t *module;
236
237     /* Initial and current configuration.
238      * You cannot modify it directly, you must use the appropriate events.
239      *
240      * It reflects the current values, i.e. after the event has been accepted
241      * and applied/configured if needed.
242      */
243     const vout_display_cfg_t *cfg;
244
245     /* video source format.
246      *
247      * Cropping is not requested while in the open function.
248      * You cannot change it.
249      */
250     video_format_t source;
251
252     /* picture_t format.
253      *
254      * You can only change it inside the module open function to
255      * match what you want, and when a VOUT_DISPLAY_RESET_PICTURES control
256      * request is made and succeeds.
257      *
258      * By default, it is equal to ::source except for the aspect ratio
259      * which is undefined(0) and is ignored.
260      */
261     video_format_t fmt;
262
263     /* Informations
264      *
265      * You can only set them in the open function.
266      */
267     vout_display_info_t info;
268
269     /* Return a pointer over the current picture_pool_t* (mandatory).
270      *
271      * For performance reasons, it is best to provide at least count
272      * pictures but it is not mandatory.
273      * You can return NULL when you cannot/do not want to allocate
274      * pictures.
275      * The vout display module keeps the ownership of the pool and can
276      * destroy it only when closing or on invalid pictures control.
277      */
278     picture_pool_t *(*pool)(vout_display_t *, unsigned count);
279
280     /* Prepare a picture for display (optional).
281      *
282      * It is called before the next pf_display call to provide as much
283      * time as possible to prepare the given picture for display.
284      * You are guaranted that pf_display will always be called and using
285      * the exact same picture_t.
286      * You cannot change the pixel content of the picture_t.
287      */
288     void       (*prepare)(vout_display_t *, picture_t *);
289
290     /* Display a picture (mandatory).
291      *
292      * The picture must be displayed as soon as possible.
293      * You cannot change the pixel content of the picture_t.
294      *
295      * This function gives away the ownership of the picture, so you must
296      * release it as soon as possible.
297      */
298     void       (*display)(vout_display_t *, picture_t *);
299
300     /* Control on the module (mandatory) */
301     int        (*control)(vout_display_t *, int, va_list);
302
303     /* Manage pending event (optional) */
304     void       (*manage)(vout_display_t *);
305
306     /* Private place holder for the vout_display_t module (optional)
307      *
308      * A module is free to use it as it wishes.
309      */
310     vout_display_sys_t *sys;
311
312     /* Reserved for the vout_display_t owner.
313      *
314      * It must not be overwritten nor used directly by a module.
315      */
316     vout_display_owner_t owner;
317 };
318
319 static inline void vout_display_SendEvent(vout_display_t *vd, int query, ...)
320 {
321     va_list args;
322     va_start(args, query);
323     vd->owner.event(vd, query, args);
324     va_end(args);
325 }
326
327 static inline void vout_display_SendEventDisplaySize(vout_display_t *vd, int width, int height, bool is_fullscreen)
328 {
329     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_DISPLAY_SIZE, width, height, is_fullscreen);
330 }
331 static inline void vout_display_SendEventPicturesInvalid(vout_display_t *vd)
332 {
333     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_PICTURES_INVALID);
334 }
335 static inline void vout_display_SendEventClose(vout_display_t *vd)
336 {
337     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_CLOSE);
338 }
339 static inline void vout_display_SendEventKey(vout_display_t *vd, int key)
340 {
341     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_KEY, key);
342 }
343 static inline void vout_display_SendEventFullscreen(vout_display_t *vd, bool is_fullscreen)
344 {
345     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_FULLSCREEN, is_fullscreen);
346 }
347 static inline void vout_display_SendEventOnTop(vout_display_t *vd, bool is_on_top)
348 {
349     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_ON_TOP, is_on_top);
350 }
351 /* The mouse position (State and Moved event) must be expressed against vout_display_t::source unit */
352 static inline void vout_display_SendEventMouseState(vout_display_t *vd, int x, int y, int button_mask)
353 {
354     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_STATE, x, y, button_mask);
355 }
356 static inline void vout_display_SendEventMouseMoved(vout_display_t *vd, int x, int y)
357 {
358     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_MOVED, x, y);
359 }
360 static inline void vout_display_SendEventMousePressed(vout_display_t *vd, int button)
361 {
362     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_PRESSED, button);
363 }
364 static inline void vout_display_SendEventMouseReleased(vout_display_t *vd, int button)
365 {
366     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_RELEASED, button);
367 }
368 static inline void vout_display_SendEventMouseDoubleClick(vout_display_t *vd)
369 {
370     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_DOUBLE_CLICK);
371 }
372
373 /**
374  * Asks for a new window with the given configuration as hint.
375  *
376  * b_standalone/i_x/i_y may be overwritten by the core
377  */
378 static inline vout_window_t *vout_display_NewWindow(vout_display_t *vd, const vout_window_cfg_t *cfg)
379 {
380     return vd->owner.window_new(vd, cfg);
381 }
382 static inline void vout_display_DeleteWindow(vout_display_t *vd,
383                                              vout_window_t *window)
384 {
385     vd->owner.window_del(vd, window);
386 }
387
388 /**
389  * Computes the default display size given the source and
390  * the display configuration.
391  *
392  * This asssumes that the picture is already cropped.
393  */
394 VLC_EXPORT( void, vout_display_GetDefaultDisplaySize, (unsigned *width, unsigned *height, const video_format_t *source, const vout_display_cfg_t *) );
395
396
397 /**
398  * Structure used to store the result of a vout_display_PlacePicture.
399  */
400 typedef struct {
401     int x;
402     int y;
403     unsigned width;
404     unsigned height;
405 } vout_display_place_t;
406
407 /**
408  * Computes how to place a picture inside the display to respect
409  * the given parameters.
410  * This assumes that cropping is done by an external mean.
411  *
412  * \param p_place Place inside the window (window pixel unit)
413  * \param p_source Video source format
414  * \param p_cfg Display configuration
415  * \param b_clip If true, prevent the video to go outside the display (break zoom).
416  */
417 VLC_EXPORT( void, vout_display_PlacePicture, (vout_display_place_t *place, const video_format_t *source, const vout_display_cfg_t *cfg, bool do_clipping) );
418
419 #endif /* VLC_VOUT_DISPLAY_H */
420