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
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>
33 #include <vlc_vout_window.h>
34 #include <vlc_viewpoint.h>
37 * \defgroup video_display Video output display
38 * Video output display: output buffers and rendering
40 * \ingroup video_output
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
;
51 * Possible alignments for vout_display.
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
59 typedef struct vlc_video_align
{
65 * Initial/Current configuration for a vout_display_t
67 typedef struct vout_display_cfg
{
68 struct vout_window_t
*window
; /**< Window */
69 #if defined(_WIN32) || defined(__OS2__)
70 bool is_fullscreen VLC_DEPRECATED
; /* Is the display fullscreen */
73 /* Display properties */
83 /* Alignment of the picture inside the display */
84 vlc_video_align_t align
;
86 /* Do we fill up the display with the video */
87 bool is_display_filled
;
90 * It will be applied to the whole display if b_display_filled is set, otherwise
91 * only on the video source */
97 vlc_viewpoint_t viewpoint
;
101 * Information from a vout_display_t to configure
102 * the core behaviour.
104 * By default they are all false or NULL.
108 bool is_slow
; /* The picture memory has slow read/write */
109 bool has_double_click
; /* Is double-click generated */
110 bool has_pictures_invalid
; /* Can handle VOUT_DISPLAY_RESET_PICTURES */
111 bool can_scale_spu
; /* Handles subpictures with a non default zoom factor */
112 const vlc_fourcc_t
*subpicture_chromas
; /* List of supported chromas for subpicture rendering. */
113 } vout_display_info_t
;
116 * Control query for vout_display_t
119 /* Ask to reset the internal buffers after a
120 * \ref VOUT_DISPLAY_CHANGE_DISPLAY_SIZE,
121 * \ref VOUT_DISPLAY_CHANGE_DISPLAY_FILLED,
122 * \ref VOUT_DISPLAY_CHANGE_ZOOM,
123 * \ref VOUT_DISPLAY_CHANGE_SOURCE_ASPECT or
124 * \ref VOUT_DISPLAY_CHANGE_SOURCE_CROP
125 * control query returns an error.
127 VOUT_DISPLAY_RESET_PICTURES
, /* const vout_display_cfg_t *, es_format_t * */
129 #if defined(_WIN32) || defined(__OS2__)
130 /* Ask the module to acknowledge/refuse the fullscreen state change after
131 * being requested (externally or by VOUT_DISPLAY_EVENT_FULLSCREEN */
132 VOUT_DISPLAY_CHANGE_FULLSCREEN VLC_DEPRECATED_ENUM
, /* bool fs */
133 /* Ask the module to acknowledge/refuse the window management state change
134 * after being requested externally or by VOUT_DISPLAY_WINDOW_STATE */
135 VOUT_DISPLAY_CHANGE_WINDOW_STATE VLC_DEPRECATED_ENUM
, /* unsigned state */
137 /* Ask the module to acknowledge the display size change */
138 VOUT_DISPLAY_CHANGE_DISPLAY_SIZE
, /* const vout_display_cfg_t *p_cfg */
140 /* Ask the module to acknowledge/refuse fill display state change after
141 * being requested externally */
142 VOUT_DISPLAY_CHANGE_DISPLAY_FILLED
, /* const vout_display_cfg_t *p_cfg */
144 /* Ask the module to acknowledge/refuse zoom change after being requested
146 VOUT_DISPLAY_CHANGE_ZOOM
, /* const vout_display_cfg_t *p_cfg */
148 /* Ask the module to acknowledge/refuse source aspect ratio after being
149 * requested externally */
150 VOUT_DISPLAY_CHANGE_SOURCE_ASPECT
, /* const vout_display_cfg_t *p_cfg */
152 /* Ask the module to acknowledge/refuse source crop change after being
153 * requested externally.
154 * The cropping requested is stored by source video_format_t::i_x/y_offset
155 * and video_format_t::i_visible_width/height */
156 VOUT_DISPLAY_CHANGE_SOURCE_CROP
, /* const vout_display_cfg_t *p_cfg */
158 /* Ask the module to acknowledge/refuse VR/360° viewing direction after
159 * being requested externally */
160 VOUT_DISPLAY_CHANGE_VIEWPOINT
, /* const vout_display_cfg_t *p_cfg */
164 * Event from vout_display_t
166 * Events modifiying the state may be sent multiple times.
167 * Only the transition will be retained and acted upon.
171 VOUT_DISPLAY_EVENT_VIEWPOINT_MOVED
,
175 * Vout owner structures
177 struct vout_display_owner_t
{
178 /* Private place holder for the vout_display_t creator
182 /* Event coming from the module
184 * This function is set prior to the module instantiation and must not
185 * be overwritten nor used directly (use the vout_display_SendEvent*
188 * You can send it at any time i.e. from any vout_display_t functions or
189 * from another thread.
190 * Be careful, it does not ensure correct serialization if it is used
191 * from multiple threads.
193 void (*event
)(vout_display_t
*, int, va_list);
197 * "vout display" open callback
199 * @param vd vout display context
200 * @param cfg Initial and current configuration.
201 * @param fmtp By default, it is equal to vd->source except for the aspect
202 * ratio which is undefined(0) and is ignored. It can be changed by the module
203 * to request a different format.
204 * @param context XXX: to be defined.
205 * @return VLC_SUCCESS or a VLC error code
207 typedef int (*vout_display_open_cb
)(vout_display_t
*vd
,
208 const vout_display_cfg_t
*cfg
,
209 video_format_t
*fmtp
,
210 vlc_video_context
*context
);
213 * "vout display" close callback
215 * @param vd vout display context
217 typedef int (*vout_display_close_cb
)(vout_display_t
*vd
);
219 struct vout_display_t
{
220 struct vlc_common_members obj
;
225 /* Initial and current configuration.
226 * You cannot modify it directly, you must use the appropriate events.
228 * It reflects the current values, i.e. after the event has been accepted
229 * and applied/configured if needed.
231 const vout_display_cfg_t
*cfg
;
233 /* video source format.
235 * Cropping is not requested while in the open function.
236 * You cannot change it.
238 video_format_t source
;
242 * You can only change it inside the module open function to
243 * match what you want, and when a VOUT_DISPLAY_RESET_PICTURES control
244 * request is made and succeeds.
246 * By default, it is equal to ::source except for the aspect ratio
247 * which is undefined(0) and is ignored.
253 * You can only set them in the open function.
255 vout_display_info_t info
;
257 /* Return a pointer over the current picture_pool_t* (mandatory).
259 * For performance reasons, it is best to provide at least count
260 * pictures but it is not mandatory.
261 * You can return NULL when you cannot/do not want to allocate
263 * The vout display module keeps the ownership of the pool and can
264 * destroy it only when closing or on invalid pictures control.
266 picture_pool_t
*(*pool
)(vout_display_t
*, unsigned count
);
268 /* Prepare a picture and an optional subpicture for display (optional).
270 * It is called before the next pf_display call to provide as much
271 * time as possible to prepare the given picture and the subpicture
273 * You are guaranted that pf_display will always be called and using
274 * the exact same picture_t and subpicture_t.
275 * You cannot change the pixel content of the picture_t or of the
278 void (*prepare
)(vout_display_t
*, picture_t
*, subpicture_t
*,
281 /* Display a picture.
283 * The picture must be displayed as soon as possible.
284 * You cannot change the pixel content of the picture_t.
286 void (*display
)(vout_display_t
*, picture_t
*);
288 /* Control on the module (mandatory) */
289 int (*control
)(vout_display_t
*, int, va_list);
291 /* Private place holder for the vout_display_t module (optional)
293 * A module is free to use it as it wishes.
295 vout_display_sys_t
*sys
;
297 /* Reserved for the vout_display_t owner.
299 * It must not be overwritten nor used directly by a module.
301 vout_display_owner_t owner
;
305 * Creates video output display.
308 vout_display_t
*vout_display_New(vlc_object_t
*, const video_format_t
*,
309 const vout_display_cfg_t
*, const char *module
,
310 const vout_display_owner_t
*);
313 * Destroys a video output display.
315 VLC_API
void vout_display_Delete(vout_display_t
*);
318 * Prepares a picture for display.
320 * This renders a picture for subsequent display, with vout_display_Display().
322 * \note A reference to the input picture is consumed by the function, which
323 * returns a reference to an output picture for display. The input and output
324 * picture may or may not be equal depending on the underlying display setup.
326 * \bug Currently, only one picture can be prepared at a time. It must be
327 * displayed with vout_display_Display() before any picture is prepared or
328 * before the display is destroyd with vout_display_Delete().
330 \ bug Rendering subpictures is not supported with this function yet.
331 * \c subpic must be @c NULL .
333 * \param vd display to prepare the picture for
334 * \param picture picure to be prepared
335 * \param subpic reserved, must be NULL
336 * \param date intended time to show the picture
337 * \return The prepared picture is returned, NULL on error.
339 VLC_API picture_t
*vout_display_Prepare(vout_display_t
*vd
, picture_t
*picture
,
340 subpicture_t
*subpic
, vlc_tick_t date
);
343 * Displays a picture.
345 static inline void vout_display_Display(vout_display_t
*vd
, picture_t
*picture
)
347 if (vd
->display
!= NULL
)
348 vd
->display(vd
, picture
);
349 picture_Release(picture
);
353 void vout_display_SetSize(vout_display_t
*vd
, unsigned width
, unsigned height
);
355 static inline int vout_display_Control(vout_display_t
*vd
, int query
, ...)
361 ret
= vd
->control(vd
, query
, ap
);
366 static inline void vout_display_SendEvent(vout_display_t
*vd
, int query
, ...)
369 va_start(args
, query
);
370 vd
->owner
.event(vd
, query
, args
);
374 VLC_API
void vout_display_SendEventPicturesInvalid(vout_display_t
*vd
);
376 #if defined(_WIN32) || defined(__OS2__)
378 static inline void vout_display_SendEventFullscreen(vout_display_t
*vd
, bool is_fullscreen
)
380 if (vout_display_Control(vd
, VOUT_DISPLAY_CHANGE_FULLSCREEN
,
381 is_fullscreen
) == VLC_SUCCESS
)
382 ((vout_display_cfg_t
*)vd
->cfg
)->is_fullscreen
= is_fullscreen
;
386 static inline void vout_display_SendWindowState(vout_display_t
*vd
, unsigned state
)
388 vout_display_Control(vd
, VOUT_DISPLAY_CHANGE_WINDOW_STATE
, state
);
391 static inline void vout_display_SendEventMousePressed(vout_display_t
*vd
, int button
)
393 vout_window_ReportMousePressed(vd
->cfg
->window
, button
);
395 static inline void vout_display_SendEventMouseReleased(vout_display_t
*vd
, int button
)
397 vout_window_ReportMouseReleased(vd
->cfg
->window
, button
);
399 static inline void vout_display_SendEventMouseDoubleClick(vout_display_t
*vd
)
401 vout_window_ReportMouseDoubleClick(vd
->cfg
->window
, MOUSE_BUTTON_LEFT
);
403 static inline void vout_display_SendEventViewpointMoved(vout_display_t
*vd
,
404 const vlc_viewpoint_t
*vp
)
406 vout_display_SendEvent(vd
, VOUT_DISPLAY_EVENT_VIEWPOINT_MOVED
, vp
);
409 static inline bool vout_display_cfg_IsWindowed(const vout_display_cfg_t
*cfg
)
411 return cfg
->window
->type
!= VOUT_WINDOW_TYPE_DUMMY
;
415 * Computes the default display size given the source and
416 * the display configuration.
418 * This asssumes that the picture is already cropped.
420 VLC_API
void vout_display_GetDefaultDisplaySize(unsigned *width
, unsigned *height
, const video_format_t
*source
, const vout_display_cfg_t
*);
424 * Structure used to store the result of a vout_display_PlacePicture.
431 } vout_display_place_t
;
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.
438 * \param p_place Place inside the window (window pixel unit)
439 * \param p_source Video source format
440 * \param p_cfg Display configuration
442 VLC_API
void vout_display_PlacePicture(vout_display_place_t
*place
, const video_format_t
*source
, const vout_display_cfg_t
*cfg
);
445 * Translates mouse state.
447 * This translates the mouse (pointer) state from window coordinates to
449 * @note @c video and @c window pointers may alias.
451 void vout_display_TranslateMouseState(vout_display_t
*vd
, vlc_mouse_t
*video
,
452 const vlc_mouse_t
*window
);
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 VLC_API
void vout_display_SendMouseMovedDisplayCoordinates(vout_display_t
*vd
, int m_x
, int m_y
);
465 #endif /* VLC_VOUT_DISPLAY_H */