+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 (IsValidPhysicalAddress(iPhysicalAddress))
+ {
+ if (IsRunning())
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - autodetected physical address '%04X'", __FUNCTION__, iPhysicalAddress);
+ else
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using physical address '%04X'", __FUNCTION__, iPhysicalAddress);
+ bPhysicalAddressChanged = (m_configuration.iPhysicalAddress != iPhysicalAddress);
+ m_configuration.iPhysicalAddress = iPhysicalAddress;
+ m_configuration.iHDMIPort = CEC_HDMI_PORTNUMBER_NONE;
+ m_configuration.baseDevice = CECDEVICE_UNKNOWN;
+ bPhysicalAutodetected = true;
+ }
+ }
+
+ // physical address
+ if (!bPhysicalAutodetected)
+ {
+ uint16_t iPhysicalAddress(IsValidPhysicalAddress(configuration->iPhysicalAddress) ? configuration->iPhysicalAddress : CEC_PHYSICAL_ADDRESS_TV);
+ bPhysicalAddressChanged = IsRunning() && m_configuration.iPhysicalAddress != iPhysicalAddress;
+ if (bPhysicalAddressChanged)
+ {
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - physical address '%04X'", __FUNCTION__, iPhysicalAddress);
+ m_configuration.iPhysicalAddress = iPhysicalAddress;
+ }
+ }
+
+ bool bHdmiPortChanged(false);
+ if (!bPhysicalAutodetected && !IsValidPhysicalAddress(configuration->iPhysicalAddress))
+ {
+ // 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 = CEC_HDMI_PORTNUMBER_NONE;
+ }
+
+ 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);
+
+ bool bReturn(true);
+ if (bReinit || m_configuration.logicalAddresses.IsEmpty())
+ {
+ if (bDeviceTypeChanged)
+ bReturn = ChangeDeviceType(oldPrimaryType, m_configuration.deviceTypes[0]);
+ else if (IsValidPhysicalAddress(m_configuration.iPhysicalAddress))
+ bReturn = SetPhysicalAddress(m_configuration.iPhysicalAddress);
+ else if (m_configuration.baseDevice != CECDEVICE_UNKNOWN && m_configuration.iHDMIPort != CEC_HDMI_PORTNUMBER_NONE)
+ bReturn = 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]);
+ }
+
+ // persist the configuration
+ if (IsRunning())
+ m_communication->PersistConfiguration(&m_configuration);
+
+ return bReturn;
+}
+