cec: mark the active source as active and other devices as inactive. removed duplicat...
authorLars Op den Kamp <lars@opdenkamp.eu>
Thu, 10 Nov 2011 17:30:00 +0000 (18:30 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Thu, 10 Nov 2011 18:00:34 +0000 (19:00 +0100)
include/cectypes.h
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/devices/CECBusDevice.cpp
src/lib/devices/CECBusDevice.h
src/lib/devices/CECPlaybackDevice.cpp
src/lib/devices/CECPlaybackDevice.h
src/lib/implementations/CECCommandHandler.cpp
src/lib/implementations/CECCommandHandler.h
src/lib/implementations/VLCommandHandler.cpp

index cb647fd2230300eb848d1635e98173e278ff18c1..4a503710248ea2557b92f4f577dde9f2dc054de5 100644 (file)
@@ -115,15 +115,15 @@ typedef enum
   CEC_MINOR_CHANNEL_NUMBER_MASK = 0xFFFF
 } ECecChannelIdentifier;
 
-typedef enum
+typedef enum cec_deck_control_mode
 {
   CEC_DESK_CONTROL_MODE_SKIP_FORWARD_WIND = 1,
   CEC_DESK_CONTROL_MODE_SKIP_REVERSE_REWIND = 2,
   CEC_DESK_CONTROL_MODE_STOP = 3,
   CEC_DESK_CONTROL_MODE_EJECT = 4
-} ECecDeskControlMode;
+} cec_deck_control_mode;
 
-typedef enum
+typedef enum cec_deck_info
 {
   CEC_DECK_INFO_PLAY = 0x11,
   CEC_DECK_INFO_RECORD = 0x12,
@@ -140,7 +140,7 @@ typedef enum
   CEC_DECK_INFO_INDEX_SEARCH_FORWARD = 0x1D,
   CEC_DECK_INFO_INDEX_SEARCH_REVERSE = 0x1E,
   CEC_DECK_INFO_OTHER_STATUS = 0x1F
-} ECecDeckInfo;
+} cec_deck_info;
 
 typedef enum cec_device_type
 {
index 1bd39dd84b2cdb90baf068dc8197ba37aff3f742..53a1da3405e7e3a1c4b5a41a39444fda83c58d75 100644 (file)
@@ -292,11 +292,31 @@ void *CCECProcessor::Process(void)
 
 bool CCECProcessor::SetActiveView(void)
 {
+  bool bReturn(false);
+
   if (!IsRunning())
-    return false;
+    return bReturn;
 
   if (!m_logicalAddresses.empty() && m_busDevices[m_logicalAddresses.primary])
-    return m_busDevices[m_logicalAddresses.primary]->TransmitActiveView();
+  {
+    SetStreamPath(m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress());
+    bReturn = m_busDevices[m_logicalAddresses.primary]->TransmitActiveSource();
+  }
+  return false;
+}
+
+bool CCECProcessor::SetStreamPath(uint16_t iStreamPath)
+{
+  CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath);
+  if (device)
+  {
+    for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+      m_busDevices[iPtr]->m_bActiveSource = false;
+
+    device->m_bActiveSource = true;
+    return true;
+  }
+
   return false;
 }
 
@@ -342,7 +362,7 @@ bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress)
   if (!m_logicalAddresses.empty() && m_busDevices[m_logicalAddresses.primary])
   {
     m_busDevices[m_logicalAddresses.primary]->SetPhysicalAddress(iPhysicalAddress);
-    return m_busDevices[m_logicalAddresses.primary]->TransmitActiveView();
+    return SetActiveView();
   }
   return false;
 }
@@ -367,6 +387,23 @@ bool CCECProcessor::PollDevice(cec_logical_address iAddress)
   return false;
 }
 
+
+CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const
+{
+  CCECBusDevice *device = NULL;
+
+  for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+  {
+    if (m_busDevices[iPtr]->GetPhysicalAddress() == iPhysicalAddress)
+    {
+      device = m_busDevices[iPtr];
+      break;
+    }
+  }
+
+  return device;
+}
+
 cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress)
 {
   return m_busDevices[iAddress]->GetCecVersion();
index 8baf726904dd3a4d0f4512f199f131d3cf58ce34..75651d7b5cce73fe667ad6fe43d7e86f4416e1a9 100644 (file)
@@ -57,6 +57,7 @@ namespace CEC
       virtual void *Process(void);
 
       virtual bool                  IsMonitoring(void) const { return m_bMonitor; }
+      virtual CCECBusDevice *       GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const;
       virtual cec_version           GetDeviceCecVersion(cec_logical_address iAddress);
       virtual bool                  GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language);
       virtual const std::string &   GetDeviceName(void) { return m_strDeviceName; }
@@ -71,6 +72,7 @@ namespace CEC
       virtual bool SetInactiveView(void);
       virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress);
       virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress);
+      virtual bool SetStreamPath(uint16_t iStreamPath);
       virtual bool SwitchMonitoring(bool bEnable);
       virtual bool PollDevice(cec_logical_address iAddress);
 
index 640534d457c2062365ddd4881ce5834cdaef7b91..49ca7db7ce64592db298735d361d040f08b23149 100644 (file)
@@ -391,20 +391,6 @@ bool CCECBusDevice::TransmitActiveSource(void)
   return false;
 }
 
-bool CCECBusDevice::TransmitActiveView(void)
-{
-  CStdString strLog;
-  strLog.Format("<< %s (%X) -> broadcast (F): active view (%4x)", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress);
-  AddLog(CEC_LOG_NOTICE, strLog);
-
-  cec_command command;
-  cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE);
-  command.parameters.push_back((m_iPhysicalAddress >> 8) & 0xFF);
-  command.parameters.push_back(m_iPhysicalAddress & 0xFF);
-
-  return m_processor->Transmit(command);
-}
-
 bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest)
 {
   CStdString strLog;
index 6e599673881e08b92e3d43ded82f30f9c8c9f67a..d07f4c8ab921b6a9b60218d5db4f1f535d160212 100644 (file)
@@ -81,7 +81,6 @@ namespace CEC
     virtual void SetPowerStatus(const cec_power_status powerStatus);
 
     virtual bool TransmitActiveSource(void);
-    virtual bool TransmitActiveView(void);
     virtual bool TransmitCECVersion(cec_logical_address dest);
     virtual bool TransmitInactiveView(void);
     virtual bool TransmitMenuState(cec_logical_address dest);
index d96d5c9f374b3f34499238af4861f7f32e8fc987..ef6f00b382c41876b7287179b0ec202365f5dc2a 100644 (file)
 using namespace CEC;
 
 CCECPlaybackDevice::CCECPlaybackDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = 0 */) :
-    CCECBusDevice(processor, address, iPhysicalAddress)
+    CCECBusDevice(processor, address, iPhysicalAddress),
+    m_deckStatus(CEC_DECK_INFO_NO_MEDIA)
 {
   m_type = CEC_DEVICE_TYPE_PLAYBACK_DEVICE;
 }
 
+void CCECPlaybackDevice::SetDeckStatus(cec_deck_info deckStatus)
+{
+  if (m_deckStatus != deckStatus)
+  {
+    CStdString strLog;
+    strLog.Format(">> %s (%X): deck status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(m_deckStatus), CCECCommandHandler::ToString(deckStatus));
+    AddLog(CEC_LOG_DEBUG, strLog.c_str());
+
+    m_deckStatus = deckStatus;
+  }
+}
+
 bool CCECPlaybackDevice::TransmitDeckStatus(cec_logical_address dest)
 {
   // need to support opcodes play and deck control before doing anything with this
index 1af94855843406fc9bda28de9ba63fb980490d95..24ce072af0e423fba722c7b5b3f393bbe1624724 100644 (file)
@@ -41,6 +41,13 @@ namespace CEC
     CCECPlaybackDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = 0);
     virtual ~CCECPlaybackDevice(void) {};
 
+    virtual cec_deck_info GetDeckStatus(void) const { return m_deckStatus; };
+
+    virtual void SetDeckStatus(cec_deck_info deckStatus);
+
     virtual bool TransmitDeckStatus(cec_logical_address dest);
+
+  protected:
+    cec_deck_info m_deckStatus;
   };
 }
index 2f6dd699dcff1c493d82fc964f007f6e38b8eaca..72294807dfb6b9ffd9c5985414e8ae7290c7f02c 100644 (file)
@@ -422,18 +422,7 @@ CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress
 
 CCECBusDevice *CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const
 {
-  CCECBusDevice *device = NULL;
-
-  for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
-  {
-    if (m_busDevice->GetProcessor()->m_busDevices[iPtr]->GetPhysicalAddress() == iPhysicalAddress)
-    {
-      device = m_busDevice->GetProcessor()->m_busDevices[iPtr];
-      break;
-    }
-  }
-
-  return device;
+  return m_busDevice->GetProcessor()->GetDeviceByPhysicalAddress(iPhysicalAddress);
 }
 
 void CCECCommandHandler::SetVendorId(const cec_command &command)
@@ -494,6 +483,45 @@ const char *CCECCommandHandler::ToString(const cec_logical_address address)
   }
 }
 
+const char *CCECCommandHandler::ToString(const cec_deck_info status)
+{
+  switch (status)
+  {
+  case CEC_DECK_INFO_PLAY:
+    return "play";
+  case CEC_DECK_INFO_RECORD:
+    return "record";
+  case CEC_DECK_INFO_PLAY_REVERSE:
+    return "play reverse";
+  case CEC_DECK_INFO_STILL:
+    return "still";
+  case CEC_DECK_INFO_SLOW:
+    return "slow";
+  case CEC_DECK_INFO_SLOW_REVERSE:
+    return "slow reverse";
+  case CEC_DECK_INFO_FAST_FORWARD:
+    return "fast forward";
+  case CEC_DECK_INFO_FAST_REVERSE:
+    return "fast reverse";
+  case CEC_DECK_INFO_NO_MEDIA:
+    return "no media";
+  case CEC_DECK_INFO_STOP:
+    return "stop";
+  case CEC_DECK_INFO_SKIP_FORWARD_WIND:
+    return "info skip forward wind";
+  case CEC_DECK_INFO_SKIP_REVERSE_REWIND:
+    return "info skip reverse rewind";
+  case CEC_DECK_INFO_INDEX_SEARCH_FORWARD:
+    return "info index search forward";
+  case CEC_DECK_INFO_INDEX_SEARCH_REVERSE:
+    return "info index search reverse";
+  case CEC_DECK_INFO_OTHER_STATUS:
+    return "other";
+  default:
+    return "unknown";
+  }
+}
+
 const char *CCECCommandHandler::ToString(const cec_opcode opcode)
 {
   switch (opcode)
index 934dfc5c6feb0d4df8c96b3b37178940f6edd4c6..58b13e9724c38516d066946e6570264d75bc4fa3 100644 (file)
@@ -47,6 +47,7 @@ namespace CEC
     virtual bool HandleCommand(const cec_command &command);
     virtual cec_vendor_id GetVendorId(void) { return CEC_VENDOR_UNKNOWN; };
 
+    static const char *ToString(const cec_deck_info status);
     static const char* ToString(const cec_logical_address address);
     static const char* ToString(const cec_opcode opcode);
 
index d1c7605e3d83574b1f172b47fd6cd3cf35c2e9f0..e3d570bf6f1e0dd51ec2965c354f4eaaec2f3738 100644 (file)
@@ -55,7 +55,6 @@ bool CVLCommandHandler::HandleSetStreamPath(const cec_command &command)
       if (device)
       {
         return device->TransmitActiveSource() &&
-               device->TransmitActiveView() &&
                device->TransmitMenuState(command.initiator);
       }
       return false;