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