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_num_event_types> 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() */ }
138 bool init() { return pthread_mutex_init(&mutex, NULL) == 0; }
139 ~EventObj() { pthread_mutex_destroy(&mutex); }
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;
154 pthread_mutex_t mutex;
156 bool ask_for_event(event_t e);
157 void unask_for_event(event_t e);
164 VlcPlugin( NPP, uint16 );
165 virtual ~VlcPlugin();
167 NPError init(int argc, char* const argn[], char* const argv[]);
168 libvlc_instance_t* getVLC()
169 { return libvlc_instance; };
170 libvlc_media_player_t* getMD(libvlc_exception_t *ex)
172 if( !libvlc_media_player )
174 libvlc_exception_raise(ex);
175 libvlc_printerr("no mediaplayer");
177 return libvlc_media_player;
180 { return p_browser; };
181 char* getAbsoluteURL(const char *url);
182 NPWindow& getWindow()
183 { return npwindow; };
184 void setWindow(const NPWindow &window)
185 { npwindow = window; };
187 NPClass* getScriptClass()
188 { return p_scriptClass; };
191 WNDPROC getWindowProc()
192 { return pf_wndproc; };
193 void setWindowProc(WNDPROC wndproc)
194 { pf_wndproc = wndproc; };
198 int setSize(unsigned width, unsigned height);
199 Window getVideoWindow()
201 void setVideoWindow(Window window)
202 { npvideo = window; };
203 Window getControlWindow()
204 { return npcontrol; };
205 void setControlWindow(Window window)
206 { npcontrol = window; };
210 void redrawToolbar();
211 void getToolbarSize(unsigned int *width, unsigned int *height)
212 { *width = i_tb_width; *height = i_tb_height; };
213 int setToolbarSize(unsigned int width, unsigned int height)
214 { i_tb_width = width; i_tb_height = height; return 1; };
215 vlc_toolbar_clicked_t getToolbarButtonClicked( int i_xpos, int i_ypos );
218 uint16 i_npmode; /* either NP_EMBED or NP_FULL */
220 /* plugin properties */
227 void playlist_play(libvlc_exception_t *ex)
229 if( libvlc_media_player||playlist_select(0,ex) )
230 libvlc_media_player_play(libvlc_media_player,ex);
232 void playlist_play_item(int idx,libvlc_exception_t *ex)
234 if( playlist_select(idx,ex) )
235 libvlc_media_player_play(libvlc_media_player,ex);
239 if( libvlc_media_player )
240 libvlc_media_player_stop(libvlc_media_player);
242 void playlist_next(libvlc_exception_t *ex)
244 if( playlist_select(playlist_index+1,ex) )
245 libvlc_media_player_play(libvlc_media_player,ex);
247 void playlist_prev(libvlc_exception_t *ex)
249 if( playlist_select(playlist_index-1,ex) )
250 libvlc_media_player_play(libvlc_media_player,ex);
252 void playlist_pause(libvlc_exception_t *ex)
254 if( libvlc_media_player )
255 libvlc_media_player_pause(libvlc_media_player,ex);
257 int playlist_isplaying()
260 if( libvlc_media_player )
261 is_playing = libvlc_media_player_is_playing(
262 libvlc_media_player );
266 int playlist_add( const char *, libvlc_exception_t * );
267 int playlist_add_extended_untrusted( const char *, const char *, int,
268 const char **, libvlc_exception_t * );
269 void playlist_delete_item( int, libvlc_exception_t * );
270 void playlist_clear( libvlc_exception_t * );
271 int playlist_count();
273 void toggle_fullscreen( libvlc_exception_t * );
274 void set_fullscreen( int, libvlc_exception_t * );
275 int get_fullscreen( libvlc_exception_t * );
277 bool player_has_vout( libvlc_exception_t * );
280 static bool canUseEventListener();
284 bool playlist_select(int,libvlc_exception_t *);
285 void set_player_window();
289 libvlc_instance_t *libvlc_instance;
290 libvlc_media_list_t *libvlc_media_list;
291 libvlc_media_player_t *libvlc_media_player;
292 NPClass *p_scriptClass;
294 /* browser reference */
298 /* display settings */
304 unsigned int i_width, i_height;
305 unsigned int i_tb_width, i_tb_height;
306 Window npvideo, npcontrol;
313 XImage *p_btnFullscreen;
320 static void eventAsync(void *);
321 static void event_callback(const libvlc_event_t *, void *);
324 /*******************************************************************************
326 ******************************************************************************/
327 #define PLUGIN_NAME "VLC Multimedia Plug-in"
328 #define PLUGIN_DESCRIPTION \
329 "Version %s, copyright 1996-2007 The VideoLAN Team" \
330 "<br><a href=\"http://www.videolan.org/\">http://www.videolan.org/</a>"
332 #define PLUGIN_MIMETYPES \
333 /* MPEG-1 and MPEG-2 */ \
334 "audio/mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
335 "audio/x-mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
336 "video/mpeg:mpg,mpeg,mpe:MPEG video;" \
337 "video/x-mpeg:mpg,mpeg,mpe:MPEG video;" \
338 "video/mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
339 "video/x-mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
341 "audio/x-mpegurl:m3u:MPEG audio;" \
343 "video/mp4:mp4,mpg4:MPEG-4 video;" \
344 "audio/mp4:mp4,mpg4:MPEG-4 audio;" \
345 "audio/x-m4a:m4a:MPEG-4 audio;" \
346 "application/mpeg4-iod:mp4,mpg4:MPEG-4 video;" \
347 "application/mpeg4-muxcodetable:mp4,mpg4:MPEG-4 video;" \
349 "video/x-msvideo:avi:AVI video;" \
351 "video/quicktime:mov,qt:QuickTime video;" \
353 "application/x-ogg:ogg:Ogg stream;" \
354 "application/ogg:ogg:Ogg stream;" \
356 "application/x-vlc-plugin:vlc:VLC plug-in;" \
357 /* Windows Media */ \
358 "video/x-ms-asf-plugin:asf,asx:Windows Media Video;" \
359 "video/x-ms-asf:asf,asx:Windows Media Video;" \
360 "application/x-mplayer2::Windows Media;" \
361 "video/x-ms-wmv:wmv:Windows Media;" \
362 "video/x-ms-wvx:wvx:Windows Media Video;" \
363 "audio/x-ms-wma:wma:Windows Media Audio;" \
365 "application/x-google-vlc-plugin::Google VLC plug-in;" \
367 "audio/wav:wav:WAV audio;" \
368 "audio/x-wav:wav:WAV audio;" \
370 "audio/3gpp:3gp,3gpp:3GPP audio;" \
371 "video/3gpp:3gp,3gpp:3GPP video;" \
373 "audio/3gpp2:3g2,3gpp2:3GPP2 audio;" \
374 "video/3gpp2:3g2,3gpp2:3GPP2 video;" \
376 "video/divx:divx:DivX video;" \
378 "video/flv:flv:FLV video;" \
379 "video/x-flv:flv:FLV video;" \
381 "video/x-matroska:mkv:Matroska video;" \
382 "audio/x-matroska:mka:Matroska audio;" \
384 "application/xspf+xml:xspf:Playlist xspf;"