home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / vlc-1.1.2-win32.exe / sdk / include / vlc / plugins / vlc_vout_display.h < prev    next >
Encoding:
C/C++ Source or Header  |  2010-07-30  |  13.6 KB  |  431 lines

  1. /*****************************************************************************
  2.  * vlc_vout_display.h: vout_display_t definitions
  3.  *****************************************************************************
  4.  * Copyright (C) 2009 Laurent Aimar
  5.  * $Id: 6f5b35f2eb94223fd3685df862e1fc49ee4ee088 $
  6.  *
  7.  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 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 General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, 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.  * Informations from a vout_display_t to configure
  117.  * the core behaviour.
  118.  *
  119.  * By default they are all false.
  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. } vout_display_info_t;
  128.  
  129. /**
  130.  * Control query for vout_display_t
  131.  */
  132. enum {
  133.     /* Hide the mouse. It will be sent when
  134.      * vout_display_t::info.b_hide_mouse is false */
  135.     VOUT_DISPLAY_HIDE_MOUSE,
  136.  
  137.     /* Ask to reset the internal buffers after a VOUT_DISPLAY_EVENT_PICTURES_INVALID
  138.      * request.
  139.      */
  140.     VOUT_DISPLAY_RESET_PICTURES,
  141.  
  142.     /* Ask the module to acknowledge/refuse the fullscreen state change after
  143.      * being requested (externally or by VOUT_DISPLAY_EVENT_FULLSCREEN */
  144.     VOUT_DISPLAY_CHANGE_FULLSCREEN,     /* const vout_display_cfg_t *p_cfg */
  145.  
  146.     /* Ask the module to acknowledge/refuse the window management state change
  147.      * after being requested externally or by VOUT_DISPLAY_WINDOW_STATE */
  148.     VOUT_DISPLAY_CHANGE_WINDOW_STATE,         /* unsigned state */
  149.  
  150.     /* Ask the module to acknowledge/refuse the display size change requested
  151.      * (externally or by VOUT_DISPLAY_EVENT_DISPLAY_SIZE) */
  152.     VOUT_DISPLAY_CHANGE_DISPLAY_SIZE,   /* const vout_display_cfg_t *p_cfg, int is_forced */
  153.  
  154.     /* Ask the module to acknowledge/refuse fill display state change after
  155.      * being requested externally */
  156.     VOUT_DISPLAY_CHANGE_DISPLAY_FILLED, /* const vout_display_cfg_t *p_cfg */
  157.  
  158.     /* Ask the module to acknowledge/refuse zoom change after being requested
  159.      * externally */
  160.     VOUT_DISPLAY_CHANGE_ZOOM, /* const vout_display_cfg_t *p_cfg */
  161.  
  162.     /* Ask the module to acknowledge/refuse source aspect ratio after being
  163.      * requested externally */
  164.     VOUT_DISPLAY_CHANGE_SOURCE_ASPECT, /* const video_format_t *p_source */
  165.  
  166.     /* Ask the module to acknowledge/refuse source crop change after being
  167.      * requested externally.
  168.      * The cropping requested is stored by video_format_t::i_x/y_offset and
  169.      * video_format_t::i_visible_width/height */
  170.     VOUT_DISPLAY_CHANGE_SOURCE_CROP,   /* const video_format_t *p_source */
  171.  
  172.     /* Ask an opengl interface if available. */
  173.     VOUT_DISPLAY_GET_OPENGL,           /* vout_opengl_t ** */
  174. };
  175.  
  176. /**
  177.  * Event from vout_display_t
  178.  *
  179.  * Events modifiying the state may be sent multiple times.
  180.  * Only the transition will be retained and acted upon.
  181.  */
  182. enum {
  183.     /* TODO:
  184.      * ZOOM ? DISPLAY_FILLED ? ON_TOP ?
  185.      */
  186.     /* */
  187.     VOUT_DISPLAY_EVENT_PICTURES_INVALID,    /* The buffer are now invalid and need to be changed */
  188.  
  189.     VOUT_DISPLAY_EVENT_FULLSCREEN,
  190.     VOUT_DISPLAY_EVENT_WINDOW_STATE,
  191.  
  192.     VOUT_DISPLAY_EVENT_DISPLAY_SIZE,        /* The display size need to change : int i_width, int i_height, bool is_fullscreen */
  193.  
  194.     /* */
  195.     VOUT_DISPLAY_EVENT_CLOSE,
  196.     VOUT_DISPLAY_EVENT_KEY,
  197.  
  198.     /* Full mouse state.
  199.      * You can use it OR use the other mouse events. The core will do
  200.      * the conversion.
  201.      */
  202.     VOUT_DISPLAY_EVENT_MOUSE_STATE,
  203.  
  204.     /* Mouse event */
  205.     VOUT_DISPLAY_EVENT_MOUSE_MOVED,
  206.     VOUT_DISPLAY_EVENT_MOUSE_PRESSED,
  207.     VOUT_DISPLAY_EVENT_MOUSE_RELEASED,
  208.     VOUT_DISPLAY_EVENT_MOUSE_DOUBLE_CLICK,
  209. };
  210.  
  211. /**
  212.  * Vout owner structures
  213.  */
  214. struct vout_display_owner_t {
  215.     /* Private place holder for the vout_display_t creator
  216.      */
  217.     vout_display_owner_sys_t *sys;
  218.  
  219.     /* Event coming from the module
  220.      *
  221.      * This function is set prior to the module instantiation and must not
  222.      * be overwritten nor used directly (use the vout_display_SendEvent*
  223.      * wrapper.
  224.      *
  225.      * You can send it at any time i.e. from any vout_display_t functions or
  226.      * from another thread.
  227.      * Be careful, it does not ensure correct serialization if it is used
  228.      * from multiple threads.
  229.      */
  230.     void            (*event)(vout_display_t *, int, va_list);
  231.  
  232.     /* Window management
  233.      *
  234.      * These functions are set prior to the module instantiation and must not
  235.      * be overwritten nor used directly (use the vout_display_*Window
  236.      * wrapper */
  237.     vout_window_t *(*window_new)(vout_display_t *, const vout_window_cfg_t *);
  238.     void           (*window_del)(vout_display_t *, vout_window_t *);
  239. };
  240.  
  241. struct vout_display_t {
  242.     VLC_COMMON_MEMBERS
  243.  
  244.     /* Module */
  245.     module_t *module;
  246.  
  247.     /* Initial and current configuration.
  248.      * You cannot modify it directly, you must use the appropriate events.
  249.      *
  250.      * It reflects the current values, i.e. after the event has been accepted
  251.      * and applied/configured if needed.
  252.      */
  253.     const vout_display_cfg_t *cfg;
  254.  
  255.     /* video source format.
  256.      *
  257.      * Cropping is not requested while in the open function.
  258.      * You cannot change it.
  259.      */
  260.     video_format_t source;
  261.  
  262.     /* picture_t format.
  263.      *
  264.      * You can only change it inside the module open function to
  265.      * match what you want, and when a VOUT_DISPLAY_RESET_PICTURES control
  266.      * request is made and succeeds.
  267.      *
  268.      * By default, it is equal to ::source except for the aspect ratio
  269.      * which is undefined(0) and is ignored.
  270.      */
  271.     video_format_t fmt;
  272.  
  273.     /* Informations
  274.      *
  275.      * You can only set them in the open function.
  276.      */
  277.     vout_display_info_t info;
  278.  
  279.     /* Return a pointer over the current picture_pool_t* (mandatory).
  280.      *
  281.      * For performance reasons, it is best to provide at least count
  282.      * pictures but it is not mandatory.
  283.      * You can return NULL when you cannot/do not want to allocate
  284.      * pictures.
  285.      * The vout display module keeps the ownership of the pool and can
  286.      * destroy it only when closing or on invalid pictures control.
  287.      */
  288.     picture_pool_t *(*pool)(vout_display_t *, unsigned count);
  289.  
  290.     /* Prepare a picture for display (optional).
  291.      *
  292.      * It is called before the next pf_display call to provide as much
  293.      * time as possible to prepare the given picture for display.
  294.      * You are guaranted that pf_display will always be called and using
  295.      * the exact same picture_t.
  296.      * You cannot change the pixel content of the picture_t.
  297.      */
  298.     void       (*prepare)(vout_display_t *, picture_t *);
  299.  
  300.     /* Display a picture (mandatory).
  301.      *
  302.      * The picture must be displayed as soon as possible.
  303.      * You cannot change the pixel content of the picture_t.
  304.      *
  305.      * This function gives away the ownership of the picture, so you must
  306.      * release it as soon as possible.
  307.      */
  308.     void       (*display)(vout_display_t *, picture_t *);
  309.  
  310.     /* Control on the module (mandatory) */
  311.     int        (*control)(vout_display_t *, int, va_list);
  312.  
  313.     /* Manage pending event (optional) */
  314.     void       (*manage)(vout_display_t *);
  315.  
  316.     /* Private place holder for the vout_display_t module (optional)
  317.      *
  318.      * A module is free to use it as it wishes.
  319.      */
  320.     vout_display_sys_t *sys;
  321.  
  322.     /* Reserved for the vout_display_t owner.
  323.      *
  324.      * It must not be overwritten nor used directly by a module.
  325.      */
  326.     vout_display_owner_t owner;
  327. };
  328.  
  329. static inline void vout_display_SendEvent(vout_display_t *vd, int query, ...)
  330. {
  331.     va_list args;
  332.     va_start(args, query);
  333.     vd->owner.event(vd, query, args);
  334.     va_end(args);
  335. }
  336.  
  337. static inline void vout_display_SendEventDisplaySize(vout_display_t *vd, int width, int height, bool is_fullscreen)
  338. {
  339.     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_DISPLAY_SIZE, width, height, is_fullscreen);
  340. }
  341. static inline void vout_display_SendEventPicturesInvalid(vout_display_t *vd)
  342. {
  343.     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_PICTURES_INVALID);
  344. }
  345. static inline void vout_display_SendEventClose(vout_display_t *vd)
  346. {
  347.     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_CLOSE);
  348. }
  349. static inline void vout_display_SendEventKey(vout_display_t *vd, int key)
  350. {
  351.     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_KEY, key);
  352. }
  353. static inline void vout_display_SendEventFullscreen(vout_display_t *vd, bool is_fullscreen)
  354. {
  355.     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_FULLSCREEN, is_fullscreen);
  356. }
  357. static inline void vout_display_SendWindowState(vout_display_t *vd, unsigned state)
  358. {
  359.     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_WINDOW_STATE, state);
  360. }
  361. /* The mouse position (State and Moved event) must be expressed against vout_display_t::source unit */
  362. static inline void vout_display_SendEventMouseState(vout_display_t *vd, int x, int y, int button_mask)
  363. {
  364.     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_STATE, x, y, button_mask);
  365. }
  366. static inline void vout_display_SendEventMouseMoved(vout_display_t *vd, int x, int y)
  367. {
  368.     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_MOVED, x, y);
  369. }
  370. static inline void vout_display_SendEventMousePressed(vout_display_t *vd, int button)
  371. {
  372.     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_PRESSED, button);
  373. }
  374. static inline void vout_display_SendEventMouseReleased(vout_display_t *vd, int button)
  375. {
  376.     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_RELEASED, button);
  377. }
  378. static inline void vout_display_SendEventMouseDoubleClick(vout_display_t *vd)
  379. {
  380.     vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_DOUBLE_CLICK);
  381. }
  382.  
  383. /**
  384.  * Asks for a new window with the given configuration as hint.
  385.  *
  386.  * b_standalone/i_x/i_y may be overwritten by the core
  387.  */
  388. static inline vout_window_t *vout_display_NewWindow(vout_display_t *vd, const vout_window_cfg_t *cfg)
  389. {
  390.     return vd->owner.window_new(vd, cfg);
  391. }
  392. static inline void vout_display_DeleteWindow(vout_display_t *vd,
  393.                                              vout_window_t *window)
  394. {
  395.     vd->owner.window_del(vd, window);
  396. }
  397.  
  398. /**
  399.  * Computes the default display size given the source and
  400.  * the display configuration.
  401.  *
  402.  * This asssumes that the picture is already cropped.
  403.  */
  404. VLC_EXPORT( void, vout_display_GetDefaultDisplaySize, (unsigned *width, unsigned *height, const video_format_t *source, const vout_display_cfg_t *) );
  405.  
  406.  
  407. /**
  408.  * Structure used to store the result of a vout_display_PlacePicture.
  409.  */
  410. typedef struct {
  411.     int x;
  412.     int y;
  413.     unsigned width;
  414.     unsigned height;
  415. } vout_display_place_t;
  416.  
  417. /**
  418.  * Computes how to place a picture inside the display to respect
  419.  * the given parameters.
  420.  * This assumes that cropping is done by an external mean.
  421.  *
  422.  * \param p_place Place inside the window (window pixel unit)
  423.  * \param p_source Video source format
  424.  * \param p_cfg Display configuration
  425.  * \param b_clip If true, prevent the video to go outside the display (break zoom).
  426.  */
  427. 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) );
  428.  
  429. #endif /* VLC_VOUT_DISPLAY_H */
  430.  
  431.