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>
35 #include <vlc_block.h>
37 #include <stdlib.h> /* malloc(), free() */
40 #include <errno.h> /* ENOMEM */
47 #ifdef HAVE_SYS_TIME_H
48 # include <sys/time.h>
50 #ifdef HAVE_SYS_TYPES_H
51 # include <sys/types.h>
54 mediacontrol_RGBPicture *
55 mediacontrol_snapshot( mediacontrol_Instance *self,
56 const mediacontrol_Position * a_position,
57 mediacontrol_Exception *exception )
60 vout_thread_t* p_vout;
61 input_thread_t *p_input;
62 mediacontrol_RGBPicture *p_pic;
63 libvlc_exception_t ex;
65 libvlc_exception_init( &ex );
66 mediacontrol_exception_init( exception );
68 p_input = libvlc_get_input_thread( self->p_media_player, &ex );
71 RAISE_NULL( mediacontrol_InternalException, "No input" );
74 p_vout = input_GetVout( p_input );
75 vlc_object_release( p_input );
78 RAISE_NULL( mediacontrol_InternalException, "No video output" );
84 if( vout_GetSnapshot( p_vout, &p_image, NULL, &fmt, "png", 500*1000 ) )
86 RAISE_NULL( mediacontrol_InternalException, "Snapshot exception" );
91 char *p_data = malloc( p_image->i_buffer );
94 memcpy( p_data, p_image->p_buffer, p_image->i_buffer );
95 p_pic = private_mediacontrol_createRGBPicture( fmt.i_width,
106 block_Release( p_image );
109 RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
114 int mediacontrol_showtext( vout_thread_t *p_vout, int i_channel,
115 const char *psz_string, text_style_t *p_style,
116 int i_flags, int i_hmargin, int i_vmargin,
117 mtime_t i_start, mtime_t i_stop )
119 return osd_ShowTextAbsolute( p_vout->p_spu, i_channel,
121 i_flags, i_hmargin, i_vmargin,
127 mediacontrol_display_text( mediacontrol_Instance *self,
128 const char * message,
129 const mediacontrol_Position * begin,
130 const mediacontrol_Position * end,
131 mediacontrol_Exception *exception )
133 vout_thread_t *p_vout = NULL;
134 input_thread_t *p_input;
135 libvlc_exception_t ex;
137 libvlc_exception_init( &ex );
138 mediacontrol_exception_init( exception );
142 RAISE_VOID( mediacontrol_InternalException, "Empty text" );
145 p_input = libvlc_get_input_thread( self->p_media_player, &ex );
148 RAISE_VOID( mediacontrol_InternalException, "No input" );
150 p_vout = input_GetVout( p_input );
153 RAISE_VOID( mediacontrol_InternalException, "No video output" );
156 if( begin->origin == mediacontrol_RelativePosition &&
158 end->origin == mediacontrol_RelativePosition )
160 mtime_t i_duration = 0;
161 mtime_t i_now = mdate();
163 i_duration = 1000 * private_mediacontrol_unit_convert(
164 self->p_media_player,
166 mediacontrol_MediaTime,
169 mediacontrol_showtext( p_vout, DEFAULT_CHAN, message, NULL,
170 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
171 i_now, i_now + i_duration );
175 mtime_t i_debut, i_fin, i_now;
178 /* i_now = input_ClockGetTS( p_input, NULL, 0 ); */
181 i_debut = private_mediacontrol_position2microsecond( self->p_media_player,
182 ( mediacontrol_Position* ) begin );
185 i_fin = private_mediacontrol_position2microsecond( self->p_media_player,
186 ( mediacontrol_Position * ) end );
189 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN, message, NULL,
190 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
194 vlc_object_release( p_vout );
198 mediacontrol_sound_get_volume( mediacontrol_Instance *self,
199 mediacontrol_Exception *exception )
201 libvlc_exception_t ex;
204 mediacontrol_exception_init( exception );
205 libvlc_exception_init( &ex );
207 i_ret = libvlc_audio_get_volume( self->p_instance, &ex );
208 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
209 /* FIXME: Normalize in [0..100] */
210 return (unsigned short)i_ret;
214 mediacontrol_sound_set_volume( mediacontrol_Instance *self,
215 const unsigned short volume,
216 mediacontrol_Exception *exception )
218 /* FIXME: Normalize in [0..100] */
219 libvlc_exception_t ex;
221 mediacontrol_exception_init( exception );
222 libvlc_exception_init( &ex );
224 libvlc_audio_set_volume( self->p_instance, volume, &ex );
225 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
228 int mediacontrol_set_visual( mediacontrol_Instance *self,
229 WINDOWHANDLE visual_id,
230 mediacontrol_Exception *exception )
232 libvlc_exception_t ex;
234 mediacontrol_exception_init( exception );
235 libvlc_exception_init( &ex );
237 libvlc_media_player_set_drawable( self->p_media_player, (libvlc_drawable_t)visual_id, &ex );
238 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
243 mediacontrol_get_rate( 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_media_player_get_rate( self->p_media_player, &ex );
253 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
259 mediacontrol_set_rate( mediacontrol_Instance *self,
261 mediacontrol_Exception *exception )
263 libvlc_exception_t ex;
265 mediacontrol_exception_init( exception );
266 libvlc_exception_init( &ex );
268 libvlc_media_player_set_rate( self->p_media_player, rate * 10, &ex );
269 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
273 mediacontrol_get_fullscreen( mediacontrol_Instance *self,
274 mediacontrol_Exception *exception )
276 libvlc_exception_t ex;
279 mediacontrol_exception_init( exception );
280 libvlc_exception_init( &ex );
282 i_ret = libvlc_get_fullscreen( self->p_media_player, &ex );
283 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
289 mediacontrol_set_fullscreen( mediacontrol_Instance *self,
290 const int b_fullscreen,
291 mediacontrol_Exception *exception )
293 libvlc_exception_t ex;
295 mediacontrol_exception_init( exception );
296 libvlc_exception_init( &ex );
298 libvlc_set_fullscreen( self->p_media_player, b_fullscreen, &ex );
299 HANDLE_LIBVLC_EXCEPTION_VOID( &ex );