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__
36 #include "control/nporuntime.h"
38 #if !defined(XP_MACOSX) && !defined(XP_UNIX) && !defined(XP_WIN)
40 #elif defined(XP_MACOSX)
52 # include <Quickdraw.h>
58 # include <X11/Xlib.h>
59 # include <X11/Intrinsic.h>
60 # include <X11/StringDefs.h>
69 # define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
72 # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
77 pthread_mutex_t mutex;
81 #warning "locking not implemented in this platform"
86 typedef enum vlc_toolbar_clicked_e {
96 } vlc_toolbar_clicked_t;
99 // Note that the accessor functions are unsafe, but this is handled in
100 // the next layer up. 64bit uints can be substituted to taste (shift=6).
101 template<size_t M> class bitmap
104 typedef uint32_t bitu_t; enum { shift=5 };
105 enum { bmax=M, bpu=1<<shift, mask=bpu-1, units=(bmax+bpu-1)/bpu };
108 bool get(size_t idx) const { return bits[idx>>shift]&(1<<(idx&mask)); }
109 void set(size_t idx) { bits[idx>>shift]|= 1<<(idx&mask); }
110 void reset(size_t idx) { bits[idx>>shift]&=~(1<<(idx&mask)); }
111 void toggle(size_t idx) { bits[idx>>shift]^= 1<<(idx&mask); }
112 size_t maxbit() const { return bmax; }
113 void clear() { memset(bits,0,sizeof(bits)); }
114 bitmap() { clear(); }
116 bool empty() const { // naive invert() will break this
117 for(size_t i=0;i<units;++i)
118 if(bits[i]) return false;
123 typedef bitmap<libvlc_VlmMediaInstanceStatusError+1> eventtypes_bitmap_t;
126 class EventObj: private eventtypes_bitmap_t
129 typedef libvlc_event_type_t event_t;
130 bool have_event(event_t e) const { return e<maxbit()?get(e):false; }
132 class Listener: public eventtypes_bitmap_t
135 Listener(event_t e,NPObject *o,bool b): _l(o), _b(b)
136 { NPN_RetainObject(o); set(e); }
137 Listener(): _l(NULL), _b(false) { }
138 ~Listener() { if(_l) NPN_ReleaseObject(_l); }
139 NPObject *listener() const { return _l; }
140 bool bubble() const { return _b; }
146 libvlc_event_manager_t *_em;
147 libvlc_callback_t _cb;
150 EventObj(): _em(NULL) { /* deferred to init() */ }
154 void deliver(NPP browser);
155 void callback(const libvlc_event_t*);
156 bool insert(const NPString &, NPObject *, bool);
157 bool remove(const NPString &, NPObject *, bool);
158 void unhook_manager();
159 void hook_manager(libvlc_event_manager_t *,libvlc_callback_t, void *);
161 event_t find_event(const char *s) const;
162 typedef std::vector<Listener> lr_l;
163 typedef std::vector<libvlc_event_type_t> ev_l;
169 bool ask_for_event(event_t e);
170 void unask_for_event(event_t e);
177 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
178 VlcPlugin( NPP, uint16 );
180 VlcPlugin( NPP, uint16_t );
182 virtual ~VlcPlugin();
184 NPError init(int argc, char* const argn[], char* const argv[]);
185 libvlc_instance_t* getVLC()
186 { return libvlc_instance; };
187 libvlc_media_player_t* getMD()
189 if( !libvlc_media_player )
191 libvlc_printerr("no mediaplayer");
193 return libvlc_media_player;
196 { return p_browser; };
197 char* getAbsoluteURL(const char *url);
198 NPWindow& getWindow()
199 { return npwindow; };
200 void setWindow(const NPWindow &window)
201 { npwindow = window; };
203 NPClass* getScriptClass()
204 { return p_scriptClass; };
207 WNDPROC getWindowProc()
208 { return pf_wndproc; };
209 void setWindowProc(WNDPROC wndproc)
210 { pf_wndproc = wndproc; };
214 int setSize(unsigned width, unsigned height);
215 Window getVideoWindow()
217 void setVideoWindow(Window window)
218 { npvideo = window; };
219 Window getControlWindow()
220 { return npcontrol; };
221 void setControlWindow(Window window)
222 { npcontrol = window; };
226 void redrawToolbar();
227 void getToolbarSize(unsigned int *width, unsigned int *height)
228 { *width = i_tb_width; *height = i_tb_height; };
229 int setToolbarSize(unsigned int width, unsigned int height)
230 { i_tb_width = width; i_tb_height = height; return 1; };
231 vlc_toolbar_clicked_t getToolbarButtonClicked( int i_xpos, int i_ypos );
234 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
235 uint16 i_npmode; /* either NP_EMBED or NP_FULL */
237 uint16_t i_npmode; /* either NP_EMBED or NP_FULL */
240 /* plugin properties */
249 if( playlist_isplaying() )
251 if( libvlc_media_player||playlist_select(0) )
252 libvlc_media_player_play(libvlc_media_player);
254 void playlist_play_item(int idx)
256 if( playlist_select(idx) )
257 libvlc_media_player_play(libvlc_media_player);
261 if( libvlc_media_player )
262 libvlc_media_player_stop(libvlc_media_player);
266 if( playlist_select(playlist_index+1) )
267 libvlc_media_player_play(libvlc_media_player);
271 if( playlist_select(playlist_index-1) )
272 libvlc_media_player_play(libvlc_media_player);
274 void playlist_pause()
276 if( libvlc_media_player )
277 libvlc_media_player_pause(libvlc_media_player);
279 int playlist_isplaying()
282 if( libvlc_media_player )
283 is_playing = libvlc_media_player_is_playing(
284 libvlc_media_player );
288 int playlist_add( const char * );
289 int playlist_add_extended_untrusted( const char *, const char *, int,
291 int playlist_delete_item( int );
292 void playlist_clear();
293 int playlist_count();
295 void toggle_fullscreen();
296 void set_fullscreen( int );
297 int get_fullscreen();
299 bool player_has_vout();
302 static bool canUseEventListener();
306 bool playlist_select(int);
307 void set_player_window();
311 libvlc_instance_t *libvlc_instance;
312 libvlc_media_list_t *libvlc_media_list;
313 libvlc_media_player_t *libvlc_media_player;
314 NPClass *p_scriptClass;
316 /* browser reference */
320 /* display settings */
326 unsigned int i_width, i_height;
327 unsigned int i_tb_width, i_tb_height;
328 Window npvideo, npcontrol;
335 XImage *p_btnFullscreen;
342 static void eventAsync(void *);
343 static void event_callback(const libvlc_event_t *, void *);
346 /*******************************************************************************
348 ******************************************************************************/
349 #define PLUGIN_NAME "VLC Multimedia Plug-in"
350 #define PLUGIN_DESCRIPTION \
351 "Version %s, copyright 1996-2007 The VideoLAN Team" \
352 "<br><a href=\"http://www.videolan.org/\">http://www.videolan.org/</a>"
354 #define PLUGIN_MIMETYPES \
355 /* MPEG-1 and MPEG-2 */ \
356 "audio/mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
357 "audio/x-mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
358 "video/mpeg:mpg,mpeg,mpe:MPEG video;" \
359 "video/x-mpeg:mpg,mpeg,mpe:MPEG video;" \
360 "video/mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
361 "video/x-mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
363 "audio/x-mpegurl:m3u:MPEG audio;" \
365 "video/mp4:mp4,mpg4:MPEG-4 video;" \
366 "audio/mp4:mp4,mpg4:MPEG-4 audio;" \
367 "audio/x-m4a:m4a:MPEG-4 audio;" \
368 "application/mpeg4-iod:mp4,mpg4:MPEG-4 video;" \
369 "application/mpeg4-muxcodetable:mp4,mpg4:MPEG-4 video;" \
371 "video/x-msvideo:avi:AVI video;" \
373 "video/quicktime:mov,qt:QuickTime video;" \
375 "application/x-ogg:ogg:Ogg stream;" \
376 "application/ogg:ogg:Ogg stream;" \
378 "application/x-vlc-plugin:vlc:VLC plug-in;" \
379 /* Windows Media */ \
380 "video/x-ms-asf-plugin:asf,asx:Windows Media Video;" \
381 "video/x-ms-asf:asf,asx:Windows Media Video;" \
382 "application/x-mplayer2::Windows Media;" \
383 "video/x-ms-wmv:wmv:Windows Media;" \
384 "video/x-ms-wvx:wvx:Windows Media Video;" \
385 "audio/x-ms-wma:wma:Windows Media Audio;" \
387 "application/x-google-vlc-plugin::Google VLC plug-in;" \
389 "audio/wav:wav:WAV audio;" \
390 "audio/x-wav:wav:WAV audio;" \
392 "audio/3gpp:3gp,3gpp:3GPP audio;" \
393 "video/3gpp:3gp,3gpp:3GPP video;" \
395 "audio/3gpp2:3g2,3gpp2:3GPP2 audio;" \
396 "video/3gpp2:3g2,3gpp2:3GPP2 video;" \
398 "video/divx:divx:DivX video;" \
400 "video/flv:flv:FLV video;" \
401 "video/x-flv:flv:FLV video;" \
403 "video/x-matroska:mkv:Matroska video;" \
404 "audio/x-matroska:mka:Matroska audio;" \
406 "application/xspf+xml:xspf:Playlist xspf;"