Skip to content
Browse files

sys: add methods for dynamic player addition/removal to PlayerCoreFac…

…tory
  • Loading branch information...
1 parent 335d8a1 commit e29f2f1747dec7bb4ced3f2b58eac8b574a7d192 @elupus committed Oct 28, 2012
View
14 xbmc/cores/playercorefactory/PlayerCoreConfig.h
@@ -38,9 +38,10 @@ class CPlayerCoreConfig
friend class CPlayerCoreFactory;
public:
- CPlayerCoreConfig(CStdString name, const EPLAYERCORES eCore, const TiXmlElement* pConfig)
+ CPlayerCoreConfig(CStdString name, const EPLAYERCORES eCore, const TiXmlElement* pConfig, const CStdString& id = "")
{
m_name = name;
+ m_id = id;
m_eCore = eCore;
m_bPlaysAudio = false;
m_bPlaysVideo = false;
@@ -70,6 +71,16 @@ friend class CPlayerCoreFactory;
return m_name;
}
+ const CStdString& GetId() const
+ {
+ return m_id;
+ }
+
+ const EPLAYERCORES& GetType() const
+ {
+ return m_eCore;
+ }
+
IPlayer* CreatePlayer(IPlayerCallback& callback) const
{
IPlayer* pPlayer;
@@ -113,6 +124,7 @@ friend class CPlayerCoreFactory;
private:
CStdString m_name;
+ CStdString m_id;
bool m_bPlaysAudio;
bool m_bPlaysVideo;
EPLAYERCORES m_eCore;
View
50 xbmc/cores/playercorefactory/PlayerCoreFactory.cpp
@@ -40,6 +40,8 @@ using namespace AUTOPTR;
std::vector<CPlayerCoreConfig *> CPlayerCoreFactory::s_vecCoreConfigs;
std::vector<CPlayerSelectionRule *> CPlayerCoreFactory::s_vecCoreSelectionRules;
+static CCriticalSection s_section;
+
CPlayerCoreFactory::CPlayerCoreFactory()
{}
@@ -72,6 +74,7 @@ IPlayer* CPlayerCoreFactory::CreatePlayer(const CStdString& strCore, IPlayerCall
IPlayer* CPlayerCoreFactory::CreatePlayer(const PLAYERCOREID eCore, IPlayerCallback& callback)
{
+ CSingleLock lock(s_section);
if (!s_vecCoreConfigs.size() || eCore-1 > s_vecCoreConfigs.size()-1)
return NULL;
@@ -80,6 +83,7 @@ IPlayer* CPlayerCoreFactory::CreatePlayer(const PLAYERCOREID eCore, IPlayerCallb
PLAYERCOREID CPlayerCoreFactory::GetPlayerCore(const CStdString& strCoreName)
{
+ CSingleLock lock(s_section);
if (!strCoreName.empty())
{
// Dereference "*default*player" aliases
@@ -101,29 +105,39 @@ PLAYERCOREID CPlayerCoreFactory::GetPlayerCore(const CStdString& strCoreName)
CStdString CPlayerCoreFactory::GetPlayerName(const PLAYERCOREID eCore)
{
+ CSingleLock lock(s_section);
return s_vecCoreConfigs[eCore-1]->GetName();
}
CPlayerCoreConfig* CPlayerCoreFactory::GetPlayerConfig(const CStdString& strCoreName)
{
+ CSingleLock lock(s_section);
PLAYERCOREID id = GetPlayerCore(strCoreName);
if (id != EPC_NONE) return s_vecCoreConfigs[id-1];
else return NULL;
}
void CPlayerCoreFactory::GetPlayers( VECPLAYERCORES &vecCores )
{
+ CSingleLock lock(s_section);
for(unsigned int i = 0; i < s_vecCoreConfigs.size(); i++)
+ {
+ if(s_vecCoreConfigs[i]->m_eCore == EPC_NONE)
+ continue;
if (s_vecCoreConfigs[i]->m_bPlaysAudio || s_vecCoreConfigs[i]->m_bPlaysVideo)
vecCores.push_back(i+1);
+ }
}
void CPlayerCoreFactory::GetPlayers( VECPLAYERCORES &vecCores, const bool audio, const bool video )
{
+ CSingleLock lock(s_section);
CLog::Log(LOGDEBUG, "CPlayerCoreFactory::GetPlayers: for video=%d, audio=%d", video, audio);
for(unsigned int i = 0; i < s_vecCoreConfigs.size(); i++)
{
+ if(s_vecCoreConfigs[i]->m_eCore == EPC_NONE)
+ continue;
if (audio == s_vecCoreConfigs[i]->m_bPlaysAudio && video == s_vecCoreConfigs[i]->m_bPlaysVideo)
{
CLog::Log(LOGDEBUG, "CPlayerCoreFactory::GetPlayers: adding player: %s (%d)", s_vecCoreConfigs[i]->m_name.c_str(), i+1);
@@ -261,6 +275,7 @@ PLAYERCOREID CPlayerCoreFactory::SelectPlayerDialog(float posX, float posY)
bool CPlayerCoreFactory::LoadConfiguration(TiXmlElement* pConfig, bool clear)
{
+ CSingleLock lock(s_section);
if (clear)
{
for(std::vector<CPlayerCoreConfig *>::iterator it = s_vecCoreConfigs.begin(); it != s_vecCoreConfigs.end(); it++)
@@ -362,3 +377,38 @@ bool CPlayerCoreFactory::LoadConfiguration(TiXmlElement* pConfig, bool clear)
return true;
}
+
+void CPlayerCoreFactory::OnPlayerDiscovered(const CStdString& id, const CStdString& name, EPLAYERCORES core)
+{
+ CSingleLock lock(s_section);
+ std::vector<CPlayerCoreConfig *>::iterator it;
+ for(it = s_vecCoreConfigs.begin();
+ it != s_vecCoreConfigs.end();
+ it++)
+ {
+ if ((*it)->GetId() == id)
+ {
+ (*it)->m_name = name;
+ (*it)->m_eCore = core;
+ return;
+ }
+ }
+
+ CPlayerCoreConfig* player = new CPlayerCoreConfig(name, core, NULL, id);
+ player->m_bPlaysAudio = true;
+ player->m_bPlaysVideo = true;
+ s_vecCoreConfigs.push_back(player);
+}
+
+void CPlayerCoreFactory::OnPlayerRemoved(const CStdString& id)
+{
+ CSingleLock lock(s_section);
+ std::vector<CPlayerCoreConfig *>::iterator it;
+ for(it = s_vecCoreConfigs.begin();
+ it != s_vecCoreConfigs.end();
+ it++)
+ {
+ if ((*it)->GetId() == id)
+ (*it)->m_eCore = EPC_NONE;
+ }
+}
View
3 xbmc/cores/playercorefactory/PlayerCoreFactory.h
@@ -82,6 +82,9 @@ class CPlayerCoreFactory
static bool LoadConfiguration(TiXmlElement* pConfig, bool clear);
+ static void OnPlayerDiscovered(const CStdString& id, const CStdString& name, EPLAYERCORES core);
+ static void OnPlayerRemoved(const CStdString& id);
+
private:
static std::vector<CPlayerCoreConfig *> s_vecCoreConfigs;
static std::vector<CPlayerSelectionRule *> s_vecCoreSelectionRules;

0 comments on commit e29f2f1

Please sign in to comment.
Something went wrong with that request. Please try again.