cec: use the correct source when transmitting an abort message as a reposonse to...
[deb_libcec.git] / src / lib / implementations / CECCommandHandler.cpp
index ad4349efb608141e6df52aac04216daac46e3fff..f35dd329373a9adda70ae80b7194ef834c1f957f 100644 (file)
@@ -246,7 +246,7 @@ bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command)
 bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command)
 {
   if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination))
-    m_processor->TransmitAbort(m_busDevice->GetLogicalAddress(), command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED);
+    m_processor->TransmitAbort(command.destination, command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED);
 
   return true;
 }
@@ -738,21 +738,24 @@ void CCECCommandHandler::SetPhysicalAddress(cec_logical_address iAddress, uint16
 {
   if (!m_processor->IsHandledByLibCEC(iAddress))
   {
-    CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iNewAddress);
-    bool bOurAddress(device && device->GetLogicalAddress() != m_busDevice->GetLogicalAddress() &&
-        device->IsHandledByLibCEC());
-
-    GetDevice(iAddress)->SetPhysicalAddress(iNewAddress);
+    CCECBusDevice *otherDevice = m_processor->GetDeviceByPhysicalAddress(iNewAddress);
+    CCECClient *client = otherDevice ? otherDevice->GetClient() : NULL;
 
-    if (bOurAddress)
+    CCECBusDevice *device = m_processor->GetDevice(iAddress);
+    if (device)
+      device->SetPhysicalAddress(iNewAddress);
+    else
     {
-      /* another device reported the same physical address as ours
-       * since we don't have physical address detection yet, we'll just use the
-       * given address, increased by 0x100 for now */
-      CCECClient *client = device->GetClient();
-      if (client)
-        client->SetPhysicalAddress(iNewAddress + 0x100);
+      LIB_CEC->AddLog(CEC_LOG_DEBUG, "device with logical address %X not found", iAddress);
     }
+
+    /* another device reported the same physical address as ours */
+    if (client)
+      client->ResetPhysicalAddress();
+  }
+  else
+  {
+    LIB_CEC->AddLog(CEC_LOG_DEBUG, "ignore physical address report for device %s (%X) because it's marked as handled by libCEC", ToString(iAddress), iAddress);
   }
 }