]> git.sesse.net Git - vlc/blob - src/control/video.c
libvlc: Vout object now released when needed
[vlc] / src / control / video.c
1 /*****************************************************************************
2  * video.c: ibvlc new API video functions
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  * $Id: core.c 14187 2006-02-07 16:37:40Z courmisch $
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include <libvlc_internal.h>
25 #include <vlc/libvlc.h>
26
27 #include <vlc/vout.h>
28 #include <vlc/intf.h>
29
30 static vout_thread_t *GetVout( libvlc_input_t *p_input,
31                                libvlc_exception_t *p_exception )
32 {
33     input_thread_t *p_input_thread;
34     vout_thread_t *p_vout;
35
36     if( !p_input )
37     {
38         libvlc_exception_raise( p_exception, "Input is NULL" );
39         return NULL;
40     }
41
42     p_input_thread = (input_thread_t*)vlc_object_get(
43                                  p_input->p_instance->p_vlc,
44                                  p_input->i_input_id );
45     if( !p_input_thread )
46     {
47         libvlc_exception_raise( p_exception, "Input does not exist" );
48         return NULL;
49     }
50
51     p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
52     if( !p_vout )
53     {
54         libvlc_exception_raise( p_exception, "No active video output" );
55         return NULL;
56     }
57     return p_vout;
58 }
59 /**********************************************************************
60  * Exported functions
61  **********************************************************************/
62
63 void libvlc_set_fullscreen( libvlc_input_t *p_input, int b_fullscreen,
64                             libvlc_exception_t *p_e )
65 {
66     /* We only work on the first vout */
67     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
68     vlc_value_t val; int i_ret;
69
70     /* GetVout will raise the exception for us */
71     if( !p_vout1 )
72     {
73         return;
74     }
75
76     if( b_fullscreen ) val.b_bool = VLC_TRUE;
77     else               val.b_bool = VLC_FALSE;
78
79     i_ret = var_Set( p_vout1, "fullscreen", val );
80     if( i_ret )
81         libvlc_exception_raise( p_e,
82                         "Unexpected error while setting fullscreen value" );
83
84     vlc_object_release( p_vout1 );
85
86 }
87
88 int libvlc_get_fullscreen( libvlc_input_t *p_input,
89                             libvlc_exception_t *p_e )
90 {
91     /* We only work on the first vout */
92     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
93     vlc_value_t val; int i_ret;
94
95     /* GetVout will raise the exception for us */
96     if( !p_vout1 )
97         return 0;
98
99     i_ret = var_Get( p_vout1, "fullscreen", &val );
100     if( i_ret )
101         libvlc_exception_raise( p_e,
102                         "Unexpected error while looking up fullscreen value" );
103
104     return val.b_bool == VLC_TRUE ? 1 : 0;
105 }
106
107 void libvlc_toggle_fullscreen( libvlc_input_t *p_input,
108                                libvlc_exception_t *p_e )
109 {
110     /* We only work on the first vout */
111     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
112     vlc_value_t val; int i_ret;
113
114     /* GetVout will raise the exception for us */
115     if( !p_vout1 )
116         return;
117
118     i_ret = var_Get( p_vout1, "fullscreen", &val );
119     if( i_ret )
120         libvlc_exception_raise( p_e,
121                         "Unexpected error while looking up fullscreen value" );
122
123     val.b_bool = !val.b_bool;
124     i_ret = var_Set( p_vout1, "fullscreen", val );
125     if( i_ret )
126         libvlc_exception_raise( p_e,
127                         "Unexpected error while setting fullscreen value" );
128
129     vlc_object_release( p_vout1 );
130
131 }
132
133 void
134 libvlc_video_take_snapshot( libvlc_input_t *p_input, char *psz_filepath,
135                        libvlc_exception_t *p_e )
136 {
137     vout_thread_t *p_vout = GetVout( p_input, p_e );
138     input_thread_t *p_input_thread;
139     
140     char path[256];
141
142     /* GetVout will raise the exception for us */
143     if( !p_vout )
144     {
145         return;
146     }
147
148     p_input_thread = (input_thread_t*)vlc_object_get(
149                                  p_input->p_instance->p_vlc,
150                                  p_input->i_input_id );
151     if( !p_input_thread )
152     {
153         libvlc_exception_raise( p_e, "Input does not exist" );
154         return NULL;
155     }
156    
157     snprintf( path, 255, "%s", psz_filepath );
158     var_SetString( p_vout, "snapshot-path", path );
159     var_SetString( p_vout, "snapshot-format", "png" );
160
161     vout_Control( p_vout, VOUT_SNAPSHOT );
162     vlc_object_release( p_vout );
163
164     return;
165     
166 }
167
168 int libvlc_video_get_height( libvlc_input_t *p_input,
169                              libvlc_exception_t *p_e ) 
170 {
171     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
172     if( !p_vout1 )
173         return 0;
174
175     vlc_object_release( p_vout1 );
176
177     return p_vout1->i_window_height;
178 }
179
180 int libvlc_video_get_width( libvlc_input_t *p_input,
181                             libvlc_exception_t *p_e ) 
182 {
183     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
184     if( !p_vout1 )
185         return 0;
186
187     vlc_object_release( p_vout1 );
188
189     return p_vout1->i_window_width;
190 }
191
192 vlc_bool_t libvlc_input_has_vout( libvlc_input_t *p_input,
193                                   libvlc_exception_t *p_e )
194 {
195     vout_thread_t *p_vout = GetVout( p_input, p_e );
196
197     /* GetVout will raise the exception for us */
198     if( !p_vout )
199     {
200         return VLC_FALSE;
201     }
202
203     vlc_object_release( p_vout );
204     
205     return VLC_TRUE;
206 }