[vlc-devel] [PATCH 3/4] Split VlcWindowlessBase into separate file

Cheng Sun chengsun9 at gmail.com
Sun Dec 30 21:51:54 CET 2012


---
 npapi/Makefile.am            |   2 +
 npapi/vlcplugin_base.cpp     |  89 --------------------------------
 npapi/vlcplugin_base.h       |  68 -------------------------
 npapi/vlcwindowless_base.cpp | 117 +++++++++++++++++++++++++++++++++++++++++++
 npapi/vlcwindowless_base.h   |  96 +++++++++++++++++++++++++++++++++++
 npapi/vlcwindowless_xcb.h    |   3 +-
 6 files changed, 216 insertions(+), 159 deletions(-)
 create mode 100644 npapi/vlcwindowless_base.cpp
 create mode 100644 npapi/vlcwindowless_base.h

diff --git a/npapi/Makefile.am b/npapi/Makefile.am
index a96df6d..7ef1bf7 100644
--- a/npapi/Makefile.am
+++ b/npapi/Makefile.am
@@ -18,6 +18,8 @@ libvlcplugin_la_SOURCES = \
 	vlcplugin.h \
 	vlcplugin_base.cpp \
 	vlcplugin_base.h \
+	vlcwindowless_base.cpp \
+	vlcwindowless_base.h \
 	control/npolibvlc.cpp \
 	control/npolibvlc.h \
 	control/nporuntime.cpp \
diff --git a/npapi/vlcplugin_base.cpp b/npapi/vlcplugin_base.cpp
index 060607c..e5589f9 100644
--- a/npapi/vlcplugin_base.cpp
+++ b/npapi/vlcplugin_base.cpp
@@ -534,92 +534,3 @@ bool VlcPluginBase::canUseEventListener()
     return false;
 }
 
-#ifdef WINDOWLESS
-VlcWindowlessBase::VlcWindowlessBase(NPP instance, NPuint16_t mode) :
-    VlcPluginBase(instance, mode), m_media_width(0), m_media_height(0)
-{
-}
-
-unsigned VlcWindowlessBase::video_format_cb(char *chroma,
-                                unsigned *width, unsigned *height,
-                                unsigned *pitches, unsigned *lines)
-{
-    if ( p_browser ) {
-        float src_aspect = (float)(*width) / (*height);
-        float dst_aspect = (float)npwindow.width/npwindow.height;
-        if ( src_aspect > dst_aspect ) {
-            if( npwindow.width != (*width) ) { //don't scale if size equal
-                (*width) = npwindow.width;
-                (*height) = static_cast<unsigned>( (*width) / src_aspect + 0.5);
-            }
-        }
-        else {
-            if( npwindow.height != (*height) ) { //don't scale if size equal
-                (*height) = npwindow.height;
-                (*width) = static_cast<unsigned>( (*height) * src_aspect + 0.5);
-            }
-        }
-    }
-
-    m_media_width = (*width);
-    m_media_height = (*height);
-
-    memcpy(chroma, DEF_CHROMA, sizeof(DEF_CHROMA)-1);
-    (*pitches) = m_media_width * DEF_PIXEL_BYTES;
-    (*lines) = m_media_height;
-
-    //+1 for vlc 2.0.3/2.1 bug workaround.
-    //They writes after buffer end boundary by some reason unknown to me...
-    m_frame_buf.resize( (*pitches) * ((*lines)+1) );
-
-    return 1;
-}
-
-void VlcWindowlessBase::video_cleanup_cb()
-{
-    m_frame_buf.resize(0);
-    m_media_width = 0;
-    m_media_height = 0;
-}
-
-void* VlcWindowlessBase::video_lock_cb(void **planes)
-{
-    (*planes) = m_frame_buf.empty()? 0 : &m_frame_buf[0];
-    return 0;
-}
-
-void VlcWindowlessBase::video_unlock_cb(void* /*picture*/, void *const * /*planes*/)
-{
-}
-
-void VlcWindowlessBase::invalidate_window()
-{
-    NPRect rect;
-    rect.left = 0;
-    rect.top = 0;
-    rect.right = npwindow.width;
-    rect.bottom = npwindow.height;
-    NPN_InvalidateRect(p_browser, &rect);
-    NPN_ForceRedraw(p_browser);
-}
-
-void VlcWindowlessBase::video_display_cb(void * /*picture*/)
-{
-    if (p_browser) {
-        NPN_PluginThreadAsyncCall(p_browser,
-                                  VlcWindowlessBase::invalidate_window_proxy,
-                                  this);
-    }
-}
-
-void VlcWindowlessBase::set_player_window() {
-    libvlc_video_set_format_callbacks(getMD(),
-                                      video_format_proxy,
-                                      video_cleanup_proxy);
-    libvlc_video_set_callbacks(getMD(),
-                               video_lock_proxy,
-                               video_unlock_proxy,
-                               video_display_proxy,
-                               this);
-}
-#endif
diff --git a/npapi/vlcplugin_base.h b/npapi/vlcplugin_base.h
index 5f1fb28..be7b21c 100644
--- a/npapi/vlcplugin_base.h
+++ b/npapi/vlcplugin_base.h
@@ -198,72 +198,4 @@ private:
     static std::set<VlcPluginBase*> _instances;
 };
 
-
-#ifdef WINDOWLESS
-const char DEF_CHROMA[] = "RV32";
-enum{
-    DEF_PIXEL_BYTES = 4
-};
-
-class VlcWindowlessBase : public VlcPluginBase
-{
-public:
-    VlcWindowlessBase(NPP, NPuint16_t);
-
-    //for libvlc_video_set_format_callbacks
-    static unsigned video_format_proxy(void **opaque, char *chroma,
-                                       unsigned *width, unsigned *height,
-                                       unsigned *pitches, unsigned *lines)
-        { return reinterpret_cast<VlcWindowlessBase*>(*opaque)->video_format_cb(chroma,
-                                                                  width, height,
-                                                                  pitches, lines); }
-    static void video_cleanup_proxy(void *opaque)
-        { reinterpret_cast<VlcWindowlessBase*>(opaque)->video_cleanup_cb(); };
-
-    unsigned video_format_cb(char *chroma,
-                             unsigned *width, unsigned *height,
-                             unsigned *pitches, unsigned *lines);
-    void video_cleanup_cb();
-    //end (for libvlc_video_set_format_callbacks)
-
-    //for libvlc_video_set_callbacks
-    static void* video_lock_proxy(void *opaque, void **planes)
-        { return reinterpret_cast<VlcWindowlessBase*>(opaque)->video_lock_cb(planes); }
-    static void video_unlock_proxy(void *opaque, void *picture, void *const *planes)
-        { reinterpret_cast<VlcWindowlessBase*>(opaque)->video_unlock_cb(picture, planes); }
-    static void video_display_proxy(void *opaque, void *picture)
-        { reinterpret_cast<VlcWindowlessBase*>(opaque)->video_display_cb(picture); }
-
-    void* video_lock_cb(void **planes);
-    void video_unlock_cb(void *picture, void *const *planes);
-    void video_display_cb(void *picture);
-    //end (for libvlc_video_set_callbacks)
-
-    static void invalidate_window_proxy(void *opaque)
-        { reinterpret_cast<VlcWindowlessBase*>(opaque)->invalidate_window(); }
-    void invalidate_window();
-
-    void set_player_window();
-
-
-    bool create_windows() { return true; }
-    bool resize_windows() { return true; }
-    bool destroy_windows() { return true; }
-
-    void toggle_fullscreen() { /* STUB */ }
-    void set_fullscreen( int ) { /* STUB */ }
-    int  get_fullscreen() { return false; }
-
-    void set_toolbar_visible(bool)  { /* STUB */ }
-    bool get_toolbar_visible()  { return false; }
-    void update_controls()      {/* STUB */}
-    void popup_menu()           {/* STUB */}
-
-protected:
-    std::vector<char> m_frame_buf;
-    unsigned int m_media_width;
-    unsigned int m_media_height;
-};
-#endif
-
 #endif
diff --git a/npapi/vlcwindowless_base.cpp b/npapi/vlcwindowless_base.cpp
new file mode 100644
index 0000000..58ef51a
--- /dev/null
+++ b/npapi/vlcwindowless_base.cpp
@@ -0,0 +1,117 @@
+/*****************************************************************************
+ * vlcwindowless_base.cpp: a VLC plugin for Mozilla
+ *****************************************************************************
+ * Copyright (C) 2002-2010 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Sergey Radionov <rsatom at gmail.com>
+ *          Cheng Sun <chengsun9 at gmail.com>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include "vlcwindowless_base.h"
+
+VlcWindowlessBase::VlcWindowlessBase(NPP instance, NPuint16_t mode) :
+    VlcPluginBase(instance, mode)
+{
+}
+
+VlcWindowlessBase::~VlcWindowlessBase()
+{
+}
+
+unsigned VlcWindowlessBase::video_format_cb(char *chroma,
+                                unsigned *width, unsigned *height,
+                                unsigned *pitches, unsigned *lines)
+{
+    if ( p_browser ) {
+        float src_aspect = (float)(*width) / (*height);
+        float dst_aspect = (float)npwindow.width/npwindow.height;
+        if ( src_aspect > dst_aspect ) {
+            if( npwindow.width != (*width) ) { //don't scale if size equal
+                (*width) = npwindow.width;
+                (*height) = static_cast<unsigned>( (*width) / src_aspect + 0.5);
+            }
+        }
+        else {
+            if( npwindow.height != (*height) ) { //don't scale if size equal
+                (*height) = npwindow.height;
+                (*width) = static_cast<unsigned>( (*height) * src_aspect + 0.5);
+            }
+        }
+    }
+
+    m_media_width = (*width);
+    m_media_height = (*height);
+
+    memcpy(chroma, DEF_CHROMA, sizeof(DEF_CHROMA)-1);
+    (*pitches) = m_media_width * DEF_PIXEL_BYTES;
+    (*lines) = m_media_height;
+
+    //+1 for vlc 2.0.3/2.1 bug workaround.
+    //They writes after buffer end boundary by some reason unknown to me...
+    m_frame_buf.resize( (*pitches) * ((*lines)+1) );
+
+    return 1;
+}
+
+void VlcWindowlessBase::video_cleanup_cb()
+{
+    m_frame_buf.resize(0);
+    m_media_width = 0;
+    m_media_height = 0;
+}
+
+void* VlcWindowlessBase::video_lock_cb(void **planes)
+{
+    (*planes) = m_frame_buf.empty()? 0 : &m_frame_buf[0];
+    return 0;
+}
+
+void VlcWindowlessBase::video_unlock_cb(void* /*picture*/, void *const * /*planes*/)
+{
+}
+
+void VlcWindowlessBase::invalidate_window()
+{
+    NPRect rect;
+    rect.left = 0;
+    rect.top = 0;
+    rect.right = npwindow.width;
+    rect.bottom = npwindow.height;
+    NPN_InvalidateRect(p_browser, &rect);
+    NPN_ForceRedraw(p_browser);
+}
+
+void VlcWindowlessBase::video_display_cb(void * /*picture*/)
+{
+    if (p_browser) {
+        NPN_PluginThreadAsyncCall(p_browser,
+                                  VlcWindowlessBase::invalidate_window_proxy,
+                                  this);
+    }
+}
+
+void VlcWindowlessBase::set_player_window() {
+    libvlc_video_set_format_callbacks(getMD(),
+                                      video_format_proxy,
+                                      video_cleanup_proxy);
+    libvlc_video_set_callbacks(getMD(),
+                               video_lock_proxy,
+                               video_unlock_proxy,
+                               video_display_proxy,
+                               this);
+}
diff --git a/npapi/vlcwindowless_base.h b/npapi/vlcwindowless_base.h
new file mode 100644
index 0000000..711a74a
--- /dev/null
+++ b/npapi/vlcwindowless_base.h
@@ -0,0 +1,96 @@
+/*****************************************************************************
+ * vlcwindowless_base.h: a VLC plugin for Mozilla
+ *****************************************************************************
+ * Copyright (C) 2002-2009 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Sergey Radionov <rsatom at gmail.com>
+ *          Cheng Sun <chengsun9 at gmail.com>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef __VLCWINDOWLESS_BASE_H__
+#define __VLCWINDOWLESS_BASE_H__
+
+#include "vlcplugin_base.h"
+
+const char DEF_CHROMA[] = "RV32";
+enum{
+    DEF_PIXEL_BYTES = 4
+};
+
+class VlcWindowlessBase : public VlcPluginBase
+{
+public:
+    VlcWindowlessBase(NPP, NPuint16_t);
+    virtual ~VlcWindowlessBase();
+
+    //for libvlc_video_set_format_callbacks
+    static unsigned video_format_proxy(void **opaque, char *chroma,
+                                       unsigned *width, unsigned *height,
+                                       unsigned *pitches, unsigned *lines)
+        { return reinterpret_cast<VlcWindowlessBase*>(*opaque)->video_format_cb(chroma,
+                                                                  width, height,
+                                                                  pitches, lines); }
+    static void video_cleanup_proxy(void *opaque)
+        { reinterpret_cast<VlcWindowlessBase*>(opaque)->video_cleanup_cb(); };
+
+    unsigned video_format_cb(char *chroma,
+                             unsigned *width, unsigned *height,
+                             unsigned *pitches, unsigned *lines);
+    void video_cleanup_cb();
+    //end (for libvlc_video_set_format_callbacks)
+
+    //for libvlc_video_set_callbacks
+    static void* video_lock_proxy(void *opaque, void **planes)
+        { return reinterpret_cast<VlcWindowlessBase*>(opaque)->video_lock_cb(planes); }
+    static void video_unlock_proxy(void *opaque, void *picture, void *const *planes)
+        { reinterpret_cast<VlcWindowlessBase*>(opaque)->video_unlock_cb(picture, planes); }
+    static void video_display_proxy(void *opaque, void *picture)
+        { reinterpret_cast<VlcWindowlessBase*>(opaque)->video_display_cb(picture); }
+
+    void* video_lock_cb(void **planes);
+    void video_unlock_cb(void *picture, void *const *planes);
+    void video_display_cb(void *picture);
+    //end (for libvlc_video_set_callbacks)
+
+    static void invalidate_window_proxy(void *opaque)
+        { reinterpret_cast<VlcWindowlessBase*>(opaque)->invalidate_window(); }
+    void invalidate_window();
+
+    void set_player_window();
+
+
+    bool create_windows() { return true; }
+    bool resize_windows() { return true; }
+    bool destroy_windows() { return true; }
+
+    void toggle_fullscreen() { /* STUB */ }
+    void set_fullscreen( int ) { /* STUB */ }
+    int  get_fullscreen() { return false; }
+
+    void set_toolbar_visible(bool)  { /* STUB */ }
+    bool get_toolbar_visible()  { return false; }
+    void update_controls()      {/* STUB */}
+    void popup_menu()           {/* STUB */}
+
+protected:
+    std::vector<char> m_frame_buf;
+    unsigned int m_media_width;
+    unsigned int m_media_height;
+};
+
+#endif
diff --git a/npapi/vlcwindowless_xcb.h b/npapi/vlcwindowless_xcb.h
index 41bb005..4c84d35 100644
--- a/npapi/vlcwindowless_xcb.h
+++ b/npapi/vlcwindowless_xcb.h
@@ -24,8 +24,7 @@
 #ifndef __VLCWINDOWLESS_XCB_H__
 #define __VLCWINDOWLESS_XCB_H__
 
-#define WINDOWLESS
-#include "vlcplugin_base.h"
+#include "vlcwindowless_base.h"
 
 #include <xcb/xcb.h>
 
-- 
1.8.0.3




More information about the vlc-devel mailing list