wall.c
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:23k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * wall.c : Wall video plugin for vlc
  3.  *****************************************************************************
  4.  * Copyright (C) 2000, 2001, 2002, 2003 the VideoLAN team
  5.  * $Id: 397dc07966098bf479154feed939e9e65e7c9895 $
  6.  *
  7.  * Authors: Samuel Hocevar <sam@zoy.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.  * Preamble
  25.  *****************************************************************************/
  26. #ifdef HAVE_CONFIG_H
  27. # include "config.h"
  28. #endif
  29. #include <vlc_common.h>
  30. #include <vlc_plugin.h>
  31. #include <vlc_vout.h>
  32. #include <assert.h>
  33. #include "filter_common.h"
  34. /*****************************************************************************
  35.  * Local prototypes
  36.  *****************************************************************************/
  37. static int  Create    ( vlc_object_t * );
  38. static void Destroy   ( vlc_object_t * );
  39. static int  Init      ( vout_thread_t * );
  40. static void End       ( vout_thread_t * );
  41. static void Render    ( vout_thread_t *, picture_t * );
  42. static void RemoveAllVout  ( vout_thread_t *p_vout );
  43. static int  MouseEvent( vlc_object_t *, char const *,
  44.                         vlc_value_t, vlc_value_t, void * );
  45. static int  FullscreenEventUp( vlc_object_t *, char const *,
  46.                                vlc_value_t, vlc_value_t, void * );
  47. static int  FullscreenEventDown( vlc_object_t *, char const *,
  48.                                  vlc_value_t, vlc_value_t, void * );
  49. /*****************************************************************************
  50.  * Module descriptor
  51.  *****************************************************************************/
  52. #define COLS_TEXT N_("Number of columns")
  53. #define COLS_LONGTEXT N_("Number of horizontal windows in " 
  54.     "which to split the video.")
  55. #define ROWS_TEXT N_("Number of rows")
  56. #define ROWS_LONGTEXT N_("Number of vertical windows in " 
  57.     "which to split the video.")
  58. #define ACTIVE_TEXT N_("Active windows")
  59. #define ACTIVE_LONGTEXT N_("Comma-separated list of active windows, " 
  60.     "defaults to all")
  61. #define ASPECT_TEXT N_("Element aspect ratio")
  62. #define ASPECT_LONGTEXT N_("Aspect ratio of the individual displays " 
  63.    "building the wall.")
  64. #define CFG_PREFIX "wall-"
  65. vlc_module_begin ()
  66.     set_description( N_("Wall video filter") )
  67.     set_shortname( N_("Image wall" ))
  68.     set_capability( "video filter", 0 )
  69.     set_category( CAT_VIDEO )
  70.     set_subcategory( SUBCAT_VIDEO_VFILTER )
  71.     add_integer( CFG_PREFIX "cols", 3, NULL, COLS_TEXT, COLS_LONGTEXT, false )
  72.     add_integer( CFG_PREFIX "rows", 3, NULL, ROWS_TEXT, ROWS_LONGTEXT, false )
  73.     add_string( CFG_PREFIX "active", NULL, NULL, ACTIVE_TEXT, ACTIVE_LONGTEXT,
  74.                  true )
  75.     add_string( CFG_PREFIX "element-aspect", "4:3", NULL, ASPECT_TEXT, ASPECT_LONGTEXT, false )
  76.     add_shortcut( "wall" )
  77.     set_callbacks( Create, Destroy )
  78. vlc_module_end ()
  79. static const char *const ppsz_filter_options[] = {
  80.     "cols", "rows", "active", "element-aspect", NULL
  81. };
  82. /*****************************************************************************
  83.  * vout_sys_t: Wall video output method descriptor
  84.  *****************************************************************************
  85.  * This structure is part of the video output thread descriptor.
  86.  * It describes the Wall specific properties of an output thread.
  87.  *****************************************************************************/
  88. struct vout_sys_t
  89. {
  90.     int    i_col;
  91.     int    i_row;
  92.     int    i_vout;
  93.     struct vout_list_t
  94.     {
  95.         bool b_active;
  96.         int i_width;
  97.         int i_height;
  98.         int i_left;
  99.         int i_top;
  100.         vout_thread_t *p_vout;
  101.     } *pp_vout;
  102. };
  103. /*****************************************************************************
  104.  * Control: control facility for the vout (forwards to child vout)
  105.  *****************************************************************************/
  106. static int Control( vout_thread_t *p_vout, int i_query, va_list args )
  107. {
  108.     int i_row, i_col, i_vout = 0;
  109.     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
  110.     {
  111.         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
  112.         {
  113.             vout_vaControl( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
  114.                             i_query, args );
  115.             i_vout++;
  116.         }
  117.     }
  118.     return VLC_SUCCESS;
  119. }
  120. /*****************************************************************************
  121.  * Create: allocates Wall video thread output method
  122.  *****************************************************************************
  123.  * This function allocates and initializes a Wall vout method.
  124.  *****************************************************************************/
  125. static int Create( vlc_object_t *p_this )
  126. {
  127.     vout_thread_t *p_vout = (vout_thread_t *)p_this;
  128.     char *psz_method, *psz_tmp, *psz_method_tmp;
  129.     int i_vout;
  130.     /* Allocate structure */
  131.     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
  132.     if( p_vout->p_sys == NULL )
  133.         return VLC_ENOMEM;
  134.     p_vout->pf_init = Init;
  135.     p_vout->pf_end = End;
  136.     p_vout->pf_manage = NULL;
  137.     p_vout->pf_render = Render;
  138.     p_vout->pf_display = NULL;
  139.     p_vout->pf_control = Control;
  140.     config_ChainParse( p_vout, CFG_PREFIX, ppsz_filter_options,
  141.                        p_vout->p_cfg );
  142.     /* Look what method was requested */
  143.     p_vout->p_sys->i_col = var_CreateGetInteger( p_vout, CFG_PREFIX "cols" );
  144.     p_vout->p_sys->i_row = var_CreateGetInteger( p_vout, CFG_PREFIX "rows" );
  145.     p_vout->p_sys->i_col = __MAX( 1, __MIN( 15, p_vout->p_sys->i_col ) );
  146.     p_vout->p_sys->i_row = __MAX( 1, __MIN( 15, p_vout->p_sys->i_row ) );
  147.     msg_Dbg( p_vout, "opening a %i x %i wall",
  148.              p_vout->p_sys->i_col, p_vout->p_sys->i_row );
  149.     p_vout->p_sys->pp_vout = malloc( p_vout->p_sys->i_row *
  150.                                      p_vout->p_sys->i_col *
  151.                                      sizeof(struct vout_list_t) );
  152.     if( p_vout->p_sys->pp_vout == NULL )
  153.     {
  154.         free( p_vout->p_sys );
  155.         return VLC_ENOMEM;
  156.     }
  157.     psz_method_tmp =
  158.     psz_method = var_CreateGetNonEmptyString( p_vout, CFG_PREFIX "active" );
  159.     /* If no trailing vout are specified, take them all */
  160.     if( psz_method == NULL )
  161.     {
  162.         for( i_vout = p_vout->p_sys->i_row * p_vout->p_sys->i_col;
  163.              i_vout--; )
  164.         {
  165.             p_vout->p_sys->pp_vout[i_vout].b_active = 1;
  166.         }
  167.     }
  168.     /* If trailing vout are specified, activate only the requested ones */
  169.     else
  170.     {
  171.         for( i_vout = p_vout->p_sys->i_row * p_vout->p_sys->i_col;
  172.              i_vout--; )
  173.         {
  174.             p_vout->p_sys->pp_vout[i_vout].b_active = 0;
  175.         }
  176.         while( *psz_method )
  177.         {
  178.             psz_tmp = psz_method;
  179.             while( *psz_tmp && *psz_tmp != ',' )
  180.             {
  181.                 psz_tmp++;
  182.             }
  183.             if( *psz_tmp )
  184.             {
  185.                 *psz_tmp = '';
  186.                 i_vout = atoi( psz_method );
  187.                 psz_method = psz_tmp + 1;
  188.             }
  189.             else
  190.             {
  191.                 i_vout = atoi( psz_method );
  192.                 psz_method = psz_tmp;
  193.             }
  194.             if( i_vout >= 0 &&
  195.                 i_vout < p_vout->p_sys->i_row * p_vout->p_sys->i_col )
  196.             {
  197.                 p_vout->p_sys->pp_vout[i_vout].b_active = 1;
  198.             }
  199.         }
  200.     }
  201.     free( psz_method_tmp );
  202.     return VLC_SUCCESS;
  203. }
  204. /*****************************************************************************
  205.  * Init: initialize Wall video thread output method
  206.  *****************************************************************************/
  207. static int Init( vout_thread_t *p_vout )
  208. {
  209.     int i_row, i_col, i_width, i_height, i_left, i_top;
  210.     unsigned int i_target_width,i_target_height;
  211.     video_format_t fmt;
  212.     int i_aspect = 4*VOUT_ASPECT_FACTOR/3;
  213.     int i_align = 0;
  214.     unsigned int i_hstart, i_hend, i_vstart, i_vend;
  215.     unsigned int w1,h1,w2,h2;
  216.     int i_xpos, i_ypos;
  217.     int i_vstart_rounded = 0, i_hstart_rounded = 0;
  218.     char *psz_aspect;
  219.     memset( &fmt, 0, sizeof(video_format_t) );
  220.     psz_aspect = var_CreateGetNonEmptyString( p_vout,
  221.                                               CFG_PREFIX "element-aspect" );
  222.     if( psz_aspect && *psz_aspect )
  223.     {
  224.         char *psz_parser = strchr( psz_aspect, ':' );
  225.         if( psz_parser )
  226.         {
  227.             *psz_parser++ = '';
  228.             i_aspect = atoi( psz_aspect ) * VOUT_ASPECT_FACTOR
  229.                 / atoi( psz_parser );
  230.         }
  231.         else
  232.         {
  233.             msg_Warn( p_vout, "invalid aspect ratio specification" );
  234.         }
  235.     }
  236.     free( psz_aspect );
  237.     i_xpos = var_CreateGetInteger( p_vout, "video-x" );
  238.     i_ypos = var_CreateGetInteger( p_vout, "video-y" );
  239.     if( i_xpos < 0 ) i_xpos = 0;
  240.     if( i_ypos < 0 ) i_ypos = 0;
  241.     I_OUTPUTPICTURES = 0;
  242.     /* Initialize the output structure */
  243.     p_vout->output.i_chroma = p_vout->render.i_chroma;
  244.     p_vout->output.i_width  = p_vout->render.i_width;
  245.     p_vout->output.i_height = p_vout->render.i_height;
  246.     p_vout->output.i_aspect = p_vout->render.i_aspect;
  247.     var_Create( p_vout, "align", VLC_VAR_INTEGER );
  248.     fmt.i_width = fmt.i_visible_width = p_vout->render.i_width;
  249.     fmt.i_height = fmt.i_visible_height = p_vout->render.i_height;
  250.     fmt.i_x_offset = fmt.i_y_offset = 0;
  251.     fmt.i_chroma = p_vout->render.i_chroma;
  252.     fmt.i_aspect = p_vout->render.i_aspect;
  253.     fmt.i_sar_num = p_vout->render.i_aspect * fmt.i_height / fmt.i_width;
  254.     fmt.i_sar_den = VOUT_ASPECT_FACTOR;
  255.     w1 = p_vout->output.i_width / p_vout->p_sys->i_col;
  256.     w1 &= ~1;
  257.     h1 = w1 * VOUT_ASPECT_FACTOR / i_aspect&~1;
  258.     h1 &= ~1;
  259.     h2 = p_vout->output.i_height / p_vout->p_sys->i_row&~1;
  260.     h2 &= ~1;
  261.     w2 = h2 * i_aspect / VOUT_ASPECT_FACTOR&~1;
  262.     w2 &= ~1;
  263.     if ( h1 * p_vout->p_sys->i_row < p_vout->output.i_height )
  264.     {
  265.         unsigned int i_tmp;
  266.         i_target_width = w2;
  267.         i_target_height = h2;
  268.         i_vstart = 0;
  269.         i_vend = p_vout->output.i_height;
  270.         i_tmp = i_target_width * p_vout->p_sys->i_col;
  271.         while( i_tmp < p_vout->output.i_width ) i_tmp += p_vout->p_sys->i_col;
  272.         i_hstart = (( i_tmp - p_vout->output.i_width ) / 2)&~1;
  273.         i_hstart_rounded  = ( ( i_tmp - p_vout->output.i_width ) % 2 ) ||
  274.             ( ( ( i_tmp - p_vout->output.i_width ) / 2 ) & 1 );
  275.         i_hend = i_hstart + p_vout->output.i_width;
  276.     }
  277.     else
  278.     {
  279.         unsigned int i_tmp;
  280.         i_target_height = h1;
  281.         i_target_width = w1;
  282.         i_hstart = 0;
  283.         i_hend = p_vout->output.i_width;
  284.         i_tmp = i_target_height * p_vout->p_sys->i_row;
  285.         while( i_tmp < p_vout->output.i_height ) i_tmp += p_vout->p_sys->i_row;
  286.         i_vstart = ( ( i_tmp - p_vout->output.i_height ) / 2 ) & ~1;
  287.         i_vstart_rounded  = ( ( i_tmp - p_vout->output.i_height ) % 2 ) ||
  288.             ( ( ( i_tmp - p_vout->output.i_height ) / 2 ) & 1 );
  289.         i_vend = i_vstart + p_vout->output.i_height;
  290.     }
  291.     msg_Dbg( p_vout, "target resolution %dx%d", i_target_width, i_target_height );
  292.     /* Try to open the real video output */
  293.     msg_Dbg( p_vout, "spawning the real video outputs" );
  294.     p_vout->p_sys->i_vout = 0;
  295.     msg_Dbg( p_vout, "target window (%d,%d)-(%d,%d)", i_hstart,i_vstart,i_hend,i_vend );
  296.     i_top = 0;
  297.     i_height = 0;
  298.     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
  299.     {
  300.         i_left = 0;
  301.         i_top += i_height;
  302.         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
  303.         {
  304.             i_align = 0;
  305.             if( i_col*i_target_width >= i_hstart &&
  306.                 (i_col+1)*i_target_width <= i_hend )
  307.             {
  308.                 i_width = i_target_width;
  309.             }
  310.             else if( ( i_col + 1 ) * i_target_width < i_hstart ||
  311.                      ( i_col * i_target_width ) > i_hend )
  312.             {
  313.                 i_width = 0;
  314.             }
  315.             else
  316.             {
  317.                 i_width = ( i_target_width - i_hstart % i_target_width );
  318.                 if( i_col >= ( p_vout->p_sys->i_col / 2 ) )
  319.                 {
  320.                     i_align |= VOUT_ALIGN_LEFT;
  321.                     i_width -= i_hstart_rounded ? 2: 0;
  322.                 }
  323.                 else
  324.                 {
  325.                     i_align |= VOUT_ALIGN_RIGHT;
  326.                 }
  327.             }
  328.             if( i_row * i_target_height >= i_vstart &&
  329.                 ( i_row + 1 ) * i_target_height <= i_vend )
  330.             {
  331.                 i_height = i_target_height;
  332.             }
  333.             else if( ( i_row + 1 ) * i_target_height < i_vstart ||
  334.                      ( i_row * i_target_height ) > i_vend )
  335.             {
  336.                 i_height = 0;
  337.             }
  338.             else
  339.             {
  340.                 i_height = ( i_target_height -
  341.                              i_vstart%i_target_height );
  342.                 if(  i_row >= ( p_vout->p_sys->i_row / 2 ) )
  343.                 {
  344.                     i_align |= VOUT_ALIGN_TOP;
  345.                     i_height -= i_vstart_rounded ? 2: 0;
  346.                 }
  347.                 else
  348.                 {
  349.                     i_align |= VOUT_ALIGN_BOTTOM;
  350.                 }
  351.             }
  352.             if( i_height == 0 || i_width == 0 )
  353.             {
  354.                 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].b_active = false;
  355.             }
  356.             p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_width = i_width;
  357.             p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_height = i_height;
  358.             p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_left = i_left;
  359.             p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_top = i_top;
  360.             i_left += i_width;
  361.             if( !p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].b_active )
  362.             {
  363.                 p_vout->p_sys->i_vout++;
  364.                 continue;
  365.             }
  366.             var_SetInteger( p_vout, "align", i_align );
  367.             var_SetInteger( p_vout, "video-x", i_left + i_xpos - i_width);
  368.             var_SetInteger( p_vout, "video-y", i_top + i_ypos );
  369.             fmt.i_width = fmt.i_visible_width = i_width;
  370.             fmt.i_height = fmt.i_visible_height = i_height;
  371.             fmt.i_aspect = i_aspect * i_target_height / i_height *
  372.                 i_width / i_target_width;
  373.             p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout =
  374.                 vout_Create( p_vout, &fmt );
  375.             if( !p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout )
  376.             {
  377.                 msg_Err( p_vout, "failed to get %ix%i vout threads",
  378.                                  p_vout->p_sys->i_col, p_vout->p_sys->i_row );
  379.                 RemoveAllVout( p_vout );
  380.                 return VLC_EGENERIC;
  381.             }
  382.             vout_filter_SetupChild( p_vout, p_vout->p_sys->pp_vout[p_vout->p_sys->i_vout].p_vout,
  383.                                     MouseEvent, FullscreenEventUp, FullscreenEventDown, true );
  384.             p_vout->p_sys->i_vout++;
  385.         }
  386.     }
  387.     vout_filter_AllocateDirectBuffers( p_vout, VOUT_MAX_PICTURES );
  388.     return VLC_SUCCESS;
  389. }
  390. /*****************************************************************************
  391.  * End: terminate Wall video thread output method
  392.  *****************************************************************************/
  393. static void End( vout_thread_t *p_vout )
  394. {
  395.     RemoveAllVout( p_vout );
  396.     vout_filter_ReleaseDirectBuffers( p_vout );
  397. }
  398. /*****************************************************************************
  399.  * Destroy: destroy Wall video thread output method
  400.  *****************************************************************************
  401.  * Terminate an output method created by WallCreateOutputMethod
  402.  *****************************************************************************/
  403. static void Destroy( vlc_object_t *p_this )
  404. {
  405.     vout_thread_t *p_vout = (vout_thread_t *)p_this;
  406.     free( p_vout->p_sys->pp_vout );
  407.     free( p_vout->p_sys );
  408. }
  409. /*****************************************************************************
  410.  * Render: displays previously rendered output
  411.  *****************************************************************************
  412.  * This function send the currently rendered image to Wall image, waits
  413.  * until it is displayed and switch the two rendering buffers, preparing next
  414.  * frame.
  415.  *****************************************************************************/
  416. static void Render( vout_thread_t *p_vout, picture_t *p_pic )
  417. {
  418.     picture_t *p_outpic = NULL;
  419.     int i_col, i_row, i_vout, i_plane;
  420.     int pi_left_skip[VOUT_MAX_PLANES], pi_top_skip[VOUT_MAX_PLANES];
  421.     i_vout = 0;
  422.     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
  423.     {
  424.         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
  425.         {
  426.             for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
  427.             {
  428.                 pi_left_skip[i_plane] = p_vout->p_sys->pp_vout[ i_vout ].i_left * p_pic->p[ i_plane ].i_pitch / p_vout->output.i_width;
  429.                 pi_top_skip[i_plane] = (p_vout->p_sys->pp_vout[ i_vout ].i_top * p_pic->p[ i_plane ].i_lines / p_vout->output.i_height)*p_pic->p[i_plane].i_pitch;
  430.             }
  431.             if( !p_vout->p_sys->pp_vout[ i_vout ].b_active )
  432.             {
  433.                 i_vout++;
  434.                 continue;
  435.             }
  436.             while( ( p_outpic =
  437.                 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
  438.                                     0, 0, 0 )
  439.                    ) == NULL )
  440.             {
  441.                 if( !vlc_object_alive (p_vout) || p_vout->b_error )
  442.                 {
  443.                     vout_DestroyPicture(
  444.                         p_vout->p_sys->pp_vout[ i_vout ].p_vout, p_outpic );
  445.                     return;
  446.                 }
  447.                 msleep( VOUT_OUTMEM_SLEEP );
  448.             }
  449.             p_outpic->date = p_pic->date;
  450.             vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
  451.                               p_outpic );
  452.             for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
  453.             {
  454.                 uint8_t *p_in, *p_in_end, *p_out;
  455.                 int i_in_pitch = p_pic->p[i_plane].i_pitch;
  456.                 int i_out_pitch = p_outpic->p[i_plane].i_pitch;
  457.                 int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;
  458.                 p_in = p_pic->p[i_plane].p_pixels
  459.                         + pi_top_skip[i_plane] + pi_left_skip[i_plane];
  460.                 p_in_end = p_in + p_outpic->p[i_plane].i_visible_lines
  461.                                    * p_pic->p[i_plane].i_pitch;
  462.                 p_out = p_outpic->p[i_plane].p_pixels;
  463.                 while( p_in < p_in_end )
  464.                 {
  465.                     vlc_memcpy( p_out, p_in, i_copy_pitch );
  466.                     p_in += i_in_pitch;
  467.                     p_out += i_out_pitch;
  468.                 }
  469. //                pi_left_skip[i_plane] += i_copy_pitch;
  470.             }
  471.             vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
  472.                                 p_outpic );
  473.             vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
  474.                                  p_outpic );
  475.             i_vout++;
  476.         }
  477. /*         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ ) */
  478. /*         { */
  479. /*             pi_top_skip[i_plane] += p_vout->p_sys->pp_vout[ i_vout ].i_height */
  480. /*                                      * p_pic->p[i_plane].i_visible_lines */
  481. /*                                      / p_vout->output.i_height */
  482. /*                                      * p_pic->p[i_plane].i_pitch; */
  483. /*         } */
  484.     }
  485. }
  486. /*****************************************************************************
  487.  * RemoveAllVout: destroy all the child video output threads
  488.  *****************************************************************************/
  489. static void RemoveAllVout( vout_thread_t *p_vout )
  490. {
  491.     vout_sys_t *p_sys = p_vout->p_sys;
  492.     while( p_sys->i_vout )
  493.     {
  494.         p_sys->i_vout--;
  495.         if( p_sys->pp_vout[p_sys->i_vout ].b_active )
  496.         {
  497.             vout_filter_SetupChild( p_vout, p_sys->pp_vout[p_sys->i_vout].p_vout,
  498.                                     MouseEvent, FullscreenEventUp, FullscreenEventDown, false );
  499.             vout_CloseAndRelease( p_sys->pp_vout[p_sys->i_vout].p_vout );
  500.         }
  501.     }
  502. }
  503. /**
  504.  * Forward mouse event with proper conversion.
  505.  */
  506. static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
  507.                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
  508. {
  509.     vout_thread_t *p_vout = p_data;
  510.     vout_sys_t *p_sys = p_vout->p_sys;
  511.     VLC_UNUSED(oldval);
  512.     int i_vout;
  513.     /* Find the video output index */
  514.     for( i_vout = 0; i_vout < p_sys->i_vout; i_vout++ )
  515.     {
  516.         if( p_sys->pp_vout[i_vout].b_active &&
  517.             p_this == VLC_OBJECT(p_sys->pp_vout[i_vout].p_vout) )
  518.             break;
  519.     }
  520.     assert( i_vout < p_vout->p_sys->i_vout );
  521.     /* Translate the mouse coordinates */
  522.     if( !strcmp( psz_var, "mouse-x" ) )
  523.         newval.i_int += p_vout->output.i_width * (i_vout % p_sys->i_col) / p_sys->i_col;
  524.     else if( !strcmp( psz_var, "mouse-y" ) )
  525.         newval.i_int += p_vout->output.i_height * (i_vout / p_sys->i_row) / p_sys->i_row;
  526.     return var_Set( p_vout, psz_var, newval );
  527. }
  528. /**
  529.  * Forward fullscreen event to/from the childrens.
  530.  */
  531. static bool IsFullscreenActive( vout_thread_t *p_vout )
  532. {
  533.     vout_sys_t *p_sys = p_vout->p_sys;
  534.     for( int i = 0; i < p_sys->i_vout; i++ )
  535.     {
  536.         if( p_sys->pp_vout[i].b_active &&
  537.             var_GetBool( p_sys->pp_vout[i].p_vout, "fullscreen" ) )
  538.             return true;
  539.     }
  540.     return false;
  541. }
  542. static int FullscreenEventUp( vlc_object_t *p_this, char const *psz_var,
  543.                               vlc_value_t oldval, vlc_value_t newval, void *p_data )
  544. {
  545.     vout_thread_t *p_vout = p_data;
  546.     VLC_UNUSED(oldval); VLC_UNUSED(p_this); VLC_UNUSED(psz_var); VLC_UNUSED(newval);
  547.     const bool b_fullscreen = IsFullscreenActive( p_vout );
  548.     if( !var_GetBool( p_vout, "fullscreen" ) != !b_fullscreen )
  549.         return var_SetBool( p_vout, "fullscreen", b_fullscreen );
  550.     return VLC_SUCCESS;
  551. }
  552. static int FullscreenEventDown( vlc_object_t *p_this, char const *psz_var,
  553.                                 vlc_value_t oldval, vlc_value_t newval, void *p_data )
  554. {
  555.     vout_thread_t *p_vout = (vout_thread_t*)p_this;
  556.     vout_sys_t *p_sys = p_vout->p_sys;
  557.     VLC_UNUSED(oldval); VLC_UNUSED(p_data); VLC_UNUSED(psz_var);
  558.     const bool b_fullscreen = IsFullscreenActive( p_vout );
  559.     if( !b_fullscreen != !newval.b_bool )
  560.     {
  561.         for( int i = 0; i < p_sys->i_vout; i++ )
  562.         {
  563.             if( !p_sys->pp_vout[i].b_active )
  564.                 continue;
  565.             vout_thread_t *p_child = p_sys->pp_vout[i].p_vout;
  566.             if( !var_GetBool( p_child, "fullscreen" ) != !newval.b_bool )
  567.             {
  568.                 var_SetBool( p_child, "fullscreen", newval.b_bool );
  569.                 if( newval.b_bool )
  570.                     return VLC_SUCCESS;
  571.             }
  572.         }
  573.     }
  574.     return VLC_SUCCESS;
  575. }