Kaydet (Commit) 8a844a4b authored tarafından Minh Ngo's avatar Minh Ngo

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
üst 88011f4c
#include "vlcmanager.hxx" #include "vlcmanager.hxx"
#include "vlcplayer.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; using namespace ::com::sun::star;
...@@ -13,7 +17,13 @@ Manager::Manager( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) ...@@ -13,7 +17,13 @@ Manager::Manager( const uno::Reference< lang::XMultiServiceFactory >& rxMgr )
: mEventHandler(new VLC::EventHandler( "EventHandler" ) ) : mEventHandler(new VLC::EventHandler( "EventHandler" ) )
, mxMgr( rxMgr ) , 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() Manager::~Manager()
...@@ -23,6 +33,9 @@ Manager::~Manager() ...@@ -23,6 +33,9 @@ Manager::~Manager()
uno::Reference< media::XPlayer > SAL_CALL Manager::createPlayer( const rtl::OUString& rURL ) uno::Reference< media::XPlayer > SAL_CALL Manager::createPlayer( const rtl::OUString& rURL )
throw (uno::RuntimeException) 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)) if ( !rURL.isEmpty() || (mPlayer.is() && dynamic_cast<VLCPlayer*>( mPlayer.get() )->url() != rURL))
{ {
VLCPlayer* pPlayer( new VLCPlayer( rURL, mEventHandler /*, mxMgr */ ) ); VLCPlayer* pPlayer( new VLCPlayer( rURL, mEventHandler /*, mxMgr */ ) );
...@@ -41,12 +54,15 @@ rtl::OUString SAL_CALL Manager::getImplementationName() ...@@ -41,12 +54,15 @@ rtl::OUString SAL_CALL Manager::getImplementationName()
sal_Bool SAL_CALL Manager::supportsService( const rtl::OUString& serviceName ) sal_Bool SAL_CALL Manager::supportsService( const rtl::OUString& serviceName )
throw (uno::RuntimeException) throw (uno::RuntimeException)
{ {
return serviceName == VLC_SERVICENAME; return serviceName == VLC_SERVICENAME && m_is_vlc_found;
} }
uno::Sequence< rtl::OUString > SAL_CALL Manager::getSupportedServiceNames() uno::Sequence< rtl::OUString > SAL_CALL Manager::getSupportedServiceNames()
throw (uno::RuntimeException) throw (uno::RuntimeException)
{ {
if ( !m_is_vlc_found )
return uno::Sequence< rtl::OUString >();
::uno::Sequence< OUString > aRet(1); ::uno::Sequence< OUString > aRet(1);
aRet[0] = VLC_SERVICENAME; aRet[0] = VLC_SERVICENAME;
return aRet; return aRet;
......
...@@ -45,6 +45,8 @@ public: ...@@ -45,6 +45,8 @@ public:
private: private:
::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMgr; ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMgr;
::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > mPlayer; ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > mPlayer;
bool m_is_vlc_found;
}; };
} }
......
...@@ -32,4 +32,4 @@ void EventHandler::execute() ...@@ -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
...@@ -31,4 +31,4 @@ namespace VLC ...@@ -31,4 +31,4 @@ namespace VLC
#endif // _WRAPPER_EVENT_HANDLER_HXX #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
...@@ -30,16 +30,9 @@ namespace VLC ...@@ -30,16 +30,9 @@ namespace VLC
libvlc_event_type_t i_event_type, libvlc_event_type_t i_event_type,
libvlc_callback_t f_callback, libvlc_callback_t f_callback,
void *p_user_data ); 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 ); EventManager *instance = static_cast<EventManager*>( pData );
switch ( event->type ) switch ( event->type )
...@@ -53,11 +46,23 @@ void EventManagerEventHandler( const libvlc_event_t *event, void *pData ) ...@@ -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 ) EventManager::EventManager( VLC::Player& player, boost::shared_ptr<VLC::EventHandler> eh )
: mEventHandler( eh ) : mEventHandler( eh )
, mManager( libvlc_media_player_event_manager( player ) )
{ {
InitApiMap( VLC_EVENT_MANAGER_API );
mManager = libvlc_media_player_event_manager( player );
} }
EventManager::~EventManager() EventManager::~EventManager()
...@@ -67,9 +72,9 @@ EventManager::~EventManager() ...@@ -67,9 +72,9 @@ EventManager::~EventManager()
void EventManager::registerSignal( int signal, const Callback& callback ) void EventManager::registerSignal( int signal, const Callback& callback )
{ {
if ( callback.empty() ) if ( callback.empty() )
libvlc_event_detach( mManager, signal, EventManagerEventHandler, this ); libvlc_event_detach( mManager, signal, Handler, this );
else else
libvlc_event_attach( mManager, signal, EventManagerEventHandler, this ); libvlc_event_attach( mManager, signal, Handler, this );
} }
void EventManager::onPaused( const EventManager::Callback& callback ) void EventManager::onPaused( const EventManager::Callback& callback )
......
...@@ -23,8 +23,9 @@ namespace VLC ...@@ -23,8 +23,9 @@ namespace VLC
class EventHandler; class EventHandler;
class EventManager class EventManager
{ {
friend void EventManagerEventHandler( const libvlc_event_t *event, void *pData );
public: public:
static bool LoadSymbols();
typedef boost::function<void()> Callback; typedef boost::function<void()> Callback;
EventManager( VLC::Player& player, boost::shared_ptr<VLC::EventHandler> eh ); EventManager( VLC::Player& player, boost::shared_ptr<VLC::EventHandler> eh );
...@@ -41,6 +42,8 @@ namespace VLC ...@@ -41,6 +42,8 @@ namespace VLC
TCallback mOnEndReached; TCallback mOnEndReached;
void registerSignal( int signal, const Callback& callback ); void registerSignal( int signal, const Callback& callback );
static void Handler( const libvlc_event_t *event, void *pData );
}; };
} }
......
...@@ -17,20 +17,23 @@ namespace VLC ...@@ -17,20 +17,23 @@ namespace VLC
libvlc_instance_t* ( *libvlc_new ) ( int argc, const char * const *argv ); libvlc_instance_t* ( *libvlc_new ) ( int argc, const char * const *argv );
void ( *libvlc_release ) ( libvlc_instance_t *p_instance ); void ( *libvlc_release ) ( libvlc_instance_t *p_instance );
void ( *libvlc_retain ) ( libvlc_instance_t *p_instance ); void ( *libvlc_retain ) ( libvlc_instance_t *p_instance );
}
bool Instance::LoadSymbols()
{
ApiMap VLC_INSTANCE_API[] = ApiMap VLC_INSTANCE_API[] =
{ {
SYM_MAP( libvlc_new ), SYM_MAP( libvlc_new ),
SYM_MAP( libvlc_release ), SYM_MAP( libvlc_release ),
SYM_MAP( libvlc_retain ) SYM_MAP( libvlc_retain )
}; };
return InitApiMap( VLC_INSTANCE_API );
} }
Instance::Instance( int argc, const char * const argv[] ) 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 ) Instance::Instance( const Instance& other )
......
...@@ -19,6 +19,7 @@ namespace VLC ...@@ -19,6 +19,7 @@ namespace VLC
class Instance class Instance
{ {
public: public:
static bool LoadSymbols();
Instance( int argc, const char * const argv[] ); Instance( int argc, const char * const argv[] );
Instance( const Instance& other ); Instance( const Instance& other );
const Instance& operator=( const Instance& other ); const Instance& operator=( const Instance& other );
......
...@@ -21,13 +21,6 @@ namespace VLC ...@@ -21,13 +21,6 @@ namespace VLC
void ( *libvlc_media_release ) ( libvlc_media_t *p_md ); void ( *libvlc_media_release ) ( libvlc_media_t *p_md );
void ( *libvlc_media_retain ) ( 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 ) libvlc_media_t* InitMedia( const rtl::OUString& url, VLC::Instance& instance )
{ {
rtl::OString dest; rtl::OString dest;
...@@ -35,14 +28,23 @@ namespace VLC ...@@ -35,14 +28,23 @@ namespace VLC
return libvlc_media_new_path(instance, dest.getStr()); 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 ) 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 ) Media::Media( const Media& other )
......
...@@ -20,6 +20,7 @@ namespace VLC ...@@ -20,6 +20,7 @@ namespace VLC
class Media class Media
{ {
public: public:
static bool LoadSymbols();
Media( const rtl::OUString& url, Instance& instance ); Media( const rtl::OUString& url, Instance& instance );
Media( const Media& other ); Media( const Media& other );
const Media& operator=( const Media& other ); const Media& operator=( const Media& other );
......
...@@ -41,7 +41,10 @@ namespace VLC ...@@ -41,7 +41,10 @@ namespace VLC
void ( *libvlc_media_player_set_xwindow ) ( libvlc_media_player_t *p_mi, uint32_t drawable ); 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 ); 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); void ( *libvlc_video_set_mouse_input ) ( libvlc_media_player_t *p_mi, unsigned on);
}
bool Player::LoadSymbols()
{
ApiMap VLC_PLAYER_API[] = ApiMap VLC_PLAYER_API[] =
{ {
SYM_MAP( libvlc_media_player_new_from_media ), SYM_MAP( libvlc_media_player_new_from_media ),
...@@ -64,12 +67,13 @@ namespace VLC ...@@ -64,12 +67,13 @@ namespace VLC
SYM_MAP( libvlc_video_set_mouse_input ), SYM_MAP( libvlc_video_set_mouse_input ),
SYM_MAP( libvlc_media_player_retain ) SYM_MAP( libvlc_media_player_retain )
}; };
return InitApiMap( VLC_PLAYER_API );
} }
Player::Player(Media& media) 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 ) Player::Player( const Player& other )
......
...@@ -23,6 +23,7 @@ namespace VLC ...@@ -23,6 +23,7 @@ namespace VLC
class Player class Player
{ {
public: public:
static bool LoadSymbols();
Player( Media& media ); Player( Media& media );
Player( const Player& other ); Player( const Player& other );
const Player& operator=( const Player& other ); const Player& operator=( const Player& other );
......
...@@ -53,31 +53,34 @@ namespace ...@@ -53,31 +53,34 @@ namespace
} }
} }
template<size_t N> namespace VLC
bool InitApiMap( const ApiMap ( &pMap )[N] )
{ {
oslModule aModule; template<size_t N>
bool InitApiMap( const ApiMap ( &pMap )[N] )
for (uint j = 0; j < sizeof(libNames) / sizeof(libNames[0]); ++j)
{ {
aModule = osl_loadModule( OUString::createFromAscii oslModule aModule;
( libNames[ j ] ).pData,
SAL_LOADMODULE_DEFAULT );
if( aModule == NULL)
continue;
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 ); 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 #endif
......
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