]> git.sesse.net Git - vlc/blob - src/video_output/vout_intf.c
* src/video_output/vout_intf.c: new vout_ControlWindow() function.
[vlc] / src / video_output / vout_intf.c
1 /*****************************************************************************
2  * vout_intf.c : video output interface
3  *****************************************************************************
4  * Copyright (C) 2000-2004 VideoLAN
5  * $Id: video_output.c 6961 2004-03-05 17:34:23Z sam $
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                                /* free() */
28
29 #include <vlc/vlc.h>
30
31 #include "vlc_video.h"
32 #include "video_output.h"
33 #include "vlc_interface.h"
34
35 /*****************************************************************************
36  * Local prototypes
37  *****************************************************************************/
38
39 /* Object variables callbacks */
40 static int ZoomCallback( vlc_object_t *, char const *,
41                          vlc_value_t, vlc_value_t, void * );
42
43 /*****************************************************************************
44  * vout_RequestWindow: Create/Get a video window if possible.
45  *****************************************************************************
46  * This function looks for the main interface and tries to request
47  * a new video window. If it fails then the vout will still need to create the
48  * window by itself.
49  *****************************************************************************/
50 void *vout_RequestWindow( vout_thread_t *p_vout,
51                           int *pi_x_hint, int *pi_y_hint,
52                           unsigned int *pi_width_hint,
53                           unsigned int *pi_height_hint )
54 {
55     intf_thread_t *p_intf;
56     void *p_window;
57     vlc_value_t val;
58
59     /* Get requested coordinates */
60     var_Get( p_vout, "video-x", &val );
61     *pi_x_hint = val.i_int ;
62     var_Get( p_vout, "video-y", &val );
63     *pi_y_hint = val.i_int;
64
65     *pi_width_hint = p_vout->i_window_width;
66     *pi_height_hint = p_vout->i_window_height;
67
68     /* Check whether someone provided us with a window ID */
69     var_Get( p_vout->p_vlc, "drawable", &val );
70     if( val.i_int ) return (void *)val.i_int;
71
72     /* Find the main interface */
73     p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
74     if( !p_intf ) return NULL;
75
76     if( !p_intf->pf_request_window )
77     {
78         vlc_object_release( p_intf );
79         return NULL;
80     }
81
82     p_window = p_intf->pf_request_window( p_intf, p_vout, pi_x_hint, pi_y_hint,
83                                           pi_width_hint, pi_height_hint );
84     vlc_object_release( p_intf );
85
86     return p_window;
87 }
88
89 void vout_ReleaseWindow( vout_thread_t *p_vout, void *p_window )
90 {
91     intf_thread_t *p_intf;
92
93     /* Find the main interface */
94     p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
95     if( !p_intf ) return;
96
97     if( !p_intf->pf_release_window )
98     {
99         msg_Err( p_vout, "no pf_release_window");
100         vlc_object_release( p_intf );
101         return;
102     }
103
104     p_intf->pf_release_window( p_intf, p_window );
105     vlc_object_release( p_intf );
106 }
107
108 int vout_ControlWindow( vout_thread_t *p_vout, void *p_window,
109                         int i_query, va_list args )
110 {
111     intf_thread_t *p_intf;
112     int i_ret;
113
114     /* Find the main interface */
115     p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
116     if( !p_intf ) return VLC_EGENERIC;
117
118     if( !p_intf->pf_control_window )
119     {
120         msg_Err( p_vout, "no pf_control_window");
121         vlc_object_release( p_intf );
122         return VLC_EGENERIC;
123     }
124
125     i_ret = p_intf->pf_control_window( p_intf, p_window, i_query, args );
126     vlc_object_release( p_intf );
127     return i_ret;
128 }
129
130 /*****************************************************************************
131  * vout_IntfInit: called during the vout creation to initialise misc things.
132  *****************************************************************************/
133 void vout_IntfInit( vout_thread_t *p_vout )
134 {
135     vlc_value_t val, text, old_val;
136
137     /* Create a few object variables we'll need later on */
138     var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
139     var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
140     var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
141     var_Create( p_vout, "align", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
142     var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
143     var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
144
145     var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
146                 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
147
148     text.psz_string = _("Zoom");
149     var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
150
151     var_Get( p_vout, "zoom", &old_val );
152     if( old_val.f_float == 0.25 ||
153         old_val.f_float == 0.5 ||
154         old_val.f_float == 1 ||
155         old_val.f_float == 2 )
156     {
157         var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
158     }
159
160     val.f_float = 0.25; text.psz_string = _("1:4 Quater");
161     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
162     val.f_float = 0.5; text.psz_string = _("1:2 Half");
163     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
164     val.f_float = 1; text.psz_string = _("1:1 Original");
165     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
166     val.f_float = 2; text.psz_string = _("2:1 Double");
167     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
168
169     var_Set( p_vout, "zoom", old_val );
170
171     var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
172 }
173
174 /*****************************************************************************
175  * Object variables callbacks
176  *****************************************************************************/
177 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
178                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
179 {
180     vout_thread_t *p_vout = (vout_thread_t *)p_this;
181     vout_Control( p_vout, VOUT_SET_ZOOM, newval.f_float );
182     return VLC_SUCCESS;
183 }