X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2FCECClient.cpp;h=accd5659fe9427d1cb9612da836208dcf8fada14;hb=dc6366e81f1ad7bad55b9ebeeb65937d7ed1c256;hp=6fe35d6d87bdbb298b3ebbed4608af38b3374807;hpb=0d800fe507054f9fc752ba70e5a9c14d95dcb87f;p=deb_libcec.git diff --git a/src/lib/CECClient.cpp b/src/lib/CECClient.cpp index 6fe35d6..accd565 100644 --- a/src/lib/CECClient.cpp +++ b/src/lib/CECClient.cpp @@ -37,6 +37,7 @@ #include "devices/CECPlaybackDevice.h" #include "devices/CECAudioSystem.h" #include "devices/CECTV.h" +#include "implementations/CECCommandHandler.h" using namespace CEC; using namespace PLATFORM; @@ -120,9 +121,6 @@ bool CCECClient::OnRegister(void) // set the physical address SetPhysicalAddress(m_configuration); - // ensure that we know the vendor id of the TV, so we are using the correct handler - m_processor->GetTV()->GetVendorId(GetPrimaryLogicalAdddress()); - // make the primary device the active source if the option is set if (m_configuration.bActivateSource == 1) GetPrimaryDevice()->ActivateSource(); @@ -195,15 +193,19 @@ void CCECClient::ResetPhysicalAddress(void) void CCECClient::SetPhysicalAddress(const libcec_configuration &configuration) { - // try to autodetect the address bool bPASet(false); - if (m_processor->CECInitialised() && configuration.bAutodetectAddress == 1) - bPASet = AutodetectPhysicalAddress(); - // try to use physical address setting + // override the physical address from configuration.iPhysicalAddress if it's set if (!bPASet && CLibCEC::IsValidPhysicalAddress(configuration.iPhysicalAddress)) bPASet = SetPhysicalAddress(configuration.iPhysicalAddress); + // try to autodetect the address + if (!bPASet && m_processor->CECInitialised()) + { + bPASet = AutodetectPhysicalAddress(); + m_configuration.bAutodetectAddress = bPASet ? 1 : 0; + } + // use the base device + hdmi port settings if (!bPASet) bPASet = SetHDMIPort(configuration.baseDevice, configuration.iHDMIPort); @@ -246,11 +248,41 @@ bool CCECClient::SetPhysicalAddress(const uint16_t iPhysicalAddress) return true; } +void CCECClient::SetSupportedDeviceTypes(void) +{ + cec_device_type_list types; + types.Clear(); + + // get the command handler for the tv + CCECCommandHandler *tvHandler = m_processor->GetTV()->GetHandler(); + if (!tvHandler) + return; + + // check all device types + for (uint8_t iPtr = 0; iPtr < 5; iPtr++) + { + if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED) + continue; + + // get the supported device type. the handler will replace types it doesn't support by one it does support + cec_device_type type = tvHandler->GetReplacementDeviceType(m_configuration.deviceTypes.types[iPtr]); + if (!types.IsSet(type)) + types.Add(type); + } + m_processor->GetTV()->MarkHandlerReady(); + + // set the new type list + m_configuration.deviceTypes = types; +} + bool CCECClient::AllocateLogicalAddresses(void) { // reset all previous LAs that were set m_configuration.logicalAddresses.Clear(); + // get the supported device types from the command handler of the TV + SetSupportedDeviceTypes(); + // display an error if no device types are set if (m_configuration.deviceTypes.IsEmpty()) { @@ -874,6 +906,30 @@ int CCECClient::MenuStateChanged(const cec_menu_state newState) return 0; } +void CCECClient::SourceActivated(const cec_logical_address logicalAddress) +{ + CLockObject lock(m_mutex); + + LIB_CEC->AddLog(CEC_LOG_NOTICE, ">> source activated: %s (%x)", ToString(logicalAddress), logicalAddress); + + if (m_configuration.callbacks && + m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_7_1 && + m_configuration.callbacks->CBCecSourceActivated) + m_configuration.callbacks->CBCecSourceActivated(m_configuration.callbackParam, logicalAddress, 1); +} + +void CCECClient::SourceDeactivated(const cec_logical_address logicalAddress) +{ + CLockObject lock(m_mutex); + + LIB_CEC->AddLog(CEC_LOG_NOTICE, ">> source deactivated: %s (%x)", ToString(logicalAddress), logicalAddress); + + if (m_configuration.callbacks && + m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_7_1 && + m_configuration.callbacks->CBCecSourceActivated) + m_configuration.callbacks->CBCecSourceActivated(m_configuration.callbackParam, logicalAddress, 0); +} + void CCECClient::Alert(const libcec_alert type, const libcec_parameter ¶m) { CLockObject lock(m_mutex); @@ -1141,7 +1197,10 @@ cec_device_type_list CCECClient::GetDeviceTypes(void) bool CCECClient::SetDevicePhysicalAddress(const uint16_t iPhysicalAddress) { if (!CLibCEC::IsValidPhysicalAddress(iPhysicalAddress)) + { + LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - not setting invalid physical address %04x", __FUNCTION__, iPhysicalAddress); return false; + } // reconfigure all devices cec_logical_address reactivateSource(CECDEVICE_UNKNOWN);