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 )
59 vlc_object_t* p_cache;
60 vout_thread_t* p_vout;
61 input_thread_t *p_input;
62 mediacontrol_RGBPicture *p_pic = NULL;
64 snapshot_t *p_snapshot;
65 libvlc_exception_t ex;
67 libvlc_exception_init( &ex );
68 mediacontrol_exception_init( exception );
70 p_input = libvlc_get_input_thread( self->p_media_player, &ex );
73 RAISE_NULL( mediacontrol_InternalException, "No input" );
75 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
78 RAISE_NULL( mediacontrol_InternalException, "No video output" );
80 p_cache = vlc_object_create( p_input, sizeof( vlc_object_t ) );
83 vlc_object_release( p_vout );
84 vlc_object_release( p_input );
85 RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
87 snprintf( path, 255, "object:%ju", (uintmax_t)(uintptr_t)p_cache );
88 var_SetString( p_vout, "snapshot-path", path );
89 var_SetString( p_vout, "snapshot-format", "png" );
91 vlc_object_lock( p_cache );
92 vout_Control( p_vout, VOUT_SNAPSHOT );
93 vlc_object_wait( p_cache );
94 vlc_object_release( p_vout );
96 p_snapshot = ( snapshot_t* ) p_cache->p_private;
97 vlc_object_unlock( p_cache );
98 vlc_object_release( p_cache );
99 vlc_object_release( p_input );
103 p_pic = private_mediacontrol_createRGBPicture( p_snapshot->i_width,
104 p_snapshot->i_height,
105 VLC_FOURCC( 'p','n','g',' ' ),
108 p_snapshot->i_datasize );
111 free( p_snapshot->p_data );
113 RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
118 RAISE_NULL( mediacontrol_InternalException, "Snapshot exception" );
124 int mediacontrol_showtext( vout_thread_t *p_vout, int i_channel,
125 char *psz_string, text_style_t *p_style,
126 int i_flags, int i_hmargin, int i_vmargin,
127 mtime_t i_start, mtime_t i_stop )
132 if( !psz_string ) return VLC_EGENERIC;
134 p_spu = spu_CreateSubpicture( p_vout->p_spu );
135 if( !p_spu ) return VLC_EGENERIC;
137 /* Create a new subpicture region */
138 memset( &fmt, 0, sizeof(video_format_t) );
139 fmt.i_chroma = VLC_FOURCC('T','E','X','T');
141 fmt.i_width = fmt.i_height = 0;
142 fmt.i_x_offset = fmt.i_y_offset = 0;
143 p_spu->p_region = p_spu->pf_create_region( VLC_OBJECT(p_vout), &fmt );
144 if( !p_spu->p_region )
146 msg_Err( p_vout, "cannot allocate SPU region" );
147 spu_DestroySubpicture( p_vout->p_spu, p_spu );
151 p_spu->p_region->psz_text = strdup( psz_string );
152 p_spu->p_region->i_align = i_flags & SUBPICTURE_ALIGN_MASK;
153 p_spu->p_region->p_style = p_style;
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 vout_thread_t *p_vout = NULL;
179 input_thread_t *p_input;
180 libvlc_exception_t ex;
182 libvlc_exception_init( &ex );
183 mediacontrol_exception_init( exception );
185 p_input = libvlc_get_input_thread( self->p_media_player, &ex );
188 RAISE_VOID( mediacontrol_InternalException, "No input" );
190 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
193 RAISE_VOID( mediacontrol_InternalException, "No video output" );
196 psz_message = strdup( message );
199 RAISE_VOID( mediacontrol_InternalException, "no more memory" );
202 if( begin->origin == mediacontrol_RelativePosition &&
204 end->origin == mediacontrol_RelativePosition )
206 mtime_t i_duration = 0;
207 mtime_t i_now = mdate();
209 i_duration = 1000 * private_mediacontrol_unit_convert(
210 self->p_media_player,
212 mediacontrol_MediaTime,
215 mediacontrol_showtext( p_vout, DEFAULT_CHAN, psz_message, NULL,
216 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
217 i_now, i_now + i_duration );
221 mtime_t i_debut, i_fin, i_now;
224 /* i_now = input_ClockGetTS( p_input, NULL, 0 ); */
227 i_debut = private_mediacontrol_position2microsecond( self->p_media_player,
228 ( mediacontrol_Position* ) begin );
231 i_fin = private_mediacontrol_position2microsecond( self->p_media_player,
232 ( mediacontrol_Position * ) end );
235 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN, psz_message, NULL,
236 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
240 vlc_object_release( p_vout );
244 mediacontrol_sound_get_volume( mediacontrol_Instance *self,
245 mediacontrol_Exception *exception )
247 libvlc_exception_t ex;
250 mediacontrol_exception_init( exception );
251 libvlc_exception_init( &ex );
253 i_ret = libvlc_audio_get_volume( self->p_instance, &ex );
254 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
255 /* FIXME: Normalize in [0..100] */
256 return (unsigned short)i_ret;
260 mediacontrol_sound_set_volume( mediacontrol_Instance *self,
261 const unsigned short volume,
262 mediacontrol_Exception *exception )
264 /* FIXME: Normalize in [0..100] */
265 libvlc_exception_t ex;
267 mediacontrol_exception_init( exception );
268 libvlc_exception_init( &ex );
270 libvlc_audio_set_volume( self->p_instance, volume, &ex );
271 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
274 int mediacontrol_set_visual( mediacontrol_Instance *self,
275 WINDOWHANDLE visual_id,
276 mediacontrol_Exception *exception )
278 libvlc_exception_t ex;
280 mediacontrol_exception_init( exception );
281 libvlc_exception_init( &ex );
283 libvlc_media_player_set_drawable( self->p_media_player, (libvlc_drawable_t)visual_id, &ex );
284 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
289 mediacontrol_get_rate( mediacontrol_Instance *self,
290 mediacontrol_Exception *exception )
292 libvlc_exception_t ex;
295 mediacontrol_exception_init( exception );
296 libvlc_exception_init( &ex );
298 i_ret = libvlc_media_player_get_rate( self->p_media_player, &ex );
299 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
305 mediacontrol_set_rate( mediacontrol_Instance *self,
307 mediacontrol_Exception *exception )
309 libvlc_exception_t ex;
311 mediacontrol_exception_init( exception );
312 libvlc_exception_init( &ex );
314 libvlc_media_player_set_rate( self->p_media_player, rate * 10, &ex );
315 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
319 mediacontrol_get_fullscreen( mediacontrol_Instance *self,
320 mediacontrol_Exception *exception )
322 libvlc_exception_t ex;
325 mediacontrol_exception_init( exception );
326 libvlc_exception_init( &ex );
328 i_ret = libvlc_get_fullscreen( self->p_media_player, &ex );
329 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
335 mediacontrol_set_fullscreen( mediacontrol_Instance *self,
336 const int b_fullscreen,
337 mediacontrol_Exception *exception )
339 libvlc_exception_t ex;
341 mediacontrol_exception_init( exception );
342 libvlc_exception_init( &ex );
344 libvlc_set_fullscreen( self->p_media_player, b_fullscreen, &ex );
345 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );