From 55c18d43f7360c8bb0ee91ea8509742c94f7a59e Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Mon, 25 Jun 2012 12:05:52 +0200 Subject: [PATCH] cec: don't forward the standby opcode more than once every 10 seconds --- include/cectypes.h | 1 + src/lib/CECClient.cpp | 14 +++++++++++++- src/lib/CECClient.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/cectypes.h b/include/cectypes.h index c5da11f..0e9f7e5 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -111,6 +111,7 @@ namespace CEC { #define CEC_CLEAR_INPUT_DEFAULT_WAIT 1000 #define CEC_ACTIVE_SOURCE_SWITCH_RETRY_TIME_MS 5000 +#define CEC_FORWARD_STANDBY_MIN_INTERVAL 10000 #define CEC_MIN_LIB_VERSION 1 #define CEC_LIB_VERSION_MAJOR 1 diff --git a/src/lib/CECClient.cpp b/src/lib/CECClient.cpp index 35dd415..d91ae2a 100644 --- a/src/lib/CECClient.cpp +++ b/src/lib/CECClient.cpp @@ -50,7 +50,8 @@ CCECClient::CCECClient(CCECProcessor *processor, const libcec_configuration &con m_bInitialised(false), m_bRegistered(false), m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN), - m_buttontime(0) + m_buttontime(0), + m_iPreventForwardingPowerOffCommand(0) { // set the initial configuration SetConfiguration(configuration); @@ -882,6 +883,17 @@ bool CCECClient::SetConfiguration(const libcec_configuration &configuration) void CCECClient::AddCommand(const cec_command &command) { + // don't forward the standby opcode more than once every 10 seconds + if (command.opcode == CEC_OPCODE_STANDBY) + { + CLockObject lock(m_mutex); + if (m_iPreventForwardingPowerOffCommand != 0 && + m_iPreventForwardingPowerOffCommand > GetTimeMs()) + return; + else + m_iPreventForwardingPowerOffCommand = GetTimeMs() + CEC_FORWARD_STANDBY_MIN_INTERVAL; + } + if (command.destination == CECDEVICE_BROADCAST || GetLogicalAddresses().IsSet(command.destination)) { CLockObject lock(m_mutex); diff --git a/src/lib/CECClient.h b/src/lib/CECClient.h index fccb083..26944a7 100644 --- a/src/lib/CECClient.h +++ b/src/lib/CECClient.h @@ -307,6 +307,7 @@ namespace CEC PLATFORM::CMutex m_logMutex; /**< mutex that is held when sending a log message back to the client */ cec_user_control_code m_iCurrentButton; /**< the control code of the button that's currently held down (if any) */ int64_t m_buttontime; /**< the timestamp when the button was pressed (in seconds since epoch), or 0 if none was pressed. */ + int64_t m_iPreventForwardingPowerOffCommand; /**< prevent forwarding standby commands until this time */ PLATFORM::SyncedBuffer m_logBuffer; /**< @deprecated will be removed in v2.0. buffer for log messages */ PLATFORM::SyncedBuffer m_keyBuffer; /**< @deprecated will be removed in v2.0. buffer for keypresses */ PLATFORM::SyncedBuffer m_commandBuffer; /**< @deprecated will be removed in v2.0. buffer for commands */ -- 2.34.1