1 /*****************************************************************************
2 * vout_intf.c : video output interface
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
7 * Authors: Gildas Bazin <gbazin@videolan.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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* free() */
31 #include "vlc_video.h"
32 #include "video_output.h"
33 #include "vlc_interface.h"
35 #include <vlc/input.h> /* for input_thread_t */
37 /*****************************************************************************
39 *****************************************************************************/
41 /* Object variables callbacks */
42 static int ZoomCallback( vlc_object_t *, char const *,
43 vlc_value_t, vlc_value_t, void * );
44 static int OnTopCallback( vlc_object_t *, char const *,
45 vlc_value_t, vlc_value_t, void * );
46 static int FullscreenCallback( vlc_object_t *, char const *,
47 vlc_value_t, vlc_value_t, void * );
49 /*****************************************************************************
50 * vout_RequestWindow: Create/Get a video window if possible.
51 *****************************************************************************
52 * This function looks for the main interface and tries to request
53 * a new video window. If it fails then the vout will still need to create the
55 *****************************************************************************/
56 void *vout_RequestWindow( vout_thread_t *p_vout,
57 int *pi_x_hint, int *pi_y_hint,
58 unsigned int *pi_width_hint,
59 unsigned int *pi_height_hint )
61 intf_thread_t *p_intf;
65 /* Get requested coordinates */
66 var_Get( p_vout, "video-x", &val );
67 *pi_x_hint = val.i_int ;
68 var_Get( p_vout, "video-y", &val );
69 *pi_y_hint = val.i_int;
71 *pi_width_hint = p_vout->i_window_width;
72 *pi_height_hint = p_vout->i_window_height;
74 /* Check whether someone provided us with a window ID */
75 var_Get( p_vout->p_vlc, "drawable", &val );
76 if( val.i_int ) return (void *)val.i_int;
78 /* Find the main interface */
79 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
80 if( !p_intf ) return NULL;
82 if( !p_intf->pf_request_window )
84 vlc_object_release( p_intf );
88 p_window = p_intf->pf_request_window( p_intf, p_vout, pi_x_hint, pi_y_hint,
89 pi_width_hint, pi_height_hint );
90 vlc_object_release( p_intf );
95 void vout_ReleaseWindow( vout_thread_t *p_vout, void *p_window )
97 intf_thread_t *p_intf;
99 /* Find the main interface */
100 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
101 if( !p_intf ) return;
103 if( !p_intf->pf_release_window )
105 msg_Err( p_vout, "no pf_release_window");
106 vlc_object_release( p_intf );
110 p_intf->pf_release_window( p_intf, p_window );
111 vlc_object_release( p_intf );
114 int vout_ControlWindow( vout_thread_t *p_vout, void *p_window,
115 int i_query, va_list args )
117 intf_thread_t *p_intf;
120 /* Find the main interface */
121 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
122 if( !p_intf ) return VLC_EGENERIC;
124 if( !p_intf->pf_control_window )
126 msg_Err( p_vout, "no pf_control_window");
127 vlc_object_release( p_intf );
131 i_ret = p_intf->pf_control_window( p_intf, p_window, i_query, args );
132 vlc_object_release( p_intf );
136 /*****************************************************************************
137 * vout_IntfInit: called during the vout creation to initialise misc things.
138 *****************************************************************************/
139 void vout_IntfInit( vout_thread_t *p_vout )
141 vlc_value_t val, text, old_val;
143 /* Create a few object variables we'll need later on */
144 var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
145 var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
146 var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
147 var_Create( p_vout, "align", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
148 var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
149 var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
151 var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
152 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
154 text.psz_string = _("Zoom");
155 var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
157 var_Get( p_vout, "zoom", &old_val );
158 if( old_val.f_float == 0.25 ||
159 old_val.f_float == 0.5 ||
160 old_val.f_float == 1 ||
161 old_val.f_float == 2 )
163 var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
166 val.f_float = 0.25; text.psz_string = _("1:4 Quarter");
167 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
168 val.f_float = 0.5; text.psz_string = _("1:2 Half");
169 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
170 val.f_float = 1; text.psz_string = _("1:1 Original");
171 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
172 val.f_float = 2; text.psz_string = _("2:1 Double");
173 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
175 var_Set( p_vout, "zoom", old_val );
177 var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
179 /* Add a variable to indicate if the window should be on top of others */
180 var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
181 text.psz_string = _("Always on top");
182 var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
183 var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
185 /* Add a fullscreen variable */
186 var_Create( p_vout, "fullscreen", VLC_VAR_BOOL );
187 text.psz_string = _("Fullscreen");
188 var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
189 var_Change( p_vout, "fullscreen", VLC_VAR_INHERITVALUE, &val, NULL );
192 /* user requested fullscreen */
193 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
195 var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
198 /*****************************************************************************
199 * Object variables callbacks
200 *****************************************************************************/
201 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
202 vlc_value_t oldval, vlc_value_t newval, void *p_data )
204 vout_thread_t *p_vout = (vout_thread_t *)p_this;
205 vout_Control( p_vout, VOUT_SET_ZOOM, newval.f_float );
209 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
210 vlc_value_t oldval, vlc_value_t newval, void *p_data )
212 vout_thread_t *p_vout = (vout_thread_t *)p_this;
213 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
217 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
218 vlc_value_t oldval, vlc_value_t newval, void *p_data )
220 vout_thread_t *p_vout = (vout_thread_t *)p_this;
221 input_thread_t *p_input;
224 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
226 p_input = (input_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INPUT,
230 /* Modify input as well because the vout might have to be restarted */
231 var_Create( p_input, "fullscreen", VLC_VAR_BOOL );
232 var_Set( p_input, "fullscreen", newval );
234 vlc_object_release( p_input );
237 /* Disable "always on top" in fullscreen mode */
238 var_Get( p_vout, "video-on-top", &val );
239 if( newval.b_bool && val.b_bool )
241 val.b_bool = VLC_FALSE;
242 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
244 else if( !newval.b_bool && val.b_bool )
246 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
249 val.b_bool = VLC_TRUE;
250 var_Set( p_vout, "intf-change", val );