sys: add methods for dynamic player addition/removal to PlayerCoreFactory
authorJoakim Plate <elupus@ecce.se>
Sun, 28 Oct 2012 19:20:25 +0000 (20:20 +0100)
committerJoakim Plate <elupus@ecce.se>
Sun, 20 Jan 2013 17:25:32 +0000 (18:25 +0100)
xbmc/cores/playercorefactory/PlayerCoreConfig.h
xbmc/cores/playercorefactory/PlayerCoreFactory.cpp
xbmc/cores/playercorefactory/PlayerCoreFactory.h

index a12cc90..3a50b69 100644 (file)
@@ -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 @@ public:
     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 @@ public:
 
 private:
   CStdString m_name;
+  CStdString m_id;
   bool m_bPlaysAudio;
   bool m_bPlaysVideo;
   EPLAYERCORES m_eCore;
index 5f0eaa2..707e86a 100644 (file)
@@ -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,11 +105,13 @@ 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;
@@ -113,17 +119,25 @@ CPlayerCoreConfig* CPlayerCoreFactory::GetPlayerConfig(const CStdString& strCore
 
 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;
+  }
+}
index 07fecb0..82eea4a 100644 (file)
@@ -82,6 +82,9 @@ public:
 
   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;