vlc_vout_display.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * vlc_vout_display.h: vout_display_t definitions
00003  *****************************************************************************
00004  * Copyright (C) 2009 Laurent Aimar
00005  * $Id: 503f92db13b46b212b32b24095ff674fa76200fa $
00006  *
00007  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00022  *****************************************************************************/
00023 
00024 #ifndef VLC_VOUT_DISPLAY_H
00025 #define VLC_VOUT_DISPLAY_H 1
00026 
00027 /**
00028  * \file
00029  * This file defines vout display structures and functions in vlc
00030  */
00031 
00032 #include <vlc_es.h>
00033 #include <vlc_picture.h>
00034 #include <vlc_picture_pool.h>
00035 #include <vlc_subpicture.h>
00036 #include <vlc_keys.h>
00037 #include <vlc_mouse.h>
00038 #include <vlc_vout_window.h>
00039 
00040 /* XXX
00041  * Do NOT use video_format_t::i_aspect but i_sar_num/den everywhere. i_aspect
00042  * will be removed as soon as possible.
00043  *
00044  */
00045 typedef struct vout_display_t vout_display_t;
00046 typedef struct vout_display_sys_t vout_display_sys_t;
00047 typedef struct vout_display_owner_t vout_display_owner_t;
00048 typedef struct vout_display_owner_sys_t vout_display_owner_sys_t;
00049 
00050 /**
00051  * Possible alignments for vout_display.
00052  */
00053 typedef enum
00054 {
00055     VOUT_DISPLAY_ALIGN_CENTER,
00056     /* */
00057     VOUT_DISPLAY_ALIGN_LEFT,
00058     VOUT_DISPLAY_ALIGN_RIGHT,
00059     /* */
00060     VOUT_DISPLAY_ALIGN_TOP,
00061     VOUT_DISPLAY_ALIGN_BOTTOM,
00062 } vout_display_align_t;
00063 
00064 /**
00065  * Window management state.
00066  */
00067 enum {
00068     VOUT_WINDOW_STATE_NORMAL=0,
00069     VOUT_WINDOW_STATE_ABOVE=1,
00070     VOUT_WINDOW_STATE_BELOW=2,
00071     VOUT_WINDOW_STACK_MASK=3,
00072 };
00073 
00074 /**
00075  * Initial/Current configuration for a vout_display_t
00076  */
00077 typedef struct {
00078     bool is_fullscreen;  /* Is the display fullscreen */
00079 
00080     /* Display properties */
00081     struct {
00082         /* Window title (may be NULL) */
00083         const char *title;
00084 
00085         /* Display size */
00086         unsigned  width;
00087         unsigned  height;
00088 
00089         /* Display SAR */
00090         struct {
00091             unsigned num;
00092             unsigned den;
00093         } sar;
00094     } display;
00095 
00096     /* Alignment of the picture inside the display */
00097     struct {
00098         int horizontal;
00099         int vertical;
00100     } align;
00101 
00102     /* Do we fill up the display with the video */
00103     bool is_display_filled;
00104 
00105     /* Zoom to use
00106      * It will be applied to the whole display if b_display_filled is set, otherwise
00107      * only on the video source */
00108     struct {
00109         int num;
00110         int den;
00111     } zoom;
00112 
00113 } vout_display_cfg_t;
00114 
00115 /**
00116  * Information from a vout_display_t to configure
00117  * the core behaviour.
00118  *
00119  * By default they are all false.
00120  *
00121  */
00122 typedef struct {
00123     bool is_slow;            /* The picture memory has slow read/write */
00124     bool has_double_click;    /* Is double-click generated */
00125     bool has_hide_mouse;      /* Is mouse automatically hidden */
00126     bool has_pictures_invalid;/* Will VOUT_DISPLAY_EVENT_PICTURES_INVALID be used */
00127     bool has_event_thread;    /* Will events (key at least) be emitted using an independent thread */
00128 } vout_display_info_t;
00129 
00130 /**
00131  * Control query for vout_display_t
00132  */
00133 enum {
00134     /* Hide the mouse. It will be sent when
00135      * vout_display_t::info.b_hide_mouse is false */
00136     VOUT_DISPLAY_HIDE_MOUSE,
00137 
00138     /* Ask to reset the internal buffers after a VOUT_DISPLAY_EVENT_PICTURES_INVALID
00139      * request.
00140      */
00141     VOUT_DISPLAY_RESET_PICTURES,
00142 
00143     /* Ask the module to acknowledge/refuse the fullscreen state change after
00144      * being requested (externally or by VOUT_DISPLAY_EVENT_FULLSCREEN */
00145     VOUT_DISPLAY_CHANGE_FULLSCREEN,     /* const vout_display_cfg_t *p_cfg */
00146 
00147     /* Ask the module to acknowledge/refuse the window management state change
00148      * after being requested externally or by VOUT_DISPLAY_WINDOW_STATE */
00149     VOUT_DISPLAY_CHANGE_WINDOW_STATE,         /* unsigned state */
00150 
00151     /* Ask the module to acknowledge/refuse the display size change requested
00152      * (externally or by VOUT_DISPLAY_EVENT_DISPLAY_SIZE) */
00153     VOUT_DISPLAY_CHANGE_DISPLAY_SIZE,   /* const vout_display_cfg_t *p_cfg, int is_forced */
00154 
00155     /* Ask the module to acknowledge/refuse fill display state change after
00156      * being requested externally */
00157     VOUT_DISPLAY_CHANGE_DISPLAY_FILLED, /* const vout_display_cfg_t *p_cfg */
00158 
00159     /* Ask the module to acknowledge/refuse zoom change after being requested
00160      * externally */
00161     VOUT_DISPLAY_CHANGE_ZOOM, /* const vout_display_cfg_t *p_cfg */
00162 
00163     /* Ask the module to acknowledge/refuse source aspect ratio after being
00164      * requested externally */
00165     VOUT_DISPLAY_CHANGE_SOURCE_ASPECT, /* const video_format_t *p_source */
00166 
00167     /* Ask the module to acknowledge/refuse source crop change after being
00168      * requested externally.
00169      * The cropping requested is stored by video_format_t::i_x/y_offset and
00170      * video_format_t::i_visible_width/height */
00171     VOUT_DISPLAY_CHANGE_SOURCE_CROP,   /* const video_format_t *p_source */
00172 
00173     /* Ask an opengl interface if available. */
00174     VOUT_DISPLAY_GET_OPENGL,           /* vout_opengl_t ** */
00175 };
00176 
00177 /**
00178  * Event from vout_display_t
00179  *
00180  * Events modifiying the state may be sent multiple times.
00181  * Only the transition will be retained and acted upon.
00182  */
00183 enum {
00184     /* TODO:
00185      * ZOOM ? DISPLAY_FILLED ? ON_TOP ?
00186      */
00187     /* */
00188     VOUT_DISPLAY_EVENT_PICTURES_INVALID,    /* The buffer are now invalid and need to be changed */
00189 
00190     VOUT_DISPLAY_EVENT_FULLSCREEN,
00191     VOUT_DISPLAY_EVENT_WINDOW_STATE,
00192 
00193     VOUT_DISPLAY_EVENT_DISPLAY_SIZE,        /* The display size need to change : int i_width, int i_height, bool is_fullscreen */
00194 
00195     /* */
00196     VOUT_DISPLAY_EVENT_CLOSE,
00197     VOUT_DISPLAY_EVENT_KEY,
00198 
00199     /* Full mouse state.
00200      * You can use it OR use the other mouse events. The core will do
00201      * the conversion.
00202      */
00203     VOUT_DISPLAY_EVENT_MOUSE_STATE,
00204 
00205     /* Mouse event */
00206     VOUT_DISPLAY_EVENT_MOUSE_MOVED,
00207     VOUT_DISPLAY_EVENT_MOUSE_PRESSED,
00208     VOUT_DISPLAY_EVENT_MOUSE_RELEASED,
00209     VOUT_DISPLAY_EVENT_MOUSE_DOUBLE_CLICK,
00210 };
00211 
00212 /**
00213  * Vout owner structures
00214  */
00215 struct vout_display_owner_t {
00216     /* Private place holder for the vout_display_t creator
00217      */
00218     vout_display_owner_sys_t *sys;
00219 
00220     /* Event coming from the module
00221      *
00222      * This function is set prior to the module instantiation and must not
00223      * be overwritten nor used directly (use the vout_display_SendEvent*
00224      * wrapper.
00225      *
00226      * You can send it at any time i.e. from any vout_display_t functions or
00227      * from another thread.
00228      * Be careful, it does not ensure correct serialization if it is used
00229      * from multiple threads.
00230      */
00231     void            (*event)(vout_display_t *, int, va_list);
00232 
00233     /* Window management
00234      *
00235      * These functions are set prior to the module instantiation and must not
00236      * be overwritten nor used directly (use the vout_display_*Window
00237      * wrapper */
00238     vout_window_t *(*window_new)(vout_display_t *, const vout_window_cfg_t *);
00239     void           (*window_del)(vout_display_t *, vout_window_t *);
00240 };
00241 
00242 struct vout_display_t {
00243     VLC_COMMON_MEMBERS
00244 
00245     /* Module */
00246     module_t *module;
00247 
00248     /* Initial and current configuration.
00249      * You cannot modify it directly, you must use the appropriate events.
00250      *
00251      * It reflects the current values, i.e. after the event has been accepted
00252      * and applied/configured if needed.
00253      */
00254     const vout_display_cfg_t *cfg;
00255 
00256     /* video source format.
00257      *
00258      * Cropping is not requested while in the open function.
00259      * You cannot change it.
00260      */
00261     video_format_t source;
00262 
00263     /* picture_t format.
00264      *
00265      * You can only change it inside the module open function to
00266      * match what you want, and when a VOUT_DISPLAY_RESET_PICTURES control
00267      * request is made and succeeds.
00268      *
00269      * By default, it is equal to ::source except for the aspect ratio
00270      * which is undefined(0) and is ignored.
00271      */
00272     video_format_t fmt;
00273 
00274     /* Information
00275      *
00276      * You can only set them in the open function.
00277      */
00278     vout_display_info_t info;
00279 
00280     /* Return a pointer over the current picture_pool_t* (mandatory).
00281      *
00282      * For performance reasons, it is best to provide at least count
00283      * pictures but it is not mandatory.
00284      * You can return NULL when you cannot/do not want to allocate
00285      * pictures.
00286      * The vout display module keeps the ownership of the pool and can
00287      * destroy it only when closing or on invalid pictures control.
00288      */
00289     picture_pool_t *(*pool)(vout_display_t *, unsigned count);
00290 
00291     /* Prepare a picture for display (optional).
00292      *
00293      * It is called before the next pf_display call to provide as much
00294      * time as possible to prepare the given picture for display.
00295      * You are guaranted that pf_display will always be called and using
00296      * the exact same picture_t.
00297      * You cannot change the pixel content of the picture_t.
00298      */
00299     void       (*prepare)(vout_display_t *, picture_t *);
00300 
00301     /* Display a picture (mandatory).
00302      *
00303      * The picture must be displayed as soon as possible.
00304      * You cannot change the pixel content of the picture_t.
00305      *
00306      * This function gives away the ownership of the picture, so you must
00307      * release it as soon as possible.
00308      */
00309     void       (*display)(vout_display_t *, picture_t *);
00310 
00311     /* Control on the module (mandatory) */
00312     int        (*control)(vout_display_t *, int, va_list);
00313 
00314     /* Manage pending event (optional) */
00315     void       (*manage)(vout_display_t *);
00316 
00317     /* Private place holder for the vout_display_t module (optional)
00318      *
00319      * A module is free to use it as it wishes.
00320      */
00321     vout_display_sys_t *sys;
00322 
00323     /* Reserved for the vout_display_t owner.
00324      *
00325      * It must not be overwritten nor used directly by a module.
00326      */
00327     vout_display_owner_t owner;
00328 };
00329 
00330 static inline void vout_display_SendEvent(vout_display_t *vd, int query, ...)
00331 {
00332     va_list args;
00333     va_start(args, query);
00334     vd->owner.event(vd, query, args);
00335     va_end(args);
00336 }
00337 
00338 static inline void vout_display_SendEventDisplaySize(vout_display_t *vd, int width, int height, bool is_fullscreen)
00339 {
00340     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_DISPLAY_SIZE, width, height, is_fullscreen);
00341 }
00342 static inline void vout_display_SendEventPicturesInvalid(vout_display_t *vd)
00343 {
00344     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_PICTURES_INVALID);
00345 }
00346 static inline void vout_display_SendEventClose(vout_display_t *vd)
00347 {
00348     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_CLOSE);
00349 }
00350 static inline void vout_display_SendEventKey(vout_display_t *vd, int key)
00351 {
00352     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_KEY, key);
00353 }
00354 static inline void vout_display_SendEventFullscreen(vout_display_t *vd, bool is_fullscreen)
00355 {
00356     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_FULLSCREEN, is_fullscreen);
00357 }
00358 static inline void vout_display_SendWindowState(vout_display_t *vd, unsigned state)
00359 {
00360     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_WINDOW_STATE, state);
00361 }
00362 /* The mouse position (State and Moved event) must be expressed against vout_display_t::source unit */
00363 static inline void vout_display_SendEventMouseState(vout_display_t *vd, int x, int y, int button_mask)
00364 {
00365     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_STATE, x, y, button_mask);
00366 }
00367 static inline void vout_display_SendEventMouseMoved(vout_display_t *vd, int x, int y)
00368 {
00369     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_MOVED, x, y);
00370 }
00371 static inline void vout_display_SendEventMousePressed(vout_display_t *vd, int button)
00372 {
00373     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_PRESSED, button);
00374 }
00375 static inline void vout_display_SendEventMouseReleased(vout_display_t *vd, int button)
00376 {
00377     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_RELEASED, button);
00378 }
00379 static inline void vout_display_SendEventMouseDoubleClick(vout_display_t *vd)
00380 {
00381     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_DOUBLE_CLICK);
00382 }
00383 
00384 /**
00385  * Asks for a new window with the given configuration as hint.
00386  *
00387  * b_standalone/i_x/i_y may be overwritten by the core
00388  */
00389 static inline vout_window_t *vout_display_NewWindow(vout_display_t *vd, const vout_window_cfg_t *cfg)
00390 {
00391     return vd->owner.window_new(vd, cfg);
00392 }
00393 /**
00394  * Deletes a window created by vout_display_NewWindow if window is non NULL
00395  * or any unused windows otherwise.
00396  */
00397 static inline void vout_display_DeleteWindow(vout_display_t *vd,
00398                                              vout_window_t *window)
00399 {
00400     vd->owner.window_del(vd, window);
00401 }
00402 
00403 /**
00404  * Computes the default display size given the source and
00405  * the display configuration.
00406  *
00407  * This asssumes that the picture is already cropped.
00408  */
00409 VLC_EXPORT( void, vout_display_GetDefaultDisplaySize, (unsigned *width, unsigned *height, const video_format_t *source, const vout_display_cfg_t *) );
00410 
00411 
00412 /**
00413  * Structure used to store the result of a vout_display_PlacePicture.
00414  */
00415 typedef struct {
00416     int x;
00417     int y;
00418     unsigned width;
00419     unsigned height;
00420 } vout_display_place_t;
00421 
00422 /**
00423  * Computes how to place a picture inside the display to respect
00424  * the given parameters.
00425  * This assumes that cropping is done by an external mean.
00426  *
00427  * \param p_place Place inside the window (window pixel unit)
00428  * \param p_source Video source format
00429  * \param p_cfg Display configuration
00430  * \param b_clip If true, prevent the video to go outside the display (break zoom).
00431  */
00432 VLC_EXPORT( void, vout_display_PlacePicture, (vout_display_place_t *place, const video_format_t *source, const vout_display_cfg_t *cfg, bool do_clipping) );
00433 
00434 #endif /* VLC_VOUT_DISPLAY_H */
00435 

Generated on Mon Nov 22 07:55:20 2010 for VLC by  doxygen 1.5.6