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__
37 #include "control/nporuntime.h"
39 #if !defined(XP_MACOSX) && !defined(XP_UNIX) && !defined(XP_WIN)
41 #elif defined(XP_MACOSX)
51 # include <Quickdraw.h>
56 # include <X11/Xlib.h>
57 # include <X11/Intrinsic.h>
58 # include <X11/StringDefs.h>
67 # define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
70 # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
73 typedef enum vlc_toolbar_clicked_e {
83 } vlc_toolbar_clicked_t;
86 // Note that the accessor functions are unsafe, but this is handled in
87 // the next layer up. 64bit uints can be substituted to taste (shift=6).
88 template<size_t M> class bitmap
91 typedef uint32_t bitu_t; enum { shift=5 };
92 enum { bmax=M, bpu=1<<shift, mask=bpu-1, units=(bmax+bpu-1)/bpu };
95 bool get(size_t idx) const { return bits[idx>>shift]&(1<<(idx&mask)); }
96 void set(size_t idx) { bits[idx>>shift]|= 1<<(idx&mask); }
97 void reset(size_t idx) { bits[idx>>shift]&=~(1<<(idx&mask)); }
98 void toggle(size_t idx) { bits[idx>>shift]^= 1<<(idx&mask); }
99 size_t maxbit() const { return bmax; }
100 void clear() { memset(bits,0,sizeof(bits)); }
101 bitmap() { clear(); }
103 bool empty() const { // naive invert() will break this
104 for(size_t i=0;i<units;++i)
105 if(bits[i]) return false;
110 typedef bitmap<libvlc_VlmMediaInstanceStatusError+1> eventtypes_bitmap_t;
113 class EventObj: private eventtypes_bitmap_t
116 typedef libvlc_event_type_t event_t;
117 bool have_event(event_t e) const { return e<maxbit()?get(e):false; }
119 class Listener: public eventtypes_bitmap_t
122 Listener(event_t e,NPObject *o,bool b): _l(o), _b(b)
123 { NPN_RetainObject(o); set(e); }
124 Listener(): _l(NULL), _b(false) { }
125 ~Listener() { if(_l) NPN_ReleaseObject(_l); }
126 NPObject *listener() const { return _l; }
127 bool bubble() const { return _b; }
133 libvlc_event_manager_t *_em;
134 libvlc_callback_t _cb;
137 EventObj(): _em(NULL) { /* deferred to init() */ }
141 void deliver(NPP browser);
142 void callback(const libvlc_event_t*);
143 bool insert(const NPString &, NPObject *, bool);
144 bool remove(const NPString &, NPObject *, bool);
145 void unhook_manager();
146 void hook_manager(libvlc_event_manager_t *,libvlc_callback_t, void *);
148 event_t find_event(const char *s) const;
149 typedef std::vector<Listener> lr_l;
150 typedef std::vector<libvlc_event_type_t> ev_l;
155 pthread_mutex_t mutex;
158 bool ask_for_event(event_t e);
159 void unask_for_event(event_t e);
166 VlcPlugin( NPP, uint16 );
167 virtual ~VlcPlugin();
169 NPError init(int argc, char* const argn[], char* const argv[]);
170 libvlc_instance_t* getVLC()
171 { return libvlc_instance; };
172 libvlc_media_player_t* getMD()
174 if( !libvlc_media_player )
176 libvlc_printerr("no mediaplayer");
178 return libvlc_media_player;
181 { return p_browser; };
182 char* getAbsoluteURL(const char *url);
183 NPWindow& getWindow()
184 { return npwindow; };
185 void setWindow(const NPWindow &window)
186 { npwindow = window; };
188 NPClass* getScriptClass()
189 { return p_scriptClass; };
192 WNDPROC getWindowProc()
193 { return pf_wndproc; };
194 void setWindowProc(WNDPROC wndproc)
195 { pf_wndproc = wndproc; };
199 int setSize(unsigned width, unsigned height);
200 Window getVideoWindow()
202 void setVideoWindow(Window window)
203 { npvideo = window; };
204 Window getControlWindow()
205 { return npcontrol; };
206 void setControlWindow(Window window)
207 { npcontrol = window; };
211 void redrawToolbar();
212 void getToolbarSize(unsigned int *width, unsigned int *height)
213 { *width = i_tb_width; *height = i_tb_height; };
214 int setToolbarSize(unsigned int width, unsigned int height)
215 { i_tb_width = width; i_tb_height = height; return 1; };
216 vlc_toolbar_clicked_t getToolbarButtonClicked( int i_xpos, int i_ypos );
219 uint16 i_npmode; /* either NP_EMBED or NP_FULL */
221 /* plugin properties */
230 if( libvlc_media_player||playlist_select(0) )
231 libvlc_media_player_play(libvlc_media_player);
233 void playlist_play_item(int idx)
235 if( playlist_select(idx) )
236 libvlc_media_player_play(libvlc_media_player);
240 if( libvlc_media_player )
241 libvlc_media_player_stop(libvlc_media_player);
245 if( playlist_select(playlist_index+1) )
246 libvlc_media_player_play(libvlc_media_player);
250 if( playlist_select(playlist_index-1) )
251 libvlc_media_player_play(libvlc_media_player);
253 void playlist_pause()
255 if( libvlc_media_player )
256 libvlc_media_player_pause(libvlc_media_player);
258 int playlist_isplaying()
261 if( libvlc_media_player )
262 is_playing = libvlc_media_player_is_playing(
263 libvlc_media_player );
267 int playlist_add( const char * );
268 int playlist_add_extended_untrusted( const char *, const char *, int,
270 int playlist_delete_item( int );
271 void playlist_clear();
272 int playlist_count();
274 void toggle_fullscreen();
275 void set_fullscreen( int );
276 int get_fullscreen();
278 bool player_has_vout();
281 static bool canUseEventListener();
285 bool playlist_select(int);
286 void set_player_window();
290 libvlc_instance_t *libvlc_instance;
291 libvlc_media_list_t *libvlc_media_list;
292 libvlc_media_player_t *libvlc_media_player;
293 NPClass *p_scriptClass;
295 /* browser reference */
299 /* display settings */
305 unsigned int i_width, i_height;
306 unsigned int i_tb_width, i_tb_height;
307 Window npvideo, npcontrol;
314 XImage *p_btnFullscreen;
321 static void eventAsync(void *);
322 static void event_callback(const libvlc_event_t *, void *);
325 /*******************************************************************************
327 ******************************************************************************/
328 #define PLUGIN_NAME "VLC Multimedia Plug-in"
329 #define PLUGIN_DESCRIPTION \
330 "Version %s, copyright 1996-2007 The VideoLAN Team" \
331 "<br><a href=\"http://www.videolan.org/\">http://www.videolan.org/</a>"
333 #define PLUGIN_MIMETYPES \
334 /* MPEG-1 and MPEG-2 */ \
335 "audio/mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
336 "audio/x-mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
337 "video/mpeg:mpg,mpeg,mpe:MPEG video;" \
338 "video/x-mpeg:mpg,mpeg,mpe:MPEG video;" \
339 "video/mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
340 "video/x-mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
342 "audio/x-mpegurl:m3u:MPEG audio;" \
344 "video/mp4:mp4,mpg4:MPEG-4 video;" \
345 "audio/mp4:mp4,mpg4:MPEG-4 audio;" \
346 "audio/x-m4a:m4a:MPEG-4 audio;" \
347 "application/mpeg4-iod:mp4,mpg4:MPEG-4 video;" \
348 "application/mpeg4-muxcodetable:mp4,mpg4:MPEG-4 video;" \
350 "video/x-msvideo:avi:AVI video;" \
352 "video/quicktime:mov,qt:QuickTime video;" \
354 "application/x-ogg:ogg:Ogg stream;" \
355 "application/ogg:ogg:Ogg stream;" \
357 "application/x-vlc-plugin:vlc:VLC plug-in;" \
358 /* Windows Media */ \
359 "video/x-ms-asf-plugin:asf,asx:Windows Media Video;" \
360 "video/x-ms-asf:asf,asx:Windows Media Video;" \
361 "application/x-mplayer2::Windows Media;" \
362 "video/x-ms-wmv:wmv:Windows Media;" \
363 "video/x-ms-wvx:wvx:Windows Media Video;" \
364 "audio/x-ms-wma:wma:Windows Media Audio;" \
366 "application/x-google-vlc-plugin::Google VLC plug-in;" \
368 "audio/wav:wav:WAV audio;" \
369 "audio/x-wav:wav:WAV audio;" \
371 "audio/3gpp:3gp,3gpp:3GPP audio;" \
372 "video/3gpp:3gp,3gpp:3GPP video;" \
374 "audio/3gpp2:3g2,3gpp2:3GPP2 audio;" \
375 "video/3gpp2:3g2,3gpp2:3GPP2 video;" \
377 "video/divx:divx:DivX video;" \
379 "video/flv:flv:FLV video;" \
380 "video/x-flv:flv:FLV video;" \
382 "video/x-matroska:mkv:Matroska video;" \
383 "audio/x-matroska:mka:Matroska audio;" \
385 "application/xspf+xml:xspf:Playlist xspf;"