fixed: mark the TV as 'in transition standby -> on' after sending 'image view on...
[deb_libcec.git] / src / lib / devices / CECBusDevice.cpp
index 3be7adf618786f2b08d68f71374b07d7d2b53c29..bfb546f8badd6303ffeb2ceae5fa9085e10755ce 100644 (file)
@@ -532,6 +532,9 @@ bool CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress)
   {
     LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress, iNewAddress);
     m_iPhysicalAddress = iNewAddress;
+
+    if (m_processor->GetDevices()->GetActiveSourceAddress() == iNewAddress)
+      MarkAsActiveSource();
   }
   return true;
 }
@@ -610,6 +613,17 @@ void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus)
   }
 }
 
+void CCECBusDevice::ImageViewOnSent(void)
+{
+  CLockObject lock(m_mutex);
+  if (m_powerStatus != CEC_POWER_STATUS_ON && m_powerStatus != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON)
+  {
+    m_iLastPowerStateUpdate = GetTimeMs();
+    LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_powerStatus), ToString(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON));
+    m_powerStatus = CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON;
+  }
+}
+
 bool CCECBusDevice::RequestPowerStatus(const cec_logical_address initiator, bool bWaitForResponse /* = true */)
 {
   bool bReturn(false);
@@ -966,7 +980,8 @@ void CCECBusDevice::MarkAsActiveSource(void)
 
   if (bWasActivated)
   {
-    m_processor->SetActiveSource(true, false);
+    if (IsHandledByLibCEC())
+      m_processor->SetActiveSource(true, false);
     CCECClient *client = GetClient();
     if (client)
       client->SourceActivated(m_iLogicalAddress);
@@ -988,7 +1003,8 @@ void CCECBusDevice::MarkAsInactiveSource(bool bClientUnregistered /* = false */)
 
   if (bWasDeactivated)
   {
-    m_processor->SetActiveSource(false, bClientUnregistered);
+    if (IsHandledByLibCEC())
+      m_processor->SetActiveSource(false, bClientUnregistered);
     CCECClient *client = GetClient();
     if (client)
       client->SourceDeactivated(m_iLogicalAddress);
@@ -1047,6 +1063,14 @@ bool CCECBusDevice::TransmitImageViewOn(void)
   MarkBusy();
   bImageViewOnSent = m_handler->TransmitImageViewOn(m_iLogicalAddress, CECDEVICE_TV);
   MarkReady();
+
+  if (bImageViewOnSent)
+  {
+    CCECBusDevice* tv = m_processor->GetDevice(CECDEVICE_TV);
+    if (tv)
+      tv->ImageViewOnSent();
+  }
+
   return bImageViewOnSent;
 }