From 0680dab3d36a09be739b1852ac622a3aac0229bb Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Thu, 26 Apr 2012 11:29:17 +0200 Subject: [PATCH] cec: fixed - don't request the PA of devices when handling an incoming CEC command, or it'll block things while waiting for a response. if that response never comes, or comes late, then other incoming commands will be timed out before they are handled --- src/lib/CECProcessor.cpp | 18 ++++++------ src/lib/CECProcessor.h | 2 +- src/lib/devices/CECBusDevice.cpp | 30 +++++++++++--------- src/lib/devices/CECBusDevice.h | 2 +- src/lib/implementations/SLCommandHandler.cpp | 2 +- src/lib/implementations/VLCommandHandler.cpp | 2 +- 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 07e7d8f..9c04b42 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -409,7 +409,7 @@ bool CCECProcessor::ChangeDeviceType(cec_device_type from, cec_device_type to) newDevice->SetOSDName(previousDevice->GetOSDName(false)); previousDevice->SetOSDName(ToString(previousDevice->GetLogicalAddress())); - newDevice->SetPhysicalAddress(previousDevice->GetPhysicalAddress(false)); + newDevice->SetPhysicalAddress(previousDevice->GetPhysicalAddress()); previousDevice->SetPhysicalAddress(0xFFFF); newDevice->SetPowerStatus(previousDevice->GetPowerStatus(false)); @@ -525,7 +525,7 @@ bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RE } m_busDevices[addr]->SetActiveSource(); - if (m_busDevices[addr]->GetPhysicalAddress(false) != 0xFFFF) + if (m_busDevices[addr]->GetPhysicalAddress() != 0xFFFF) bReturn = m_busDevices[addr]->ActivateSource(); return bReturn; @@ -536,7 +536,7 @@ bool CCECProcessor::SetActiveSource(uint16_t iStreamPath) bool bReturn(false); // suppress polls when searching for a device - CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath, false, true); + CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath); if (device) { device->SetActiveSource(); @@ -649,7 +649,7 @@ bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress) { for (unsigned int iPtr = 0; iPtr < 15; iPtr++) { - if (m_busDevices[iPtr]->GetPhysicalAddress(false) == iPhysicalAddress) + if (m_busDevices[iPtr]->GetPhysicalAddress() == iPhysicalAddress) return true; } return false; @@ -810,15 +810,15 @@ uint8_t CCECProcessor::MuteAudio(bool bSendRelease /* = true */) return status; } -CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bRefresh /* = false */, bool bSuppressPoll /* = false */) const +CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bSuppressUpdate /* = true */) { - if (m_busDevices[m_configuration.logicalAddresses.primary]->GetPhysicalAddress(false) == iPhysicalAddress) + if (m_busDevices[m_configuration.logicalAddresses.primary]->GetPhysicalAddress() == iPhysicalAddress) return m_busDevices[m_configuration.logicalAddresses.primary]; CCECBusDevice *device = NULL; for (unsigned int iPtr = 0; iPtr < 16; iPtr++) { - if (m_busDevices[iPtr]->GetPhysicalAddress(bRefresh, bSuppressPoll) == iPhysicalAddress) + if (m_busDevices[iPtr]->GetPhysicalAddress(bSuppressUpdate) == iPhysicalAddress) { device = m_busDevices[iPtr]; break; @@ -896,7 +896,7 @@ uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress) uint16_t CCECProcessor::GetDevicePhysicalAddress(cec_logical_address iAddress) { if (m_busDevices[iAddress]) - return m_busDevices[iAddress]->GetPhysicalAddress(false); + return m_busDevices[iAddress]->GetPhysicalAddress(); return false; } @@ -1023,7 +1023,7 @@ bool CCECProcessor::IsPresentDeviceType(cec_device_type type) uint16_t CCECProcessor::GetPhysicalAddress(void) const { if (!m_configuration.logicalAddresses.IsEmpty() && m_busDevices[m_configuration.logicalAddresses.primary]) - return m_busDevices[m_configuration.logicalAddresses.primary]->GetPhysicalAddress(false); + return m_busDevices[m_configuration.logicalAddresses.primary]->GetPhysicalAddress(); return false; } diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index d557104..acefd8b 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -109,7 +109,7 @@ namespace CEC bool OnCommandReceived(const cec_command &command); bool IsMonitoring(void) const { return m_bMonitor; } - CCECBusDevice * GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bRefresh = false, bool bSuppressPoll = false) const; + CCECBusDevice * GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bSuppressUpdate = true); CCECBusDevice * GetDeviceByType(cec_device_type type) const; CCECBusDevice * GetPrimaryDevice(void) const; cec_version GetDeviceCecVersion(cec_logical_address iAddress); diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index cfdc520..51ddfec 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -278,21 +278,23 @@ bool CCECBusDevice::RequestOSDName(bool bWaitForResponse /* = true */) return bReturn; } -uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate /* = false */, bool bSuppressPoll /* = false */) +uint16_t CCECBusDevice::GetPhysicalAddress(bool bSuppressUpdate /* = true */) { - bool bIsPresent(GetStatus(false, bSuppressPoll) == CEC_DEVICE_STATUS_PRESENT); - bool bRequestUpdate(false); + if (!bSuppressUpdate) { - CLockObject lock(m_mutex); - bRequestUpdate = bIsPresent && - (m_iPhysicalAddress == 0xFFFF || bUpdate); - } + bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT); + bool bRequestUpdate(false); + { + CLockObject lock(m_mutex); + bRequestUpdate = bIsPresent && m_iPhysicalAddress == 0xFFFF; + } - if (bRequestUpdate) - { - CheckVendorIdRequested(); - if (!RequestPhysicalAddress()) - CLibCEC::AddLog(CEC_LOG_ERROR, "failed to request the physical address"); + if (bRequestUpdate) + { + CheckVendorIdRequested(); + if (!RequestPhysicalAddress()) + CLibCEC::AddLog(CEC_LOG_ERROR, "failed to request the physical address"); + } } CLockObject lock(m_mutex); @@ -644,7 +646,7 @@ void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* m_iStreamPath = iNewAddress; // suppress polls when searching for a device - CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iNewAddress, false, true); + CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iNewAddress); if (device) { // if a device is found with the new physical address, mark it as active, which will automatically mark all other devices as inactive @@ -653,7 +655,7 @@ void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* else { // try to find the device with the old address, and mark it as inactive when found - device = m_processor->GetDeviceByPhysicalAddress(iOldAddress, false, true); + device = m_processor->GetDeviceByPhysicalAddress(iOldAddress); if (device) device->SetInactiveSource(); } diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index 377bec3..803f6f6 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -63,7 +63,7 @@ namespace CEC virtual cec_logical_address GetMyLogicalAddress(void) const; virtual uint16_t GetMyPhysicalAddress(void) const; virtual CStdString GetOSDName(bool bUpdate = false); - virtual uint16_t GetPhysicalAddress(bool bUpdate = false, bool bSuppressPoll = false); + virtual uint16_t GetPhysicalAddress(bool bSuppressUpdate = true); virtual cec_power_status GetPowerStatus(bool bUpdate = false); virtual CCECProcessor * GetProcessor(void) const { return m_processor; } virtual cec_device_type GetType(void) const { return m_type; } diff --git a/src/lib/implementations/SLCommandHandler.cpp b/src/lib/implementations/SLCommandHandler.cpp index 5b8a729..f32209b 100644 --- a/src/lib/implementations/SLCommandHandler.cpp +++ b/src/lib/implementations/SLCommandHandler.cpp @@ -127,7 +127,7 @@ bool CSLCommandHandler::HandleActiveSource(const cec_command &command) { uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); CCECBusDevice *primary = m_processor->GetPrimaryDevice(); - bool bSendPowerOffState(iAddress != primary->GetPhysicalAddress(false) && primary->IsActiveSource()); + bool bSendPowerOffState(iAddress != primary->GetPhysicalAddress() && primary->IsActiveSource()); m_processor->SetActiveSource(iAddress); if (bSendPowerOffState) diff --git a/src/lib/implementations/VLCommandHandler.cpp b/src/lib/implementations/VLCommandHandler.cpp index 5914697..e8cf7c8 100644 --- a/src/lib/implementations/VLCommandHandler.cpp +++ b/src/lib/implementations/VLCommandHandler.cpp @@ -133,7 +133,7 @@ bool CVLCommandHandler::TransmitPendingActiveSourceCommands(void) if (bTransmitCommand) { CLibCEC::AddLog(CEC_LOG_DEBUG, "transmitting delayed activate source command"); - return CCECCommandHandler::TransmitActiveSource(m_busDevice->GetLogicalAddress(), m_busDevice->GetPhysicalAddress(false, true)); + return CCECCommandHandler::TransmitActiveSource(m_busDevice->GetLogicalAddress(), m_busDevice->GetPhysicalAddress()); } return true; } -- 2.34.1