]> git.sesse.net Git - vlc/blob - modules/video_filter/filter_common.h
5413cc7ff8822b2c33c3b213ca513fe3d81da3a6
[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 * p_vout->output.i_height,
54                               VOUT_ASPECT_FACTOR      * p_vout->output.i_width );
55
56         if( !p_pic->i_planes )
57             break;
58
59         p_pic->i_status = DESTROYED_PICTURE;
60         p_pic->i_type   = DIRECT_PICTURE;
61
62         PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
63
64         I_OUTPUTPICTURES++;
65     }
66 }
67
68 static inline void vout_filter_ReleaseDirectBuffers( vout_thread_t *p_vout )
69 {
70     for( int i_index = I_OUTPUTPICTURES-1; i_index >= 0; i_index-- )
71         free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
72 }
73
74 /**
75  * Internal helper to forward an event from p_this to p_data
76  */
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 )
79 {
80     VLC_UNUSED(p_this); VLC_UNUSED(oldval);
81     vlc_object_t *p_dst = (vlc_object_t*)p_data;
82
83     return var_Set( p_dst, psz_var, newval );
84 }
85 /**
86  * Internal helper to forward fullscreen event from p_this to p_data.
87  */
88 static inline int ForwardFullscreen( vlc_object_t *p_this, char const *psz_var,
89                                      vlc_value_t oldval, vlc_value_t newval, void *p_data )
90 {
91     VLC_UNUSED(p_this); VLC_UNUSED(oldval);
92     vlc_object_t *p_dst = (vlc_object_t*)p_data;
93
94     if( !var_GetBool( p_dst, "fullscreen" ) != !newval.b_bool )
95         return var_SetBool( p_dst, psz_var, newval.b_bool );
96     return VLC_SUCCESS;
97 }
98 /**
99  * Install/remove all callbacks needed for proper event handling inside
100  * a vout-filter.
101  */
102 static inline void vout_filter_SetupChild( vout_thread_t *p_parent, vout_thread_t *p_child,
103                                            vlc_callback_t pf_mouse_event,
104                                            vlc_callback_t pf_fullscreen_up,
105                                            vlc_callback_t pf_fullscreen_down,
106                                            bool b_init )
107 {
108     int (*pf_execute)( vlc_object_t *, const char *, vlc_callback_t, void * );
109
110     if( b_init )
111         pf_execute = var_AddCallback;
112     else
113         pf_execute = var_DelCallback;
114
115     /* */
116     if( !pf_mouse_event )
117         pf_mouse_event = ForwardEvent;
118     pf_execute( VLC_OBJECT(p_child), "mouse-x",           pf_mouse_event, p_parent );
119     pf_execute( VLC_OBJECT(p_child), "mouse-y",           pf_mouse_event, p_parent );
120     pf_execute( VLC_OBJECT(p_child), "mouse-moved",       pf_mouse_event, p_parent );
121     pf_execute( VLC_OBJECT(p_child), "mouse-clicked",     pf_mouse_event, p_parent );
122     pf_execute( VLC_OBJECT(p_child), "mouse-button-down", pf_mouse_event, p_parent );
123
124     /* */
125     pf_execute( VLC_OBJECT(p_parent), "autoscale",    ForwardEvent, p_child );
126     pf_execute( VLC_OBJECT(p_parent), "scale",        ForwardEvent, p_child );
127     pf_execute( VLC_OBJECT(p_parent), "aspect-ratio", ForwardEvent, p_child );
128     pf_execute( VLC_OBJECT(p_parent), "crop",         ForwardEvent, p_child );
129
130     /* */
131     if( !pf_fullscreen_up )
132         pf_fullscreen_up = ForwardFullscreen;
133     if( !pf_fullscreen_down )
134         pf_fullscreen_down = ForwardFullscreen;
135     pf_execute( VLC_OBJECT(p_child),  "fullscreen", pf_fullscreen_up,   p_parent );
136     pf_execute( VLC_OBJECT(p_parent), "fullscreen", pf_fullscreen_down, p_child );
137 }
138
139 #define vout_filter_AddChild( a, b, c ) vout_filter_SetupChild( a, b, c, NULL, NULL, true )
140 #define vout_filter_DelChild( a, b, c ) vout_filter_SetupChild( a, b, c, NULL, NULL, false )
141