cec: retry 'activate source' every 10 seconds if it failed
[deb_libcec.git] / src / lib / CECProcessor.cpp
index 11076ecb78d191dfabdb80341a0a124af90be085..fe40990553d2a4ea2dc278e70cda437262f2c666 100644 (file)
@@ -51,6 +51,7 @@ using namespace std;
 using namespace PLATFORM;
 
 #define CEC_PROCESSOR_SIGNAL_WAIT_TIME 1000
+#define ACTIVE_SOURCE_CHECK_TIMEOUT    10000
 
 #define ToString(x) CCECTypeUtils::ToString(x)
 
@@ -200,6 +201,19 @@ void CCECProcessor::ReplaceHandlers(void)
     it->second->ReplaceHandler(true);
 }
 
+void CCECProcessor::CheckPendingActiveSource(void)
+{
+  if (!CECInitialised())
+    return;
+
+  // check each device
+  for (CECDEVICEMAP::iterator it = m_busDevices->Begin(); it != m_busDevices->End(); it++)
+  {
+    if (it->second->GetHandler()->ActiveSourcePending())
+      it->second->ActivateSource();
+  }
+}
+
 bool CCECProcessor::OnCommandReceived(const cec_command &command)
 {
   return m_inBuffer.Push(command);
@@ -210,6 +224,7 @@ void *CCECProcessor::Process(void)
   m_libcec->AddLog(CEC_LOG_DEBUG, "processor thread started");
 
   cec_command command;
+  CTimeout activeSourceCheck(ACTIVE_SOURCE_CHECK_TIMEOUT);
 
   // as long as we're not being stopped and the connection is open
   while (!IsStopped() && m_communication->IsOpen())
@@ -225,6 +240,13 @@ void *CCECProcessor::Process(void)
 
       // check if we need to replace handlers
       ReplaceHandlers();
+
+      // check whether we need to activate a source, if it failed before
+      if (activeSourceCheck.TimeLeft() == 0)
+      {
+        CheckPendingActiveSource();
+        activeSourceCheck.Init(ACTIVE_SOURCE_CHECK_TIMEOUT);
+      }
     }
   }