vout: vout_ChangeRate: remove display assert
[vlc.git] / include / vlc_vout_display.h
blobb6282b052b4a4b590bda98619730f8d8f2d3e1ec
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 * - 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.
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
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;
107 * Window properties
109 * Should be ignored from display modules.
111 struct {
112 /** Current window width */
113 unsigned width;
114 /** Current window height */
115 unsigned height;
116 } window_props;
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;
130 vlc_viewpoint_t viewpoint;
131 } vout_display_cfg_t;
134 * Information from a vout_display_t to configure
135 * the core behaviour.
137 * By default they are all false or NULL.
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. */
143 } vout_display_info_t;
146 * Control query for vout_display_t
148 enum vout_display_query {
150 * Asks to reset the internal buffers and picture format.
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.
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
171 * Notifies a change in display size.
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
177 VOUT_DISPLAY_CHANGE_DISPLAY_SIZE, /* const vout_display_cfg_t *p_cfg */
180 * Notifies a change of the display fill display flag by the user.
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
186 VOUT_DISPLAY_CHANGE_DISPLAY_FILLED, /* const vout_display_cfg_t *p_cfg */
189 * Notifies a change of the user zoom factor.
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
195 VOUT_DISPLAY_CHANGE_ZOOM, /* const vout_display_cfg_t *p_cfg */
198 * Notifies a change of the sample aspect ratio.
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
204 VOUT_DISPLAY_CHANGE_SOURCE_ASPECT, /* const vout_display_cfg_t *p_cfg */
207 * Notifies a change of the source cropping.
209 * The cropping requested is stored by source video_format_t::i_x/y_offset
210 * and video_format_t::i_visible_width/height
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
216 VOUT_DISPLAY_CHANGE_SOURCE_CROP, /* const vout_display_cfg_t *p_cfg */
219 * Notifies a change of VR/360° viewpoint.
221 VOUT_DISPLAY_CHANGE_VIEWPOINT, /* const vout_display_cfg_t *p_cfg */
225 * Vout owner structures
227 struct vout_display_owner_t {
228 /* Private place holder for the vout_display_t creator
230 void *sys;
232 /* Event coming from the module
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.
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.
243 void (*viewpoint_moved)(void *sys, const vlc_viewpoint_t *vp);
247 * "vout display" open callback
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
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);
262 #define set_callback_display(activate, priority) \
264 vout_display_open_cb open__ = activate; \
265 (void) open__; \
266 set_callback(activate) \
268 set_capability( "vout display", priority )
271 struct vout_display_t {
272 struct vlc_object_t obj;
275 * User configuration.
277 * This cannot be modified directly. It reflects the current values.
279 const vout_display_cfg_t *cfg;
282 * Source video format.
284 * This is the format of the video that is being displayed (after decoding
285 * and filtering). It cannot be modified.
287 * \note
288 * Cropping is not requested while in the open function.
290 video_format_t source;
293 * Picture format.
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.
299 * This can only be changed from the display module activation callback,
300 * or within a VOUT_DISPLAY_RESET_PICTURES control request.
302 * By default, it is equal to ::source except for the aspect ratio
303 * which is undefined(0) and is ignored.
305 video_format_t fmt;
307 /* Information
309 * You can only set them in the open function.
311 vout_display_info_t info;
314 * Prepares a picture and an optional subpicture for display (optional).
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.
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.
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.
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.
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
338 void (*prepare)(vout_display_t *, picture_t *pic,
339 subpicture_t *subpic, vlc_tick_t date);
342 * Displays a picture.
344 * This callback is invoked at the time when the picture should be shown.
345 * The picture must be displayed as soon as possible.
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.
351 void (*display)(vout_display_t *, picture_t *pic);
354 * Performs a control request (mandatory).
356 * \param query request type
358 * See \ref vout_display_query for the list of request types.
360 int (*control)(vout_display_t *, int query, va_list);
363 * Destroys the display.
365 void (*close)(vout_display_t *);
368 * Private data for the display module.
370 * A module is free to use it as it wishes.
372 vout_display_sys_t *sys;
374 /* Reserved for the vout_display_t owner.
376 * It must not be overwritten nor used directly by a module.
378 vout_display_owner_t owner;
382 * Creates video output display.
384 VLC_API
385 vout_display_t *vout_display_New(vlc_object_t *,
386 const video_format_t *, vlc_video_context *,
387 const vout_display_cfg_t *, const char *module,
388 const vout_display_owner_t *);
391 * Destroys a video output display.
393 VLC_API void vout_display_Delete(vout_display_t *);
396 * Prepares a picture for display.
398 * This renders a picture for subsequent display, with vout_display_Display().
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.
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().
408 \ bug Rendering subpictures is not supported with this function yet.
409 * \c subpic must be @c NULL .
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.
417 VLC_API picture_t *vout_display_Prepare(vout_display_t *vd, picture_t *picture,
418 subpicture_t *subpic, vlc_tick_t date);
421 * Displays a picture.
423 static inline void vout_display_Display(vout_display_t *vd, picture_t *picture)
425 if (vd->display != NULL)
426 vd->display(vd, picture);
427 picture_Release(picture);
430 VLC_API
431 void vout_display_SetSize(vout_display_t *vd, unsigned width, unsigned height);
433 VLC_API void vout_display_SendEventPicturesInvalid(vout_display_t *vd);
435 static inline void vout_display_SendEventMousePressed(vout_display_t *vd, int button)
437 vout_window_ReportMousePressed(vd->cfg->window, button);
439 static inline void vout_display_SendEventMouseReleased(vout_display_t *vd, int button)
441 vout_window_ReportMouseReleased(vd->cfg->window, button);
443 static inline void vout_display_SendEventMouseDoubleClick(vout_display_t *vd)
445 vout_window_ReportMouseDoubleClick(vd->cfg->window, MOUSE_BUTTON_LEFT);
447 static inline void vout_display_SendEventViewpointMoved(vout_display_t *vd,
448 const vlc_viewpoint_t *vp)
450 if (vd->owner.viewpoint_moved)
451 vd->owner.viewpoint_moved(vd->owner.sys, vp);
455 * Helper function that applies the necessary transforms to the mouse position
456 * and then calls vout_display_SendEventMouseMoved.
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).
462 static inline void vout_display_SendMouseMovedDisplayCoordinates(vout_display_t *vd, int m_x, int m_y)
464 vout_window_ReportMouseMoved(vd->cfg->window, m_x, m_y);
467 static inline bool vout_display_cfg_IsWindowed(const vout_display_cfg_t *cfg)
469 return cfg->window->type != VOUT_WINDOW_TYPE_DUMMY;
473 * Computes the default display size given the source and
474 * the display configuration.
476 * This asssumes that the picture is already cropped.
478 VLC_API void vout_display_GetDefaultDisplaySize(unsigned *width, unsigned *height, const video_format_t *source, const vout_display_cfg_t *);
482 * Video placement.
484 * This structure stores the result of a vout_display_PlacePicture() call.
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 */
491 } vout_display_place_t;
494 * Compares two \ref vout_display_place_t.
496 static inline bool vout_display_PlaceEquals(const vout_display_place_t *p1,
497 const vout_display_place_t *p2)
499 return p1->x == p2->x && p1->width == p2->width &&
500 p1->y == p2->y && p1->height == p2->height;
504 * Computes the intended picture placement inside the display.
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.
510 * This assumes that cropping is done by an external mean.
512 * \param place Storage space for the picture placement [OUT]
513 * \param source Video source format
514 * \param cfg Display configuration
516 VLC_API void vout_display_PlacePicture(vout_display_place_t *place, const video_format_t *source, const vout_display_cfg_t *cfg);
519 * Translates mouse state.
521 * This translates the mouse (pointer) state from window coordinates to
522 * video coordinates.
523 * @note @c video and @c window pointers may alias.
525 void vout_display_TranslateMouseState(vout_display_t *vd, vlc_mouse_t *video,
526 const vlc_mouse_t *window);
528 /** @} */
529 #endif /* VLC_VOUT_DISPLAY_H */