1 /*****************************************************************************
2 * filter_common.h: Common filter functions
3 *****************************************************************************
4 * Copyright (C) 2001, 2002, 2003 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
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.
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.
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 *****************************************************************************/
25 * Initialize i_max direct buffers for a vout_thread_t.
27 static inline void vout_filter_AllocateDirectBuffers( vout_thread_t *p_vout, int i_max )
31 /* Try to initialize i_max direct buffers */
32 while( I_OUTPUTPICTURES < i_max )
34 picture_t *p_pic = NULL;
36 /* Find an empty picture slot */
37 for( int i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
39 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
41 p_pic = p_vout->p_picture + i_index;
49 /* Allocate the picture */
50 vout_AllocatePicture( VLC_OBJECT(p_vout), p_pic, p_vout->output.i_chroma,
51 p_vout->output.i_width,
52 p_vout->output.i_height,
53 p_vout->output.i_aspect * p_vout->output.i_height,
54 VOUT_ASPECT_FACTOR * p_vout->output.i_width );
56 if( !p_pic->i_planes )
59 p_pic->i_status = DESTROYED_PICTURE;
60 p_pic->i_type = DIRECT_PICTURE;
62 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
68 static inline void vout_filter_ReleaseDirectBuffers( vout_thread_t *p_vout )
70 for( int i_index = I_OUTPUTPICTURES-1; i_index >= 0; i_index-- )
71 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
75 * Internal helper to forward an event from p_this to p_data
77 static inline int ForwardEvent( vlc_object_t *p_this, char const *psz_var,
78 vlc_value_t oldval, vlc_value_t newval, void *p_data )
80 VLC_UNUSED(p_this); VLC_UNUSED(oldval);
81 vlc_object_t *p_dst = (vlc_object_t*)p_data;
83 return var_Set( p_dst, psz_var, newval );
86 * Install/remove all callbacks needed for proper event handling inside
89 static inline void vout_filter_SetupChild( vout_thread_t *p_parent,
90 vout_thread_t *p_child,
91 vlc_callback_t pf_mouse_event,
92 vlc_callback_t pf_fullscreen_down,
95 int (*pf_execute)( vlc_object_t *, const char *, vlc_callback_t, void * );
98 pf_execute = var_AddCallback;
100 pf_execute = var_DelCallback;
103 if( !pf_mouse_event )
104 pf_mouse_event = ForwardEvent;
105 pf_execute( VLC_OBJECT(p_child), "mouse-x", pf_mouse_event, p_parent );
106 pf_execute( VLC_OBJECT(p_child), "mouse-y", pf_mouse_event, p_parent );
107 pf_execute( VLC_OBJECT(p_child), "mouse-moved", pf_mouse_event, p_parent );
108 pf_execute( VLC_OBJECT(p_child), "mouse-clicked", pf_mouse_event, p_parent );
109 pf_execute( VLC_OBJECT(p_child), "mouse-button-down", pf_mouse_event, p_parent );
112 pf_execute( VLC_OBJECT(p_parent), "autoscale", ForwardEvent, p_child );
113 pf_execute( VLC_OBJECT(p_parent), "scale", ForwardEvent, p_child );
114 pf_execute( VLC_OBJECT(p_parent), "aspect-ratio", ForwardEvent, p_child );
115 pf_execute( VLC_OBJECT(p_parent), "crop", ForwardEvent, p_child );
118 if( !pf_fullscreen_down )
119 pf_fullscreen_down = ForwardEvent;
120 pf_execute( VLC_OBJECT(p_parent), "fullscreen", pf_fullscreen_down, p_child );
123 #define vout_filter_AddChild( a, b, c ) vout_filter_SetupChild( a, b, c, NULL, true )
124 #define vout_filter_DelChild( a, b, c ) vout_filter_SetupChild( a, b, c, NULL, false )