VLC  4.0.0-dev
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  *
6  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22 
23 #ifndef VLC_VOUT_DISPLAY_H
24 #define VLC_VOUT_DISPLAY_H 1
25 
26 #include <vlc_es.h>
27 #include <vlc_picture.h>
28 #include <vlc_picture_pool.h>
29 #include <vlc_subpicture.h>
30 #include <vlc_actions.h>
31 #include <vlc_mouse.h>
32 #include <vlc_vout.h>
33 #include <vlc_vout_window.h>
34 #include <vlc_viewpoint.h>
35 
36 /**
37  * \defgroup video_display Video output display
38  * Video output display: output buffers and rendering
39  *
40  * \ingroup video_output
41  * @{
42  * \file
43  * Video output display modules interface
44  */
45 
46 typedef struct vout_display_t vout_display_t;
49 
50 /**
51  * Possible alignments for vout_display.
52  */
53 #define VLC_VIDEO_ALIGN_CENTER 0
54 #define VLC_VIDEO_ALIGN_LEFT 1
55 #define VLC_VIDEO_ALIGN_RIGHT 2
56 #define VLC_VIDEO_ALIGN_TOP 1
57 #define VLC_VIDEO_ALIGN_BOTTOM 2
58 
59 typedef struct vlc_video_align {
60  char horizontal;
61  char vertical;
63 
64 /**
65  * Initial/Current configuration for a vout_display_t
66  */
67 typedef struct vout_display_cfg {
68  struct vout_window_t *window; /**< Window */
69 #if defined(__OS2__)
70  bool is_fullscreen VLC_DEPRECATED; /* Is the display fullscreen */
71 #endif
72 
73  /* Display properties */
74  struct {
75  /* Display size */
76  unsigned width;
77  unsigned height;
78 
79  /* Display SAR */
80  vlc_rational_t sar;
81  } display;
82 
83  /* Alignment of the picture inside the display */
84  vlc_video_align_t align;
85 
86  /* Do we fill up the display with the video */
87  bool is_display_filled;
88 
89  /* Zoom to use
90  * It will be applied to the whole display if b_display_filled is set, otherwise
91  * only on the video source */
92  struct {
93  unsigned num;
94  unsigned den;
95  } zoom;
96 
97  vlc_viewpoint_t viewpoint;
99 
100 /**
101  * Information from a vout_display_t to configure
102  * the core behaviour.
103  *
104  * By default they are all false or NULL.
105  *
106  */
107 typedef struct {
108  bool can_scale_spu; /* Handles subpictures with a non default zoom factor */
109  const vlc_fourcc_t *subpicture_chromas; /* List of supported chromas for subpicture rendering. */
111 
112 /**
113  * Control query for vout_display_t
114  */
115 enum {
116  /* Ask to reset the internal buffers after a
117  * \ref VOUT_DISPLAY_CHANGE_DISPLAY_SIZE,
118  * \ref VOUT_DISPLAY_CHANGE_DISPLAY_FILLED,
119  * \ref VOUT_DISPLAY_CHANGE_ZOOM,
120  * \ref VOUT_DISPLAY_CHANGE_SOURCE_ASPECT or
121  * \ref VOUT_DISPLAY_CHANGE_SOURCE_CROP
122  * control query returns an error.
123  */
124  VOUT_DISPLAY_RESET_PICTURES, /* const vout_display_cfg_t *, video_format_t * */
126 #if defined(__OS2__)
127  /* Ask the module to acknowledge/refuse the fullscreen state change after
128  * being requested (externally or by VOUT_DISPLAY_EVENT_FULLSCREEN */
129  VOUT_DISPLAY_CHANGE_FULLSCREEN VLC_DEPRECATED_ENUM, /* bool fs */
130  /* Ask the module to acknowledge/refuse the window management state change
131  * after being requested externally or by VOUT_DISPLAY_WINDOW_STATE */
132  VOUT_DISPLAY_CHANGE_WINDOW_STATE VLC_DEPRECATED_ENUM, /* unsigned state */
133 #endif
134  /* Ask the module to acknowledge the display size change */
135  VOUT_DISPLAY_CHANGE_DISPLAY_SIZE, /* const vout_display_cfg_t *p_cfg */
137  /* Ask the module to acknowledge/refuse fill display state change after
138  * being requested externally */
139  VOUT_DISPLAY_CHANGE_DISPLAY_FILLED, /* const vout_display_cfg_t *p_cfg */
141  /* Ask the module to acknowledge/refuse zoom change after being requested
142  * externally */
143  VOUT_DISPLAY_CHANGE_ZOOM, /* const vout_display_cfg_t *p_cfg */
145  /* Ask the module to acknowledge/refuse source aspect ratio after being
146  * requested externally */
147  VOUT_DISPLAY_CHANGE_SOURCE_ASPECT, /* const vout_display_cfg_t *p_cfg */
149  /* Ask the module to acknowledge/refuse source crop change after being
150  * requested externally.
151  * The cropping requested is stored by source video_format_t::i_x/y_offset
152  * and video_format_t::i_visible_width/height */
153  VOUT_DISPLAY_CHANGE_SOURCE_CROP, /* const vout_display_cfg_t *p_cfg */
155  /* Ask the module to acknowledge/refuse VR/360° viewing direction after
156  * being requested externally */
157  VOUT_DISPLAY_CHANGE_VIEWPOINT, /* const vout_display_cfg_t *p_cfg */
158 };
159 
160 /**
161  * Event from vout_display_t
162  *
163  * Events modifiying the state may be sent multiple times.
164  * Only the transition will be retained and acted upon.
165  */
166 enum {
167  /* VR navigation, vlc_viewpoint_t* */
169 };
170 
171 /**
172  * Vout owner structures
173  */
174 struct vout_display_owner_t {
175  /* Private place holder for the vout_display_t creator
176  */
177  void *sys;
179  /* Event coming from the module
180  *
181  * This function is set prior to the module instantiation and must not
182  * be overwritten nor used directly (use the vout_display_SendEvent*
183  * wrapper.
184  *
185  * You can send it at any time i.e. from any vout_display_t functions or
186  * from another thread.
187  * Be careful, it does not ensure correct serialization if it is used
188  * from multiple threads.
189  */
190  void (*viewpoint_moved)(void *sys, const vlc_viewpoint_t *vp);
191 };
192 
193 /**
194  * "vout display" open callback
195  *
196  * @param vd vout display context
197  * @param cfg Initial and current configuration.
198  * @param fmtp By default, it is equal to vd->source except for the aspect
199  * ratio which is undefined(0) and is ignored. It can be changed by the module
200  * to request a different format.
201  * @param context XXX: to be defined.
202  * @return VLC_SUCCESS or a VLC error code
203  */
204 typedef int (*vout_display_open_cb)(vout_display_t *vd,
205  const vout_display_cfg_t *cfg,
206  video_format_t *fmtp,
207  vlc_video_context *context);
208 
209 #define set_callback_display(activate, priority) \
210  { \
211  vout_display_open_cb open__ = activate; \
212  (void) open__; \
213  set_callback(activate) \
214  } \
215  set_capability( "vout display", priority )
216 
217 
218 struct vout_display_t {
221  /* Initial and current configuration.
222  * You cannot modify it directly, you must use the appropriate events.
223  *
224  * It reflects the current values, i.e. after the event has been accepted
225  * and applied/configured if needed.
226  */
227  const vout_display_cfg_t *cfg;
229  /* video source format.
230  *
231  * Cropping is not requested while in the open function.
232  * You cannot change it.
233  */
234  video_format_t source;
236  /* picture_t format.
237  *
238  * You can only change it inside the module open function to
239  * match what you want, and when a VOUT_DISPLAY_RESET_PICTURES control
240  * request is made and succeeds.
241  *
242  * By default, it is equal to ::source except for the aspect ratio
243  * which is undefined(0) and is ignored.
244  */
245  video_format_t fmt;
247  /* Information
248  *
249  * You can only set them in the open function.
250  */
251  vout_display_info_t info;
253  /* Return a pointer over the current picture_pool_t* (optional).
254  *
255  * For performance reasons, it is best to provide at least count
256  * pictures but it is not mandatory.
257  * You can return NULL when you cannot/do not want to allocate
258  * pictures.
259  * The vout display module keeps the ownership of the pool and can
260  * destroy it only when closing or on invalid pictures control.
261  */
262  picture_pool_t *(*pool)(vout_display_t *, unsigned count);
264  /* Prepare a picture and an optional subpicture for display (optional).
265  *
266  * It is called before the next pf_display call to provide as much
267  * time as possible to prepare the given picture and the subpicture
268  * for display.
269  * You are guaranted that pf_display will always be called and using
270  * the exact same picture_t and subpicture_t.
271  * You cannot change the pixel content of the picture_t or of the
272  * subpicture_t.
273  */
274  void (*prepare)(vout_display_t *, picture_t *, subpicture_t *,
275  vlc_tick_t date);
276 
277  /* Display a picture.
278  *
279  * The picture must be displayed as soon as possible.
280  * You cannot change the pixel content of the picture_t.
281  */
282  void (*display)(vout_display_t *, picture_t *);
284  /* Control on the module (mandatory) */
285  int (*control)(vout_display_t *, int, va_list);
287  /**
288  * Destroys the display.
289  */
290  void (*close)(vout_display_t *);
292  /* Private place holder for the vout_display_t module (optional)
293  *
294  * A module is free to use it as it wishes.
295  */
296  vout_display_sys_t *sys;
298  /* Reserved for the vout_display_t owner.
299  *
300  * It must not be overwritten nor used directly by a module.
301  */
302  vout_display_owner_t owner;
303 };
304 
305 /**
306  * Creates video output display.
307  */
308 VLC_API
311  const vout_display_cfg_t *, const char *module,
312  const vout_display_owner_t *);
313 
314 /**
315  * Destroys a video output display.
316  */
318 
319 /**
320  * Prepares a picture for display.
321  *
322  * This renders a picture for subsequent display, with vout_display_Display().
323  *
324  * \note A reference to the input picture is consumed by the function, which
325  * returns a reference to an output picture for display. The input and output
326  * picture may or may not be equal depending on the underlying display setup.
327  *
328  * \bug Currently, only one picture can be prepared at a time. It must be
329  * displayed with vout_display_Display() before any picture is prepared or
330  * before the display is destroyd with vout_display_Delete().
331  *
332  \ bug Rendering subpictures is not supported with this function yet.
333  * \c subpic must be @c NULL .
334  *
335  * \param vd display to prepare the picture for
336  * \param picture picure to be prepared
337  * \param subpic reserved, must be NULL
338  * \param date intended time to show the picture
339  * \return The prepared picture is returned, NULL on error.
340  */
342  subpicture_t *subpic, vlc_tick_t date);
343 
344 /**
345  * Displays a picture.
346  */
347 static inline void vout_display_Display(vout_display_t *vd, picture_t *picture)
348 {
349  if (vd->display != NULL)
350  vd->display(vd, picture);
351  picture_Release(picture);
352 }
353 
354 VLC_API
355 void vout_display_SetSize(vout_display_t *vd, unsigned width, unsigned height);
356 
357 static inline int vout_display_Control(vout_display_t *vd, int query, ...)
358 {
359  va_list ap;
360  int ret;
361 
362  va_start(ap, query);
363  ret = vd->control(vd, query, ap);
364  va_end(ap);
365  return ret;
366 }
367 
369 
370 static inline void vout_display_SendEventMousePressed(vout_display_t *vd, int button)
371 {
373 }
374 static inline void vout_display_SendEventMouseReleased(vout_display_t *vd, int button)
375 {
377 }
379 {
381 }
383  const vlc_viewpoint_t *vp)
384 {
385  if (vd->owner.viewpoint_moved)
386  vd->owner.viewpoint_moved(vd->owner.sys, vp);
387 }
388 
389 /**
390  * Helper function that applies the necessary transforms to the mouse position
391  * and then calls vout_display_SendEventMouseMoved.
392  *
393  * \param vd vout_display_t.
394  * \param m_x Mouse x position (relative to place, origin is top left).
395  * \param m_y Mouse y position (relative to place, origin is top left).
396  */
397 static inline void vout_display_SendMouseMovedDisplayCoordinates(vout_display_t *vd, int m_x, int m_y)
398 {
399  vout_window_ReportMouseMoved(vd->cfg->window, m_x, m_y);
400 }
401 
402 static inline bool vout_display_cfg_IsWindowed(const vout_display_cfg_t *cfg)
403 {
404  return cfg->window->type != VOUT_WINDOW_TYPE_DUMMY;
405 }
406 
407 /**
408  * Computes the default display size given the source and
409  * the display configuration.
410  *
411  * This asssumes that the picture is already cropped.
412  */
413 VLC_API void vout_display_GetDefaultDisplaySize(unsigned *width, unsigned *height, const video_format_t *source, const vout_display_cfg_t *);
414 
415 
416 /**
417  * Structure used to store the result of a vout_display_PlacePicture.
418  */
419 typedef struct {
420  int x;
421  int y;
422  unsigned width;
423  unsigned height;
425 
426 static inline bool vout_display_PlaceEquals(const vout_display_place_t *p1,
428 {
429  return p1->x == p2->x && p1->width == p2->width &&
430  p1->y == p2->y && p1->height == p2->height;
431 }
432 
433 /**
434  * Computes how to place a picture inside the display to respect
435  * the given parameters.
436  * This assumes that cropping is done by an external mean.
437  *
438  * \param p_place Place inside the window (window pixel unit)
439  * \param p_source Video source format
440  * \param p_cfg Display configuration
441  */
443 
444 /**
445  * Translates mouse state.
446  *
447  * This translates the mouse (pointer) state from window coordinates to
448  * video coordinates.
449  * @note @c video and @c window pointers may alias.
450  */
452  const vlc_mouse_t *window);
453 
454 /** @} */
455 #endif /* VLC_VOUT_DISPLAY_H */
Subpictures functions.
This file defines picture structures and functions in vlc.
Definition: vlc_vout_display.h:125
static void vout_display_SendMouseMovedDisplayCoordinates(vout_display_t *vd, int m_x, int m_y)
Helper function that applies the necessary transforms to the mouse position and then calls vout_displ...
Definition: vlc_vout_display.h:398
#define VLC_DEPRECATED_ENUM
Deprecated enum member annotation.
Definition: vlc_common.h:129
static void vout_window_ReportMouseMoved(vout_window_t *window, int x, int y)
Reports a pointer movement.
Definition: vlc_vout_window.h:606
Definition: vlc_vout_display.h:169
Information from a vout_display_t to configure the core behaviour.
Definition: vlc_vout_display.h:108
int x
Definition: vlc_vout_display.h:421
void vout_display_GetDefaultDisplaySize(unsigned *width, unsigned *height, const video_format_t *source, const vout_display_cfg_t *)
Computes the default display size given the source and the display configuration. ...
Definition: display.c:91
Video picture.
Definition: vlc_picture.h:126
void vout_display_SetSize(vout_display_t *vd, unsigned width, unsigned height)
Definition: display.c:622
picture_t * vout_display_Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic, vlc_tick_t date)
Prepares a picture for display.
Definition: display.c:442
unsigned height
Definition: vlc_vout_display.h:424
static void vout_window_ReportMouseDoubleClick(vout_window_t *window, int button)
Reports a mouse double-click.
Definition: vlc_vout_window.h:651
unsigned type
Window handle type.
Definition: vlc_vout_window.h:348
struct vout_window_t * window
Window.
Definition: vlc_vout_display.h:69
void vout_display_PlacePicture(vout_display_place_t *place, const video_format_t *source, const vout_display_cfg_t *cfg)
Computes how to place a picture inside the display to respect the given parameters.
Definition: display.c:126
Structure used to store the result of a vout_display_PlacePicture.
Definition: vlc_vout_display.h:420
void(* display)(vout_display_t *, picture_t *)
Definition: vlc_vout_display.h:283
#define VLC_DEPRECATED
Deprecated functions or compound members annotation.
Definition: vlc_common.h:119
static void vout_window_ReportMousePressed(vout_window_t *window, int button)
Reports a mouse button press.
Definition: vlc_vout_window.h:621
const vout_display_cfg_t * cfg
Definition: vlc_vout_display.h:228
Definition: vlc_vout_display.h:136
Definition: vlc_vout_display.h:144
Video subtitle.
Definition: vlc_subpicture.h:166
static void vout_display_SendEventViewpointMoved(vout_display_t *vd, const vlc_viewpoint_t *vp)
Definition: vlc_vout_display.h:383
struct vout_display_sys_t vout_display_sys_t
Definition: vlc_vout_display.h:48
Vout owner structures.
Definition: vlc_vout_display.h:175
Video output thread interface.
This file defines keys and functions.
static void vout_display_SendEventMousePressed(vout_display_t *vd, int button)
Definition: vlc_vout_display.h:371
struct vout_display_cfg vout_display_cfg_t
Initial/Current configuration for a vout_display_t.
Definition: decoder_helpers.c:231
static int vout_display_Control(vout_display_t *vd, int query,...)
Definition: vlc_vout_display.h:358
Definition: fourcc_gen.c:34
int64_t vlc_tick_t
High precision date or time interval.
Definition: vlc_tick.h:45
static void vout_display_SendEventMouseReleased(vout_display_t *vd, int button)
Definition: vlc_vout_display.h:375
vout_display_owner_t owner
Definition: vlc_vout_display.h:303
uint32_t vlc_fourcc_t
Definition: fourcc_gen.c:33
vout_display_t * vout_display_New(vlc_object_t *, const video_format_t *, vlc_video_context *, const vout_display_cfg_t *, const char *module, const vout_display_owner_t *)
Creates video output display.
Definition: display.c:724
struct vlc_object_marker * obj
Definition: vlc_objects.h:48
static void picture_Release(picture_t *picture)
Decrements the picture reference count.
Definition: vlc_picture.h:235
Viewpoints.
Definition: vlc_viewpoint.h:41
Definition: vlc_vout_display.h:158
Definition: vlc_vout_display.h:140
void vout_display_TranslateMouseState(vout_display_t *vd, vlc_mouse_t *video, const vlc_mouse_t *window)
Translates mouse state.
Definition: display.c:204
void * sys
Definition: vlc_vout_display.h:178
size_t count
Definition: core.c:402
struct vlc_video_align vlc_video_align_t
video format description
Definition: vlc_es.h:349
Definition: vlc_mouse.h:32
Mouse state.
Definition: vlc_mouse.h:45
Video and audio viewpoint struct and helpers.
void vout_display_SendEventPicturesInvalid(vout_display_t *vd)
Definition: display.c:357
static bool vout_display_cfg_IsWindowed(const vout_display_cfg_t *cfg)
Definition: vlc_vout_display.h:403
char vertical
Definition: vlc_vout_display.h:62
Definition: picture_pool.c:41
void vout_display_Delete(vout_display_t *)
Destroys a video output display.
Definition: display.c:798
#define VLC_API
Definition: fourcc_gen.c:31
void(* viewpoint_moved)(void *sys, const vlc_viewpoint_t *vp)
Definition: vlc_vout_display.h:191
Definition: vlc_vout_display.h:60
unsigned width
Definition: vlc_vout_display.h:423
char horizontal
Definition: vlc_vout_display.h:61
int(* control)(vout_display_t *, int, va_list)
Definition: vlc_vout_display.h:286
static void vout_display_Display(vout_display_t *vd, picture_t *picture)
Displays a picture.
Definition: vlc_vout_display.h:348
int y
Definition: vlc_vout_display.h:422
static void vout_window_ReportMouseReleased(vout_window_t *window, int button)
Reports a mouse button release.
Definition: vlc_vout_window.h:636
Initial/Current configuration for a vout_display_t.
Definition: vlc_vout_display.h:68
This file defines picture pool structures and functions in vlc.
Definition: vlc_vout_display.h:148
Dummy window (not an actual window)
Definition: vlc_vout_window.h:61
int(* vout_display_open_cb)(vout_display_t *vd, const vout_display_cfg_t *cfg, video_format_t *fmtp, vlc_video_context *context)
"vout display" open callback
Definition: vlc_vout_display.h:205
Window object.
Definition: vlc_vout_window.h:336
This file defines the elementary streams format types.
VLC object common members.
Definition: vlc_objects.h:43
static bool vout_display_PlaceEquals(const vout_display_place_t *p1, const vout_display_place_t *p2)
Definition: vlc_vout_display.h:427
Definition: vlc_vout_display.h:219
static void vout_display_SendEventMouseDoubleClick(vout_display_t *vd)
Definition: vlc_vout_display.h:379
Window modules interface.
Definition: vlc_vout_display.h:154