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