From: Lars Op den Kamp Date: Thu, 31 May 2012 21:06:42 +0000 (+0200) Subject: cec: retry 'activate source' every 10 seconds if it failed X-Git-Tag: upstream/2.2.0~1^2~23^2^2~18 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=b0015449e4448934bbac6326d2e599d6be54d654;p=deb_libcec.git cec: retry 'activate source' every 10 seconds if it failed --- diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 11076ec..fe40990 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -51,6 +51,7 @@ using namespace std; using namespace PLATFORM; #define CEC_PROCESSOR_SIGNAL_WAIT_TIME 1000 +#define ACTIVE_SOURCE_CHECK_TIMEOUT 10000 #define ToString(x) CCECTypeUtils::ToString(x) @@ -200,6 +201,19 @@ void CCECProcessor::ReplaceHandlers(void) it->second->ReplaceHandler(true); } +void CCECProcessor::CheckPendingActiveSource(void) +{ + if (!CECInitialised()) + return; + + // check each device + for (CECDEVICEMAP::iterator it = m_busDevices->Begin(); it != m_busDevices->End(); it++) + { + if (it->second->GetHandler()->ActiveSourcePending()) + it->second->ActivateSource(); + } +} + bool CCECProcessor::OnCommandReceived(const cec_command &command) { return m_inBuffer.Push(command); @@ -210,6 +224,7 @@ void *CCECProcessor::Process(void) m_libcec->AddLog(CEC_LOG_DEBUG, "processor thread started"); cec_command command; + CTimeout activeSourceCheck(ACTIVE_SOURCE_CHECK_TIMEOUT); // as long as we're not being stopped and the connection is open while (!IsStopped() && m_communication->IsOpen()) @@ -225,6 +240,13 @@ void *CCECProcessor::Process(void) // check if we need to replace handlers ReplaceHandlers(); + + // check whether we need to activate a source, if it failed before + if (activeSourceCheck.TimeLeft() == 0) + { + CheckPendingActiveSource(); + activeSourceCheck.Init(ACTIVE_SOURCE_CHECK_TIMEOUT); + } } } diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index 5f496d2..04d84f5 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -134,6 +134,7 @@ namespace CEC void SetCECInitialised(bool bSetTo = true); void ReplaceHandlers(void); + void CheckPendingActiveSource(void); bool PhysicalAddressInUse(uint16_t iPhysicalAddress); bool SetAckMask(uint16_t iMask); diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index 6ffc4ac..3627c4e 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -56,7 +56,8 @@ CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice) : m_bHandlerInited(false), m_bOPTSendDeckStatusUpdateOnActiveSource(false), m_vendorId(CEC_VENDOR_UNKNOWN), - m_waitForResponse(new CWaitForResponse) + m_waitForResponse(new CWaitForResponse), + m_bActiveSourcePending(false) { } @@ -1056,16 +1057,27 @@ bool CCECCommandHandler::ActivateSource(void) if (m_busDevice->IsActiveSource() && m_busDevice->IsHandledByLibCEC()) { + { + CLockObject lock(m_mutex); + m_bActiveSourcePending = false; + } + m_busDevice->SetPowerStatus(CEC_POWER_STATUS_ON); m_busDevice->SetMenuState(CEC_MENU_STATE_ACTIVATED); - m_busDevice->TransmitImageViewOn(); - m_busDevice->TransmitActiveSource(); - m_busDevice->TransmitMenuState(CECDEVICE_TV); + if (!m_busDevice->TransmitImageViewOn() || + !m_busDevice->TransmitActiveSource() || + !m_busDevice->TransmitMenuState(CECDEVICE_TV)) + { + CLockObject lock(m_mutex); + m_bActiveSourcePending = true; + return false; + } CCECPlaybackDevice *playbackDevice = m_busDevice->AsPlaybackDevice(); if (playbackDevice && SendDeckStatusUpdateOnActiveSource()) playbackDevice->TransmitDeckStatus(CECDEVICE_TV); + m_bHandlerInited = true; } return true; @@ -1075,3 +1087,9 @@ void CCECCommandHandler::SignalOpcode(cec_opcode opcode) { m_waitForResponse->Received(opcode); } + +bool CCECCommandHandler::ActiveSourcePending(void) +{ + CLockObject lock(m_mutex); + return m_bActiveSourcePending; +} diff --git a/src/lib/implementations/CECCommandHandler.h b/src/lib/implementations/CECCommandHandler.h index 1bced84..6e0121f 100644 --- a/src/lib/implementations/CECCommandHandler.h +++ b/src/lib/implementations/CECCommandHandler.h @@ -162,6 +162,8 @@ namespace CEC virtual void SignalOpcode(cec_opcode opcode); + virtual bool ActiveSourcePending(void); + protected: virtual bool HandleActiveSource(const cec_command &command); virtual bool HandleDeckControl(const cec_command &command); @@ -218,5 +220,7 @@ namespace CEC bool m_bOPTSendDeckStatusUpdateOnActiveSource; cec_vendor_id m_vendorId; CWaitForResponse *m_waitForResponse; + bool m_bActiveSourcePending; + PLATFORM::CMutex m_mutex; }; };