cec_client_version clientVersion; /*!< the version of the client that is connecting */
char strDeviceName[13]; /*!< how to name the device on the CEC bus */
cec_device_type_list deviceTypes; /*!< the CEC device types to emulate */
- uint16_t iPhysicalAddress; /*!< the physical address of the CEC adapter */
- cec_logical_address baseDevice; /*!< the logical address of the device to which the adapter is connected. only used when iPhysicalAddress = 0 */
- uint8_t iHDMIPort; /*!< the HDMI port to which the adapter is connected. only used when iPhysicalAddress = 0 */
+ uint8_t bAutodetectAddress; /*!< try to autodetect the physical address when 1 */
+ uint16_t iPhysicalAddress; /*!< the physical address of the CEC adapter. only used when bAutodetectAddress = 0 or when the adapter doesn't support autodetection */
+ cec_logical_address baseDevice; /*!< the logical address of the device to which the adapter is connected. only used when iPhysicalAddress = 0 and bAutodetectAddress = 0 or when the adapter doesn't support autodetection */
+ uint8_t iHDMIPort; /*!< the HDMI port to which the adapter is connected. only used when iPhysicalAddress = 0 and bAutodetectAddress = 0 or when the adapter doesn't support autodetection */
cec_vendor_id tvVendor; /*!< override the vendor ID of the TV. leave this untouched to autodetect */
cec_logical_addresses wakeDevices; /*!< wake these CEC devices when initialising libCEC or when calling PowerOnDevices() without any parameter */
cec_logical_addresses powerOffDevices; /*!< power off these devices when calling StandbyDevices() without any parameter */
wakeDevices.Clear();
powerOffDevices.Clear();
+ bAutodetectAddress = 1;
bGetSettingsFromROM = 0;
bUseTVMenuLanguage = CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE;
bActivateSource = CEC_DEFAULT_SETTING_ACTIVATE_SOURCE;
for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
config.deviceTypes.types[iPtr] = (cec_device_type)netConfig->DeviceTypes->Types[iPtr];
+ config.bAutodetectAddress = netConfig->AutodetectAddress ? 1 : 0;
config.iPhysicalAddress = netConfig->PhysicalAddress;
config.baseDevice = (cec_logical_address)netConfig->BaseDevice;
config.iHDMIPort = netConfig->HDMIPort;
config.clientVersion = (cec_client_version)netConfig->ClientVersion;
- config.bGetSettingsFromROM = netConfig->GetSettingsFromROM;
- config.bActivateSource = netConfig->ActivateSource;
+ config.bGetSettingsFromROM = netConfig->GetSettingsFromROM ? 1 : 0;
+ config.bActivateSource = netConfig->ActivateSource ? 1 : 0;
config.tvVendor = (cec_vendor_id)netConfig->TvVendor;
config.wakeDevices.Clear();
for (int iPtr = 0; iPtr < 16; iPtr++)
if (netConfig->PowerOffDevices->IsSet((CecLogicalAddress)iPtr))
config.powerOffDevices.Set((cec_logical_address)iPtr);
}
- config.bPowerOffScreensaver = netConfig->PowerOffScreensaver;
- config.bPowerOffOnStandby = netConfig->PowerOffOnStandby;
+ config.bPowerOffScreensaver = netConfig->PowerOffScreensaver ? 1 : 0;
+ config.bPowerOffOnStandby = netConfig->PowerOffOnStandby ? 1 : 0;
config.callbacks = &g_cecCallbacks;
}
}
void Close(void)
+ {
+ DisableCallbacks();
+ m_libCec->Close();
+ }
+
+ virtual void DisableCallbacks(void) override
{
// delete the callbacks, since these might already have been destroyed in .NET
CecCallbackMethods::DisableCallbacks();
- m_libCec->EnableCallbacks(NULL, NULL);
- m_libCec->StandbyDevices();
- m_libCec->Close();
+ if (m_libCec)
+ m_libCec->EnableCallbacks(NULL, NULL);
}
virtual bool EnableCallbacks(CecCallbackMethods ^ callbacks) override
if (m_libCec->GetCurrentConfiguration(&config))
{
+ configuration->AutodetectAddress = config.bAutodetectAddress == 1;
configuration->BaseDevice = (CecLogicalAddress)config.baseDevice;
configuration->DeviceName = gcnew String(config.strDeviceName);
configuration->HDMIPort = config.iHDMIPort;
else if (m_configuration.iPhysicalAddress == 0 && (bReturn = SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort, true)) == false)
CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set HDMI port %d on %s (%x)", m_configuration.iHDMIPort, ToString(m_configuration.baseDevice), (uint8_t)m_configuration.baseDevice);
- PowerOnDevices();
-
SetInitialised(bReturn);
CLibCEC::ConfigurationChanged(m_configuration);
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::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, bool bForce /* = false */)
{
bool bReturn(false);
- CLockObject lock(m_mutex);
- m_configuration.baseDevice = iBaseDevice;
- m_configuration.iHDMIPort = iPort;
+ {
+ CLockObject lock(m_mutex);
+ m_configuration.baseDevice = iBaseDevice;
+ m_configuration.iHDMIPort = iPort;
+ m_configuration.bAutodetectAddress = false;
+ }
+
if (!IsRunning() && !bForce)
return true;
uint16_t iPhysicalAddress(0);
if (iBaseDevice > CECDEVICE_TV)
{
- lock.Unlock();
iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress();
- lock.Lock();
}
if (iPhysicalAddress < 0xffff)
if (!bReturn)
CLibCEC::AddLog(CEC_LOG_ERROR, "failed to set the physical address");
else
- {
- lock.Unlock();
SetPhysicalAddress(iPhysicalAddress);
- }
return bReturn;
}
{
CLockObject lock(m_mutex);
m_configuration.iPhysicalAddress = iPhysicalAddress;
+ if (m_configuration.bAutodetectAddress)
+ {
+ m_configuration.baseDevice = CECDEVICE_UNKNOWN;
+ m_configuration.iHDMIPort = 0;
+ }
if (!m_logicalAddresses.IsEmpty())
{
return m_busDevices[iDestination]->TransmitKeyRelease(bWait);
}
+bool CCECProcessor::EnablePhysicalAddressDetection(void)
+{
+ CLibCEC::AddLog(CEC_LOG_WARNING, "deprecated method %s called", __FUNCTION__);
+ uint16_t iPhysicalAddress = m_communication->GetPhysicalAddress();
+ if (iPhysicalAddress != 0)
+ {
+ m_configuration.bAutodetectAddress = 1;
+ m_configuration.iPhysicalAddress = iPhysicalAddress;
+ m_configuration.baseDevice = CECDEVICE_UNKNOWN;
+ m_configuration.iHDMIPort = 0;
+ return SetPhysicalAddress(iPhysicalAddress);
+ }
+ return false;
+}
+
bool CCECProcessor::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
{
if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0)
bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration)
{
bool bReinit(false);
- bool bPhysicalAddressChanged(false);
- bool bHdmiPortChanged(false);
- bool bDeviceTypeChanged(false);
CCECBusDevice *primary = IsRunning() ? GetPrimaryDevice() : NULL;
cec_device_type oldPrimaryType = primary ? primary->GetType() : CEC_DEVICE_TYPE_RECORDING_DEVICE;
m_configuration.clientVersion = configuration->clientVersion;
// client version 1.5.0
// device types
- bDeviceTypeChanged |= IsRunning () && m_configuration.deviceTypes != configuration->deviceTypes;
+ bool bDeviceTypeChanged = IsRunning () && m_configuration.deviceTypes != configuration->deviceTypes;
m_configuration.deviceTypes = configuration->deviceTypes;
+ // autodetect address
+ uint16_t iPhysicalAddress = IsRunning() && configuration->bAutodetectAddress ? m_communication->GetPhysicalAddress() : 0;
+ bool bPhysicalAutodetected = IsRunning() && configuration->bAutodetectAddress && iPhysicalAddress != m_configuration.iPhysicalAddress && iPhysicalAddress != 0;
+ if (bPhysicalAutodetected)
+ {
+ m_configuration.iPhysicalAddress = iPhysicalAddress;
+ m_configuration.bAutodetectAddress = true;
+ }
+ else
+ {
+ m_configuration.bAutodetectAddress = false;
+ }
+
// physical address
- bPhysicalAddressChanged |= IsRunning() && m_configuration.iPhysicalAddress != configuration->iPhysicalAddress;
- m_configuration.iPhysicalAddress = configuration->iPhysicalAddress;
+ bool bPhysicalAddressChanged(false);
+ if (!bPhysicalAutodetected)
+ {
+ bPhysicalAddressChanged = IsRunning() && m_configuration.iPhysicalAddress != configuration->iPhysicalAddress;
+ m_configuration.iPhysicalAddress = configuration->iPhysicalAddress;
+ }
// base device
- bHdmiPortChanged |= IsRunning() && m_configuration.baseDevice != configuration->baseDevice;
- m_configuration.baseDevice = configuration->baseDevice;
+ bool bHdmiPortChanged(false);
+ if (!bPhysicalAutodetected && !bPhysicalAddressChanged)
+ {
+ bHdmiPortChanged = IsRunning() && m_configuration.baseDevice != configuration->baseDevice;
+ m_configuration.baseDevice = configuration->baseDevice;
+ }
+ else
+ {
+ m_configuration.baseDevice = CECDEVICE_UNKNOWN;
+ }
// hdmi port
- bHdmiPortChanged |= IsRunning() && m_configuration.iHDMIPort != configuration->iHDMIPort;
- m_configuration.iHDMIPort = configuration->iHDMIPort;
+ if (!bPhysicalAutodetected && !bPhysicalAddressChanged)
+ {
+ bHdmiPortChanged |= IsRunning() && m_configuration.iHDMIPort != configuration->iHDMIPort;
+ m_configuration.iHDMIPort = configuration->iHDMIPort;
+ }
+ else
+ {
+ m_configuration.iHDMIPort = 0;
+ }
- bReinit = bPhysicalAddressChanged || bHdmiPortChanged || bDeviceTypeChanged;
+ bReinit = bPhysicalAddressChanged || bHdmiPortChanged || bDeviceTypeChanged || bPhysicalAutodetected;
// device name
snprintf(m_configuration.strDeviceName, 13, "%s", configuration->strDeviceName);
return ChangeDeviceType(oldPrimaryType, m_configuration.deviceTypes[0]);
else if (bPhysicalAddressChanged)
return SetPhysicalAddress(m_configuration.iPhysicalAddress);
- else
+ else
return SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort);
}
configuration->clientVersion = m_configuration.clientVersion;
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;