lua: factorize the right way.
[vlc/asuraparaju-public.git] / projects / mozilla / vlcplugin.h
blobe625611d030d1c5155a1d65499b9cc5522aca52c
1 /*****************************************************************************
2 * vlcplugin.h: a VLC plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002-2009 the VideoLAN team
5 * $Id$
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__
32 #include <vlc/vlc.h>
34 // Setup XP_MACOSX, XP_UNIX, XP_WIN
35 #if defined(_WIN32)
36 #define XP_WIN 1
37 #elif defined(__APPLE__)
38 #define XP_MACOSX 1
39 #else
40 #define XP_UNIX 1
41 #define MOZ_X11 1
42 #endif
44 #if !defined(XP_MACOSX) && !defined(XP_UNIX) && !defined(XP_WIN)
45 #define XP_UNIX 1
46 #elif defined(XP_MACOSX)
47 #undef XP_UNIX
48 #endif
50 #ifdef XP_WIN
51 /* Windows stuff */
52 # include <windows.h>
53 # include <winbase.h>
54 #endif
56 #ifdef XP_MACOSX
57 /* Mac OS X stuff */
58 # include <Quickdraw.h>
59 #endif
61 #ifdef XP_UNIX
62 # include <pthread.h>
63 /* X11 stuff */
64 # include <X11/Xlib.h>
65 # include <X11/Intrinsic.h>
66 # include <X11/StringDefs.h>
67 # include <X11/X.h>
69 # ifndef __APPLE__
70 # include <X11/xpm.h>
71 # endif
72 #endif
74 #ifndef __MAX
75 # define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
76 #endif
77 #ifndef __MIN
78 # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
79 #endif
81 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
83 #include <npapi.h>
84 #include <vector>
85 #include <assert.h>
87 #include "control/nporuntime.h"
89 typedef struct {
90 #if defined(XP_UNIX)
91 pthread_mutex_t mutex;
92 #elif defined(XP_WIN)
93 CRITICAL_SECTION cs;
94 #else
95 #warning "locking not implemented in this platform"
96 #endif
97 } plugin_lock_t;
99 typedef enum vlc_toolbar_clicked_e {
100 clicked_Unknown = 0,
101 clicked_Play,
102 clicked_Pause,
103 clicked_Stop,
104 clicked_timeline,
105 clicked_Time,
106 clicked_Fullscreen,
107 clicked_Mute,
108 clicked_Unmute
109 } vlc_toolbar_clicked_t;
111 typedef struct {
112 const char *name; /* event name */
113 const libvlc_event_type_t libvlc_type; /* libvlc event type */
114 libvlc_callback_t libvlc_callback; /* libvlc callback function */
115 } vlcplugin_event_t;
117 class EventObj
119 private:
121 class Listener
123 public:
124 Listener(vlcplugin_event_t *event, NPObject *p_object, bool b_bubble):
125 _event(event), _listener(p_object), _bubble(b_bubble)
127 assert(event);
128 assert(p_object);
130 Listener(): _event(NULL), _listener(NULL), _bubble(false) { }
131 ~Listener()
134 const libvlc_event_type_t event_type() const { return _event->libvlc_type; }
135 NPObject *listener() const { return _listener; }
136 bool bubble() const { return _bubble; }
137 private:
138 vlcplugin_event_t *_event;
139 NPObject *_listener;
140 bool _bubble;
143 class VLCEvent
145 public:
146 VLCEvent(libvlc_event_type_t libvlc_event_type, NPVariant *npparams, uint32_t npcount):
147 _libvlc_event_type(libvlc_event_type), _npparams(npparams), _npcount(npcount)
150 VLCEvent(): _libvlc_event_type(0), _npparams(NULL), _npcount(0) { }
151 ~VLCEvent()
154 const libvlc_event_type_t event_type() { return _libvlc_event_type; }
155 NPVariant *params() const { return _npparams; }
156 const uint32_t count() { return _npcount; }
157 private:
158 libvlc_event_type_t _libvlc_event_type;
159 NPVariant *_npparams;
160 uint32_t _npcount;
162 libvlc_event_manager_t *_em; /* libvlc media_player event manager */
163 public:
164 EventObj(): _em(NULL) { /* deferred to init() */ }
165 bool init();
166 ~EventObj();
168 void deliver(NPP browser);
169 void callback(const libvlc_event_t *event, NPVariant *npparams, uint32_t count);
170 bool insert(const NPString &name, NPObject *listener, bool bubble);
171 bool remove(const NPString &name, NPObject *listener, bool bubble);
172 void unhook_manager(void *);
173 void hook_manager(libvlc_event_manager_t *, void *);
174 private:
175 vlcplugin_event_t *find_event(const char *s) const;
176 const char *find_name(const libvlc_event_t *event);
177 typedef std::vector<Listener> lr_l;
178 typedef std::vector<VLCEvent> ev_l;
179 lr_l _llist; /* list of registered listeners with 'addEventListener' method */
180 ev_l _elist; /* scheduled events list for delivery to browser */
182 plugin_lock_t lock;
185 class VlcPlugin
187 public:
188 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
189 VlcPlugin( NPP, uint16 );
190 #else
191 VlcPlugin( NPP, uint16_t );
192 #endif
193 virtual ~VlcPlugin();
195 NPError init(int argc, char* const argn[], char* const argv[]);
196 libvlc_instance_t* getVLC()
197 { return libvlc_instance; };
198 libvlc_media_player_t* getMD()
200 if( !libvlc_media_player )
202 libvlc_printerr("no mediaplayer");
204 return libvlc_media_player;
206 NPP getBrowser()
207 { return p_browser; };
208 char* getAbsoluteURL(const char *url);
209 NPWindow& getWindow()
210 { return npwindow; };
211 void setWindow(const NPWindow &window)
212 { npwindow = window; };
214 NPClass* getScriptClass()
215 { return p_scriptClass; };
217 #if defined(XP_WIN)
218 WNDPROC getWindowProc()
219 { return pf_wndproc; };
220 void setWindowProc(WNDPROC wndproc)
221 { pf_wndproc = wndproc; };
222 #endif
224 #if defined(XP_UNIX)
225 int setSize(unsigned width, unsigned height);
226 Window getVideoWindow()
227 { return npvideo; };
228 void setVideoWindow(Window window)
229 { npvideo = window; };
230 Window getControlWindow()
231 { return npcontrol; };
232 void setControlWindow(Window window)
233 { npcontrol = window; };
235 void showToolbar();
236 void hideToolbar();
237 void redrawToolbar();
238 void getToolbarSize(unsigned int *width, unsigned int *height)
239 { *width = i_tb_width; *height = i_tb_height; };
240 int setToolbarSize(unsigned int width, unsigned int height)
241 { i_tb_width = width; i_tb_height = height; return 1; };
242 vlc_toolbar_clicked_t getToolbarButtonClicked( int i_xpos, int i_ypos );
243 #endif
245 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
246 uint16 i_npmode; /* either NP_EMBED or NP_FULL */
247 #else
248 uint16_t i_npmode; /* either NP_EMBED or NP_FULL */
249 #endif
251 /* plugin properties */
252 int b_stream;
253 int b_autoplay;
254 int b_toolbar;
255 char * psz_text;
256 char * psz_target;
258 void playlist_play()
260 if( playlist_isplaying() )
261 playlist_stop();
262 if( libvlc_media_player||playlist_select(0) )
263 libvlc_media_player_play(libvlc_media_player);
265 void playlist_play_item(int idx)
267 if( playlist_select(idx) )
268 libvlc_media_player_play(libvlc_media_player);
270 void playlist_stop()
272 if( libvlc_media_player )
273 libvlc_media_player_stop(libvlc_media_player);
275 void playlist_next()
277 if( playlist_select(playlist_index+1) )
278 libvlc_media_player_play(libvlc_media_player);
280 void playlist_prev()
282 if( playlist_select(playlist_index-1) )
283 libvlc_media_player_play(libvlc_media_player);
285 void playlist_pause()
287 if( libvlc_media_player )
288 libvlc_media_player_pause(libvlc_media_player);
290 int playlist_isplaying()
292 int is_playing = 0;
293 if( libvlc_media_player )
294 is_playing = libvlc_media_player_is_playing(
295 libvlc_media_player );
296 return is_playing;
299 int playlist_add( const char * );
300 int playlist_add_extended_untrusted( const char *, const char *, int,
301 const char ** );
302 int playlist_delete_item( int );
303 void playlist_clear();
304 int playlist_count();
306 void toggle_fullscreen();
307 void set_fullscreen( int );
308 int get_fullscreen();
310 bool player_has_vout();
313 static bool canUseEventListener();
315 EventObj events;
316 static void event_callback(const libvlc_event_t *, NPVariant *, uint32_t, void *);
317 private:
318 bool playlist_select(int);
319 void set_player_window();
321 /* VLC reference */
322 int playlist_index;
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 */
329 NPP p_browser;
330 char* psz_baseURL;
332 /* display settings */
333 NPWindow npwindow;
334 #if defined(XP_WIN)
335 WNDPROC pf_wndproc;
336 #endif
337 #if defined(XP_UNIX)
338 unsigned int i_width, i_height;
339 unsigned int i_tb_width, i_tb_height;
340 Window npvideo, npcontrol;
342 XImage *p_btnPlay;
343 XImage *p_btnPause;
344 XImage *p_btnStop;
345 XImage *p_timeline;
346 XImage *p_btnTime;
347 XImage *p_btnFullscreen;
348 XImage *p_btnMute;
349 XImage *p_btnUnmute;
351 int i_last_position;
352 #endif
354 static void eventAsync(void *);
357 /*******************************************************************************
358 * Plugin properties.
359 ******************************************************************************/
360 #define PLUGIN_NAME "VLC Web Plugin"
361 #define PLUGIN_DESCRIPTION \
362 "Version %s, copyright 1996-2010 VideoLAN and Authors" \
363 "<br><a href=\"http://www.videolan.org/\">http://www.videolan.org/</a>"
365 #define PLUGIN_MIMETYPES \
366 /* MPEG-1 and MPEG-2 */ \
367 "audio/mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
368 "audio/x-mpeg:mp2,mp3,mpga,mpega:MPEG audio;" \
369 "video/mpeg:mpg,mpeg,mpe:MPEG video;" \
370 "video/x-mpeg:mpg,mpeg,mpe:MPEG video;" \
371 "video/mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
372 "video/x-mpeg-system:mpg,mpeg,mpe,vob:MPEG video;" \
373 /* M3U */ \
374 "audio/x-mpegurl:m3u:MPEG audio;" \
375 /* MPEG-4 */ \
376 "video/mp4:mp4,mpg4:MPEG-4 video;" \
377 "audio/mp4:mp4,mpg4:MPEG-4 audio;" \
378 "audio/x-m4a:m4a:MPEG-4 audio;" \
379 "application/mpeg4-iod:mp4,mpg4:MPEG-4 video;" \
380 "application/mpeg4-muxcodetable:mp4,mpg4:MPEG-4 video;" \
381 /* AVI */ \
382 "video/x-msvideo:avi:AVI video;" \
383 /* QuickTime */ \
384 "video/quicktime:mov,qt:QuickTime video;" \
385 /* OGG */ \
386 "application/x-ogg:ogg:Ogg stream;" \
387 "application/ogg:ogg:Ogg stream;" \
388 /* VLC */ \
389 "application/x-vlc-plugin:vlc:VLC plug-in;" \
390 /* Windows Media */ \
391 "video/x-ms-asf-plugin:asf,asx:Windows Media Video;" \
392 "video/x-ms-asf:asf,asx:Windows Media Video;" \
393 "application/x-mplayer2::Windows Media;" \
394 "video/x-ms-wmv:wmv:Windows Media;" \
395 "video/x-ms-wvx:wvx:Windows Media Video;" \
396 "audio/x-ms-wma:wma:Windows Media Audio;" \
397 /* Google VLC */ \
398 "application/x-google-vlc-plugin::Google VLC plug-in;" \
399 /* WAV audio */ \
400 "audio/wav:wav:WAV audio;" \
401 "audio/x-wav:wav:WAV audio;" \
402 /* 3GPP */ \
403 "audio/3gpp:3gp,3gpp:3GPP audio;" \
404 "video/3gpp:3gp,3gpp:3GPP video;" \
405 /* 3GPP2 */ \
406 "audio/3gpp2:3g2,3gpp2:3GPP2 audio;" \
407 "video/3gpp2:3g2,3gpp2:3GPP2 video;" \
408 /* DIVX */ \
409 "video/divx:divx:DivX video;" \
410 /* FLV */ \
411 "video/flv:flv:FLV video;" \
412 "video/x-flv:flv:FLV video;" \
413 /* Matroska */ \
414 "video/x-matroska:mkv:Matroska video;" \
415 "audio/x-matroska:mka:Matroska audio;" \
416 /* XSPF */ \
417 "application/xspf+xml:xspf:Playlist xspf;" \
418 /* Webm */ \
419 "video/webm:webm:WebM video;" \
420 "audio/webm:webm:WebM audio;" \
421 /* Real Media */ \
422 "application/vnd.rn-realmedia:rm:Real Media File;" \
423 "audio/x-realaudio:ra:Real Media Audio;"
425 #endif