+
+void CCECProcessor::HandlePoll(cec_logical_address initiator, cec_logical_address destination)
+{
+ if (destination < CECDEVICE_BROADCAST)
+ m_busDevices[destination]->HandlePollFrom(initiator);
+}
+
+bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator)
+{
+ return !m_busDevices[initiator]->HandleReceiveFailed();
+}
+
+bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress)
+{
+ // stream path changes are sent by the TV
+ return m_busDevices[CECDEVICE_TV]->GetHandler()->TransmitSetStreamPath(iPhysicalAddress);
+}
+
+bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration)
+{
+ bool bReinit(false);
+ CCECBusDevice *primary = IsRunning() ? GetPrimaryDevice() : NULL;
+ cec_device_type oldPrimaryType = primary ? primary->GetType() : CEC_DEVICE_TYPE_RECORDING_DEVICE;
+ m_configuration.clientVersion = configuration->clientVersion;
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using client version '%s'", __FUNCTION__, ToString((cec_client_version)configuration->clientVersion));
+
+ // client version 1.5.0
+
+ // device types
+ bool bDeviceTypeChanged = IsRunning () && m_configuration.deviceTypes != configuration->deviceTypes;
+ m_configuration.deviceTypes = configuration->deviceTypes;
+ if (bDeviceTypeChanged)
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using primary device type '%s'", __FUNCTION__, ToString(configuration->deviceTypes[0]));
+
+ bool bPhysicalAddressChanged(false);
+
+ // autodetect address
+ bool bPhysicalAutodetected(false);
+ if (IsRunning() && configuration->bAutodetectAddress == 1)
+ {
+ uint16_t iPhysicalAddress = m_communication->GetPhysicalAddress();
+ if (iPhysicalAddress != 0)
+ {
+ if (IsRunning())
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - autodetected physical address '%4x'", __FUNCTION__, iPhysicalAddress);
+ else
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using physical address '%x'", __FUNCTION__, iPhysicalAddress);
+ bPhysicalAddressChanged = (m_configuration.iPhysicalAddress != iPhysicalAddress);
+ m_configuration.iPhysicalAddress = iPhysicalAddress;
+ m_configuration.iHDMIPort = 0;
+ m_configuration.baseDevice = CECDEVICE_UNKNOWN;
+ bPhysicalAutodetected = true;
+ }
+ }
+
+ // physical address
+ if (!bPhysicalAutodetected)
+ {
+ if (configuration->iPhysicalAddress != 0)
+ bPhysicalAddressChanged = IsRunning() && m_configuration.iPhysicalAddress != configuration->iPhysicalAddress;
+ if (bPhysicalAddressChanged)
+ {
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - physical address '%x'", __FUNCTION__, configuration->iPhysicalAddress);
+ m_configuration.iPhysicalAddress = configuration->iPhysicalAddress;
+ }
+ }
+
+ bool bHdmiPortChanged(false);
+ if (!bPhysicalAutodetected && !bPhysicalAddressChanged)
+ {
+ // base device
+ bHdmiPortChanged = IsRunning() && m_configuration.baseDevice != configuration->baseDevice;
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using base device '%x'", __FUNCTION__, (int)configuration->baseDevice);
+ m_configuration.baseDevice = configuration->baseDevice;
+
+ // hdmi port
+ bHdmiPortChanged |= IsRunning() && m_configuration.iHDMIPort != configuration->iHDMIPort;
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using HDMI port '%d'", __FUNCTION__, configuration->iHDMIPort);
+ m_configuration.iHDMIPort = configuration->iHDMIPort;
+ }
+ else
+ {
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - resetting HDMI port and base device to defaults", __FUNCTION__);
+ m_configuration.baseDevice = CECDEVICE_UNKNOWN;
+ m_configuration.iHDMIPort = 0;
+ }
+
+ bReinit = bPhysicalAddressChanged || bHdmiPortChanged || bDeviceTypeChanged;
+
+ // device name
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using OSD name '%s'", __FUNCTION__, configuration->strDeviceName);
+ snprintf(m_configuration.strDeviceName, 13, "%s", configuration->strDeviceName);
+ if (primary && !primary->GetOSDName().Equals(m_configuration.strDeviceName))
+ {
+ primary->SetOSDName(m_configuration.strDeviceName);
+ if (!bReinit && IsRunning())
+ primary->TransmitOSDName(CECDEVICE_TV);
+ }
+
+ // tv vendor id override
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - vendor id '%s'", __FUNCTION__, ToString((cec_vendor_id)configuration->tvVendor));
+ if (m_configuration.tvVendor != configuration->tvVendor)
+ {
+ m_configuration.tvVendor= configuration->tvVendor;
+ m_busDevices[CECDEVICE_TV]->SetVendorId((uint64_t)m_configuration.tvVendor);
+ }
+
+ // wake CEC devices
+ if (m_configuration.wakeDevices != configuration->wakeDevices)
+ {
+ m_configuration.wakeDevices = configuration->wakeDevices;
+ if (!bReinit && IsRunning())
+ PowerOnDevices();
+ }
+
+ // just copy these
+ m_configuration.bUseTVMenuLanguage = configuration->bUseTVMenuLanguage;
+ m_configuration.bActivateSource = configuration->bActivateSource;
+ m_configuration.bGetSettingsFromROM = configuration->bGetSettingsFromROM;
+ m_configuration.powerOffDevices = configuration->powerOffDevices;
+ m_configuration.bPowerOffScreensaver = configuration->bPowerOffScreensaver;
+ m_configuration.bPowerOffOnStandby = configuration->bPowerOffOnStandby;
+
+ // client version 1.5.1
+ if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_5_1)
+ m_configuration.bSendInactiveSource = configuration->bSendInactiveSource;
+
+ // client version 1.6.0
+ if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_6_0)
+ {
+ m_configuration.bPowerOffDevicesOnStandby = configuration->bPowerOffDevicesOnStandby;
+ m_configuration.bShutdownOnStandby = configuration->bShutdownOnStandby;
+ }
+
+ // client version 1.6.2
+ if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_6_2)
+ {
+ memcpy(m_configuration.strDeviceLanguage, configuration->strDeviceLanguage, 3);
+ }
+
+ // ensure that there is at least 1 device type set
+ if (m_configuration.deviceTypes.IsEmpty())
+ m_configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
+
+ // persist the configuration
+ if (IsRunning())
+ m_communication->PersistConfiguration(&m_configuration);
+
+ if (bReinit || m_configuration.logicalAddresses.IsEmpty())
+ {
+ if (bDeviceTypeChanged)
+ return ChangeDeviceType(oldPrimaryType, m_configuration.deviceTypes[0]);
+ else if (bPhysicalAddressChanged)
+ return SetPhysicalAddress(m_configuration.iPhysicalAddress);
+ else
+ return SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort);
+ }
+ else if (m_configuration.bActivateSource == 1 && IsRunning() && !IsActiveSource(m_configuration.logicalAddresses.primary))
+ {
+ // activate the source if we're not already the active source
+ SetActiveSource(m_configuration.deviceTypes.types[0]);
+ }
+
+ return true;
+}
+
+bool CCECProcessor::GetCurrentConfiguration(libcec_configuration *configuration)
+{
+ // client version 1.5.0
+ snprintf(configuration->strDeviceName, 13, "%s", m_configuration.strDeviceName);
+ configuration->deviceTypes = m_configuration.deviceTypes;
+ configuration->bAutodetectAddress = m_configuration.bAutodetectAddress;
+ configuration->iPhysicalAddress = m_configuration.iPhysicalAddress;
+ configuration->baseDevice = m_configuration.baseDevice;
+ configuration->iHDMIPort = m_configuration.iHDMIPort;
+ configuration->clientVersion = m_configuration.clientVersion;
+ configuration->serverVersion = m_configuration.serverVersion;
+ configuration->tvVendor = m_configuration.tvVendor;
+
+ configuration->bGetSettingsFromROM = m_configuration.bGetSettingsFromROM;
+ configuration->bUseTVMenuLanguage = m_configuration.bUseTVMenuLanguage;
+ configuration->bActivateSource = m_configuration.bActivateSource;
+ configuration->wakeDevices = m_configuration.wakeDevices;
+ configuration->powerOffDevices = m_configuration.powerOffDevices;
+ configuration->bPowerOffScreensaver = m_configuration.bPowerOffScreensaver;
+ configuration->bPowerOffOnStandby = m_configuration.bPowerOffOnStandby;
+
+ // client version 1.5.1
+ if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_5_1)
+ configuration->bSendInactiveSource = m_configuration.bSendInactiveSource;
+
+ // client version 1.5.3
+ if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_5_3)
+ configuration->logicalAddresses = m_configuration.logicalAddresses;
+
+ // client version 1.6.0
+ if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_6_0)
+ {
+ configuration->iFirmwareVersion = m_configuration.iFirmwareVersion;
+ configuration->bPowerOffDevicesOnStandby = m_configuration.bPowerOffDevicesOnStandby;
+ configuration->bShutdownOnStandby = m_configuration.bShutdownOnStandby;
+ }
+
+ // client version 1.6.2
+ if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_6_2)
+ {
+ memcpy(configuration->strDeviceLanguage, m_configuration.strDeviceLanguage, 3);
+ configuration->iFirmwareBuildDate = m_configuration.iFirmwareBuildDate;
+ }
+ return true;
+}
+
+bool CCECProcessor::CanPersistConfiguration(void)
+{
+ return m_communication ? m_communication->GetFirmwareVersion() >= 2 : false;
+}
+
+bool CCECProcessor::PersistConfiguration(libcec_configuration *configuration)
+{
+ return m_communication ? m_communication->PersistConfiguration(configuration) : false;
+}
+
+void CCECProcessor::RescanActiveDevices(void)
+{
+ for (unsigned int iPtr = 0; iPtr < CECDEVICE_BROADCAST; iPtr++)
+ m_busDevices[iPtr]->GetStatus(true);
+}
+
+bool CCECProcessor::GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs /* = 10000 */)
+{
+ if (!OpenConnection(strPort, 38400, iTimeoutMs, false))
+ return false;
+
+ config->iFirmwareVersion = m_communication->GetFirmwareVersion();
+ config->iPhysicalAddress = m_communication->GetPhysicalAddress();
+
+ delete m_communication;
+ m_communication = NULL;
+ return true;
+}
+
+bool CCECProcessor::TransmitPendingActiveSourceCommands(void)
+{
+ bool bReturn(true);
+ for (unsigned int iPtr = 0; iPtr < CECDEVICE_BROADCAST; iPtr++)
+ bReturn &= m_busDevices[iPtr]->TransmitPendingActiveSourceCommands();
+ return bReturn;
+}