X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fdevices%2FCECBusDevice.cpp;h=845cb07d6426af2ab801fa7ba674a439c7628517;hb=0eb7639ed29e68a004e3eee32d53395d98252657;hp=3638453125809c92ef2383e4f77cad62202ff7af;hpb=6bbfc3f7460c5806ffd80834b3c3c68e0738a2d5;p=deb_libcec.git diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 3638453..845cb07 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -60,7 +60,8 @@ CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogi m_cecVersion(CEC_VERSION_UNKNOWN), m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN), m_iHandlerUseCount(0), - m_bAwaitingReceiveFailed(false) + m_bAwaitingReceiveFailed(false), + m_bVendorIdRequested(false) { m_handler = new CCECCommandHandler(this); @@ -86,6 +87,7 @@ bool CCECBusDevice::HandleCommand(const cec_command &command) CLockObject lock(m_mutex); m_iLastActive = GetTimeMs(); + /* don't call GetStatus() here, just read the value with the mutex locked */ if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC) m_deviceStatus = CEC_DEVICE_STATUS_PRESENT; @@ -159,7 +161,10 @@ cec_version CCECBusDevice::GetCecVersion(bool bUpdate /* = false */) } if (bRequestUpdate) + { + CheckVendorIdRequested(); RequestCecVersion(); + } CLockObject lock(m_mutex); return m_cecVersion; @@ -169,7 +174,8 @@ bool CCECBusDevice::RequestCecVersion(void) { bool bReturn(false); - if (!MyLogicalAddressContains(m_iLogicalAddress)) + if (!MyLogicalAddressContains(m_iLogicalAddress) && + !IsUnsupportedFeature(CEC_OPCODE_GET_CEC_VERSION)) { MarkBusy(); CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); @@ -196,7 +202,10 @@ cec_menu_language &CCECBusDevice::GetMenuLanguage(bool bUpdate /* = false */) } if (bRequestUpdate) + { + CheckVendorIdRequested(); RequestMenuLanguage(); + } CLockObject lock(m_mutex); return m_menuLanguage; @@ -245,7 +254,10 @@ CStdString CCECBusDevice::GetOSDName(bool bUpdate /* = false */) } if (bRequestUpdate) + { + CheckVendorIdRequested(); RequestOSDName(); + } CLockObject lock(m_mutex); return m_strDeviceName; @@ -276,8 +288,12 @@ uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate /* = false */) (m_iPhysicalAddress == 0xFFFF || bUpdate); } - if (bRequestUpdate && !RequestPhysicalAddress()) - CLibCEC::AddLog(CEC_LOG_ERROR, "failed to request the physical address"); + if (bRequestUpdate) + { + CheckVendorIdRequested(); + if (!RequestPhysicalAddress()) + CLibCEC::AddLog(CEC_LOG_ERROR, "failed to request the physical address"); + } CLockObject lock(m_mutex); return m_iPhysicalAddress; @@ -311,7 +327,10 @@ cec_power_status CCECBusDevice::GetPowerStatus(bool bUpdate /* = false */) } if (bRequestUpdate) + { + CheckVendorIdRequested(); RequestPowerStatus(); + } CLockObject lock(m_mutex); return m_powerStatus; @@ -438,20 +457,27 @@ bool CCECBusDevice::NeedsPoll(void) cec_bus_device_status CCECBusDevice::GetStatus(bool bForcePoll /* = false */) { - CLockObject lock(m_mutex); - if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC && - (m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN || bForcePoll)) + cec_bus_device_status status(CEC_DEVICE_STATUS_UNKNOWN); + bool bNeedsPoll(false); + + { + CLockObject lock(m_mutex); + status = m_deviceStatus; + bNeedsPoll = (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC && + (m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN || bForcePoll)); + } + + if (bNeedsPoll) { - lock.Unlock(); bool bPollAcked(false); - if (bForcePoll || NeedsPoll()) + if (bNeedsPoll && NeedsPoll()) bPollAcked = m_processor->PollDevice(m_iLogicalAddress); - lock.Lock(); - m_deviceStatus = bPollAcked ? CEC_DEVICE_STATUS_PRESENT : CEC_DEVICE_STATUS_NOT_PRESENT; + status = bPollAcked ? CEC_DEVICE_STATUS_PRESENT : CEC_DEVICE_STATUS_NOT_PRESENT; + SetDeviceStatus(status); } - return m_deviceStatus; + return status; } //@} @@ -498,6 +524,8 @@ void CCECBusDevice::SetInactiveSource(void) { { CLockObject lock(m_mutex); + if (m_bActiveSource) + CLibCEC::AddLog(CEC_LOG_DEBUG, "marking %s (%X) as inactive source", GetLogicalAddressName(), m_iLogicalAddress); m_bActiveSource = false; } @@ -811,7 +839,7 @@ bool CCECBusDevice::TransmitOSDName(cec_logical_address dest) bool CCECBusDevice::TransmitOSDString(cec_logical_address dest, cec_display_control duration, const char *strMessage) { bool bReturn(false); - if (!IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING)) + if (!m_processor->m_busDevices[dest]->IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING)) { CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, strMessage); MarkBusy(); @@ -875,7 +903,10 @@ bool CCECBusDevice::TransmitPowerState(cec_logical_address dest) { CLockObject lock(m_mutex); if (!IsActiveSource()) + { + CLibCEC::AddLog(CEC_LOG_NOTICE, "power state requested of %s (%X), but we are not the active source. setting power state to standby", GetLogicalAddressName(), m_iLogicalAddress); SetPowerStatus(CEC_POWER_STATUS_STANDBY); + } CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_powerStatus)); state = m_powerStatus; @@ -933,11 +964,15 @@ bool CCECBusDevice::TransmitKeyRelease(bool bWait /* = true */) bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode) const { - return m_unsupportedFeatures.find(opcode) != m_unsupportedFeatures.end(); + bool bUnsupported = (m_unsupportedFeatures.find(opcode) != m_unsupportedFeatures.end()); + if (bUnsupported) + CLibCEC::AddLog(CEC_LOG_NOTICE, "'%s' is marked as unsupported feature for device '%s'", ToString(opcode), GetLogicalAddressName()); + return bUnsupported; } void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode) { + CLibCEC::AddLog(CEC_LOG_DEBUG, "marking opcode '%s' as unsupported feature for device '%s'", ToString(opcode), GetLogicalAddressName()); m_unsupportedFeatures.insert(opcode); } @@ -962,4 +997,20 @@ bool CCECBusDevice::HandleReceiveFailed(void) return bReturn; } +void CCECBusDevice::CheckVendorIdRequested(void) +{ + bool bRequestVendorId(false); + { + CLockObject lock(m_mutex); + bRequestVendorId = !m_bVendorIdRequested; + m_bVendorIdRequested = true; + } + + if (bRequestVendorId) + { + ReplaceHandler(false); + GetVendorId(); + } +} + //@}