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>
32 #include <vlc_demux.h>
38 #include <stdlib.h> /* malloc(), free() */
41 #include <errno.h> /* ENOMEM */
48 #ifdef HAVE_SYS_TIME_H
49 # include <sys/time.h>
51 #ifdef HAVE_SYS_TYPES_H
52 # include <sys/types.h>
55 mediacontrol_RGBPicture *
56 mediacontrol_snapshot( mediacontrol_Instance *self,
57 const mediacontrol_Position * a_position,
58 mediacontrol_Exception *exception )
60 vlc_object_t* p_cache;
61 vout_thread_t* p_vout;
62 mediacontrol_RGBPicture *p_pic = NULL;
64 snapshot_t *p_snapshot;
66 exception=mediacontrol_exception_init( exception );
68 p_vout = vlc_object_find( self->p_playlist, VLC_OBJECT_VOUT, FIND_CHILD );
71 RAISE_NULL( mediacontrol_InternalException, "No video output" );
73 p_cache = vlc_object_create( self->p_playlist, VLC_OBJECT_GENERIC );
76 vlc_object_release( p_vout );
77 RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
79 snprintf( path, 255, "object:%d", p_cache->i_object_id );
80 var_SetString( p_vout, "snapshot-path", path );
81 var_SetString( p_vout, "snapshot-format", "png" );
83 vlc_mutex_lock( &p_cache->object_lock );
84 vout_Control( p_vout, VOUT_SNAPSHOT );
85 vlc_cond_wait( &p_cache->object_wait, &p_cache->object_lock );
86 vlc_object_release( p_vout );
88 p_snapshot = ( snapshot_t* ) p_cache->p_private;
89 vlc_object_destroy( p_cache );
93 p_pic = _mediacontrol_createRGBPicture( p_snapshot->i_width,
95 VLC_FOURCC( 'p','n','g',' ' ),
98 p_snapshot->i_datasize );
101 free( p_snapshot->p_data );
103 RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
108 RAISE_NULL( mediacontrol_InternalException, "Snapshot exception" );
113 mediacontrol_RGBPicture **
114 mediacontrol_all_snapshots( mediacontrol_Instance *self,
115 mediacontrol_Exception *exception )
117 exception=mediacontrol_exception_init( exception );
119 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->i_start = i_start;
151 p_spu->i_stop = i_stop;
152 p_spu->b_ephemer = VLC_FALSE;
153 p_spu->b_absolute = VLC_FALSE;
155 p_spu->i_x = i_hmargin;
156 p_spu->i_y = i_vmargin;
157 p_spu->i_flags = i_flags;
158 p_spu->i_channel = i_channel;
160 spu_DisplaySubpicture( p_vout->p_spu, p_spu );
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 input_thread_t *p_input = NULL;
174 vout_thread_t *p_vout = NULL;
177 psz_message = strdup( message );
180 RAISE_VOID( mediacontrol_InternalException, "no more memory" );
183 p_vout = vlc_object_find( self->p_playlist, VLC_OBJECT_VOUT, FIND_CHILD );
186 RAISE_VOID( mediacontrol_InternalException, "no video output" );
189 if( begin->origin == mediacontrol_RelativePosition &&
191 end->origin == mediacontrol_RelativePosition )
193 mtime_t i_duration = 0;
194 mtime_t i_now = mdate();
196 i_duration = 1000 * mediacontrol_unit_convert(
197 self->p_playlist->p_input,
199 mediacontrol_MediaTime,
202 mediacontrol_showtext( p_vout, DEFAULT_CHAN, psz_message, NULL,
203 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
204 i_now, i_now + i_duration );
208 mtime_t i_debut, i_fin, i_now;
210 p_input = self->p_playlist->p_input;
213 vlc_object_release( p_vout );
214 RAISE_VOID( mediacontrol_InternalException, "No input" );
218 /* i_now = input_ClockGetTS( p_input, NULL, 0 ); */
221 i_debut = mediacontrol_position2microsecond( p_input,
222 ( mediacontrol_Position* ) begin );
225 i_fin = mediacontrol_position2microsecond( p_input,
226 ( mediacontrol_Position * ) end );
229 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN, psz_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 vlc_bool_t 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_video_set_parent( self->p_instance, 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;
287 libvlc_input_t* p_input;
290 mediacontrol_exception_init( exception );
291 libvlc_exception_init( &ex );
293 p_input = libvlc_playlist_get_input( self->p_instance, &ex );
294 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
296 i_ret = libvlc_input_get_rate( p_input, &ex );
297 libvlc_input_free( p_input );
298 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
304 mediacontrol_set_rate( mediacontrol_Instance *self,
306 mediacontrol_Exception *exception )
308 libvlc_exception_t ex;
309 libvlc_input_t* p_input;
311 mediacontrol_exception_init( exception );
312 libvlc_exception_init( &ex );
314 p_input = libvlc_playlist_get_input( self->p_instance, &ex );
315 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
317 libvlc_input_set_rate( p_input, rate * 10, &ex );
318 libvlc_input_free( p_input );
319 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
323 mediacontrol_get_fullscreen( mediacontrol_Instance *self,
324 mediacontrol_Exception *exception )
326 libvlc_exception_t ex;
327 libvlc_input_t* p_input;
330 mediacontrol_exception_init( exception );
331 libvlc_exception_init( &ex );
333 p_input = libvlc_playlist_get_input( self->p_instance, &ex );
334 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
336 i_ret = libvlc_get_fullscreen( p_input, &ex );
337 libvlc_input_free( p_input );
338 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
344 mediacontrol_set_fullscreen( mediacontrol_Instance *self,
345 const int b_fullscreen,
346 mediacontrol_Exception *exception )
348 libvlc_exception_t ex;
349 libvlc_input_t* p_input;
351 mediacontrol_exception_init( exception );
352 libvlc_exception_init( &ex );
354 p_input = libvlc_playlist_get_input( self->p_instance, &ex );
355 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
357 libvlc_set_fullscreen( p_input, b_fullscreen, &ex );
358 libvlc_input_free( p_input );
359 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );