1 /*****************************************************************************
2 * vlcplugin.h: a VLC plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002-2009 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Damien Fouilleul <damienf@videolan.org>
9 * Jean-Paul Saman <jpsaman@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*******************************************************************************
27 * Instance state information about the plugin.
28 ******************************************************************************/
29 #ifndef __VLCPLUGIN_H__
30 #define __VLCPLUGIN_H__
34 // Setup XP_MACOSX, XP_UNIX, XP_WIN
37 #elif defined(__APPLE__)
44 #if !defined(XP_MACOSX) && !defined(XP_UNIX) && !defined(XP_WIN)
46 #elif defined(XP_MACOSX)
58 # include <Quickdraw.h>
64 # include <X11/Xlib.h>
65 # include <X11/Intrinsic.h>
66 # include <X11/StringDefs.h>
75 # define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
78 # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
81 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
87 #include "control/nporuntime.h"
91 pthread_mutex_t mutex;
95 #warning "locking not implemented in this platform"
99 typedef enum vlc_toolbar_clicked_e {
109 } vlc_toolbar_clicked_t;
112 const char *name; /* event name */
113 const libvlc_event_type_t libvlc_type; /* libvlc event type */
114 libvlc_callback_t libvlc_callback; /* libvlc callback function */
124 Listener(vlcplugin_event_t *event, NPObject *p_object, bool b_bubble):
125 _event(event), _listener(p_object), _bubble(b_bubble)
130 Listener(): _event(NULL), _listener(NULL), _bubble(false) { }
134 const libvlc_event_type_t event_type() const { return _event->libvlc_type; }
135 NPObject *listener() const { return _listener; }
136 bool bubble() const { return _bubble; }
138 vlcplugin_event_t *_event;
146 VLCEvent(libvlc_event_type_t libvlc_event_type, NPVariant *npparams, uint32_t npcount):
147 _libvlc_event_type(libvlc_event_type), _npparams(npparams), _npcount(npcount)
150 VLCEvent(): _libvlc_event_type(0), _npparams(NULL), _npcount(0) { }
154 const libvlc_event_type_t event_type() { return _libvlc_event_type; }
155 NPVariant *params() const { return _npparams; }
156 const uint32_t count() { return _npcount; }
158 libvlc_event_type_t _libvlc_event_type;
159 NPVariant *_npparams;
162 libvlc_event_manager_t *_em; /* libvlc media_player event manager */
164 EventObj(): _em(NULL) { /* deferred to init() */ }
168 void deliver(NPP browser);
169 void callback(const libvlc_event_t *event, NPVariant *npparams, uint32_t count);
170 bool insert(const NPString &name, NPObject *listener, bool bubble);
171 bool remove(const NPString &name, NPObject *listener, bool bubble);
172 void unhook_manager(void *);
173 void hook_manager(libvlc_event_manager_t *, void *);
175 vlcplugin_event_t *find_event(const char *s) const;
176 const char *find_name(const libvlc_event_t *event);
177 typedef std::vector<Listener> lr_l;
178 typedef std::vector<VLCEvent> ev_l;
179 lr_l _llist; /* list of registered listeners with 'addEventListener' method */
180 ev_l _elist; /* scheduled events list for delivery to browser */
188 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
189 VlcPlugin( NPP, uint16 );
191 VlcPlugin( NPP, uint16_t );
193 virtual ~VlcPlugin();
195 NPError init(int argc, char* const argn[], char* const argv[]);
196 libvlc_instance_t* getVLC()
197 { return libvlc_instance; };
198 libvlc_media_player_t* getMD()
200 if( !libvlc_media_player )
202 libvlc_printerr("no mediaplayer");
204 return libvlc_media_player;
207 { return p_browser; };
208 char* getAbsoluteURL(const char *url);
209 NPWindow& getWindow()
210 { return npwindow; };
211 void setWindow(const NPWindow &window)
212 { npwindow = window; };
214 NPClass* getScriptClass()
215 { return p_scriptClass; };
218 WNDPROC getWindowProc()
219 { return pf_wndproc; };
220 void setWindowProc(WNDPROC wndproc)
221 { pf_wndproc = wndproc; };
225 int setSize(unsigned width, unsigned height);
226 Window getVideoWindow()
228 void setVideoWindow(Window window)
229 { npvideo = window; };
230 Window getControlWindow()
231 { return npcontrol; };
232 void setControlWindow(Window window)
233 { npcontrol = window; };
237 void redrawToolbar();
238 void getToolbarSize(unsigned int *width, unsigned int *height)
239 { *width = i_tb_width; *height = i_tb_height; };
240 int setToolbarSize(unsigned int width, unsigned int height)
241 { i_tb_width = width; i_tb_height = height; return 1; };
242 vlc_toolbar_clicked_t getToolbarButtonClicked( int i_xpos, int i_ypos );
245 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
246 uint16 i_npmode; /* either NP_EMBED or NP_FULL */
248 uint16_t i_npmode; /* either NP_EMBED or NP_FULL */
251 /* plugin properties */
260 if( playlist_isplaying() )
262 if( libvlc_media_player||playlist_select(0) )
263 libvlc_media_player_play(libvlc_media_player);
265 void playlist_play_item(int idx)
267 if( playlist_select(idx) )
268 libvlc_media_player_play(libvlc_media_player);
272 if( libvlc_media_player )
273 libvlc_media_player_stop(libvlc_media_player);
277 if( playlist_select(playlist_index+1) )
278 libvlc_media_player_play(libvlc_media_player);
282 if( playlist_select(playlist_index-1) )
283 libvlc_media_player_play(libvlc_media_player);
285 void playlist_pause()
287 if( libvlc_media_player )
288 libvlc_media_player_pause(libvlc_media_player);
290 int playlist_isplaying()
293 if( libvlc_media_player )
294 is_playing = libvlc_media_player_is_playing(
295 libvlc_media_player );
299 int playlist_add( const char * );
300 int playlist_add_extended_untrusted( const char *, const char *, int,
302 int playlist_delete_item( int );
303 void playlist_clear();
304 int playlist_count();
306 void toggle_fullscreen();
307 void set_fullscreen( int );
308 int get_fullscreen();
310 bool player_has_vout();
313 static bool canUseEventListener();
316 static void event_callback(const libvlc_event_t *, NPVariant *, uint32_t, void *);
318 bool playlist_select(int);
319 void set_player_window();
323 libvlc_instance_t *libvlc_instance;
324 libvlc_media_list_t *libvlc_media_list;
325 libvlc_media_player_t *libvlc_media_player;
326 NPClass *p_scriptClass;
328 /* browser reference */
332 /* display settings */
338 unsigned int i_width, i_height;
339 unsigned int i_tb_width, i_tb_height;
340 Window npvideo, npcontrol;
347 XImage *p_btnFullscreen;
354 static void eventAsync(void *);
357 /*******************************************************************************
359 ******************************************************************************/
360 #define PLUGIN_NAME "VLC Web Plugin"
361 #define PLUGIN_DESCRIPTION \
362 "Version %s, copyright 1996-2010 VideoLAN and Authors" \
363 "<br><a href=\"http://www.videolan.org/\">http://www.videolan.org/</a>"
365 #define PLUGIN_MIMETYPES \
366 /* MPEG-1 and MPEG-2 */ \
367 "audio/mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
368 "audio/x-mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
369 "video/mpeg:mpg,mpeg,mpe:MPEG video;" \
370 "video/x-mpeg:mpg,mpeg,mpe:MPEG video;" \
371 "video/mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
372 "video/x-mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
374 "audio/x-mpegurl:m3u:MPEG audio;" \
376 "video/mp4:mp4,mpg4:MPEG-4 video;" \
377 "audio/mp4:mp4,mpg4:MPEG-4 audio;" \
378 "audio/x-m4a:m4a:MPEG-4 audio;" \
379 "application/mpeg4-iod:mp4,mpg4:MPEG-4 video;" \
380 "application/mpeg4-muxcodetable:mp4,mpg4:MPEG-4 video;" \
382 "video/x-msvideo:avi:AVI video;" \
384 "video/quicktime:mov,qt:QuickTime video;" \
386 "application/x-ogg:ogg:Ogg stream;" \
387 "application/ogg:ogg:Ogg stream;" \
389 "application/x-vlc-plugin:vlc:VLC plug-in;" \
390 /* Windows Media */ \
391 "video/x-ms-asf-plugin:asf,asx:Windows Media Video;" \
392 "video/x-ms-asf:asf,asx:Windows Media Video;" \
393 "application/x-mplayer2::Windows Media;" \
394 "video/x-ms-wmv:wmv:Windows Media;" \
395 "video/x-ms-wvx:wvx:Windows Media Video;" \
396 "audio/x-ms-wma:wma:Windows Media Audio;" \
398 "application/x-google-vlc-plugin::Google VLC plug-in;" \
400 "audio/wav:wav:WAV audio;" \
401 "audio/x-wav:wav:WAV audio;" \
403 "audio/3gpp:3gp,3gpp:3GPP audio;" \
404 "video/3gpp:3gp,3gpp:3GPP video;" \
406 "audio/3gpp2:3g2,3gpp2:3GPP2 audio;" \
407 "video/3gpp2:3g2,3gpp2:3GPP2 video;" \
409 "video/divx:divx:DivX video;" \
411 "video/flv:flv:FLV video;" \
412 "video/x-flv:flv:FLV video;" \
414 "video/x-matroska:mkv:Matroska video;" \
415 "audio/x-matroska:mka:Matroska audio;" \
417 "application/xspf+xml:xspf:Playlist xspf;" \
419 "video/webm:webm:WebM video;" \
420 "audio/webm:webm:WebM audio;" \
422 "application/vnd.rn-realmedia:rm:Real Media File;" \
423 "audio/x-realaudio:ra:Real Media Audio;"