1 /*****************************************************************************
2 * audio_video.c: Audio/Video management : volume, snapshot, OSD
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
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 *****************************************************************************/
27 #include "mediacontrol_internal.h"
28 #include "libvlc_internal.h"
30 #include <vlc/mediacontrol.h>
31 #include <vlc/libvlc.h>
36 #include <stdlib.h> /* malloc(), free() */
39 #include <errno.h> /* ENOMEM */
46 #ifdef HAVE_SYS_TIME_H
47 # include <sys/time.h>
49 #ifdef HAVE_SYS_TYPES_H
50 # include <sys/types.h>
53 mediacontrol_RGBPicture *
54 mediacontrol_snapshot( mediacontrol_Instance *self,
55 const mediacontrol_Position * a_position,
56 mediacontrol_Exception *exception )
59 vout_thread_t* p_vout;
60 input_thread_t *p_input;
61 mediacontrol_RGBPicture *p_pic = NULL;
63 snapshot_t *p_snapshot;
64 libvlc_exception_t ex;
66 libvlc_exception_init( &ex );
67 mediacontrol_exception_init( exception );
70 p_snapshot = malloc( sizeof( snapshot_t ) );
73 RAISE_NULL( mediacontrol_InternalException, "Cannot allocate snapshot" );
76 p_input = libvlc_get_input_thread( self->p_media_player, &ex );
79 RAISE_NULL( mediacontrol_InternalException, "No input" );
82 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
83 vlc_object_release( p_input );
86 RAISE_NULL( mediacontrol_InternalException, "No video output" );
89 snprintf( path, 255, "object:%p", p_snapshot );
90 var_SetString( p_vout, "snapshot-path", path );
91 var_SetString( p_vout, "snapshot-format", "png" );
93 vlc_mutex_init( &p_snapshot->p_mutex );
94 vlc_cond_init( &p_snapshot->p_condvar );
96 vlc_mutex_lock( &p_snapshot->p_mutex );
97 mutex_cleanup_push( &p_snapshot->p_mutex );
99 /* Use p_snapshot address as sentinel against spurious vlc_object_wait wakeups.
101 If a legitimate wakeup occurs, then p_snapshot->p_data will hold either
102 NULL (in case of error) or a pointer to valid data. */
103 p_snapshot->p_data = ( char* )p_snapshot;
105 vout_Control( p_vout, VOUT_SNAPSHOT );
106 while ( p_snapshot->p_data == ( char* )p_snapshot )
108 vlc_cond_wait( &p_snapshot->p_condvar, &p_snapshot->p_mutex );
112 vlc_object_release( p_vout );
114 vlc_mutex_unlock( &p_snapshot->p_mutex );
115 vlc_cond_destroy( &p_snapshot->p_condvar );
116 vlc_mutex_destroy( &p_snapshot->p_mutex );
118 if( p_snapshot->p_data )
120 /* Note: p_snapshot->p_data is directly used, not copied. Thus
121 do not free it here. */
122 p_pic = private_mediacontrol_createRGBPicture( p_snapshot->i_width,
123 p_snapshot->i_height,
124 VLC_FOURCC( 'p','n','g',' ' ),
127 p_snapshot->i_datasize );
131 RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
136 RAISE_NULL( mediacontrol_InternalException, "Snapshot exception" );
142 int mediacontrol_showtext( vout_thread_t *p_vout, int i_channel,
143 const char *psz_string, text_style_t *p_style,
144 int i_flags, int i_hmargin, int i_vmargin,
145 mtime_t i_start, mtime_t i_stop )
147 return osd_ShowTextAbsolute( p_vout->p_spu, i_channel,
149 i_flags, i_hmargin, i_vmargin,
155 mediacontrol_display_text( mediacontrol_Instance *self,
156 const char * message,
157 const mediacontrol_Position * begin,
158 const mediacontrol_Position * end,
159 mediacontrol_Exception *exception )
161 vout_thread_t *p_vout = NULL;
162 input_thread_t *p_input;
163 libvlc_exception_t ex;
165 libvlc_exception_init( &ex );
166 mediacontrol_exception_init( exception );
170 RAISE_VOID( mediacontrol_InternalException, "Empty text" );
173 p_input = libvlc_get_input_thread( self->p_media_player, &ex );
176 RAISE_VOID( mediacontrol_InternalException, "No input" );
178 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
181 RAISE_VOID( mediacontrol_InternalException, "No video output" );
184 if( begin->origin == mediacontrol_RelativePosition &&
186 end->origin == mediacontrol_RelativePosition )
188 mtime_t i_duration = 0;
189 mtime_t i_now = mdate();
191 i_duration = 1000 * private_mediacontrol_unit_convert(
192 self->p_media_player,
194 mediacontrol_MediaTime,
197 mediacontrol_showtext( p_vout, DEFAULT_CHAN, message, NULL,
198 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
199 i_now, i_now + i_duration );
203 mtime_t i_debut, i_fin, i_now;
206 /* i_now = input_ClockGetTS( p_input, NULL, 0 ); */
209 i_debut = private_mediacontrol_position2microsecond( self->p_media_player,
210 ( mediacontrol_Position* ) begin );
213 i_fin = private_mediacontrol_position2microsecond( self->p_media_player,
214 ( mediacontrol_Position * ) end );
217 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN, message, NULL,
218 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
222 vlc_object_release( p_vout );
226 mediacontrol_sound_get_volume( mediacontrol_Instance *self,
227 mediacontrol_Exception *exception )
229 libvlc_exception_t ex;
232 mediacontrol_exception_init( exception );
233 libvlc_exception_init( &ex );
235 i_ret = libvlc_audio_get_volume( self->p_instance, &ex );
236 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
237 /* FIXME: Normalize in [0..100] */
238 return (unsigned short)i_ret;
242 mediacontrol_sound_set_volume( mediacontrol_Instance *self,
243 const unsigned short volume,
244 mediacontrol_Exception *exception )
246 /* FIXME: Normalize in [0..100] */
247 libvlc_exception_t ex;
249 mediacontrol_exception_init( exception );
250 libvlc_exception_init( &ex );
252 libvlc_audio_set_volume( self->p_instance, volume, &ex );
253 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
256 int mediacontrol_set_visual( mediacontrol_Instance *self,
257 WINDOWHANDLE visual_id,
258 mediacontrol_Exception *exception )
260 libvlc_exception_t ex;
262 mediacontrol_exception_init( exception );
263 libvlc_exception_init( &ex );
265 libvlc_media_player_set_drawable( self->p_media_player, (libvlc_drawable_t)visual_id, &ex );
266 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
271 mediacontrol_get_rate( mediacontrol_Instance *self,
272 mediacontrol_Exception *exception )
274 libvlc_exception_t ex;
277 mediacontrol_exception_init( exception );
278 libvlc_exception_init( &ex );
280 i_ret = libvlc_media_player_get_rate( self->p_media_player, &ex );
281 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
287 mediacontrol_set_rate( mediacontrol_Instance *self,
289 mediacontrol_Exception *exception )
291 libvlc_exception_t ex;
293 mediacontrol_exception_init( exception );
294 libvlc_exception_init( &ex );
296 libvlc_media_player_set_rate( self->p_media_player, rate * 10, &ex );
297 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
301 mediacontrol_get_fullscreen( mediacontrol_Instance *self,
302 mediacontrol_Exception *exception )
304 libvlc_exception_t ex;
307 mediacontrol_exception_init( exception );
308 libvlc_exception_init( &ex );
310 i_ret = libvlc_get_fullscreen( self->p_media_player, &ex );
311 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
317 mediacontrol_set_fullscreen( mediacontrol_Instance *self,
318 const int b_fullscreen,
319 mediacontrol_Exception *exception )
321 libvlc_exception_t ex;
323 mediacontrol_exception_init( exception );
324 libvlc_exception_init( &ex );
326 libvlc_set_fullscreen( self->p_media_player, b_fullscreen, &ex );
327 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );