Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion HdmiCecSink/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ All notable changes to this RDK Service will be documented in this file.
* **Security** in case of vulnerabilities.

* Changes in CHANGELOG should be updated when commits are added to the main or release branches. There should be one CHANGELOG entry per JIRA Ticket. This is not enforced on sprint branches since there could be multiple changes for the same JIRA ticket during development.

183 changes: 138 additions & 45 deletions HdmiCecSink/HdmiCecSink.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**

Check failure on line 1 in HdmiCecSink/HdmiCecSink.cpp

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'HdmiCecSink/HdmiCecSink.cpp' (Match: rdkcentral/rdkservices/1, 3563 lines, url: https://github.com/rdkcentral/rdkservices/archive/GRT_v1.tar.gz, file: HdmiCecSink/HdmiCecSink.cpp)

Check failure on line 1 in HdmiCecSink/HdmiCecSink.cpp

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'HdmiCecSink/HdmiCecSink.cpp' (Match: rdkcentral/rdkservices/866, 3538 lines, url: https://github.com/rdkcentral/rdkservices/archive/AML_BSP_VERSION_866.tar.gz, file: HdmiCecSink/HdmiCecSink.cpp)
* If not stated otherwise in this file or this component's LICENSE
* file the following copyright and licenses apply:
*
Expand Down Expand Up @@ -76,6 +76,7 @@
#define HDMICECSINK_NUMBER_TV_ADDR 2
#define HDMICECSINK_UPDATE_POWER_STATUS_INTERVA_MS (60 * 1000)
#define HDMISINK_ARC_START_STOP_MAX_WAIT_MS 4000
#define HDMICECSINK_UPDATE_AUDIO_STATUS_INTERVAL_MS 500


#define SAD_FMT_CODE_AC3 2
Expand Down Expand Up @@ -175,9 +176,7 @@

#define API_VERSION_NUMBER_MAJOR 1
#define API_VERSION_NUMBER_MINOR 3
#define API_VERSION_NUMBER_PATCH 7

using PowerState = WPEFramework::Exchange::IPowerManager::PowerState;
#define API_VERSION_NUMBER_PATCH 10

namespace WPEFramework
{
Expand Down Expand Up @@ -711,7 +710,10 @@
m_currentActiveSource = -1;
m_isHdmiInConnected = false;
hdmiCecAudioDeviceConnected = false;
m_audioDevicePowerStatusRequested = false;
m_isAudioStatusInfoUpdated = false;
m_audioStatusReceived = false;
m_audioStatusTimerStarted = false;
m_audioDevicePowerStatusRequested = false;
m_pollNextState = POLL_THREAD_STATE_NONE;
m_pollThreadState = POLL_THREAD_STATE_NONE;
m_video_latency = DEFAULT_VIDEO_LATENCY;
Expand Down Expand Up @@ -746,22 +748,30 @@
Register(HDMICECSINK_METHOD_SET_LATENCY_INFO, &HdmiCecSink::setLatencyInfoWrapper, this);
logicalAddressDeviceType = "None";
logicalAddress = 0xFF;
// load persistence setting
loadSettings();
}

HdmiCecSink::~HdmiCecSink()
{
}
const std::string HdmiCecSink::Initialize(PluginHost::IShell * /* service */)
{
HdmiCecSink::_instance = this;
int err;
dsHdmiInGetNumberOfInputsParam_t hdmiInput;
InitializeIARM();
m_sendKeyEventThreadExit = false;
m_sendKeyEventThread = std::thread(threadSendKeyEvent);

m_currentArcRoutingState = ARC_STATE_ARC_TERMINATED;
m_semSignaltoArcRoutingThread.acquire();
m_arcRoutingThread = std::thread(threadArcRouting);


m_audioStatusDetectionTimer.connect( std::bind( &HdmiCecSink::audioStatusTimerFunction, this ) );
m_audioStatusDetectionTimer.setSingleShot(true);
m_arcStartStopTimer.connect( std::bind( &HdmiCecSink::arcStartStopTimerFunction, this ) );
m_arcStartStopTimer.setSingleShot(true);
// load persistence setting
loadSettings();

int err;
dsHdmiInGetNumberOfInputsParam_t hdmiInput;
InitializeIARM();
// get power state:
uint32_t res = Core::ERROR_GENERAL;
PowerState pwrStateCur = WPEFramework::Exchange::IPowerManager::POWER_STATE_UNKNOWN;
Expand Down Expand Up @@ -813,7 +823,7 @@
}
}
getCecVersion();
getHdmiArcPortID();
LOGINFO(" HdmiCecSink plugin Initialize completed \n");
return (std::string());

}
Expand Down Expand Up @@ -1146,6 +1156,18 @@
JsonObject params;
if(!HdmiCecSink::_instance)
return;
if (m_audioStatusTimerStarted)
{
m_audioStatusReceived = true;
m_isAudioStatusInfoUpdated = true;
m_audioStatusTimerStarted = false;
if (m_audioStatusDetectionTimer.isActive())
{
LOGINFO("AudioStatus received from the Audio Device and the timer is still active. So stopping the timer!\n");
m_audioStatusDetectionTimer.stop();
}
LOGINFO("AudioStatus received from the Audio Device. Updating the AudioStatus info! m_isAudioStatusInfoUpdated :%d, m_audioStatusReceived :%d, m_audioStatusTimerStarted:%d ", m_isAudioStatusInfoUpdated,m_audioStatusReceived,m_audioStatusTimerStarted);
}
LOGINFO("Command: ReportAudioStatus %s audio Mute status %d means %s and current Volume level is %d \n",GetOpName(msg.opCode()),msg.status.getAudioMuteStatus(),msg.status.toString().c_str(),msg.status.getAudioVolume());
params["muteStatus"] = msg.status.getAudioMuteStatus();
params["volumeLevel"] = msg.status.getAudioVolume();
Expand Down Expand Up @@ -2476,7 +2498,14 @@
params["status"] = string("success");
params["audioDeviceConnected"] = string("false");
hdmiCecAudioDeviceConnected = false;
sendNotify(eventString[HDMICECSINK_EVENT_AUDIO_DEVICE_CONNECTED_STATUS], params);
if (m_audioStatusDetectionTimer.isActive()){
m_audioStatusDetectionTimer.stop();
}
m_isAudioStatusInfoUpdated = false;
m_audioStatusReceived = false;
m_audioStatusTimerStarted = false;
LOGINFO("Audio device removed, reset the audio status info. m_isAudioStatusInfoUpdated :%d, m_audioStatusReceived :%d, m_audioStatusTimerStarted:%d ", m_isAudioStatusInfoUpdated,m_audioStatusReceived,m_audioStatusTimerStarted);
sendNotify(eventString[HDMICECSINK_EVENT_AUDIO_DEVICE_CONNECTED_STATUS], params)
}

_instance->deviceList[logicalAddress].m_isRequestRetry = 0;
Expand Down Expand Up @@ -2719,29 +2748,44 @@
_instance->allocateLogicalAddress(DeviceType::TV);
if ( _instance->m_logicalAddressAllocated != LogicalAddress::UNREGISTERED)
{
logicalAddress = LogicalAddress(_instance->m_logicalAddressAllocated);
LibCCEC::getInstance().addLogicalAddress(logicalAddress);
_instance->smConnection->setSource(logicalAddress);
_instance->m_numberOfDevices = 0;
_instance->deviceList[_instance->m_logicalAddressAllocated].m_deviceType = DeviceType::TV;
_instance->deviceList[_instance->m_logicalAddressAllocated].m_isDevicePresent = true;
_instance->deviceList[_instance->m_logicalAddressAllocated].update(physical_addr);
_instance->deviceList[_instance->m_logicalAddressAllocated].m_cecVersion = Version::V_1_4;
_instance->deviceList[_instance->m_logicalAddressAllocated].m_vendorID = appVendorId;
_instance->deviceList[_instance->m_logicalAddressAllocated].m_powerStatus = PowerStatus(powerState);
_instance->deviceList[_instance->m_logicalAddressAllocated].m_currentLanguage = defaultLanguage;
_instance->deviceList[_instance->m_logicalAddressAllocated].m_osdName = osdName.toString().c_str();
if(cecVersion == 2.0) {
_instance->deviceList[_instance->m_logicalAddressAllocated].m_cecVersion = Version::V_2_0;
_instance->smConnection->sendTo(LogicalAddress(LogicalAddress::BROADCAST),
MessageEncoder().encode(ReportFeatures(Version::V_2_0,allDevicetype,rcProfile,deviceFeatures)), 500);
}
_instance->smConnection->addFrameListener(_instance->msgFrameListener);
_instance->smConnection->sendTo(LogicalAddress(LogicalAddress::BROADCAST),
MessageEncoder().encode(ReportPhysicalAddress(physical_addr, _instance->deviceList[_instance->m_logicalAddressAllocated].m_deviceType)), 100);

_instance->m_sleepTime = 0;
_instance->m_pollThreadState = POLL_THREAD_STATE_PING;
try{

logicalAddress = LogicalAddress(_instance->m_logicalAddressAllocated);
LibCCEC::getInstance().addLogicalAddress(logicalAddress);
_instance->smConnection->setSource(logicalAddress);
_instance->m_numberOfDevices = 0;
_instance->deviceList[_instance->m_logicalAddressAllocated].m_deviceType = DeviceType::TV;
_instance->deviceList[_instance->m_logicalAddressAllocated].m_isDevicePresent = true;
_instance->deviceList[_instance->m_logicalAddressAllocated].update(physical_addr);
_instance->deviceList[_instance->m_logicalAddressAllocated].m_cecVersion = Version::V_1_4;
_instance->deviceList[_instance->m_logicalAddressAllocated].m_vendorID = appVendorId;
_instance->deviceList[_instance->m_logicalAddressAllocated].m_powerStatus = PowerStatus(powerState);
_instance->deviceList[_instance->m_logicalAddressAllocated].m_currentLanguage = defaultLanguage;
_instance->deviceList[_instance->m_logicalAddressAllocated].m_osdName = osdName.toString().c_str();
if(cecVersion == 2.0) {
_instance->deviceList[_instance->m_logicalAddressAllocated].m_cecVersion = Version::V_2_0;
_instance->smConnection->sendTo(LogicalAddress(LogicalAddress::BROADCAST),
MessageEncoder().encode(ReportFeatures(Version::V_2_0,allDevicetype,rcProfile,deviceFeatures)), 500);
}
_instance->smConnection->addFrameListener(_instance->msgFrameListener);
_instance->smConnection->sendTo(LogicalAddress(LogicalAddress::BROADCAST),
MessageEncoder().encode(ReportPhysicalAddress(physical_addr, _instance->deviceList[_instance->m_logicalAddressAllocated].m_deviceType)), 100);

_instance->m_sleepTime = 0;
_instance->m_pollThreadState = POLL_THREAD_STATE_PING;
}
catch(InvalidStateException &e){
LOGWARN("InvalidStateException caught while allocated logical address. %s", e.what());
_instance->m_pollThreadState = POLL_THREAD_STATE_EXIT;
}
catch(IOException &e){
LOGWARN("IOException caught while allocated logical address. %s", e.what());
_instance->m_pollThreadState = POLL_THREAD_STATE_EXIT;
}
catch(...){
LOGWARN("Exception caught while allocated logical address.");
_instance->m_pollThreadState = POLL_THREAD_STATE_EXIT;
}
}
else
{
Expand Down Expand Up @@ -2977,9 +3021,14 @@
{
LibCCEC::getInstance().init("HdmiCecSink");
}
catch (const std::exception& e)
{
LOGWARN("CEC exception caught from LibCCEC::getInstance().init()");
catch(InvalidStateException &e){
LOGWARN("InvalidStateException caught in LibCCEC::init %s", e.what());
}
catch(IOException &e){
LOGWARN("IOException caught in LibCCEC::init %s", e.what());
}
catch(...){
LOGWARN("Exception caught in LibCCEC::init");
}
}
libcecInitStatus++;
Expand Down Expand Up @@ -3073,6 +3122,14 @@

m_logicalAddressAllocated = LogicalAddress::UNREGISTERED;
m_currentArcRoutingState = ARC_STATE_ARC_TERMINATED;
if (m_audioStatusDetectionTimer.isActive()){
m_audioStatusDetectionTimer.stop();
}
m_isAudioStatusInfoUpdated = false;
m_audioStatusReceived = false;
m_audioStatusTimerStarted = false;
LOGINFO("CEC Disabled, reset the audio status info. m_isAudioStatusInfoUpdated :%d, m_audioStatusReceived :%d, m_audioStatusTimerStarted:%d ", m_isAudioStatusInfoUpdated,m_audioStatusReceived,m_audioStatusTimerStarted);


for(int i=0; i< 16; i++)
{
Expand All @@ -3088,9 +3145,14 @@
{
LibCCEC::getInstance().term();
}
catch (const std::exception& e)
{
LOGWARN("CEC exception caught from LibCCEC::getInstance().term() ");
catch(InvalidStateException &e){
LOGWARN("InvalidStateException caught in LibCCEC::term %s", e.what());
}
catch(IOException &e){
LOGWARN("IOException caught in LibCCEC::term %s", e.what());
}
catch(...){
LOGWARN("Exception caught in LibCCEC::term");
}
}

Expand Down Expand Up @@ -3323,12 +3385,43 @@

if((_instance->m_SendKeyQueue.size()<=1 || (_instance->m_SendKeyQueue.size() % 2 == 0)) && ((keyInfo.keyCode == VOLUME_UP) || (keyInfo.keyCode == VOLUME_DOWN) || (keyInfo.keyCode == MUTE)) )
{
_instance->sendGiveAudioStatusMsg();
}
if(keyInfo.keyCode == MUTE)
{
_instance->sendGiveAudioStatusMsg();
}
else
{
LOGINFO("m_isAudioStatusInfoUpdated :%d, m_audioStatusReceived :%d, m_audioStatusTimerStarted:%d ",_instance->m_isAudioStatusInfoUpdated,_instance->m_audioStatusReceived,_instance->m_audioStatusTimerStarted);
if (!_instance->m_isAudioStatusInfoUpdated)
{
if ( !(_instance->m_audioStatusDetectionTimer.isActive()))
{
LOGINFO("Audio status info not updated. Starting the Timer!");
_instance->m_audioStatusTimerStarted = true;
_instance->m_audioStatusDetectionTimer.start((HDMICECSINK_UPDATE_AUDIO_STATUS_INTERVAL_MS));
}
LOGINFO("m_isAudioStatusInfoUpdated :%d, m_audioStatusReceived :%d, m_audioStatusTimerStarted:%d ", _instance->m_isAudioStatusInfoUpdated,_instance->m_audioStatusReceived,_instance->m_audioStatusTimerStarted);
}
else
{
if (!_instance->m_audioStatusReceived){
_instance->sendGiveAudioStatusMsg();
}
}
}
}

}//while(!_instance->m_sendKeyEventThreadExit)
}//threadSendKeyEvent

void HdmiCecSink::audioStatusTimerFunction()
{
m_audioStatusTimerStarted = false;
m_isAudioStatusInfoUpdated = true;
LOGINFO("Timer Expired. Requesting the AudioStatus since not received.\n");
sendGiveAudioStatusMsg();
LOGINFO("m_isAudioStatusInfoUpdated :%d, m_audioStatusReceived :%d, m_audioStatusTimerStarted:%d ", m_isAudioStatusInfoUpdated,m_audioStatusReceived,m_audioStatusTimerStarted);
}

void HdmiCecSink::threadArcRouting()
{
Expand All @@ -3339,7 +3432,7 @@
return;

LOGINFO("Running threadArcRouting");

_instance->getHdmiArcPortID();

while(1)
{
Expand Down
11 changes: 7 additions & 4 deletions HdmiCecSink/HdmiCecSink.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**

Check failure on line 1 in HdmiCecSink/HdmiCecSink.h

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'HdmiCecSink/HdmiCecSink.h' (Match: rdkcentral/rdkservices/1, 740 lines, url: https://github.com/rdkcentral/rdkservices/archive/GRT_v1.tar.gz, file: HdmiCecSink/HdmiCecSink.h)
* If not stated otherwise in this file or this component's LICENSE
* file the following copyright and licenses apply:
*
Expand Down Expand Up @@ -573,9 +573,8 @@
void sendKeyReleaseEvent(const int logicalAddress);
void sendUserControlPressed(const int logicalAddress, int keyCode);
void sendUserControlReleased(const int logicalAddress);
void sendGiveAudioStatusMsg();
void onPowerModeChanged(const PowerState &currentState, const PowerState &newState);
void registerEventHandlers();
void sendGiveAudioStatusMsg();
void getHdmiArcPortID();
int m_numberOfDevices; /* Number of connected devices othethan own device */
bool m_audioDevicePowerStatusRequested;

Expand Down Expand Up @@ -667,6 +666,9 @@
/* Send Key event related */
bool m_sendKeyEventThreadExit;
bool m_sendKeyEventThreadRun;
bool m_isAudioStatusInfoUpdated;
bool m_audioStatusReceived;
bool m_audioStatusTimerStarted;
std::thread m_sendKeyEventThread;
std::mutex m_sendKeyEventMutex;
std::queue<SendKeyInfo> m_SendKeyQueue;
Expand All @@ -685,6 +687,7 @@
binary_semaphore m_semSignaltoArcRoutingThread;
bool m_arcstarting;
TpTimer m_arcStartStopTimer;
TpTimer m_audioStatusDetectionTimer;

Connection *smConnection;
std::vector<uint8_t> m_connectedDevices;
Expand Down Expand Up @@ -731,7 +734,7 @@
void Send_Request_Arc_Termination_Message();
void Send_Report_Arc_Terminated_Message();
void arcStartStopTimerFunction();
void getHdmiArcPortID();
void audioStatusTimerFunction();
void getCecVersion();
};
} // namespace Plugin
Expand Down
32 changes: 25 additions & 7 deletions HdmiCecSource/HdmiCecSource.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**

Check failure on line 1 in HdmiCecSource/HdmiCecSource.cpp

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'HdmiCecSource/HdmiCecSource.cpp' (Match: rdkcentral/rdkservices/1, 1725 lines, url: https://github.com/rdkcentral/rdkservices/archive/GRT_v1.tar.gz, file: HdmiCecSource/HdmiCecSource.cpp)
* If not stated otherwise in this file or this component's LICENSE
* file the following copyright and licenses apply:
*
Expand Down Expand Up @@ -1118,9 +1118,14 @@
{
LibCCEC::getInstance().init("HdmiCecSource");
}
catch (const std::exception& e)
{
LOGWARN("CEC exception caught from LibCCEC::getInstance().init()");
catch(InvalidStateException &e){
LOGWARN("InvalidStateException caught in LibCCEC::init %s", e.what());
}
catch(IOException &e){
LOGWARN("IOException caught in LibCCEC::init %s", e.what());
}
catch(...){
LOGWARN("Exception caught in LibCCEC::init");
}
}
libcecInitStatus++;
Expand Down Expand Up @@ -1265,9 +1270,14 @@
{
LibCCEC::getInstance().term();
}
catch (const std::exception& e)
{
LOGWARN("CEC exception caught from LibCCEC::getInstance().term() ");
catch(InvalidStateException &e){
LOGWARN("InvalidStateException caught in LibCCEC::getInstance().term() %s", e.what());
}
catch(IOException &e){
LOGWARN("IOException caught in LibCCEC::getInstance().term()%s", e.what());
}
catch(...){
LOGWARN("Exception caught in LibCCEC::getInstance().term()");
}
}

Expand Down Expand Up @@ -1525,7 +1535,15 @@
CECFrame frame = CECFrame((const uint8_t *)buf.data(), size);
// SVCLOG_WARN("Frame to be sent from servicemanager in %s \n",__FUNCTION__);
// frame.hexDump();
smConnection->sendAsync(frame);
try{
smConnection->sendAsync(frame);
}
catch(InvalidStateException &e){
LOGERR("InvalidStateException caught in sendUnencryptMsg %s", e.what());
}
catch(...){
LOGERR("Exception caught in sendUnencryptMsg");
}
}
else
LOGWARN("cecEnableStatus=false");
Expand Down
Loading