avmedia/source/vlc/vlcmanager.cxx | 20 +++++++++++++-- avmedia/source/vlc/vlcmanager.hxx | 2 + avmedia/source/vlc/wrapper/EventHandler.cxx | 2 - avmedia/source/vlc/wrapper/EventHandler.hxx | 2 - avmedia/source/vlc/wrapper/EventManager.cxx | 29 ++++++++++++--------- avmedia/source/vlc/wrapper/EventManager.hxx | 5 +++ avmedia/source/vlc/wrapper/Instance.cxx | 9 ++++-- avmedia/source/vlc/wrapper/Instance.hxx | 1 avmedia/source/vlc/wrapper/Media.cxx | 22 +++++++++------- avmedia/source/vlc/wrapper/Media.hxx | 1 avmedia/source/vlc/wrapper/Player.cxx | 8 ++++-- avmedia/source/vlc/wrapper/Player.hxx | 1 avmedia/source/vlc/wrapper/SymbolLoader.hxx | 37 +++++++++++++++------------- 13 files changed, 90 insertions(+), 49 deletions(-)
New commits: commit 8a844a4b924eaadec25f9e27cef56b52a0abe50e Author: Minh Ngo <nlmin...@gmail.com> Date: Sun Aug 25 20:56:20 2013 +0300 Linking symbols only once. If they were linked unsuccessfully a VLC instance won't be created. Some static functions and variables were encapsulated. Change-Id: I9d07ac9a73a6bd59928bcc349458ea346a26deb4 diff --git a/avmedia/source/vlc/vlcmanager.cxx b/avmedia/source/vlc/vlcmanager.cxx index 6a5431d..5565f5a 100644 --- a/avmedia/source/vlc/vlcmanager.cxx +++ b/avmedia/source/vlc/vlcmanager.cxx @@ -1,5 +1,9 @@ #include "vlcmanager.hxx" #include "vlcplayer.hxx" +#include "wrapper/Instance.hxx" +#include "wrapper/EventManager.hxx" +#include "wrapper/Media.hxx" +#include "wrapper/Player.hxx" using namespace ::com::sun::star; @@ -13,7 +17,13 @@ Manager::Manager( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) : mEventHandler(new VLC::EventHandler( "EventHandler" ) ) , mxMgr( rxMgr ) { - mEventHandler->launch(); + using namespace VLC; + static bool success = Instance::LoadSymbols() && EventManager::LoadSymbols() + && Media::LoadSymbols() && Player::LoadSymbols(); + + m_is_vlc_found = success; + if (m_is_vlc_found) + mEventHandler->launch(); } Manager::~Manager() @@ -23,6 +33,9 @@ Manager::~Manager() uno::Reference< media::XPlayer > SAL_CALL Manager::createPlayer( const rtl::OUString& rURL ) throw (uno::RuntimeException) { + 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 */ ) ); @@ -41,12 +54,15 @@ rtl::OUString SAL_CALL Manager::getImplementationName() sal_Bool SAL_CALL Manager::supportsService( const rtl::OUString& serviceName ) throw (uno::RuntimeException) { - return serviceName == VLC_SERVICENAME; + return serviceName == VLC_SERVICENAME && m_is_vlc_found; } uno::Sequence< rtl::OUString > SAL_CALL Manager::getSupportedServiceNames() throw (uno::RuntimeException) { + if ( !m_is_vlc_found ) + return uno::Sequence< rtl::OUString >(); + ::uno::Sequence< OUString > aRet(1); aRet[0] = VLC_SERVICENAME; return aRet; diff --git a/avmedia/source/vlc/vlcmanager.hxx b/avmedia/source/vlc/vlcmanager.hxx index dbcaed6..b2ea01f 100644 --- a/avmedia/source/vlc/vlcmanager.hxx +++ b/avmedia/source/vlc/vlcmanager.hxx @@ -45,6 +45,8 @@ public: private: ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMgr; ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > mPlayer; + + bool m_is_vlc_found; }; } diff --git a/avmedia/source/vlc/wrapper/EventHandler.cxx b/avmedia/source/vlc/wrapper/EventHandler.cxx index 19054d6..6104d31 100644 --- a/avmedia/source/vlc/wrapper/EventHandler.cxx +++ b/avmedia/source/vlc/wrapper/EventHandler.cxx @@ -32,4 +32,4 @@ void EventHandler::execute() } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file diff --git a/avmedia/source/vlc/wrapper/EventHandler.hxx b/avmedia/source/vlc/wrapper/EventHandler.hxx index 9118da0..f203e39 100644 --- a/avmedia/source/vlc/wrapper/EventHandler.hxx +++ b/avmedia/source/vlc/wrapper/EventHandler.hxx @@ -31,4 +31,4 @@ namespace VLC #endif // _WRAPPER_EVENT_HANDLER_HXX -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file diff --git a/avmedia/source/vlc/wrapper/EventManager.cxx b/avmedia/source/vlc/wrapper/EventManager.cxx index b8a194b..fe893c7 100644 --- a/avmedia/source/vlc/wrapper/EventManager.cxx +++ b/avmedia/source/vlc/wrapper/EventManager.cxx @@ -30,16 +30,9 @@ namespace VLC libvlc_event_type_t i_event_type, libvlc_callback_t f_callback, void *p_user_data ); - - ApiMap VLC_EVENT_MANAGER_API[] = - { - SYM_MAP( libvlc_media_player_event_manager ), - SYM_MAP( libvlc_event_attach ), - SYM_MAP( libvlc_event_detach ) - }; } -void EventManagerEventHandler( const libvlc_event_t *event, void *pData ) +void EventManager::Handler( const libvlc_event_t *event, void *pData ) { EventManager *instance = static_cast<EventManager*>( pData ); switch ( event->type ) @@ -53,11 +46,23 @@ void EventManagerEventHandler( const libvlc_event_t *event, void *pData ) } } +bool EventManager::LoadSymbols() +{ + ApiMap VLC_EVENT_MANAGER_API[] = + { + SYM_MAP( libvlc_media_player_event_manager ), + SYM_MAP( libvlc_event_attach ), + SYM_MAP( libvlc_event_detach ) + }; + + return InitApiMap( VLC_EVENT_MANAGER_API ); +} + EventManager::EventManager( VLC::Player& player, boost::shared_ptr<VLC::EventHandler> eh ) : mEventHandler( eh ) + , mManager( libvlc_media_player_event_manager( player ) ) { - InitApiMap( VLC_EVENT_MANAGER_API ); - mManager = libvlc_media_player_event_manager( player ); + } EventManager::~EventManager() @@ -67,9 +72,9 @@ EventManager::~EventManager() void EventManager::registerSignal( int signal, const Callback& callback ) { if ( callback.empty() ) - libvlc_event_detach( mManager, signal, EventManagerEventHandler, this ); + libvlc_event_detach( mManager, signal, Handler, this ); else - libvlc_event_attach( mManager, signal, EventManagerEventHandler, this ); + libvlc_event_attach( mManager, signal, Handler, this ); } void EventManager::onPaused( const EventManager::Callback& callback ) diff --git a/avmedia/source/vlc/wrapper/EventManager.hxx b/avmedia/source/vlc/wrapper/EventManager.hxx index d0fdd07..751c0e8 100644 --- a/avmedia/source/vlc/wrapper/EventManager.hxx +++ b/avmedia/source/vlc/wrapper/EventManager.hxx @@ -23,8 +23,9 @@ namespace VLC class EventHandler; class EventManager { - friend void EventManagerEventHandler( const libvlc_event_t *event, void *pData ); + public: + static bool LoadSymbols(); typedef boost::function<void()> Callback; EventManager( VLC::Player& player, boost::shared_ptr<VLC::EventHandler> eh ); @@ -41,6 +42,8 @@ namespace VLC TCallback mOnEndReached; void registerSignal( int signal, const Callback& callback ); + + static void Handler( const libvlc_event_t *event, void *pData ); }; } diff --git a/avmedia/source/vlc/wrapper/Instance.cxx b/avmedia/source/vlc/wrapper/Instance.cxx index 39c2ce3..b9b6ff9 100644 --- a/avmedia/source/vlc/wrapper/Instance.cxx +++ b/avmedia/source/vlc/wrapper/Instance.cxx @@ -17,20 +17,23 @@ namespace VLC libvlc_instance_t* ( *libvlc_new ) ( int argc, const char * const *argv ); void ( *libvlc_release ) ( libvlc_instance_t *p_instance ); void ( *libvlc_retain ) ( libvlc_instance_t *p_instance ); + } + bool Instance::LoadSymbols() + { ApiMap VLC_INSTANCE_API[] = { SYM_MAP( libvlc_new ), SYM_MAP( libvlc_release ), SYM_MAP( libvlc_retain ) }; + + return InitApiMap( VLC_INSTANCE_API ); } Instance::Instance( int argc, const char * const argv[] ) + : mInstance( libvlc_new( argc, argv ) ) { - InitApiMap( VLC_INSTANCE_API ); - - mInstance = libvlc_new( argc, argv ); } Instance::Instance( const Instance& other ) diff --git a/avmedia/source/vlc/wrapper/Instance.hxx b/avmedia/source/vlc/wrapper/Instance.hxx index 887baf1..cbb6f4f 100644 --- a/avmedia/source/vlc/wrapper/Instance.hxx +++ b/avmedia/source/vlc/wrapper/Instance.hxx @@ -19,6 +19,7 @@ namespace VLC class Instance { public: + static bool LoadSymbols(); Instance( int argc, const char * const argv[] ); Instance( const Instance& other ); const Instance& operator=( const Instance& other ); diff --git a/avmedia/source/vlc/wrapper/Media.cxx b/avmedia/source/vlc/wrapper/Media.cxx index 825bb06..b893d42 100644 --- a/avmedia/source/vlc/wrapper/Media.cxx +++ b/avmedia/source/vlc/wrapper/Media.cxx @@ -21,13 +21,6 @@ namespace VLC void ( *libvlc_media_release ) ( libvlc_media_t *p_md ); void ( *libvlc_media_retain ) ( libvlc_media_t *p_md ); - ApiMap VLC_MEDIA_API[] = - { - SYM_MAP( libvlc_media_new_path ), - SYM_MAP( libvlc_media_release ), - SYM_MAP( libvlc_media_retain ) - }; - libvlc_media_t* InitMedia( const rtl::OUString& url, VLC::Instance& instance ) { rtl::OString dest; @@ -35,14 +28,23 @@ namespace VLC return libvlc_media_new_path(instance, dest.getStr()); } - } +bool Media::LoadSymbols() +{ + ApiMap VLC_MEDIA_API[] = + { + SYM_MAP( libvlc_media_new_path ), + SYM_MAP( libvlc_media_release ), + SYM_MAP( libvlc_media_retain ) + }; + + return InitApiMap( VLC_MEDIA_API ); +} Media::Media( const rtl::OUString& url, Instance& instance ) + : mMedia( InitMedia( url, instance ) ) { - InitApiMap(VLC_MEDIA_API); - mMedia = InitMedia( url, instance ); } Media::Media( const Media& other ) diff --git a/avmedia/source/vlc/wrapper/Media.hxx b/avmedia/source/vlc/wrapper/Media.hxx index 4821581..0575e6e 100644 --- a/avmedia/source/vlc/wrapper/Media.hxx +++ b/avmedia/source/vlc/wrapper/Media.hxx @@ -20,6 +20,7 @@ namespace VLC class Media { public: + static bool LoadSymbols(); Media( const rtl::OUString& url, Instance& instance ); Media( const Media& other ); const Media& operator=( const Media& other ); diff --git a/avmedia/source/vlc/wrapper/Player.cxx b/avmedia/source/vlc/wrapper/Player.cxx index 9c739bd..a36a15d 100644 --- a/avmedia/source/vlc/wrapper/Player.cxx +++ b/avmedia/source/vlc/wrapper/Player.cxx @@ -41,7 +41,10 @@ namespace VLC void ( *libvlc_media_player_set_xwindow ) ( libvlc_media_player_t *p_mi, uint32_t drawable ); unsigned ( *libvlc_media_player_has_vout ) ( libvlc_media_player_t *p_mi ); void ( *libvlc_video_set_mouse_input ) ( libvlc_media_player_t *p_mi, unsigned on); + } + bool Player::LoadSymbols() + { ApiMap VLC_PLAYER_API[] = { SYM_MAP( libvlc_media_player_new_from_media ), @@ -64,12 +67,13 @@ namespace VLC SYM_MAP( libvlc_video_set_mouse_input ), SYM_MAP( libvlc_media_player_retain ) }; + + return InitApiMap( VLC_PLAYER_API ); } Player::Player(Media& media) + : mPlayer( libvlc_media_player_new_from_media( media ) ) { - InitApiMap(VLC_PLAYER_API); - mPlayer = libvlc_media_player_new_from_media( media ); } Player::Player( const Player& other ) diff --git a/avmedia/source/vlc/wrapper/Player.hxx b/avmedia/source/vlc/wrapper/Player.hxx index bba169b..34886c9 100644 --- a/avmedia/source/vlc/wrapper/Player.hxx +++ b/avmedia/source/vlc/wrapper/Player.hxx @@ -23,6 +23,7 @@ namespace VLC class Player { public: + static bool LoadSymbols(); Player( Media& media ); Player( const Player& other ); const Player& operator=( const Player& other ); diff --git a/avmedia/source/vlc/wrapper/SymbolLoader.hxx b/avmedia/source/vlc/wrapper/SymbolLoader.hxx index 8730e05..92b52ee 100644 --- a/avmedia/source/vlc/wrapper/SymbolLoader.hxx +++ b/avmedia/source/vlc/wrapper/SymbolLoader.hxx @@ -53,31 +53,34 @@ namespace } } -template<size_t N> -bool InitApiMap( const ApiMap ( &pMap )[N] ) +namespace VLC { - oslModule aModule; - - for (uint j = 0; j < sizeof(libNames) / sizeof(libNames[0]); ++j) + template<size_t N> + bool InitApiMap( const ApiMap ( &pMap )[N] ) { - aModule = osl_loadModule( OUString::createFromAscii - ( libNames[ j ] ).pData, - SAL_LOADMODULE_DEFAULT ); - - if( aModule == NULL) - continue; + oslModule aModule; - if (tryLink( aModule, pMap )) + for (uint j = 0; j < sizeof(libNames) / sizeof(libNames[0]); ++j) { + aModule = osl_loadModule( OUString::createFromAscii + ( libNames[ j ] ).pData, + SAL_LOADMODULE_DEFAULT ); + + if( aModule == NULL) + continue; + + if (tryLink( aModule, pMap )) + { + osl_unloadModule( aModule ); + return true; + } + osl_unloadModule( aModule ); - return true; } - osl_unloadModule( aModule ); + std::cerr << "Cannot load libvlc" << std::endl; + return false; } - - std::cerr << "Cannot load libvlc" << std::endl; - return false; } #endif _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits