1 /*****************************************************************************
2 * vlcpeer.cpp: scriptable peer descriptor
3 *****************************************************************************
4 * Copyright (C) 2002-2005 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
32 /* We do not want to use nsDebug.h */
36 #ifdef HAVE_MOZILLA_CONFIG_H
37 # include <mozilla-config.h>
39 #include <nsISupports.h>
43 #if !defined(XP_MACOSX) && !defined(XP_UNIX) && !defined(XP_WIN)
45 #elif defined(XP_MACOSX)
50 #include "vlcplugin.h"
52 NS_IMPL_ISUPPORTS2( VlcPeer, VlcIntf, nsIClassInfo )
54 /*****************************************************************************
55 * Scriptable peer constructor and destructor
56 *****************************************************************************/
62 VlcPeer::VlcPeer( VlcPlugin * plugin )
73 /*****************************************************************************
74 * Scriptable peer methods
75 *****************************************************************************/
76 void VlcPeer::Disable()
81 /*****************************************************************************
82 * Scriptable peer plugin methods
83 *****************************************************************************/
84 NS_IMETHODIMP VlcPeer::Play()
88 if( !p_plugin->b_stream && p_plugin->psz_target )
90 VLC_AddTarget( p_plugin->i_vlc, p_plugin->psz_target, 0, 0,
91 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
92 p_plugin->b_stream = 1;
95 VLC_Play( p_plugin->i_vlc );
100 NS_IMETHODIMP VlcPeer::Pause()
104 VLC_Pause( p_plugin->i_vlc );
109 NS_IMETHODIMP VlcPeer::Stop()
113 VLC_Stop( p_plugin->i_vlc );
114 p_plugin->b_stream = 0;
119 NS_IMETHODIMP VlcPeer::Fullscreen()
125 VLC_FullScreen( p_plugin->i_vlc );
131 /* Set/Get vlc variables */
132 NS_IMETHODIMP VlcPeer::Set_int_variable(const char *psz_var, PRInt64 value )
138 VLC_VariableSet( p_plugin->i_vlc, psz_var, val );
143 NS_IMETHODIMP VlcPeer::Set_str_variable(const char *psz_var, const char *value )
146 val.psz_string = strdup( value );
149 VLC_VariableSet( p_plugin->i_vlc, psz_var, val );
154 NS_IMETHODIMP VlcPeer::Set_bool_variable(const char *psz_var, PRBool value )
157 val.b_bool = value >= 1 ? VLC_TRUE : VLC_FALSE;
160 VLC_VariableSet( p_plugin->i_vlc, psz_var, val );
165 NS_IMETHODIMP VlcPeer::Get_int_variable( const char *psz_var, PRInt64 *result )
170 fprintf(stderr, "Choppage de %s\n", psz_var );
171 VLC_VariableGet( p_plugin->i_vlc, psz_var, &val );
172 fprintf(stderr, "Valeur %i\n", val.i_int );
173 *result = (PRInt64)val.i_int;
178 NS_IMETHODIMP VlcPeer::Get_bool_variable( const char *psz_var,PRBool *result )
183 VLC_VariableGet( p_plugin->i_vlc, psz_var, &val );
184 *result = (PRBool)val.b_bool;
189 NS_IMETHODIMP VlcPeer::Get_str_variable( const char *psz_var, char **result )
194 fprintf(stderr, "Choppage de %s\n", psz_var );
195 VLC_VariableGet( p_plugin->i_vlc, psz_var, &val );
198 *result = strdup( val.psz_string );
202 *result = strdup( "" );
208 /* Playlist control */
209 NS_IMETHODIMP VlcPeer::Clear_playlist()
213 VLC_PlaylistClear( p_plugin->i_vlc );
218 NS_IMETHODIMP VlcPeer::Add_item( const char *psz_item )
222 VLC_AddTarget( p_plugin->i_vlc, psz_item, NULL, 0,
223 PLAYLIST_APPEND, PLAYLIST_END);
229 NS_IMETHODIMP VlcPeer::Isplaying( PRBool *b_playing )
231 if( p_plugin->i_vlc )
233 *b_playing = VLC_IsPlaying( p_plugin->i_vlc );
238 NS_IMETHODIMP VlcPeer::Get_position( PRInt64 *i_position )
240 if( p_plugin->i_vlc )
242 *i_position = (PRInt64)VLC_PositionGet( p_plugin->i_vlc );
247 NS_IMETHODIMP VlcPeer::Get_time( PRInt64 *i_time )
249 if( p_plugin->i_vlc )
251 *i_time = VLC_TimeGet( p_plugin->i_vlc );
256 NS_IMETHODIMP VlcPeer::Get_length( PRInt64 *i_length )
258 if( p_plugin->i_vlc )
260 *i_length = VLC_LengthGet( p_plugin->i_vlc );
265 NS_IMETHODIMP VlcPeer::Seek( PRInt64 i_secs, PRInt64 b_relative )
267 if( p_plugin->i_vlc )
269 VLC_TimeSet( p_plugin->i_vlc, i_secs, b_relative );
274 NS_IMETHODIMP VlcPeer::Next()
276 if( p_plugin->i_vlc )
278 VLC_PlaylistNext( p_plugin->i_vlc);
283 NS_IMETHODIMP VlcPeer::Previous()
285 if( p_plugin->i_vlc )
287 VLC_PlaylistPrev( p_plugin->i_vlc );
292 NS_IMETHODIMP VlcPeer::Set_volume( PRInt64 i_volume )
294 if( p_plugin->i_vlc )
296 VLC_VolumeSet( p_plugin->i_vlc, i_volume );
301 NS_IMETHODIMP VlcPeer::Get_volume( PRInt64 *i_volume )
303 if( p_plugin->i_vlc )
305 *i_volume = VLC_VolumeGet( p_plugin->i_vlc );
310 NS_IMETHODIMP VlcPeer::Mute()
312 if( p_plugin->i_vlc )
314 VLC_VolumeMute( p_plugin->i_vlc );