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