summaryrefslogtreecommitdiff
path: root/avmedia
diff options
context:
space:
mode:
authorMinh Ngo <nlminhtl@gmail.com>2013-09-08 00:52:46 +0300
committerMinh Ngo <nlminhtl@gmail.com>2013-09-08 00:54:29 +0300
commit79bed99d078d3fcc7445a150a70fc085fdcf3d67 (patch)
tree9ea1d9aca2857100250c9beeff011085ad0249e2 /avmedia
parent6b1b5b7c0b0e75c625603f3c6025484988cd5482 (diff)
Refactoring vlc module
Change-Id: If5454d2ce70eee40cf42205a5dcbcfef93f0abe8
Diffstat (limited to 'avmedia')
-rw-r--r--avmedia/source/vlc/vlcframegrabber.cxx8
-rw-r--r--avmedia/source/vlc/vlcframegrabber.hxx4
-rw-r--r--avmedia/source/vlc/vlcmanager.cxx40
-rw-r--r--avmedia/source/vlc/vlcmanager.hxx10
-rw-r--r--avmedia/source/vlc/vlcplayer.cxx29
-rw-r--r--avmedia/source/vlc/vlcplayer.hxx23
-rw-r--r--avmedia/source/vlc/wrapper/EventManager.cxx11
-rw-r--r--avmedia/source/vlc/wrapper/EventManager.hxx5
-rw-r--r--avmedia/source/vlc/wrapper/Player.cxx6
-rw-r--r--avmedia/source/vlc/wrapper/Player.hxx2
-rw-r--r--avmedia/source/vlc/wrapper/Wrapper.hxx14
11 files changed, 85 insertions, 67 deletions
diff --git a/avmedia/source/vlc/vlcframegrabber.cxx b/avmedia/source/vlc/vlcframegrabber.cxx
index 6a25d396614c..5c01a2d6f154 100644
--- a/avmedia/source/vlc/vlcframegrabber.cxx
+++ b/avmedia/source/vlc/vlcframegrabber.cxx
@@ -24,7 +24,7 @@ const ::rtl::OUString AVMEDIA_VLC_GRABBER_IMPLEMENTATIONNAME = "com.sun.star.com
const ::rtl::OUString AVMEDIA_VLC_GRABBER_SERVICENAME = "com.sun.star.media.VLCFrameGrabber_VLC";
const int MSEC_IN_SEC = 1000;
-VLCFrameGrabber::VLCFrameGrabber( VLC::Player& player, boost::shared_ptr<VLC::EventHandler> eh, const rtl::OUString& url )
+VLCFrameGrabber::VLCFrameGrabber( VLC::Player& player, VLC::EventHandler& eh, const rtl::OUString& url )
: FrameGrabber_BASE()
, mPlayer( player )
, mUrl( url )
@@ -45,7 +45,8 @@ VLCFrameGrabber::VLCFrameGrabber( VLC::Player& player, boost::shared_ptr<VLC::Ev
if ( !mPlayer.play() )
{
- std::cerr << "Couldn't play" << std::endl;
+ std::cerr << "Couldn't play when trying to grab frame" << std::endl;
+ return ::uno::Reference< css::graphic::XGraphic >();
}
mPlayer.setTime( ( fMediaTime > 0 ? fMediaTime : 0 ) * MSEC_IN_SEC );
@@ -63,7 +64,8 @@ VLCFrameGrabber::VLCFrameGrabber( VLC::Player& player, boost::shared_ptr<VLC::Ev
return ::uno::Reference< css::graphic::XGraphic >();
}
- mPlayer.takeSnapshot( fileName );
+ std::cout << "Take snapshot " << fileName << std::endl;
+ std::cout << mPlayer.takeSnapshot( fileName ) << std::endl;
mPlayer.setMute( false );
mPlayer.stop();
diff --git a/avmedia/source/vlc/vlcframegrabber.hxx b/avmedia/source/vlc/vlcframegrabber.hxx
index 8dc7b56c76c5..616ab2f5952e 100644
--- a/avmedia/source/vlc/vlcframegrabber.hxx
+++ b/avmedia/source/vlc/vlcframegrabber.hxx
@@ -41,9 +41,9 @@ class VLCFrameGrabber : public FrameGrabber_BASE
{
VLC::Player& mPlayer;
const rtl::OUString& mUrl;
- boost::shared_ptr<VLC::EventHandler> mEventHandler;
+ VLC::EventHandler& mEventHandler;
public:
- VLCFrameGrabber( VLC::Player& player, boost::shared_ptr<VLC::EventHandler> eh, const rtl::OUString& url );
+ VLCFrameGrabber( VLC::Player& player, VLC::EventHandler& eh, const rtl::OUString& url );
::com::sun::star::uno::Reference< css::graphic::XGraphic > SAL_CALL grabFrame( double fMediaTime ) throw ( ::com::sun::star::uno::RuntimeException );
diff --git a/avmedia/source/vlc/vlcmanager.cxx b/avmedia/source/vlc/vlcmanager.cxx
index 56e43654c40d..ef536f44c060 100644
--- a/avmedia/source/vlc/vlcmanager.cxx
+++ b/avmedia/source/vlc/vlcmanager.cxx
@@ -13,20 +13,32 @@ using namespace ::com::sun::star;
namespace avmedia {
namespace vlc {
-const rtl::OUString VLC_IMPLEMENTATION_NAME = "com.sun.star.comp.avmedia.Manager_VLC";
-const ::rtl::OUString VLC_SERVICENAME = "com.sun.star.media.Manager_VLC";
+namespace
+{
+ const rtl::OUString VLC_IMPLEMENTATION_NAME = "com.sun.star.comp.avmedia.Manager_VLC";
+ const ::rtl::OUString VLC_SERVICENAME = "com.sun.star.media.Manager_VLC";
+
+ const char * const VLC_ARGS[] = {
+ "-Vdummy",
+ "--snapshot-format=png",
+ "--ffmpeg-threads",
+ "--verbose=-1"
+ };
+}
Manager::Manager( const uno::Reference< lang::XMultiServiceFactory >& rxMgr )
- : mEventHandler(new VLC::EventHandler( "EventHandler" ) )
+ : mEventHandler()
, mxMgr( rxMgr )
{
using namespace VLC;
static bool success = Instance::LoadSymbols() && EventManager::LoadSymbols()
- && Media::LoadSymbols() && Player::LoadSymbols() && Common::LoadSymbols();
+ && Media::LoadSymbols() && Player::LoadSymbols()
+ && Common::LoadSymbols();
m_is_vlc_found = success;
if (m_is_vlc_found)
{
+ mInstance.reset(new Instance( sizeof( VLC_ARGS ) / sizeof( VLC_ARGS[0] ), VLC_ARGS ));
//Check VLC version
std::vector<std::string> verComponents;
const std::string str(Common::Version());
@@ -37,20 +49,20 @@ Manager::Manager( const uno::Reference< lang::XMultiServiceFactory >& rxMgr )
boost::is_any_of(". "));
if (verComponents.size() < 3
|| boost::lexical_cast<int>(verComponents[0]) < 2
- || (boost::lexical_cast<int>(verComponents[1]) == 0 && boost::lexical_cast<int>(verComponents[2]) < 8))
+ || (boost::lexical_cast<int>(verComponents[1]) == 0
+ && boost::lexical_cast<int>(verComponents[2]) < 8))
{
m_is_vlc_found = false;
}
}
- std::cout << "T" << std::endl;
- //if (m_is_vlc_found)
- // mEventHandler->launch();
- std::cout << "T" << std::endl;
+ if (m_is_vlc_found)
+ mEventHandler.create();
}
Manager::~Manager()
{
+ mEventHandler.stop();
}
uno::Reference< media::XPlayer > SAL_CALL Manager::createPlayer( const rtl::OUString& rURL )
@@ -59,12 +71,10 @@ uno::Reference< media::XPlayer > SAL_CALL Manager::createPlayer( const rtl::OUSt
if ( !m_is_vlc_found )
return uno::Reference< media::XPlayer >();
- if ( !rURL.isEmpty() || (mPlayer.is() && dynamic_cast<VLCPlayer*>( mPlayer.get() )->url() != rURL))
- {
- VLCPlayer* pPlayer( new VLCPlayer( rURL, mEventHandler /*, mxMgr */ ) );
- mPlayer = uno::Reference< media::XPlayer >( pPlayer );
- }
- std::cout << "A" << std::endl;
+ VLCPlayer* pPlayer( new VLCPlayer( rURL,
+ *mInstance,
+ mEventHandler /*, mxMgr */ ) );
+ mPlayer = uno::Reference< media::XPlayer >( pPlayer );
return mPlayer;
}
diff --git a/avmedia/source/vlc/vlcmanager.hxx b/avmedia/source/vlc/vlcmanager.hxx
index b2ea01fbbb5b..92e01691370a 100644
--- a/avmedia/source/vlc/vlcmanager.hxx
+++ b/avmedia/source/vlc/vlcmanager.hxx
@@ -19,11 +19,10 @@
#ifndef _VLCMANAGER_HXX
#define _VLCMANAGER_HXX
-#include <boost/shared_ptr.hpp>
+#include <boost/scoped_ptr.hpp>
+#include <com/sun/star/media/XManager.hpp>
#include "vlccommon.hxx"
-
-#include "com/sun/star/media/XManager.hpp"
-#include "wrapper/EventHandler.hxx"
+#include "wrapper/Wrapper.hxx"
namespace avmedia {
namespace vlc {
@@ -31,7 +30,8 @@ namespace vlc {
class Manager : public ::cppu::WeakImplHelper2 < ::com::sun::star::media::XManager,
::com::sun::star::lang::XServiceInfo >
{
- boost::shared_ptr<VLC::EventHandler> mEventHandler;
+ boost::scoped_ptr<VLC::Instance> mInstance;
+ VLC::EventHandler mEventHandler;
public:
Manager( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxMgr );
~Manager();
diff --git a/avmedia/source/vlc/vlcplayer.cxx b/avmedia/source/vlc/vlcplayer.cxx
index 9c7d714ab2b2..a43c412d3d55 100644
--- a/avmedia/source/vlc/vlcplayer.cxx
+++ b/avmedia/source/vlc/vlcplayer.cxx
@@ -1,3 +1,4 @@
+#include <iostream>
#include <boost/bind.hpp>
#include <vcl/syschild.hxx>
#include <vcl/sysdata.hxx>
@@ -18,34 +19,24 @@ namespace
const ::rtl::OUString AVMEDIA_VLC_PLAYER_SERVICENAME = "com.sun.star.media.Player_VLC";
const int MS_IN_SEC = 1000; // Millisec in sec
-
- const char * const VLC_ARGS[] = {
- "-Vdummy",
- "--snapshot-format=png",
- "--ffmpeg-threads",
- "--verbose=2"
- };
}
-VLCPlayer::VLCPlayer( const rtl::OUString& iurl, boost::shared_ptr<VLC::EventHandler> eh )
- : VLC_Base(m_aMutex)
+VLCPlayer::VLCPlayer( const rtl::OUString& url,
+ VLC::Instance& instance,
+ VLC::EventHandler& eh )
+ : VLC_Base( m_aMutex )
+ , mInstance( instance )
, mEventHandler( eh )
- , mInstance( sizeof( VLC_ARGS ) / sizeof( VLC_ARGS[0] ), VLC_ARGS )
- , mMedia( iurl, mInstance )
+ , mMedia( url, mInstance )
, mPlayer( mMedia )
, mEventManager( mPlayer, mEventHandler )
- , mUrl( iurl )
+ , mUrl( url )
, mPlaybackLoop( false )
{
- mPlayer.setMouseHandling(false);
-}
-
-const rtl::OUString& VLCPlayer::url() const
-{
- return mUrl;
+ mPlayer.setMouseHandling( false );
}
-void SAL_CALL VLCPlayer::start() throw (::com::sun::star::uno::RuntimeException)
+void SAL_CALL VLCPlayer::start() throw ( ::com::sun::star::uno::RuntimeException )
{
::osl::MutexGuard aGuard(m_aMutex);
mPlayer.play();
diff --git a/avmedia/source/vlc/vlcplayer.hxx b/avmedia/source/vlc/vlcplayer.hxx
index 2996cb203d6c..e2aa17bda89d 100644
--- a/avmedia/source/vlc/vlcplayer.hxx
+++ b/avmedia/source/vlc/vlcplayer.hxx
@@ -42,17 +42,18 @@ typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::media::XPlayer,
class VLCPlayer : public ::cppu::BaseMutex,
public VLC_Base
{
- boost::shared_ptr<VLC::EventHandler> mEventHandler;
- VLC::Instance mInstance;
+ VLC::Instance& mInstance;
+ VLC::EventHandler& mEventHandler;
+
VLC::Media mMedia;
VLC::Player mPlayer;
VLC::EventManager mEventManager;
const rtl::OUString mUrl;
bool mPlaybackLoop;
public:
- VLCPlayer( const rtl::OUString& iurl, boost::shared_ptr<VLC::EventHandler> eh );
-
- const rtl::OUString& url() const;
+ VLCPlayer( const rtl::OUString& url,
+ VLC::Instance& instance,
+ VLC::EventHandler& eh );
void SAL_CALL start() throw ( ::com::sun::star::uno::RuntimeException );
void SAL_CALL stop() throw ( ::com::sun::star::uno::RuntimeException );
@@ -70,11 +71,15 @@ public:
css::awt::Size SAL_CALL getPreferredPlayerWindowSize() throw ( ::com::sun::star::uno::RuntimeException );
::com::sun::star::uno::Reference< css::media::XPlayerWindow > SAL_CALL createPlayerWindow( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
throw ( ::com::sun::star::uno::RuntimeException );
- ::com::sun::star::uno::Reference< css::media::XFrameGrabber > SAL_CALL createFrameGrabber() throw ( ::com::sun::star::uno::RuntimeException );
+ ::com::sun::star::uno::Reference< css::media::XFrameGrabber > SAL_CALL createFrameGrabber()
+ throw ( ::com::sun::star::uno::RuntimeException );
- ::rtl::OUString SAL_CALL getImplementationName() throw ( ::com::sun::star::uno::RuntimeException );;
- ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& serviceName ) throw ( ::com::sun::star::uno::RuntimeException );;
- ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw ( ::com::sun::star::uno::RuntimeException );;
+ ::rtl::OUString SAL_CALL getImplementationName()
+ throw ( ::com::sun::star::uno::RuntimeException );
+ ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& serviceName )
+ throw ( ::com::sun::star::uno::RuntimeException );;
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
+ throw ( ::com::sun::star::uno::RuntimeException );;
private:
void replay();
diff --git a/avmedia/source/vlc/wrapper/EventManager.cxx b/avmedia/source/vlc/wrapper/EventManager.cxx
index 2edad303fd3f..0aac04151aec 100644
--- a/avmedia/source/vlc/wrapper/EventManager.cxx
+++ b/avmedia/source/vlc/wrapper/EventManager.cxx
@@ -30,13 +30,14 @@ namespace VLC
void EventManager::Handler( const libvlc_event_t *event, void *pData )
{
EventManager *instance = static_cast<EventManager*>( pData );
+ std::cout << "HANDLER" << std::endl;
switch ( event->type )
{
case libvlc_MediaPlayerPaused:
- instance->mEventHandler->mCallbackQueue.push( instance->mOnPaused );
+ instance->mEventHandler.mCallbackQueue.push( instance->mOnPaused );
break;
case libvlc_MediaPlayerEndReached:
- instance->mEventHandler->mCallbackQueue.push( instance->mOnEndReached );
+ instance->mEventHandler.mCallbackQueue.push( instance->mOnEndReached );
break;
}
}
@@ -53,17 +54,13 @@ bool EventManager::LoadSymbols()
return InitApiMap( VLC_EVENT_MANAGER_API );
}
-EventManager::EventManager( VLC::Player& player, boost::shared_ptr<VLC::EventHandler> eh )
+EventManager::EventManager( VLC::Player& player, VLC::EventHandler& eh )
: mEventHandler( eh )
, mManager( libvlc_media_player_event_manager( player ) )
{
}
-EventManager::~EventManager()
-{
-}
-
void EventManager::registerSignal( int signal, const Callback& callback )
{
if ( callback.empty() )
diff --git a/avmedia/source/vlc/wrapper/EventManager.hxx b/avmedia/source/vlc/wrapper/EventManager.hxx
index 751c0e8c20f0..5efdc07a29e6 100644
--- a/avmedia/source/vlc/wrapper/EventManager.hxx
+++ b/avmedia/source/vlc/wrapper/EventManager.hxx
@@ -28,14 +28,13 @@ namespace VLC
static bool LoadSymbols();
typedef boost::function<void()> Callback;
- EventManager( VLC::Player& player, boost::shared_ptr<VLC::EventHandler> eh );
- virtual ~EventManager();
+ EventManager( VLC::Player& player, VLC::EventHandler& eh );
void onPaused( const Callback& callback = Callback() );
void onEndReached( const Callback& callback = Callback() );
private:
- boost::shared_ptr<VLC::EventHandler> mEventHandler;
+ VLC::EventHandler& mEventHandler;
typedef boost::function< void() > TCallback;
libvlc_event_manager_t *mManager;
TCallback mOnPaused;
diff --git a/avmedia/source/vlc/wrapper/Player.cxx b/avmedia/source/vlc/wrapper/Player.cxx
index 973078a915bb..f2faee0bfe3a 100644
--- a/avmedia/source/vlc/wrapper/Player.cxx
+++ b/avmedia/source/vlc/wrapper/Player.cxx
@@ -115,7 +115,7 @@ namespace VLC
bool Player::play()
{
- return libvlc_media_player_play( mPlayer );
+ return libvlc_media_player_play( mPlayer ) == 0;
}
void Player::pause()
@@ -190,11 +190,11 @@ namespace VLC
#endif
}
- void Player::takeSnapshot(const rtl::OUString& file)
+ bool Player::takeSnapshot(const rtl::OUString& file)
{
rtl::OString dest;
file.convertToString( &dest, RTL_TEXTENCODING_UTF8, 0 );
- libvlc_video_take_snapshot( mPlayer, 0, dest.getStr(), 0, 0 );
+ return libvlc_video_take_snapshot( mPlayer, 0, dest.getStr(), 480, 360 ) == 0;
}
bool Player::hasVout() const
diff --git a/avmedia/source/vlc/wrapper/Player.hxx b/avmedia/source/vlc/wrapper/Player.hxx
index 4ff066a8dc38..bb5e6b9fc886 100644
--- a/avmedia/source/vlc/wrapper/Player.hxx
+++ b/avmedia/source/vlc/wrapper/Player.hxx
@@ -51,7 +51,7 @@ namespace VLC
void setWindow( intptr_t id );
- void takeSnapshot(const rtl::OUString& file);
+ bool takeSnapshot(const rtl::OUString& file);
bool hasVout() const;
diff --git a/avmedia/source/vlc/wrapper/Wrapper.hxx b/avmedia/source/vlc/wrapper/Wrapper.hxx
new file mode 100644
index 000000000000..1af0323d7fab
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/Wrapper.hxx
@@ -0,0 +1,14 @@
+/* -*- 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 "Common.hxx"
+#include "EventHandler.hxx"
+#include "EventManager.hxx"
+#include "Instance.hxx"
+#include "Media.hxx"
+#include "Player.hxx" \ No newline at end of file