From 5d7960cb1894c3038fdce35057363e082b2a62d8 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Tue, 28 Oct 2014 13:33:33 +0100 Subject: [PATCH] backwards compatibility for older client versions and the new double tap timeout. fixes very long timeouts when upgrading libCEC without upgrading XBMC to Helix --- include/cectypes.h | 9 +++++---- src/lib/CECClient.cpp | 12 ++++++++++-- src/lib/CECClient.h | 2 ++ src/lib/implementations/VLCommandHandler.cpp | 4 ++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/include/cectypes.h b/include/cectypes.h index 557ce18..0a90d0e 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -83,7 +83,8 @@ namespace CEC { * don't send the same key twice within this timeout in units of 50 milliseconds * 4 = 200ms */ -#define CEC_DOUBLE_TAP_TIMEOUT_MS 4 +#define CEC_DOUBLE_TAP_TIMEOUT_50_MS 4 +#define CEC_DOUBLE_TAP_TIMEOUT_MS_OLD 200 /*! * don't query the power state for the same device within this timeout in milliseconds @@ -1527,7 +1528,7 @@ struct libcec_configuration uint8_t bMonitorOnly; /*!< won't allocate a CCECClient when starting the connection when set (same as monitor mode). added in 1.6.3 */ cec_version cecVersion; /*!< CEC spec version to use by libCEC. defaults to v1.4. added in 1.8.0 */ cec_adapter_type adapterType; /*!< type of the CEC adapter that we're connected to. added in 1.8.2 */ - uint8_t iDoubleTapTimeoutMs; /*!< prevent double taps withing this timeout, in units of 50ms. defaults to 200ms (value: 4). added in 2.0.0, + uint8_t iDoubleTapTimeout50Ms; /*!< prevent double taps withing this timeout, in units of 50ms. defaults to 200ms (value: 4). added in 2.0.0, XXX changed meaning in 2.2.0 to not break binary compatibility. next major (3.0) release will fix it in a nicer way */ cec_user_control_code comboKey; /*!< key code that initiates combo keys. defaults to CEC_USER_CONTROL_CODE_F1_BLUE. CEC_USER_CONTROL_CODE_UNKNOWN to disable. added in 2.0.5 */ uint32_t iComboKeyTimeoutMs; /*!< timeout until the combo key is sent as normal keypress */ @@ -1564,7 +1565,7 @@ struct libcec_configuration bMonitorOnly == other.bMonitorOnly && cecVersion == other.cecVersion && adapterType == other.adapterType && - iDoubleTapTimeoutMs == other.iDoubleTapTimeoutMs && + iDoubleTapTimeout50Ms == other.iDoubleTapTimeout50Ms && (other.clientVersion <= CEC_CLIENT_VERSION_2_0_4 || comboKey == other.comboKey) && (other.clientVersion <= CEC_CLIENT_VERSION_2_0_4 || iComboKeyTimeoutMs == other.iComboKeyTimeoutMs) && (other.clientVersion < CEC_CLIENT_VERSION_2_1_0 || bPowerOnScreensaver == other.bPowerOnScreensaver)); @@ -1602,7 +1603,7 @@ struct libcec_configuration bMonitorOnly = 0; cecVersion = (cec_version)CEC_DEFAULT_SETTING_CEC_VERSION; adapterType = ADAPTERTYPE_UNKNOWN; - iDoubleTapTimeoutMs = CEC_DOUBLE_TAP_TIMEOUT_MS; + iDoubleTapTimeout50Ms = CEC_DOUBLE_TAP_TIMEOUT_50_MS; comboKey = CEC_USER_CONTROL_CODE_STOP; iComboKeyTimeoutMs = CEC_DEFAULT_COMBO_TIMEOUT_MS; diff --git a/src/lib/CECClient.cpp b/src/lib/CECClient.cpp index 12ca4ce..0bc9705 100644 --- a/src/lib/CECClient.cpp +++ b/src/lib/CECClient.cpp @@ -876,7 +876,7 @@ bool CCECClient::SetConfiguration(const libcec_configuration &configuration) m_configuration.bMonitorOnly = configuration.bMonitorOnly; m_configuration.cecVersion = configuration.cecVersion; m_configuration.adapterType = configuration.adapterType; - m_configuration.iDoubleTapTimeoutMs = configuration.iDoubleTapTimeoutMs; + m_configuration.iDoubleTapTimeout50Ms = configuration.iDoubleTapTimeout50Ms; m_configuration.deviceTypes.Add(configuration.deviceTypes[0]); if (m_configuration.clientVersion >= CEC_CLIENT_VERSION_2_0_5) @@ -1457,6 +1457,14 @@ void CCECClient::CallbackAddCommand(const cec_command &command) m_configuration.callbacks->CBCecCommand(m_configuration.callbackParam, command); } +uint32_t CCECClient::DoubleTapTimeoutMS(void) +{ + CLockObject lock(m_cbMutex); + return m_configuration.clientVersion >= CEC_CLIENT_VERSION_2_2_0 ? + m_configuration.iDoubleTapTimeout50Ms * DOUBLE_TAP_TIMEOUT_UNIT_SIZE : + m_configuration.iDoubleTapTimeout50Ms; +} + void CCECClient::CallbackAddKey(const cec_keypress &key) { CLockObject lock(m_cbMutex); @@ -1466,7 +1474,7 @@ void CCECClient::CallbackAddKey(const cec_keypress &key) int64_t now = GetTimeMs(); if (m_lastKeypress.keycode != key.keycode || key.duration > 0 || - now - m_iLastKeypressTime >= m_configuration.iDoubleTapTimeoutMs * DOUBLE_TAP_TIMEOUT_UNIT_SIZE) + now - m_iLastKeypressTime >= DoubleTapTimeoutMS()) { // no double tap if (key.duration == 0) diff --git a/src/lib/CECClient.h b/src/lib/CECClient.h index ba76736..3ef0453 100644 --- a/src/lib/CECClient.h +++ b/src/lib/CECClient.h @@ -302,6 +302,8 @@ namespace CEC virtual int CallbackMenuStateChanged(const cec_menu_state newState); virtual void CallbackSourceActivated(bool bActivated, const cec_logical_address logicalAddress); + uint32_t DoubleTapTimeoutMS(void); + CCECProcessor * m_processor; /**< a pointer to the processor */ libcec_configuration m_configuration; /**< the configuration of this client */ bool m_bInitialised; /**< true when initialised, false otherwise */ diff --git a/src/lib/implementations/VLCommandHandler.cpp b/src/lib/implementations/VLCommandHandler.cpp index 0e74a06..12a36e6 100644 --- a/src/lib/implementations/VLCommandHandler.cpp +++ b/src/lib/implementations/VLCommandHandler.cpp @@ -78,9 +78,9 @@ bool CVLCommandHandler::InitHandler(void) { libcec_configuration config; m_processor->GetPrimaryClient()->GetCurrentConfiguration(config); - if (config.iDoubleTapTimeoutMs == 0) + if (config.iDoubleTapTimeout50Ms == 0) { - config.iDoubleTapTimeoutMs = CEC_DOUBLE_TAP_TIMEOUT_MS; + config.iDoubleTapTimeout50Ms = config.clientVersion >= CEC_CLIENT_VERSION_2_2_0 ? CEC_DOUBLE_TAP_TIMEOUT_50_MS : CEC_DOUBLE_TAP_TIMEOUT_MS_OLD; m_processor->GetPrimaryClient()->SetConfiguration(config); } -- 2.34.1