Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

vlcpeer.cpp

00001 /*****************************************************************************
00002  * vlcpeer.cpp: scriptable peer descriptor
00003  *****************************************************************************
00004  * Copyright (C) 2002-2005 the VideoLAN team
00005  * $Id: vlcpeer.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Samuel Hocevar <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include "config.h"
00028 
00029 #include <vlc/vlc.h>
00030 
00031 #ifdef DEBUG
00032 /* We do not want to use nsDebug.h */
00033 #   undef DEBUG
00034 #endif
00035 
00036 #ifdef HAVE_MOZILLA_CONFIG_H
00037 #   include <mozilla-config.h>
00038 #endif
00039 #include <nsISupports.h>
00040 #include <nsMemory.h>
00041 #include <npapi.h>
00042 
00043 #if !defined(XP_MACOSX) && !defined(XP_UNIX) && !defined(XP_WIN)
00044 #define XP_UNIX 1
00045 #elif defined(XP_MACOSX)
00046 #undef XP_UNIX
00047 #endif
00048 
00049 #include "vlcpeer.h"
00050 #include "vlcplugin.h"
00051 
00052 NS_IMPL_ISUPPORTS2( VlcPeer, VlcIntf, nsIClassInfo )
00053 
00054 /*****************************************************************************
00055  * Scriptable peer constructor and destructor
00056  *****************************************************************************/
00057 VlcPeer::VlcPeer()
00058 {
00059     NS_INIT_ISUPPORTS();
00060 }
00061 
00062 VlcPeer::VlcPeer( VlcPlugin * plugin )
00063 {
00064     NS_INIT_ISUPPORTS();
00065     p_plugin = plugin;
00066 }
00067 
00068 VlcPeer::~VlcPeer()
00069 {
00070     ;
00071 }
00072 
00073 /*****************************************************************************
00074  * Scriptable peer methods
00075  *****************************************************************************/
00076 void VlcPeer::Disable()
00077 {
00078     p_plugin = NULL;
00079 }
00080 
00081 /*****************************************************************************
00082  * Scriptable peer plugin methods
00083  *****************************************************************************/
00084 NS_IMETHODIMP VlcPeer::Play()
00085 {
00086     if( p_plugin )
00087     {
00088         if( !p_plugin->b_stream && p_plugin->psz_target )
00089         {
00090             VLC_AddTarget( p_plugin->i_vlc, p_plugin->psz_target, 0, 0,
00091                            PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
00092             p_plugin->b_stream = 1;
00093         }
00094 
00095         VLC_Play( p_plugin->i_vlc );
00096     }
00097     return NS_OK;
00098 }
00099 
00100 NS_IMETHODIMP VlcPeer::Pause()
00101 {
00102     if( p_plugin )
00103     {
00104         VLC_Pause( p_plugin->i_vlc );
00105     }
00106     return NS_OK;
00107 }
00108 
00109 NS_IMETHODIMP VlcPeer::Stop()
00110 {
00111     if( p_plugin )
00112     {
00113         VLC_Stop( p_plugin->i_vlc );
00114         p_plugin->b_stream = 0;
00115     }
00116     return NS_OK;
00117 }
00118 
00119 NS_IMETHODIMP VlcPeer::Fullscreen()
00120 {
00121     if( p_plugin )
00122     {
00123 #ifdef XP_MACOSX
00124 #else
00125         VLC_FullScreen( p_plugin->i_vlc );
00126 #endif
00127     }
00128     return NS_OK;
00129 }
00130 
00131 /* Set/Get vlc variables */
00132 NS_IMETHODIMP VlcPeer::Set_int_variable(const char *psz_var, PRInt64 value )
00133 {
00134     vlc_value_t val;
00135     val.i_int = value;
00136     if( p_plugin )
00137     {
00138         VLC_VariableSet( p_plugin->i_vlc, psz_var, val );
00139     }
00140     return NS_OK;
00141 }
00142 
00143 NS_IMETHODIMP VlcPeer::Set_str_variable(const char *psz_var, const char *value )
00144 {
00145     vlc_value_t val;
00146     val.psz_string = strdup( value );
00147     if( p_plugin )
00148     {
00149         VLC_VariableSet( p_plugin->i_vlc, psz_var, val );
00150     }
00151     return NS_OK;
00152 }
00153 
00154 NS_IMETHODIMP VlcPeer::Set_bool_variable(const char *psz_var, PRBool value )
00155 {
00156     vlc_value_t val;
00157     val.b_bool = value >= 1 ? VLC_TRUE : VLC_FALSE;
00158     if( p_plugin )
00159     {
00160         VLC_VariableSet( p_plugin->i_vlc, psz_var, val );
00161     }
00162     return NS_OK;
00163 }
00164 
00165 NS_IMETHODIMP VlcPeer::Get_int_variable( const char *psz_var, PRInt64 *result )
00166 {
00167     vlc_value_t val;
00168     if( p_plugin )
00169     {
00170         fprintf(stderr, "Choppage de %s\n", psz_var );
00171         VLC_VariableGet( p_plugin->i_vlc, psz_var, &val );
00172         fprintf(stderr, "Valeur %i\n", val.i_int );
00173         *result = (PRInt64)val.i_int;
00174     }
00175     return NS_OK;
00176 }
00177 
00178 NS_IMETHODIMP VlcPeer::Get_bool_variable(  const char *psz_var,PRBool *result )
00179 {
00180     vlc_value_t val;
00181     if( p_plugin )
00182     {
00183         VLC_VariableGet( p_plugin->i_vlc, psz_var, &val );
00184         *result = (PRBool)val.b_bool;
00185     }
00186     return NS_OK;
00187 }
00188 
00189 NS_IMETHODIMP VlcPeer::Get_str_variable( const char *psz_var, char **result )
00190 {
00191     vlc_value_t val;
00192     if( p_plugin )
00193     {
00194         fprintf(stderr, "Choppage de %s\n", psz_var );
00195         VLC_VariableGet( p_plugin->i_vlc, psz_var, &val );
00196         if( val.psz_string )
00197         {
00198             *result = strdup( val.psz_string );
00199         }
00200         else
00201         {
00202             *result = strdup( "" );
00203         }
00204     }
00205     return NS_OK;
00206 }
00207 
00208 /* Playlist control */
00209 NS_IMETHODIMP VlcPeer::Clear_playlist()
00210 {
00211     if( p_plugin )
00212     {
00213         VLC_PlaylistClear( p_plugin->i_vlc );
00214     }
00215     return NS_OK;
00216 }
00217 
00218 NS_IMETHODIMP VlcPeer::Add_item( const char *psz_item )
00219 {
00220      if( p_plugin )
00221      {
00222           VLC_AddTarget( p_plugin->i_vlc, psz_item, NULL, 0,
00223                          PLAYLIST_APPEND, PLAYLIST_END);
00224      }
00225      return NS_OK;
00226 }
00227 
00228 
00229 NS_IMETHODIMP VlcPeer::Isplaying( PRBool *b_playing )
00230 {
00231     if( p_plugin->i_vlc )
00232     {
00233         *b_playing = VLC_IsPlaying( p_plugin->i_vlc );
00234     }
00235     return NS_OK;
00236 }
00237 
00238 NS_IMETHODIMP VlcPeer::Get_position( PRInt64 *i_position )
00239 {
00240     if( p_plugin->i_vlc )
00241     {
00242         *i_position = (PRInt64)VLC_PositionGet( p_plugin->i_vlc );
00243     }
00244     return NS_OK;
00245 }
00246 
00247 NS_IMETHODIMP VlcPeer::Get_time( PRInt64 *i_time )
00248 {
00249     if( p_plugin->i_vlc )
00250     {
00251         *i_time = VLC_TimeGet( p_plugin->i_vlc );
00252     }
00253     return NS_OK;
00254 }
00255 
00256 NS_IMETHODIMP VlcPeer::Get_length( PRInt64 *i_length )
00257 {
00258     if( p_plugin->i_vlc )
00259     {
00260         *i_length = VLC_LengthGet( p_plugin->i_vlc );
00261     }
00262     return NS_OK;
00263 }
00264 
00265 NS_IMETHODIMP VlcPeer::Seek( PRInt64 i_secs, PRInt64 b_relative )
00266 {
00267     if( p_plugin->i_vlc )
00268     {
00269         VLC_TimeSet( p_plugin->i_vlc, i_secs, b_relative );
00270     }
00271     return NS_OK;
00272 }
00273 
00274 NS_IMETHODIMP VlcPeer::Next()
00275 {
00276     if( p_plugin->i_vlc )
00277     {
00278         VLC_PlaylistNext( p_plugin->i_vlc);
00279     }
00280     return NS_OK;
00281 }
00282 
00283 NS_IMETHODIMP VlcPeer::Previous()
00284 {
00285     if( p_plugin->i_vlc )
00286     {
00287         VLC_PlaylistPrev( p_plugin->i_vlc );
00288     }
00289     return NS_OK;
00290 }
00291 
00292 NS_IMETHODIMP VlcPeer::Set_volume( PRInt64 i_volume )
00293 {
00294     if( p_plugin->i_vlc )
00295     {
00296         VLC_VolumeSet( p_plugin->i_vlc, i_volume );
00297     }
00298     return NS_OK;
00299 }
00300 
00301 NS_IMETHODIMP VlcPeer::Get_volume( PRInt64 *i_volume )
00302 {
00303     if( p_plugin->i_vlc )
00304     {
00305         *i_volume = VLC_VolumeGet( p_plugin->i_vlc );
00306     }
00307     return NS_OK;
00308 }
00309 
00310 NS_IMETHODIMP VlcPeer::Mute()
00311 {
00312     if( p_plugin->i_vlc )
00313     {
00314         VLC_VolumeMute( p_plugin->i_vlc );
00315     }
00316     return NS_OK;
00317 }

Generated on Tue Dec 20 10:14:59 2005 for vlc-0.8.4a by  doxygen 1.4.2