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