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  * \defgroup video_align Video alignment
52  * @{
53  */
54 #define VLC_VIDEO_ALIGN_CENTER 0
55 #define VLC_VIDEO_ALIGN_LEFT 1
56 #define VLC_VIDEO_ALIGN_RIGHT 2
57 #define VLC_VIDEO_ALIGN_TOP 1
58 #define VLC_VIDEO_ALIGN_BOTTOM 2
59 
60 /**
61  * Video alignment within the display.
62  */
63 typedef struct vlc_video_align {
64  /**
65  * Horizontal alignment.
66  *
67  * This must be one of \ref VLC_VIDEO_ALIGN_CENTER,
68  * \ref VLC_VIDEO_ALIGN_LEFT or \ref VLC_VIDEO_ALIGN_RIGHT.
69  */
70  char horizontal;
71 
72  /**
73  * Vectical alignment.
74  *
75  * This must be one of \ref VLC_VIDEO_ALIGN_CENTER,
76  * \ref VLC_VIDEO_ALIGN_TOP or \ref VLC_VIDEO_ALIGN_BOTTOM.
77  */
78  char vertical;
80 /** @} */
81 
82 /**
83  * User configuration for a video output display (\ref vout_display_t)
84  *
85  * This primarily controls the size of the display area within the video
86  * window, as follows:
87  * - If \ref is_display_filled is set,
88  * the video size is fitted to the display size.
89  * - If \ref window size is valid, the video size is set to the window size,
90  * - Otherwise, the video size is determined from the original video format,
91  * multiplied by the zoom factor.
92  */
93 typedef struct vout_display_cfg {
94  struct vout_window_t *window; /**< Window */
95 #if defined(__OS2__)
96  bool is_fullscreen VLC_DEPRECATED; /* Is the display fullscreen */
97 #endif
98 
99  /** Display properties */
100  struct {
101  unsigned width; /**< Requested display pixel width (0 by default). */
102  unsigned height; /**< Requested display pixel height (0 by default). */
103  vlc_rational_t sar; /**< Requested sample aspect ratio */
104  } display;
105 
106  /**
107  * Window properties
108  *
109  * Should be ignored from display modules.
110  */
111  struct {
112  /** Current window width */
113  unsigned width;
114  /** Current window height */
115  unsigned height;
116  } window_props;
117 
118  /** Alignment of the video within the window */
119  vlc_video_align_t align;
121  /** Automatic scaling/fitting flag */
122  bool is_display_filled;
124  /** Zoom ratio */
125  struct {
126  unsigned num;
127  unsigned den;
128  } zoom;
129 
130  vlc_viewpoint_t viewpoint;
132 
133 /**
134  * Information from a vout_display_t to configure
135  * the core behaviour.
136  *
137  * By default they are all false or NULL.
138  *
139  */
140 typedef struct {
141  bool can_scale_spu; /* Handles subpictures with a non default zoom factor */
142  const vlc_fourcc_t *subpicture_chromas; /* List of supported chromas for subpicture rendering. */
144 
145 /**
146  * Control query for vout_display_t
147  */
148 enum vout_display_query {
149  /**
150  * Asks to reset the internal buffers and picture format.
151  *
152  * This occurs after a
153  * \ref VOUT_DISPLAY_CHANGE_DISPLAY_SIZE,
154  * \ref VOUT_DISPLAY_CHANGE_DISPLAY_FILLED,
155  * \ref VOUT_DISPLAY_CHANGE_ZOOM,
156  * \ref VOUT_DISPLAY_CHANGE_SOURCE_ASPECT or
157  * \ref VOUT_DISPLAY_CHANGE_SOURCE_CROP
158  * control query returns an error.
159  */
160  VOUT_DISPLAY_RESET_PICTURES, /* const vout_display_cfg_t *, video_format_t * */
162 #if defined(__OS2__)
163  /* Ask the module to acknowledge/refuse the fullscreen state change after
164  * being requested (externally or by VOUT_DISPLAY_EVENT_FULLSCREEN */
165  VOUT_DISPLAY_CHANGE_FULLSCREEN VLC_DEPRECATED_ENUM, /* bool fs */
166  /* Ask the module to acknowledge/refuse the window management state change
167  * after being requested externally or by VOUT_DISPLAY_WINDOW_STATE */
168  VOUT_DISPLAY_CHANGE_WINDOW_STATE VLC_DEPRECATED_ENUM, /* unsigned state */
169 #endif
170  /**
171  * Notifies a change in display size.
172  *
173  * \retval VLC_SUCCESS if the display handled the change
174  * \retval VLC_EGENERIC if a \ref VOUT_DISPLAY_RESET_PICTURES request
175  * is necessary
176  */
177  VOUT_DISPLAY_CHANGE_DISPLAY_SIZE, /* const vout_display_cfg_t *p_cfg */
179  /**
180  * Notifies a change of the display fill display flag by the user.
181  *
182  * \retval VLC_SUCCESS if the display handled the change
183  * \retval VLC_EGENERIC if a \ref VOUT_DISPLAY_RESET_PICTURES request
184  * is necessary
185  */
186  VOUT_DISPLAY_CHANGE_DISPLAY_FILLED, /* const vout_display_cfg_t *p_cfg */
188  /**
189  * Notifies a change of the user zoom factor.
190  *
191  * \retval VLC_SUCCESS if the display handled the change
192  * \retval VLC_EGENERIC if a \ref VOUT_DISPLAY_RESET_PICTURES request
193  * is necessary
194  */
195  VOUT_DISPLAY_CHANGE_ZOOM, /* const vout_display_cfg_t *p_cfg */
197  /**
198  * Notifies a change of the sample aspect ratio.
199  *
200  * \retval VLC_SUCCESS if the display handled the change
201  * \retval VLC_EGENERIC if a \ref VOUT_DISPLAY_RESET_PICTURES request
202  * is necessary
203  */
204  VOUT_DISPLAY_CHANGE_SOURCE_ASPECT, /* const vout_display_cfg_t *p_cfg */
206  /**
207  * Notifies a change of the source cropping.
208  *
209  * The cropping requested is stored by source video_format_t::i_x/y_offset
210  * and video_format_t::i_visible_width/height
211  *
212  * \retval VLC_SUCCESS if the display handled the change
213  * \retval VLC_EGENERIC if a \ref VOUT_DISPLAY_RESET_PICTURES request
214  * is necessary
215  */
216  VOUT_DISPLAY_CHANGE_SOURCE_CROP, /* const vout_display_cfg_t *p_cfg */
218  /**
219  * Notifies a change of VR/360° viewpoint.
220  */
221  VOUT_DISPLAY_CHANGE_VIEWPOINT, /* const vout_display_cfg_t *p_cfg */
222 };
223 
224 /**
225  * Vout owner structures
226  */
227 struct vout_display_owner_t {
228  /* Private place holder for the vout_display_t creator
229  */
230  void *sys;
232  /* Event coming from the module
233  *
234  * This function is set prior to the module instantiation and must not
235  * be overwritten nor used directly (use the vout_display_SendEvent*
236  * wrapper.
237  *
238  * You can send it at any time i.e. from any vout_display_t functions or
239  * from another thread.
240  * Be careful, it does not ensure correct serialization if it is used
241  * from multiple threads.
242  */
243  void (*viewpoint_moved)(void *sys, const vlc_viewpoint_t *vp);
244 };
245 
246 /**
247  * "vout display" open callback
248  *
249  * @param vd vout display context
250  * @param cfg Initial and current configuration.
251  * @param fmtp By default, it is equal to vd->source except for the aspect
252  * ratio which is undefined(0) and is ignored. It can be changed by the module
253  * to request a different format.
254  * @param context XXX: to be defined.
255  * @return VLC_SUCCESS or a VLC error code
256  */
257 typedef int (*vout_display_open_cb)(vout_display_t *vd,
258  const vout_display_cfg_t *cfg,
259  video_format_t *fmtp,
260  vlc_video_context *context);
261 
262 #define set_callback_display(activate, priority) \
263  { \
264  vout_display_open_cb open__ = activate; \
265  (void) open__; \
266  set_callback(activate) \
267  } \
268  set_capability( "vout display", priority )
269 
270 
271 struct vout_display_t {
274  /**
275  * User configuration.
276  *
277  * This cannot be modified directly. It reflects the current values.
278  */
279  const vout_display_cfg_t *cfg;
281  /**
282  * Source video format.
283  *
284  * This is the format of the video that is being displayed (after decoding
285  * and filtering). It cannot be modified.
286  *
287  * \note
288  * Cropping is not requested while in the open function.
289  */
290  video_format_t source;
292  /**
293  * Picture format.
294  *
295  * This is the format of the pictures that are supplied to the
296  * \ref prepare and \ref display callbacks. Ideally, it should be identical
297  * or as close as possible as \ref source.
298  *
299  * This can only be changed from the display module activation callback,
300  * or within a VOUT_DISPLAY_RESET_PICTURES control request.
301  *
302  * By default, it is equal to ::source except for the aspect ratio
303  * which is undefined(0) and is ignored.
304  */
305  video_format_t fmt;
307  /* Information
308  *
309  * You can only set them in the open function.
310  */
311  vout_display_info_t info;
313  /**
314  * Prepares a picture and an optional subpicture for display (optional).
315  *
316  * This callback is called once a picture buffer content is ready,
317  * as far in advance as possible to the intended display time,
318  * but only after the previous picture was displayed.
319  *
320  * The callback should perform any preprocessing operation that will not
321  * actually cause the picture to be shown, such as blending the subpicture
322  * or upload the picture to video memory. If supported, this can also
323  * queue the picture to be shown asynchronously at the given date.
324  *
325  * If prepare is not \c NULL, there is an implicit guarantee that display
326  * will be invoked with the exact same picture afterwards:
327  * prepare 1st picture, display 1st picture, prepare 2nd picture, display
328  * 2nd picture, and so on.
329  *
330  * \note The picture buffers may have multiple references.
331  * Therefore the pixel content of the picture or of the subpicture
332  * must not be changed.
333  *
334  * \param pic picture
335  * \param subpic subpicture to render over the picture
336  * \param date time when the picture is intended to be shown
337  */
338  void (*prepare)(vout_display_t *, picture_t *pic,
339  subpicture_t *subpic, vlc_tick_t date);
340 
341  /**
342  * Displays a picture.
343  *
344  * This callback is invoked at the time when the picture should be shown.
345  * The picture must be displayed as soon as possible.
346  *
347  * \note The picture buffers may have multiple references.
348  * Therefore the pixel content of the picture or of the subpicture
349  * must not be changed.
350  */
351  void (*display)(vout_display_t *, picture_t *pic);
353  /**
354  * Performs a control request (mandatory).
355  *
356  * \param query request type
357  *
358  * See \ref vout_display_query for the list of request types.
359  */
360  int (*control)(vout_display_t *, int query, va_list);
362  /**
363  * Destroys the display.
364  */
365  void (*close)(vout_display_t *);
367  /**
368  * Private data for the display module.
369  *
370  * A module is free to use it as it wishes.
371  */
372  vout_display_sys_t *sys;
374  /* Reserved for the vout_display_t owner.
375  *
376  * It must not be overwritten nor used directly by a module.
377  */
378  vout_display_owner_t owner;
379 };
380 
381 /**
382  * Creates video output display.
383  */
384 VLC_API
387  const vout_display_cfg_t *, const char *module,
388  const vout_display_owner_t *);
389 
390 /**
391  * Destroys a video output display.
392  */
394 
395 /**
396  * Prepares a picture for display.
397  *
398  * This renders a picture for subsequent display, with vout_display_Display().
399  *
400  * \note A reference to the input picture is consumed by the function, which
401  * returns a reference to an output picture for display. The input and output
402  * picture may or may not be equal depending on the underlying display setup.
403  *
404  * \bug Currently, only one picture can be prepared at a time. It must be
405  * displayed with vout_display_Display() before any picture is prepared or
406  * before the display is destroyd with vout_display_Delete().
407  *
408  \ bug Rendering subpictures is not supported with this function yet.
409  * \c subpic must be @c NULL .
410  *
411  * \param vd display to prepare the picture for
412  * \param picture picure to be prepared
413  * \param subpic reserved, must be NULL
414  * \param date intended time to show the picture
415  * \return The prepared picture is returned, NULL on error.
416  */
418  subpicture_t *subpic, vlc_tick_t date);
419 
420 /**
421  * Displays a picture.
422  */
423 static inline void vout_display_Display(vout_display_t *vd, picture_t *picture)
424 {
425  if (vd->display != NULL)
426  vd->display(vd, picture);
427  picture_Release(picture);
428 }
429 
430 VLC_API
431 void vout_display_SetSize(vout_display_t *vd, unsigned width, unsigned height);
432 
434 
435 static inline void vout_display_SendEventMousePressed(vout_display_t *vd, int button)
436 {
438 }
439 static inline void vout_display_SendEventMouseReleased(vout_display_t *vd, int button)
440 {
442 }
444 {
446 }
448  const vlc_viewpoint_t *vp)
449 {
450  if (vd->owner.viewpoint_moved)
451  vd->owner.viewpoint_moved(vd->owner.sys, vp);
452 }
453 
454 /**
455  * Helper function that applies the necessary transforms to the mouse position
456  * and then calls vout_display_SendEventMouseMoved.
457  *
458  * \param vd vout_display_t.
459  * \param m_x Mouse x position (relative to place, origin is top left).
460  * \param m_y Mouse y position (relative to place, origin is top left).
461  */
462 static inline void vout_display_SendMouseMovedDisplayCoordinates(vout_display_t *vd, int m_x, int m_y)
463 {
464  vout_window_ReportMouseMoved(vd->cfg->window, m_x, m_y);
465 }
466 
467 static inline bool vout_display_cfg_IsWindowed(const vout_display_cfg_t *cfg)
468 {
469  return cfg->window->type != VOUT_WINDOW_TYPE_DUMMY;
470 }
471 
472 /**
473  * Computes the default display size given the source and
474  * the display configuration.
475  *
476  * This asssumes that the picture is already cropped.
477  */
478 VLC_API void vout_display_GetDefaultDisplaySize(unsigned *width, unsigned *height, const video_format_t *source, const vout_display_cfg_t *);
479 
480 
481 /**
482  * Video placement.
483  *
484  * This structure stores the result of a vout_display_PlacePicture() call.
485  */
486 typedef struct {
487  int x; /*< Relative pixel offset from the display left edge */
488  int y; /*< Relative pixel offset from the display top edge */
489  unsigned width; /*< Picture pixel width */
490  unsigned height; /*< Picture pixel height */
492 
493 /**
494  * Compares two \ref vout_display_place_t.
495  */
496 static inline bool vout_display_PlaceEquals(const vout_display_place_t *p1,
498 {
499  return p1->x == p2->x && p1->width == p2->width &&
500  p1->y == p2->y && p1->height == p2->height;
501 }
502 
503 /**
504  * Computes the intended picture placement inside the display.
505  *
506  * This function computes where to show a picture inside the display with
507  * respect to the provided parameters, and returns the result
508  * in a \ref vout_display_place_t structure.
509  *
510  * This assumes that cropping is done by an external mean.
511  *
512  * \param place Storage space for the picture placement [OUT]
513  * \param source Video source format
514  * \param cfg Display configuration
515  */
517 
518 /**
519  * Translates mouse state.
520  *
521  * This translates the mouse (pointer) state from window coordinates to
522  * video coordinates.
523  * @note @c video and @c window pointers may alias.
524  */
526  const vlc_mouse_t *window);
527 
528 /** @} */
529 #endif /* VLC_VOUT_DISPLAY_H */
Subpictures functions.
This file defines picture structures and functions in vlc.
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:463
#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
Information from a vout_display_t to configure the core behaviour.
Definition: vlc_vout_display.h:141
int x
Definition: vlc_vout_display.h:488
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:101
Video picture.
Definition: vlc_picture.h:127
void vout_display_SetSize(vout_display_t *vd, unsigned width, unsigned height)
Definition: display.c:634
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:452
unsigned height
Definition: vlc_vout_display.h:491
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:95
void vout_display_PlacePicture(vout_display_place_t *place, const video_format_t *source, const vout_display_cfg_t *cfg)
Computes the intended picture placement inside the display.
Definition: display.c:144
Video placement.
Definition: vlc_vout_display.h:487
#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
User configuration.
Definition: vlc_vout_display.h:280
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:448
struct vout_display_sys_t vout_display_sys_t
Definition: vlc_vout_display.h:48
Vout owner structures.
Definition: vlc_vout_display.h:228
Notifies a change of the sample aspect ratio.
Definition: vlc_vout_display.h:205
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:436
struct vout_display_cfg vout_display_cfg_t
User configuration for a video output display (vout_display_t)
Definition: decoder_helpers.c:232
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:440
vout_display_owner_t owner
Definition: vlc_vout_display.h:379
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:736
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:241
Viewpoints.
Definition: vlc_viewpoint.h:41
void vout_display_TranslateMouseState(vout_display_t *vd, vlc_mouse_t *video, const vlc_mouse_t *window)
Translates mouse state.
Definition: display.c:226
void * sys
Definition: vlc_vout_display.h:231
struct vlc_video_align vlc_video_align_t
Video alignment within the display.
video format description
Definition: vlc_es.h:349
void(* display)(vout_display_t *, picture_t *pic)
Displays a picture.
Definition: vlc_vout_display.h:352
Definition: vlc_mouse.h:32
Mouse state.
Definition: vlc_mouse.h:45
Notifies a change of VR/360° viewpoint.
Definition: vlc_vout_display.h:222
Video and audio viewpoint struct and helpers.
void vout_display_SendEventPicturesInvalid(vout_display_t *vd)
Definition: display.c:388
Notifies a change of the source cropping.
Definition: vlc_vout_display.h:217
static bool vout_display_cfg_IsWindowed(const vout_display_cfg_t *cfg)
Definition: vlc_vout_display.h:468
char vertical
Vectical alignment.
Definition: vlc_vout_display.h:79
Notifies a change in display size.
Definition: vlc_vout_display.h:178
void vout_display_Delete(vout_display_t *)
Destroys a video output display.
Definition: display.c:818
#define VLC_API
Definition: fourcc_gen.c:31
void(* viewpoint_moved)(void *sys, const vlc_viewpoint_t *vp)
Definition: vlc_vout_display.h:244
Video alignment within the display.
Definition: vlc_vout_display.h:64
vout_display_query
Control query for vout_display_t.
Definition: vlc_vout_display.h:149
unsigned width
Definition: vlc_vout_display.h:490
char horizontal
Horizontal alignment.
Definition: vlc_vout_display.h:71
static void vout_display_Display(vout_display_t *vd, picture_t *picture)
Displays a picture.
Definition: vlc_vout_display.h:424
int y
Definition: vlc_vout_display.h:489
static void vout_window_ReportMouseReleased(vout_window_t *window, int button)
Reports a mouse button release.
Definition: vlc_vout_window.h:636
Asks to reset the internal buffers and picture format.
Definition: vlc_vout_display.h:161
Notifies a change of the display fill display flag by the user.
Definition: vlc_vout_display.h:187
User configuration for a video output display (vout_display_t)
Definition: vlc_vout_display.h:94
This file defines picture pool structures and functions in vlc.
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:258
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)
Compares two vout_display_place_t.
Definition: vlc_vout_display.h:497
Definition: vlc_vout_display.h:272
static void vout_display_SendEventMouseDoubleClick(vout_display_t *vd)
Definition: vlc_vout_display.h:444
Window modules interface.
Notifies a change of the user zoom factor.
Definition: vlc_vout_display.h:196