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() */
32 #include "vlc_video.h"
33 #include "video_output.h"
35 /*****************************************************************************
37 *****************************************************************************/
39 /* Object variables callbacks */
40 static int ZoomCallback( vlc_object_t *, char const *,
41 vlc_value_t, vlc_value_t, void * );
42 static int OnTopCallback( vlc_object_t *, char const *,
43 vlc_value_t, vlc_value_t, void * );
44 static int FullscreenCallback( vlc_object_t *, char const *,
45 vlc_value_t, vlc_value_t, void * );
47 /*****************************************************************************
48 * vout_RequestWindow: Create/Get a video window if possible.
49 *****************************************************************************
50 * This function looks for the main interface and tries to request
51 * a new video window. If it fails then the vout will still need to create the
53 *****************************************************************************/
54 void *vout_RequestWindow( vout_thread_t *p_vout,
55 int *pi_x_hint, int *pi_y_hint,
56 unsigned int *pi_width_hint,
57 unsigned int *pi_height_hint )
59 intf_thread_t *p_intf = NULL;
66 if( !var_Type( p_vout, "aspect-ratio" ) ) vout_IntfInit( p_vout );
68 /* Get requested coordinates */
69 var_Get( p_vout, "video-x", &val );
70 *pi_x_hint = val.i_int ;
71 var_Get( p_vout, "video-y", &val );
72 *pi_y_hint = val.i_int;
74 *pi_width_hint = p_vout->i_window_width;
75 *pi_height_hint = p_vout->i_window_height;
77 /* Check whether someone provided us with a window ID */
78 var_Get( p_vout->p_vlc, "drawable", &val );
79 if( val.i_int ) return (void *)val.i_int;
81 /* Find if the main interface supports embedding */
82 p_list = vlc_list_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
83 if( !p_list ) return NULL;
85 for( i = 0; i < p_list->i_count; i++ )
87 p_intf = (intf_thread_t *)p_list->p_values[i].p_object;
88 if( p_intf->b_block && p_intf->pf_request_window ) break;
94 vlc_list_release( p_list );
98 vlc_object_yield( p_intf );
99 vlc_list_release( p_list );
101 p_window = p_intf->pf_request_window( p_intf, p_vout, pi_x_hint, pi_y_hint,
102 pi_width_hint, pi_height_hint );
104 if( !p_window ) vlc_object_release( p_intf );
105 else p_vout->p_parent_intf = p_intf;
110 void vout_ReleaseWindow( vout_thread_t *p_vout, void *p_window )
112 intf_thread_t *p_intf = p_vout->p_parent_intf;
114 if( !p_intf ) return;
116 vlc_mutex_lock( &p_intf->object_lock );
119 vlc_mutex_unlock( &p_intf->object_lock );
123 if( !p_intf->pf_release_window )
125 msg_Err( p_vout, "no pf_release_window");
126 vlc_mutex_unlock( &p_intf->object_lock );
127 vlc_object_release( p_intf );
131 p_intf->pf_release_window( p_intf, p_window );
133 p_vout->p_parent_intf = NULL;
134 vlc_mutex_unlock( &p_intf->object_lock );
135 vlc_object_release( p_intf );
138 int vout_ControlWindow( vout_thread_t *p_vout, void *p_window,
139 int i_query, va_list args )
141 intf_thread_t *p_intf = p_vout->p_parent_intf;
144 if( !p_intf ) return VLC_EGENERIC;
146 vlc_mutex_lock( &p_intf->object_lock );
149 vlc_mutex_unlock( &p_intf->object_lock );
153 if( !p_intf->pf_control_window )
155 msg_Err( p_vout, "no pf_control_window");
156 vlc_mutex_unlock( &p_intf->object_lock );
160 i_ret = p_intf->pf_control_window( p_intf, p_window, i_query, args );
161 vlc_mutex_unlock( &p_intf->object_lock );
165 /*****************************************************************************
166 * vout_IntfInit: called during the vout creation to initialise misc things.
167 *****************************************************************************/
168 void vout_IntfInit( vout_thread_t *p_vout )
170 vlc_value_t val, text, old_val;
172 /* Create a few object variables we'll need later on */
173 var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
174 var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
175 var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
176 var_Create( p_vout, "align", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
177 var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
178 var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
180 var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
181 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
183 text.psz_string = _("Zoom");
184 var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
186 var_Get( p_vout, "zoom", &old_val );
187 if( old_val.f_float == 0.25 ||
188 old_val.f_float == 0.5 ||
189 old_val.f_float == 1 ||
190 old_val.f_float == 2 )
192 var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
195 val.f_float = 0.25; text.psz_string = _("1:4 Quarter");
196 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
197 val.f_float = 0.5; text.psz_string = _("1:2 Half");
198 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
199 val.f_float = 1; text.psz_string = _("1:1 Original");
200 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
201 val.f_float = 2; text.psz_string = _("2:1 Double");
202 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
204 var_Set( p_vout, "zoom", old_val );
206 var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
208 /* Add a variable to indicate if the window should be on top of others */
209 var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
210 text.psz_string = _("Always on top");
211 var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
212 var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
214 /* Add a variable to indicate whether we want window decoration or not */
215 var_Create( p_vout, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
217 /* Add a fullscreen variable */
218 var_Create( p_vout, "fullscreen", VLC_VAR_BOOL );
219 text.psz_string = _("Fullscreen");
220 var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
221 var_Change( p_vout, "fullscreen", VLC_VAR_INHERITVALUE, &val, NULL );
224 /* user requested fullscreen */
225 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
227 var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
229 /* Mouse coordinates */
230 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
231 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
232 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
233 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
234 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
236 var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
237 val.b_bool = VLC_TRUE;
238 var_Set( p_vout, "intf-change", val );
241 /*****************************************************************************
242 * vout_ControlDefault: default methods for video output control.
243 *****************************************************************************/
244 int vout_vaControlDefault( vout_thread_t *p_vout, int i_query, va_list args )
250 if( p_vout->p_parent_intf )
252 vlc_object_release( p_vout->p_parent_intf );
253 p_vout->p_parent_intf = NULL;
259 msg_Dbg( p_vout, "control query not supported" );
264 /*****************************************************************************
265 * Object variables callbacks
266 *****************************************************************************/
267 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
268 vlc_value_t oldval, vlc_value_t newval, void *p_data )
270 vout_thread_t *p_vout = (vout_thread_t *)p_this;
271 vout_Control( p_vout, VOUT_SET_ZOOM, newval.f_float );
275 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
276 vlc_value_t oldval, vlc_value_t newval, void *p_data )
278 vout_thread_t *p_vout = (vout_thread_t *)p_this;
279 playlist_t *p_playlist;
280 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
282 p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
286 /* Modify playlist as well because the vout might have to be restarted */
287 var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL );
288 var_Set( p_playlist, "video-on-top", newval );
290 vlc_object_release( p_playlist );
295 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
296 vlc_value_t oldval, vlc_value_t newval, void *p_data )
298 vout_thread_t *p_vout = (vout_thread_t *)p_this;
299 playlist_t *p_playlist;
302 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
304 p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
308 /* Modify playlist as well because the vout might have to be restarted */
309 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL );
310 var_Set( p_playlist, "fullscreen", newval );
312 vlc_object_release( p_playlist );
315 /* Disable "always on top" in fullscreen mode */
316 var_Get( p_vout, "video-on-top", &val );
317 if( newval.b_bool && val.b_bool )
319 val.b_bool = VLC_FALSE;
320 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
322 else if( !newval.b_bool && val.b_bool )
324 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
327 val.b_bool = VLC_TRUE;
328 var_Set( p_vout, "intf-change", val );