Skip to content

Commit 7b2c0f6

Browse files
committed
RDKEMW-1015 : HDMICEC SINK COMRPC
1 parent 092c001 commit 7b2c0f6

File tree

2 files changed

+134
-39
lines changed

2 files changed

+134
-39
lines changed

HdmiCecSink/HdmiCecSinkImplementation.cpp

Lines changed: 127 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,9 @@ namespace WPEFramework
688688
m_currentActiveSource = -1;
689689
m_isHdmiInConnected = false;
690690
hdmiCecAudioDeviceConnected = false;
691+
m_isAudioStatusInfoUpdated = false;
692+
m_audioStatusReceived = false;
693+
m_audioStatusTimerStarted = false;
691694
m_audioDevicePowerStatusRequested = false;
692695
m_pollNextState = POLL_THREAD_STATE_NONE;
693696
m_pollThreadState = POLL_THREAD_STATE_NONE;
@@ -697,22 +700,24 @@ namespace WPEFramework
697700

698701
logicalAddressDeviceType = "None";
699702
logicalAddress = 0xFF;
703+
// load persistence setting
704+
loadSettings();
705+
706+
int err;
707+
dsHdmiInGetNumberOfInputsParam_t hdmiInput;
708+
InitializeIARM();
700709
m_sendKeyEventThreadExit = false;
701710
m_sendKeyEventThread = std::thread(threadSendKeyEvent);
702711

703712
m_currentArcRoutingState = ARC_STATE_ARC_TERMINATED;
704713
m_semSignaltoArcRoutingThread.acquire();
705714
m_arcRoutingThread = std::thread(threadArcRouting);
706715

707-
716+
m_audioStatusDetectionTimer.connect( std::bind( &HdmiCecSink::audioStatusTimerFunction, this ) );
717+
m_audioStatusDetectionTimer.setSingleShot(true);
708718
m_arcStartStopTimer.connect( std::bind( &HdmiCecSinkImplementation::arcStartStopTimerFunction, this ) );
709719
m_arcStartStopTimer.setSingleShot(true);
710-
// load persistence setting
711-
loadSettings();
712720

713-
int err;
714-
dsHdmiInGetNumberOfInputsParam_t hdmiInput;
715-
InitializeIARM();
716721
// get power state:
717722
uint32_t res = Core::ERROR_GENERAL;
718723
PowerState pwrStateCur = WPEFramework::Exchange::IPowerManager::POWER_STATE_UNKNOWN;
@@ -764,8 +769,8 @@ namespace WPEFramework
764769
}
765770
}
766771
getCecVersion();
767-
getHdmiArcPortID();
768-
return (std::string());
772+
LOGINFO(" HdmiCecSink plugin Initialize completed \n");
773+
return (std::string());
769774

770775
}
771776

@@ -1092,6 +1097,18 @@ namespace WPEFramework
10921097
{
10931098
if(!HdmiCecSinkImplementation::_instance)
10941099
return;
1100+
if (m_audioStatusTimerStarted)
1101+
{
1102+
m_audioStatusReceived = true;
1103+
m_isAudioStatusInfoUpdated = true;
1104+
m_audioStatusTimerStarted = false;
1105+
if (m_audioStatusDetectionTimer.isActive())
1106+
{
1107+
LOGINFO("AudioStatus received from the Audio Device and the timer is still active. So stopping the timer!\n");
1108+
m_audioStatusDetectionTimer.stop();
1109+
}
1110+
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);
1111+
}
10951112
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());
10961113
while (index != _hdmiCecSourceNotifications.end()) {
10971114
(*index)->ReportAudioStatusEvent(msg.status.getAudioMuteStatus(), msg.status.getAudioVolume());
@@ -2393,6 +2410,13 @@ namespace WPEFramework
23932410
LOGINFO(" logicalAddress =%d , Audio device removed, Notify Device Settings", logicalAddress );
23942411

23952412
hdmiCecAudioDeviceConnected = false;
2413+
if (m_audioStatusDetectionTimer.isActive()){
2414+
m_audioStatusDetectionTimer.stop();
2415+
}
2416+
m_isAudioStatusInfoUpdated = false;
2417+
m_audioStatusReceived = false;
2418+
m_audioStatusTimerStarted = false;
2419+
LOGINFO("Audio device removed, reset the audio status info. m_isAudioStatusInfoUpdated :%d, m_audioStatusReceived :%d, m_audioStatusTimerStarted:%d ", m_isAudioStatusInfoUpdated,m_audioStatusReceived,m_audioStatusTimerStarted);
23962420
while (index != _hdmiCecSourceNotifications.end()) {
23972421
(*index)->ReportAudioDeviceConnectedStatus("success", "false");
23982422
index++;
@@ -2642,29 +2666,44 @@ namespace WPEFramework
26422666
_instance->allocateLogicalAddress(DeviceType::TV);
26432667
if ( _instance->m_logicalAddressAllocated != LogicalAddress::UNREGISTERED)
26442668
{
2645-
logicalAddress = LogicalAddress(_instance->m_logicalAddressAllocated);
2646-
LibCCEC::getInstance().addLogicalAddress(logicalAddress);
2647-
_instance->smConnection->setSource(logicalAddress);
2648-
_instance->m_numberOfDevices = 0;
2649-
_instance->deviceList[_instance->m_logicalAddressAllocated].m_deviceType = DeviceType::TV;
2650-
_instance->deviceList[_instance->m_logicalAddressAllocated].m_isDevicePresent = true;
2651-
_instance->deviceList[_instance->m_logicalAddressAllocated].update(physical_addr);
2652-
_instance->deviceList[_instance->m_logicalAddressAllocated].m_cecVersion = Version::V_1_4;
2653-
_instance->deviceList[_instance->m_logicalAddressAllocated].m_vendorID = appVendorId;
2654-
_instance->deviceList[_instance->m_logicalAddressAllocated].m_powerStatus = PowerStatus(powerState);
2655-
_instance->deviceList[_instance->m_logicalAddressAllocated].m_currentLanguage = defaultLanguage;
2656-
_instance->deviceList[_instance->m_logicalAddressAllocated].m_osdName = osdName.toString().c_str();
2657-
if(cecVersion == 2.0) {
2658-
_instance->deviceList[_instance->m_logicalAddressAllocated].m_cecVersion = Version::V_2_0;
2659-
_instance->smConnection->sendTo(LogicalAddress(LogicalAddress::BROADCAST),
2660-
MessageEncoder().encode(ReportFeatures(Version::V_2_0,allDevicetype,rcProfile,deviceFeatures)), 500);
2669+
try{
2670+
2671+
logicalAddress = LogicalAddress(_instance->m_logicalAddressAllocated);
2672+
LibCCEC::getInstance().addLogicalAddress(logicalAddress);
2673+
_instance->smConnection->setSource(logicalAddress);
2674+
_instance->m_numberOfDevices = 0;
2675+
_instance->deviceList[_instance->m_logicalAddressAllocated].m_deviceType = DeviceType::TV;
2676+
_instance->deviceList[_instance->m_logicalAddressAllocated].m_isDevicePresent = true;
2677+
_instance->deviceList[_instance->m_logicalAddressAllocated].update(physical_addr);
2678+
_instance->deviceList[_instance->m_logicalAddressAllocated].m_cecVersion = Version::V_1_4;
2679+
_instance->deviceList[_instance->m_logicalAddressAllocated].m_vendorID = appVendorId;
2680+
_instance->deviceList[_instance->m_logicalAddressAllocated].m_powerStatus = PowerStatus(powerState);
2681+
_instance->deviceList[_instance->m_logicalAddressAllocated].m_currentLanguage = defaultLanguage;
2682+
_instance->deviceList[_instance->m_logicalAddressAllocated].m_osdName = osdName.toString().c_str();
2683+
if(cecVersion == 2.0) {
2684+
_instance->deviceList[_instance->m_logicalAddressAllocated].m_cecVersion = Version::V_2_0;
2685+
_instance->smConnection->sendTo(LogicalAddress(LogicalAddress::BROADCAST),
2686+
MessageEncoder().encode(ReportFeatures(Version::V_2_0,allDevicetype,rcProfile,deviceFeatures)), 500);
2687+
}
2688+
_instance->smConnection->addFrameListener(_instance->msgFrameListener);
2689+
_instance->smConnection->sendTo(LogicalAddress(LogicalAddress::BROADCAST),
2690+
MessageEncoder().encode(ReportPhysicalAddress(physical_addr, _instance->deviceList[_instance->m_logicalAddressAllocated].m_deviceType)), 100);
2691+
2692+
_instance->m_sleepTime = 0;
2693+
_instance->m_pollThreadState = POLL_THREAD_STATE_PING;
2694+
}
2695+
catch(InvalidStateException &e){
2696+
LOGWARN("InvalidStateException caught while allocated logical address. %s", e.what());
2697+
_instance->m_pollThreadState = POLL_THREAD_STATE_EXIT;
2698+
}
2699+
catch(IOException &e){
2700+
LOGWARN("IOException caught while allocated logical address. %s", e.what());
2701+
_instance->m_pollThreadState = POLL_THREAD_STATE_EXIT;
2702+
}
2703+
catch(...){
2704+
LOGWARN("Exception caught while allocated logical address.");
2705+
_instance->m_pollThreadState = POLL_THREAD_STATE_EXIT;
26612706
}
2662-
_instance->smConnection->addFrameListener(_instance->msgFrameListener);
2663-
_instance->smConnection->sendTo(LogicalAddress(LogicalAddress::BROADCAST),
2664-
MessageEncoder().encode(ReportPhysicalAddress(physical_addr, _instance->deviceList[_instance->m_logicalAddressAllocated].m_deviceType)), 100);
2665-
2666-
_instance->m_sleepTime = 0;
2667-
_instance->m_pollThreadState = POLL_THREAD_STATE_PING;
26682707
}
26692708
else
26702709
{
@@ -2900,9 +2939,14 @@ namespace WPEFramework
29002939
{
29012940
LibCCEC::getInstance().init("HdmiCecSink");
29022941
}
2903-
catch (const std::exception& e)
2904-
{
2905-
LOGWARN("CEC exception caught from LibCCEC::getInstance().init()");
2942+
catch(InvalidStateException &e){
2943+
LOGWARN("InvalidStateException caught in LibCCEC::init %s", e.what());
2944+
}
2945+
catch(IOException &e){
2946+
LOGWARN("IOException caught in LibCCEC::init %s", e.what());
2947+
}
2948+
catch(...){
2949+
LOGWARN("Exception caught in LibCCEC::init");
29062950
}
29072951
}
29082952
libcecInitStatus++;
@@ -2998,7 +3042,14 @@ namespace WPEFramework
29983042
}
29993043

30003044
m_logicalAddressAllocated = LogicalAddress::UNREGISTERED;
3001-
m_currentArcRoutingState = ARC_STATE_ARC_TERMINATED;
3045+
m_currentArcRoutingState = ARC_STATE_ARC_TERMINATED;
3046+
if (m_audioStatusDetectionTimer.isActive()){
3047+
m_audioStatusDetectionTimer.stop();
3048+
}
3049+
m_isAudioStatusInfoUpdated = false;
3050+
m_audioStatusReceived = false;
3051+
m_audioStatusTimerStarted = false;
3052+
LOGINFO("CEC Disabled, reset the audio status info. m_isAudioStatusInfoUpdated :%d, m_audioStatusReceived :%d, m_audioStatusTimerStarted:%d ", m_isAudioStatusInfoUpdated,m_audioStatusReceived,m_audioStatusTimerStarted);
30023053

30033054
for(int i=0; i< 16; i++)
30043055
{
@@ -3014,10 +3065,14 @@ namespace WPEFramework
30143065
{
30153066
LibCCEC::getInstance().term();
30163067
}
3017-
catch (const std::exception& e)
3018-
{
3019-
LOGWARN("CEC exception caught from LibCCEC::getInstance().term() ");
3068+
catch(InvalidStateException &e){
3069+
LOGWARN("InvalidStateException caught in LibCCEC::term %s", e.what());
30203070
}
3071+
catch(IOException &e){
3072+
LOGWARN("IOException caught in LibCCEC::term %s", e.what());
3073+
}
3074+
catch(...){
3075+
LOGWARN("Exception caught in LibCCEC::term");
30213076
}
30223077

30233078
libcecInitStatus--;
@@ -3253,12 +3308,45 @@ namespace WPEFramework
32533308

32543309
if((_instance->m_SendKeyQueue.size()<=1 || (_instance->m_SendKeyQueue.size() % 2 == 0)) && ((keyInfo.keyCode == VOLUME_UP) || (keyInfo.keyCode == VOLUME_DOWN) || (keyInfo.keyCode == MUTE)) )
32553310
{
3256-
_instance->sendGiveAudioStatusMsg();
3311+
if(keyInfo.keyCode == MUTE)
3312+
{
3313+
_instance->sendGiveAudioStatusMsg();
3314+
}
3315+
else
3316+
{
3317+
LOGINFO("m_isAudioStatusInfoUpdated :%d, m_audioStatusReceived :%d, m_audioStatusTimerStarted:%d ",_instance->m_isAudioStatusInfoUpdated,_instance->m_audioStatusReceived,_instance->m_audioStatusTimerStarted);
3318+
if (!_instance->m_isAudioStatusInfoUpdated)
3319+
{
3320+
if ( !(_instance->m_audioStatusDetectionTimer.isActive()))
3321+
{
3322+
LOGINFO("Audio status info not updated. Starting the Timer!");
3323+
_instance->m_audioStatusTimerStarted = true;
3324+
_instance->m_audioStatusDetectionTimer.start((HDMICECSINK_UPDATE_AUDIO_STATUS_INTERVAL_MS));
3325+
}
3326+
LOGINFO("m_isAudioStatusInfoUpdated :%d, m_audioStatusReceived :%d, m_audioStatusTimerStarted:%d ", _instance->m_isAudioStatusInfoUpdated,_instance->m_audioStatusReceived,_instance->m_audioStatusTimerStarted);
3327+
}
3328+
else
3329+
{
3330+
if (!_instance->m_audioStatusReceived){
3331+
_instance->sendGiveAudioStatusMsg();
3332+
}
3333+
}
3334+
}
3335+
}
32573336
}
32583337

32593338
}//while(!_instance->m_sendKeyEventThreadExit)
32603339
}//threadSendKeyEvent
32613340

3341+
void HdmiCecSinkImplementation::audioStatusTimerFunction()
3342+
{
3343+
m_audioStatusTimerStarted = false;
3344+
m_isAudioStatusInfoUpdated = true;
3345+
LOGINFO("Timer Expired. Requesting the AudioStatus since not received.\n");
3346+
sendGiveAudioStatusMsg();
3347+
LOGINFO("m_isAudioStatusInfoUpdated :%d, m_audioStatusReceived :%d, m_audioStatusTimerStarted:%d ", m_isAudioStatusInfoUpdated,m_audioStatusReceived,m_audioStatusTimerStarted);
3348+
}
3349+
32623350

32633351
void HdmiCecSinkImplementation::threadArcRouting()
32643352
{
@@ -3269,7 +3357,7 @@ namespace WPEFramework
32693357
return;
32703358

32713359
LOGINFO("Running threadArcRouting");
3272-
3360+
_instance->getHdmiArcPortID();
32733361

32743362
while(1)
32753363
{

HdmiCecSink/HdmiCecSinkImplementation.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,8 @@ namespace WPEFramework {
576576
void sendGiveAudioStatusMsg();
577577
void onPowerModeChanged(const PowerState &currentState, const PowerState &newState);
578578
void registerEventHandlers();
579+
void sendGiveAudioStatusMsg();
580+
void getHdmiArcPortID();
579581
int m_numberOfDevices; /* Number of connected devices othethan own device */
580582
bool m_audioDevicePowerStatusRequested;
581583

@@ -643,6 +645,9 @@ namespace WPEFramework {
643645
/* Send Key event related */
644646
bool m_sendKeyEventThreadExit;
645647
bool m_sendKeyEventThreadRun;
648+
bool m_isAudioStatusInfoUpdated;
649+
bool m_audioStatusReceived;
650+
bool m_audioStatusTimerStarted;
646651
std::thread m_sendKeyEventThread;
647652
std::mutex m_sendKeyEventMutex;
648653
std::queue<SendKeyInfo> m_SendKeyQueue;
@@ -661,6 +666,7 @@ namespace WPEFramework {
661666
binary_semaphore m_semSignaltoArcRoutingThread;
662667
bool m_arcstarting;
663668
TpTimer m_arcStartStopTimer;
669+
TpTimer m_audioStatusDetectionTimer;
664670

665671
Connection *smConnection;
666672
std::vector<uint8_t> m_connectedDevices;
@@ -707,6 +713,7 @@ namespace WPEFramework {
707713
void Send_Request_Arc_Termination_Message();
708714
void Send_Report_Arc_Terminated_Message();
709715
void arcStartStopTimerFunction();
716+
void audioStatusTimerFunction();
710717
void getHdmiArcPortID();
711718
void getCecVersion();
712719

0 commit comments

Comments
 (0)