]> git.sesse.net Git - vlc/blob - modules/video_filter/filter_common.h
"fullscreen" callback: do nothing if value is unchanged
[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  * Install/remove all callbacks needed for proper event handling inside
87  * a vout-filter.
88  */
89 static inline void vout_filter_SetupChild( vout_thread_t *p_parent, vout_thread_t *p_child,
90                                            vlc_callback_t pf_mouse_event,
91                                            vlc_callback_t pf_fullscreen_up,
92                                            vlc_callback_t pf_fullscreen_down,
93                                            bool b_init )
94 {
95     int (*pf_execute)( vlc_object_t *, const char *, vlc_callback_t, void * );
96
97     if( b_init )
98         pf_execute = var_AddCallback;
99     else
100         pf_execute = var_DelCallback;
101
102     /* */
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 );
110
111     /* */
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 );
116
117     /* */
118     if( !pf_fullscreen_up )
119         pf_fullscreen_up = ForwardEvent;
120     if( !pf_fullscreen_down )
121         pf_fullscreen_down = ForwardEvent;
122     pf_execute( VLC_OBJECT(p_child),  "fullscreen", pf_fullscreen_up,   p_parent );
123     pf_execute( VLC_OBJECT(p_parent), "fullscreen", pf_fullscreen_down, p_child );
124 }
125
126 #define vout_filter_AddChild( a, b, c ) vout_filter_SetupChild( a, b, c, NULL, NULL, true )
127 #define vout_filter_DelChild( a, b, c ) vout_filter_SetupChild( a, b, c, NULL, NULL, false )
128