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

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * filter_common.h: Common filter functions
  3.  *****************************************************************************
  4.  * Copyright (C) 2001, 2002, 2003 the VideoLAN team
  5.  * $Id: 2f3e40e9870d66f911eeb1333f7c1108296c8159 $
  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.  * Initialize i_max direct buffers for a vout_thread_t.
  25.  */
  26. static inline void vout_filter_AllocateDirectBuffers( vout_thread_t *p_vout, int i_max )
  27. {
  28.     I_OUTPUTPICTURES = 0;
  29.     /* Try to initialize i_max direct buffers */
  30.     while( I_OUTPUTPICTURES < i_max )
  31.     {
  32.         picture_t *p_pic = NULL;
  33.         /* Find an empty picture slot */
  34.         for( int i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
  35.         {
  36.             if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
  37.             {
  38.                 p_pic = p_vout->p_picture + i_index;
  39.                 break;
  40.             }
  41.         }
  42.         if( p_pic == NULL )
  43.             break;
  44.         /* Allocate the picture */
  45.         vout_AllocatePicture( VLC_OBJECT(p_vout), p_pic, p_vout->output.i_chroma,
  46.                               p_vout->output.i_width,
  47.                               p_vout->output.i_height,
  48.                               p_vout->output.i_aspect );
  49.         if( !p_pic->i_planes )
  50.             break;
  51.         p_pic->i_status = DESTROYED_PICTURE;
  52.         p_pic->i_type   = DIRECT_PICTURE;
  53.         PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
  54.         I_OUTPUTPICTURES++;
  55.     }
  56. }
  57. static inline void vout_filter_ReleaseDirectBuffers( vout_thread_t *p_vout )
  58. {
  59.     for( int i_index = I_OUTPUTPICTURES-1; i_index >= 0; i_index-- )
  60.         free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
  61. }
  62. /**
  63.  * Internal helper to forward an event from p_this to p_data
  64.  */
  65. static inline int ForwardEvent( vlc_object_t *p_this, char const *psz_var,
  66.                                 vlc_value_t oldval, vlc_value_t newval, void *p_data )
  67. {
  68.     VLC_UNUSED(p_this); VLC_UNUSED(oldval);
  69.     vlc_object_t *p_dst = (vlc_object_t*)p_data;
  70.     return var_Set( p_dst, psz_var, newval );
  71. }
  72. /**
  73.  * Internal helper to forward fullscreen event from p_this to p_data.
  74.  */
  75. static inline int ForwardFullscreen( vlc_object_t *p_this, char const *psz_var,
  76.                                      vlc_value_t oldval, vlc_value_t newval, void *p_data )
  77. {
  78.     VLC_UNUSED(p_this); VLC_UNUSED(oldval);
  79.     vlc_object_t *p_dst = (vlc_object_t*)p_data;
  80.     if( !var_GetBool( p_dst, "fullscreen" ) != !newval.b_bool )
  81.         return var_SetBool( p_dst, psz_var, newval.b_bool );
  82.     return VLC_SUCCESS;
  83. }
  84. /**
  85.  * Install/remove all callbacks needed for proper event handling inside
  86.  * a vout-filter.
  87.  */
  88. static inline void vout_filter_SetupChild( vout_thread_t *p_parent, vout_thread_t *p_child,
  89.                                            vlc_callback_t pf_mouse_event,
  90.                                            vlc_callback_t pf_fullscreen_up,
  91.                                            vlc_callback_t pf_fullscreen_down,
  92.                                            bool b_init )
  93. {
  94.     int (*pf_execute)( vlc_object_t *, const char *, vlc_callback_t, void * );
  95.     if( b_init )
  96.         pf_execute = __var_AddCallback;
  97.     else
  98.         pf_execute = __var_DelCallback;
  99.     /* */
  100.     if( !pf_mouse_event )
  101.         pf_mouse_event = ForwardEvent;
  102.     pf_execute( VLC_OBJECT(p_child), "mouse-x",           pf_mouse_event, p_parent );
  103.     pf_execute( VLC_OBJECT(p_child), "mouse-y",           pf_mouse_event, p_parent );
  104.     pf_execute( VLC_OBJECT(p_child), "mouse-moved",       pf_mouse_event, p_parent );
  105.     pf_execute( VLC_OBJECT(p_child), "mouse-clicked",     pf_mouse_event, p_parent );
  106.     pf_execute( VLC_OBJECT(p_child), "mouse-button-down", pf_mouse_event, p_parent );
  107.     /* */
  108.     pf_execute( VLC_OBJECT(p_parent), "autoscale",    ForwardEvent, p_child );
  109.     pf_execute( VLC_OBJECT(p_parent), "scale",        ForwardEvent, p_child );
  110.     pf_execute( VLC_OBJECT(p_parent), "aspect-ratio", ForwardEvent, p_child );
  111.     pf_execute( VLC_OBJECT(p_parent), "crop",         ForwardEvent, p_child );
  112.     /* */
  113.     if( !pf_fullscreen_up )
  114.         pf_fullscreen_up = ForwardFullscreen;
  115.     if( !pf_fullscreen_down )
  116.         pf_fullscreen_down = ForwardFullscreen;
  117.     pf_execute( VLC_OBJECT(p_child),  "fullscreen", pf_fullscreen_up,   p_parent );
  118.     pf_execute( VLC_OBJECT(p_parent), "fullscreen", pf_fullscreen_down, p_child );
  119. }
  120. #define vout_filter_AddChild( a, b, c ) vout_filter_SetupChild( a, b, c, NULL, NULL, true )
  121. #define vout_filter_DelChild( a, b, c ) vout_filter_SetupChild( a, b, c, NULL, NULL, false )