cec: get the vendor id of the TV before allocating logical addresses, so we can deter...
[deb_libcec.git] / src / lib / implementations / CECCommandHandler.cpp
index 6ffc4ac980db71cdfbdbd42cfd577084426e0e00..77b94a49f0d27241ff27e49f760a6d477fdea4d3 100644 (file)
@@ -56,7 +56,8 @@ CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice) :
     m_bHandlerInited(false),
     m_bOPTSendDeckStatusUpdateOnActiveSource(false),
     m_vendorId(CEC_VENDOR_UNKNOWN),
-    m_waitForResponse(new CWaitForResponse)
+    m_waitForResponse(new CWaitForResponse),
+    m_bActiveSourcePending(false)
 {
 }
 
@@ -195,6 +196,10 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command)
   case CEC_OPCODE_VENDOR_COMMAND:
     HandleVendorCommand(command);
     break;
+  case CEC_OPCODE_PLAY:
+    // libCEC (currently) doesn't need to do anything with this, since player applications handle it
+    // but it should not respond with a feature abort
+    break;
   default:
     bHandled = false;
     break;
@@ -1056,16 +1061,27 @@ bool CCECCommandHandler::ActivateSource(void)
   if (m_busDevice->IsActiveSource() &&
     m_busDevice->IsHandledByLibCEC())
   {
+    {
+      CLockObject lock(m_mutex);
+      m_bActiveSourcePending = false;
+    }
+
     m_busDevice->SetPowerStatus(CEC_POWER_STATUS_ON);
     m_busDevice->SetMenuState(CEC_MENU_STATE_ACTIVATED);
 
-    m_busDevice->TransmitImageViewOn();
-    m_busDevice->TransmitActiveSource();
-    m_busDevice->TransmitMenuState(CECDEVICE_TV);
+    if (!m_busDevice->TransmitImageViewOn() ||
+        !m_busDevice->TransmitActiveSource() ||
+        !m_busDevice->TransmitMenuState(CECDEVICE_TV))
+    {
+      CLockObject lock(m_mutex);
+      m_bActiveSourcePending = true;
+      return false;
+    }
 
     CCECPlaybackDevice *playbackDevice = m_busDevice->AsPlaybackDevice();
     if (playbackDevice && SendDeckStatusUpdateOnActiveSource())
       playbackDevice->TransmitDeckStatus(CECDEVICE_TV);
+
     m_bHandlerInited = true;
   }
   return true;
@@ -1075,3 +1091,9 @@ void CCECCommandHandler::SignalOpcode(cec_opcode opcode)
 {
   m_waitForResponse->Received(opcode);
 }
+
+bool CCECCommandHandler::ActiveSourcePending(void)
+{
+  CLockObject lock(m_mutex);
+  return m_bActiveSourcePending;
+}