#define __VLCPLUGIN_H__
#include <vlc/vlc.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
+
#include <npapi.h>
#include <vector>
+
#include "control/nporuntime.h"
#if !defined(XP_MACOSX) && !defined(XP_UNIX) && !defined(XP_WIN)
#ifdef XP_WIN
/* Windows stuff */
+# include <winbase.h>
+# include <windows.h>
#endif
#ifdef XP_MACOSX
#endif
#ifdef XP_UNIX
+# include <pthread.h>
/* X11 stuff */
# include <X11/Xlib.h>
# include <X11/Intrinsic.h>
# define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
#endif
+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,
enum { bmax=M, bpu=1<<shift, mask=bpu-1, units=(bmax+bpu-1)/bpu };
bitu_t bits[units];
public:
- bool get(size_t idx) const
- {
- return bits[idx>>shift]&(1<<(idx&mask));
- }
-
+ bool get(size_t idx) const { return bits[idx>>shift]&(1<<(idx&mask)); }
void set(size_t idx) { bits[idx>>shift]|= 1<<(idx&mask); }
void reset(size_t idx) { bits[idx>>shift]&=~(1<<(idx&mask)); }
void toggle(size_t idx) { bits[idx>>shift]^= 1<<(idx&mask); }
void clear() { memset(bits,0,sizeof(bits)); }
bitmap() { clear(); }
~bitmap() { }
+ bool empty() const { // naive invert() will break this
+ for(size_t i=0;i<units;++i)
+ if(bits[i]) return false;
+ return true;
+ }
};
-typedef bitmap<libvlc_num_event_types> parent;
+typedef bitmap<libvlc_VlmMediaInstanceStatusError+1> eventtypes_bitmap_t;
-class eventtypes_bitmap_t: private bitmap<libvlc_num_event_types> {
+
+class EventObj: private eventtypes_bitmap_t
+{
private:
typedef libvlc_event_type_t event_t;
- event_t find_event(const char *s) const
- {
- event_t i;
- for(i=0;i<maxbit();++i)
- if(!strcmp(s,libvlc_event_type_name(i)))
- break;
- return i;
- }
-public:
- bool add_event(const eventtypes_bitmap_t &eventBitmap)
- {
- event_t i;
- for(i=0;i<maxbit();++i)
- if (eventBitmap.have_event(i))
- set(i);
- }
- bool add_event(const char *s)
- {
- if (!strcmp(s, "all"))
- {
- set_all_events();
- return true;
- }
- if (!strcmp(s, "none"))
- {
- clear();
- return true;
- }
+ bool have_event(event_t e) const { return e<maxbit()?get(e):false; }
- event_t event = find_event(s);
- bool b = event<maxbit();
- if(b) set(event);
- return b;
- }
- bool del_event(const char *s)
- {
- event_t event=find_event(s);
- bool b=event<maxbit();
- if(b) reset(event);
- return b;
- }
- bool have_event(libvlc_event_type_t event) const
- {
- return event<maxbit()?get(event):false;
- }
- void clear()
- {
- parent::clear();
- }
- void set_all_events()
+ class Listener: public eventtypes_bitmap_t
{
- event_t i;
- for(i=0;i<maxbit();++i)
- set(i);
- }
-};
+ public:
+ Listener(event_t e,NPObject *o,bool b): _l(o), _b(b)
+ { NPN_RetainObject(o); set(e); }
+ Listener(): _l(NULL), _b(false) { }
+ ~Listener() { if(_l) NPN_ReleaseObject(_l); }
+ NPObject *listener() const { return _l; }
+ bool bubble() const { return _b; }
+ private:
+ NPObject *_l;
+ bool _b;
+ };
+
+ libvlc_event_manager_t *_em;
+ libvlc_callback_t _cb;
+ void *_ud;
+public:
+ EventObj(): _em(NULL) { /* deferred to init() */ }
+ bool init();
+ ~EventObj();
+
+ void deliver(NPP browser);
+ void callback(const libvlc_event_t*);
+ bool insert(const NPString &, NPObject *, bool);
+ bool remove(const NPString &, NPObject *, bool);
+ void unhook_manager();
+ void hook_manager(libvlc_event_manager_t *,libvlc_callback_t, void *);
+private:
+ event_t find_event(const char *s) const;
+ typedef std::vector<Listener> lr_l;
+ typedef std::vector<libvlc_event_type_t> ev_l;
+ lr_l _llist;
+ ev_l _elist;
+ plugin_lock_t lock;
-// Structure used to represent an EventListener.
-// It contains the listener object that will be invoked,
-// An Id given by the addEventListener function and sent
-// when invoking the listener. Can be anything or nothing.
-// The profile associated with the listener used to invoke
-// the listener only to some events.
-typedef struct s_EventListener
-{
- NPObject *listener;
- NPVariant id;
- eventtypes_bitmap_t eventMap;
-
-} EventListener;
+ bool ask_for_event(event_t e);
+ void unask_for_event(event_t e);
+};
-void event_callback(const libvlc_event_t* event, void *param);
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);
libvlc_printerr("no mediaplayer");
}
return libvlc_media_player;
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;
char * psz_text;
char * psz_target;
- void playlist_play(libvlc_exception_t *ex)
+ void playlist_play()
{
- if( libvlc_media_player||playlist_select(0,ex) )
- libvlc_media_player_play(libvlc_media_player,ex);
+ 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,libvlc_exception_t *ex)
+ void playlist_play_item(int idx)
{
- if( playlist_select(idx,ex) )
- libvlc_media_player_play(libvlc_media_player,ex);
+ 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(libvlc_exception_t *ex)
+ void playlist_next()
{
- if( playlist_select(playlist_index+1,ex) )
- libvlc_media_player_play(libvlc_media_player,ex);
+ if( playlist_select(playlist_index+1) )
+ libvlc_media_player_play(libvlc_media_player);
}
- void playlist_prev(libvlc_exception_t *ex)
+ void playlist_prev()
{
- if( playlist_select(playlist_index-1,ex) )
- libvlc_media_player_play(libvlc_media_player,ex);
+ if( playlist_select(playlist_index-1) )
+ libvlc_media_player_play(libvlc_media_player);
}
- void playlist_pause(libvlc_exception_t *ex)
+ void playlist_pause()
{
if( libvlc_media_player )
- libvlc_media_player_pause(libvlc_media_player,ex);
+ libvlc_media_player_pause(libvlc_media_player);
}
int playlist_isplaying()
{
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_delete_item( int, libvlc_exception_t * );
- void playlist_clear( libvlc_exception_t * );
+ const char ** );
+ int playlist_delete_item( int );
+ void playlist_clear();
int playlist_count();
- void toggle_fullscreen( libvlc_exception_t * );
- void set_fullscreen( int, libvlc_exception_t * );
- int get_fullscreen( libvlc_exception_t * );
+ void toggle_fullscreen();
+ void set_fullscreen( int );
+ int get_fullscreen();
- bool player_has_vout( libvlc_exception_t * );
+ bool player_has_vout();
- // Events related members
- std::vector<EventListener*> eventListeners; // List of registered listerners.
- std::vector<libvlc_event_type_t> eventList; // List of event sent by VLC that must be returned to JS.
- eventtypes_bitmap_t eventToCatch;
- pthread_mutex_t mutex;
-
static bool canUseEventListener();
+ EventObj events;
private:
- bool playlist_select(int,libvlc_exception_t *);
+ bool playlist_select(int);
void set_player_window();
/* VLC reference */
int i_last_position;
#endif
+
+ static void eventAsync(void *);
+ static void event_callback(const libvlc_event_t *, void *);
};
/*******************************************************************************