]> git.sesse.net Git - vlc/blobdiff - projects/mozilla/vlcplugin.h
Default to rebase on submodule updates to prevent losing local changes.
[vlc] / projects / mozilla / vlcplugin.h
index d14e1a94a86b3ff58803bf03db585ec9687cda3a..bb32917aa85277ff4b165f2fb89e8bc66d1fa869 100644 (file)
 #define __VLCPLUGIN_H__
 
 #include <vlc/vlc.h>
+#include <pthread.h>
 #include <npapi.h>
+#include <vector>
+
 #include "control/nporuntime.h"
 
 #if !defined(XP_MACOSX) && !defined(XP_UNIX) && !defined(XP_WIN)
@@ -79,6 +82,82 @@ typedef enum vlc_toolbar_clicked_e {
     clicked_Unmute
 } vlc_toolbar_clicked_t;
 
+
+// Note that the accessor functions are unsafe, but this is handled in
+// the next layer up. 64bit uints can be substituted to taste (shift=6).
+template<size_t M> class bitmap
+{
+private:
+    typedef uint32_t bitu_t; enum { shift=5 };
+    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)); }
+    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);  }
+    size_t maxbit() const      { return bmax; }
+    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> eventtypes_bitmap_t;
+
+
+class EventObj: private eventtypes_bitmap_t
+{
+private:
+    typedef libvlc_event_type_t event_t;
+    bool have_event(event_t e) const { return e<maxbit()?get(e):false; }
+
+    class Listener: public eventtypes_bitmap_t
+    {
+    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() { return pthread_mutex_init(&mutex, NULL) == 0; }
+    ~EventObj() { pthread_mutex_destroy(&mutex); }
+
+    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;
+
+    pthread_mutex_t mutex;
+
+    bool ask_for_event(event_t e);
+    void unask_for_event(event_t e);
+};
+
+
 class VlcPlugin
 {
 public:
@@ -88,11 +167,11 @@ public:
     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,"no mediaplayer");
+             libvlc_printerr("no mediaplayer");
         }
         return libvlc_media_player;
     }
@@ -107,14 +186,14 @@ public:
     NPClass*            getScriptClass()
                             { return p_scriptClass; };
 
-#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; };
@@ -144,61 +223,65 @@ public:
     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( 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(libvlc_exception_t *ex)
+    void playlist_stop()
     {
         if( libvlc_media_player )
-            libvlc_media_player_stop(libvlc_media_player,ex);
+            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(libvlc_exception_t *ex)
+    int playlist_isplaying()
     {
         int is_playing = 0;
         if( libvlc_media_player )
             is_playing = libvlc_media_player_is_playing(
-                                libvlc_media_player, ex );
+                                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_delete_item( int, libvlc_exception_t * );
-    void playlist_clear( libvlc_exception_t * );
-    int  playlist_count( 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();
 
+
+    static bool canUseEventListener();
+
+    EventObj events;
 private:
-    bool playlist_select(int,libvlc_exception_t *);
-    void set_player_window( libvlc_exception_t * );
+    bool playlist_select(int);
+    void set_player_window();
 
     /* VLC reference */
     int                 playlist_index;
@@ -213,10 +296,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;
@@ -232,6 +315,9 @@ private:
 
     int i_last_position;
 #endif
+
+    static void eventAsync(void *);
+    static void event_callback(const libvlc_event_t *, void *);
 };
 
 /*******************************************************************************