]> git.sesse.net Git - vlc/blob - src/control/mediacontrol_audio_video.c
8f6602d448f0b57a3e5e93af438dfb8f92f5ef80
[vlc] / src / control / mediacontrol_audio_video.c
1 /*****************************************************************************
2  * audio_video.c: Audio/Video management : volume, snapshot, OSD
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Olivier Aubert <olivier.aubert@liris.univ-lyon1.fr>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27 #include "mediacontrol_internal.h"
28 #include "libvlc_internal.h"
29 #include "media_player_internal.h"
30
31 #include <vlc/mediacontrol.h>
32 #include <vlc/libvlc.h>
33
34 #include <vlc_vout.h>
35 #include <vlc_input.h>
36 #include <vlc_osd.h>
37 #include <vlc_block.h>
38
39 #include <stdlib.h>                                      /* malloc(), free() */
40 #include <string.h>
41
42 #include <stdio.h>
43
44 #ifdef HAVE_UNISTD_H
45 #    include <unistd.h>
46 #endif
47 #ifdef HAVE_SYS_TIME_H
48 #    include <sys/time.h>
49 #endif
50 #ifdef HAVE_SYS_TYPES_H
51 #    include <sys/types.h>
52 #endif
53
54 mediacontrol_RGBPicture *
55 mediacontrol_snapshot( mediacontrol_Instance *self,
56                        const mediacontrol_Position * a_position,
57                        mediacontrol_Exception *exception )
58 {
59     (void)a_position;
60     vout_thread_t* p_vout;
61     input_thread_t *p_input;
62     mediacontrol_RGBPicture *p_pic;
63     libvlc_exception_t ex;
64
65     libvlc_exception_init( &ex );
66     mediacontrol_exception_init( exception );
67
68     p_input = libvlc_get_input_thread( self->p_media_player, &ex );
69     if( ! p_input )
70     {
71         RAISE_NULL( mediacontrol_InternalException, "No input" );
72     }
73
74     p_vout = input_GetVout( p_input );
75     vlc_object_release( p_input );
76     if( ! p_vout )
77     {
78         RAISE_NULL( mediacontrol_InternalException, "No video output" );
79     }
80
81     block_t *p_image;
82     video_format_t fmt;
83
84     if( vout_GetSnapshot( p_vout, &p_image, NULL, &fmt, "png", 500*1000 ) )
85     {
86         vlc_object_release( p_vout );
87         RAISE_NULL( mediacontrol_InternalException, "Snapshot exception" );
88         return NULL;
89     }
90
91     /* */
92     char *p_data = malloc( p_image->i_buffer );
93     if( p_data )
94     {
95         memcpy( p_data, p_image->p_buffer, p_image->i_buffer );
96         p_pic = private_mediacontrol_createRGBPicture( fmt.i_width,
97                                                        fmt.i_height,
98                                                        fmt.i_chroma,
99                                                        p_image->i_pts,
100                                                        p_data,
101                                                        p_image->i_buffer );
102     }
103     else
104     {
105         p_pic = NULL;
106     }
107     block_Release( p_image );
108
109     if( !p_pic )
110         RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
111
112     vlc_object_release( p_vout );
113     return p_pic;
114 }
115
116 static
117 int mediacontrol_showtext( vout_thread_t *p_vout, int i_channel,
118                            const char *psz_string, text_style_t *p_style,
119                            int i_flags, int i_hmargin, int i_vmargin,
120                            mtime_t i_start, mtime_t i_stop )
121 {
122     return osd_ShowTextAbsolute( vout_GetSpu( p_vout ), i_channel,
123                                  psz_string, p_style,
124                                  i_flags, i_hmargin, i_vmargin,
125                                  i_start, i_stop );
126 }
127
128
129 void
130 mediacontrol_display_text( mediacontrol_Instance *self,
131                            const char * message,
132                            const mediacontrol_Position * begin,
133                            const mediacontrol_Position * end,
134                            mediacontrol_Exception *exception )
135 {
136     vout_thread_t *p_vout = NULL;
137     input_thread_t *p_input;
138     libvlc_exception_t ex;
139
140     libvlc_exception_init( &ex );
141     mediacontrol_exception_init( exception );
142
143     if( !message )
144     {
145         RAISE_VOID( mediacontrol_InternalException, "Empty text" );
146     }
147
148     p_input = libvlc_get_input_thread( self->p_media_player, &ex );
149     if( ! p_input )
150     {
151         RAISE_VOID( mediacontrol_InternalException, "No input" );
152     }
153     p_vout = input_GetVout( p_input );
154     /*FIXME: take care of the next fixme that can use p_input */
155     vlc_object_release( p_input );
156
157     if( ! p_vout )
158     {
159         RAISE_VOID( mediacontrol_InternalException, "No video output" );
160     }
161
162     if( begin->origin == mediacontrol_RelativePosition &&
163         begin->value == 0 &&
164         end->origin == mediacontrol_RelativePosition )
165     {
166         mtime_t i_duration = 0;
167         mtime_t i_now = mdate();
168
169         i_duration = 1000 * private_mediacontrol_unit_convert(
170                                                               self->p_media_player,
171                                                               end->key,
172                                                               mediacontrol_MediaTime,
173                                                               end->value );
174
175         mediacontrol_showtext( p_vout, DEFAULT_CHAN, message, NULL,
176                                OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
177                                i_now, i_now + i_duration );
178     }
179     else
180     {
181         mtime_t i_debut, i_fin, i_now;
182
183         /* FIXME */
184         /* i_now = input_ClockGetTS( p_input, NULL, 0 ); */
185         i_now = mdate();
186
187         i_debut = private_mediacontrol_position2microsecond( self->p_media_player,
188                                             ( mediacontrol_Position* ) begin );
189         i_debut += i_now;
190
191         i_fin = private_mediacontrol_position2microsecond( self->p_media_player,
192                                           ( mediacontrol_Position * ) end );
193         i_fin += i_now;
194
195         vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN, message, NULL,
196                                OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
197                                i_debut, i_fin );
198     }
199
200     vlc_object_release( p_vout );
201 }
202
203 unsigned short
204 mediacontrol_sound_get_volume( mediacontrol_Instance *self,
205                                mediacontrol_Exception *exception )
206 {
207     int i_ret = 0;
208
209     mediacontrol_exception_init( exception );
210
211     i_ret = libvlc_audio_get_volume( self->p_instance );
212     /* FIXME: Normalize in [0..100] */
213     return (unsigned short)i_ret;
214 }
215
216 void
217 mediacontrol_sound_set_volume( mediacontrol_Instance *self,
218                                const unsigned short volume,
219                                mediacontrol_Exception *exception )
220 {
221     /* FIXME: Normalize in [0..100] */
222     libvlc_exception_t ex;
223
224     mediacontrol_exception_init( exception );
225     libvlc_exception_init( &ex );
226
227     libvlc_audio_set_volume( self->p_instance, volume, &ex );
228     HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
229 }
230
231 int mediacontrol_set_visual( mediacontrol_Instance *self,
232                                     WINDOWHANDLE visual_id,
233                                     mediacontrol_Exception *exception )
234 {
235     libvlc_exception_t ex;
236
237     mediacontrol_exception_init( exception );
238     libvlc_exception_init( &ex );
239 #ifdef WIN32
240     libvlc_media_player_set_hwnd( self->p_media_player, visual_id, &ex );
241 #else
242     libvlc_media_player_set_xwindow( self->p_media_player, visual_id, &ex );
243 #endif
244     HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
245     return true;
246 }
247
248 int
249 mediacontrol_get_rate( mediacontrol_Instance *self,
250                mediacontrol_Exception *exception )
251 {
252     libvlc_exception_t ex;
253     int i_ret;
254
255     mediacontrol_exception_init( exception );
256     libvlc_exception_init( &ex );
257
258     i_ret = libvlc_media_player_get_rate( self->p_media_player, &ex );
259     HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
260
261     return i_ret / 10;
262 }
263
264 void
265 mediacontrol_set_rate( mediacontrol_Instance *self,
266                const int rate,
267                mediacontrol_Exception *exception )
268 {
269     libvlc_exception_t ex;
270
271     mediacontrol_exception_init( exception );
272     libvlc_exception_init( &ex );
273
274     libvlc_media_player_set_rate( self->p_media_player, rate * 10, &ex );
275     HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
276 }
277
278 int
279 mediacontrol_get_fullscreen( mediacontrol_Instance *self,
280                  mediacontrol_Exception *exception )
281 {
282     libvlc_exception_t ex;
283     int i_ret;
284
285     mediacontrol_exception_init( exception );
286     libvlc_exception_init( &ex );
287
288     i_ret = libvlc_get_fullscreen( self->p_media_player, &ex );
289     HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
290
291     return i_ret;
292 }
293
294 void
295 mediacontrol_set_fullscreen( mediacontrol_Instance *self,
296                  const int b_fullscreen,
297                  mediacontrol_Exception *exception )
298 {
299     libvlc_exception_t ex;
300
301     mediacontrol_exception_init( exception );
302     libvlc_exception_init( &ex );
303
304     libvlc_set_fullscreen( self->p_media_player, b_fullscreen, &ex );
305     HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
306 }