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__
35 #include "control/nporuntime.h"
37 #if !defined(XP_MACOSX) && !defined(XP_UNIX) && !defined(XP_WIN)
39 #elif defined(XP_MACOSX)
49 # include <Quickdraw.h>
54 # include <X11/Xlib.h>
55 # include <X11/Intrinsic.h>
56 # include <X11/StringDefs.h>
65 # define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
68 # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
71 typedef enum vlc_toolbar_clicked_e {
81 } vlc_toolbar_clicked_t;
84 // Note that the accessor functions are unsafe, but this is handled in
85 // the next layer up. 64bit uints can be substituted to taste (shift=6).
86 template<size_t M> class bitmap
89 typedef uint32_t bitu_t; enum { shift=5 };
90 enum { bmax=M, bpu=1<<shift, mask=bpu-1, units=(bmax+bpu-1)/bpu };
93 bool get(size_t idx) const
95 return bits[idx>>shift]&(1<<(idx&mask));
98 void set(size_t idx) { bits[idx>>shift]|= 1<<(idx&mask); }
99 void reset(size_t idx) { bits[idx>>shift]&=~(1<<(idx&mask)); }
100 void toggle(size_t idx) { bits[idx>>shift]^= 1<<(idx&mask); }
101 size_t maxbit() const { return bmax; }
102 void clear() { memset(bits,0,sizeof(bits)); }
103 bitmap() { clear(); }
107 typedef bitmap<libvlc_num_event_types> parent;
109 class eventtypes_bitmap_t: private bitmap<libvlc_num_event_types> {
111 typedef libvlc_event_type_t event_t;
112 event_t find_event(const char *s) const
115 for(i=0;i<maxbit();++i)
116 if(!strcmp(s,libvlc_event_type_name(i)))
121 bool add_event(const eventtypes_bitmap_t &eventBitmap)
124 for(i=0;i<maxbit();++i)
125 if (eventBitmap.have_event(i))
128 bool add_event(const char *s)
130 if (!strcmp(s, "all"))
135 if (!strcmp(s, "none"))
141 event_t event = find_event(s);
142 bool b = event<maxbit();
146 bool del_event(const char *s)
148 event_t event=find_event(s);
149 bool b=event<maxbit();
153 bool have_event(libvlc_event_type_t event) const
155 return event<maxbit()?get(event):false;
161 void set_all_events()
164 for(i=0;i<maxbit();++i)
170 // Structure used to represent an EventListener.
171 // It contains the listener object that will be invoked,
172 // An Id given by the addEventListener function and sent
173 // when invoking the listener. Can be anything or nothing.
174 // The profile associated with the listener used to invoke
175 // the listener only to some events.
176 typedef struct s_EventListener
180 eventtypes_bitmap_t eventMap;
184 void event_callback(const libvlc_event_t* event, void *param);
189 VlcPlugin( NPP, uint16 );
190 virtual ~VlcPlugin();
192 NPError init(int argc, char* const argn[], char* const argv[]);
193 libvlc_instance_t* getVLC()
194 { return libvlc_instance; };
195 libvlc_media_player_t* getMD(libvlc_exception_t *ex)
197 if( !libvlc_media_player )
199 libvlc_exception_raise(ex);
200 libvlc_printerr("no mediaplayer");
202 return libvlc_media_player;
205 { return p_browser; };
206 char* getAbsoluteURL(const char *url);
207 NPWindow& getWindow()
208 { return npwindow; };
209 void setWindow(const NPWindow &window)
210 { npwindow = window; };
212 NPClass* getScriptClass()
213 { return p_scriptClass; };
216 WNDPROC getWindowProc()
217 { return pf_wndproc; };
218 void setWindowProc(WNDPROC wndproc)
219 { pf_wndproc = wndproc; };
223 int setSize(unsigned width, unsigned height);
224 Window getVideoWindow()
226 void setVideoWindow(Window window)
227 { npvideo = window; };
228 Window getControlWindow()
229 { return npcontrol; };
230 void setControlWindow(Window window)
231 { npcontrol = window; };
235 void redrawToolbar();
236 void getToolbarSize(unsigned int *width, unsigned int *height)
237 { *width = i_tb_width; *height = i_tb_height; };
238 int setToolbarSize(unsigned int width, unsigned int height)
239 { i_tb_width = width; i_tb_height = height; return 1; };
240 vlc_toolbar_clicked_t getToolbarButtonClicked( int i_xpos, int i_ypos );
243 uint16 i_npmode; /* either NP_EMBED or NP_FULL */
245 /* plugin properties */
252 void playlist_play(libvlc_exception_t *ex)
254 if( libvlc_media_player||playlist_select(0,ex) )
255 libvlc_media_player_play(libvlc_media_player,ex);
257 void playlist_play_item(int idx,libvlc_exception_t *ex)
259 if( playlist_select(idx,ex) )
260 libvlc_media_player_play(libvlc_media_player,ex);
264 if( libvlc_media_player )
265 libvlc_media_player_stop(libvlc_media_player);
267 void playlist_next(libvlc_exception_t *ex)
269 if( playlist_select(playlist_index+1,ex) )
270 libvlc_media_player_play(libvlc_media_player,ex);
272 void playlist_prev(libvlc_exception_t *ex)
274 if( playlist_select(playlist_index-1,ex) )
275 libvlc_media_player_play(libvlc_media_player,ex);
277 void playlist_pause(libvlc_exception_t *ex)
279 if( libvlc_media_player )
280 libvlc_media_player_pause(libvlc_media_player,ex);
282 int playlist_isplaying()
285 if( libvlc_media_player )
286 is_playing = libvlc_media_player_is_playing(
287 libvlc_media_player );
291 int playlist_add( const char *, libvlc_exception_t * );
292 int playlist_add_extended_untrusted( const char *, const char *, int,
293 const char **, libvlc_exception_t * );
294 void playlist_delete_item( int, libvlc_exception_t * );
295 void playlist_clear( libvlc_exception_t * );
296 int playlist_count();
298 void toggle_fullscreen( libvlc_exception_t * );
299 void set_fullscreen( int, libvlc_exception_t * );
300 int get_fullscreen( libvlc_exception_t * );
302 bool player_has_vout( libvlc_exception_t * );
305 // Events related members
306 std::vector<EventListener*> eventListeners; // List of registered listerners.
307 std::vector<libvlc_event_type_t> eventList; // List of event sent by VLC that must be returned to JS.
308 eventtypes_bitmap_t eventToCatch;
309 pthread_mutex_t mutex;
311 static bool canUseEventListener();
314 bool playlist_select(int,libvlc_exception_t *);
315 void set_player_window();
319 libvlc_instance_t *libvlc_instance;
320 libvlc_media_list_t *libvlc_media_list;
321 libvlc_media_player_t *libvlc_media_player;
322 NPClass *p_scriptClass;
324 /* browser reference */
328 /* display settings */
334 unsigned int i_width, i_height;
335 unsigned int i_tb_width, i_tb_height;
336 Window npvideo, npcontrol;
343 XImage *p_btnFullscreen;
351 /*******************************************************************************
353 ******************************************************************************/
354 #define PLUGIN_NAME "VLC Multimedia Plug-in"
355 #define PLUGIN_DESCRIPTION \
356 "Version %s, copyright 1996-2007 The VideoLAN Team" \
357 "<br><a href=\"http://www.videolan.org/\">http://www.videolan.org/</a>"
359 #define PLUGIN_MIMETYPES \
360 /* MPEG-1 and MPEG-2 */ \
361 "audio/mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
362 "audio/x-mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
363 "video/mpeg:mpg,mpeg,mpe:MPEG video;" \
364 "video/x-mpeg:mpg,mpeg,mpe:MPEG video;" \
365 "video/mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
366 "video/x-mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
368 "audio/x-mpegurl:m3u:MPEG audio;" \
370 "video/mp4:mp4,mpg4:MPEG-4 video;" \
371 "audio/mp4:mp4,mpg4:MPEG-4 audio;" \
372 "audio/x-m4a:m4a:MPEG-4 audio;" \
373 "application/mpeg4-iod:mp4,mpg4:MPEG-4 video;" \
374 "application/mpeg4-muxcodetable:mp4,mpg4:MPEG-4 video;" \
376 "video/x-msvideo:avi:AVI video;" \
378 "video/quicktime:mov,qt:QuickTime video;" \
380 "application/x-ogg:ogg:Ogg stream;" \
381 "application/ogg:ogg:Ogg stream;" \
383 "application/x-vlc-plugin:vlc:VLC plug-in;" \
384 /* Windows Media */ \
385 "video/x-ms-asf-plugin:asf,asx:Windows Media Video;" \
386 "video/x-ms-asf:asf,asx:Windows Media Video;" \
387 "application/x-mplayer2::Windows Media;" \
388 "video/x-ms-wmv:wmv:Windows Media;" \
389 "video/x-ms-wvx:wvx:Windows Media Video;" \
390 "audio/x-ms-wma:wma:Windows Media Audio;" \
392 "application/x-google-vlc-plugin::Google VLC plug-in;" \
394 "audio/wav:wav:WAV audio;" \
395 "audio/x-wav:wav:WAV audio;" \
397 "audio/3gpp:3gp,3gpp:3GPP audio;" \
398 "video/3gpp:3gp,3gpp:3GPP video;" \
400 "audio/3gpp2:3g2,3gpp2:3GPP2 audio;" \
401 "video/3gpp2:3g2,3gpp2:3GPP2 video;" \
403 "video/divx:divx:DivX video;" \
405 "video/flv:flv:FLV video;" \
406 "video/x-flv:flv:FLV video;" \
408 "video/x-matroska:mkv:Matroska video;" \
409 "audio/x-matroska:mka:Matroska audio;" \
411 "application/xspf+xml:xspf:Playlist xspf;"