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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 #include <mediacontrol_internal.h>
26 #include <vlc/mediacontrol.h>
31 #include <vlc_demux.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 #define RAISE( c, m ) exception->code = c; \
55 exception->message = strdup(m);
57 mediacontrol_RGBPicture *
58 mediacontrol_snapshot( mediacontrol_Instance *self,
59 const mediacontrol_Position * a_position,
60 mediacontrol_Exception *exception )
62 vlc_object_t* p_cache;
63 vout_thread_t* p_vout;
64 mediacontrol_RGBPicture *p_pic = NULL;
66 snapshot_t *p_snapshot;
68 exception=mediacontrol_exception_init( exception );
70 p_cache = vlc_object_create( self->p_playlist, VLC_OBJECT_GENERIC );
73 msg_Err( self->p_playlist, "out of memory" );
74 RAISE( mediacontrol_InternalException, "Out of memory" );
78 p_vout = vlc_object_find( self->p_playlist, VLC_OBJECT_VOUT, FIND_CHILD );
81 RAISE( mediacontrol_InternalException, "No video output" );
84 snprintf( path, 255, "object:%d", p_cache->i_object_id );
85 fprintf( stderr, "snapshot-path: %s\n", path );
86 var_SetString( p_vout, "snapshot-path", path );
87 var_SetString( p_vout, "snapshot-format", "png" );
89 vlc_mutex_lock( &p_cache->object_lock );
90 vout_Control( p_vout, VOUT_SNAPSHOT );
92 vlc_cond_wait( &p_cache->object_wait, &p_cache->object_lock );
94 p_snapshot = ( snapshot_t* ) p_cache->p_private;
95 vlc_object_destroy( p_cache );
99 p_pic = _mediacontrol_createRGBPicture( p_snapshot->i_width,
100 p_snapshot->i_height,
104 p_snapshot->i_datasize );
106 RAISE( mediacontrol_InternalException, "Out of memory" );
107 free( p_snapshot->p_data );
112 RAISE( mediacontrol_InternalException, "Snapshot exception" );
117 mediacontrol_RGBPicture **
118 mediacontrol_all_snapshots( mediacontrol_Instance *self,
119 mediacontrol_Exception *exception )
121 exception=mediacontrol_exception_init( exception );
123 RAISE( mediacontrol_InternalException, "Unsupported method" );
127 int mediacontrol_showtext( vout_thread_t *p_vout, int i_channel,
128 char *psz_string, text_style_t *p_style,
129 int i_flags, int i_hmargin, int i_vmargin,
130 mtime_t i_start, mtime_t i_stop )
135 if( !psz_string ) return VLC_EGENERIC;
137 p_spu = spu_CreateSubpicture( p_vout->p_spu );
138 if( !p_spu ) return VLC_EGENERIC;
140 /* Create a new subpicture region */
141 memset( &fmt, 0, sizeof(video_format_t) );
142 fmt.i_chroma = VLC_FOURCC('T','E','X','T');
144 fmt.i_width = fmt.i_height = 0;
145 fmt.i_x_offset = fmt.i_y_offset = 0;
146 p_spu->p_region = p_spu->pf_create_region( VLC_OBJECT(p_vout), &fmt );
147 if( !p_spu->p_region )
149 msg_Err( p_vout, "cannot allocate SPU region" );
150 spu_DestroySubpicture( p_vout->p_spu, p_spu );
154 p_spu->p_region->psz_text = strdup( psz_string );
155 p_spu->i_start = i_start;
156 p_spu->i_stop = i_stop;
157 p_spu->b_ephemer = VLC_FALSE;
158 p_spu->b_absolute = VLC_FALSE;
160 p_spu->i_x = i_hmargin;
161 p_spu->i_y = i_vmargin;
162 p_spu->i_flags = i_flags;
163 p_spu->i_channel = i_channel;
165 spu_DisplaySubpicture( p_vout->p_spu, p_spu );
172 mediacontrol_display_text( mediacontrol_Instance *self,
173 const char * message,
174 const mediacontrol_Position * begin,
175 const mediacontrol_Position * end,
176 mediacontrol_Exception *exception )
178 input_thread_t *p_input = NULL;
179 vout_thread_t *p_vout = NULL;
182 psz_message = strdup( message );
185 RAISE( mediacontrol_InternalException, "No more memory" );
189 p_vout = vlc_object_find( self->p_playlist, VLC_OBJECT_VOUT, FIND_CHILD );
192 RAISE( mediacontrol_InternalException, "No video output" );
196 if( begin->origin == mediacontrol_RelativePosition &&
198 end->origin == mediacontrol_RelativePosition )
200 mtime_t i_duration = 0;
201 mtime_t i_now = mdate();
203 i_duration = 1000 * mediacontrol_unit_convert( self->p_playlist->p_input,
205 mediacontrol_MediaTime,
208 mediacontrol_showtext( p_vout, DEFAULT_CHAN, psz_message, NULL,
209 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
210 i_now, i_now + i_duration );
214 mtime_t i_debut, i_fin, i_now;
216 p_input = self->p_playlist->p_input;
219 RAISE( mediacontrol_InternalException, "No input" );
220 vlc_object_release( p_vout );
225 /* i_now = input_ClockGetTS( p_input, NULL, 0 ); */
228 i_debut = mediacontrol_position2microsecond( p_input,
229 ( mediacontrol_Position* ) begin );
232 i_fin = mediacontrol_position2microsecond( p_input,
233 ( mediacontrol_Position * ) end );
236 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN, psz_message, NULL,
237 OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
241 vlc_object_release( p_vout );
245 mediacontrol_sound_get_volume( mediacontrol_Instance *self,
246 mediacontrol_Exception *exception )
249 audio_volume_t i_volume;
253 RAISE( mediacontrol_InternalException, "No interface module" );
256 aout_VolumeGet( self->p_intf, &i_volume );
262 mediacontrol_sound_set_volume( mediacontrol_Instance *self,
263 const unsigned short volume,
264 mediacontrol_Exception *exception )
268 RAISE( mediacontrol_InternalException, "No interface module" );
271 aout_VolumeSet( self->p_intf,( audio_volume_t )volume );
274 vlc_bool_t mediacontrol_set_visual( mediacontrol_Instance *self,
275 WINDOWHANDLE visual_id,
276 mediacontrol_Exception *exception )
283 RAISE( mediacontrol_InternalException, "No vlc reference" );
286 value.i_int=visual_id;
287 ret = var_Set(self->p_vlc, "drawable", value);
289 return (ret == VLC_SUCCESS);