Merge branch 'master' into release
[deb_libcec.git] / src / lib / CECProcessor.cpp
index 44b2acb44dbcdae590f3646f11b618e7fedf8978..4f2caa70d38ba7526f1bb31bae26bc58ac6cf319 100644 (file)
@@ -85,17 +85,23 @@ void *CCECProcessor::Process(void)
   while (!IsStopped())
   {
     bool bParseFrame(false);
+    cec_frame msg;
+    msg.clear();
+
     {
       CLockObject lock(&m_mutex);
-      cec_frame msg;
-      msg.clear();
-
-      if (m_communication->IsOpen() && m_communication->Read(msg, CEC_BUTTON_TIMEOUT))
+      if (m_communication->IsOpen() && m_communication->Read(msg, 50))
         bParseFrame = ParseMessage(msg) && !IsStopped();
+
+      if (bParseFrame)
+      {
+        msg.clear();
+        msg = m_currentframe;
+      }
     }
 
     if (bParseFrame)
-      ParseCurrentFrame();
+      ParseCurrentFrame(msg);
 
     m_controller->CheckKeypressTimeout();
 
@@ -489,26 +495,26 @@ bool CCECProcessor::ParseMessage(cec_frame &msg)
   return bReturn;
 }
 
-void CCECProcessor::ParseCurrentFrame(void)
+void CCECProcessor::ParseCurrentFrame(cec_frame &frame)
 {
-  uint8_t initiator = m_currentframe.data[0] >> 4;
-  uint8_t destination = m_currentframe.data[0] & 0xF;
+  uint8_t initiator = frame.data[0] >> 4;
+  uint8_t destination = frame.data[0] & 0xF;
 
   CStdString dataStr;
   dataStr.Format("received frame: initiator: %u destination: %u", initiator, destination);
 
-  if (m_currentframe.size > 1)
+  if (frame.size > 1)
   {
     dataStr += " data:";
-    for (unsigned int i = 1; i < m_currentframe.size; i++)
-      dataStr.AppendFormat(" %02x", m_currentframe.data[i]);
+    for (unsigned int i = 1; i < frame.size; i++)
+      dataStr.AppendFormat(" %02x", frame.data[i]);
   }
   m_controller->AddLog(CEC_LOG_DEBUG, dataStr.c_str());
 
-  if (m_currentframe.size <= 1)
+  if (frame.size <= 1)
     return;
 
-  cec_opcode opCode = (cec_opcode) m_currentframe.data[1];
+  cec_opcode opCode = (cec_opcode) frame.data[1];
   if (destination == (uint16_t) m_iLogicalAddress)
   {
     switch(opCode)
@@ -533,19 +539,19 @@ void CCECProcessor::ParseCurrentFrame(void)
       ReportCECVersion((cec_logical_address)initiator);
       break;
     case CEC_OPCODE_USER_CONTROL_PRESSED:
-      if (m_currentframe.size > 2)
+      if (frame.size > 2)
       {
         m_controller->AddKey();
 
-        if (m_currentframe.data[2] <= CEC_USER_CONTROL_CODE_MAX)
-          m_controller->SetCurrentButton((cec_user_control_code) m_currentframe.data[2]);
+        if (frame.data[2] <= CEC_USER_CONTROL_CODE_MAX)
+          m_controller->SetCurrentButton((cec_user_control_code) frame.data[2]);
       }
       break;
     case CEC_OPCODE_USER_CONTROL_RELEASE:
       m_controller->AddKey();
       break;
     default:
-      cec_frame params = m_currentframe;
+      cec_frame params = frame;
       params.shift(2);
       m_controller->AddCommand((cec_logical_address) initiator, (cec_logical_address) destination, opCode, &params);
       break;
@@ -562,9 +568,9 @@ void CCECProcessor::ParseCurrentFrame(void)
     }
     else if (opCode == CEC_OPCODE_SET_STREAM_PATH)
     {
-      if (m_currentframe.size >= 4)
+      if (frame.size >= 4)
       {
-        int streamaddr = ((int)m_currentframe.data[2] << 8) | ((int)m_currentframe.data[3]);
+        int streamaddr = ((int)frame.data[2] << 8) | ((int)frame.data[3]);
         strLog.Format("%i requests stream path from physical address %04x", initiator, streamaddr);
         m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
         if (streamaddr == m_physicaladdress)
@@ -573,7 +579,7 @@ void CCECProcessor::ParseCurrentFrame(void)
     }
     else
     {
-      cec_frame params = m_currentframe;
+      cec_frame params = frame;
       params.shift(2);
       m_controller->AddCommand((cec_logical_address) initiator, (cec_logical_address) destination, opCode, &params);
     }