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

Generated on Sun Nov 22 08:05:13 2009 for VLC by  doxygen 1.5.6