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" );
90 vlc_mutex_lock (&lock);
91 mutex_cleanup_push (&lock); // release the mutex in case of cancellation
94 vlc_cond_wait (&wait, &lock);
96 --- foobar is now true, do something about it here --
98 vlc_cleanup_run (); // release the mutex
101 snprintf( path, 255, "object:%p", p_snapshot );
102 var_SetString( p_vout, "snapshot-path", path );
103 var_SetString( p_vout, "snapshot-format", "png" );
105 vlc_mutex_init( &p_snapshot->p_mutex );
106 vlc_cond_init( &p_snapshot->p_condvar );
108 vlc_mutex_lock( &p_snapshot->p_mutex );
109 mutex_cleanup_push( &p_snapshot->p_mutex );
111 /* Use p_snapshot address as sentinel against spurious vlc_object_wait wakeups.
113 If a legitimate wakeup occurs, then p_snapshot->p_data will hold either
114 NULL (in case of error) or a pointer to valid data. */
115 p_snapshot->p_data = ( char* )p_snapshot;
117 vout_Control( p_vout, VOUT_SNAPSHOT );
118 while ( p_snapshot->p_data == ( char* )p_snapshot )
120 vlc_cond_wait( &p_snapshot->p_condvar, &p_snapshot->p_mutex );
124 vlc_object_release( p_vout );
126 vlc_mutex_unlock( &p_snapshot->p_mutex );
127 vlc_cond_destroy( &p_snapshot->p_condvar );
128 vlc_mutex_destroy( &p_snapshot->p_mutex );
130 if( p_snapshot->p_data )
132 /* Note: p_snapshot->p_data is directly used, not copied. Thus
133 do not free it here. */
134 p_pic = private_mediacontrol_createRGBPicture( p_snapshot->i_width,
135 p_snapshot->i_height,
136 VLC_FOURCC( 'p','n','g',' ' ),
139 p_snapshot->i_datasize );
143 RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
148 RAISE_NULL( mediacontrol_InternalException, "Snapshot exception" );
154 int mediacontrol_showtext( vout_thread_t *p_vout, int i_channel,
155 const char *psz_string, text_style_t *p_style,
156 int i_flags, int i_hmargin, int i_vmargin,
157 mtime_t i_start, mtime_t i_stop )
159 return osd_ShowTextAbsolute( p_vout->p_spu, i_channel,
161 i_flags, i_hmargin, i_vmargin,
167 mediacontrol_display_text( mediacontrol_Instance *self,
168 const char * message,
169 const mediacontrol_Position * begin,
170 const mediacontrol_Position * end,
171 mediacontrol_Exception *exception )
173 vout_thread_t *p_vout = NULL;
174 input_thread_t *p_input;
175 libvlc_exception_t ex;
177 libvlc_exception_init( &ex );
178 mediacontrol_exception_init( exception );
182 RAISE_VOID( mediacontrol_InternalException, "Empty text" );
185 p_input = libvlc_get_input_thread( self->p_media_player, &ex );
188 RAISE_VOID( mediacontrol_InternalException, "No input" );
190 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
193 RAISE_VOID( mediacontrol_InternalException, "No video output" );
196 if( begin->origin == mediacontrol_RelativePosition &&
198 end->origin == mediacontrol_RelativePosition )
200 mtime_t i_duration = 0;
201 mtime_t i_now = mdate();
203 i_duration = 1000 * private_mediacontrol_unit_convert(
204 self->p_media_player,
206 mediacontrol_MediaTime,
209 mediacontrol_showtext( p_vout, DEFAULT_CHAN, message, NULL,
210 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
211 i_now, i_now + i_duration );
215 mtime_t i_debut, i_fin, i_now;
218 /* i_now = input_ClockGetTS( p_input, NULL, 0 ); */
221 i_debut = private_mediacontrol_position2microsecond( self->p_media_player,
222 ( mediacontrol_Position* ) begin );
225 i_fin = private_mediacontrol_position2microsecond( self->p_media_player,
226 ( mediacontrol_Position * ) end );
229 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN, message, NULL,
230 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
234 vlc_object_release( p_vout );
238 mediacontrol_sound_get_volume( mediacontrol_Instance *self,
239 mediacontrol_Exception *exception )
241 libvlc_exception_t ex;
244 mediacontrol_exception_init( exception );
245 libvlc_exception_init( &ex );
247 i_ret = libvlc_audio_get_volume( self->p_instance, &ex );
248 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
249 /* FIXME: Normalize in [0..100] */
250 return (unsigned short)i_ret;
254 mediacontrol_sound_set_volume( mediacontrol_Instance *self,
255 const unsigned short volume,
256 mediacontrol_Exception *exception )
258 /* FIXME: Normalize in [0..100] */
259 libvlc_exception_t ex;
261 mediacontrol_exception_init( exception );
262 libvlc_exception_init( &ex );
264 libvlc_audio_set_volume( self->p_instance, volume, &ex );
265 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
268 int mediacontrol_set_visual( mediacontrol_Instance *self,
269 WINDOWHANDLE visual_id,
270 mediacontrol_Exception *exception )
272 libvlc_exception_t ex;
274 mediacontrol_exception_init( exception );
275 libvlc_exception_init( &ex );
277 libvlc_media_player_set_drawable( self->p_media_player, (libvlc_drawable_t)visual_id, &ex );
278 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
283 mediacontrol_get_rate( mediacontrol_Instance *self,
284 mediacontrol_Exception *exception )
286 libvlc_exception_t ex;
289 mediacontrol_exception_init( exception );
290 libvlc_exception_init( &ex );
292 i_ret = libvlc_media_player_get_rate( self->p_media_player, &ex );
293 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
299 mediacontrol_set_rate( mediacontrol_Instance *self,
301 mediacontrol_Exception *exception )
303 libvlc_exception_t ex;
305 mediacontrol_exception_init( exception );
306 libvlc_exception_init( &ex );
308 libvlc_media_player_set_rate( self->p_media_player, rate * 10, &ex );
309 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
313 mediacontrol_get_fullscreen( mediacontrol_Instance *self,
314 mediacontrol_Exception *exception )
316 libvlc_exception_t ex;
319 mediacontrol_exception_init( exception );
320 libvlc_exception_init( &ex );
322 i_ret = libvlc_get_fullscreen( self->p_media_player, &ex );
323 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
329 mediacontrol_set_fullscreen( mediacontrol_Instance *self,
330 const int b_fullscreen,
331 mediacontrol_Exception *exception )
333 libvlc_exception_t ex;
335 mediacontrol_exception_init( exception );
336 libvlc_exception_init( &ex );
338 libvlc_set_fullscreen( self->p_media_player, b_fullscreen, &ex );
339 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );