2014-03-26 18:46:52 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "oglplayer.hxx"
|
|
|
|
#include "oglframegrabber.hxx"
|
|
|
|
#include "oglwindow.hxx"
|
|
|
|
|
|
|
|
#include <cppuhelper/supportsservice.hxx>
|
2014-04-20 10:27:13 +02:00
|
|
|
#include <tools/stream.hxx>
|
|
|
|
#include <vcl/graph.hxx>
|
|
|
|
#include <vcl/graphicfilter.hxx>
|
|
|
|
#include <tools/urlobj.hxx>
|
|
|
|
#include <vcl/opengl/OpenGLHelper.hxx>
|
2014-03-26 18:46:52 +01:00
|
|
|
|
|
|
|
using namespace com::sun::star;
|
|
|
|
|
|
|
|
namespace avmedia { namespace ogl {
|
|
|
|
|
2014-04-18 14:06:22 +02:00
|
|
|
OGLPlayer::OGLPlayer()
|
2014-03-26 18:46:52 +01:00
|
|
|
: Player_BASE(m_aMutex)
|
2014-04-29 11:17:46 +01:00
|
|
|
, m_pHandle(NULL)
|
2014-05-23 10:27:01 +01:00
|
|
|
, m_pOGLWindow(NULL)
|
2014-03-26 18:46:52 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
OGLPlayer::~OGLPlayer()
|
|
|
|
{
|
2014-05-28 15:38:22 +02:00
|
|
|
osl::MutexGuard aGuard(m_aMutex);
|
2014-05-29 05:27:46 +02:00
|
|
|
if( m_pHandle )
|
2014-05-28 13:07:38 +02:00
|
|
|
{
|
2014-05-29 05:27:46 +02:00
|
|
|
for (size_t i = 0; i < m_pHandle->size; ++i)
|
2014-05-28 13:07:38 +02:00
|
|
|
{
|
2014-05-29 05:27:46 +02:00
|
|
|
if (m_pHandle->files[i].type != GLTF_JSON)
|
|
|
|
{
|
|
|
|
delete [] m_pHandle->files[i].buffer;
|
|
|
|
}
|
2014-05-28 13:07:38 +02:00
|
|
|
}
|
2014-05-29 05:27:46 +02:00
|
|
|
gltf_renderer_release(m_pHandle);
|
2014-05-28 13:07:38 +02:00
|
|
|
}
|
2014-03-26 18:46:52 +01:00
|
|
|
}
|
|
|
|
|
2014-04-20 10:27:13 +02:00
|
|
|
static bool lcl_LoadFile( glTFFile* io_pFile, const OUString& rURL)
|
|
|
|
{
|
|
|
|
SvFileStream aStream( rURL, STREAM_READ );
|
|
|
|
if( !aStream.IsOpen() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const sal_Int64 nBytes = aStream.remainingSize();
|
|
|
|
char* pBuffer = new char[nBytes];
|
|
|
|
aStream.Read( pBuffer, nBytes );
|
|
|
|
aStream.Close();
|
|
|
|
|
|
|
|
io_pFile->buffer = pBuffer;
|
|
|
|
io_pFile->size = nBytes;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-18 14:06:22 +02:00
|
|
|
bool OGLPlayer::create( const OUString& rURL )
|
|
|
|
{
|
2014-05-28 15:38:22 +02:00
|
|
|
osl::MutexGuard aGuard(m_aMutex);
|
|
|
|
|
2014-04-18 14:06:22 +02:00
|
|
|
m_sURL = rURL;
|
2014-04-20 10:27:13 +02:00
|
|
|
|
|
|
|
// Load *.json file and init renderer
|
|
|
|
glTFFile aJsonFile;
|
|
|
|
aJsonFile.type = GLTF_JSON;
|
2014-04-22 13:05:23 +02:00
|
|
|
OString sFileName = OUStringToOString(INetURLObject(m_sURL).GetLastName(),RTL_TEXTENCODING_UTF8);
|
2014-04-20 10:27:13 +02:00
|
|
|
aJsonFile.filename = (char*)sFileName.getStr();
|
|
|
|
if( !lcl_LoadFile(&aJsonFile, m_sURL) )
|
2014-05-09 18:03:03 +02:00
|
|
|
{
|
|
|
|
SAL_WARN("avmedia.opengl", "Can't load *.json file: " + sFileName);
|
2014-04-20 10:27:13 +02:00
|
|
|
return false;
|
2014-05-09 18:03:03 +02:00
|
|
|
}
|
2014-04-20 10:27:13 +02:00
|
|
|
|
|
|
|
m_pHandle = gltf_renderer_init(&aJsonFile);
|
|
|
|
|
2014-05-28 13:07:38 +02:00
|
|
|
delete [] aJsonFile.buffer;
|
|
|
|
|
2014-04-20 10:27:13 +02:00
|
|
|
if( !m_pHandle || !m_pHandle->files )
|
2014-05-09 18:03:03 +02:00
|
|
|
{
|
|
|
|
SAL_WARN("avmedia.opengl", "gltf_renderer_init returned an invalid glTFHandle");
|
2014-04-20 10:27:13 +02:00
|
|
|
return false;
|
2014-05-09 18:03:03 +02:00
|
|
|
}
|
2014-04-20 10:27:13 +02:00
|
|
|
|
|
|
|
// Load external resources
|
|
|
|
for( size_t i = 0; i < m_pHandle->size; ++i )
|
|
|
|
{
|
2014-05-24 17:49:38 +02:00
|
|
|
glTFFile& rFile = m_pHandle->files[i];
|
|
|
|
if( rFile.filename )
|
2014-04-20 10:27:13 +02:00
|
|
|
{
|
2014-04-22 13:05:23 +02:00
|
|
|
const OUString sFilesURL =
|
2014-05-24 17:49:38 +02:00
|
|
|
INetURLObject::GetAbsURL(m_sURL,OStringToOUString(OString(rFile.filename),RTL_TEXTENCODING_UTF8));
|
|
|
|
if( rFile.type == GLTF_IMAGE )
|
2014-04-20 10:27:13 +02:00
|
|
|
{
|
|
|
|
// Load images as bitmaps
|
|
|
|
GraphicFilter aFilter;
|
|
|
|
Graphic aGraphic;
|
2014-05-28 13:07:38 +02:00
|
|
|
if( aFilter.ImportGraphic(aGraphic, INetURLObject(sFilesURL)) != GRFILTER_OK )
|
|
|
|
{
|
|
|
|
rFile.buffer = 0;
|
|
|
|
rFile.imagewidth = 0;
|
|
|
|
rFile.imageheight = 0;
|
|
|
|
SAL_WARN("avmedia.opengl", "Can't load texture file: " + sFilesURL);
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-27 20:12:59 +02:00
|
|
|
BitmapEx aBitmapEx = aGraphic.GetBitmapEx();
|
|
|
|
aBitmapEx.Mirror(BMP_MIRROR_VERT);
|
2014-05-24 17:49:38 +02:00
|
|
|
rFile.buffer = (char*)OpenGLHelper::ConvertBitmapExToRGBABuffer(aBitmapEx);
|
|
|
|
rFile.imagewidth = aBitmapEx.GetSizePixel().Width();
|
|
|
|
rFile.imageheight = aBitmapEx.GetSizePixel().Height();
|
2014-04-20 10:27:13 +02:00
|
|
|
}
|
2014-05-24 17:49:38 +02:00
|
|
|
else if( rFile.type == GLTF_BINARY || rFile.type == GLTF_GLSL )
|
2014-04-20 10:27:13 +02:00
|
|
|
{
|
2014-05-24 17:49:38 +02:00
|
|
|
if( !lcl_LoadFile(&rFile, sFilesURL) )
|
2014-05-09 18:03:03 +02:00
|
|
|
{
|
2014-05-28 13:07:38 +02:00
|
|
|
rFile.buffer = 0;
|
|
|
|
rFile.size = 0;
|
2014-05-09 18:03:03 +02:00
|
|
|
SAL_WARN("avmedia.opengl", "Can't load glTF file: " + sFilesURL);
|
2014-04-20 10:27:13 +02:00
|
|
|
return false;
|
2014-05-09 18:03:03 +02:00
|
|
|
}
|
2014-04-20 10:27:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-16 22:07:16 +02:00
|
|
|
|
|
|
|
// Set timer
|
|
|
|
m_aTimer.SetTimeout(10);
|
|
|
|
m_aTimer.SetTimeoutHdl(LINK(this,OGLPlayer,TimerHandler));
|
2014-04-18 14:06:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-26 18:46:52 +01:00
|
|
|
void SAL_CALL OGLPlayer::start() throw ( uno::RuntimeException, std::exception )
|
|
|
|
{
|
|
|
|
osl::MutexGuard aGuard(m_aMutex);
|
2014-04-27 16:30:46 +02:00
|
|
|
gltf_animation_start(m_pHandle);
|
2014-05-16 22:07:16 +02:00
|
|
|
m_aTimer.Start();
|
2014-03-26 18:46:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL OGLPlayer::stop() throw ( uno::RuntimeException, std::exception )
|
|
|
|
{
|
|
|
|
osl::MutexGuard aGuard(m_aMutex);
|
2014-04-27 16:30:46 +02:00
|
|
|
gltf_animation_stop(m_pHandle);
|
2014-05-16 22:07:16 +02:00
|
|
|
m_aTimer.Stop();
|
2014-03-26 18:46:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL OGLPlayer::isPlaying() throw ( uno::RuntimeException, std::exception )
|
|
|
|
{
|
|
|
|
osl::MutexGuard aGuard(m_aMutex);
|
2014-05-06 17:10:59 +02:00
|
|
|
return (sal_Bool)gltf_animation_is_playing(m_pHandle);
|
2014-03-26 18:46:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
double SAL_CALL OGLPlayer::getDuration() throw ( uno::RuntimeException, std::exception )
|
|
|
|
{
|
|
|
|
osl::MutexGuard aGuard(m_aMutex);
|
2014-04-27 16:30:46 +02:00
|
|
|
return gltf_animation_get_duration(m_pHandle);
|
2014-03-26 18:46:52 +01:00
|
|
|
}
|
|
|
|
|
2014-04-27 16:30:46 +02:00
|
|
|
void SAL_CALL OGLPlayer::setMediaTime( double fTime ) throw ( uno::RuntimeException, std::exception )
|
2014-03-26 18:46:52 +01:00
|
|
|
{
|
2014-05-16 22:08:23 +02:00
|
|
|
// TODO: doesn't work, but cause problem in playing
|
2014-03-26 18:46:52 +01:00
|
|
|
osl::MutexGuard aGuard(m_aMutex);
|
2014-05-16 23:41:59 +03:00
|
|
|
(void) fTime;
|
2014-05-16 22:08:23 +02:00
|
|
|
//gltf_animation_set_time(m_pHandle, fTime);
|
2014-03-26 18:46:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
double SAL_CALL OGLPlayer::getMediaTime() throw ( ::com::sun::star::uno::RuntimeException, std::exception )
|
|
|
|
{
|
|
|
|
osl::MutexGuard aGuard(m_aMutex);
|
2014-05-16 22:57:33 +02:00
|
|
|
return 0.0; //gltf_animation_get_time(m_pHandle);
|
2014-03-26 18:46:52 +01:00
|
|
|
}
|
|
|
|
|
2014-04-27 16:30:46 +02:00
|
|
|
void SAL_CALL OGLPlayer::setPlaybackLoop( sal_Bool bSet ) throw ( uno::RuntimeException, std::exception )
|
2014-03-26 18:46:52 +01:00
|
|
|
{
|
|
|
|
osl::MutexGuard aGuard(m_aMutex);
|
2014-04-27 16:30:46 +02:00
|
|
|
gltf_animation_set_looping(m_pHandle, (int)bSet);
|
2014-03-26 18:46:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL OGLPlayer::isPlaybackLoop() throw ( uno::RuntimeException, std::exception )
|
|
|
|
{
|
|
|
|
osl::MutexGuard aGuard(m_aMutex);
|
2014-04-27 16:30:46 +02:00
|
|
|
return (sal_Bool)gltf_animation_get_looping(m_pHandle);
|
2014-03-26 18:46:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL OGLPlayer::setVolumeDB( sal_Int16 /*nVolumDB*/ ) throw ( uno::RuntimeException, std::exception )
|
|
|
|
{
|
2014-04-27 14:41:12 +02:00
|
|
|
// OpenGL models have no sound.
|
2014-03-26 18:46:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int16 SAL_CALL OGLPlayer::getVolumeDB() throw ( uno::RuntimeException, std::exception )
|
|
|
|
{
|
2014-04-27 14:41:12 +02:00
|
|
|
// OpenGL models have no sound.
|
2014-03-26 18:46:52 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL OGLPlayer::setMute( sal_Bool /*bSet*/ ) throw ( uno::RuntimeException, std::exception )
|
|
|
|
{
|
2014-04-27 14:41:12 +02:00
|
|
|
// OpenGL models have no sound.
|
2014-03-26 18:46:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL OGLPlayer::isMute() throw ( uno::RuntimeException, std::exception )
|
|
|
|
{
|
2014-04-27 14:41:12 +02:00
|
|
|
// OpenGL models have no sound.
|
2014-03-26 18:46:52 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
awt::Size SAL_CALL OGLPlayer::getPreferredPlayerWindowSize() throw ( uno::RuntimeException, std::exception )
|
|
|
|
{
|
2014-05-06 17:10:59 +02:00
|
|
|
return awt::Size( 480, 360 );
|
2014-03-26 18:46:52 +01:00
|
|
|
}
|
|
|
|
|
2014-04-27 12:20:13 +02:00
|
|
|
uno::Reference< media::XPlayerWindow > SAL_CALL OGLPlayer::createPlayerWindow( const uno::Sequence< uno::Any >& rArguments )
|
2014-03-26 18:46:52 +01:00
|
|
|
throw ( uno::RuntimeException, std::exception )
|
|
|
|
{
|
|
|
|
osl::MutexGuard aGuard( m_aMutex );
|
2014-04-27 12:20:13 +02:00
|
|
|
|
2014-05-09 18:03:03 +02:00
|
|
|
assert( rArguments.getLength() >= 3 );
|
|
|
|
|
|
|
|
sal_IntPtr pIntPtr = 0;
|
|
|
|
rArguments[ 2 ] >>= pIntPtr;
|
|
|
|
SystemChildWindow *pChildWindow = reinterpret_cast< SystemChildWindow* >( pIntPtr );
|
|
|
|
|
|
|
|
if( !m_aContext.init(pChildWindow) )
|
2014-04-27 12:20:13 +02:00
|
|
|
{
|
2014-05-09 18:03:03 +02:00
|
|
|
SAL_WARN("avmedia.opengl", "Context initialization failed");
|
|
|
|
return uno::Reference< media::XPlayerWindow >();
|
2014-04-27 12:20:13 +02:00
|
|
|
}
|
2014-05-09 18:03:03 +02:00
|
|
|
|
|
|
|
Size aSize = pChildWindow->GetSizePixel();
|
|
|
|
m_aContext.setWinSize(aSize);
|
|
|
|
m_pHandle->viewport.x = 0;
|
|
|
|
m_pHandle->viewport.y = 0;
|
|
|
|
m_pHandle->viewport.width = aSize.Width();
|
|
|
|
m_pHandle->viewport.height = aSize.Height();
|
2014-05-29 05:48:54 +02:00
|
|
|
|
|
|
|
// TODO: In libgltf different return values are defined (for different errors)
|
|
|
|
// but these error codes are not part of the library interface
|
|
|
|
int nRet = gltf_renderer_set_content(m_pHandle);
|
|
|
|
if( nRet != 0 )
|
|
|
|
{
|
|
|
|
SAL_WARN("avmedia.opengl", "Error occured while parsing *.json file! Error code: " << nRet);
|
|
|
|
return uno::Reference< media::XPlayerWindow >();
|
|
|
|
}
|
2014-05-16 22:07:16 +02:00
|
|
|
m_pOGLWindow = new OGLWindow(m_pHandle, &m_aContext, pChildWindow);
|
|
|
|
return uno::Reference< media::XPlayerWindow >( m_pOGLWindow );
|
2014-03-26 18:46:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uno::Reference< media::XFrameGrabber > SAL_CALL OGLPlayer::createFrameGrabber()
|
|
|
|
throw ( uno::RuntimeException, std::exception )
|
|
|
|
{
|
|
|
|
osl::MutexGuard aGuard(m_aMutex);
|
2014-05-09 18:03:03 +02:00
|
|
|
|
|
|
|
if( !m_aContext.init() )
|
|
|
|
{
|
|
|
|
SAL_WARN("avmedia.opengl", "Offscreen context initialization failed");
|
|
|
|
return uno::Reference< media::XFrameGrabber >();
|
|
|
|
}
|
|
|
|
|
2014-04-20 22:57:08 +02:00
|
|
|
m_pHandle->viewport.x = 0;
|
|
|
|
m_pHandle->viewport.y = 0;
|
2014-04-27 12:20:13 +02:00
|
|
|
m_pHandle->viewport.width = getPreferredPlayerWindowSize().Width;
|
|
|
|
m_pHandle->viewport.height = getPreferredPlayerWindowSize().Height;
|
2014-05-29 05:48:54 +02:00
|
|
|
|
|
|
|
int nRet = gltf_renderer_set_content(m_pHandle);
|
|
|
|
if( nRet != 0 )
|
|
|
|
{
|
|
|
|
SAL_WARN("avmedia.opengl", "Error occured while parsing *.json file! Error code: " << nRet);
|
|
|
|
return uno::Reference< media::XFrameGrabber >();
|
|
|
|
}
|
2014-04-20 18:00:33 +02:00
|
|
|
OGLFrameGrabber *pFrameGrabber = new OGLFrameGrabber( m_pHandle );
|
2014-05-06 17:10:59 +02:00
|
|
|
return uno::Reference< media::XFrameGrabber >( pFrameGrabber );
|
2014-03-26 18:46:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
OUString SAL_CALL OGLPlayer::getImplementationName()
|
|
|
|
throw ( ::com::sun::star::uno::RuntimeException, std::exception )
|
|
|
|
{
|
|
|
|
return OUString("com.sun.star.comp.avmedia.Player_OpenGL");
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL OGLPlayer::supportsService( const OUString& rServiceName )
|
2014-04-03 11:28:53 +02:00
|
|
|
throw ( uno::RuntimeException, std::exception )
|
2014-03-26 18:46:52 +01:00
|
|
|
{
|
|
|
|
return cppu::supportsService(this, rServiceName);
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Sequence< OUString > SAL_CALL OGLPlayer::getSupportedServiceNames()
|
2014-04-03 11:28:53 +02:00
|
|
|
throw ( uno::RuntimeException, std::exception )
|
2014-03-26 18:46:52 +01:00
|
|
|
{
|
|
|
|
uno::Sequence< OUString > aRet(1);
|
|
|
|
aRet[0] = OUString("com.sun.star.media.Player_OpenGL");
|
|
|
|
return aRet;
|
|
|
|
}
|
|
|
|
|
2014-05-16 22:07:16 +02:00
|
|
|
IMPL_LINK(OGLPlayer,TimerHandler,Timer*,pTimer)
|
|
|
|
{
|
|
|
|
if (pTimer == &m_aTimer)
|
|
|
|
{
|
2014-05-28 15:38:22 +02:00
|
|
|
osl::MutexGuard aGuard(m_aMutex);
|
2014-05-16 22:07:16 +02:00
|
|
|
m_pOGLWindow->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-26 18:46:52 +01:00
|
|
|
} // namespace ogl
|
|
|
|
} // namespace avmedia
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|