VLC  2.1.0-git
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vlc_vout_display.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vlc_vout_display.h: vout_display_t definitions
3  *****************************************************************************
4  * Copyright (C) 2009 Laurent Aimar
5  * $Id: d99cf7eea9c1079754a3a47ea1df8ecd8e8d6163 $
6  *
7  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * 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;
49 
50 /**
51  * Possible alignments for vout_display.
52  */
53 typedef enum
54 {
56  /* */
59  /* */
63 
64 /**
65  * Window management state.
66  */
67 enum {
72 };
73 
74 /**
75  * Initial/Current configuration for a vout_display_t
76  */
77 typedef struct {
78  bool is_fullscreen; /* Is the display fullscreen */
79 
80  /* Display properties */
81  struct {
82  /* Window title (may be NULL) */
83  const char *title;
84 
85  /* Display size */
86  unsigned width;
87  unsigned height;
88 
89  /* Display SAR */
90  struct {
91  unsigned num;
92  unsigned den;
93  } sar;
94  } display;
95 
96  /* Alignment of the picture inside the display */
97  struct {
98  int horizontal;
99  int vertical;
100  } align;
101 
102  /* Do we fill up the display with the video */
103  bool is_display_filled;
105  /* Zoom to use
106  * It will be applied to the whole display if b_display_filled is set, otherwise
107  * only on the video source */
108  struct {
109  int num;
110  int den;
111  } zoom;
112 
114 
115 /**
116  * Information from a vout_display_t to configure
117  * the core behaviour.
118  *
119  * By default they are all false or NULL.
120  *
121  */
122 typedef struct {
123  bool is_slow; /* The picture memory has slow read/write */
124  bool has_double_click; /* Is double-click generated */
125  bool has_hide_mouse; /* Is mouse automatically hidden */
126  bool has_pictures_invalid; /* Will VOUT_DISPLAY_EVENT_PICTURES_INVALID be used */
127  bool has_event_thread; /* Will events (key at least) be emitted using an independent thread */
128  const vlc_fourcc_t *subpicture_chromas; /* List of supported chromas for subpicture rendering. */
130 
131 /**
132  * Control query for vout_display_t
133  */
134 enum {
135  /* Hide the mouse. It will be sent when
136  * vout_display_t::info.b_hide_mouse is false */
139  /* Ask to reset the internal buffers after a VOUT_DISPLAY_EVENT_PICTURES_INVALID
140  * request.
141  */
144  /* Ask the module to acknowledge/refuse the fullscreen state change after
145  * being requested (externally or by VOUT_DISPLAY_EVENT_FULLSCREEN */
146  VOUT_DISPLAY_CHANGE_FULLSCREEN, /* const vout_display_cfg_t *p_cfg */
148  /* Ask the module to acknowledge/refuse the window management state change
149  * after being requested externally or by VOUT_DISPLAY_WINDOW_STATE */
150  VOUT_DISPLAY_CHANGE_WINDOW_STATE, /* unsigned state */
152  /* Ask the module to acknowledge/refuse the display size change requested
153  * (externally or by VOUT_DISPLAY_EVENT_DISPLAY_SIZE) */
154  VOUT_DISPLAY_CHANGE_DISPLAY_SIZE, /* const vout_display_cfg_t *p_cfg, int is_forced */
156  /* Ask the module to acknowledge/refuse fill display state change after
157  * being requested externally */
158  VOUT_DISPLAY_CHANGE_DISPLAY_FILLED, /* const vout_display_cfg_t *p_cfg */
160  /* Ask the module to acknowledge/refuse zoom change after being requested
161  * externally */
162  VOUT_DISPLAY_CHANGE_ZOOM, /* const vout_display_cfg_t *p_cfg */
164  /* Ask the module to acknowledge/refuse source aspect ratio after being
165  * requested externally */
166  VOUT_DISPLAY_CHANGE_SOURCE_ASPECT, /* const video_format_t *p_source */
168  /* Ask the module to acknowledge/refuse source crop change after being
169  * requested externally.
170  * The cropping requested is stored by video_format_t::i_x/y_offset and
171  * video_format_t::i_visible_width/height */
172  VOUT_DISPLAY_CHANGE_SOURCE_CROP, /* const video_format_t *p_source */
174  /* Ask an opengl interface if available. */
175  VOUT_DISPLAY_GET_OPENGL, /* vlc_gl_t ** */
176 };
177 
178 /**
179  * Event from vout_display_t
180  *
181  * Events modifiying the state may be sent multiple times.
182  * Only the transition will be retained and acted upon.
183  */
184 enum {
185  /* TODO:
186  * ZOOM ? DISPLAY_FILLED ? ON_TOP ?
187  */
188  /* */
189  VOUT_DISPLAY_EVENT_PICTURES_INVALID, /* The buffer are now invalid and need to be changed */
194  VOUT_DISPLAY_EVENT_DISPLAY_SIZE, /* The display size need to change : int i_width, int i_height, bool is_fullscreen */
196  /* */
200  /* Full mouse state.
201  * You can use it OR use the other mouse events. The core will do
202  * the conversion.
203  */
206  /* Mouse event */
211 };
212 
213 /**
214  * Vout owner structures
215  */
216 struct vout_display_owner_t {
217  /* Private place holder for the vout_display_t creator
218  */
221  /* Event coming from the module
222  *
223  * This function is set prior to the module instantiation and must not
224  * be overwritten nor used directly (use the vout_display_SendEvent*
225  * wrapper.
226  *
227  * You can send it at any time i.e. from any vout_display_t functions or
228  * from another thread.
229  * Be careful, it does not ensure correct serialization if it is used
230  * from multiple threads.
231  */
232  void (*event)(vout_display_t *, int, va_list);
234  /* Window management
235  *
236  * These functions are set prior to the module instantiation and must not
237  * be overwritten nor used directly (use the vout_display_*Window
238  * wrapper */
239  vout_window_t *(*window_new)(vout_display_t *, const vout_window_cfg_t *);
241 };
242 
243 struct vout_display_t {
246  /* Module */
247  module_t *module;
249  /* Initial and current configuration.
250  * You cannot modify it directly, you must use the appropriate events.
251  *
252  * It reflects the current values, i.e. after the event has been accepted
253  * and applied/configured if needed.
254  */
255  const vout_display_cfg_t *cfg;
257  /* video source format.
258  *
259  * Cropping is not requested while in the open function.
260  * You cannot change it.
261  */
264  /* picture_t format.
265  *
266  * You can only change it inside the module open function to
267  * match what you want, and when a VOUT_DISPLAY_RESET_PICTURES control
268  * request is made and succeeds.
269  *
270  * By default, it is equal to ::source except for the aspect ratio
271  * which is undefined(0) and is ignored.
272  */
275  /* Information
276  *
277  * You can only set them in the open function.
278  */
281  /* Return a pointer over the current picture_pool_t* (mandatory).
282  *
283  * For performance reasons, it is best to provide at least count
284  * pictures but it is not mandatory.
285  * You can return NULL when you cannot/do not want to allocate
286  * pictures.
287  * The vout display module keeps the ownership of the pool and can
288  * destroy it only when closing or on invalid pictures control.
289  */
290  picture_pool_t *(*pool)(vout_display_t *, unsigned count);
292  /* Prepare a picture and an optional subpicture for display (optional).
293  *
294  * It is called before the next pf_display call to provide as much
295  * time as possible to prepare the given picture and the subpicture
296  * for display.
297  * You are guaranted that pf_display will always be called and using
298  * the exact same picture_t and subpicture_t.
299  * You cannot change the pixel content of the picture_t or of the
300  * subpicture_t.
301  */
302  void (*prepare)(vout_display_t *, picture_t *, subpicture_t *);
304  /* Display a picture and an optional subpicture (mandatory).
305  *
306  * The picture and the optional subpicture must be displayed as soon as
307  * possible.
308  * You cannot change the pixel content of the picture_t or of the
309  * subpicture_t.
310  *
311  * This function gives away the ownership of the picture and of the
312  * subpicture, so you must release them as soon as possible.
313  */
314  void (*display)(vout_display_t *, picture_t *, subpicture_t *);
316  /* Control on the module (mandatory) */
317  int (*control)(vout_display_t *, int, va_list);
319  /* Manage pending event (optional) */
320  void (*manage)(vout_display_t *);
322  /* Private place holder for the vout_display_t module (optional)
323  *
324  * A module is free to use it as it wishes.
325  */
328  /* Reserved for the vout_display_t owner.
329  *
330  * It must not be overwritten nor used directly by a module.
331  */
333 };
334 
335 static inline void vout_display_SendEvent(vout_display_t *vd, int query, ...)
336 {
337  va_list args;
338  va_start(args, query);
339  vd->owner.event(vd, query, args);
340  va_end(args);
341 }
342 
343 static inline void vout_display_SendEventDisplaySize(vout_display_t *vd, int width, int height, bool is_fullscreen)
344 {
345  vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_DISPLAY_SIZE, width, height, is_fullscreen);
346 }
348 {
350 }
351 static inline void vout_display_SendEventClose(vout_display_t *vd)
352 {
354 }
355 static inline void vout_display_SendEventKey(vout_display_t *vd, int key)
356 {
358 }
359 static inline void vout_display_SendEventFullscreen(vout_display_t *vd, bool is_fullscreen)
360 {
362 }
363 static inline void vout_display_SendWindowState(vout_display_t *vd, unsigned state)
364 {
366 }
367 /* The mouse position (State and Moved event) must be expressed against vout_display_t::source unit */
368 static inline void vout_display_SendEventMouseState(vout_display_t *vd, int x, int y, int button_mask)
369 {
371 }
372 static inline void vout_display_SendEventMouseMoved(vout_display_t *vd, int x, int y)
373 {
375 }
376 static inline void vout_display_SendEventMousePressed(vout_display_t *vd, int button)
377 {
379 }
380 static inline void vout_display_SendEventMouseReleased(vout_display_t *vd, int button)
381 {
383 }
385 {
387 }
388 
389 /**
390  * Asks for a new window with the given configuration as hint.
391  *
392  * b_standalone/i_x/i_y may be overwritten by the core
393  */
395 {
396  return vd->owner.window_new(vd, cfg);
397 }
398 /**
399  * Deletes a window created by vout_display_NewWindow if window is non NULL
400  * or any unused windows otherwise.
401  */
402 static inline void vout_display_DeleteWindow(vout_display_t *vd,
403  vout_window_t *window)
404 {
405  vd->owner.window_del(vd, window);
406 }
407 
408 /**
409  * Computes the default display size given the source and
410  * the display configuration.
411  *
412  * This asssumes that the picture is already cropped.
413  */
414 VLC_API void vout_display_GetDefaultDisplaySize(unsigned *width, unsigned *height, const video_format_t *source, const vout_display_cfg_t *);
415 
416 
417 /**
418  * Structure used to store the result of a vout_display_PlacePicture.
419  */
420 typedef struct {
421  int x;
422  int y;
423  unsigned width;
424  unsigned height;
426 
427 /**
428  * Computes how to place a picture inside the display to respect
429  * the given parameters.
430  * This assumes that cropping is done by an external mean.
431  *
432  * \param p_place Place inside the window (window pixel unit)
433  * \param p_source Video source format
434  * \param p_cfg Display configuration
435  * \param b_clip If true, prevent the video to go outside the display (break zoom).
436  */
437 VLC_API void vout_display_PlacePicture(vout_display_place_t *place, const video_format_t *source, const vout_display_cfg_t *cfg, bool do_clipping);
438 
439 #endif /* VLC_VOUT_DISPLAY_H */
440