cec: don't forward the standby opcode more than once every 10 seconds
authorLars Op den Kamp <lars@opdenkamp.eu>
Mon, 25 Jun 2012 10:05:52 +0000 (12:05 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Mon, 25 Jun 2012 14:58:30 +0000 (16:58 +0200)
include/cectypes.h
src/lib/CECClient.cpp
src/lib/CECClient.h

index c5da11f1c8883c4adb2c9a7cdbaa155ac550ea01..0e9f7e52707465476ea9fd7fe0a2ce0f436f3658 100644 (file)
@@ -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
index 35dd415139169200414e7ffc19c0d79c56d4093e..d91ae2aa4c4ca204c636cf7418cbf545c87a1d10 100644 (file)
@@ -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);
index fccb083e4dd49a3d3b85bc2706b17c4fbb6b209e..26944a7068281229d444b36e77dedbf6c2d1a673 100644 (file)
@@ -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<cec_log_message> m_logBuffer;      /**< @deprecated will be removed in v2.0. buffer for log messages */
     PLATFORM::SyncedBuffer<cec_keypress>    m_keyBuffer;      /**< @deprecated will be removed in v2.0. buffer for keypresses */
     PLATFORM::SyncedBuffer<cec_command>     m_commandBuffer;  /**< @deprecated will be removed in v2.0. buffer for commands */