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 "vlcplayer.hxx"
#include "wrapper/Instance.hxx"
#include "wrapper/EventManager.hxx"
#include "wrapper/Media.hxx"
#include "wrapper/Player.hxx"
using namespace ::com::sun::star;
......@@ -13,6 +17,12 @@ Manager::Manager( const uno::Reference< lang::XMultiServiceFactory >& rxMgr )
: mEventHandler(new VLC::EventHandler( "EventHandler" ) )
, mxMgr( rxMgr )
{
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();
}
......@@ -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;
......
......@@ -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;
};
}
......
......@@ -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 )
......
......@@ -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 );
};
}
......
......@@ -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 )
......
......@@ -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 );
......
......@@ -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 )
......
......@@ -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 );
......
......@@ -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 )
......
......@@ -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 );
......
......@@ -53,9 +53,11 @@ namespace
}
}
template<size_t N>
bool InitApiMap( const ApiMap ( &pMap )[N] )
namespace VLC
{
template<size_t N>
bool InitApiMap( const ApiMap ( &pMap )[N] )
{
oslModule aModule;
for (uint j = 0; j < sizeof(libNames) / sizeof(libNames[0]); ++j)
......@@ -78,6 +80,7 @@ bool InitApiMap( const ApiMap ( &pMap )[N] )
std::cerr << "Cannot load libvlc" << std::endl;
return false;
}
}
#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