cec: inactive source should be directly addressed at the TV
[deb_libcec.git] / src / lib / CECProcessor.cpp
index 8f2ea98f24ac4529bca5339717e4a90ad1e3b0cb..2b8874b709d6099d3ba3615e0d32647fc633b140 100644 (file)
@@ -131,7 +131,14 @@ bool CCECProcessor::Start(void)
       m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
       return false;
     }
-    return true;
+
+    lock.Leave();
+    if (SetAckMask(m_logicalAddresses.AckMask()) &&
+        SetHDMIPort(m_iHDMIPort, true))
+    {
+      ScanCECBus();
+      return true;
+    }
   }
   else
     m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
@@ -220,28 +227,19 @@ void *CCECProcessor::Process(void)
   cec_command           command;
   CCECAdapterMessage    msg;
 
+  if (m_logicalAddresses.IsEmpty() && !FindLogicalAddresses())
   {
-    if (m_logicalAddresses.IsEmpty() && !FindLogicalAddresses())
-    {
-      CLockObject lock(&m_mutex);
-      m_controller->AddLog(CEC_LOG_ERROR, "could not detect our logical addresses");
-      m_startCondition.Signal();
-      return NULL;
-    }
-
-    SetAckMask(m_logicalAddresses.AckMask());
-
-    {
-      CLockObject lock(&m_mutex);
-      m_bStarted = true;
-      lock.Leave();
-
-      SetHDMIPort(m_iHDMIPort);
-
-      lock.Lock();
-      m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
-      m_startCondition.Signal();
-    }
+    CLockObject lock(&m_mutex);
+    m_controller->AddLog(CEC_LOG_ERROR, "could not detect our logical addresses");
+    m_startCondition.Signal();
+    return NULL;
+  }
+  else
+  {
+    CLockObject lock(&m_mutex);
+    m_bStarted = true;
+    m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
+    m_startCondition.Signal();
   }
 
   while (!IsStopped())
@@ -271,7 +269,7 @@ void *CCECProcessor::Process(void)
 
     m_controller->CheckKeypressTimeout();
 
-    for (unsigned int iDevicePtr = 0; iDevicePtr < 16; iDevicePtr++)
+    for (uint8_t iDevicePtr = 0; iDevicePtr < 16; iDevicePtr++)
     {
       if (!m_logicalAddresses[iDevicePtr])
         m_busDevices[iDevicePtr]->PollVendorId();
@@ -350,7 +348,7 @@ bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true *
   return bReturn;
 }
 
-bool CCECProcessor::SetHDMIPort(uint8_t iPort)
+bool CCECProcessor::SetHDMIPort(uint8_t iPort, bool bForce /* = false */)
 {
   bool bReturn(false);
 
@@ -359,7 +357,7 @@ bool CCECProcessor::SetHDMIPort(uint8_t iPort)
   AddLog(CEC_LOG_DEBUG, strLog);
 
   m_iHDMIPort = iPort;
-  if (!m_bStarted)
+  if (!m_bStarted && !bForce)
     return true;
 
   uint16_t iPhysicalAddress(0);
@@ -385,9 +383,24 @@ bool CCECProcessor::SetHDMIPort(uint8_t iPort)
   return bReturn;
 }
 
-bool CCECProcessor::CheckPhysicalAddress(uint16_t iPhysicalAddress)
+void CCECProcessor::ScanCECBus(void)
 {
+  CCECBusDevice *device(NULL);
   for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+  {
+    device = m_busDevices[iPtr];
+    if (device && device->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
+    {
+      device->GetPhysicalAddress();
+      device->GetCecVersion();
+      device->GetVendorId();
+    }
+  }
+}
+
+bool CCECProcessor::CheckPhysicalAddress(uint16_t iPhysicalAddress)
+{
+  for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
   {
     if (m_busDevices[iPtr]->GetPhysicalAddress(false) == iPhysicalAddress)
       return true;
@@ -409,13 +422,13 @@ bool CCECProcessor::SetStreamPath(uint16_t iStreamPath)
   return bReturn;
 }
 
-bool CCECProcessor::SetInactiveView(void)
+bool CCECProcessor::TransmitInactiveSource(void)
 {
   if (!IsRunning())
     return false;
 
   if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary])
-    return m_busDevices[m_logicalAddresses.primary]->TransmitInactiveView();
+    return m_busDevices[m_logicalAddresses.primary]->TransmitInactiveSource();
   return false;
 }
 
@@ -488,33 +501,37 @@ bool CCECProcessor::SwitchMonitoring(bool bEnable)
 bool CCECProcessor::PollDevice(cec_logical_address iAddress)
 {
   if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress])
-    return m_busDevices[m_logicalAddresses.primary]->TransmitPoll(iAddress);
+  {
+    return m_logicalAddresses.primary == CECDEVICE_UNKNOWN ?
+        m_busDevices[iAddress]->TransmitPoll(iAddress) :
+        m_busDevices[m_logicalAddresses.primary]->TransmitPoll(iAddress);
+  }
   return false;
 }
 
-uint8_t CCECProcessor::VolumeUp(void)
+uint8_t CCECProcessor::VolumeUp(bool bWait /* = true */)
 {
   uint8_t status = 0;
   if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM))
-    status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp();
+    status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp(bWait);
 
   return status;
 }
 
-uint8_t CCECProcessor::VolumeDown(void)
+uint8_t CCECProcessor::VolumeDown(bool bWait /* = true */)
 {
   uint8_t status = 0;
   if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM))
-    status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown();
+    status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown(bWait);
 
   return status;
 }
 
-uint8_t CCECProcessor::MuteAudio(void)
+uint8_t CCECProcessor::MuteAudio(bool bWait /* = true */)
 {
   uint8_t status = 0;
   if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM))
-    status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio();
+    status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio(bWait);
 
   return status;
 }
@@ -558,6 +575,17 @@ cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress)
   return m_busDevices[iAddress]->GetCecVersion();
 }
 
+cec_osd_name CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress)
+{
+  CStdString strOSDName = m_busDevices[iAddress]->GetOSDName();
+  cec_osd_name retVal;
+
+  snprintf(retVal.name, sizeof(retVal.name), "%s", strOSDName.c_str());
+  retVal.device = iAddress;
+
+  return retVal;
+}
+
 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language)
 {
   if (m_busDevices[iAddress])
@@ -735,6 +763,7 @@ void CCECProcessor::ParseCommand(cec_command &command)
 cec_logical_addresses CCECProcessor::GetActiveDevices(void)
 {
   cec_logical_addresses addresses;
+  addresses.Clear();
   for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
   {
     if (m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
@@ -813,3 +842,13 @@ bool CCECProcessor::SetAckMask(uint16_t iMask)
 
   return bReturn;
 }
+
+bool CCECProcessor::SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = false */)
+{
+  return m_busDevices[iDestination]->SendKeypress(key, bWait);
+}
+
+bool CCECProcessor::SendKeyRelease(cec_logical_address iDestination, bool bWait /* = false */)
+{
+  return m_busDevices[iDestination]->SendKeyRelease(bWait);
+}