X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fdevices%2FCECBusDevice.cpp;h=8f966a233194dd748e76a1a43c1b85263ca1a225;hb=75060af4927b7e412634756bb1ec952a25fab772;hp=a0d20a8a43d5ebfab551715993734b9e9e033438;hpb=99aeafb929fa132a096c236c4ae1eb78c2a595ec;p=deb_libcec.git diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index a0d20a8..8f966a2 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -37,7 +37,9 @@ #include "../implementations/SLCommandHandler.h" #include "../implementations/VLCommandHandler.h" #include "../LibCEC.h" +#include "../CECTypeUtils.h" #include "../platform/util/timeutils.h" +#include "../platform/util/util.h" #include "CECAudioSystem.h" #include "CECPlaybackDevice.h" @@ -50,7 +52,7 @@ using namespace CEC; using namespace PLATFORM; #define LIB_CEC m_processor->GetLib() -#define ToString(p) LIB_CEC->ToString(p) +#define ToString(p) CCECTypeUtils::ToString(p) CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress /* = CEC_INVALID_PHYSICAL_ADDRESS */) : m_type (CEC_DEVICE_TYPE_RESERVED), @@ -83,7 +85,7 @@ CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogi CCECBusDevice::~CCECBusDevice(void) { - delete m_handler; + DELETE_AND_NULL(m_handler); } bool CCECBusDevice::ReplaceHandler(bool bActivateSource /* = true */) @@ -105,7 +107,7 @@ bool CCECBusDevice::ReplaceHandler(bool bActivateSource /* = true */) if (CCECCommandHandler::HasSpecificHandler(m_vendor)) { LIB_CEC->AddLog(CEC_LOG_DEBUG, "replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress()); - delete m_handler; + DELETE_AND_NULL(m_handler); switch (m_vendor) { @@ -131,10 +133,14 @@ bool CCECBusDevice::ReplaceHandler(bool bActivateSource /* = true */) if (bInitHandler) { - m_handler->InitHandler(); + CCECBusDevice *primary = GetProcessor()->GetPrimaryDevice(); + if (primary->GetLogicalAddress() != CECDEVICE_UNREGISTERED) + { + m_handler->InitHandler(); - if (bActivateSource && IsHandledByLibCEC() && IsActiveSource()) - m_handler->ActivateSource(); + if (bActivateSource && IsHandledByLibCEC() && IsActiveSource()) + m_handler->ActivateSource(); + } } MarkReady(); @@ -333,7 +339,7 @@ void CCECBusDevice::SetMenuLanguage(const char *strLanguage) if (strcmp(strLanguage, m_menuLanguage.language)) { memcpy(m_menuLanguage.language, strLanguage, 3); - LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, m_menuLanguage.language); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, m_menuLanguage.language); } } @@ -404,6 +410,12 @@ bool CCECBusDevice::TransmitOSDString(const cec_logical_address destination, cec return bReturn; } +CStdString CCECBusDevice::GetCurrentOSDName(void) +{ + CLockObject lock(m_mutex); + return m_strDeviceName; +} + CStdString CCECBusDevice::GetOSDName(const cec_logical_address initiator, bool bUpdate /* = false */) { bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT); @@ -430,7 +442,7 @@ void CCECBusDevice::SetOSDName(CStdString strName) CLockObject lock(m_mutex); if (m_strDeviceName != strName) { - LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, strName.c_str()); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, strName.c_str()); m_strDeviceName = strName; } } @@ -505,7 +517,7 @@ bool CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress) CLockObject lock(m_mutex); if (iNewAddress > 0 && m_iPhysicalAddress != iNewAddress) { - LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress, iNewAddress); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress, iNewAddress); m_iPhysicalAddress = iNewAddress; } return true; @@ -580,7 +592,7 @@ void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus) if (m_powerStatus != powerStatus) { m_iLastPowerStateUpdate = GetTimeMs(); - LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_powerStatus), ToString(powerStatus)); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_powerStatus), ToString(powerStatus)); m_powerStatus = powerStatus; } } @@ -735,15 +747,9 @@ void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus) CLockObject lock(m_mutex); switch (newStatus) { - case CEC_DEVICE_STATUS_UNKNOWN: - if (m_deviceStatus != newStatus) - LIB_CEC->AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'unknown'", ToString(m_iLogicalAddress)); - ResetDeviceStatus(); - m_deviceStatus = newStatus; - break; case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC: if (m_deviceStatus != newStatus) - LIB_CEC->AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'handled by libCEC'", ToString(m_iLogicalAddress)); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): device status changed into 'handled by libCEC'", GetLogicalAddressName(), m_iLogicalAddress); SetPowerStatus (CEC_POWER_STATUS_ON); SetVendorId (CEC_VENDOR_UNKNOWN); SetMenuState (CEC_MENU_STATE_ACTIVATED); @@ -755,17 +761,20 @@ void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus) break; case CEC_DEVICE_STATUS_PRESENT: if (m_deviceStatus != newStatus) - LIB_CEC->AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'present'", ToString(m_iLogicalAddress)); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): device status changed into 'present'", GetLogicalAddressName(), m_iLogicalAddress); m_deviceStatus = newStatus; break; case CEC_DEVICE_STATUS_NOT_PRESENT: if (m_deviceStatus != newStatus) { - LIB_CEC->AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'not present'", ToString(m_iLogicalAddress)); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): device status changed into 'not present'", GetLogicalAddressName(), m_iLogicalAddress); ResetDeviceStatus(); m_deviceStatus = newStatus; } break; + default: + ResetDeviceStatus(); + break; } } } @@ -780,9 +789,14 @@ void CCECBusDevice::ResetDeviceStatus(void) SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS); SetOSDName (ToString(m_iLogicalAddress)); MarkAsInactiveSource(); + m_iLastActive = 0; m_bVendorIdRequested = false; m_unsupportedFeatures.clear(); + + if (m_deviceStatus != CEC_DEVICE_STATUS_UNKNOWN) + LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): device status changed into 'unknown'", GetLogicalAddressName(), m_iLogicalAddress); + m_deviceStatus = CEC_DEVICE_STATUS_UNKNOWN; } bool CCECBusDevice::TransmitPoll(const cec_logical_address dest) @@ -848,7 +862,7 @@ void CCECBusDevice::SetMenuState(const cec_menu_state state) CLockObject lock(m_mutex); if (m_menuState != state) { - LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_menuState)); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_menuState)); m_menuState = state; } } @@ -938,15 +952,15 @@ bool CCECBusDevice::TransmitActiveSource(void) LIB_CEC->AddLog(CEC_LOG_DEBUG, "<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress); } + bool bActiveSourceSent(false); if (bSendActiveSource) { MarkBusy(); - m_handler->TransmitActiveSource(m_iLogicalAddress, m_iPhysicalAddress); + bActiveSourceSent = m_handler->TransmitActiveSource(m_iLogicalAddress, m_iPhysicalAddress); MarkReady(); - return true; } - return false; + return bActiveSourceSent; } bool CCECBusDevice::TransmitImageViewOn(void) @@ -960,10 +974,11 @@ bool CCECBusDevice::TransmitImageViewOn(void) } } + bool bImageViewOnSent(false); MarkBusy(); - m_handler->TransmitImageViewOn(m_iLogicalAddress, CECDEVICE_TV); + bImageViewOnSent = m_handler->TransmitImageViewOn(m_iLogicalAddress, CECDEVICE_TV); MarkReady(); - return true; + return bImageViewOnSent; } bool CCECBusDevice::TransmitInactiveSource(void) @@ -994,7 +1009,7 @@ void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* CLockObject lock(m_mutex); if (iNewAddress != m_iStreamPath) { - LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, iOldAddress == 0 ? m_iStreamPath : iOldAddress, iNewAddress); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, iOldAddress == 0 ? m_iStreamPath : iOldAddress, iNewAddress); m_iStreamPath = iNewAddress; }