- m_busDevices[addr]->SetActiveSource();
- if (m_busDevices[addr]->GetPhysicalAddress() != CEC_INVALID_PHYSICAL_ADDRESS)
- bReturn = m_busDevices[addr]->ActivateSource();
-
- return bReturn;
-}
-
-bool CCECProcessor::SetActiveSource(uint16_t iStreamPath)
-{
- bool bReturn(false);
-
- // suppress polls when searching for a device
- CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath);
- if (device)
- {
- device->SetActiveSource();
- bReturn = true;
- }
- else
- {
- CLibCEC::AddLog(CEC_LOG_DEBUG, "device with PA '%04x' not found", iStreamPath);
- }
-
- return bReturn;
-}
-
-void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout)
-{
- CLockObject lock(m_mutex);
- m_iStandardLineTimeout = iTimeout;
-}
-
-void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout)
-{
- CLockObject lock(m_mutex);
- m_iRetryLineTimeout = iTimeout;
-}
-
-bool CCECProcessor::SetActiveView(void)
-{
- CLibCEC::AddLog(CEC_LOG_WARNING, "deprecated method %s called", __FUNCTION__);
- return SetActiveSource(m_configuration.deviceTypes.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED : m_configuration.deviceTypes[0]);
-}
-
-bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */)
-{
- bool bReturn(false);
-
- CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
- if (device)
- {
- ((CCECPlaybackDevice *) device)->SetDeckControlMode(mode);
- if (bSendUpdate)
- ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
- bReturn = true;
- }
-
- return bReturn;
-}
-
-bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */)
-{
- bool bReturn(false);
-
- CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
- if (device)
- {
- ((CCECPlaybackDevice *) device)->SetDeckStatus(info);
- if (bSendUpdate)
- ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
- bReturn = true;
- }
-
- return bReturn;
-}
-
-bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, bool bForce /* = false */)
-{
- bool bReturn(false);
-
- // limit the HDMI port range to 1-15
- if (iPort < 1)
- iPort = 1;
- if (iPort > 15)
- iPort = 15;
-
- {
- CLockObject lock(m_mutex);
- m_configuration.baseDevice = iBaseDevice;
- m_configuration.iHDMIPort = iPort;
- }
-
- if (!IsRunning() && !bForce)
- return true;
-
- CLibCEC::AddLog(CEC_LOG_DEBUG, "setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice);
-
- uint16_t iPhysicalAddress(0);
- if (iBaseDevice > CECDEVICE_TV)
- {
- iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress();
- }
-
- if (iPhysicalAddress <= CEC_MAX_PHYSICAL_ADDRESS)
- {
- if (iPhysicalAddress == 0)
- iPhysicalAddress += 0x1000 * iPort;
- else if (iPhysicalAddress % 0x1000 == 0)
- iPhysicalAddress += 0x100 * iPort;
- else if (iPhysicalAddress % 0x100 == 0)
- iPhysicalAddress += 0x10 * iPort;
- else if (iPhysicalAddress % 0x10 == 0)
- iPhysicalAddress += iPort;
-
- bReturn = true;
- }
-
- if (!bReturn)
- CLibCEC::AddLog(CEC_LOG_ERROR, "failed to set the physical address");
- else
- SetPhysicalAddress(iPhysicalAddress);
-
- return bReturn;
-}
-
-bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress)
-{
- for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
- {
- if (m_busDevices[iPtr]->GetPhysicalAddress() == iPhysicalAddress)
- return true;
- }
- return false;
-}
-
-bool CCECProcessor::TransmitInactiveSource(void)
-{
- if (!IsRunning())
- return false;
-
- if (!m_configuration.logicalAddresses.IsEmpty() && m_busDevices[m_configuration.logicalAddresses.primary])
- return m_busDevices[m_configuration.logicalAddresses.primary]->TransmitInactiveSource();
- return false;
-}
-
-void CCECProcessor::LogOutput(const cec_command &data)
-{
- CStdString strTx;
- strTx.Format("<< %02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination);
- if (data.opcode_set)
- strTx.AppendFormat(":%02x", (uint8_t)data.opcode);
-
- for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++)
- strTx.AppendFormat(":%02x", data.parameters[iPtr]);
- CLibCEC::AddLog(CEC_LOG_TRAFFIC, strTx.c_str());
-}
-
-bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
-{
- CLockObject lock(m_mutex);
- if (m_configuration.logicalAddresses.primary != iLogicalAddress)
- {
- CLibCEC::AddLog(CEC_LOG_NOTICE, "<< setting primary logical address to %1x", iLogicalAddress);
- m_configuration.logicalAddresses.primary = iLogicalAddress;
- m_configuration.logicalAddresses.Set(iLogicalAddress);
- return SetAckMask(m_configuration.logicalAddresses.AckMask());
- }
-
- return true;
-}
-
-bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */)
-{
- for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
- {
- if (m_configuration.logicalAddresses[iPtr])
- m_busDevices[iPtr]->SetMenuState(state);
- }
-
- if (bSendUpdate)
- m_busDevices[m_configuration.logicalAddresses.primary]->TransmitMenuState(CECDEVICE_TV);
-
- return true;
-}
-
-bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress, bool bSendUpdate /* = true */)
-{
- bool bSendActiveView(false);
- bool bReturn(false);
- cec_logical_addresses sendUpdatesTo;
- sendUpdatesTo.Clear();
-
- {
- CLockObject lock(m_mutex);
- m_configuration.iPhysicalAddress = iPhysicalAddress;
- CLibCEC::AddLog(CEC_LOG_DEBUG, "setting physical address to '%4x'", iPhysicalAddress);
-
- if (!m_configuration.logicalAddresses.IsEmpty())
- {
- bool bWasActiveSource(false);
- for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
- if (m_configuration.logicalAddresses[iPtr])
- {
- bWasActiveSource |= m_busDevices[iPtr]->IsActiveSource();
- m_busDevices[iPtr]->SetInactiveSource();
- m_busDevices[iPtr]->SetPhysicalAddress(iPhysicalAddress);
- if (bSendUpdate)
- sendUpdatesTo.Set((cec_logical_address)iPtr);
- }
-
- bSendActiveView = bWasActiveSource && bSendUpdate;
- bReturn = true;
- }
- }
-
- for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
- if (sendUpdatesTo[iPtr])
- m_busDevices[iPtr]->TransmitPhysicalAddress();
-
- if (bSendActiveView)
- SetActiveView();
-
- if (bReturn)
- {
- libcec_configuration config;
- {
- CLockObject lock(m_mutex);
- config = m_configuration;
- }
-
- PersistConfiguration(&config);
- CLibCEC::ConfigurationChanged(config);
- }
-
- return bReturn;
-}
-
-bool CCECProcessor::SwitchMonitoring(bool bEnable)
-{
- CLibCEC::AddLog(CEC_LOG_NOTICE, "== %s monitoring mode ==", bEnable ? "enabling" : "disabling");
-
- {
- CLockObject lock(m_mutex);
- m_bMonitor = bEnable;
- }
-
- if (bEnable)
- return SetAckMask(0);
- else
- return SetAckMask(m_configuration.logicalAddresses.AckMask());
-}
-
-bool CCECProcessor::PollDevice(cec_logical_address iAddress)
-{
- if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress])
- {
- return m_configuration.logicalAddresses.primary == CECDEVICE_UNKNOWN ?
- m_busDevices[iAddress]->TransmitPoll(iAddress) :
- m_busDevices[m_configuration.logicalAddresses.primary]->TransmitPoll(iAddress);
- }
- return false;
-}
-
-uint8_t CCECProcessor::VolumeUp(bool bSendRelease /* = true */)
-{
- uint8_t status = 0;
- if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
- status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp(bSendRelease);
-
- return status;
-}
-
-uint8_t CCECProcessor::VolumeDown(bool bSendRelease /* = true */)
-{
- uint8_t status = 0;
- if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
- status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown(bSendRelease);
-
- return status;
-}
-
-uint8_t CCECProcessor::MuteAudio(bool bSendRelease /* = true */)
-{
- uint8_t status = 0;
- if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
- status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio(bSendRelease);
-
- return status;
-}
-
-CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bSuppressUpdate /* = true */)
-{
- CCECBusDevice *device(NULL);
-
- // invalid PA
- if (iPhysicalAddress == CEC_INVALID_PHYSICAL_ADDRESS)
- return device;
-
- // check each device until we found a match
- for (unsigned int iPtr = 0; !device && iPtr < 16; iPtr++)
- {
- if (m_busDevices[iPtr]->GetPhysicalAddress(bSuppressUpdate) == iPhysicalAddress)
- device = m_busDevices[iPtr];
- }
-
- return device;