X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=projects%2Fmozilla%2Fvlcplugin.h;h=e625611d030d1c5155a1d65499b9cc5522aca52c;hb=7e39dc8b10afd76ab1b40844d971cdcb63e8d843;hp=39e84b892338f3cfe9bfeaba5a89a4b679cda94f;hpb=c8be4195422005d94816f3714d115f3b64c20abc;p=vlc diff --git a/projects/mozilla/vlcplugin.h b/projects/mozilla/vlcplugin.h index 39e84b8923..e625611d03 100644 --- a/projects/mozilla/vlcplugin.h +++ b/projects/mozilla/vlcplugin.h @@ -1,12 +1,12 @@ /***************************************************************************** * vlcplugin.h: a VLC plugin for Mozilla ***************************************************************************** - * Copyright (C) 2002-2008 the VideoLAN team + * Copyright (C) 2002-2009 the VideoLAN team * $Id$ * * Authors: Samuel Hocevar * Damien Fouilleul - * Jean-Paul Saman + * Jean-Paul Saman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,8 +30,16 @@ #define __VLCPLUGIN_H__ #include -#include -#include "control/nporuntime.h" + +// Setup XP_MACOSX, XP_UNIX, XP_WIN +#if defined(_WIN32) +#define XP_WIN 1 +#elif defined(__APPLE__) +#define XP_MACOSX 1 +#else +#define XP_UNIX 1 +#define MOZ_X11 1 +#endif #if !defined(XP_MACOSX) && !defined(XP_UNIX) && !defined(XP_WIN) #define XP_UNIX 1 @@ -41,6 +49,8 @@ #ifdef XP_WIN /* Windows stuff */ +# include +# include #endif #ifdef XP_MACOSX @@ -49,6 +59,7 @@ #endif #ifdef XP_UNIX +# include /* X11 stuff */ # include # include @@ -67,6 +78,24 @@ # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) ) #endif +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +#include +#include +#include + +#include "control/nporuntime.h" + +typedef struct { +#if defined(XP_UNIX) + pthread_mutex_t mutex; +#elif defined(XP_WIN) + CRITICAL_SECTION cs; +#else +#warning "locking not implemented in this platform" +#endif +} plugin_lock_t; + typedef enum vlc_toolbar_clicked_e { clicked_Unknown = 0, clicked_Play, @@ -79,20 +108,98 @@ typedef enum vlc_toolbar_clicked_e { clicked_Unmute } vlc_toolbar_clicked_t; +typedef struct { + const char *name; /* event name */ + const libvlc_event_type_t libvlc_type; /* libvlc event type */ + libvlc_callback_t libvlc_callback; /* libvlc callback function */ +} vlcplugin_event_t; + +class EventObj +{ +private: + + class Listener + { + public: + Listener(vlcplugin_event_t *event, NPObject *p_object, bool b_bubble): + _event(event), _listener(p_object), _bubble(b_bubble) + { + assert(event); + assert(p_object); + } + Listener(): _event(NULL), _listener(NULL), _bubble(false) { } + ~Listener() + { + } + const libvlc_event_type_t event_type() const { return _event->libvlc_type; } + NPObject *listener() const { return _listener; } + bool bubble() const { return _bubble; } + private: + vlcplugin_event_t *_event; + NPObject *_listener; + bool _bubble; + }; + + class VLCEvent + { + public: + VLCEvent(libvlc_event_type_t libvlc_event_type, NPVariant *npparams, uint32_t npcount): + _libvlc_event_type(libvlc_event_type), _npparams(npparams), _npcount(npcount) + { + } + VLCEvent(): _libvlc_event_type(0), _npparams(NULL), _npcount(0) { } + ~VLCEvent() + { + } + const libvlc_event_type_t event_type() { return _libvlc_event_type; } + NPVariant *params() const { return _npparams; } + const uint32_t count() { return _npcount; } + private: + libvlc_event_type_t _libvlc_event_type; + NPVariant *_npparams; + uint32_t _npcount; + }; + libvlc_event_manager_t *_em; /* libvlc media_player event manager */ +public: + EventObj(): _em(NULL) { /* deferred to init() */ } + bool init(); + ~EventObj(); + + void deliver(NPP browser); + void callback(const libvlc_event_t *event, NPVariant *npparams, uint32_t count); + bool insert(const NPString &name, NPObject *listener, bool bubble); + bool remove(const NPString &name, NPObject *listener, bool bubble); + void unhook_manager(void *); + void hook_manager(libvlc_event_manager_t *, void *); +private: + vlcplugin_event_t *find_event(const char *s) const; + const char *find_name(const libvlc_event_t *event); + typedef std::vector lr_l; + typedef std::vector ev_l; + lr_l _llist; /* list of registered listeners with 'addEventListener' method */ + ev_l _elist; /* scheduled events list for delivery to browser */ + + plugin_lock_t lock; +}; + class VlcPlugin { public: +#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20) VlcPlugin( NPP, uint16 ); +#else + VlcPlugin( NPP, uint16_t ); +#endif virtual ~VlcPlugin(); NPError init(int argc, char* const argn[], char* const argv[]); libvlc_instance_t* getVLC() { return libvlc_instance; }; - libvlc_media_player_t* getMD(libvlc_exception_t *ex) + libvlc_media_player_t* getMD() { if( !libvlc_media_player ) { - libvlc_exception_raise(ex,"null mediaplayer"); + libvlc_printerr("no mediaplayer"); } return libvlc_media_player; } @@ -107,18 +214,14 @@ public: NPClass* getScriptClass() { return p_scriptClass; }; - void setLog(libvlc_log_t *log) - { libvlc_log = log; }; - libvlc_log_t* getLog() - { return libvlc_log; }; -#if XP_WIN +#if defined(XP_WIN) WNDPROC getWindowProc() { return pf_wndproc; }; void setWindowProc(WNDPROC wndproc) { pf_wndproc = wndproc; }; #endif -#if XP_UNIX +#if defined(XP_UNIX) int setSize(unsigned width, unsigned height); Window getVideoWindow() { return npvideo; }; @@ -139,46 +242,87 @@ public: vlc_toolbar_clicked_t getToolbarButtonClicked( int i_xpos, int i_ypos ); #endif +#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20) uint16 i_npmode; /* either NP_EMBED or NP_FULL */ +#else + uint16_t i_npmode; /* either NP_EMBED or NP_FULL */ +#endif /* plugin properties */ int b_stream; int b_autoplay; int b_toolbar; + char * psz_text; char * psz_target; - bool playlist_select(int,libvlc_exception_t *); + void playlist_play() + { + if( playlist_isplaying() ) + playlist_stop(); + if( libvlc_media_player||playlist_select(0) ) + libvlc_media_player_play(libvlc_media_player); + } + void playlist_play_item(int idx) + { + if( playlist_select(idx) ) + libvlc_media_player_play(libvlc_media_player); + } + void playlist_stop() + { + if( libvlc_media_player ) + libvlc_media_player_stop(libvlc_media_player); + } + void playlist_next() + { + if( playlist_select(playlist_index+1) ) + libvlc_media_player_play(libvlc_media_player); + } + void playlist_prev() + { + if( playlist_select(playlist_index-1) ) + libvlc_media_player_play(libvlc_media_player); + } + void playlist_pause() + { + if( libvlc_media_player ) + libvlc_media_player_pause(libvlc_media_player); + } + int playlist_isplaying() + { + int is_playing = 0; + if( libvlc_media_player ) + is_playing = libvlc_media_player_is_playing( + libvlc_media_player ); + return is_playing; + } - int playlist_add( const char *, libvlc_exception_t * ); + int playlist_add( const char * ); int playlist_add_extended_untrusted( const char *, const char *, int, - const char **, libvlc_exception_t * ); - void playlist_play( libvlc_exception_t * ); - void playlist_play_item( int, libvlc_exception_t * ); - void playlist_stop( libvlc_exception_t * ); - void playlist_next( libvlc_exception_t * ); - void playlist_prev( libvlc_exception_t * ); - void playlist_pause( libvlc_exception_t * ); - void playlist_delete_item( int, libvlc_exception_t * ); + const char ** ); + int playlist_delete_item( int ); + void playlist_clear(); + int playlist_count(); + + void toggle_fullscreen(); + void set_fullscreen( int ); + int get_fullscreen(); - void playlist_clear( libvlc_exception_t * ); - int playlist_count( libvlc_exception_t * ); - int playlist_isplaying( libvlc_exception_t * ); + bool player_has_vout(); - void toggle_fullscreen( libvlc_exception_t * ); - void set_fullscreen( int, libvlc_exception_t * ); - int get_fullscreen( libvlc_exception_t * ); - int player_has_vout( libvlc_exception_t * ); + static bool canUseEventListener(); + EventObj events; + static void event_callback(const libvlc_event_t *, NPVariant *, uint32_t, void *); private: - void set_player_window( libvlc_exception_t * ); + bool playlist_select(int); + void set_player_window(); /* VLC reference */ int playlist_index; libvlc_instance_t *libvlc_instance; libvlc_media_list_t *libvlc_media_list; libvlc_media_player_t *libvlc_media_player; - libvlc_log_t *libvlc_log; NPClass *p_scriptClass; /* browser reference */ @@ -187,10 +331,10 @@ private: /* display settings */ NPWindow npwindow; -#if XP_WIN +#if defined(XP_WIN) WNDPROC pf_wndproc; #endif -#if XP_UNIX +#if defined(XP_UNIX) unsigned int i_width, i_height; unsigned int i_tb_width, i_tb_height; Window npvideo, npcontrol; @@ -206,14 +350,16 @@ private: int i_last_position; #endif + + static void eventAsync(void *); }; /******************************************************************************* * Plugin properties. ******************************************************************************/ -#define PLUGIN_NAME "VLC Multimedia Plug-in" +#define PLUGIN_NAME "VLC Web Plugin" #define PLUGIN_DESCRIPTION \ - "Version %s, copyright 1996-2007 The VideoLAN Team" \ + "Version %s, copyright 1996-2010 VideoLAN and Authors" \ "
http://www.videolan.org/" #define PLUGIN_MIMETYPES \ @@ -268,8 +414,12 @@ private: "video/x-matroska:mkv:Matroska video;" \ "audio/x-matroska:mka:Matroska audio;" \ /* XSPF */ \ - "application/xspf+xml:xspf:Playlist xspf;" - - + "application/xspf+xml:xspf:Playlist xspf;" \ + /* Webm */ \ + "video/webm:webm:WebM video;" \ + "audio/webm:webm:WebM audio;" \ + /* Real Media */ \ + "application/vnd.rn-realmedia:rm:Real Media File;" \ + "audio/x-realaudio:ra:Real Media Audio;" #endif