X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fdevices%2FCECBusDevice.cpp;h=de75db5760b7e3bff8f3c365cc08ecdc07c8b7cf;hb=0c271bd0fc05728d0dd90065a064737a979f50d3;hp=5fe6d4dd26ee0060267dfd90880b2ad123a00947;hpb=844eab4ec63477613b4ec5747e6994521108d4b3;p=deb_libcec.git diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 5fe6d4d..de75db5 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -39,6 +39,7 @@ #include "lib/implementations/CECCommandHandler.h" #include "lib/implementations/SLCommandHandler.h" #include "lib/implementations/VLCommandHandler.h" +#include "lib/implementations/PHCommandHandler.h" #include "lib/LibCEC.h" #include "lib/CECTypeUtils.h" #include "lib/platform/util/timeutils.h" @@ -75,7 +76,8 @@ CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogi m_iHandlerUseCount (0), m_bAwaitingReceiveFailed(false), m_bVendorIdRequested (false), - m_waitForResponse (new CWaitForResponse) + m_waitForResponse (new CWaitForResponse), + m_bImageViewOnSent (false) { m_handler = new CCECCommandHandler(this); @@ -131,6 +133,9 @@ bool CCECBusDevice::ReplaceHandler(bool bActivateSource /* = true */) case CEC_VENDOR_PANASONIC: m_handler = new CVLCommandHandler(this, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending); break; + case CEC_VENDOR_PHILIPS: + m_handler = new CPHCommandHandler(this, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending); + break; default: m_handler = new CCECCommandHandler(this, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending); break; @@ -610,6 +615,25 @@ void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus) } } +void CCECBusDevice::OnImageViewOnSent(bool bSentByLibCEC) +{ + CLockObject lock(m_mutex); + m_bImageViewOnSent = bSentByLibCEC; + + if (m_powerStatus != CEC_POWER_STATUS_ON && m_powerStatus != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON) + { + 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(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON)); + m_powerStatus = CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON; + } +} + +bool CCECBusDevice::ImageViewOnSent(void) +{ + CLockObject lock(m_mutex); + return m_bImageViewOnSent; +} + bool CCECBusDevice::RequestPowerStatus(const cec_logical_address initiator, bool bWaitForResponse /* = true */) { bool bReturn(false); @@ -619,6 +643,8 @@ bool CCECBusDevice::RequestPowerStatus(const cec_logical_address initiator, bool { MarkBusy(); bReturn = m_handler->TransmitRequestPowerStatus(initiator, m_iLogicalAddress, bWaitForResponse); + if (!bReturn) + SetPowerStatus(CEC_POWER_STATUS_UNKNOWN); MarkReady(); } return bReturn; @@ -740,8 +766,13 @@ cec_bus_device_status CCECBusDevice::GetStatus(bool bForcePoll /* = false */, bo CLockObject lock(m_mutex); status = m_deviceStatus; bNeedsPoll = !bSuppressPoll && - (bForcePoll || m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN) && - m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC; + m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC && + // poll forced + (bForcePoll || + // don't know the status + m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN || + // always poll the TV if it's marked as not present + (m_deviceStatus == CEC_DEVICE_STATUS_NOT_PRESENT && m_iLogicalAddress == CECDEVICE_TV)); } if (bNeedsPoll) @@ -788,7 +819,7 @@ void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus, cec_v if (m_deviceStatus != newStatus) { LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): device status changed into 'not present'", GetLogicalAddressName(), m_iLogicalAddress); - ResetDeviceStatus(); + ResetDeviceStatus(true); m_deviceStatus = newStatus; } break; @@ -799,7 +830,7 @@ void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus, cec_v } } -void CCECBusDevice::ResetDeviceStatus(void) +void CCECBusDevice::ResetDeviceStatus(bool bClientUnregistered /* = false */) { CLockObject lock(m_mutex); SetPowerStatus (CEC_POWER_STATUS_UNKNOWN); @@ -808,7 +839,7 @@ void CCECBusDevice::ResetDeviceStatus(void) SetCecVersion (CEC_VERSION_UNKNOWN); SetStreamPath (CEC_INVALID_PHYSICAL_ADDRESS); SetOSDName (ToString(m_iLogicalAddress)); - MarkAsInactiveSource(); + MarkAsInactiveSource(bClientUnregistered); m_iLastActive = 0; m_bVendorIdRequested = false; @@ -952,6 +983,10 @@ void CCECBusDevice::MarkAsActiveSource(void) m_bActiveSource = true; } + CCECBusDevice* tv = m_processor->GetDevice(CECDEVICE_TV); + if (tv) + tv->OnImageViewOnSent(false); + // mark other devices as inactive sources CECDEVICEVEC devices; m_processor->GetDevices()->Get(devices); @@ -961,13 +996,15 @@ void CCECBusDevice::MarkAsActiveSource(void) if (bWasActivated) { + if (IsHandledByLibCEC()) + m_processor->SetActiveSource(true, false); CCECClient *client = GetClient(); if (client) client->SourceActivated(m_iLogicalAddress); } } -void CCECBusDevice::MarkAsInactiveSource(void) +void CCECBusDevice::MarkAsInactiveSource(bool bClientUnregistered /* = false */) { bool bWasDeactivated(false); { @@ -982,6 +1019,8 @@ void CCECBusDevice::MarkAsInactiveSource(void) if (bWasDeactivated) { + if (IsHandledByLibCEC()) + m_processor->SetActiveSource(false, bClientUnregistered); CCECClient *client = GetClient(); if (client) client->SourceDeactivated(m_iLogicalAddress); @@ -1036,10 +1075,27 @@ bool CCECBusDevice::TransmitImageViewOn(void) } } + CCECBusDevice* tv = m_processor->GetDevice(CECDEVICE_TV); + if (!tv) + { + LIB_CEC->AddLog(CEC_LOG_ERROR, "%s - couldn't get TV instance", __FUNCTION__); + return false; + } + + if (tv->ImageViewOnSent()) + { + LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - 'image view on' already sent", __FUNCTION__); + return true; + } + bool bImageViewOnSent(false); MarkBusy(); bImageViewOnSent = m_handler->TransmitImageViewOn(m_iLogicalAddress, CECDEVICE_TV); MarkReady(); + + if (bImageViewOnSent) + tv->OnImageViewOnSent(true); + return bImageViewOnSent; } @@ -1068,6 +1124,8 @@ bool CCECBusDevice::TransmitPendingActiveSourceCommands(void) void CCECBusDevice::SetActiveRoute(uint16_t iRoute) { + SetPowerStatus(CEC_POWER_STATUS_ON); + CCECDeviceMap* map = m_processor->GetDevices(); if (!map) return; @@ -1081,13 +1139,18 @@ void CCECBusDevice::SetActiveRoute(uint16_t iRoute) for (CECDEVICEVEC::iterator it = devices.begin(); it != devices.end(); it++) { - if (!CCECTypeUtils::PhysicalAddressIsIncluded(iRoute, (*it)->GetCurrentPhysicalAddress())) + if ((*it)->GetCurrentPhysicalAddress() == iRoute && (*it)->IsHandledByLibCEC()) + (*it)->ActivateSource(); + else if (!CCECTypeUtils::PhysicalAddressIsIncluded(iRoute, (*it)->GetCurrentPhysicalAddress())) (*it)->MarkAsInactiveSource(); } } void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = CEC_INVALID_PHYSICAL_ADDRESS */) { + if (iNewAddress != CEC_INVALID_PHYSICAL_ADDRESS) + SetPowerStatus(CEC_POWER_STATUS_ON); + CLockObject lock(m_mutex); if (iNewAddress != m_iStreamPath) {