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_mutex_unlock( &p_cache->object_lock );
88 vlc_object_destroy( p_cache );
92 p_pic = private_mediacontrol_createRGBPicture( p_snapshot->i_width,
94 VLC_FOURCC( 'p','n','g',' ' ),
97 p_snapshot->i_datasize );
100 free( p_snapshot->p_data );
102 RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
107 RAISE_NULL( mediacontrol_InternalException, "Snapshot exception" );
112 mediacontrol_RGBPicture **
113 mediacontrol_all_snapshots( mediacontrol_Instance *self,
114 mediacontrol_Exception *exception )
116 mediacontrol_exception_init( exception );
118 RAISE_NULL( mediacontrol_InternalException, "unsupported method" );
122 int mediacontrol_showtext( vout_thread_t *p_vout, int i_channel,
123 char *psz_string, text_style_t *p_style,
124 int i_flags, int i_hmargin, int i_vmargin,
125 mtime_t i_start, mtime_t i_stop )
130 if( !psz_string ) return VLC_EGENERIC;
132 p_spu = spu_CreateSubpicture( p_vout->p_spu );
133 if( !p_spu ) return VLC_EGENERIC;
135 /* Create a new subpicture region */
136 memset( &fmt, 0, sizeof(video_format_t) );
137 fmt.i_chroma = VLC_FOURCC('T','E','X','T');
139 fmt.i_width = fmt.i_height = 0;
140 fmt.i_x_offset = fmt.i_y_offset = 0;
141 p_spu->p_region = p_spu->pf_create_region( VLC_OBJECT(p_vout), &fmt );
142 if( !p_spu->p_region )
144 msg_Err( p_vout, "cannot allocate SPU region" );
145 spu_DestroySubpicture( p_vout->p_spu, p_spu );
149 p_spu->p_region->psz_text = strdup( psz_string );
150 p_spu->p_region->i_align = i_flags & SUBPICTURE_ALIGN_MASK;
151 p_spu->i_start = i_start;
152 p_spu->i_stop = i_stop;
153 p_spu->b_ephemer = VLC_FALSE;
154 p_spu->b_absolute = VLC_FALSE;
156 p_spu->i_x = i_hmargin;
157 p_spu->i_y = i_vmargin;
158 p_spu->i_flags = i_flags & ~SUBPICTURE_ALIGN_MASK;
159 p_spu->i_channel = i_channel;
161 spu_DisplaySubpicture( p_vout->p_spu, p_spu );
168 mediacontrol_display_text( mediacontrol_Instance *self,
169 const char * message,
170 const mediacontrol_Position * begin,
171 const mediacontrol_Position * end,
172 mediacontrol_Exception *exception )
174 input_thread_t *p_input = NULL;
175 vout_thread_t *p_vout = NULL;
178 psz_message = strdup( message );
181 RAISE_VOID( mediacontrol_InternalException, "no more memory" );
184 p_vout = vlc_object_find( self->p_playlist, VLC_OBJECT_VOUT, FIND_CHILD );
187 RAISE_VOID( mediacontrol_InternalException, "no video output" );
190 if( begin->origin == mediacontrol_RelativePosition &&
192 end->origin == mediacontrol_RelativePosition )
194 mtime_t i_duration = 0;
195 mtime_t i_now = mdate();
197 i_duration = 1000 * private_mediacontrol_unit_convert(
198 self->p_playlist->p_input,
200 mediacontrol_MediaTime,
203 mediacontrol_showtext( p_vout, DEFAULT_CHAN, psz_message, NULL,
204 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
205 i_now, i_now + i_duration );
209 mtime_t i_debut, i_fin, i_now;
211 p_input = self->p_playlist->p_input;
214 vlc_object_release( p_vout );
215 RAISE_VOID( mediacontrol_InternalException, "No input" );
219 /* i_now = input_ClockGetTS( p_input, NULL, 0 ); */
222 i_debut = private_mediacontrol_position2microsecond( p_input,
223 ( mediacontrol_Position* ) begin );
226 i_fin = private_mediacontrol_position2microsecond( p_input,
227 ( mediacontrol_Position * ) end );
230 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN, psz_message, NULL,
231 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
235 vlc_object_release( p_vout );
239 mediacontrol_sound_get_volume( mediacontrol_Instance *self,
240 mediacontrol_Exception *exception )
242 libvlc_exception_t ex;
245 mediacontrol_exception_init( exception );
246 libvlc_exception_init( &ex );
248 i_ret = libvlc_audio_get_volume( self->p_instance, &ex );
249 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
250 /* FIXME: Normalize in [0..100] */
251 return (unsigned short)i_ret;
255 mediacontrol_sound_set_volume( mediacontrol_Instance *self,
256 const unsigned short volume,
257 mediacontrol_Exception *exception )
259 /* FIXME: Normalize in [0..100] */
260 libvlc_exception_t ex;
262 mediacontrol_exception_init( exception );
263 libvlc_exception_init( &ex );
265 libvlc_audio_set_volume( self->p_instance, volume, &ex );
266 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
269 vlc_bool_t mediacontrol_set_visual( mediacontrol_Instance *self,
270 WINDOWHANDLE visual_id,
271 mediacontrol_Exception *exception )
273 libvlc_exception_t ex;
275 mediacontrol_exception_init( exception );
276 libvlc_exception_init( &ex );
278 libvlc_video_set_parent( self->p_instance, visual_id, &ex );
279 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
284 mediacontrol_get_rate( mediacontrol_Instance *self,
285 mediacontrol_Exception *exception )
287 libvlc_exception_t ex;
288 libvlc_media_instance_t* p_mi;
291 mediacontrol_exception_init( exception );
292 libvlc_exception_init( &ex );
294 p_mi = libvlc_playlist_get_media_instance( self->p_instance, &ex );
295 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
297 i_ret = libvlc_media_instance_get_rate( p_mi, &ex );
298 libvlc_media_instance_release( p_mi );
299 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
305 mediacontrol_set_rate( mediacontrol_Instance *self,
307 mediacontrol_Exception *exception )
309 libvlc_exception_t ex;
310 libvlc_media_instance_t* p_mi;
312 mediacontrol_exception_init( exception );
313 libvlc_exception_init( &ex );
315 p_mi = libvlc_playlist_get_media_instance( self->p_instance, &ex );
316 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
318 libvlc_media_instance_set_rate( p_mi, rate * 10, &ex );
319 libvlc_media_instance_release( p_mi );
320 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
324 mediacontrol_get_fullscreen( mediacontrol_Instance *self,
325 mediacontrol_Exception *exception )
327 libvlc_exception_t ex;
328 libvlc_media_instance_t* p_mi;
331 mediacontrol_exception_init( exception );
332 libvlc_exception_init( &ex );
334 p_mi = libvlc_playlist_get_media_instance( self->p_instance, &ex );
335 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
337 i_ret = libvlc_get_fullscreen( p_mi, &ex );
338 libvlc_media_instance_release( p_mi );
339 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
345 mediacontrol_set_fullscreen( mediacontrol_Instance *self,
346 const int b_fullscreen,
347 mediacontrol_Exception *exception )
349 libvlc_exception_t ex;
350 libvlc_media_instance_t* p_mi;
352 mediacontrol_exception_init( exception );
353 libvlc_exception_init( &ex );
355 p_mi = libvlc_playlist_get_media_instance( self->p_instance, &ex );
356 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
358 libvlc_set_fullscreen( p_mi, b_fullscreen, &ex );
359 libvlc_media_instance_release( p_mi );
360 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );