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__
34 // Setup XP_MACOSX, XP_UNIX, XP_WIN
37 #elif defined(__APPLE__)
44 #if !defined(XP_MACOSX) && !defined(XP_UNIX) && !defined(XP_WIN)
46 #elif defined(XP_MACOSX)
58 # include <Quickdraw.h>
64 # include <X11/Xlib.h>
65 # include <X11/Intrinsic.h>
66 # include <X11/StringDefs.h>
75 # define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
78 # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
84 #include "control/nporuntime.h"
89 pthread_mutex_t mutex
;
93 #warning "locking not implemented in this platform"
98 typedef enum vlc_toolbar_clicked_e
{
108 } vlc_toolbar_clicked_t
;
111 // Note that the accessor functions are unsafe, but this is handled in
112 // the next layer up. 64bit uints can be substituted to taste (shift=6).
113 template<size_t M
> class bitmap
116 typedef uint32_t bitu_t
; enum { shift
=5 };
117 enum { bmax
=M
, bpu
=1<<shift
, mask
=bpu
-1, units
=(bmax
+bpu
-1)/bpu
};
120 bool get(size_t idx
) const { return bits
[idx
>>shift
]&(1<<(idx
&mask
)); }
121 void set(size_t idx
) { bits
[idx
>>shift
]|= 1<<(idx
&mask
); }
122 void reset(size_t idx
) { bits
[idx
>>shift
]&=~(1<<(idx
&mask
)); }
123 void toggle(size_t idx
) { bits
[idx
>>shift
]^= 1<<(idx
&mask
); }
124 size_t maxbit() const { return bmax
; }
125 void clear() { memset(bits
,0,sizeof(bits
)); }
126 bitmap() { clear(); }
128 bool empty() const { // naive invert() will break this
129 for(size_t i
=0;i
<units
;++i
)
130 if(bits
[i
]) return false;
135 typedef bitmap
<libvlc_VlmMediaInstanceStatusError
+1> eventtypes_bitmap_t
;
138 class EventObj
: private eventtypes_bitmap_t
141 typedef libvlc_event_type_t event_t
;
142 bool have_event(event_t e
) const { return e
<maxbit()?get(e
):false; }
144 class Listener
: public eventtypes_bitmap_t
147 Listener(event_t e
,NPObject
*o
,bool b
): _l(o
), _b(b
)
148 { NPN_RetainObject(o
); set(e
); }
149 Listener(): _l(NULL
), _b(false) { }
150 ~Listener() { if(_l
) NPN_ReleaseObject(_l
); }
151 NPObject
*listener() const { return _l
; }
152 bool bubble() const { return _b
; }
158 libvlc_event_manager_t
*_em
;
159 libvlc_callback_t _cb
;
162 EventObj(): _em(NULL
) { /* deferred to init() */ }
166 void deliver(NPP browser
);
167 void callback(const libvlc_event_t
*);
168 bool insert(const NPString
&, NPObject
*, bool);
169 bool remove(const NPString
&, NPObject
*, bool);
170 void unhook_manager();
171 void hook_manager(libvlc_event_manager_t
*,libvlc_callback_t
, void *);
173 event_t
find_event(const char *s
) const;
174 typedef std::vector
<Listener
> lr_l
;
175 typedef std::vector
<libvlc_event_type_t
> ev_l
;
181 bool ask_for_event(event_t e
);
182 void unask_for_event(event_t e
);
189 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
190 VlcPlugin( NPP
, uint16
);
192 VlcPlugin( NPP
, uint16_t );
194 virtual ~VlcPlugin();
196 NPError
init(int argc
, char* const argn
[], char* const argv
[]);
197 libvlc_instance_t
* getVLC()
198 { return libvlc_instance
; };
199 libvlc_media_player_t
* getMD()
201 if( !libvlc_media_player
)
203 libvlc_printerr("no mediaplayer");
205 return libvlc_media_player
;
208 { return p_browser
; };
209 char* getAbsoluteURL(const char *url
);
210 NPWindow
& getWindow()
211 { return npwindow
; };
212 void setWindow(const NPWindow
&window
)
213 { npwindow
= window
; };
215 NPClass
* getScriptClass()
216 { return p_scriptClass
; };
219 WNDPROC
getWindowProc()
220 { return pf_wndproc
; };
221 void setWindowProc(WNDPROC wndproc
)
222 { pf_wndproc
= wndproc
; };
226 int setSize(unsigned width
, unsigned height
);
227 Window
getVideoWindow()
229 void setVideoWindow(Window window
)
230 { npvideo
= window
; };
231 Window
getControlWindow()
232 { return npcontrol
; };
233 void setControlWindow(Window window
)
234 { npcontrol
= window
; };
238 void redrawToolbar();
239 void getToolbarSize(unsigned int *width
, unsigned int *height
)
240 { *width
= i_tb_width
; *height
= i_tb_height
; };
241 int setToolbarSize(unsigned int width
, unsigned int height
)
242 { i_tb_width
= width
; i_tb_height
= height
; return 1; };
243 vlc_toolbar_clicked_t
getToolbarButtonClicked( int i_xpos
, int i_ypos
);
246 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
247 uint16 i_npmode
; /* either NP_EMBED or NP_FULL */
249 uint16_t i_npmode
; /* either NP_EMBED or NP_FULL */
252 /* plugin properties */
261 if( playlist_isplaying() )
263 if( libvlc_media_player
||playlist_select(0) )
264 libvlc_media_player_play(libvlc_media_player
);
266 void playlist_play_item(int idx
)
268 if( playlist_select(idx
) )
269 libvlc_media_player_play(libvlc_media_player
);
273 if( libvlc_media_player
)
274 libvlc_media_player_stop(libvlc_media_player
);
278 if( playlist_select(playlist_index
+1) )
279 libvlc_media_player_play(libvlc_media_player
);
283 if( playlist_select(playlist_index
-1) )
284 libvlc_media_player_play(libvlc_media_player
);
286 void playlist_pause()
288 if( libvlc_media_player
)
289 libvlc_media_player_pause(libvlc_media_player
);
291 int playlist_isplaying()
294 if( libvlc_media_player
)
295 is_playing
= libvlc_media_player_is_playing(
296 libvlc_media_player
);
300 int playlist_add( const char * );
301 int playlist_add_extended_untrusted( const char *, const char *, int,
303 int playlist_delete_item( int );
304 void playlist_clear();
305 int playlist_count();
307 void toggle_fullscreen();
308 void set_fullscreen( int );
309 int get_fullscreen();
311 bool player_has_vout();
314 static bool canUseEventListener();
318 bool playlist_select(int);
319 void set_player_window();
323 libvlc_instance_t
*libvlc_instance
;
324 libvlc_media_list_t
*libvlc_media_list
;
325 libvlc_media_player_t
*libvlc_media_player
;
326 NPClass
*p_scriptClass
;
328 /* browser reference */
332 /* display settings */
338 unsigned int i_width
, i_height
;
339 unsigned int i_tb_width
, i_tb_height
;
340 Window npvideo
, npcontrol
;
347 XImage
*p_btnFullscreen
;
354 static void eventAsync(void *);
355 static void event_callback(const libvlc_event_t
*, void *);
358 /*******************************************************************************
360 ******************************************************************************/
361 #define PLUGIN_NAME "VLC Multimedia Plug-in"
362 #define PLUGIN_DESCRIPTION \
363 "Version %s, copyright 1996-2007 The VideoLAN Team" \
364 "<br><a href=\"http://www.videolan.org/\">http://www.videolan.org/</a>"
366 #define PLUGIN_MIMETYPES \
367 /* MPEG-1 and MPEG-2 */ \
368 "audio/mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
369 "audio/x-mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
370 "video/mpeg:mpg,mpeg,mpe:MPEG video;" \
371 "video/x-mpeg:mpg,mpeg,mpe:MPEG video;" \
372 "video/mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
373 "video/x-mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
375 "audio/x-mpegurl:m3u:MPEG audio;" \
377 "video/mp4:mp4,mpg4:MPEG-4 video;" \
378 "audio/mp4:mp4,mpg4:MPEG-4 audio;" \
379 "audio/x-m4a:m4a:MPEG-4 audio;" \
380 "application/mpeg4-iod:mp4,mpg4:MPEG-4 video;" \
381 "application/mpeg4-muxcodetable:mp4,mpg4:MPEG-4 video;" \
383 "video/x-msvideo:avi:AVI video;" \
385 "video/quicktime:mov,qt:QuickTime video;" \
387 "application/x-ogg:ogg:Ogg stream;" \
388 "application/ogg:ogg:Ogg stream;" \
390 "application/x-vlc-plugin:vlc:VLC plug-in;" \
391 /* Windows Media */ \
392 "video/x-ms-asf-plugin:asf,asx:Windows Media Video;" \
393 "video/x-ms-asf:asf,asx:Windows Media Video;" \
394 "application/x-mplayer2::Windows Media;" \
395 "video/x-ms-wmv:wmv:Windows Media;" \
396 "video/x-ms-wvx:wvx:Windows Media Video;" \
397 "audio/x-ms-wma:wma:Windows Media Audio;" \
399 "application/x-google-vlc-plugin::Google VLC plug-in;" \
401 "audio/wav:wav:WAV audio;" \
402 "audio/x-wav:wav:WAV audio;" \
404 "audio/3gpp:3gp,3gpp:3GPP audio;" \
405 "video/3gpp:3gp,3gpp:3GPP video;" \
407 "audio/3gpp2:3g2,3gpp2:3GPP2 audio;" \
408 "video/3gpp2:3g2,3gpp2:3GPP2 video;" \
410 "video/divx:divx:DivX video;" \
412 "video/flv:flv:FLV video;" \
413 "video/x-flv:flv:FLV video;" \
415 "video/x-matroska:mkv:Matroska video;" \
416 "audio/x-matroska:mka:Matroska audio;" \
418 "application/xspf+xml:xspf:Playlist xspf;" \
420 "video/webm:webm:WebM video;" \
421 "audio/webm:webm:WebM audio;"