X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2FCECProcessor.cpp;h=11065ebfec6e5b6bb7198986825db3f93d8c9bd9;hb=ef79edcce663c6156731ad73d63acbe0c6be85b9;hp=f8ea3bc871f9eee71c4e2fe33fd7ff753708ca52;hpb=9902f4e81052ba0260c587a4b9309e1dd4c729db;p=deb_libcec.git diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index f8ea3bc..11065eb 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -55,8 +55,7 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, cec m_strDeviceName(strDeviceName), m_controller(controller), m_bMonitor(false), - m_busScan(NULL), - m_iLineTimeout(0) + m_busScan(NULL) { m_communication = new CAdapterCommunication(this); m_logicalAddresses.Clear(); @@ -73,8 +72,7 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, con m_strDeviceName(strDeviceName), m_types(types), m_controller(controller), - m_bMonitor(false), - m_iLineTimeout(0) + m_bMonitor(false) { m_communication = new CAdapterCommunication(this); m_logicalAddresses.Clear(); @@ -156,14 +154,18 @@ bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, if (SetAckMask(m_logicalAddresses.AckMask()) && SetHDMIPort(m_iBaseDevice, m_iHDMIPort, true)) { + m_controller->AddLog(CEC_LOG_ERROR, "processor thread started"); m_busScan = new CCECBusScan(this); m_busScan->CreateThread(true); return true; } + else + { + m_controller->AddLog(CEC_LOG_ERROR, "failed to initialise the processor"); + } } - else - m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); + m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); return false; } @@ -242,27 +244,6 @@ bool CCECProcessor::FindLogicalAddresses(void) return bReturn; } -bool CCECProcessor::SetLineTimeout(uint8_t iTimeout) -{ - bool bReturn(m_iLineTimeout != iTimeout); - - if (!bReturn) - { - CCECAdapterMessage *output = new CCECAdapterMessage; - - output->push_back(MSGSTART); - output->push_escaped(MSGCODE_TRANSMIT_IDLETIME); - output->push_escaped(iTimeout); - output->push_back(MSGEND); - - if ((bReturn = Transmit(output)) == false) - m_controller->AddLog(CEC_LOG_ERROR, "could not set the idletime"); - delete output; - } - - return bReturn; -} - void *CCECProcessor::Process(void) { bool bParseFrame(false); @@ -278,6 +259,7 @@ void *CCECProcessor::Process(void) } else { + m_busDevices[m_logicalAddresses.primary]->TransmitPhysicalAddress(); CLockObject lock(&m_mutex); m_bStarted = true; m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started"); @@ -338,8 +320,17 @@ bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RE } } - return SetStreamPath(m_busDevices[addr]->GetPhysicalAddress(false)) && - m_busDevices[addr]->TransmitActiveSource(); + bReturn = m_busDevices[CECDEVICE_TV]->PowerOn() && + m_busDevices[addr]->TransmitActiveSource() && + SetStreamPath(m_busDevices[addr]->GetPhysicalAddress(false)); + + if (bReturn && (m_busDevices[addr]->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || + m_busDevices[addr]->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)) + { + bReturn = ((CCECPlaybackDevice *)m_busDevices[addr])->TransmitDeckStatus(CECDEVICE_TV); + } + + return bReturn; } bool CCECProcessor::SetActiveSource(cec_logical_address iAddress) @@ -414,7 +405,7 @@ bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, iPhysicalAddress += (uint16_t)(iPort * iPos); strLog.Format("checking physical address %4x", iPhysicalAddress); AddLog(CEC_LOG_DEBUG, strLog); - if (CheckPhysicalAddress(iPhysicalAddress)) + if (PhysicalAddressInUse(iPhysicalAddress)) { strLog.Format("physical address %4x is in use", iPhysicalAddress); AddLog(CEC_LOG_DEBUG, strLog); @@ -422,6 +413,8 @@ bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, } else { + strLog.Format("physical address %4x is free", iPhysicalAddress); + AddLog(CEC_LOG_DEBUG, strLog); SetPhysicalAddress(iPhysicalAddress); bReturn = true; } @@ -430,7 +423,7 @@ bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, return bReturn; } -bool CCECProcessor::CheckPhysicalAddress(uint16_t iPhysicalAddress) +bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress) { for (unsigned int iPtr = 0; iPtr < 15; iPtr++) { @@ -681,12 +674,12 @@ bool CCECProcessor::Transmit(CCECAdapterMessage *output) bool bReturn(false); CLockObject lock(&m_mutex); { - SetLineTimeout(3); + m_communication->SetLineTimeout(3); do { if (output->tries > 0) - SetLineTimeout(5); + m_communication->SetLineTimeout(5); CLockObject msgLock(&output->mutex); if (!m_communication || !m_communication->Write(output)) @@ -711,7 +704,7 @@ bool CCECProcessor::Transmit(CCECAdapterMessage *output) }while (output->transmit_timeout > 0 && output->needs_retry() && ++output->tries <= output->maxTries); } - SetLineTimeout(3); + m_communication->SetLineTimeout(3); return bReturn; } @@ -1277,19 +1270,26 @@ const char *CCECProcessor::ToString(const cec_vendor_id vendor) void *CCECBusScan::Process(void) { CCECBusDevice *device(NULL); + int iCount(0); while (!IsStopped()) { - for (unsigned int iPtr = 0; iPtr < 15 && !IsStopped(); iPtr++) + if (iCount == 0) { - device = m_processor->m_busDevices[iPtr]; - if (device && device->GetStatus() == CEC_DEVICE_STATUS_PRESENT) + for (unsigned int iPtr = 0; iPtr < 15 && !IsStopped(); iPtr++) { - if (!IsStopped()) - device->GetVendorId(); - Sleep(5); + device = m_processor->m_busDevices[iPtr]; + if (device && device->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT) + { + if (!IsStopped()) + device->GetVendorId(); + Sleep(5); + } } } - Sleep(5000); + + if (++iCount > 60) + iCount = 0; + Sleep(1000); } return NULL; }