Commit 6a68ec05 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Split Windowless base class in another class

Based on a patch by Cheng Sun
parent 95c844b6
......@@ -83,7 +83,9 @@ AM_CPPFLAGS += $(XCB_CFLAGS)
libvlcplugin_la_LIBADD += $(XCB_LIBS)
SOURCES_support += \
vlcwindowless_xcb.cpp \
vlcwindowless_xcb.h
vlcwindowless_xcb.h \
vlcwindowless_base.cpp \
vlcwindowless_base.h
endif # !HAVE_XCB
else # Win32
......@@ -137,6 +139,8 @@ AM_CPPFLAGS += -I. -I$(top_builddir) -c \
SOURCES_support = support/npmac.cpp \
vlcplugin_mac.cpp \
vlcplugin_mac.h \
vlcwindowless_base.cpp \
vlcwindowless_base.h \
vlcwindowless_mac.cpp \
vlcwindowless_mac.h
libvlcplugin_la_LDFLAGS += \
......
......@@ -532,92 +532,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
......@@ -198,76 +198,4 @@ private:
static std::set<VlcPluginBase*> _instances;
};
#ifdef WINDOWLESS
#ifdef XP_MACOSX
const char DEF_CHROMA[] = "RGBA";
#else
const char DEF_CHROMA[] = "RV32";
#endif
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
/*****************************************************************************
* vlcplugin_base.cpp: a VLC plugin for Mozilla
*****************************************************************************
* Copyright (C) 2002-2010 the VideoLAN team
* $Id$
*
* Authors: Samuel Hocevar <sam@zoy.org>
* Damien Fouilleul <damienf.fouilleul@laposte.net>
* Jean-Paul Saman <jpsaman@videolan.org>
* Sergey Radionov <rsatom@gmail.com>
* Cheng Sun <chengsun9@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), 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);
}
/*****************************************************************************
* vlcplugin_base.h: a VLC plugin for Mozilla
*****************************************************************************
* Copyright (C) 2002-2009 the VideoLAN team
* $Id$
*
* Authors: Samuel Hocevar <sam@zoy.org>
* Damien Fouilleul <damienf@videolan.org>
* Jean-Paul Saman <jpsaman@videolan.org>
* Sergey Radionov <rsatom@gmail.com>
* Cheng Sun <chengsun9@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.
*****************************************************************************/
/*******************************************************************************
* Instance state information about the plugin.
******************************************************************************/
#ifndef __VLCWINDOWLESS_BASE_H__
#define __VLCWINDOWLESS_BASE_H__
#include "vlcplugin_base.h"
#ifdef XP_MACOSX
const char DEF_CHROMA[] = "RGBA";
#else
const char DEF_CHROMA[] = "RV32";
#endif
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
......@@ -24,8 +24,7 @@
#ifndef __VLCWINDOWLESS_MAC_H__
#define __VLCWINDOWLESS_MAC_H__
#define WINDOWLESS
#include "vlcplugin_base.h"
#include "vlcwindowless_base.h"
class VlcWindowlessMac : public VlcWindowlessBase
{
......
......@@ -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>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment