cec: set controlled mode and retry to send the previous command if it failed with...
[deb_libcec.git] / src / lib / adapter / USBCECAdapterCommunication.cpp
index 09a3bb2029de81b4774f8c41294014c18398e29d..72abd15833e7c588e58a3e4fd6663cbb5dff1382 100644 (file)
@@ -967,7 +967,7 @@ CStdString CUSBCECAdapterCommunication::GetPortName(void)
   return strName;
 }
 
-bool CUSBCECAdapterCommunication::SendCommand(cec_adapter_messagecode msgCode, CCECAdapterMessage &params, bool bExpectAck /* = true */, bool bIsTransmission /* = false */, bool bSendDirectly /* = true */)
+bool CUSBCECAdapterCommunication::SendCommand(cec_adapter_messagecode msgCode, CCECAdapterMessage &params, bool bExpectAck /* = true */, bool bIsTransmission /* = false */, bool bSendDirectly /* = true */, bool bIsRetry /* = false */)
 {
   CLockObject lock(m_mutex);
 
@@ -990,6 +990,13 @@ bool CUSBCECAdapterCommunication::SendCommand(cec_adapter_messagecode msgCode, C
   {
     CLibCEC::AddLog(CEC_LOG_ERROR, "'%s' failed", CCECAdapterMessage::ToString(msgCode));
     delete output;
+
+    if (!bIsRetry && output->reply == MSGCODE_COMMAND_REJECTED && msgCode != MSGCODE_SET_CONTROLLED)
+    {
+      CLibCEC::AddLog(CEC_LOG_DEBUG, "setting controlled mode and retrying");
+      if (SetControlledMode(true))
+        return SendCommand(msgCode, params, bExpectAck, bIsTransmission, bSendDirectly, true);
+    }
     return false;
   }