]> git.sesse.net Git - vlc/blob - include/vlc_vout_display.h
input: replace ITEM_TYPE_NET by ITEM_TYPE_STREAM
[vlc] / include / vlc_vout_display.h
1 /*****************************************************************************
2  * vlc_vout_display.h: vout_display_t definitions
3  *****************************************************************************
4  * Copyright (C) 2009 Laurent Aimar
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifndef VLC_VOUT_DISPLAY_H
25 #define VLC_VOUT_DISPLAY_H 1
26
27 /**
28  * \file
29  * This file defines vout display structures and functions in vlc
30  */
31
32 #include <vlc_es.h>
33 #include <vlc_picture.h>
34 #include <vlc_picture_pool.h>
35 #include <vlc_subpicture.h>
36 #include <vlc_keys.h>
37 #include <vlc_mouse.h>
38 #include <vlc_vout_window.h>
39
40 /* XXX
41  * Do NOT use video_format_t::i_aspect but i_sar_num/den everywhere. i_aspect
42  * will be removed as soon as possible.
43  *
44  */
45 typedef struct vout_display_t vout_display_t;
46 typedef struct vout_display_sys_t vout_display_sys_t;
47 typedef struct vout_display_owner_t vout_display_owner_t;
48 typedef struct vout_display_owner_sys_t vout_display_owner_sys_t;
49
50 /**
51  * Possible alignments for vout_display.
52  */
53 typedef enum
54 {
55     VOUT_DISPLAY_ALIGN_CENTER,
56     /* */
57     VOUT_DISPLAY_ALIGN_LEFT,
58     VOUT_DISPLAY_ALIGN_RIGHT,
59     /* */
60     VOUT_DISPLAY_ALIGN_TOP,
61     VOUT_DISPLAY_ALIGN_BOTTOM,
62 } vout_display_align_t;
63
64 /**
65  * Window management state.
66  */
67 enum {
68     VOUT_WINDOW_STATE_NORMAL=0,
69     VOUT_WINDOW_STATE_ABOVE=1,
70     VOUT_WINDOW_STATE_BELOW=2,
71     VOUT_WINDOW_STACK_MASK=3,
72 };
73
74 /**
75  * Initial/Current configuration for a vout_display_t
76  */
77 typedef struct {
78     bool is_fullscreen;  /* Is the display fullscreen */
79
80     /* Display properties */
81     struct {
82         /* Window title (may be NULL) */
83         const char *title;
84
85         /* Display size */
86         unsigned  width;
87         unsigned  height;
88
89         /* Display SAR */
90         struct {
91             unsigned num;
92             unsigned den;
93         } sar;
94     } display;
95
96     /* Alignment of the picture inside the display */
97     struct {
98         int horizontal;
99         int vertical;
100     } align;
101
102     /* Do we fill up the display with the video */
103     bool is_display_filled;
104
105     /* Zoom to use
106      * It will be applied to the whole display if b_display_filled is set, otherwise
107      * only on the video source */
108     struct {
109         int num;
110         int den;
111     } zoom;
112
113 } vout_display_cfg_t;
114
115 /**
116  * Information from a vout_display_t to configure
117  * the core behaviour.
118  *
119  * By default they are all false or NULL.
120  *
121  */
122 typedef struct {
123     bool is_slow;                           /* The picture memory has slow read/write */
124     bool has_double_click;                  /* Is double-click generated */
125     bool has_hide_mouse;                    /* Is mouse automatically hidden */
126     bool has_pictures_invalid;              /* Will VOUT_DISPLAY_EVENT_PICTURES_INVALID be used */
127     bool has_event_thread;                  /* Will events (key at least) be emitted using an independent thread */
128     const vlc_fourcc_t *subpicture_chromas; /* List of supported chromas for subpicture rendering. */
129 } vout_display_info_t;
130
131 /**
132  * Control query for vout_display_t
133  */
134 enum {
135     /* Hide the mouse. It will be sent when
136      * vout_display_t::info.b_hide_mouse is false */
137     VOUT_DISPLAY_HIDE_MOUSE,
138
139     /* Ask to reset the internal buffers after a VOUT_DISPLAY_EVENT_PICTURES_INVALID
140      * request.
141      */
142     VOUT_DISPLAY_RESET_PICTURES,
143
144     /* Ask the module to acknowledge/refuse the fullscreen state change after
145      * being requested (externally or by VOUT_DISPLAY_EVENT_FULLSCREEN */
146     VOUT_DISPLAY_CHANGE_FULLSCREEN,     /* bool fs */
147
148     /* Ask the module to acknowledge/refuse the window management state change
149      * after being requested externally or by VOUT_DISPLAY_WINDOW_STATE */
150     VOUT_DISPLAY_CHANGE_WINDOW_STATE,         /* unsigned state */
151
152     /* Ask the module to acknowledge/refuse the display size change requested
153      * (externally or by VOUT_DISPLAY_EVENT_DISPLAY_SIZE) */
154     VOUT_DISPLAY_CHANGE_DISPLAY_SIZE,   /* const vout_display_cfg_t *p_cfg */
155
156     /* Ask the module to acknowledge/refuse fill display state change after
157      * being requested externally */
158     VOUT_DISPLAY_CHANGE_DISPLAY_FILLED, /* const vout_display_cfg_t *p_cfg */
159
160     /* Ask the module to acknowledge/refuse zoom change after being requested
161      * externally */
162     VOUT_DISPLAY_CHANGE_ZOOM, /* const vout_display_cfg_t *p_cfg */
163
164     /* Ask the module to acknowledge/refuse source aspect ratio after being
165      * requested externally */
166     VOUT_DISPLAY_CHANGE_SOURCE_ASPECT, /* const video_format_t *p_source */
167
168     /* Ask the module to acknowledge/refuse source crop change after being
169      * requested externally.
170      * The cropping requested is stored by video_format_t::i_x/y_offset and
171      * video_format_t::i_visible_width/height */
172     VOUT_DISPLAY_CHANGE_SOURCE_CROP,   /* const video_format_t *p_source */
173 };
174
175 /**
176  * Event from vout_display_t
177  *
178  * Events modifiying the state may be sent multiple times.
179  * Only the transition will be retained and acted upon.
180  */
181 enum {
182     /* TODO:
183      * ZOOM ? DISPLAY_FILLED ? ON_TOP ?
184      */
185     /* */
186     VOUT_DISPLAY_EVENT_PICTURES_INVALID,    /* The buffer are now invalid and need to be changed */
187
188     VOUT_DISPLAY_EVENT_FULLSCREEN,
189 #if defined(_WIN32) || defined(__OS2__)
190     VOUT_DISPLAY_EVENT_WINDOW_STATE,
191 #endif
192
193     VOUT_DISPLAY_EVENT_DISPLAY_SIZE,        /* The display size need to change : int i_width, int i_height */
194
195     /* */
196     VOUT_DISPLAY_EVENT_CLOSE,
197     VOUT_DISPLAY_EVENT_KEY,
198
199     /* Full mouse state.
200      * You can use it OR use the other mouse events. The core will do
201      * the conversion.
202      */
203     VOUT_DISPLAY_EVENT_MOUSE_STATE,
204
205     /* Mouse event */
206     VOUT_DISPLAY_EVENT_MOUSE_MOVED,
207     VOUT_DISPLAY_EVENT_MOUSE_PRESSED,
208     VOUT_DISPLAY_EVENT_MOUSE_RELEASED,
209     VOUT_DISPLAY_EVENT_MOUSE_DOUBLE_CLICK,
210 };
211
212 /**
213  * Vout owner structures
214  */
215 struct vout_display_owner_t {
216     /* Private place holder for the vout_display_t creator
217      */
218     vout_display_owner_sys_t *sys;
219
220     /* Event coming from the module
221      *
222      * This function is set prior to the module instantiation and must not
223      * be overwritten nor used directly (use the vout_display_SendEvent*
224      * wrapper.
225      *
226      * You can send it at any time i.e. from any vout_display_t functions or
227      * from another thread.
228      * Be careful, it does not ensure correct serialization if it is used
229      * from multiple threads.
230      */
231     void            (*event)(vout_display_t *, int, va_list);
232
233     /* Window management
234      *
235      * These functions are set prior to the module instantiation and must not
236      * be overwritten nor used directly (use the vout_display_*Window
237      * wrapper */
238     vout_window_t *(*window_new)(vout_display_t *, unsigned type);
239     void           (*window_del)(vout_display_t *, vout_window_t *);
240 };
241
242 struct vout_display_t {
243     VLC_COMMON_MEMBERS
244
245     /* Module */
246     module_t *module;
247
248     /* Initial and current configuration.
249      * You cannot modify it directly, you must use the appropriate events.
250      *
251      * It reflects the current values, i.e. after the event has been accepted
252      * and applied/configured if needed.
253      */
254     const vout_display_cfg_t *cfg;
255
256     /* video source format.
257      *
258      * Cropping is not requested while in the open function.
259      * You cannot change it.
260      */
261     video_format_t source;
262
263     /* picture_t format.
264      *
265      * You can only change it inside the module open function to
266      * match what you want, and when a VOUT_DISPLAY_RESET_PICTURES control
267      * request is made and succeeds.
268      *
269      * By default, it is equal to ::source except for the aspect ratio
270      * which is undefined(0) and is ignored.
271      */
272     video_format_t fmt;
273
274     /* Information
275      *
276      * You can only set them in the open function.
277      */
278     vout_display_info_t info;
279
280     /* Return a pointer over the current picture_pool_t* (mandatory).
281      *
282      * For performance reasons, it is best to provide at least count
283      * pictures but it is not mandatory.
284      * You can return NULL when you cannot/do not want to allocate
285      * pictures.
286      * The vout display module keeps the ownership of the pool and can
287      * destroy it only when closing or on invalid pictures control.
288      */
289     picture_pool_t *(*pool)(vout_display_t *, unsigned count);
290
291     /* Prepare a picture and an optional subpicture for display (optional).
292      *
293      * It is called before the next pf_display call to provide as much
294      * time as possible to prepare the given picture and the subpicture
295      * for display.
296      * You are guaranted that pf_display will always be called and using
297      * the exact same picture_t and subpicture_t.
298      * You cannot change the pixel content of the picture_t or of the
299      * subpicture_t.
300      */
301     void       (*prepare)(vout_display_t *, picture_t *, subpicture_t *);
302
303     /* Display a picture and an optional subpicture (mandatory).
304      *
305      * The picture and the optional subpicture must be displayed as soon as
306      * possible.
307      * You cannot change the pixel content of the picture_t or of the
308      * subpicture_t.
309      *
310      * This function gives away the ownership of the picture and of the
311      * subpicture, so you must release them as soon as possible.
312      */
313     void       (*display)(vout_display_t *, picture_t *, subpicture_t *);
314
315     /* Control on the module (mandatory) */
316     int        (*control)(vout_display_t *, int, va_list);
317
318     /* Manage pending event (optional) */
319     void       (*manage)(vout_display_t *);
320
321     /* Private place holder for the vout_display_t module (optional)
322      *
323      * A module is free to use it as it wishes.
324      */
325     vout_display_sys_t *sys;
326
327     /* Reserved for the vout_display_t owner.
328      *
329      * It must not be overwritten nor used directly by a module.
330      */
331     vout_display_owner_t owner;
332 };
333
334 static inline void vout_display_SendEvent(vout_display_t *vd, int query, ...)
335 {
336     va_list args;
337     va_start(args, query);
338     vd->owner.event(vd, query, args);
339     va_end(args);
340 }
341
342 static inline void vout_display_SendEventDisplaySize(vout_display_t *vd, int width, int height)
343 {
344     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_DISPLAY_SIZE, width, height);
345 }
346 static inline void vout_display_SendEventPicturesInvalid(vout_display_t *vd)
347 {
348     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_PICTURES_INVALID);
349 }
350 static inline void vout_display_SendEventClose(vout_display_t *vd)
351 {
352     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_CLOSE);
353 }
354 static inline void vout_display_SendEventKey(vout_display_t *vd, int key)
355 {
356     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_KEY, key);
357 }
358 static inline void vout_display_SendEventFullscreen(vout_display_t *vd, bool is_fullscreen)
359 {
360     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_FULLSCREEN, is_fullscreen);
361 }
362 #if defined(_WIN32)
363 static inline void vout_display_SendWindowState(vout_display_t *vd, unsigned state)
364 {
365     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_WINDOW_STATE, state);
366 }
367 #endif
368 /* The mouse position (State and Moved event) must be expressed against vout_display_t::source unit */
369 static inline void vout_display_SendEventMouseState(vout_display_t *vd, int x, int y, int button_mask)
370 {
371     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_STATE, x, y, button_mask);
372 }
373 static inline void vout_display_SendEventMouseMoved(vout_display_t *vd, int x, int y)
374 {
375     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_MOVED, x, y);
376 }
377 static inline void vout_display_SendEventMousePressed(vout_display_t *vd, int button)
378 {
379     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_PRESSED, button);
380 }
381 static inline void vout_display_SendEventMouseReleased(vout_display_t *vd, int button)
382 {
383     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_RELEASED, button);
384 }
385 static inline void vout_display_SendEventMouseDoubleClick(vout_display_t *vd)
386 {
387     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_DOUBLE_CLICK);
388 }
389
390 /**
391  * Asks for a new window of a given type.
392  */
393 static inline vout_window_t *vout_display_NewWindow(vout_display_t *vd, unsigned type)
394 {
395     return vd->owner.window_new(vd, type);
396 }
397 /**
398  * Deletes a window created by vout_display_NewWindow if window is non NULL
399  * or any unused windows otherwise.
400  */
401 static inline void vout_display_DeleteWindow(vout_display_t *vd,
402                                              vout_window_t *window)
403 {
404     vd->owner.window_del(vd, window);
405 }
406
407 static inline bool vout_display_IsWindowed(vout_display_t *vd)
408 {
409     vout_window_t *window = vout_display_NewWindow(vd, VOUT_WINDOW_TYPE_INVALID);
410     if (window != NULL)
411         vout_display_DeleteWindow(vd, window);
412     return window != NULL;
413 }
414
415 /**
416  * Computes the default display size given the source and
417  * the display configuration.
418  *
419  * This asssumes that the picture is already cropped.
420  */
421 VLC_API void vout_display_GetDefaultDisplaySize(unsigned *width, unsigned *height, const video_format_t *source, const vout_display_cfg_t *);
422
423
424 /**
425  * Structure used to store the result of a vout_display_PlacePicture.
426  */
427 typedef struct {
428     int x;
429     int y;
430     unsigned width;
431     unsigned height;
432 } vout_display_place_t;
433
434 /**
435  * Computes how to place a picture inside the display to respect
436  * the given parameters.
437  * This assumes that cropping is done by an external mean.
438  *
439  * \param p_place Place inside the window (window pixel unit)
440  * \param p_source Video source format
441  * \param p_cfg Display configuration
442  * \param b_clip If true, prevent the video to go outside the display (break zoom).
443  */
444 VLC_API void vout_display_PlacePicture(vout_display_place_t *place, const video_format_t *source, const vout_display_cfg_t *cfg, bool do_clipping);
445
446
447 /**
448  * Helper function that applies the necessary transforms to the mouse position
449  * and then calls vout_display_SendEventMouseMoved.
450  *
451  * \param vd vout_display_t.
452  * \param orient_display The orientation of the picture as seen on screen (probably ORIENT_NORMAL).
453  * \param m_x Mouse x position (relative to place, origin is top left).
454  * \param m_y Mouse y position (relative to place, origin is top left).
455  * \param place Place of the picture.
456  */
457 VLC_API void vout_display_SendMouseMovedDisplayCoordinates(vout_display_t *vd, video_orientation_t orient_display, int m_x, int m_y,
458                                                            vout_display_place_t *place);
459 #endif /* VLC_VOUT_DISPLAY_H */
460