X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2FCECProcessor.cpp;h=b8d6d2bfb357b46538794e699449eeccd7327659;hb=7c63a480cbe63c5c6725b9558ae21acbe427ccc2;hp=8315cd297b1f66ba6d204b924351f939b7bdd6df;hpb=16b1e052e4a14432ca3bd6007e0e977ff2bed6ae;p=deb_libcec.git diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 8315cd2..b8d6d2b 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -53,7 +53,8 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm m_strDeviceName(strDeviceName), m_communication(serComm), m_controller(controller), - m_bMonitor(false) + m_bMonitor(false), + m_busScan(NULL) { m_logicalAddresses.Clear(); m_logicalAddresses.Set(iLogicalAddress); @@ -107,8 +108,15 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm CCECProcessor::~CCECProcessor(void) { + if (m_busScan) + { + m_busScan->StopThread(); + delete m_busScan; + } + m_startCondition.Broadcast(); StopThread(); + m_communication = NULL; m_controller = NULL; for (unsigned int iPtr = 0; iPtr < 16; iPtr++) @@ -131,7 +139,15 @@ bool CCECProcessor::Start(void) m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); return false; } - return true; + + lock.Leave(); + if (SetAckMask(m_logicalAddresses.AckMask()) && + SetHDMIPort(m_iHDMIPort, true)) + { + m_busScan = new CCECBusScan(this); + m_busScan->CreateThread(true); + return true; + } } else m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); @@ -220,28 +236,19 @@ void *CCECProcessor::Process(void) cec_command command; CCECAdapterMessage msg; + if (m_logicalAddresses.IsEmpty() && !FindLogicalAddresses()) { - if (m_logicalAddresses.IsEmpty() && !FindLogicalAddresses()) - { - CLockObject lock(&m_mutex); - m_controller->AddLog(CEC_LOG_ERROR, "could not detect our logical addresses"); - m_startCondition.Signal(); - return NULL; - } - - SetAckMask(m_logicalAddresses.AckMask()); - - { - CLockObject lock(&m_mutex); - m_bStarted = true; - lock.Leave(); - - SetHDMIPort(m_iHDMIPort); - - lock.Lock(); - m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started"); - m_startCondition.Signal(); - } + CLockObject lock(&m_mutex); + m_controller->AddLog(CEC_LOG_ERROR, "could not detect our logical addresses"); + m_startCondition.Signal(); + return NULL; + } + else + { + CLockObject lock(&m_mutex); + m_bStarted = true; + m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started"); + m_startCondition.Signal(); } while (!IsStopped()) @@ -271,7 +278,7 @@ void *CCECProcessor::Process(void) m_controller->CheckKeypressTimeout(); - for (unsigned int iDevicePtr = 0; iDevicePtr < 16; iDevicePtr++) + for (uint8_t iDevicePtr = 0; iDevicePtr < 16; iDevicePtr++) { if (!m_logicalAddresses[iDevicePtr]) m_busDevices[iDevicePtr]->PollVendorId(); @@ -350,7 +357,7 @@ bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true * return bReturn; } -bool CCECProcessor::SetHDMIPort(uint8_t iPort) +bool CCECProcessor::SetHDMIPort(uint8_t iPort, bool bForce /* = false */) { bool bReturn(false); @@ -359,7 +366,7 @@ bool CCECProcessor::SetHDMIPort(uint8_t iPort) AddLog(CEC_LOG_DEBUG, strLog); m_iHDMIPort = iPort; - if (!m_bStarted) + if (!m_bStarted && !bForce) return true; uint16_t iPhysicalAddress(0); @@ -387,7 +394,7 @@ bool CCECProcessor::SetHDMIPort(uint8_t iPort) bool CCECProcessor::CheckPhysicalAddress(uint16_t iPhysicalAddress) { - for (unsigned int iPtr = 0; iPtr < 16; iPtr++) + for (unsigned int iPtr = 0; iPtr < 15; iPtr++) { if (m_busDevices[iPtr]->GetPhysicalAddress(false) == iPhysicalAddress) return true; @@ -409,13 +416,13 @@ bool CCECProcessor::SetStreamPath(uint16_t iStreamPath) return bReturn; } -bool CCECProcessor::SetInactiveView(void) +bool CCECProcessor::TransmitInactiveSource(void) { if (!IsRunning()) return false; if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary]) - return m_busDevices[m_logicalAddresses.primary]->TransmitInactiveView(); + return m_busDevices[m_logicalAddresses.primary]->TransmitInactiveSource(); return false; } @@ -488,10 +495,41 @@ bool CCECProcessor::SwitchMonitoring(bool bEnable) bool CCECProcessor::PollDevice(cec_logical_address iAddress) { if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress]) - return m_busDevices[m_logicalAddresses.primary]->TransmitPoll(iAddress); + { + return m_logicalAddresses.primary == CECDEVICE_UNKNOWN ? + m_busDevices[iAddress]->TransmitPoll(iAddress) : + m_busDevices[m_logicalAddresses.primary]->TransmitPoll(iAddress); + } return false; } +uint8_t CCECProcessor::VolumeUp(bool bWait /* = true */) +{ + uint8_t status = 0; + if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM)) + status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp(bWait); + + return status; +} + +uint8_t CCECProcessor::VolumeDown(bool bWait /* = true */) +{ + uint8_t status = 0; + if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM)) + status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown(bWait); + + return status; +} + +uint8_t CCECProcessor::MuteAudio(bool bWait /* = true */) +{ + uint8_t status = 0; + if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM)) + status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio(bWait); + + return status; +} + CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bRefresh /* = false */) const { if (m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress(false) == iPhysicalAddress) @@ -531,6 +569,17 @@ cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress) return m_busDevices[iAddress]->GetCecVersion(); } +cec_osd_name CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress) +{ + CStdString strOSDName = m_busDevices[iAddress]->GetOSDName(); + cec_osd_name retVal; + + snprintf(retVal.name, sizeof(retVal.name), "%s", strOSDName.c_str()); + retVal.device = iAddress; + + return retVal; +} + bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language) { if (m_busDevices[iAddress]) @@ -708,6 +757,7 @@ void CCECProcessor::ParseCommand(cec_command &command) cec_logical_addresses CCECProcessor::GetActiveDevices(void) { cec_logical_addresses addresses; + addresses.Clear(); for (unsigned int iPtr = 0; iPtr < 15; iPtr++) { if (m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT) @@ -786,3 +836,37 @@ bool CCECProcessor::SetAckMask(uint16_t iMask) return bReturn; } + +bool CCECProcessor::SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = false */) +{ + return m_busDevices[iDestination]->SendKeypress(key, bWait); +} + +bool CCECProcessor::SendKeyRelease(cec_logical_address iDestination, bool bWait /* = false */) +{ + return m_busDevices[iDestination]->SendKeyRelease(bWait); +} + +void *CCECBusScan::Process(void) +{ + CCECBusDevice *device(NULL); + for (unsigned int iPtr = 0; iPtr < 15 && !IsStopped(); iPtr++) + { + device = m_processor->m_busDevices[iPtr]; + if (device && device->GetStatus() == CEC_DEVICE_STATUS_PRESENT) + { + if (!IsStopped()) + device->GetPhysicalAddress(); + Sleep(5); + + if (!IsStopped()) + device->GetCecVersion(); + Sleep(5); + + if (!IsStopped()) + device->GetVendorId(); + Sleep(5); + } + } + return NULL; +}