From: Lars Op den Kamp Date: Thu, 26 Apr 2012 12:08:16 +0000 (+0200) Subject: cec: request the active source if it's unknown in CCECProcessor::GetActiveSource() X-Git-Tag: upstream/2.2.0~1^2~29^2^2~20 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=5734016c1b1e932c19a85bb671211c4967399f8c;p=deb_libcec.git cec: request the active source if it's unknown in CCECProcessor::GetActiveSource() --- diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 0e85dab..a1603e8 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -911,7 +911,7 @@ cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddres return CEC_POWER_STATUS_UNKNOWN; } -cec_logical_address CCECProcessor::GetActiveSource(void) +cec_logical_address CCECProcessor::GetActiveSource(bool bRequestActiveSource /* = true */) { for (uint8_t iPtr = 0; iPtr <= 11; iPtr++) { @@ -919,6 +919,15 @@ cec_logical_address CCECProcessor::GetActiveSource(void) return (cec_logical_address)iPtr; } + if (bRequestActiveSource && m_configuration.logicalAddresses.primary != CECDEVICE_UNKNOWN) + { + CCECBusDevice *primary = m_busDevices[m_configuration.logicalAddresses.primary]; + if (primary) + primary->RequestActiveSource(); + + return GetActiveSource(false); + } + return CECDEVICE_UNKNOWN; } diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index acefd8b..9b7a6e3 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -127,7 +127,7 @@ namespace CEC bool IsPresentDeviceType(cec_device_type type); uint16_t GetPhysicalAddress(void) const; uint64_t GetLastTransmission(void) const { return m_iLastTransmission; } - cec_logical_address GetActiveSource(void); + cec_logical_address GetActiveSource(bool bRequestActiveSource = true); bool IsActiveSource(cec_logical_address iAddress); bool IsInitialised(void); bool SetStreamPath(uint16_t iPhysicalAddress); diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 757204c..0cd28d5 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -170,6 +170,21 @@ cec_version CCECBusDevice::GetCecVersion(bool bUpdate /* = false */) return m_cecVersion; } +bool CCECBusDevice::RequestActiveSource(bool bWaitForResponse /* = true */) +{ + bool bReturn(false); + + if (MyLogicalAddressContains(m_iLogicalAddress)) + { + MarkBusy(); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting active source"); + + bReturn = m_handler->TransmitRequestActiveSource(GetMyLogicalAddress(), bWaitForResponse); + MarkReady(); + } + return bReturn; +} + bool CCECBusDevice::RequestCecVersion(bool bWaitForResponse /* = true */) { bool bReturn(false); diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index f6e0d82..f5868c1 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -111,6 +111,8 @@ namespace CEC bool ReplaceHandler(bool bActivateSource = true); virtual bool TransmitPendingActiveSourceCommands(void); + virtual bool RequestActiveSource(bool bWaitForResponse = true); + protected: void ResetDeviceStatus(void); void CheckVendorIdRequested(void); diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index 5fa83ed..82110bc 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -773,6 +773,14 @@ bool CCECCommandHandler::TransmitStandby(const cec_logical_address iInitiator, c return Transmit(command); } +bool CCECCommandHandler::TransmitRequestActiveSource(const cec_logical_address iInitiator, bool bWaitForResponse /* = true */) +{ + cec_command command; + cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_REQUEST_ACTIVE_SOURCE); + + return Transmit(command, !bWaitForResponse); +} + bool CCECCommandHandler::TransmitRequestCecVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */) { cec_command command; diff --git a/src/lib/implementations/CECCommandHandler.h b/src/lib/implementations/CECCommandHandler.h index 8a01828..be1f643 100644 --- a/src/lib/implementations/CECCommandHandler.h +++ b/src/lib/implementations/CECCommandHandler.h @@ -132,6 +132,7 @@ namespace CEC virtual bool PowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination); virtual bool TransmitImageViewOn(const cec_logical_address iInitiator, const cec_logical_address iDestination); virtual bool TransmitStandby(const cec_logical_address iInitiator, const cec_logical_address iDestination); + virtual bool TransmitRequestActiveSource(const cec_logical_address iInitiator, bool bWaitForResponse = true); virtual bool TransmitRequestCecVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse = true); virtual bool TransmitRequestMenuLanguage(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse = true); virtual bool TransmitRequestOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse = true); diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index fe5d647..cb5903b 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -848,7 +848,7 @@ bool ProcessCommandSCAN(ICECAdapter *parser, const string &command, string & UNU } cec_logical_address activeSource = parser->GetActiveSource(); - strLog.AppendFormat("currently active source: %s (%X)", parser->ToString(activeSource), (int)activeSource); + strLog.AppendFormat("currently active source: %s (%d)", parser->ToString(activeSource), (int)activeSource); PrintToStdOut(strLog); return true;