cec: fixed - mark a device as active source before transmitting the active source...
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 9 Dec 2011 10:37:45 +0000 (11:37 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 9 Dec 2011 10:37:45 +0000 (11:37 +0100)
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/LibCEC.cpp
src/lib/devices/CECBusDevice.cpp
src/lib/devices/CECBusDevice.h
src/lib/implementations/CECCommandHandler.cpp
src/lib/implementations/SLCommandHandler.cpp

index a3c22df3169ad9f3851b3b34a30fd38c22cd96c7..565d226493e08c96a316338180332befaa4aa5f4 100644 (file)
@@ -176,12 +176,6 @@ bool CCECProcessor::TryLogicalAddress(cec_logical_address address)
 {
   if (m_busDevices[address]->TryLogicalAddress())
   {
-    /* only set our OSD name and active source for the primary device */
-    if (m_logicalAddresses.IsEmpty())
-    {
-      m_busDevices[address]->m_strDeviceName = m_strDeviceName;
-      m_busDevices[address]->m_bActiveSource = true;
-    }
     m_logicalAddresses.Set(address);
     return true;
   }
@@ -262,6 +256,10 @@ void *CCECProcessor::Process(void)
   }
   else
   {
+    /* only set our OSD name and active source for the primary device */
+    m_busDevices[m_logicalAddresses.primary]->m_strDeviceName = m_strDeviceName;
+    m_busDevices[m_logicalAddresses.primary]->m_bActiveSource = true;
+
     SetAckMask(m_logicalAddresses.AckMask());
 
     CLockObject lock(&m_mutex);
@@ -331,8 +329,8 @@ bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RE
     }
   }
 
-  bReturn = m_busDevices[addr]->TransmitActiveSource() &&
-      SetStreamPath(m_busDevices[addr]->GetPhysicalAddress(false));
+  m_busDevices[addr]->SetActiveSource();
+  bReturn = m_busDevices[addr]->TransmitActiveSource();
 
   if (bReturn && (m_busDevices[addr]->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE ||
       m_busDevices[addr]->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE))
@@ -343,6 +341,20 @@ bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RE
   return bReturn;
 }
 
+bool CCECProcessor::SetActiveSource(uint16_t iStreamPath)
+{
+  bool bReturn(false);
+
+  CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath);
+  if (device)
+  {
+    device->SetActiveSource();
+    bReturn = true;
+  }
+
+  return bReturn;
+}
+
 void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout)
 {
   CLockObject lock(&m_mutex);
@@ -460,20 +472,6 @@ bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress)
   return false;
 }
 
-bool CCECProcessor::SetStreamPath(uint16_t iStreamPath)
-{
-  bool bReturn(false);
-
-  CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath);
-  if (device)
-  {
-    device->SetActiveDevice();
-    bReturn = true;
-  }
-
-  return bReturn;
-}
-
 bool CCECProcessor::TransmitInactiveSource(void)
 {
   if (!IsRunning())
@@ -590,7 +588,7 @@ bool CCECProcessor::PollDevice(cec_logical_address iAddress)
 uint8_t CCECProcessor::VolumeUp(void)
 {
   uint8_t status = 0;
-  if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM))
+  if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
     status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp();
 
   return status;
@@ -599,7 +597,7 @@ uint8_t CCECProcessor::VolumeUp(void)
 uint8_t CCECProcessor::VolumeDown(void)
 {
   uint8_t status = 0;
-  if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM))
+  if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
     status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown();
 
   return status;
@@ -608,7 +606,7 @@ uint8_t CCECProcessor::VolumeDown(void)
 uint8_t CCECProcessor::MuteAudio(void)
 {
   uint8_t status = 0;
-  if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM))
+  if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
     status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio();
 
   return status;
@@ -933,12 +931,12 @@ cec_logical_addresses CCECProcessor::GetActiveDevices(void)
   return addresses;
 }
 
-bool CCECProcessor::IsActiveDevice(cec_logical_address address)
+bool CCECProcessor::IsPresentDevice(cec_logical_address address)
 {
   return m_busDevices[address]->GetStatus() == CEC_DEVICE_STATUS_PRESENT;
 }
 
-bool CCECProcessor::IsActiveDeviceType(cec_device_type type)
+bool CCECProcessor::IsPresentDeviceType(cec_device_type type)
 {
   for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
   {
index d2aa22206b046f3309e51ef22156df42686d10f6..a0e0e73b8b5e95113305d0f1473acbf326bbf787 100644 (file)
@@ -70,8 +70,8 @@ namespace CEC
       virtual cec_logical_addresses GetActiveDevices(void);
       virtual uint16_t              GetDevicePhysicalAddress(cec_logical_address iAddress);
       virtual bool                  HasLogicalAddress(cec_logical_address address) const { return m_logicalAddresses.IsSet(address); }
-      virtual bool                  IsActiveDevice(cec_logical_address address);
-      virtual bool                  IsActiveDeviceType(cec_device_type type);
+      virtual bool                  IsPresentDevice(cec_logical_address address);
+      virtual bool                  IsPresentDeviceType(cec_device_type type);
       virtual uint16_t              GetPhysicalAddress(void) const;
       virtual uint64_t              GetLastTransmission(void) const { return m_iLastTransmission; }
       virtual bool                  IsStarted(void) const { return m_bStarted; }
@@ -87,7 +87,7 @@ namespace CEC
       virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress);
       virtual bool SetMenuState(cec_menu_state state, bool bSendUpdate = true);
       virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress);
-      virtual bool SetStreamPath(uint16_t iStreamPath);
+      virtual bool SetActiveSource(uint16_t iStreamPath);
       virtual bool SwitchMonitoring(bool bEnable);
       virtual bool PollDevice(cec_logical_address iAddress);
       virtual uint8_t VolumeUp(void);
index f43071c32025314bb0a0956805c25d2175edbce4..0ca0188bfa0b596847beafcfdeb7622cb7b78e18 100644 (file)
@@ -267,14 +267,14 @@ cec_logical_addresses CLibCEC::GetActiveDevices(void)
 bool CLibCEC::IsActiveDevice(cec_logical_address iAddress)
 {
   if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST)
-    return m_cec->IsActiveDevice(iAddress);
+    return m_cec->IsPresentDevice(iAddress);
   return false;
 }
 
 bool CLibCEC::IsActiveDeviceType(cec_device_type type)
 {
   if (m_cec && type >= CEC_DEVICE_TYPE_TV && type <= CEC_DEVICE_TYPE_AUDIO_SYSTEM)
-    return m_cec->IsActiveDeviceType(type);
+    return m_cec->IsPresentDeviceType(type);
   return false;
 }
 
index 8b4278119746c13a710102d3906958a063696d11..f03f0cba0bbf590fd6d2baa325a5b6d56a595df2 100644 (file)
@@ -440,7 +440,7 @@ void CCECBusDevice::SetInactiveDevice(void)
   m_bActiveSource = false;
 }
 
-void CCECBusDevice::SetActiveDevice(void)
+void CCECBusDevice::SetActiveSource(void)
 {
   CLockObject lock(&m_writeMutex);
 
index 14f3302952b6cdefcd85a10e943ab2786af6cc21..f1786f948d7725008aa1135501846f1974d2948b 100644 (file)
@@ -76,7 +76,7 @@ namespace CEC
 
 
     virtual void SetInactiveDevice(void);
-    virtual void SetActiveDevice(void);
+    virtual void SetActiveSource(void);
     virtual bool TryLogicalAddress(void);
 
     virtual void SetDeviceStatus(const cec_bus_device_status newStatus);
index 5c6a52f0abc2e9d4d82ea2b1e944f8361cf5a077..c7b030543ca044a137b78e8947009e98fabb39c7 100644 (file)
@@ -178,7 +178,7 @@ bool CCECCommandHandler::HandleActiveSource(const cec_command &command)
   if (command.parameters.size == 2)
   {
     uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
-    return m_processor->SetStreamPath(iAddress);
+    return m_processor->SetActiveSource(iAddress);
   }
 
   return true;
@@ -319,7 +319,7 @@ bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &comm
 
 bool CCECCommandHandler::HandleImageViewOn(const cec_command &command)
 {
-  m_processor->SetStreamPath(m_processor->m_busDevices[command.initiator]->GetPhysicalAddress(false));
+  m_processor->m_busDevices[command.initiator]->SetActiveSource();
   return true;
 }
 
@@ -409,7 +409,7 @@ bool CCECCommandHandler::HandleRoutingInformation(const cec_command &command)
   if (command.parameters.size == 2)
   {
     uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
-    m_processor->SetStreamPath(iNewAddress);
+    m_processor->SetActiveSource(iNewAddress);
   }
 
   return false;
@@ -464,14 +464,12 @@ bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command)
     strLog.Format(">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress);
     m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
 
-    if (m_processor->SetStreamPath(iStreamAddress))
+    CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamAddress);
+    if (device)
     {
-      CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamAddress);
-      if (device)
-      {
-        return device->TransmitActiveSource() &&
-            device->TransmitMenuState(command.initiator);
-      }
+      device->SetActiveSource();
+      return device->TransmitActiveSource() &&
+          device->TransmitMenuState(command.initiator);
     }
   }
   return false;
@@ -491,7 +489,7 @@ bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command &command
         uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
         CCECBusDevice *newActiveDevice = GetDeviceByPhysicalAddress(iNewAddress);
         if (newActiveDevice)
-          m_processor->SetStreamPath(newActiveDevice->GetPhysicalAddress(false));
+          newActiveDevice->SetActiveSource();
         return ((CCECAudioSystem *) device)->TransmitSetSystemAudioMode(command.initiator);
       }
       else
@@ -545,7 +543,7 @@ bool CCECCommandHandler::HandleSetSystemAudioMode(const cec_command &command)
 
 bool CCECCommandHandler::HandleTextViewOn(const cec_command &command)
 {
-  m_processor->SetStreamPath(m_processor->m_busDevices[command.initiator]->GetPhysicalAddress(false));
+  m_processor->m_busDevices[command.initiator]->SetActiveSource();
   return true;
 }
 
index c23099eb0d2c408ba0ef6f37f7fccdef7055dcae..0f007176d623f9e83732abbef114790b97446d28 100644 (file)
@@ -145,8 +145,8 @@ void CSLCommandHandler::HandleVendorCommandPowerOn(const cec_command &command)
 void CSLCommandHandler::HandleVendorCommandSLConnect(const cec_command &command)
 {
   m_bSLEnabled = true;
+  m_processor->m_busDevices[command.initiator]->SetActiveSource();
   m_processor->m_busDevices[command.destination]->TransmitActiveSource();
-  m_processor->SetStreamPath(m_processor->m_busDevices[command.destination]->GetPhysicalAddress(false));
   TransmitVendorCommand05(command.destination, command.initiator);
   TransmitDeckStatus(command.initiator);
 }