qml: don't show resolution or audio channels label when unknown
[vlc.git] / include / vlc_vout_display.h
blob1827592887b26e1cc142ef2b4be65452bf7502a5
1 /*****************************************************************************
2 * vlc_vout_display.h: vout_display_t definitions
3 *****************************************************************************
4 * Copyright (C) 2009 Laurent Aimar
6 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
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.
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.
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 *****************************************************************************/
23 #ifndef VLC_VOUT_DISPLAY_H
24 #define VLC_VOUT_DISPLAY_H 1
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>
36 /**
37 * \defgroup video_display Video output display
38 * Video output display: output buffers and rendering
40 * \ingroup video_output
41 * @{
42 * \file
43 * Video output display modules interface
46 typedef struct vout_display_t vout_display_t;
47 typedef struct vout_display_sys_t vout_display_sys_t;
48 typedef struct vout_display_owner_t vout_display_owner_t;
50 /**
51 * \defgroup video_align Video alignment
52 * @{
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
60 /**
61 * Video alignment within the display.
63 typedef struct vlc_video_align {
64 /**
65 * Horizontal alignment.
67 * This must be one of \ref VLC_VIDEO_ALIGN_CENTER,
68 * \ref VLC_VIDEO_ALIGN_LEFT or \ref VLC_VIDEO_ALIGN_RIGHT.
70 char horizontal;
72 /**
73 * Vectical alignment.
75 * This must be one of \ref VLC_VIDEO_ALIGN_CENTER,
76 * \ref VLC_VIDEO_ALIGN_TOP or \ref VLC_VIDEO_ALIGN_BOTTOM.
78 char vertical;
79 } vlc_video_align_t;
80 /** @} */
82 /**
83 * User configuration for a video output display (\ref vout_display_t)
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 * - Otherwise, the video size is determined from the original video format,
90 * multiplied by the zoom factor.
92 typedef struct vout_display_cfg {
93 struct vout_window_t *window; /**< Window */
94 #if defined(__OS2__)
95 bool is_fullscreen VLC_DEPRECATED; /* Is the display fullscreen */
96 #endif
98 /** Display properties */
99 struct {
100 unsigned width; /**< Requested display pixel width (0 by default). */
101 unsigned height; /**< Requested display pixel height (0 by default). */
102 vlc_rational_t sar; /**< Requested sample aspect ratio */
103 } display;
105 /** Alignment of the video within the window */
106 vlc_video_align_t align;
108 /** Automatic scaling/fitting flag */
109 bool is_display_filled;
111 /** Zoom ratio */
112 struct {
113 unsigned num;
114 unsigned den;
115 } zoom;
117 vlc_viewpoint_t viewpoint;
118 } vout_display_cfg_t;
121 * Information from a vout_display_t to configure
122 * the core behaviour.
124 * By default they are all false or NULL.
127 typedef struct {
128 bool can_scale_spu; /* Handles subpictures with a non default zoom factor */
129 const vlc_fourcc_t *subpicture_chromas; /* List of supported chromas for subpicture rendering. */
130 } vout_display_info_t;
133 * Control query for vout_display_t
135 enum vout_display_query {
137 * Asks to reset the internal buffers and picture format.
139 * This occurs after a
140 * \ref VOUT_DISPLAY_CHANGE_DISPLAY_SIZE,
141 * \ref VOUT_DISPLAY_CHANGE_DISPLAY_FILLED,
142 * \ref VOUT_DISPLAY_CHANGE_ZOOM,
143 * \ref VOUT_DISPLAY_CHANGE_SOURCE_ASPECT or
144 * \ref VOUT_DISPLAY_CHANGE_SOURCE_CROP
145 * control query returns an error.
147 VOUT_DISPLAY_RESET_PICTURES, /* const vout_display_cfg_t *, video_format_t * */
149 #if defined(__OS2__)
150 /* Ask the module to acknowledge/refuse the fullscreen state change after
151 * being requested (externally or by VOUT_DISPLAY_EVENT_FULLSCREEN */
152 VOUT_DISPLAY_CHANGE_FULLSCREEN VLC_DEPRECATED_ENUM, /* bool fs */
153 /* Ask the module to acknowledge/refuse the window management state change
154 * after being requested externally or by VOUT_DISPLAY_WINDOW_STATE */
155 VOUT_DISPLAY_CHANGE_WINDOW_STATE VLC_DEPRECATED_ENUM, /* unsigned state */
156 #endif
158 * Notifies a change in display size.
160 * \retval VLC_SUCCESS if the display handled the change
161 * \retval VLC_EGENERIC if a \ref VOUT_DISPLAY_RESET_PICTURES request
162 * is necessary
164 VOUT_DISPLAY_CHANGE_DISPLAY_SIZE, /* const vout_display_cfg_t *p_cfg */
167 * Notifies a change of the display fill display flag by the user.
169 * \retval VLC_SUCCESS if the display handled the change
170 * \retval VLC_EGENERIC if a \ref VOUT_DISPLAY_RESET_PICTURES request
171 * is necessary
173 VOUT_DISPLAY_CHANGE_DISPLAY_FILLED, /* const vout_display_cfg_t *p_cfg */
176 * Notifies a change of the user zoom factor.
178 * \retval VLC_SUCCESS if the display handled the change
179 * \retval VLC_EGENERIC if a \ref VOUT_DISPLAY_RESET_PICTURES request
180 * is necessary
182 VOUT_DISPLAY_CHANGE_ZOOM, /* const vout_display_cfg_t *p_cfg */
185 * Notifies a change of the sample aspect ratio.
187 * \retval VLC_SUCCESS if the display handled the change
188 * \retval VLC_EGENERIC if a \ref VOUT_DISPLAY_RESET_PICTURES request
189 * is necessary
191 VOUT_DISPLAY_CHANGE_SOURCE_ASPECT, /* const vout_display_cfg_t *p_cfg */
194 * Notifies a change of the source cropping.
196 * The cropping requested is stored by source video_format_t::i_x/y_offset
197 * and video_format_t::i_visible_width/height
199 * \retval VLC_SUCCESS if the display handled the change
200 * \retval VLC_EGENERIC if a \ref VOUT_DISPLAY_RESET_PICTURES request
201 * is necessary
203 VOUT_DISPLAY_CHANGE_SOURCE_CROP, /* const vout_display_cfg_t *p_cfg */
206 * Notifies a change of VR/360° viewpoint.
208 VOUT_DISPLAY_CHANGE_VIEWPOINT, /* const vout_display_cfg_t *p_cfg */
212 * Event from vout_display_t
214 * Events modifiying the state may be sent multiple times.
215 * Only the transition will be retained and acted upon.
217 enum {
218 /* VR navigation, vlc_viewpoint_t* */
219 VOUT_DISPLAY_EVENT_VIEWPOINT_MOVED,
223 * Vout owner structures
225 struct vout_display_owner_t {
226 /* Private place holder for the vout_display_t creator
228 void *sys;
230 /* Event coming from the module
232 * This function is set prior to the module instantiation and must not
233 * be overwritten nor used directly (use the vout_display_SendEvent*
234 * wrapper.
236 * You can send it at any time i.e. from any vout_display_t functions or
237 * from another thread.
238 * Be careful, it does not ensure correct serialization if it is used
239 * from multiple threads.
241 void (*viewpoint_moved)(void *sys, const vlc_viewpoint_t *vp);
245 * "vout display" open callback
247 * @param vd vout display context
248 * @param cfg Initial and current configuration.
249 * @param fmtp By default, it is equal to vd->source except for the aspect
250 * ratio which is undefined(0) and is ignored. It can be changed by the module
251 * to request a different format.
252 * @param context XXX: to be defined.
253 * @return VLC_SUCCESS or a VLC error code
255 typedef int (*vout_display_open_cb)(vout_display_t *vd,
256 const vout_display_cfg_t *cfg,
257 video_format_t *fmtp,
258 vlc_video_context *context);
260 #define set_callback_display(activate, priority) \
262 vout_display_open_cb open__ = activate; \
263 (void) open__; \
264 set_callback(activate) \
266 set_capability( "vout display", priority )
269 struct vout_display_t {
270 struct vlc_object_t obj;
273 * User configuration.
275 * This cannot be modified directly. It reflects the current values.
277 const vout_display_cfg_t *cfg;
280 * Source video format.
282 * This is the format of the video that is being displayed (after decoding
283 * and filtering). It cannot be modified.
285 * \note
286 * Cropping is not requested while in the open function.
288 video_format_t source;
291 * Picture format.
293 * This is the format of the pictures that are supplied to the
294 * \ref prepare and \ref display callbacks. Ideally, it should be identical
295 * or as close as possible as \ref source.
297 * This can only be changed from the display module activation callback,
298 * or within a VOUT_DISPLAY_RESET_PICTURES control request.
300 * By default, it is equal to ::source except for the aspect ratio
301 * which is undefined(0) and is ignored.
303 video_format_t fmt;
305 /* Information
307 * You can only set them in the open function.
309 vout_display_info_t info;
311 /* Return a pointer over the current picture_pool_t* (optional).
313 * For performance reasons, it is best to provide at least count
314 * pictures but it is not mandatory.
315 * You can return NULL when you cannot/do not want to allocate
316 * pictures.
317 * The vout display module keeps the ownership of the pool and can
318 * destroy it only when closing or on invalid pictures control.
320 picture_pool_t *(*pool)(vout_display_t *, unsigned count);
323 * Prepares a picture and an optional subpicture for display (optional).
325 * This callback is called once a picture buffer content is ready,
326 * as far in advance as possible to the intended display time,
327 * but only after the previous picture was displayed.
329 * The callback should perform any preprocessing operation that will not
330 * actually cause the picture to be shown, such as blending the subpicture
331 * or upload the picture to video memory. If supported, this can also
332 * queue the picture to be shown asynchronously at the given date.
334 * If prepare is not \c NULL, there is an implicit guarantee that display
335 * will be invoked with the exact same picture afterwards:
336 * prepare 1st picture, display 1st picture, prepare 2nd picture, display
337 * 2nd picture, and so on.
339 * \note The picture buffers may have multiple references.
340 * Therefore the pixel content of the picture or of the subpicture
341 * must not be changed.
343 * \param pic picture
344 * \param subpic subpicture to render over the picture
345 * \param date time when the picture is intended to be shown
347 void (*prepare)(vout_display_t *, picture_t *pic,
348 subpicture_t *subpic, vlc_tick_t date);
351 * Displays a picture.
353 * This callback is invoked at the time when the picture should be shown.
354 * The picture must be displayed as soon as possible.
356 * \note The picture buffers may have multiple references.
357 * Therefore the pixel content of the picture or of the subpicture
358 * must not be changed.
360 void (*display)(vout_display_t *, picture_t *pic);
363 * Performs a control request (mandatory).
365 * \param query request type
367 * See \ref vout_display_query for the list of request types.
369 int (*control)(vout_display_t *, int query, va_list);
372 * Destroys the display.
374 void (*close)(vout_display_t *);
377 * Private data for the display module.
379 * A module is free to use it as it wishes.
381 vout_display_sys_t *sys;
383 /* Reserved for the vout_display_t owner.
385 * It must not be overwritten nor used directly by a module.
387 vout_display_owner_t owner;
391 * Creates video output display.
393 VLC_API
394 vout_display_t *vout_display_New(vlc_object_t *,
395 const video_format_t *, vlc_video_context *,
396 const vout_display_cfg_t *, const char *module,
397 const vout_display_owner_t *);
400 * Destroys a video output display.
402 VLC_API void vout_display_Delete(vout_display_t *);
405 * Prepares a picture for display.
407 * This renders a picture for subsequent display, with vout_display_Display().
409 * \note A reference to the input picture is consumed by the function, which
410 * returns a reference to an output picture for display. The input and output
411 * picture may or may not be equal depending on the underlying display setup.
413 * \bug Currently, only one picture can be prepared at a time. It must be
414 * displayed with vout_display_Display() before any picture is prepared or
415 * before the display is destroyd with vout_display_Delete().
417 \ bug Rendering subpictures is not supported with this function yet.
418 * \c subpic must be @c NULL .
420 * \param vd display to prepare the picture for
421 * \param picture picure to be prepared
422 * \param subpic reserved, must be NULL
423 * \param date intended time to show the picture
424 * \return The prepared picture is returned, NULL on error.
426 VLC_API picture_t *vout_display_Prepare(vout_display_t *vd, picture_t *picture,
427 subpicture_t *subpic, vlc_tick_t date);
430 * Displays a picture.
432 static inline void vout_display_Display(vout_display_t *vd, picture_t *picture)
434 if (vd->display != NULL)
435 vd->display(vd, picture);
436 picture_Release(picture);
439 VLC_API
440 void vout_display_SetSize(vout_display_t *vd, unsigned width, unsigned height);
442 static inline int vout_display_Control(vout_display_t *vd, int query, ...)
444 va_list ap;
445 int ret;
447 va_start(ap, query);
448 ret = vd->control(vd, query, ap);
449 va_end(ap);
450 return ret;
453 VLC_API void vout_display_SendEventPicturesInvalid(vout_display_t *vd);
455 static inline void vout_display_SendEventMousePressed(vout_display_t *vd, int button)
457 vout_window_ReportMousePressed(vd->cfg->window, button);
459 static inline void vout_display_SendEventMouseReleased(vout_display_t *vd, int button)
461 vout_window_ReportMouseReleased(vd->cfg->window, button);
463 static inline void vout_display_SendEventMouseDoubleClick(vout_display_t *vd)
465 vout_window_ReportMouseDoubleClick(vd->cfg->window, MOUSE_BUTTON_LEFT);
467 static inline void vout_display_SendEventViewpointMoved(vout_display_t *vd,
468 const vlc_viewpoint_t *vp)
470 if (vd->owner.viewpoint_moved)
471 vd->owner.viewpoint_moved(vd->owner.sys, vp);
475 * Helper function that applies the necessary transforms to the mouse position
476 * and then calls vout_display_SendEventMouseMoved.
478 * \param vd vout_display_t.
479 * \param m_x Mouse x position (relative to place, origin is top left).
480 * \param m_y Mouse y position (relative to place, origin is top left).
482 static inline void vout_display_SendMouseMovedDisplayCoordinates(vout_display_t *vd, int m_x, int m_y)
484 vout_window_ReportMouseMoved(vd->cfg->window, m_x, m_y);
487 static inline bool vout_display_cfg_IsWindowed(const vout_display_cfg_t *cfg)
489 return cfg->window->type != VOUT_WINDOW_TYPE_DUMMY;
493 * Computes the default display size given the source and
494 * the display configuration.
496 * This asssumes that the picture is already cropped.
498 VLC_API void vout_display_GetDefaultDisplaySize(unsigned *width, unsigned *height, const video_format_t *source, const vout_display_cfg_t *);
502 * Video placement.
504 * This structure stores the result of a vout_display_PlacePicture() call.
506 typedef struct {
507 int x; /*< Relative pixel offset from the display left edge */
508 int y; /*< Relative pixel offset from the display top edge */
509 unsigned width; /*< Picture pixel width */
510 unsigned height; /*< Picture pixel height */
511 } vout_display_place_t;
514 * Compares two \ref vout_display_place_t.
516 static inline bool vout_display_PlaceEquals(const vout_display_place_t *p1,
517 const vout_display_place_t *p2)
519 return p1->x == p2->x && p1->width == p2->width &&
520 p1->y == p2->y && p1->height == p2->height;
524 * Computes the intended picture placement inside the display.
526 * This function computes where to show a picture inside the display with
527 * respect to the provided parameters, and returns the result
528 * in a \ref vout_display_place_t structure.
530 * This assumes that cropping is done by an external mean.
532 * \param place Storage space for the picture placement [OUT]
533 * \param source Video source format
534 * \param cfg Display configuration
536 VLC_API void vout_display_PlacePicture(vout_display_place_t *place, const video_format_t *source, const vout_display_cfg_t *cfg);
539 * Translates mouse state.
541 * This translates the mouse (pointer) state from window coordinates to
542 * video coordinates.
543 * @note @c video and @c window pointers may alias.
545 void vout_display_TranslateMouseState(vout_display_t *vd, vlc_mouse_t *video,
546 const vlc_mouse_t *window);
548 /** @} */
549 #endif /* VLC_VOUT_DISPLAY_H */