]> git.sesse.net Git - vlc/blob - mozilla/vlcpeer.cpp
* mozilla/vlcpeer.cpp: proper float->int cast.
[vlc] / mozilla / vlcpeer.cpp
1 /*****************************************************************************
2  * vlcpeer.cpp: scriptable peer descriptor
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include "config.h"
28
29 #include <vlc/vlc.h>
30
31 #ifdef DEBUG
32 /* We do not want to use nsDebug.h */
33 #   undef DEBUG
34 #endif
35
36 #ifdef HAVE_MOZILLA_CONFIG_H
37 #   include <mozilla-config.h>
38 #endif
39 #include <nsISupports.h>
40 #include <nsMemory.h>
41 #include <npapi.h>
42
43 #if !defined(XP_MACOSX) && !defined(XP_UNIX) && !defined(XP_WIN)
44 #define XP_UNIX 1
45 #elif defined(XP_MACOSX)
46 #undef XP_UNIX
47 #endif
48
49 #include "vlcpeer.h"
50 #include "vlcplugin.h"
51
52 NS_IMPL_ISUPPORTS2( VlcPeer, VlcIntf, nsIClassInfo )
53
54 /*****************************************************************************
55  * Scriptable peer constructor and destructor
56  *****************************************************************************/
57 VlcPeer::VlcPeer()
58 {
59     NS_INIT_ISUPPORTS();
60 }
61
62 VlcPeer::VlcPeer( VlcPlugin * plugin )
63 {
64     NS_INIT_ISUPPORTS();
65     p_plugin = plugin;
66 }
67
68 VlcPeer::~VlcPeer()
69 {
70     ;
71 }
72
73 /*****************************************************************************
74  * Scriptable peer methods
75  *****************************************************************************/
76 void VlcPeer::Disable()
77 {
78     p_plugin = NULL;
79 }
80
81 /*****************************************************************************
82  * Scriptable peer plugin methods
83  *****************************************************************************/
84 NS_IMETHODIMP VlcPeer::Play()
85 {
86     if( p_plugin )
87     {
88         if( !p_plugin->b_stream && p_plugin->psz_target )
89         {
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;
93         }
94
95         VLC_Play( p_plugin->i_vlc );
96     }
97     return NS_OK;
98 }
99
100 NS_IMETHODIMP VlcPeer::Pause()
101 {
102     if( p_plugin )
103     {
104         VLC_Pause( p_plugin->i_vlc );
105     }
106     return NS_OK;
107 }
108
109 NS_IMETHODIMP VlcPeer::Stop()
110 {
111     if( p_plugin )
112     {
113         VLC_Stop( p_plugin->i_vlc );
114         p_plugin->b_stream = 0;
115     }
116     return NS_OK;
117 }
118
119 NS_IMETHODIMP VlcPeer::Fullscreen()
120 {
121     if( p_plugin )
122     {
123 #ifdef XP_MACOSX
124 #else
125         VLC_FullScreen( p_plugin->i_vlc );
126 #endif
127     }
128     return NS_OK;
129 }
130
131
132 /* Playlist control */
133 NS_IMETHODIMP VlcPeer::Clear_playlist()
134 {
135     if( p_plugin )
136     {
137         VLC_PlaylistClear( p_plugin->i_vlc );
138     }
139     return NS_OK;
140 }
141
142 NS_IMETHODIMP VlcPeer::Add_item( const char *psz_item )
143 {
144      if( p_plugin )
145      {
146           VLC_AddTarget( p_plugin->i_vlc, psz_item, NULL, 0,
147                          PLAYLIST_APPEND, PLAYLIST_END);
148      }
149      return NS_OK;
150 }
151
152
153 NS_IMETHODIMP VlcPeer::Isplaying( PRBool *b_playing )
154 {
155     if( p_plugin->i_vlc )
156     {
157         *b_playing = VLC_IsPlaying( p_plugin->i_vlc );
158     }
159     return NS_OK;
160 }
161
162 NS_IMETHODIMP VlcPeer::Get_position( PRInt64 *i_position )
163 {
164     if( p_plugin->i_vlc )
165     {
166         *i_position = (PRInt64)VLC_PositionGet( p_plugin->i_vlc );
167     }
168     return NS_OK;
169 }
170
171 NS_IMETHODIMP VlcPeer::Get_time( PRInt64 *i_time )
172 {
173     if( p_plugin->i_vlc )
174     {
175         *i_time = VLC_TimeGet( p_plugin->i_vlc );
176     }
177     return NS_OK;
178 }
179
180 NS_IMETHODIMP VlcPeer::Get_length( PRInt64 *i_length )
181 {
182     if( p_plugin->i_vlc )
183     {
184         *i_length = VLC_LengthGet( p_plugin->i_vlc );
185     }
186     return NS_OK;
187 }
188
189 NS_IMETHODIMP VlcPeer::Seek( PRInt64 i_secs, PRInt64 b_relative )
190 {
191     if( p_plugin->i_vlc )
192     {
193         VLC_TimeSet( p_plugin->i_vlc, i_secs, b_relative );
194     }
195     return NS_OK;
196 }
197
198 NS_IMETHODIMP VlcPeer::Next()
199 {
200     if( p_plugin->i_vlc )
201     {
202         VLC_PlaylistNext( p_plugin->i_vlc);
203     }
204     return NS_OK;
205 }
206
207 NS_IMETHODIMP VlcPeer::Previous()
208 {
209     if( p_plugin->i_vlc )
210     {
211         VLC_PlaylistPrev( p_plugin->i_vlc );
212     }
213     return NS_OK;
214 }
215
216 NS_IMETHODIMP VlcPeer::Set_volume( PRInt64 i_volume )
217 {
218     if( p_plugin->i_vlc )
219     {
220         VLC_VolumeSet( p_plugin->i_vlc, i_volume );
221     }
222     return NS_OK;
223 }
224
225 NS_IMETHODIMP VlcPeer::Get_volume( PRInt64 *i_volume )
226 {
227     if( p_plugin->i_vlc )
228     {
229         *i_volume = VLC_VolumeGet( p_plugin->i_vlc );
230     }
231     return NS_OK;
232 }
233
234 NS_IMETHODIMP VlcPeer::Mute()
235 {
236     if( p_plugin->i_vlc )
237     {
238         VLC_VolumeMute( p_plugin->i_vlc );
239     }
240     return NS_OK;
241 }