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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
27 #include "mediacontrol_internal.h"
28 #include "libvlc_internal.h"
29 #include "media_player_internal.h"
31 #include <vlc/mediacontrol.h>
32 #include <vlc/libvlc.h>
35 #include <vlc_input.h>
37 #include <vlc_block.h>
39 #include <stdlib.h> /* malloc(), free() */
47 #include <sys/types.h>
49 mediacontrol_RGBPicture
*
50 mediacontrol_snapshot( mediacontrol_Instance
*self
,
51 const mediacontrol_Position
* a_position
,
52 mediacontrol_Exception
*exception
)
55 vout_thread_t
* p_vout
;
56 input_thread_t
*p_input
;
57 mediacontrol_RGBPicture
*p_pic
;
58 libvlc_exception_t ex
;
60 libvlc_exception_init( &ex
);
61 mediacontrol_exception_init( exception
);
63 p_input
= libvlc_get_input_thread( self
->p_media_player
);
66 RAISE_NULL( mediacontrol_InternalException
, "No input" );
69 p_vout
= input_GetVout( p_input
);
70 vlc_object_release( p_input
);
73 RAISE_NULL( mediacontrol_InternalException
, "No video output" );
79 if( vout_GetSnapshot( p_vout
, &p_image
, NULL
, &fmt
, "png", 500*1000 ) )
81 vlc_object_release( p_vout
);
82 RAISE_NULL( mediacontrol_InternalException
, "Snapshot exception" );
87 char *p_data
= malloc( p_image
->i_buffer
);
90 memcpy( p_data
, p_image
->p_buffer
, p_image
->i_buffer
);
91 p_pic
= private_mediacontrol_createRGBPicture( fmt
.i_width
,
102 block_Release( p_image
);
105 RAISE_NULL( mediacontrol_InternalException
, "Out of memory" );
107 vlc_object_release( p_vout
);
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
)
117 (void)p_style
; (void)i_hmargin
; (void)i_vmargin
;
118 vout_OSDText( p_vout
, i_channel
, i_flags
& ~SUBPICTURE_ALIGN_MASK
,
119 i_stop
- i_start
, psz_string
);
124 mediacontrol_display_text( mediacontrol_Instance
*self
,
125 const char * message
,
126 const mediacontrol_Position
* begin
,
127 const mediacontrol_Position
* end
,
128 mediacontrol_Exception
*exception
)
130 vout_thread_t
*p_vout
= NULL
;
131 input_thread_t
*p_input
;
132 libvlc_exception_t ex
;
134 libvlc_exception_init( &ex
);
135 mediacontrol_exception_init( exception
);
139 RAISE_VOID( mediacontrol_InternalException
, "Empty text" );
142 p_input
= libvlc_get_input_thread( self
->p_media_player
);
145 RAISE_VOID( mediacontrol_InternalException
, "No input" );
147 p_vout
= input_GetVout( p_input
);
148 /*FIXME: take care of the next fixme that can use p_input */
149 vlc_object_release( p_input
);
153 RAISE_VOID( mediacontrol_InternalException
, "No video output" );
156 if( begin
->origin
== mediacontrol_RelativePosition
&&
158 end
->origin
== mediacontrol_RelativePosition
)
160 mtime_t i_duration
= 0;
161 mtime_t i_now
= mdate();
163 i_duration
= 1000 * private_mediacontrol_unit_convert(
164 self
->p_media_player
,
166 mediacontrol_MediaTime
,
169 mediacontrol_showtext( p_vout
, DEFAULT_CHAN
, message
, NULL
,
170 OSD_ALIGN_BOTTOM
| OSD_ALIGN_LEFT
, 0, 0,
171 i_now
, i_now
+ i_duration
);
175 mtime_t i_debut
, i_fin
, i_now
;
178 /* i_now = input_ClockGetTS( p_input, NULL, 0 ); */
181 i_debut
= private_mediacontrol_position2microsecond( self
->p_media_player
,
182 ( mediacontrol_Position
* ) begin
);
185 i_fin
= private_mediacontrol_position2microsecond( self
->p_media_player
,
186 ( mediacontrol_Position
* ) end
);
189 vout_ShowTextAbsolute( p_vout
, DEFAULT_CHAN
, message
, NULL
,
190 OSD_ALIGN_BOTTOM
| OSD_ALIGN_LEFT
, 0, 0,
194 vlc_object_release( p_vout
);
198 mediacontrol_sound_get_volume( mediacontrol_Instance
*self
,
199 mediacontrol_Exception
*exception
)
203 mediacontrol_exception_init( exception
);
205 //i_ret = libvlc_audio_get_volume( self->p_instance );
206 #warning FIXME: unimplented
207 /* FIXME: Normalize in [0..100] */
208 return (unsigned short)i_ret
;
212 mediacontrol_sound_set_volume( mediacontrol_Instance
*self
,
213 const unsigned short volume
,
214 mediacontrol_Exception
*exception
)
216 /* FIXME: Normalize in [0..100] */
217 mediacontrol_exception_init( exception
);
219 //libvlc_audio_set_volume( self->p_instance, volume );
220 #warning FIXME: unimplented
223 int mediacontrol_set_visual( mediacontrol_Instance
*self
,
224 WINDOWHANDLE visual_id
,
225 mediacontrol_Exception
*exception
)
227 mediacontrol_exception_init( exception
);
229 libvlc_media_player_set_hwnd( self
->p_media_player
, visual_id
);
231 libvlc_media_player_set_xwindow( self
->p_media_player
, visual_id
);
237 mediacontrol_get_rate( mediacontrol_Instance
*self
,
238 mediacontrol_Exception
*exception
)
242 mediacontrol_exception_init( exception
);
243 i_ret
= libvlc_media_player_get_rate( self
->p_media_player
);
245 return (i_ret
>= 0) ? (i_ret
/ 10) : -1;
249 mediacontrol_set_rate( mediacontrol_Instance
*self
,
251 mediacontrol_Exception
*exception
)
253 mediacontrol_exception_init( exception
);
255 libvlc_media_player_set_rate( self
->p_media_player
, rate
* 10 );
259 mediacontrol_get_fullscreen( mediacontrol_Instance
*self
,
260 mediacontrol_Exception
*exception
)
262 libvlc_exception_t ex
;
265 mediacontrol_exception_init( exception
);
266 libvlc_exception_init( &ex
);
268 i_ret
= libvlc_get_fullscreen( self
->p_media_player
, &ex
);
269 HANDLE_LIBVLC_EXCEPTION_ZERO( &ex
);
275 mediacontrol_set_fullscreen( mediacontrol_Instance
*self
,
276 const int b_fullscreen
,
277 mediacontrol_Exception
*exception
)
279 libvlc_exception_t ex
;
281 mediacontrol_exception_init( exception
);
282 libvlc_exception_init( &ex
);
284 libvlc_set_fullscreen( self
->p_media_player
, b_fullscreen
, &ex
);
285 HANDLE_LIBVLC_EXCEPTION_VOID( &ex
);