From 057497c68be516af6fab07c8ec3a33e8235524b9 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Tue, 22 Jan 2013 01:47:18 +0100 Subject: [PATCH] rpi: don't try to re-register a logical address when the logical address isn't registered and we receive a VC_CEC_LOGICAL_ADDR_LOST message from the firmware. issue #109 --- .../RPi/RPiCECAdapterCommunication.cpp | 23 +++++++++++++++---- .../adapter/RPi/RPiCECAdapterCommunication.h | 1 + 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/lib/adapter/RPi/RPiCECAdapterCommunication.cpp b/src/lib/adapter/RPi/RPiCECAdapterCommunication.cpp index e1fcae6..8084b78 100644 --- a/src/lib/adapter/RPi/RPiCECAdapterCommunication.cpp +++ b/src/lib/adapter/RPi/RPiCECAdapterCommunication.cpp @@ -62,7 +62,8 @@ CRPiCECAdapterCommunication::CRPiCECAdapterCommunication(IAdapterCommunicationCa IAdapterCommunication(callback), m_logicalAddress(CECDEVICE_UNKNOWN), m_bLogicalAddressChanged(false), - m_previousLogicalAddress(CECDEVICE_FREEUSE) + m_previousLogicalAddress(CECDEVICE_FREEUSE), + m_bLogicalAddressRegistered(false) { m_queue = new CRPiCECAdapterMessageQueue(this); } @@ -199,7 +200,12 @@ void CRPiCECAdapterCommunication::OnDataReceived(uint32_t header, uint32_t p0, u m_logicalAddress = CECDEVICE_UNKNOWN; // notify libCEC that we lost our LA when the connection was initialised - if (m_bInitialised) + bool bNotify(false); + { + CLockObject lock(m_mutex); + bNotify = m_bInitialised && m_bLogicalAddressRegistered; + } + if (bNotify) m_callback->HandleLogicalAddressLost(previousAddress); } break; @@ -379,7 +385,11 @@ bool CRPiCECAdapterCommunication::UnregisterLogicalAddress(void) return true; LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - releasing previous logical address", __FUNCTION__); - m_bLogicalAddressChanged = false; + { + CLockObject lock(m_mutex); + m_bLogicalAddressRegistered = false; + m_bLogicalAddressChanged = false; + } vc_cec_release_logical_address(); @@ -411,7 +421,12 @@ bool CRPiCECAdapterCommunication::RegisterLogicalAddress(const cec_logical_addre return false; } - return m_logicalAddressCondition.Wait(m_mutex, m_bLogicalAddressChanged); + if (m_logicalAddressCondition.Wait(m_mutex, m_bLogicalAddressChanged)) + { + m_bLogicalAddressRegistered = true; + return true; + } + return false; } cec_logical_addresses CRPiCECAdapterCommunication::GetLogicalAddresses(void) diff --git a/src/lib/adapter/RPi/RPiCECAdapterCommunication.h b/src/lib/adapter/RPi/RPiCECAdapterCommunication.h index 92b7157..9a0a9fd 100644 --- a/src/lib/adapter/RPi/RPiCECAdapterCommunication.h +++ b/src/lib/adapter/RPi/RPiCECAdapterCommunication.h @@ -110,6 +110,7 @@ namespace CEC VCHI_INSTANCE_T m_vchi_instance; VCHI_CONNECTION_T * m_vchi_connection; cec_logical_address m_previousLogicalAddress; + bool m_bLogicalAddressRegistered; }; }; -- 2.34.1