38 #include <sys/types.h>
43 #include "libIBusDaemon.h"
56 #include "dsVideoResolutionSettings.h"
58 #include "dsAudioSettings.h"
60 #include "safec_lib.h"
64 extern IARM_Result_t _dsSetResolution(
void *arg);
65 extern IARM_Result_t _dsGetResolution(
void *arg);
66 extern IARM_Result_t _dsInitResolution(
void *arg);
67 extern IARM_Result_t _dsGetAudioPort(
void *arg);
68 extern IARM_Result_t _dsGetStereoMode(
void *arg);
69 extern IARM_Result_t _dsSetStereoMode(
void *arg);
70 extern IARM_Result_t _dsGetEDID(
void *arg);
71 extern IARM_Result_t _dsGetEDIDBytes(
void *arg);
72 extern IARM_Result_t _dsGetVideoPort(
void *arg);
73 extern IARM_Result_t _dsIsDisplayConnected(
void *arg);
74 extern IARM_Result_t _dsGetStereoAuto(
void *arg);
75 extern IARM_Result_t _dsIsDisplaySurround(
void *arg);
76 extern IARM_Result_t _dsGetForceDisable4K(
void *arg);
77 extern IARM_Result_t _dsSetBackgroundColor(
void *arg);
78 extern IARM_Result_t _dsGetIgnoreEDIDStatus(
void *arg);
79 extern bool isComponentPortPresent();
81 extern bool dsGetHDMIDDCLineStatus(
void);
82 static int _SetVideoPortResolution();
84 static void _EventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
87 static int iTuneReady = 0;
88 static dsDisplayEvent_t edisplayEventStatus = dsDISPLAY_EVENT_MAX;
89 static pthread_t edsHDMIHPDThreadID;
90 static pthread_mutex_t tdsMutexLock;
91 static pthread_cond_t tdsMutexCond;
94 void _setEASAudioMode();
95 static int iResnCount = 5;
96 static int iInitResnFlag = 0;
97 static bool bHDCPAuthenticated =
false;
98 static bool bPwrMgeRFCEnabled =
false;
99 IARM_Bus_Daemon_SysMode_t isEAS = IARM_BUS_SYS_MODE_NORMAL;
101 #define RFC_PWRMGR2 "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Power.PwrMgr2.Enable"
106 GMainLoop *dsMgr_Gloop = NULL;
107 static gboolean heartbeatMsg(gpointer data);
108 static gboolean _SetResolutionHandler(gpointer data);
109 static guint hotplug_event_src = 0;
110 static gboolean dumpEdidOnChecksumDiff(gpointer data);
111 static bool IsIgnoreEdid_gs =
false;
117 memset(&vidPortParam, 0,
sizeof(vidPortParam));
118 vidPortParam.type = port;
119 vidPortParam.index = 0;
120 _dsGetVideoPort(&vidPortParam);
121 return vidPortParam.handle;
124 static bool isHDMIConnected()
128 memset(&ConParam, 0,
sizeof(ConParam));
130 _dsIsDisplayConnected(&ConParam);
131 return ConParam.connected;
134 IARM_Result_t DSMgr_Start()
136 FILE *fDSCtrptr = NULL;
140 setvbuf(stdout, NULL, _IOLBF, 0);
141 INT_INFO(
"Entering [%s] - [%s] - disabling io redirect buf \r\n", __FUNCTION__, IARM_BUS_DSMGR_NAME);
153 memset(&ignoreEdidParam,0,
sizeof(ignoreEdidParam));
155 _dsGetIgnoreEDIDStatus(&ignoreEdidParam);
156 IsIgnoreEdid_gs = ignoreEdidParam.ignoreEDID;
157 __TIMESTAMP();printf(
"ResOverride DSMgr_Start IsIgnoreEdid_gs: %d\n", IsIgnoreEdid_gs);
166 RFC_ParamData_t rfcParam;
167 WDMP_STATUS status = getRFCParameter(
"dsMgr", RFC_PWRMGR2, &rfcParam);
168 if(strncmp(rfcParam.value,
"true",4) == 0)
170 bPwrMgeRFCEnabled=
true;
171 __TIMESTAMP(); printf(
"dsMgr:RFC PwrMgr2 feature enabled \r\n");
174 if(bPwrMgeRFCEnabled)
177 initPwrEventListner();
180 pthread_mutex_init (&tdsMutexLock, NULL);
181 pthread_cond_init (&tdsMutexCond, NULL);
188 fDSCtrptr = fopen(
"/opt/ddcDelay",
"r");
189 if (NULL != fDSCtrptr)
191 if(0 > fscanf(fDSCtrptr,
"%d",&iResnCount))
193 INT_INFO(
"Error: fscanf on ddcDelay failed");
197 __TIMESTAMP(); printf(
"Retry DS manager Resolution count is iResnCount = %d \r\n",iResnCount);
201 __TIMESTAMP(); printf(
"Tune Ready Status on start up is %d \r\n",tuneReadyParam.TuneReadyStatus.state);
204 if(1 == tuneReadyParam.TuneReadyStatus.state)
210 dsMgr_Gloop = g_main_loop_new ( NULL , FALSE );
211 if(dsMgr_Gloop != NULL){
212 g_timeout_add_seconds (300 , heartbeatMsg , dsMgr_Gloop);
215 INT_INFO(
"Fails to Create a main Loop for [%s] \r\n",IARM_BUS_DSMGR_NAME);
218 if(!isHDMIConnected())
220 __TIMESTAMP();printf(
"HDMI not connected at bootup -Schedule a handler to set the resolution .. \r\n");
221 _SetVideoPortResolution();
223 return IARM_RESULT_SUCCESS;
226 IARM_Result_t DSMgr_Loop()
232 g_main_loop_run (dsMgr_Gloop);
233 g_main_loop_unref(dsMgr_Gloop);
235 return IARM_RESULT_SUCCESS;
238 static gboolean heartbeatMsg(gpointer data)
242 INT_INFO(
"I-ARM BUS DS Mgr: HeartBeat at %s\r\n", ctime(&curr));
246 IARM_Result_t DSMgr_Stop()
251 g_main_loop_quit(dsMgr_Gloop);
256 pthread_mutex_destroy (&tdsMutexLock);
257 pthread_cond_destroy (&tdsMutexCond);
259 return IARM_RESULT_SUCCESS;
274 IARM_Bus_CommonAPI_SysModeChange_Param_t *param = (IARM_Bus_CommonAPI_SysModeChange_Param_t *)arg;
275 IARM_Bus_Daemon_SysMode_t isNextEAS = IARM_BUS_SYS_MODE_NORMAL;
277 __TIMESTAMP();printf(
"[DSMgr] Recvd Sysmode Change::New mode --> %d,Old mode --> %d",param->newMode,param->oldMode);
279 if ((param->newMode == IARM_BUS_SYS_MODE_EAS) ||
280 (param->newMode == IARM_BUS_SYS_MODE_NORMAL))
282 isNextEAS = param->newMode;
287 return IARM_RESULT_SUCCESS;
290 if ((isEAS == IARM_BUS_SYS_MODE_EAS) && (isNextEAS == IARM_BUS_SYS_MODE_NORMAL) ) {
291 isEAS = IARM_BUS_SYS_MODE_NORMAL;
294 else if ((isEAS == IARM_BUS_SYS_MODE_NORMAL) && (isNextEAS == IARM_BUS_SYS_MODE_EAS) ) {
298 isEAS = IARM_BUS_SYS_MODE_EAS;
305 return IARM_RESULT_SUCCESS;
312 memset(&vidPortParam, 0,
sizeof(vidPortParam));
314 vidPortParam.index = 0;
315 _dsGetVideoPort(&vidPortParam);
318 if(vidPortParam.handle != NULL)
321 memset(&setBGColorParam, 0,
sizeof(setBGColorParam));
322 setBGColorParam.color = color;
323 setBGColorParam.handle= vidPortParam.handle;
324 _dsSetBackgroundColor(&setBGColorParam);
330 static void _EventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
336 if (eventId != IARM_BUS_SYSMGR_EVENT_SYSTEMSTATE)
return;
339 IARM_Bus_SYSMgr_SystemState_t stateId = sysEventData->data.systemStates.stateId;
340 int state = sysEventData->data.systemStates.state;
341 __TIMESTAMP();printf(
"_sysEventHandler invoked for stateid %d of state %d \r\n", stateId, state);
343 case IARM_BUS_SYSMGR_SYSSTATE_TUNEREADY:
344 __TIMESTAMP();printf(
"Tune Ready Evenets in DS Manager \r\n");
354 pthread_mutex_lock(&tdsMutexLock);
355 pthread_cond_signal(&tdsMutexCond);
356 pthread_mutex_unlock(&tdsMutexLock);
362 }
else if (strcmp(owner,IARM_BUS_DSMGR_NAME) == 0)
370 __TIMESTAMP();printf(
"[DsMgr] Got HDMI %s Event \r\n",(eventData->data.hdmi_hpd.event ==
dsDISPLAY_EVENT_CONNECTED ?
"Connect" :
"Disconnect"));
375 pthread_mutex_lock(&tdsMutexLock);
377 pthread_cond_signal(&tdsMutexCond);
378 pthread_mutex_unlock(&tdsMutexLock);
386 int status = eventData->data.hdmi_hdcp.hdcpStatus;
390 HDCPeventData.data.systemStates.stateId = IARM_BUS_SYSMGR_SYSSTATE_HDCP_ENABLED;
391 HDCPeventData.data.systemStates.state = 1;
394 __TIMESTAMP();printf(
"Changed status to HDCP Authentication Pass !!!!!!!! ..\r\n");
395 HDCPeventData.data.systemStates.state = 1;
396 bHDCPAuthenticated =
true;
397 __TIMESTAMP();printf(
"HDCP success - Removed hotplug_event_src Time source %d and set resolution immediately \r\n",hotplug_event_src);
398 if(hotplug_event_src)
400 g_source_remove(hotplug_event_src);
401 hotplug_event_src = 0;
404 if (!IsIgnoreEdid_gs) {
405 _SetVideoPortResolution();
407 g_timeout_add_seconds((guint)1,dumpEdidOnChecksumDiff,NULL);
411 __TIMESTAMP();printf(
"Changed status to HDCP Authentication Fail !!!!!!!! ..\r\n");
412 HDCPeventData.data.systemStates.state = 0;
414 bHDCPAuthenticated =
false;
415 if (!IsIgnoreEdid_gs) {
416 _SetVideoPortResolution();
418 g_timeout_add_seconds((guint)1,dumpEdidOnChecksumDiff,NULL);
432 static int _SetVideoPortResolution()
434 intptr_t _hdmihandle = 0;
435 intptr_t _comphandle = 0;
436 bool connected=
false;
440 __TIMESTAMP(); printf(
"%s:Enter \r\n",__FUNCTION__);
443 if(_hdmihandle != NULL)
452 connected = isHDMIConnected();
453 if(iInitResnFlag && connected)
456 #ifdef _INIT_RESN_SETTINGS
458 while(iCount < iResnCount)
461 if (dsGetHDMIDDCLineStatus())
465 __TIMESTAMP(); printf (
"Waiting for HDMI DDC Line to be ready for resolution Change...\r\n");
474 __TIMESTAMP(); printf(
"Setting HDMI resolution.......... \r\n");
480 if (NULL != _comphandle)
482 __TIMESTAMP();printf(
"Setting Component/Composite Resolution.......... \r\n");
487 __TIMESTAMP();printf(
"%s: NULL Handle for component\r\n",__FUNCTION__);
491 if (NULL != _compositehandle)
493 __TIMESTAMP();printf(
"Setting BB Composite Resolution.......... \r\n");
498 __TIMESTAMP();printf(
"%s: NULL Handle for Composite \r\n",__FUNCTION__);
500 if (NULL != _rfhandle)
502 __TIMESTAMP();printf(
"Setting RF Resolution.......... \r\n");
507 __TIMESTAMP();printf(
"%s: NULL Handle for RF \r\n",__FUNCTION__);
516 __TIMESTAMP();printf(
"%s: NULL Handle for HDMI \r\n",__FUNCTION__);
518 __TIMESTAMP();printf(
"%s:Exit \r\n",__FUNCTION__);
536 intptr_t _displayHandle = 0;
537 int numResolutions = 0,i=0;
538 intptr_t _handle = *handle;
539 bool IsValidResolution =
false;
548 Setparam.forceCompatible =
false;
551 memset(&edidData, 0,
sizeof(edidData));
556 __TIMESTAMP();printf(
"_SetResolution - Got NULL Handle ..\r\n");
561 memset(&Getparam,0,
sizeof(Getparam));
562 Getparam.handle = _handle;
563 Getparam.toPersist =
true;
564 _dsGetResolution(&Getparam);
566 __TIMESTAMP();printf(
"Got User Persisted Resolution - %s..\r\n",presolution->
name);
575 memset(&Edidparam,0,
sizeof(Edidparam));
576 Edidparam.handle = _displayHandle;
577 _dsGetEDID(&Edidparam);
578 rc = memcpy_s(&edidData,
sizeof(edidData), &Edidparam.edid,
sizeof(Edidparam.edid));
583 dumpHdmiEdidInfo(&edidData);
585 __TIMESTAMP();printf(
"numResolutions is %d \r\n",numResolutions);
595 __TIMESTAMP();printf(
"Do not Set Resolution..The HDMI is not Ready !! \r\n");
596 __TIMESTAMP();printf(
"numResolutions = %d edidData.hdmiDeviceType = %d !! \r\n",numResolutions,edidData.
hdmiDeviceType);
604 for (i = 0; i < numResolutions; i++)
607 printf(
"presolution->name : %s, resolution->name : %s\r\n",presolution->
name,setResn->
name);
608 if ((strcmp(presolution->
name,setResn->
name) == 0 ))
610 __TIMESTAMP();printf(
"Breaking..Got Platform Resolution - %s..\r\n",setResn->
name);
611 IsValidResolution =
true;
612 Setparam.forceCompatible =
true;
620 if (
false == IsValidResolution)
623 for (i = numResolutions-1; i >= 0; i--)
626 int pNumResolutions =
dsUTL_DIM(kResolutions);
627 for (
int j = pNumResolutions-1; j >=0; j--)
630 if (0 == (strcmp(pfResolution->
name,setResn->
name)))
632 __TIMESTAMP();printf(
"[DsMgr] Set Best TV Supported Resolution %s \r\n",pfResolution->
name);
633 IsValidResolution =
true;
637 if (IsValidResolution)
648 if (
false == IsValidResolution)
652 defaultResn = &kResolutions[kDefaultResIndex];
653 for (i = 0; i < numResolutions; i++)
657 if ((strcmp(defaultResn->
name,setResn->
name) == 0 ))
659 IsValidResolution =
true;
660 __TIMESTAMP();printf(
"Breaking..Got Default Platform Resolution - %s..\r\n",setResn->
name);
666 if (
false == IsValidResolution)
669 for (i = 0; i < numResolutions; i++)
672 if ((strcmp(
"480p",setResn->
name) == 0 ))
674 __TIMESTAMP();printf(
"Breaking..Default to 480p Resolution - %s..\r\n",setResn->
name);
675 IsValidResolution =
true;
681 if (
false == IsValidResolution)
684 for (i = 0; i < numResolutions; i++)
687 size_t numResolutions =
dsUTL_DIM(kResolutions);
688 for (
size_t j = 0; j < numResolutions; j++)
691 if (0 == (strcmp(pfResolution->
name,setResn->
name)))
693 __TIMESTAMP();printf(
"[DsMgr] Boot with TV Supported Resolution %s \r\n",pfResolution->
name);
694 IsValidResolution =
true;
705 numResolutions =
dsUTL_DIM(kResolutions);
706 for (i = 0; i < numResolutions; i++)
708 setResn = &kResolutions[i];
709 if ((strcmp(presolution->
name,setResn->
name) == 0 ))
711 __TIMESTAMP();printf(
"Breaking..Got Platform Resolution - %s..\r\n",setResn->
name);
712 IsValidResolution =
true;
722 if(
false == IsValidResolution)
724 setResn = &kResolutions[kDefaultResIndex];
728 Setparam.handle = _handle;
729 Setparam.toPersist =
false;
733 memset(&res_4K_override, 0,
sizeof(res_4K_override));
734 _dsGetForceDisable4K((
void *) &res_4K_override);
735 if(
true == res_4K_override.disable)
737 if(0 == strncmp(presolution->
name,
"2160", 4))
739 __TIMESTAMP();printf(
"User persisted 4K resolution. Now limiting to default (720p?) as 4K support is now disabled.\n");
740 setResn = &kResolutions[kDefaultResIndex];
744 Setparam.resolution = *setResn;
747 #ifdef _INIT_RESN_SETTINGS
748 if(0 == iInitResnFlag)
750 printf(
"Init Platform Resolution - %s..\r\n",setResn->
name);
751 _dsInitResolution(&Setparam);
756 _dsSetResolution(&Setparam);
775 __TIMESTAMP(); printf (
"_DSMgrResnThreadFunc... wait for for HDMI or Tune Ready Events \r\n");
778 pthread_mutex_lock(&tdsMutexLock);
779 pthread_cond_wait(&tdsMutexCond, &tdsMutexLock);
780 pthread_mutex_unlock(&tdsMutexLock);
782 __TIMESTAMP();printf(
"%s: Setting Resolution On:: HDMI %s Event with TuneReady status = %d \r\n",__FUNCTION__, (edisplayEventStatus ==
dsDISPLAY_EVENT_CONNECTED ?
"Connect" :
"Disconnect"),iTuneReady);
786 if(hotplug_event_src)
788 g_source_remove(hotplug_event_src);
789 __TIMESTAMP();printf(
"Removed Hot Plug Event Time source %d \r\n",hotplug_event_src);
790 hotplug_event_src = 0;
796 if(bHDCPAuthenticated)
798 _SetVideoPortResolution();
808 bHDCPAuthenticated =
false;
809 if(isComponentPortPresent())
811 hotplug_event_src = g_timeout_add_seconds((guint)5,_SetResolutionHandler,dsMgr_Gloop);
812 __TIMESTAMP();printf(
"Schedule a handler to set the resolution after 5 sec for %d time src.. \r\n",hotplug_event_src);
821 static gboolean _SetResolutionHandler(gpointer data)
823 __TIMESTAMP();printf(
"Set Video Resolution after delayed time .. \r\n");
824 _SetVideoPortResolution();
825 hotplug_event_src = 0;
830 void _setEASAudioMode()
833 if (isEAS != IARM_BUS_SYS_MODE_EAS) {
834 __TIMESTAMP();printf(
"EAS Not In progress..Do not Modify Audio \r\n");
842 numPorts =
dsUTL_DIM(kSupportedPortTypes);
843 for (i=0; i < numPorts; i++)
846 memset(&getHandle, 0,
sizeof(getHandle));
847 getHandle.type = *audioPort;
849 _dsGetAudioPort (&getHandle);
851 memset(&setMode, 0,
sizeof(setMode));
852 setMode.handle = getHandle.handle;
853 setMode.toPersist =
false;
854 _dsGetStereoMode(&setMode);
861 __TIMESTAMP();printf(
"EAS Audio mode for audio port %d is : %d \r\n",getHandle.type, setMode.mode);
862 setMode.toPersist =
false;
863 _dsSetStereoMode (&setMode);
877 if (isEAS == IARM_BUS_SYS_MODE_EAS) {
878 __TIMESTAMP();printf(
"EAS In progress..Do not Modify Audio \r\n");
886 numPorts =
dsUTL_DIM(kSupportedPortTypes);
887 for (i=0; i < numPorts; i++)
890 memset(&getHandle, 0,
sizeof(getHandle));
891 getHandle.type = *audioPort;
893 _dsGetAudioPort (&getHandle);
895 memset(&setMode, 0,
sizeof(setMode));
896 setMode.handle = getHandle.handle;
897 setMode.toPersist =
true;
898 _dsGetStereoMode(&setMode);
903 intptr_t vHandle = 0;
906 bool IsSurround =
false;
909 memset(¶m, 0,
sizeof(param));
912 _dsGetVideoPort(¶m);
913 vHandle = param.handle;
918 memset(¶m, 0,
sizeof(param));
919 param.handle = vHandle;
920 _dsIsDisplayConnected(¶m);
921 connected = param.connected;
926 __TIMESTAMP();printf(
"HDMI Not Connected ..Do not Set Audio on HDMI !!! \r\n");
932 memset(¶m, 0,
sizeof(param));
933 param.handle = getHandle.handle;
934 _dsGetStereoAuto(¶m);
935 autoMode = param.autoMode;
948 param.handle = vHandle;
949 param.surround =
false;
950 _dsIsDisplaySurround(¶m);
951 IsSurround = param.surround;
960 __TIMESTAMP();printf(
"Surround mode not Supported on HDMI ..Set Stereo \r\n");
963 __TIMESTAMP();printf(
"Audio mode for audio port %d is : %d \r\n",getHandle.type, setMode.mode);
964 setMode.toPersist =
false;
965 _dsSetStereoMode (&setMode);
977 __TIMESTAMP();printf(
"Connected HDMI Display Device Info !!!!!\r\n");
979 if (NULL == pedidData) {
980 __TIMESTAMP(); printf(
"Received EDID is NULL \r\n");
985 printf(
"HDMI Monitor Name is %s \r\n",pedidData->
monitorName);
986 printf(
"HDMI Manufacturing ID is %d \r\n",pedidData->
serialNumber);
987 printf(
"HDMI Product Code is %d \r\n",pedidData->
productCode);
988 printf(
"HDMI Device Type is %s \r\n",pedidData->
hdmiDeviceType?
"HDMI":
"DVI");
989 printf(
"HDMI Sink Device %s a Repeater \r\n",pedidData->
isRepeater?
"is":
"is not");
990 printf(
"HDMI Physical Address is %d:%d:%d:%d \r\n",pedidData->
physicalAddressA,
995 static gboolean dumpEdidOnChecksumDiff(gpointer data) {
996 __TIMESTAMP();printf(
"dumpEdidOnChecksumDiff HDMI-EDID Dump>>>>>>>>>>>>>>\r\n");
997 intptr_t _displayHandle = 0;
999 if (_displayHandle) {
1002 static int cached_EDID_checksum = 0;
1003 int current_EDID_checksum = 0;
1004 memset(&EdidBytesParam,0,
sizeof(EdidBytesParam));
1005 EdidBytesParam.handle = _displayHandle;
1006 _dsGetEDIDBytes(&EdidBytesParam);
1007 length = EdidBytesParam.length;
1009 if((length > 0) && (length <= 512)) {
1010 unsigned char* edidBytes = EdidBytesParam.bytes;
1011 for (
int i = 0; i < (length / 128); i++)
1012 current_EDID_checksum += edidBytes[(i+1)*128 - 1];
1014 if((cached_EDID_checksum == 0) || (current_EDID_checksum != cached_EDID_checksum)) {
1015 cached_EDID_checksum = current_EDID_checksum;
1016 __TIMESTAMP();printf(
"HDMI-EDID Dump BEGIN>>>>>>>>>>>>>>\r\n");
1017 for (
int i = 0; i < length; i++) {
1024 printf(
"%02X ", edidBytes[i]);
1026 printf(
"\nHDMI-EDID Dump END>>>>>>>>>>>>>>\r\n");