Contribs: Die if NO_RELOCATION
[vlc/davidf-public.git] / src / control / mediacontrol_audio_video.c
blobcf6f0268c96e3708e587f21aa5c98da3960556aa
1 /*****************************************************************************
2 * audio_video.c: Audio/Video management : volume, snapshot, OSD
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
5 * $Id$
7 * Authors: Olivier Aubert <olivier.aubert@liris.univ-lyon1.fr>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27 #include "mediacontrol_internal.h"
28 #include "libvlc_internal.h"
30 #include <vlc/mediacontrol.h>
31 #include <vlc/libvlc.h>
33 #include <vlc_vout.h>
34 #include <vlc_osd.h>
36 #include <stdlib.h> /* malloc(), free() */
37 #include <string.h>
39 #include <errno.h> /* ENOMEM */
40 #include <stdio.h>
41 #include <ctype.h>
43 #ifdef HAVE_UNISTD_H
44 # include <unistd.h>
45 #endif
46 #ifdef HAVE_SYS_TIME_H
47 # include <sys/time.h>
48 #endif
49 #ifdef HAVE_SYS_TYPES_H
50 # include <sys/types.h>
51 #endif
53 mediacontrol_RGBPicture *
54 mediacontrol_snapshot( mediacontrol_Instance *self,
55 const mediacontrol_Position * a_position,
56 mediacontrol_Exception *exception )
58 (void)a_position;
59 vlc_object_t* p_cache;
60 vout_thread_t* p_vout;
61 input_thread_t *p_input;
62 mediacontrol_RGBPicture *p_pic = NULL;
63 char path[256];
64 snapshot_t *p_snapshot;
65 libvlc_exception_t ex;
67 libvlc_exception_init( &ex );
68 mediacontrol_exception_init( exception );
70 p_input = libvlc_get_input_thread( self->p_media_player, &ex );
71 if( ! p_input )
73 RAISE_NULL( mediacontrol_InternalException, "No input" );
75 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
76 if( ! p_vout )
78 RAISE_NULL( mediacontrol_InternalException, "No video output" );
80 p_cache = vlc_object_create( p_input, sizeof( vlc_object_t ) );
81 if( p_cache == NULL )
83 vlc_object_release( p_vout );
84 vlc_object_release( p_input );
85 RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
87 snprintf( path, 255, "object:%ju", (uintmax_t)(uintptr_t)p_cache );
88 var_SetString( p_vout, "snapshot-path", path );
89 var_SetString( p_vout, "snapshot-format", "png" );
91 vlc_object_lock( p_cache );
92 vout_Control( p_vout, VOUT_SNAPSHOT );
93 vlc_object_wait( p_cache );
94 vlc_object_release( p_vout );
96 p_snapshot = ( snapshot_t* ) p_cache->p_private;
97 vlc_object_unlock( p_cache );
98 vlc_object_release( p_cache );
99 vlc_object_release( p_input );
101 if( p_snapshot )
103 /* Note: p_snapshot->p_data is directly used, not copied. Thus
104 do not free it here. */
105 p_pic = private_mediacontrol_createRGBPicture( p_snapshot->i_width,
106 p_snapshot->i_height,
107 VLC_FOURCC( 'p','n','g',' ' ),
108 p_snapshot->date,
109 p_snapshot->p_data,
110 p_snapshot->i_datasize );
111 if( !p_pic )
113 free( p_snapshot );
114 RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
117 else
119 RAISE_NULL( mediacontrol_InternalException, "Snapshot exception" );
121 return p_pic;
124 static
125 int mediacontrol_showtext( vout_thread_t *p_vout, int i_channel,
126 char *psz_string, text_style_t *p_style,
127 int i_flags, int i_hmargin, int i_vmargin,
128 mtime_t i_start, mtime_t i_stop )
130 return osd_ShowTextAbsolute( p_vout->p_spu, i_channel,
131 psz_string, p_style,
132 i_flags, i_hmargin, i_vmargin,
133 i_start, i_stop );
137 void
138 mediacontrol_display_text( mediacontrol_Instance *self,
139 const char * message,
140 const mediacontrol_Position * begin,
141 const mediacontrol_Position * end,
142 mediacontrol_Exception *exception )
144 vout_thread_t *p_vout = NULL;
145 char* psz_message;
146 input_thread_t *p_input;
147 libvlc_exception_t ex;
149 libvlc_exception_init( &ex );
150 mediacontrol_exception_init( exception );
152 p_input = libvlc_get_input_thread( self->p_media_player, &ex );
153 if( ! p_input )
155 RAISE_VOID( mediacontrol_InternalException, "No input" );
157 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
158 if( ! p_vout )
160 RAISE_VOID( mediacontrol_InternalException, "No video output" );
163 psz_message = strdup( message );
164 if( !psz_message )
166 RAISE_VOID( mediacontrol_InternalException, "no more memory" );
169 if( begin->origin == mediacontrol_RelativePosition &&
170 begin->value == 0 &&
171 end->origin == mediacontrol_RelativePosition )
173 mtime_t i_duration = 0;
174 mtime_t i_now = mdate();
176 i_duration = 1000 * private_mediacontrol_unit_convert(
177 self->p_media_player,
178 end->key,
179 mediacontrol_MediaTime,
180 end->value );
182 mediacontrol_showtext( p_vout, DEFAULT_CHAN, psz_message, NULL,
183 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
184 i_now, i_now + i_duration );
186 else
188 mtime_t i_debut, i_fin, i_now;
190 /* FIXME */
191 /* i_now = input_ClockGetTS( p_input, NULL, 0 ); */
192 i_now = mdate();
194 i_debut = private_mediacontrol_position2microsecond( self->p_media_player,
195 ( mediacontrol_Position* ) begin );
196 i_debut += i_now;
198 i_fin = private_mediacontrol_position2microsecond( self->p_media_player,
199 ( mediacontrol_Position * ) end );
200 i_fin += i_now;
202 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN, psz_message, NULL,
203 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
204 i_debut, i_fin );
207 vlc_object_release( p_vout );
210 unsigned short
211 mediacontrol_sound_get_volume( mediacontrol_Instance *self,
212 mediacontrol_Exception *exception )
214 libvlc_exception_t ex;
215 int i_ret = 0;
217 mediacontrol_exception_init( exception );
218 libvlc_exception_init( &ex );
220 i_ret = libvlc_audio_get_volume( self->p_instance, &ex );
221 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
222 /* FIXME: Normalize in [0..100] */
223 return (unsigned short)i_ret;
226 void
227 mediacontrol_sound_set_volume( mediacontrol_Instance *self,
228 const unsigned short volume,
229 mediacontrol_Exception *exception )
231 /* FIXME: Normalize in [0..100] */
232 libvlc_exception_t ex;
234 mediacontrol_exception_init( exception );
235 libvlc_exception_init( &ex );
237 libvlc_audio_set_volume( self->p_instance, volume, &ex );
238 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
241 int mediacontrol_set_visual( mediacontrol_Instance *self,
242 WINDOWHANDLE visual_id,
243 mediacontrol_Exception *exception )
245 libvlc_exception_t ex;
247 mediacontrol_exception_init( exception );
248 libvlc_exception_init( &ex );
250 libvlc_media_player_set_drawable( self->p_media_player, (libvlc_drawable_t)visual_id, &ex );
251 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
252 return true;
256 mediacontrol_get_rate( mediacontrol_Instance *self,
257 mediacontrol_Exception *exception )
259 libvlc_exception_t ex;
260 int i_ret;
262 mediacontrol_exception_init( exception );
263 libvlc_exception_init( &ex );
265 i_ret = libvlc_media_player_get_rate( self->p_media_player, &ex );
266 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
268 return i_ret / 10;
271 void
272 mediacontrol_set_rate( mediacontrol_Instance *self,
273 const int rate,
274 mediacontrol_Exception *exception )
276 libvlc_exception_t ex;
278 mediacontrol_exception_init( exception );
279 libvlc_exception_init( &ex );
281 libvlc_media_player_set_rate( self->p_media_player, rate * 10, &ex );
282 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
286 mediacontrol_get_fullscreen( mediacontrol_Instance *self,
287 mediacontrol_Exception *exception )
289 libvlc_exception_t ex;
290 int i_ret;
292 mediacontrol_exception_init( exception );
293 libvlc_exception_init( &ex );
295 i_ret = libvlc_get_fullscreen( self->p_media_player, &ex );
296 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
298 return i_ret;
301 void
302 mediacontrol_set_fullscreen( mediacontrol_Instance *self,
303 const int b_fullscreen,
304 mediacontrol_Exception *exception )
306 libvlc_exception_t ex;
308 mediacontrol_exception_init( exception );
309 libvlc_exception_init( &ex );
311 libvlc_set_fullscreen( self->p_media_player, b_fullscreen, &ex );
312 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );