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() */ }
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()
172 if( !libvlc_media_player )
174 libvlc_printerr("no mediaplayer");
176 return libvlc_media_player;
179 { return p_browser; };
180 char* getAbsoluteURL(const char *url);
181 NPWindow& getWindow()
182 { return npwindow; };
183 void setWindow(const NPWindow &window)
184 { npwindow = window; };
186 NPClass* getScriptClass()
187 { return p_scriptClass; };
190 WNDPROC getWindowProc()
191 { return pf_wndproc; };
192 void setWindowProc(WNDPROC wndproc)
193 { pf_wndproc = wndproc; };
197 int setSize(unsigned width, unsigned height);
198 Window getVideoWindow()
200 void setVideoWindow(Window window)
201 { npvideo = window; };
202 Window getControlWindow()
203 { return npcontrol; };
204 void setControlWindow(Window window)
205 { npcontrol = window; };
209 void redrawToolbar();
210 void getToolbarSize(unsigned int *width, unsigned int *height)
211 { *width = i_tb_width; *height = i_tb_height; };
212 int setToolbarSize(unsigned int width, unsigned int height)
213 { i_tb_width = width; i_tb_height = height; return 1; };
214 vlc_toolbar_clicked_t getToolbarButtonClicked( int i_xpos, int i_ypos );
217 uint16 i_npmode; /* either NP_EMBED or NP_FULL */
219 /* plugin properties */
228 if( libvlc_media_player||playlist_select(0) )
229 libvlc_media_player_play(libvlc_media_player);
231 void playlist_play_item(int idx)
233 if( playlist_select(idx) )
234 libvlc_media_player_play(libvlc_media_player);
238 if( libvlc_media_player )
239 libvlc_media_player_stop(libvlc_media_player);
243 if( playlist_select(playlist_index+1) )
244 libvlc_media_player_play(libvlc_media_player);
248 if( playlist_select(playlist_index-1) )
249 libvlc_media_player_play(libvlc_media_player);
251 void playlist_pause()
253 if( libvlc_media_player )
254 libvlc_media_player_pause(libvlc_media_player);
256 int playlist_isplaying()
259 if( libvlc_media_player )
260 is_playing = libvlc_media_player_is_playing(
261 libvlc_media_player );
265 int playlist_add( const char * );
266 int playlist_add_extended_untrusted( const char *, const char *, int,
268 int playlist_delete_item( int );
269 void playlist_clear();
270 int playlist_count();
272 void toggle_fullscreen();
273 void set_fullscreen( int );
274 int get_fullscreen();
276 bool player_has_vout();
279 static bool canUseEventListener();
283 bool playlist_select(int);
284 void set_player_window();
288 libvlc_instance_t *libvlc_instance;
289 libvlc_media_list_t *libvlc_media_list;
290 libvlc_media_player_t *libvlc_media_player;
291 NPClass *p_scriptClass;
293 /* browser reference */
297 /* display settings */
303 unsigned int i_width, i_height;
304 unsigned int i_tb_width, i_tb_height;
305 Window npvideo, npcontrol;
312 XImage *p_btnFullscreen;
319 static void eventAsync(void *);
320 static void event_callback(const libvlc_event_t *, void *);
323 /*******************************************************************************
325 ******************************************************************************/
326 #define PLUGIN_NAME "VLC Multimedia Plug-in"
327 #define PLUGIN_DESCRIPTION \
328 "Version %s, copyright 1996-2007 The VideoLAN Team" \
329 "<br><a href=\"http://www.videolan.org/\">http://www.videolan.org/</a>"
331 #define PLUGIN_MIMETYPES \
332 /* MPEG-1 and MPEG-2 */ \
333 "audio/mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
334 "audio/x-mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
335 "video/mpeg:mpg,mpeg,mpe:MPEG video;" \
336 "video/x-mpeg:mpg,mpeg,mpe:MPEG video;" \
337 "video/mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
338 "video/x-mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
340 "audio/x-mpegurl:m3u:MPEG audio;" \
342 "video/mp4:mp4,mpg4:MPEG-4 video;" \
343 "audio/mp4:mp4,mpg4:MPEG-4 audio;" \
344 "audio/x-m4a:m4a:MPEG-4 audio;" \
345 "application/mpeg4-iod:mp4,mpg4:MPEG-4 video;" \
346 "application/mpeg4-muxcodetable:mp4,mpg4:MPEG-4 video;" \
348 "video/x-msvideo:avi:AVI video;" \
350 "video/quicktime:mov,qt:QuickTime video;" \
352 "application/x-ogg:ogg:Ogg stream;" \
353 "application/ogg:ogg:Ogg stream;" \
355 "application/x-vlc-plugin:vlc:VLC plug-in;" \
356 /* Windows Media */ \
357 "video/x-ms-asf-plugin:asf,asx:Windows Media Video;" \
358 "video/x-ms-asf:asf,asx:Windows Media Video;" \
359 "application/x-mplayer2::Windows Media;" \
360 "video/x-ms-wmv:wmv:Windows Media;" \
361 "video/x-ms-wvx:wvx:Windows Media Video;" \
362 "audio/x-ms-wma:wma:Windows Media Audio;" \
364 "application/x-google-vlc-plugin::Google VLC plug-in;" \
366 "audio/wav:wav:WAV audio;" \
367 "audio/x-wav:wav:WAV audio;" \
369 "audio/3gpp:3gp,3gpp:3GPP audio;" \
370 "video/3gpp:3gp,3gpp:3GPP video;" \
372 "audio/3gpp2:3g2,3gpp2:3GPP2 audio;" \
373 "video/3gpp2:3g2,3gpp2:3GPP2 video;" \
375 "video/divx:divx:DivX video;" \
377 "video/flv:flv:FLV video;" \
378 "video/x-flv:flv:FLV video;" \
380 "video/x-matroska:mkv:Matroska video;" \
381 "audio/x-matroska:mka:Matroska audio;" \
383 "application/xspf+xml:xspf:Playlist xspf;"