X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2FCECProcessor.cpp;h=a8f40c55709c382f4f6d9dd8efc1b7080b2c4f52;hb=3c5b4d054fc5067655c2001e0cfb9e1186a5ae15;hp=23afdb623bdfb7c0217fbcd289af5bc1fd129ed7;hpb=d297cbd4fc30bc93836532a9a31027b7e64150b3;p=deb_libcec.git diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 23afdb6..a8f40c5 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -59,7 +59,7 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, libcec_configuration *configur { CreateBusDevices(); m_configuration.Clear(); - m_configuration.serverVersion = configuration->serverVersion; + m_configuration.serverVersion = CEC_SERVER_VERSION_1_6_0; SetConfiguration(configuration); if (m_configuration.tvVendor != CEC_VENDOR_UNKNOWN) @@ -77,7 +77,7 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, con m_iLastTransmission(0) { m_configuration.Clear(); - m_configuration.serverVersion = CEC_SERVER_VERSION_1_5_2; + m_configuration.serverVersion = CEC_SERVER_VERSION_1_6_0; // client version < 1.5.0 m_configuration.clientVersion = (uint32_t)CEC_CLIENT_VERSION_PRE_1_5; @@ -132,7 +132,10 @@ CCECProcessor::~CCECProcessor(void) Close(); for (unsigned int iPtr = 0; iPtr < 16; iPtr++) + { delete m_busDevices[iPtr]; + m_busDevices[iPtr] = NULL; + } } void CCECProcessor::Close(void) @@ -157,7 +160,7 @@ void CCECProcessor::Close(void) } } -bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs) +bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening /* = true */) { bool bReturn(false); Close(); @@ -184,7 +187,7 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint /* open a new connection */ unsigned iConnectTry(0); - while (timeout.TimeLeft() > 0 && (bReturn = m_communication->Open(this, (timeout.TimeLeft() / CEC_CONNECT_TRIES))) == false) + while (timeout.TimeLeft() > 0 && (bReturn = m_communication->Open((timeout.TimeLeft() / CEC_CONNECT_TRIES), false, bStartListening)) == false) { CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry); m_communication->Close(); @@ -192,7 +195,10 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint } if (bReturn) - CLibCEC::AddLog(CEC_LOG_NOTICE, "connected to the CEC adapter. firmware version = %d, client version = %s", m_communication->GetFirmwareVersion(), ToString((cec_client_version)m_configuration.clientVersion)); + { + m_configuration.iFirmwareVersion = m_communication->GetFirmwareVersion(); + CLibCEC::AddLog(CEC_LOG_NOTICE, "connected to the CEC adapter. firmware version = %d, client version = %s", m_configuration.iFirmwareVersion, ToString((cec_client_version)m_configuration.clientVersion)); + } if (m_configuration.bGetSettingsFromROM == 1) m_communication->GetConfiguration(&m_configuration); @@ -247,7 +253,7 @@ bool CCECProcessor::Initialise(void) else if (m_configuration.iPhysicalAddress == 0 && (bReturn = SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort, true)) == false) CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set HDMI port %d on %s (%x)", m_configuration.iHDMIPort, ToString(m_configuration.baseDevice), (uint8_t)m_configuration.baseDevice); - if (m_configuration.bActivateSource == 1) + if (bReturn && m_configuration.bActivateSource == 1) m_busDevices[m_configuration.logicalAddresses.primary]->ActivateSource(); SetInitialised(bReturn); @@ -450,23 +456,27 @@ void CCECProcessor::ReplaceHandlers(void) bool CCECProcessor::OnCommandReceived(const cec_command &command) { - ParseCommand(command); - return true; + return m_inBuffer.Push(command); } void *CCECProcessor::Process(void) { CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started"); + cec_command command; + command.Clear(); + while (!IsStopped() && m_communication->IsOpen()) { + if (m_inBuffer.Pop(command, 500)) + ParseCommand(command); + if (IsInitialised()) { ReplaceHandlers(); m_controller->CheckKeypressTimeout(); } - Sleep(5); } return NULL; @@ -504,7 +514,8 @@ bool CCECProcessor::SetActiveSource(uint16_t iStreamPath) { bool bReturn(false); - CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath); + // suppress polls when searching for a device + CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath, false, true); if (device) { device->SetActiveSource(); @@ -568,6 +579,12 @@ bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, { bool bReturn(false); + // limit the HDMI port range to 1-15 + if (iPort < 1) + iPort = 1; + if (iPort > 15) + iPort = 15; + { CLockObject lock(m_mutex); m_configuration.baseDevice = iBaseDevice; @@ -763,7 +780,7 @@ uint8_t CCECProcessor::MuteAudio(bool bSendRelease /* = true */) return status; } -CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bRefresh /* = false */) const +CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bRefresh /* = false */, bool bSuppressPoll /* = false */) const { if (m_busDevices[m_configuration.logicalAddresses.primary]->GetPhysicalAddress(false) == iPhysicalAddress) return m_busDevices[m_configuration.logicalAddresses.primary]; @@ -771,7 +788,7 @@ CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddre CCECBusDevice *device = NULL; for (unsigned int iPtr = 0; iPtr < 16; iPtr++) { - if (m_busDevices[iPtr]->GetPhysicalAddress(bRefresh) == iPhysicalAddress) + if (m_busDevices[iPtr]->GetPhysicalAddress(bRefresh, bSuppressPoll) == iPhysicalAddress) { device = m_busDevices[iPtr]; break; @@ -1380,6 +1397,10 @@ const char *CCECProcessor::ToString(const cec_client_version version) return "1.5.1"; case CEC_CLIENT_VERSION_1_5_2: return "1.5.2"; + case CEC_CLIENT_VERSION_1_5_3: + return "1.5.3"; + case CEC_CLIENT_VERSION_1_6_0: + return "1.6.0"; default: return "Unknown"; } @@ -1397,6 +1418,10 @@ const char *CCECProcessor::ToString(const cec_server_version version) return "1.5.1"; case CEC_SERVER_VERSION_1_5_2: return "1.5.2"; + case CEC_SERVER_VERSION_1_5_3: + return "1.5.3"; + case CEC_SERVER_VERSION_1_6_0: + return "1.6.0"; default: return "Unknown"; } @@ -1455,7 +1480,7 @@ bool CCECProcessor::StartBootloader(const char *strPort /* = NULL */) IAdapterCommunication *comm = new CUSBCECAdapterCommunication(this, strPort); CTimeout timeout(10000); int iConnectTry(0); - while (timeout.TimeLeft() > 0 && (bReturn = comm->Open(NULL, (timeout.TimeLeft() / CEC_CONNECT_TRIES)), true) == false) + while (timeout.TimeLeft() > 0 && (bReturn = comm->Open(timeout.TimeLeft() / CEC_CONNECT_TRIES, true)) == false) { CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry); comm->Close(); @@ -1481,7 +1506,8 @@ bool CCECProcessor::PingAdapter(void) void CCECProcessor::HandlePoll(cec_logical_address initiator, cec_logical_address destination) { - m_busDevices[initiator]->HandlePoll(destination); + if (destination < CECDEVICE_BROADCAST) + m_busDevices[destination]->HandlePollFrom(initiator); } bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator) @@ -1532,9 +1558,12 @@ bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration) { if (configuration->iPhysicalAddress != 0) bPhysicalAddressChanged = IsRunning() && m_configuration.iPhysicalAddress != configuration->iPhysicalAddress; - if (IsRunning()) - CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using physical address '%4x'", __FUNCTION__, configuration->iPhysicalAddress); - m_configuration.iPhysicalAddress = configuration->iPhysicalAddress; + if (bPhysicalAddressChanged) + { + if (IsRunning()) + CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using physical address '%4x'", __FUNCTION__, configuration->iPhysicalAddress); + m_configuration.iPhysicalAddress = configuration->iPhysicalAddress; + } } bool bHdmiPortChanged(false); @@ -1588,6 +1617,7 @@ bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration) // just copy these m_configuration.clientVersion = configuration->clientVersion; + m_configuration.bUseTVMenuLanguage = configuration->bUseTVMenuLanguage; m_configuration.bActivateSource = configuration->bActivateSource; m_configuration.bGetSettingsFromROM = configuration->bGetSettingsFromROM; m_configuration.powerOffDevices = configuration->powerOffDevices; @@ -1598,6 +1628,13 @@ bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration) if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_5_1) m_configuration.bSendInactiveSource = configuration->bSendInactiveSource; + // client version 1.6.0 + if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_6_0) + { + m_configuration.bPowerOffDevicesOnStandby = configuration->bPowerOffDevicesOnStandby; + m_configuration.bShutdownOnStandby = configuration->bShutdownOnStandby; + } + // ensure that there is at least 1 device type set if (m_configuration.deviceTypes.IsEmpty()) m_configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE); @@ -1649,6 +1686,14 @@ bool CCECProcessor::GetCurrentConfiguration(libcec_configuration *configuration) if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_5_3) configuration->logicalAddresses = m_configuration.logicalAddresses; + // client version 1.6.0 + if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_6_0) + { + configuration->iFirmwareVersion = m_configuration.iFirmwareVersion; + configuration->bPowerOffDevicesOnStandby = m_configuration.bPowerOffDevicesOnStandby; + configuration->bShutdownOnStandby = m_configuration.bShutdownOnStandby; + } + return true; } @@ -1667,3 +1712,16 @@ void CCECProcessor::RescanActiveDevices(void) for (unsigned int iPtr = 0; iPtr < 16; iPtr++) m_busDevices[iPtr]->GetStatus(true); } + +bool CCECProcessor::GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs /* = 10000 */) +{ + if (!OpenConnection(strPort, 38400, iTimeoutMs, false)) + return false; + + config->iFirmwareVersion = m_communication->GetFirmwareVersion(); + config->iPhysicalAddress = m_communication->GetPhysicalAddress(); + + delete m_communication; + m_communication = NULL; + return true; +}