mark the adapter as (in)active source for firmware v3+
authorLars Op den Kamp <lars@opdenkamp.eu>
Mon, 12 Nov 2012 15:04:12 +0000 (16:04 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Mon, 12 Nov 2012 15:04:12 +0000 (16:04 +0100)
13 files changed:
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/adapter/AdapterCommunication.h
src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.cpp
src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.h
src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp
src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.h
src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.h
src/lib/adapter/Pulse-Eight/USBCECAdapterMessageQueue.cpp
src/lib/adapter/RPi/RPiCECAdapterCommunication.h
src/lib/adapter/TDA995x/TDA995xCECAdapterCommunication.h
src/lib/devices/CECBusDevice.cpp
src/lib/devices/CECBusDevice.h

index 73c921d8120f68c0ffff4f440e6e66e2e0443b07..6b93b3de9683bc43af165228c84b0d6612f46a4d 100644 (file)
@@ -260,6 +260,12 @@ bool CCECProcessor::ActivateSource(uint16_t iStreamPath)
   return bReturn;
 }
 
+void CCECProcessor::SetActiveSource(bool bSetTo, bool bClientUnregistered)
+{
+  if (m_communication)
+    m_communication->SetActiveSource(bSetTo, bClientUnregistered);
+}
+
 void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout)
 {
   CLockObject lock(m_mutex);
@@ -863,7 +869,7 @@ bool CCECProcessor::UnregisterClient(CCECClient *client)
         m_clients.erase(entry);
 
       // reset the device status
-      (*it)->ResetDeviceStatus();
+      (*it)->ResetDeviceStatus(true);
     }
   }
 
index 5593a2cc99e5be970756bd2d778df3f91e27ba50..69586a7cb8fd47f7f010223ad40eb58d5195b0a4 100644 (file)
@@ -110,6 +110,7 @@ namespace CEC
 
       bool SetDeckInfo(cec_deck_info info, bool bSendUpdate = true);
       bool ActivateSource(uint16_t iStreamPath);
+      void SetActiveSource(bool bSetTo, bool bClientUnregistered);
       bool PollDevice(cec_logical_address iAddress);
       void SetStandardLineTimeout(uint8_t iTimeout);
       uint8_t GetStandardLineTimeout(void);
index 7dd56b7fdbfebd22eb3a8c86867fbe916193f980..b1762b7a111db0755c03ede6922cf4e7ac785ae8 100644 (file)
@@ -221,6 +221,13 @@ namespace CEC
      */
     virtual uint16_t GetAdapterProductId(void) const = 0;
 
+    /*!
+     * @brief Marks the adapter as active or inactive source
+     * @param bSetTo True to mark as active source, false to mark as inactive source
+     * @param bClientUnregistered True when the client was unregistered, false when the device was explicitly marked as (in)active source
+     */
+    virtual void SetActiveSource(bool bSetTo, bool bClientUnregistered) = 0;
+
     IAdapterCommunicationCallback *m_callback;
   };
 };
index 944806828ea5553c95d6549c8f006ee22cd00f58..b037e1cab9f9a2d0975a8dc5e8b175648141a228 100644 (file)
@@ -592,6 +592,19 @@ bool CUSBCECAdapterCommands::SetAckMask(uint16_t iMask)
   return bReturn;
 }
 
+void CUSBCECAdapterCommands::SetActiveSource(bool bSetTo, bool bClientUnregistered)
+{
+  if (bClientUnregistered) return;
+  if (m_persistedConfiguration.iFirmwareVersion >= 3)
+  {
+    LIB_CEC->AddLog(CEC_LOG_DEBUG, "marking the adapter as %s source", bSetTo ? "active" : "inactive");
+    CCECAdapterMessage params;
+    params.PushEscaped(bSetTo ? 1 : 0);
+    CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_ACTIVE_SOURCE, params);
+    delete message;
+  }
+}
+
 bool CUSBCECAdapterCommands::StartBootloader(void)
 {
   LIB_CEC->AddLog(CEC_LOG_DEBUG, "starting the bootloader");
index fa7f543261ef8e8c6aee8a9b0dc5c4c81f5fdad7..e0bfb1fe7388b3318ee82c5ac54004338cd10779 100644 (file)
@@ -131,6 +131,8 @@ namespace CEC
      */
     bool WriteEEPROM(void);
 
+    void SetActiveSource(bool bSetTo, bool bClientUnregistered);
+
   private:
     /*!
      * @brief Reads all settings from the eeprom.
index 9c6743f0851ec8c7a241cddec6c3e6b39418979b..ae404588e366ff94c47e3ab8e2c4b2aa68a98958 100644 (file)
@@ -628,6 +628,12 @@ uint16_t CUSBCECAdapterCommunication::GetAdapterProductId(void) const
   return iBuildDate >= CEC_FW_DATE_DESCRIPTOR2 ? CEC_PID2 : CEC_PID;
 }
 
+void CUSBCECAdapterCommunication::SetActiveSource(bool bSetTo, bool bClientUnregistered)
+{
+  if (m_commands)
+    m_commands->SetActiveSource(bSetTo, bClientUnregistered);
+}
+
 bool CUSBCECAdapterCommunication::IsRunningLatestFirmware(void)
 {
   return GetFirmwareBuildDate() >= CEC_LATEST_ADAPTER_FW_DATE &&
index 04199e2bc079b3a7371aa5455da23bc3f856f2bc..0c473ea3216cfb956845423f57d2b3b8e83d9a07 100644 (file)
@@ -90,6 +90,7 @@ namespace CEC
     cec_adapter_type GetAdapterType(void);
     uint16_t GetAdapterVendorId(void) const;
     uint16_t GetAdapterProductId(void) const;
+    void SetActiveSource(bool bSetTo, bool bClientUnregistered);
     ///}
 
     bool ProvidesExtendedResponse(void);
index 89005e8694ff54419e7a93ddddc199dc5a9b50bc..ec45bb9e63e38d3cfa1ac46dce96e12c46e6d55f 100644 (file)
@@ -78,6 +78,8 @@ namespace CEC
     MSGCODE_SET_OSD_NAME,
     MSGCODE_WRITE_EEPROM,
     MSGCODE_GET_ADAPTER_TYPE,
+    MSGCODE_SET_ACTIVE_SOURCE,
+
     MSGCODE_FRAME_EOM = 0x80,
     MSGCODE_FRAME_ACK = 0x40,
   } cec_adapter_messagecode;
index 9fca017c05020f3366afc69599257e72716464bc..4e4c2cb82a678e1b0f63e94d1b2b82bfe7b5b49b 100644 (file)
@@ -164,7 +164,8 @@ bool CCECAdapterMessageQueueEntry::IsResponse(const CCECAdapterMessage &msg)
       thisMsgCode == MSGCODE_SET_HDMI_VERSION ||
       thisMsgCode == MSGCODE_SET_OSD_NAME ||
       thisMsgCode == MSGCODE_WRITE_EEPROM ||
-      thisMsgCode == MSGCODE_TRANSMIT_IDLETIME)
+      thisMsgCode == MSGCODE_TRANSMIT_IDLETIME ||
+      thisMsgCode == MSGCODE_SET_ACTIVE_SOURCE)
     return thisMsgCode == msgResponse;
 
   if (!m_message->IsTranmission())
index 3cbbdde6551e612870dfbfc153049ec02c3a51a7..92b7157be3360d0e00e1af181cbce4968ec45a60 100644 (file)
@@ -85,6 +85,7 @@ namespace CEC
     cec_adapter_type GetAdapterType(void) { return ADAPTERTYPE_RPI; };
     uint16_t GetAdapterVendorId(void) const { return RPI_ADAPTER_VID; }
     uint16_t GetAdapterProductId(void) const { return RPI_ADAPTER_PID; }
+    void SetActiveSource(bool UNUSED(bSetTo), bool UNUSED(bClientUnregistered)) {}
     ///}
 
     bool IsInitialised(void);
index 9476383d2edf7bb9b63f3ea48a993ca37bdc4d93..2adc1f824a6fa199422b69b5f6d31b318c2c7388 100644 (file)
@@ -89,6 +89,7 @@ namespace CEC
     uint16_t GetAdapterVendorId(void) const { return TDA995X_ADAPTER_VID; }
     uint16_t GetAdapterProductId(void) const { return TDA995X_ADAPTER_PID; }
     void HandleLogicalAddressLost(cec_logical_address oldAddress);
+    void SetActiveSource(bool UNUSED(bSetTo), bool UNUSED(bClientUnregistered)) {}
     ///}
 
     /** @name PLATFORM::CThread implementation */
index 1176089b57200081974880329531e01f1ee14380..3be7adf618786f2b08d68f71374b07d7d2b53c29 100644 (file)
@@ -793,7 +793,7 @@ void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus, cec_v
       if (m_deviceStatus != newStatus)
       {
         LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): device status changed into 'not present'", GetLogicalAddressName(), m_iLogicalAddress);
-        ResetDeviceStatus();
+        ResetDeviceStatus(true);
         m_deviceStatus = newStatus;
       }
       break;
@@ -804,7 +804,7 @@ void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus, cec_v
   }
 }
 
-void CCECBusDevice::ResetDeviceStatus(void)
+void CCECBusDevice::ResetDeviceStatus(bool bClientUnregistered /* = false */)
 {
   CLockObject lock(m_mutex);
   SetPowerStatus   (CEC_POWER_STATUS_UNKNOWN);
@@ -813,7 +813,7 @@ void CCECBusDevice::ResetDeviceStatus(void)
   SetCecVersion    (CEC_VERSION_UNKNOWN);
   SetStreamPath    (CEC_INVALID_PHYSICAL_ADDRESS);
   SetOSDName       (ToString(m_iLogicalAddress));
-  MarkAsInactiveSource();
+  MarkAsInactiveSource(bClientUnregistered);
 
   m_iLastActive = 0;
   m_bVendorIdRequested = false;
@@ -966,13 +966,14 @@ void CCECBusDevice::MarkAsActiveSource(void)
 
   if (bWasActivated)
   {
+    m_processor->SetActiveSource(true, false);
     CCECClient *client = GetClient();
     if (client)
       client->SourceActivated(m_iLogicalAddress);
   }
 }
 
-void CCECBusDevice::MarkAsInactiveSource(void)
+void CCECBusDevice::MarkAsInactiveSource(bool bClientUnregistered /* = false */)
 {
   bool bWasDeactivated(false);
   {
@@ -987,6 +988,7 @@ void CCECBusDevice::MarkAsInactiveSource(void)
 
   if (bWasDeactivated)
   {
+    m_processor->SetActiveSource(false, bClientUnregistered);
     CCECClient *client = GetClient();
     if (client)
       client->SourceDeactivated(m_iLogicalAddress);
index 6cba39f864f9adc4105b2bf639dbd964644bb25c..1abf488a8aa36aff0f2f35df901891d041bb7b0f 100644 (file)
@@ -205,7 +205,7 @@ namespace CEC
     virtual cec_bus_device_status GetCurrentStatus(void) { return GetStatus(false, true); }
     virtual cec_bus_device_status GetStatus(bool bForcePoll = false, bool bSuppressPoll = false);
     virtual void                  SetDeviceStatus(const cec_bus_device_status newStatus, cec_version libCECSpecVersion = CEC_VERSION_1_4);
-    virtual void                  ResetDeviceStatus(void);
+    virtual void                  ResetDeviceStatus(bool bClientUnregistered = false);
     virtual bool                  TransmitPoll(const cec_logical_address destination, bool bUpdateDeviceStatus);
     virtual void                  HandlePoll(const cec_logical_address destination);
     virtual void                  HandlePollFrom(const cec_logical_address initiator);
@@ -219,7 +219,7 @@ namespace CEC
     virtual bool                  IsActiveSource(void) const    { return m_bActiveSource; }
     virtual bool                  RequestActiveSource(bool bWaitForResponse = true);
     virtual void                  MarkAsActiveSource(void);
-    virtual void                  MarkAsInactiveSource(void);
+    virtual void                  MarkAsInactiveSource(bool bClientUnregistered = false);
     virtual bool                  TransmitActiveSource(bool bIsReply);
     virtual bool                  TransmitImageViewOn(void);
     virtual bool                  TransmitInactiveSource(void);