X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2FCECProcessor.cpp;h=78d24360b6da344ed7471379b9e7b96ee097c118;hb=f42d3e0fb1f63456b87232019d9cce731acad640;hp=faa8d8c27cdf182682903b46748615f5473279f8;hpb=8e57f83c5cc5b448024c9e2c9bf8f2d93b78c756;p=deb_libcec.git diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index faa8d8c..78d2436 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -146,51 +146,28 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint uint64_t iNow = GetTimeMs(); uint64_t iTarget = iTimeoutMs > 0 ? iNow + iTimeoutMs : iNow + CEC_DEFAULT_TRANSMIT_WAIT; - unsigned iConnectTry(0), iPingTry(0), iFwVersionTry(0), iControlledTry(0); - bool bConnected(false), bPinged(false), bControlled(false); /* open a new connection */ - while (iNow < iTarget && (bConnected = m_communication->Open(iTimeoutMs)) == false) + unsigned iConnectTry(0); + while (iNow < iTarget && (bReturn = m_communication->Open(this, iTimeoutMs)) == false) { CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry); Sleep(500); iNow = GetTimeMs(); } - /* try to ping the adapter */ - while (bConnected && iNow < iTarget && (bPinged = m_communication->PingAdapter()) == false) - { - CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter did not respond correctly to a ping (try %d)", ++iPingTry); - Sleep(500); - iNow = GetTimeMs(); - } - - /* try to read the firmware version */ - uint16_t iFirmwareVersion(CEC_FW_VERSION_UNKNOWN); - while (bPinged && iNow < iTarget && (iFirmwareVersion = m_communication->GetFirmwareVersion()) == CEC_FW_VERSION_UNKNOWN) - { - CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter did not respond with a correct firmware version (try %d)", ++iFwVersionTry); - Sleep(500); - iNow = GetTimeMs(); - } - - if (iFirmwareVersion >= 2) - { - /* try to set controlled mode */ - while (bConnected && iNow < iTarget && (bControlled = m_communication->SetControlledMode(true)) == false) - { - CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter did not respond correctly to setting controlled mode (try %d)", ++iControlledTry); - Sleep(500); - iNow = GetTimeMs(); - } - } - - if ((bReturn = iFirmwareVersion != CEC_FW_VERSION_UNKNOWN) == true) - CLibCEC::AddLog(CEC_LOG_NOTICE, "connected to the CEC adapter. firmware version = %d", iFirmwareVersion); + if (bReturn) + CLibCEC::AddLog(CEC_LOG_NOTICE, "connected to the CEC adapter. firmware version = %d", m_communication->GetFirmwareVersion()); return bReturn; } +bool CCECProcessor::IsInitialised(void) +{ + CLockObject lock(m_mutex); + return m_bInitialised; +} + void CCECProcessor::SetInitialised(bool bSetTo /* = true */) { CLockObject lock(m_mutex); @@ -406,36 +383,32 @@ bool CCECProcessor::FindLogicalAddresses(void) void CCECProcessor::ReplaceHandlers(void) { + CLockObject lock(m_mutex); + if (!IsInitialised()) + return; for (uint8_t iPtr = 0; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++) m_busDevices[iPtr]->ReplaceHandler(m_bInitialised); } +bool CCECProcessor::OnCommandReceived(const cec_command &command) +{ + m_commandBuffer.Push(command); + return true; +} + void *CCECProcessor::Process(void) { - bool bParseCommand(false); cec_command command; CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started"); - while (!IsStopped()) + while (!IsStopped() && m_communication->IsOpen()) { ReplaceHandlers(); - command.Clear(); - - { - CLockObject lock(m_mutex); - if (m_commandBuffer.Pop(command)) - bParseCommand = true; - else if (m_communication->IsOpen() && m_communication->Read(command, 50)) - bParseCommand = true; - } - - if (bParseCommand) + if (m_commandBuffer.Pop(command)) ParseCommand(command); - bParseCommand = false; - - Sleep(5); m_controller->CheckKeypressTimeout(); + Sleep(5); } if (m_communication) @@ -664,6 +637,7 @@ bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress, bool bSendUpda bool bSendActiveView(false); bool bReturn(false); cec_logical_addresses sendUpdatesTo; + sendUpdatesTo.Clear(); { CLockObject lock(m_mutex); @@ -888,7 +862,7 @@ void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode Transmit(command); } -void CCECProcessor::ParseCommand(cec_command &command) +void CCECProcessor::ParseCommand(const cec_command &command) { CStdString dataStr; dataStr.Format(">> %1x%1x:%02x", command.initiator, command.destination, command.opcode); @@ -1351,10 +1325,16 @@ bool CCECProcessor::PingAdapter(void) void CCECProcessor::HandlePoll(cec_logical_address initiator, cec_logical_address destination) { - m_busDevices[initiator]->GetHandler()->HandlePoll(initiator, destination); + m_busDevices[initiator]->HandlePoll(destination); } bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator) { - return !m_busDevices[initiator]->GetHandler()->HandleReceiveFailed(); + return !m_busDevices[initiator]->HandleReceiveFailed(); +} + +bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress) +{ + // stream path changes are sent by the TV + return m_busDevices[CECDEVICE_TV]->GetHandler()->TransmitSetStreamPath(iPhysicalAddress); }