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 )
58 vlc_object_t* p_cache;
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 );
69 p_input = libvlc_get_input_thread( self->p_media_player, &ex );
72 RAISE_NULL( mediacontrol_InternalException, "No input" );
74 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
77 RAISE_NULL( mediacontrol_InternalException, "No video output" );
79 p_cache = vlc_object_create( p_input, sizeof( vlc_object_t ) );
82 vlc_object_release( p_vout );
83 vlc_object_release( p_input );
84 RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
86 snprintf( path, 255, "object:%d", p_cache->i_object_id );
87 var_SetString( p_vout, "snapshot-path", path );
88 var_SetString( p_vout, "snapshot-format", "png" );
90 vlc_object_lock( p_cache );
91 vout_Control( p_vout, VOUT_SNAPSHOT );
92 vlc_object_wait( p_cache );
93 vlc_object_release( p_vout );
95 p_snapshot = ( snapshot_t* ) p_cache->p_private;
96 vlc_object_unlock( p_cache );
97 vlc_object_release( p_cache );
98 vlc_object_release( p_input );
102 p_pic = private_mediacontrol_createRGBPicture( p_snapshot->i_width,
103 p_snapshot->i_height,
104 VLC_FOURCC( 'p','n','g',' ' ),
107 p_snapshot->i_datasize );
110 free( p_snapshot->p_data );
112 RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
117 RAISE_NULL( mediacontrol_InternalException, "Snapshot exception" );
123 int mediacontrol_showtext( vout_thread_t *p_vout, int i_channel,
124 char *psz_string, text_style_t *p_style,
125 int i_flags, int i_hmargin, int i_vmargin,
126 mtime_t i_start, mtime_t i_stop )
131 if( !psz_string ) return VLC_EGENERIC;
133 p_spu = spu_CreateSubpicture( p_vout->p_spu );
134 if( !p_spu ) return VLC_EGENERIC;
136 /* Create a new subpicture region */
137 memset( &fmt, 0, sizeof(video_format_t) );
138 fmt.i_chroma = VLC_FOURCC('T','E','X','T');
140 fmt.i_width = fmt.i_height = 0;
141 fmt.i_x_offset = fmt.i_y_offset = 0;
142 p_spu->p_region = p_spu->pf_create_region( VLC_OBJECT(p_vout), &fmt );
143 if( !p_spu->p_region )
145 msg_Err( p_vout, "cannot allocate SPU region" );
146 spu_DestroySubpicture( p_vout->p_spu, p_spu );
150 p_spu->p_region->psz_text = strdup( psz_string );
151 p_spu->p_region->i_align = i_flags & SUBPICTURE_ALIGN_MASK;
152 p_spu->p_region->p_style = p_style;
153 p_spu->i_start = i_start;
154 p_spu->i_stop = i_stop;
155 p_spu->b_ephemer = false;
156 p_spu->b_absolute = false;
158 p_spu->i_x = i_hmargin;
159 p_spu->i_y = i_vmargin;
160 p_spu->i_flags = i_flags & ~SUBPICTURE_ALIGN_MASK;
161 p_spu->i_channel = i_channel;
163 spu_DisplaySubpicture( p_vout->p_spu, p_spu );
170 mediacontrol_display_text( mediacontrol_Instance *self,
171 const char * message,
172 const mediacontrol_Position * begin,
173 const mediacontrol_Position * end,
174 mediacontrol_Exception *exception )
176 vout_thread_t *p_vout = NULL;
178 input_thread_t *p_input;
179 libvlc_exception_t ex;
181 libvlc_exception_init( &ex );
182 mediacontrol_exception_init( exception );
184 p_input = libvlc_get_input_thread( self->p_media_player, &ex );
187 RAISE_VOID( mediacontrol_InternalException, "No input" );
189 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
192 RAISE_VOID( mediacontrol_InternalException, "No video output" );
195 psz_message = strdup( message );
198 RAISE_VOID( mediacontrol_InternalException, "no more memory" );
201 if( begin->origin == mediacontrol_RelativePosition &&
203 end->origin == mediacontrol_RelativePosition )
205 mtime_t i_duration = 0;
206 mtime_t i_now = mdate();
208 i_duration = 1000 * private_mediacontrol_unit_convert(
209 self->p_media_player,
211 mediacontrol_MediaTime,
214 mediacontrol_showtext( p_vout, DEFAULT_CHAN, psz_message, NULL,
215 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
216 i_now, i_now + i_duration );
220 mtime_t i_debut, i_fin, i_now;
223 /* i_now = input_ClockGetTS( p_input, NULL, 0 ); */
226 i_debut = private_mediacontrol_position2microsecond( self->p_media_player,
227 ( mediacontrol_Position* ) begin );
230 i_fin = private_mediacontrol_position2microsecond( self->p_media_player,
231 ( mediacontrol_Position * ) end );
234 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN, psz_message, NULL,
235 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
239 vlc_object_release( p_vout );
243 mediacontrol_sound_get_volume( mediacontrol_Instance *self,
244 mediacontrol_Exception *exception )
246 libvlc_exception_t ex;
249 mediacontrol_exception_init( exception );
250 libvlc_exception_init( &ex );
252 i_ret = libvlc_audio_get_volume( self->p_instance, &ex );
253 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
254 /* FIXME: Normalize in [0..100] */
255 return (unsigned short)i_ret;
259 mediacontrol_sound_set_volume( mediacontrol_Instance *self,
260 const unsigned short volume,
261 mediacontrol_Exception *exception )
263 /* FIXME: Normalize in [0..100] */
264 libvlc_exception_t ex;
266 mediacontrol_exception_init( exception );
267 libvlc_exception_init( &ex );
269 libvlc_audio_set_volume( self->p_instance, volume, &ex );
270 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
273 int mediacontrol_set_visual( mediacontrol_Instance *self,
274 WINDOWHANDLE visual_id,
275 mediacontrol_Exception *exception )
277 libvlc_exception_t ex;
279 mediacontrol_exception_init( exception );
280 libvlc_exception_init( &ex );
282 libvlc_media_player_set_drawable( self->p_media_player, (libvlc_drawable_t)visual_id, &ex );
283 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
288 mediacontrol_get_rate( mediacontrol_Instance *self,
289 mediacontrol_Exception *exception )
291 libvlc_exception_t ex;
294 mediacontrol_exception_init( exception );
295 libvlc_exception_init( &ex );
297 i_ret = libvlc_media_player_get_rate( self->p_media_player, &ex );
298 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
304 mediacontrol_set_rate( mediacontrol_Instance *self,
306 mediacontrol_Exception *exception )
308 libvlc_exception_t ex;
310 mediacontrol_exception_init( exception );
311 libvlc_exception_init( &ex );
313 libvlc_media_player_set_rate( self->p_media_player, rate * 10, &ex );
314 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
318 mediacontrol_get_fullscreen( mediacontrol_Instance *self,
319 mediacontrol_Exception *exception )
321 libvlc_exception_t ex;
324 mediacontrol_exception_init( exception );
325 libvlc_exception_init( &ex );
327 i_ret = libvlc_get_fullscreen( self->p_media_player, &ex );
328 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
334 mediacontrol_set_fullscreen( mediacontrol_Instance *self,
335 const int b_fullscreen,
336 mediacontrol_Exception *exception )
338 libvlc_exception_t ex;
340 mediacontrol_exception_init( exception );
341 libvlc_exception_init( &ex );
343 libvlc_set_fullscreen( self->p_media_player, b_fullscreen, &ex );
344 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );