From: Lars Op den Kamp Date: Wed, 14 Nov 2012 00:08:04 +0000 (+0100) Subject: ensure that we only send 'image view on' when needed X-Git-Tag: upstream/2.2.0~1^2~12^2~25 X-Git-Url: https://git.piment-noir.org/?p=deb_libcec.git;a=commitdiff_plain;h=14f5626891e260b5294a9d4cb73988ed11a41443 ensure that we only send 'image view on' when needed --- diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index bfb546f..0bd6dab 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -75,7 +75,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); @@ -613,9 +614,11 @@ void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus) } } -void CCECBusDevice::ImageViewOnSent(void) +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(); @@ -624,6 +627,12 @@ void CCECBusDevice::ImageViewOnSent(void) } } +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); @@ -971,6 +980,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); @@ -1059,17 +1072,26 @@ 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) - { - CCECBusDevice* tv = m_processor->GetDevice(CECDEVICE_TV); - if (tv) - tv->ImageViewOnSent(); - } + tv->OnImageViewOnSent(true); return bImageViewOnSent; } diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index e0c2f9c..d04b559 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -192,7 +192,8 @@ namespace CEC virtual cec_power_status GetCurrentPowerStatus(void); virtual cec_power_status GetPowerStatus(const cec_logical_address initiator, bool bUpdate = false); virtual void SetPowerStatus(const cec_power_status powerStatus); - virtual void ImageViewOnSent(void); + virtual void OnImageViewOnSent(bool bSentByLibCEC); + virtual bool ImageViewOnSent(void); virtual bool RequestPowerStatus(const cec_logical_address initiator, bool bWaitForResponse = true); virtual bool TransmitPowerState(const cec_logical_address destination, bool bIsReply); @@ -280,5 +281,6 @@ namespace CEC bool m_bAwaitingReceiveFailed; bool m_bVendorIdRequested; CWaitForResponse *m_waitForResponse; + bool m_bImageViewOnSent; }; }; diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index 5a2afb1..d1af939 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -385,12 +385,14 @@ int CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &comma int CCECCommandHandler::HandleImageViewOn(const cec_command &command) { CCECBusDevice *device = GetDevice(command.destination); - if (device && (device->GetCurrentStatus() == CEC_DEVICE_STATUS_PRESENT || - device->GetCurrentStatus() == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC)) + if (device && device->GetCurrentStatus() == CEC_DEVICE_STATUS_PRESENT) { if (device->GetCurrentPowerStatus() == CEC_POWER_STATUS_STANDBY || device->GetCurrentPowerStatus() == CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY) device->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); + CCECBusDevice* tv = GetDevice(CECDEVICE_TV); + if (tv) + tv->OnImageViewOnSent(false); } return COMMAND_HANDLED; } @@ -1181,10 +1183,7 @@ bool CCECCommandHandler::ActivateSource(bool bTransmitDelayedCommandsOnly /* = f bool bTvPresent = (tv && tv->GetStatus() == CEC_DEVICE_STATUS_PRESENT); bool bActiveSourceFailed(false); if (bTvPresent) - { - if (tv->GetCurrentPowerStatus() != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON) - bActiveSourceFailed = !m_busDevice->TransmitImageViewOn(); - } + bActiveSourceFailed = !m_busDevice->TransmitImageViewOn(); else LIB_CEC->AddLog(CEC_LOG_DEBUG, "TV not present, not sending 'image view on'");