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)
51 # include <Quickdraw.h>
57 # include <X11/Xlib.h>
58 # include <X11/Intrinsic.h>
59 # include <X11/StringDefs.h>
68 # define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
71 # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
76 pthread_mutex_t mutex;
80 #warning "locking not implemented in this platform"
85 typedef enum vlc_toolbar_clicked_e {
95 } vlc_toolbar_clicked_t;
98 // Note that the accessor functions are unsafe, but this is handled in
99 // the next layer up. 64bit uints can be substituted to taste (shift=6).
100 template<size_t M> class bitmap
103 typedef uint32_t bitu_t; enum { shift=5 };
104 enum { bmax=M, bpu=1<<shift, mask=bpu-1, units=(bmax+bpu-1)/bpu };
107 bool get(size_t idx) const { return bits[idx>>shift]&(1<<(idx&mask)); }
108 void set(size_t idx) { bits[idx>>shift]|= 1<<(idx&mask); }
109 void reset(size_t idx) { bits[idx>>shift]&=~(1<<(idx&mask)); }
110 void toggle(size_t idx) { bits[idx>>shift]^= 1<<(idx&mask); }
111 size_t maxbit() const { return bmax; }
112 void clear() { memset(bits,0,sizeof(bits)); }
113 bitmap() { clear(); }
115 bool empty() const { // naive invert() will break this
116 for(size_t i=0;i<units;++i)
117 if(bits[i]) return false;
122 typedef bitmap<libvlc_VlmMediaInstanceStatusError+1> eventtypes_bitmap_t;
125 class EventObj: private eventtypes_bitmap_t
128 typedef libvlc_event_type_t event_t;
129 bool have_event(event_t e) const { return e<maxbit()?get(e):false; }
131 class Listener: public eventtypes_bitmap_t
134 Listener(event_t e,NPObject *o,bool b): _l(o), _b(b)
135 { NPN_RetainObject(o); set(e); }
136 Listener(): _l(NULL), _b(false) { }
137 ~Listener() { if(_l) NPN_ReleaseObject(_l); }
138 NPObject *listener() const { return _l; }
139 bool bubble() const { return _b; }
145 libvlc_event_manager_t *_em;
146 libvlc_callback_t _cb;
149 EventObj(): _em(NULL) { /* deferred to init() */ }
153 void deliver(NPP browser);
154 void callback(const libvlc_event_t*);
155 bool insert(const NPString &, NPObject *, bool);
156 bool remove(const NPString &, NPObject *, bool);
157 void unhook_manager();
158 void hook_manager(libvlc_event_manager_t *,libvlc_callback_t, void *);
160 event_t find_event(const char *s) const;
161 typedef std::vector<Listener> lr_l;
162 typedef std::vector<libvlc_event_type_t> ev_l;
168 bool ask_for_event(event_t e);
169 void unask_for_event(event_t e);
176 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
177 VlcPlugin( NPP, uint16 );
179 VlcPlugin( NPP, uint16_t );
181 virtual ~VlcPlugin();
183 NPError init(int argc, char* const argn[], char* const argv[]);
184 libvlc_instance_t* getVLC()
185 { return libvlc_instance; };
186 libvlc_media_player_t* getMD()
188 if( !libvlc_media_player )
190 libvlc_printerr("no mediaplayer");
192 return libvlc_media_player;
195 { return p_browser; };
196 char* getAbsoluteURL(const char *url);
197 NPWindow& getWindow()
198 { return npwindow; };
199 void setWindow(const NPWindow &window)
200 { npwindow = window; };
202 NPClass* getScriptClass()
203 { return p_scriptClass; };
206 WNDPROC getWindowProc()
207 { return pf_wndproc; };
208 void setWindowProc(WNDPROC wndproc)
209 { pf_wndproc = wndproc; };
213 int setSize(unsigned width, unsigned height);
214 Window getVideoWindow()
216 void setVideoWindow(Window window)
217 { npvideo = window; };
218 Window getControlWindow()
219 { return npcontrol; };
220 void setControlWindow(Window window)
221 { npcontrol = window; };
225 void redrawToolbar();
226 void getToolbarSize(unsigned int *width, unsigned int *height)
227 { *width = i_tb_width; *height = i_tb_height; };
228 int setToolbarSize(unsigned int width, unsigned int height)
229 { i_tb_width = width; i_tb_height = height; return 1; };
230 vlc_toolbar_clicked_t getToolbarButtonClicked( int i_xpos, int i_ypos );
233 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
234 uint16 i_npmode; /* either NP_EMBED or NP_FULL */
236 uint16_t i_npmode; /* either NP_EMBED or NP_FULL */
239 /* plugin properties */
248 if( playlist_isplaying() )
250 if( libvlc_media_player||playlist_select(0) )
251 libvlc_media_player_play(libvlc_media_player);
253 void playlist_play_item(int idx)
255 if( playlist_select(idx) )
256 libvlc_media_player_play(libvlc_media_player);
260 if( libvlc_media_player )
261 libvlc_media_player_stop(libvlc_media_player);
265 if( playlist_select(playlist_index+1) )
266 libvlc_media_player_play(libvlc_media_player);
270 if( playlist_select(playlist_index-1) )
271 libvlc_media_player_play(libvlc_media_player);
273 void playlist_pause()
275 if( libvlc_media_player )
276 libvlc_media_player_pause(libvlc_media_player);
278 int playlist_isplaying()
281 if( libvlc_media_player )
282 is_playing = libvlc_media_player_is_playing(
283 libvlc_media_player );
287 int playlist_add( const char * );
288 int playlist_add_extended_untrusted( const char *, const char *, int,
290 int playlist_delete_item( int );
291 void playlist_clear();
292 int playlist_count();
294 void toggle_fullscreen();
295 void set_fullscreen( int );
296 int get_fullscreen();
298 bool player_has_vout();
301 static bool canUseEventListener();
305 bool playlist_select(int);
306 void set_player_window();
310 libvlc_instance_t *libvlc_instance;
311 libvlc_media_list_t *libvlc_media_list;
312 libvlc_media_player_t *libvlc_media_player;
313 NPClass *p_scriptClass;
315 /* browser reference */
319 /* display settings */
325 unsigned int i_width, i_height;
326 unsigned int i_tb_width, i_tb_height;
327 Window npvideo, npcontrol;
334 XImage *p_btnFullscreen;
341 static void eventAsync(void *);
342 static void event_callback(const libvlc_event_t *, void *);
345 /*******************************************************************************
347 ******************************************************************************/
348 #define PLUGIN_NAME "VLC Multimedia Plug-in"
349 #define PLUGIN_DESCRIPTION \
350 "Version %s, copyright 1996-2007 The VideoLAN Team" \
351 "<br><a href=\"http://www.videolan.org/\">http://www.videolan.org/</a>"
353 #define PLUGIN_MIMETYPES \
354 /* MPEG-1 and MPEG-2 */ \
355 "audio/mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
356 "audio/x-mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
357 "video/mpeg:mpg,mpeg,mpe:MPEG video;" \
358 "video/x-mpeg:mpg,mpeg,mpe:MPEG video;" \
359 "video/mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
360 "video/x-mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
362 "audio/x-mpegurl:m3u:MPEG audio;" \
364 "video/mp4:mp4,mpg4:MPEG-4 video;" \
365 "audio/mp4:mp4,mpg4:MPEG-4 audio;" \
366 "audio/x-m4a:m4a:MPEG-4 audio;" \
367 "application/mpeg4-iod:mp4,mpg4:MPEG-4 video;" \
368 "application/mpeg4-muxcodetable:mp4,mpg4:MPEG-4 video;" \
370 "video/x-msvideo:avi:AVI video;" \
372 "video/quicktime:mov,qt:QuickTime video;" \
374 "application/x-ogg:ogg:Ogg stream;" \
375 "application/ogg:ogg:Ogg stream;" \
377 "application/x-vlc-plugin:vlc:VLC plug-in;" \
378 /* Windows Media */ \
379 "video/x-ms-asf-plugin:asf,asx:Windows Media Video;" \
380 "video/x-ms-asf:asf,asx:Windows Media Video;" \
381 "application/x-mplayer2::Windows Media;" \
382 "video/x-ms-wmv:wmv:Windows Media;" \
383 "video/x-ms-wvx:wvx:Windows Media Video;" \
384 "audio/x-ms-wma:wma:Windows Media Audio;" \
386 "application/x-google-vlc-plugin::Google VLC plug-in;" \
388 "audio/wav:wav:WAV audio;" \
389 "audio/x-wav:wav:WAV audio;" \
391 "audio/3gpp:3gp,3gpp:3GPP audio;" \
392 "video/3gpp:3gp,3gpp:3GPP video;" \
394 "audio/3gpp2:3g2,3gpp2:3GPP2 audio;" \
395 "video/3gpp2:3g2,3gpp2:3GPP2 video;" \
397 "video/divx:divx:DivX video;" \
399 "video/flv:flv:FLV video;" \
400 "video/x-flv:flv:FLV video;" \
402 "video/x-matroska:mkv:Matroska video;" \
403 "audio/x-matroska:mka:Matroska audio;" \
405 "application/xspf+xml:xspf:Playlist xspf;"