From 97fc4ffb29ee23862d42f0875ae03ee8fbd7da44 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Wed, 28 Dec 2011 02:32:34 +0100 Subject: [PATCH] cec: don't hold a lock while waiting for a response. fixes failed libCEC inits and slow responses --- src/lib/CECProcessor.cpp | 17 ++++---- src/lib/devices/CECBusDevice.cpp | 75 +++++++++++++++++++++++--------- 2 files changed, 63 insertions(+), 29 deletions(-) diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 7afafaf..31f4399 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -171,6 +171,7 @@ bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, /* get the vendor id from the TV, so we are using the correct handler */ m_busDevices[CECDEVICE_TV]->GetVendorId(); + ReplaceHandlers(); bReturn = SetHDMIPort(m_iBaseDevice, m_iHDMIPort, true); } @@ -271,7 +272,7 @@ bool CCECProcessor::FindLogicalAddresses(void) void CCECProcessor::ReplaceHandlers(void) { for (uint8_t iPtr = 0; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++) - m_busDevices[iPtr]->ReplaceHandler(true); + m_busDevices[iPtr]->ReplaceHandler(false); } void *CCECProcessor::Process(void) @@ -289,8 +290,6 @@ void *CCECProcessor::Process(void) while (!IsStopped()) { - ReplaceHandlers(); - command.Clear(); msg.clear(); @@ -424,12 +423,14 @@ bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true * bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, bool bForce /* = false */) { bool bReturn(false); - CLockObject lock(&m_mutex); + { + CLockObject lock(&m_mutex); - m_iBaseDevice = iBaseDevice; - m_iHDMIPort = iPort; - if (!m_bStarted && !bForce) - return true; + m_iBaseDevice = iBaseDevice; + m_iHDMIPort = iPort; + if (!m_bStarted && !bForce) + return true; + } CStdString strLog; strLog.Format("setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice); diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 824e561..328e2b6 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -156,11 +156,17 @@ bool CCECBusDevice::Standby(void) //@{ cec_version CCECBusDevice::GetCecVersion(bool bUpdate /* = false */) { - CLockObject lock(&m_mutex); - if (GetStatus() == CEC_DEVICE_STATUS_PRESENT && - (bUpdate || m_cecVersion == CEC_VERSION_UNKNOWN)) + bool bRequestUpdate(false); + { + CLockObject lock(&m_mutex); + bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT && + (bUpdate || m_cecVersion == CEC_VERSION_UNKNOWN)); + } + + if (bRequestUpdate) RequestCecVersion(); + CLockObject lock(&m_mutex); return m_cecVersion; } @@ -186,11 +192,17 @@ const char* CCECBusDevice::GetLogicalAddressName(void) const cec_menu_language &CCECBusDevice::GetMenuLanguage(bool bUpdate /* = false */) { - CLockObject lock(&m_mutex); - if (GetStatus() == CEC_DEVICE_STATUS_PRESENT && - (bUpdate || !strcmp(m_menuLanguage.language, "???"))) + bool bRequestUpdate(false); + { + CLockObject lock(&m_mutex); + bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT && + (bUpdate || !strcmp(m_menuLanguage.language, "???"))); + } + + if (bRequestUpdate) RequestMenuLanguage(); + CLockObject lock(&m_mutex); return m_menuLanguage; } @@ -221,12 +233,18 @@ uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const CStdString CCECBusDevice::GetOSDName(bool bUpdate /* = false */) { - CLockObject lock(&m_mutex); - if (GetStatus() == CEC_DEVICE_STATUS_PRESENT && - (bUpdate || m_strDeviceName.Equals(ToString(m_iLogicalAddress))) && - m_type != CEC_DEVICE_TYPE_TV) + bool bRequestUpdate(false); + { + CLockObject lock(&m_mutex); + bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT && + (bUpdate || m_strDeviceName.Equals(ToString(m_iLogicalAddress))) && + m_type != CEC_DEVICE_TYPE_TV); + } + + if (bRequestUpdate) RequestOSDName(); + CLockObject lock(&m_mutex); return m_strDeviceName; } @@ -247,14 +265,17 @@ bool CCECBusDevice::RequestOSDName(void) uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate /* = false */) { - CLockObject lock(&m_mutex); - if (GetStatus() == CEC_DEVICE_STATUS_PRESENT && - (m_iPhysicalAddress == 0xFFFF || bUpdate)) + bool bRequestUpdate(false); { - if (!RequestPhysicalAddress()) - AddLog(CEC_LOG_ERROR, "failed to request the physical address"); + CLockObject lock(&m_mutex); + bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT && + (m_iPhysicalAddress == 0xFFFF || bUpdate)); } + if (bRequestUpdate && !RequestPhysicalAddress()) + AddLog(CEC_LOG_ERROR, "failed to request the physical address (1)"); + + CLockObject lock(&m_mutex); return m_iPhysicalAddress; } @@ -274,11 +295,17 @@ bool CCECBusDevice::RequestPhysicalAddress(void) cec_power_status CCECBusDevice::GetPowerStatus(bool bUpdate /* = false */) { - CLockObject lock(&m_mutex); - if (GetStatus() == CEC_DEVICE_STATUS_PRESENT && - (bUpdate || m_powerStatus == CEC_POWER_STATUS_UNKNOWN)) + bool bRequestUpdate(false); + { + CLockObject lock(&m_mutex); + bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT && + (bUpdate || m_powerStatus == CEC_POWER_STATUS_UNKNOWN)); + } + + if (bRequestUpdate) RequestPowerStatus(); + CLockObject lock(&m_mutex); return m_powerStatus; } @@ -299,11 +326,17 @@ bool CCECBusDevice::RequestPowerStatus(void) cec_vendor_id CCECBusDevice::GetVendorId(bool bUpdate /* = false */) { - CLockObject lock(&m_mutex); - if (GetStatus() == CEC_DEVICE_STATUS_PRESENT && - (bUpdate || m_vendor == CEC_VENDOR_UNKNOWN)) + bool bRequestUpdate(false); + { + CLockObject lock(&m_mutex); + bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT && + (bUpdate || m_vendor == CEC_VENDOR_UNKNOWN)); + } + + if (bRequestUpdate) RequestVendorId(); + CLockObject lock(&m_mutex); return m_vendor; } -- 2.34.1