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