From a38292a3c2ec93a21d74da778516276e92d431c0 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Wed, 25 Jul 2012 11:45:15 +0200 Subject: [PATCH] p8: fixed - always set controlled mode to false when unregistering the last client. fixes 30 second timeout before controlled mode gets deactivated --- src/lib/CECProcessor.cpp | 15 ++++++++++++++- .../Pulse-Eight/USBCECAdapterCommands.cpp | 16 +++++++++++++++- .../adapter/Pulse-Eight/USBCECAdapterCommands.h | 1 + 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 71e5c69..76c2465 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -660,6 +660,9 @@ bool CCECProcessor::RegisterClient(CCECClient *client) if (client->IsRegistered()) UnregisterClient(client); + // ensure that controlled mode is enabled + m_communication->SetControlledMode(true); + // ensure that we know the vendor id of the TV CCECBusDevice *tv = GetTV(); if (m_communication->SupportsSourceLogicalAddress(CECDEVICE_UNREGISTERED)) @@ -784,7 +787,17 @@ bool CCECProcessor::UnregisterClient(CCECClient *client) } // set the new ackmask - return SetLogicalAddresses(GetLogicalAddresses());; + cec_logical_addresses addresses = GetLogicalAddresses(); + if (SetLogicalAddresses(addresses)) + { + // no more clients left, disable controlled mode + if (addresses.IsEmpty()) + m_communication->SetControlledMode(false); + + return true; + } + + return false; } void CCECProcessor::UnregisterClients(void) diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.cpp b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.cpp index af4d6a0..457889c 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.cpp +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.cpp @@ -53,7 +53,8 @@ CUSBCECAdapterCommands::CUSBCECAdapterCommands(CUSBCECAdapterCommunication *comm m_settingCecVersion(CEC_VERSION_UNKNOWN), m_iSettingLAMask(0), m_bNeedsWrite(false), - m_iBuildDate(CEC_FW_BUILD_UNKNOWN) + m_iBuildDate(CEC_FW_BUILD_UNKNOWN), + m_bControlledMode(false) { m_persistedConfiguration.Clear(); } @@ -575,6 +576,12 @@ bool CUSBCECAdapterCommands::SetLineTimeout(uint8_t iTimeout) bool CUSBCECAdapterCommands::SetControlledMode(bool controlled) { + { + CLockObject lock(m_mutex); + if (m_bControlledMode == controlled) + return true; + } + LIB_CEC->AddLog(CEC_LOG_DEBUG, "turning controlled mode %s", controlled ? "on" : "off"); CCECAdapterMessage params; @@ -582,5 +589,12 @@ bool CUSBCECAdapterCommands::SetControlledMode(bool controlled) CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_CONTROLLED, params); bool bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; delete message; + + if (bReturn) + { + CLockObject lock(m_mutex); + m_bControlledMode = controlled; + } + return bReturn; } diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.h b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.h index df376f3..897ed1c 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.h +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.h @@ -232,6 +232,7 @@ namespace CEC bool m_bNeedsWrite; /**< true when we sent changed settings to the adapter that have not been persisted */ libcec_configuration m_persistedConfiguration; /**< the configuration that is persisted in the eeprom */ uint32_t m_iBuildDate; /**< the build date of the firmware */ + bool m_bControlledMode; /**< current value of the controlled mode feature */ PLATFORM::CMutex m_mutex; }; } -- 2.34.1