Make OGLFrameGrabber work

Steps of grabFrame
- Init opengl context
- Call libgltf to render
- Get a RGB buffer from libgltf
- Create a Bitmap from this RGB buffer

Additionally:
- Using mimetype is neccessary to decide which player to create.
- bAllowToCreateReplacementGraphic is unneeded.

Change-Id: I7fef043a3341771389144a4f4cac71b0862ef8a7
This commit is contained in:
Zolnai Tamás
2014-04-20 18:00:33 +02:00
parent 78609b36e0
commit d8920e6d1d
10 changed files with 53 additions and 20 deletions

View File

@@ -12,13 +12,16 @@
#include <cppuhelper/supportsservice.hxx> #include <cppuhelper/supportsservice.hxx>
#include <vcl/bitmapex.hxx> #include <vcl/bitmapex.hxx>
#include <vcl/graph.hxx> #include <vcl/graph.hxx>
#include <vcl/salbtype.hxx>
#include <vcl/bmpacc.hxx>
using namespace com::sun::star; using namespace com::sun::star;
namespace avmedia { namespace ogl { namespace avmedia { namespace ogl {
OGLFrameGrabber::OGLFrameGrabber( const OUString& /*rUrl*/ ) OGLFrameGrabber::OGLFrameGrabber( glTFHandle* pHandle )
: FrameGrabber_BASE() : FrameGrabber_BASE()
, m_pHandle( pHandle )
{ {
} }
@@ -26,12 +29,29 @@ OGLFrameGrabber::~OGLFrameGrabber()
{ {
} }
uno::Reference< css::graphic::XGraphic > SAL_CALL OGLFrameGrabber::grabFrame( double /*fMediaTime*/ ) uno::Reference< css::graphic::XGraphic > SAL_CALL OGLFrameGrabber::grabFrame( double fMediaTime )
throw ( uno::RuntimeException, std::exception ) throw ( uno::RuntimeException, std::exception )
{ {
// TODO: Here we need a bitmap of the model at the point specified by fMediaTime // TODO: libgltf should provide an RGBA buffer, not just an RGB one. See: OpenGLRender::GetAsBitmap().
// See com::sun::star::media::XFrameGrabber char* pBuffer = new char[m_pHandle->viewport.width * m_pHandle->viewport.height * 3];
BitmapEx aBitmap; gltf_renderer_get_bitmap(m_pHandle, fMediaTime, pBuffer, 800, 600);
Bitmap aBitmap( Size(m_pHandle->viewport.width, m_pHandle->viewport.height), 24 );
{
Bitmap::ScopedWriteAccess pWriteAccess( aBitmap );
size_t nCurPos = 0;
for( int y = 0; y < m_pHandle->viewport.height; ++y)
{
Scanline pScan = pWriteAccess->GetScanline(y);
for( int x = 0; x < m_pHandle->viewport.width; ++x )
{
*pScan++ = pBuffer[nCurPos];
*pScan++ = pBuffer[nCurPos+1];
*pScan++ = pBuffer[nCurPos+2];
nCurPos += 3;
}
}
}
delete [] pBuffer;
return Graphic( aBitmap ).GetXGraphic(); return Graphic( aBitmap ).GetXGraphic();
} }

View File

@@ -14,6 +14,8 @@
#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/media/XFrameGrabber.hpp> #include <com/sun/star/media/XFrameGrabber.hpp>
#include <libgltf.h>
namespace avmedia { namespace ogl { namespace avmedia { namespace ogl {
typedef ::cppu::WeakImplHelper2< com::sun::star::media::XFrameGrabber, typedef ::cppu::WeakImplHelper2< com::sun::star::media::XFrameGrabber,
@@ -23,7 +25,7 @@ class OGLFrameGrabber : public FrameGrabber_BASE
{ {
public: public:
OGLFrameGrabber( const OUString& rURL ); OGLFrameGrabber( glTFHandle* pHandle );
virtual ~OGLFrameGrabber(); virtual ~OGLFrameGrabber();
// XFrameGrabber // XFrameGrabber
@@ -33,6 +35,9 @@ public:
virtual OUString SAL_CALL getImplementationName() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; virtual OUString SAL_CALL getImplementationName() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; virtual com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
private:
glTFHandle* m_pHandle;
}; };
} // namespace ogl } // namespace ogl

View File

@@ -196,7 +196,10 @@ uno::Reference< media::XFrameGrabber > SAL_CALL OGLPlayer::createFrameGrabber()
throw ( uno::RuntimeException, std::exception ) throw ( uno::RuntimeException, std::exception )
{ {
osl::MutexGuard aGuard(m_aMutex); osl::MutexGuard aGuard(m_aMutex);
OGLFrameGrabber *pFrameGrabber = new OGLFrameGrabber( m_sURL ); m_aContext.init();
m_pHandle->viewport = glTFViewport({0,0,800,600}); //TODO: Use real values instead of constants.
gltf_renderer_set_content(m_pHandle);
OGLFrameGrabber *pFrameGrabber = new OGLFrameGrabber( m_pHandle );
return uno::Reference< media::XFrameGrabber >( pFrameGrabber );; return uno::Reference< media::XFrameGrabber >( pFrameGrabber );;
} }

View File

@@ -15,6 +15,7 @@
#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/media/XPlayer.hpp> #include <com/sun/star/media/XPlayer.hpp>
#include <libgltf.h> #include <libgltf.h>
#include <vcl/opengl/OpenGLContext.hxx>
namespace avmedia { namespace ogl { namespace avmedia { namespace ogl {
@@ -56,6 +57,7 @@ public:
private: private:
OUString m_sURL; OUString m_sURL;
glTFHandle* m_pHandle; glTFHandle* m_pHandle;
OpenGLContext m_aContext;
}; };
} // namespace ogl } // namespace ogl

View File

@@ -385,19 +385,19 @@ bool MediaWindow::isMediaURL( const OUString& rURL, const OUString& rReferer, bo
uno::Reference< media::XPlayer > MediaWindow::createPlayer( const OUString& rURL, const OUString& rReferer ) uno::Reference< media::XPlayer > MediaWindow::createPlayer( const OUString& rURL, const OUString& rReferer, const OUString* pMimeType )
{ {
return priv::MediaWindowImpl::createPlayer( rURL, rReferer ); return priv::MediaWindowImpl::createPlayer( rURL, rReferer, pMimeType );
} }
uno::Reference< graphic::XGraphic > MediaWindow::grabFrame( const OUString& rURL, uno::Reference< graphic::XGraphic > MediaWindow::grabFrame( const OUString& rURL,
const OUString& rReferer, const OUString& rReferer,
bool bAllowToCreateReplacementGraphic, const OUString& sMimeType,
double fMediaTime ) double fMediaTime )
{ {
uno::Reference< media::XPlayer > xPlayer( createPlayer( rURL, rReferer ) ); uno::Reference< media::XPlayer > xPlayer( createPlayer( rURL, rReferer, &sMimeType ) );
uno::Reference< graphic::XGraphic > xRet; uno::Reference< graphic::XGraphic > xRet;
boost::scoped_ptr< Graphic > apGraphic; boost::scoped_ptr< Graphic > apGraphic;
@@ -416,7 +416,7 @@ uno::Reference< graphic::XGraphic > MediaWindow::grabFrame( const OUString& rURL
xRet = xGrabber->grabFrame( fMediaTime ); xRet = xGrabber->grabFrame( fMediaTime );
} }
if( !xRet.is() && bAllowToCreateReplacementGraphic ) if( !xRet.is() )
{ {
awt::Size aPrefSize( xPlayer->getPreferredPlayerWindowSize() ); awt::Size aPrefSize( xPlayer->getPreferredPlayerWindowSize() );
@@ -428,7 +428,7 @@ uno::Reference< graphic::XGraphic > MediaWindow::grabFrame( const OUString& rURL
} }
} }
if( !xRet.is() && !apGraphic.get() && bAllowToCreateReplacementGraphic ) if( !xRet.is() && !apGraphic.get() )
{ {
const BitmapEx aBmpEx( getEmptyLogo() ); const BitmapEx aBmpEx( getEmptyLogo() );
apGraphic.reset( new Graphic( aBmpEx ) ); apGraphic.reset( new Graphic( aBmpEx ) );

View File

@@ -205,7 +205,7 @@ MediaWindowImpl::~MediaWindowImpl()
delete mpMediaWindowControl; delete mpMediaWindowControl;
} }
uno::Reference< media::XPlayer > MediaWindowImpl::createPlayer( const OUString& rURL, const OUString& rReferer, OUString* pMimeType ) uno::Reference< media::XPlayer > MediaWindowImpl::createPlayer( const OUString& rURL, const OUString& rReferer, const OUString* pMimeType )
{ {
uno::Reference< media::XPlayer > xPlayer; uno::Reference< media::XPlayer > xPlayer;

View File

@@ -94,7 +94,7 @@ namespace avmedia
MediaWindowImpl( Window* parent, MediaWindow* pMediaWindow, bool bInternalMediaControl ); MediaWindowImpl( Window* parent, MediaWindow* pMediaWindow, bool bInternalMediaControl );
virtual ~MediaWindowImpl(); virtual ~MediaWindowImpl();
static ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > createPlayer( const OUString& rURL, const OUString& rReferer, OUString* pMimeType = 0 ); static ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > createPlayer( const OUString& rURL, const OUString& rReferer, const OUString* pMimeType = 0 );
void setURL( const OUString& rURL, OUString const& rTempURL, OUString const& rReferer ); void setURL( const OUString& rURL, OUString const& rTempURL, OUString const& rReferer );

View File

@@ -102,11 +102,10 @@ namespace avmedia
static void executeFormatErrorBox( Window* pParent ); static void executeFormatErrorBox( Window* pParent );
static bool isMediaURL( const OUString& rURL, const OUString& rReferer, bool bDeep = false, Size* pPreferredSizePixel = NULL ); static bool isMediaURL( const OUString& rURL, const OUString& rReferer, bool bDeep = false, Size* pPreferredSizePixel = NULL );
static ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > createPlayer( const OUString& rURL, const OUString& rReferer ); static ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > createPlayer( const OUString& rURL, const OUString& rReferer, const OUString* pMimeType = 0 );
static ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > grabFrame( const OUString& rURL, const OUString& rReferer, static ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > grabFrame( const OUString& rURL, const OUString& rReferer,
bool bAllowToCreateReplacementGraphic = false, const OUString& sMimeType, double fMediaTime = AVMEDIA_FRAMEGRABBER_DEFAULTFRAME );
double fMediaTime = AVMEDIA_FRAMEGRABBER_DEFAULTFRAME );
static BitmapEx getAudioLogo(); static BitmapEx getAudioLogo();
static BitmapEx getEmptyLogo(); static BitmapEx getEmptyLogo();

View File

@@ -191,11 +191,15 @@ namespace slideshow
if( !mpMediaWindow.get() && !mxPlayerWindow.is() ) if( !mpMediaWindow.get() && !mxPlayerWindow.is() )
{ {
OUString sURL; OUString sURL;
OUString sMimeType;
uno::Reference< beans::XPropertySet > xPropSet( mxShape, uno::UNO_QUERY ); uno::Reference< beans::XPropertySet > xPropSet( mxShape, uno::UNO_QUERY );
if (xPropSet.is()) if (xPropSet.is())
{
xPropSet->getPropertyValue("PrivateTempFileURL") >>= sURL; xPropSet->getPropertyValue("PrivateTempFileURL") >>= sURL;
xPropSet->getPropertyValue("MediaMimeType") >>= sMimeType;
}
const Graphic aGraphic(avmedia::MediaWindow::grabFrame(sURL,"", true)); const Graphic aGraphic(avmedia::MediaWindow::grabFrame(sURL,"",sMimeType));
const BitmapEx aBmp = aGraphic.GetBitmapEx(); const BitmapEx aBmp = aGraphic.GetBitmapEx();
uno::Reference< rendering::XBitmap > xBitmap(vcl::unotools::xBitmapFromBitmapEx( uno::Reference< rendering::XBitmap > xBitmap(vcl::unotools::xBitmapFromBitmapEx(

View File

@@ -171,7 +171,7 @@ uno::Reference< graphic::XGraphic > SdrMediaObj::getSnapshot()
OUString aRealURL = m_pImpl->m_MediaProperties.getTempURL(); OUString aRealURL = m_pImpl->m_MediaProperties.getTempURL();
if( aRealURL.isEmpty() ) if( aRealURL.isEmpty() )
aRealURL = m_pImpl->m_MediaProperties.getURL(); aRealURL = m_pImpl->m_MediaProperties.getURL();
m_pImpl->m_xCachedSnapshot = avmedia::MediaWindow::grabFrame( aRealURL, m_pImpl->m_MediaProperties.getReferer(), true ); m_pImpl->m_xCachedSnapshot = avmedia::MediaWindow::grabFrame( aRealURL, m_pImpl->m_MediaProperties.getReferer(), m_pImpl->m_MediaProperties.getMimeType());
} }
return m_pImpl->m_xCachedSnapshot; return m_pImpl->m_xCachedSnapshot;
} }