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 *****************************************************************************/
24 #include "mediacontrol_internal.h"
26 #include <vlc/mediacontrol.h>
27 #include <vlc/libvlc.h>
29 #include <vlc_playlist.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 )
58 vlc_object_t* p_cache;
59 vout_thread_t* p_vout;
60 mediacontrol_RGBPicture *p_pic = NULL;
62 snapshot_t *p_snapshot;
64 mediacontrol_exception_init( exception );
66 p_vout = vlc_object_find( self->p_playlist, VLC_OBJECT_VOUT, FIND_CHILD );
69 RAISE_NULL( mediacontrol_InternalException, "No video output" );
71 p_cache = vlc_object_create( self->p_playlist, VLC_OBJECT_GENERIC );
74 vlc_object_release( p_vout );
75 RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
77 snprintf( path, 255, "object:%d", p_cache->i_object_id );
78 var_SetString( p_vout, "snapshot-path", path );
79 var_SetString( p_vout, "snapshot-format", "png" );
81 vlc_mutex_lock( &p_cache->object_lock );
82 vout_Control( p_vout, VOUT_SNAPSHOT );
83 vlc_cond_wait( &p_cache->object_wait, &p_cache->object_lock );
84 vlc_object_release( p_vout );
86 p_snapshot = ( snapshot_t* ) p_cache->p_private;
87 vlc_object_destroy( p_cache );
91 p_pic = _mediacontrol_createRGBPicture( p_snapshot->i_width,
93 VLC_FOURCC( 'p','n','g',' ' ),
96 p_snapshot->i_datasize );
99 free( p_snapshot->p_data );
101 RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
106 RAISE_NULL( mediacontrol_InternalException, "Snapshot exception" );
111 mediacontrol_RGBPicture **
112 mediacontrol_all_snapshots( mediacontrol_Instance *self,
113 mediacontrol_Exception *exception )
115 mediacontrol_exception_init( exception );
117 RAISE_NULL( mediacontrol_InternalException, "unsupported method" );
121 int mediacontrol_showtext( vout_thread_t *p_vout, int i_channel,
122 char *psz_string, text_style_t *p_style,
123 int i_flags, int i_hmargin, int i_vmargin,
124 mtime_t i_start, mtime_t i_stop )
129 if( !psz_string ) return VLC_EGENERIC;
131 p_spu = spu_CreateSubpicture( p_vout->p_spu );
132 if( !p_spu ) return VLC_EGENERIC;
134 /* Create a new subpicture region */
135 memset( &fmt, 0, sizeof(video_format_t) );
136 fmt.i_chroma = VLC_FOURCC('T','E','X','T');
138 fmt.i_width = fmt.i_height = 0;
139 fmt.i_x_offset = fmt.i_y_offset = 0;
140 p_spu->p_region = p_spu->pf_create_region( VLC_OBJECT(p_vout), &fmt );
141 if( !p_spu->p_region )
143 msg_Err( p_vout, "cannot allocate SPU region" );
144 spu_DestroySubpicture( p_vout->p_spu, p_spu );
148 p_spu->p_region->psz_text = strdup( psz_string );
149 p_spu->i_start = i_start;
150 p_spu->i_stop = i_stop;
151 p_spu->b_ephemer = VLC_FALSE;
152 p_spu->b_absolute = VLC_FALSE;
154 p_spu->i_x = i_hmargin;
155 p_spu->i_y = i_vmargin;
156 p_spu->i_flags = i_flags;
157 p_spu->i_channel = i_channel;
159 spu_DisplaySubpicture( p_vout->p_spu, p_spu );
166 mediacontrol_display_text( mediacontrol_Instance *self,
167 const char * message,
168 const mediacontrol_Position * begin,
169 const mediacontrol_Position * end,
170 mediacontrol_Exception *exception )
172 input_thread_t *p_input = NULL;
173 vout_thread_t *p_vout = NULL;
176 psz_message = strdup( message );
179 RAISE_VOID( mediacontrol_InternalException, "no more memory" );
182 p_vout = vlc_object_find( self->p_playlist, VLC_OBJECT_VOUT, FIND_CHILD );
185 RAISE_VOID( mediacontrol_InternalException, "no video output" );
188 if( begin->origin == mediacontrol_RelativePosition &&
190 end->origin == mediacontrol_RelativePosition )
192 mtime_t i_duration = 0;
193 mtime_t i_now = mdate();
195 i_duration = 1000 * mediacontrol_unit_convert(
196 self->p_playlist->p_input,
198 mediacontrol_MediaTime,
201 mediacontrol_showtext( p_vout, DEFAULT_CHAN, psz_message, NULL,
202 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
203 i_now, i_now + i_duration );
207 mtime_t i_debut, i_fin, i_now;
209 p_input = self->p_playlist->p_input;
212 vlc_object_release( p_vout );
213 RAISE_VOID( mediacontrol_InternalException, "No input" );
217 /* i_now = input_ClockGetTS( p_input, NULL, 0 ); */
220 i_debut = mediacontrol_position2microsecond( p_input,
221 ( mediacontrol_Position* ) begin );
224 i_fin = mediacontrol_position2microsecond( p_input,
225 ( mediacontrol_Position * ) end );
228 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN, psz_message, NULL,
229 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
233 vlc_object_release( p_vout );
237 mediacontrol_sound_get_volume( mediacontrol_Instance *self,
238 mediacontrol_Exception *exception )
240 libvlc_exception_t ex;
243 mediacontrol_exception_init( exception );
244 libvlc_exception_init( &ex );
246 i_ret = libvlc_audio_get_volume( self->p_instance, &ex );
247 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
248 /* FIXME: Normalize in [0..100] */
249 return (unsigned short)i_ret;
253 mediacontrol_sound_set_volume( mediacontrol_Instance *self,
254 const unsigned short volume,
255 mediacontrol_Exception *exception )
257 /* FIXME: Normalize in [0..100] */
258 libvlc_exception_t ex;
260 mediacontrol_exception_init( exception );
261 libvlc_exception_init( &ex );
263 libvlc_audio_set_volume( self->p_instance, volume, &ex );
264 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
267 vlc_bool_t mediacontrol_set_visual( mediacontrol_Instance *self,
268 WINDOWHANDLE visual_id,
269 mediacontrol_Exception *exception )
271 libvlc_exception_t ex;
273 mediacontrol_exception_init( exception );
274 libvlc_exception_init( &ex );
276 libvlc_video_set_parent( self->p_instance, visual_id, &ex );
277 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
282 mediacontrol_get_rate( mediacontrol_Instance *self,
283 mediacontrol_Exception *exception )
285 libvlc_exception_t ex;
286 libvlc_media_instance_t* p_mi;
289 mediacontrol_exception_init( exception );
290 libvlc_exception_init( &ex );
292 p_mi = libvlc_playlist_get_media_instance( self->p_instance, &ex );
293 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
295 i_ret = libvlc_media_instance_get_rate( p_mi, &ex );
296 libvlc_media_instance_destroy_and_detach( p_mi );
297 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
303 mediacontrol_set_rate( mediacontrol_Instance *self,
305 mediacontrol_Exception *exception )
307 libvlc_exception_t ex;
308 libvlc_media_instance_t* p_mi;
310 mediacontrol_exception_init( exception );
311 libvlc_exception_init( &ex );
313 p_mi = libvlc_playlist_get_media_instance( self->p_instance, &ex );
314 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
316 libvlc_media_instance_set_rate( p_mi, rate * 10, &ex );
317 libvlc_media_instance_destroy_and_detach( p_mi );
318 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
322 mediacontrol_get_fullscreen( mediacontrol_Instance *self,
323 mediacontrol_Exception *exception )
325 libvlc_exception_t ex;
326 libvlc_media_instance_t* p_mi;
329 mediacontrol_exception_init( exception );
330 libvlc_exception_init( &ex );
332 p_mi = libvlc_playlist_get_media_instance( self->p_instance, &ex );
333 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
335 i_ret = libvlc_get_fullscreen( p_mi, &ex );
336 libvlc_media_instance_destroy_and_detach( p_mi );
337 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
343 mediacontrol_set_fullscreen( mediacontrol_Instance *self,
344 const int b_fullscreen,
345 mediacontrol_Exception *exception )
347 libvlc_exception_t ex;
348 libvlc_media_instance_t* p_mi;
350 mediacontrol_exception_init( exception );
351 libvlc_exception_init( &ex );
353 p_mi = libvlc_playlist_get_media_instance( self->p_instance, &ex );
354 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
356 libvlc_set_fullscreen( p_mi, b_fullscreen, &ex );
357 libvlc_media_instance_destroy_and_detach( p_mi );
358 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );