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"
29 #include <vlc/mediacontrol.h>
30 #include <vlc/libvlc.h>
32 #include <vlc_playlist.h>
39 #include <stdlib.h> /* malloc(), free() */
42 #include <errno.h> /* ENOMEM */
49 #ifdef HAVE_SYS_TIME_H
50 # include <sys/time.h>
52 #ifdef HAVE_SYS_TYPES_H
53 # include <sys/types.h>
56 mediacontrol_RGBPicture *
57 mediacontrol_snapshot( mediacontrol_Instance *self,
58 const mediacontrol_Position * a_position,
59 mediacontrol_Exception *exception )
61 vlc_object_t* p_cache;
62 vout_thread_t* p_vout;
63 mediacontrol_RGBPicture *p_pic = NULL;
65 snapshot_t *p_snapshot;
67 mediacontrol_exception_init( exception );
69 p_vout = vlc_object_find( self->p_playlist, VLC_OBJECT_VOUT, FIND_CHILD );
72 RAISE_NULL( mediacontrol_InternalException, "No video output" );
74 p_cache = vlc_object_create( self->p_playlist, VLC_OBJECT_GENERIC );
77 vlc_object_release( p_vout );
78 RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
80 snprintf( path, 255, "object:%d", p_cache->i_object_id );
81 var_SetString( p_vout, "snapshot-path", path );
82 var_SetString( p_vout, "snapshot-format", "png" );
84 vlc_object_lock( p_cache );
85 vout_Control( p_vout, VOUT_SNAPSHOT );
86 vlc_object_wait( p_cache );
87 vlc_object_release( p_vout );
89 p_snapshot = ( snapshot_t* ) p_cache->p_private;
90 vlc_object_unlock( p_cache );
91 vlc_object_release( p_cache );
95 p_pic = private_mediacontrol_createRGBPicture( p_snapshot->i_width,
97 VLC_FOURCC( 'p','n','g',' ' ),
100 p_snapshot->i_datasize );
103 free( p_snapshot->p_data );
105 RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
110 RAISE_NULL( mediacontrol_InternalException, "Snapshot exception" );
115 mediacontrol_RGBPicture **
116 mediacontrol_all_snapshots( mediacontrol_Instance *self,
117 mediacontrol_Exception *exception )
119 mediacontrol_exception_init( exception );
121 RAISE_NULL( mediacontrol_InternalException, "unsupported method" );
125 int mediacontrol_showtext( vout_thread_t *p_vout, int i_channel,
126 char *psz_string, text_style_t *p_style,
127 int i_flags, int i_hmargin, int i_vmargin,
128 mtime_t i_start, mtime_t i_stop )
133 if( !psz_string ) return VLC_EGENERIC;
135 p_spu = spu_CreateSubpicture( p_vout->p_spu );
136 if( !p_spu ) return VLC_EGENERIC;
138 /* Create a new subpicture region */
139 memset( &fmt, 0, sizeof(video_format_t) );
140 fmt.i_chroma = VLC_FOURCC('T','E','X','T');
142 fmt.i_width = fmt.i_height = 0;
143 fmt.i_x_offset = fmt.i_y_offset = 0;
144 p_spu->p_region = p_spu->pf_create_region( VLC_OBJECT(p_vout), &fmt );
145 if( !p_spu->p_region )
147 msg_Err( p_vout, "cannot allocate SPU region" );
148 spu_DestroySubpicture( p_vout->p_spu, p_spu );
152 p_spu->p_region->psz_text = strdup( psz_string );
153 p_spu->p_region->i_align = i_flags & SUBPICTURE_ALIGN_MASK;
154 p_spu->i_start = i_start;
155 p_spu->i_stop = i_stop;
156 p_spu->b_ephemer = false;
157 p_spu->b_absolute = false;
159 p_spu->i_x = i_hmargin;
160 p_spu->i_y = i_vmargin;
161 p_spu->i_flags = i_flags & ~SUBPICTURE_ALIGN_MASK;
162 p_spu->i_channel = i_channel;
164 spu_DisplaySubpicture( p_vout->p_spu, p_spu );
171 mediacontrol_display_text( mediacontrol_Instance *self,
172 const char * message,
173 const mediacontrol_Position * begin,
174 const mediacontrol_Position * end,
175 mediacontrol_Exception *exception )
177 input_thread_t *p_input = NULL;
178 vout_thread_t *p_vout = NULL;
181 psz_message = strdup( message );
184 RAISE_VOID( mediacontrol_InternalException, "no more memory" );
187 p_vout = vlc_object_find( self->p_playlist, VLC_OBJECT_VOUT, FIND_CHILD );
190 RAISE_VOID( mediacontrol_InternalException, "no video output" );
193 if( begin->origin == mediacontrol_RelativePosition &&
195 end->origin == mediacontrol_RelativePosition )
197 mtime_t i_duration = 0;
198 mtime_t i_now = mdate();
200 i_duration = 1000 * private_mediacontrol_unit_convert(
201 self->p_playlist->p_input,
203 mediacontrol_MediaTime,
206 mediacontrol_showtext( p_vout, DEFAULT_CHAN, psz_message, NULL,
207 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
208 i_now, i_now + i_duration );
212 mtime_t i_debut, i_fin, i_now;
214 p_input = self->p_playlist->p_input;
217 vlc_object_release( p_vout );
218 RAISE_VOID( mediacontrol_InternalException, "No input" );
222 /* i_now = input_ClockGetTS( p_input, NULL, 0 ); */
225 i_debut = private_mediacontrol_position2microsecond( p_input,
226 ( mediacontrol_Position* ) begin );
229 i_fin = private_mediacontrol_position2microsecond( p_input,
230 ( mediacontrol_Position * ) end );
233 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN, psz_message, NULL,
234 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
238 vlc_object_release( p_vout );
242 mediacontrol_sound_get_volume( mediacontrol_Instance *self,
243 mediacontrol_Exception *exception )
245 libvlc_exception_t ex;
248 mediacontrol_exception_init( exception );
249 libvlc_exception_init( &ex );
251 i_ret = libvlc_audio_get_volume( self->p_instance, &ex );
252 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
253 /* FIXME: Normalize in [0..100] */
254 return (unsigned short)i_ret;
258 mediacontrol_sound_set_volume( mediacontrol_Instance *self,
259 const unsigned short volume,
260 mediacontrol_Exception *exception )
262 /* FIXME: Normalize in [0..100] */
263 libvlc_exception_t ex;
265 mediacontrol_exception_init( exception );
266 libvlc_exception_init( &ex );
268 libvlc_audio_set_volume( self->p_instance, volume, &ex );
269 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
272 bool mediacontrol_set_visual( mediacontrol_Instance *self,
273 WINDOWHANDLE visual_id,
274 mediacontrol_Exception *exception )
276 libvlc_exception_t ex;
278 mediacontrol_exception_init( exception );
279 libvlc_exception_init( &ex );
281 libvlc_video_set_parent( self->p_instance, visual_id, &ex );
282 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
287 mediacontrol_get_rate( mediacontrol_Instance *self,
288 mediacontrol_Exception *exception )
290 libvlc_exception_t ex;
291 libvlc_media_player_t* p_mi;
294 mediacontrol_exception_init( exception );
295 libvlc_exception_init( &ex );
297 p_mi = libvlc_playlist_get_media_player( self->p_instance, &ex );
298 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
300 i_ret = libvlc_media_player_get_rate( p_mi, &ex );
301 libvlc_media_player_release( p_mi );
302 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
308 mediacontrol_set_rate( mediacontrol_Instance *self,
310 mediacontrol_Exception *exception )
312 libvlc_exception_t ex;
313 libvlc_media_player_t* p_mi;
315 mediacontrol_exception_init( exception );
316 libvlc_exception_init( &ex );
318 p_mi = libvlc_playlist_get_media_player( self->p_instance, &ex );
319 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
321 libvlc_media_player_set_rate( p_mi, rate * 10, &ex );
322 libvlc_media_player_release( p_mi );
323 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
327 mediacontrol_get_fullscreen( mediacontrol_Instance *self,
328 mediacontrol_Exception *exception )
330 libvlc_exception_t ex;
331 libvlc_media_player_t* p_mi;
334 mediacontrol_exception_init( exception );
335 libvlc_exception_init( &ex );
337 p_mi = libvlc_playlist_get_media_player( self->p_instance, &ex );
338 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
340 i_ret = libvlc_get_fullscreen( p_mi, &ex );
341 libvlc_media_player_release( p_mi );
342 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
348 mediacontrol_set_fullscreen( mediacontrol_Instance *self,
349 const int b_fullscreen,
350 mediacontrol_Exception *exception )
352 libvlc_exception_t ex;
353 libvlc_media_player_t* p_mi;
355 mediacontrol_exception_init( exception );
356 libvlc_exception_init( &ex );
358 p_mi = libvlc_playlist_get_media_player( self->p_instance, &ex );
359 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
361 libvlc_set_fullscreen( p_mi, b_fullscreen, &ex );
362 libvlc_media_player_release( p_mi );
363 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );