32 #include <sys/types.h>
47 #include "dsserverlogger.h"
49 #include "dsVideoPortSettings.h"
50 #include "dsVideoResolutionSettings.h"
52 #include "safec_lib.h"
54 static int m_isInitialized = 0;
55 static int m_isPlatInitialized = 0;
56 static pthread_mutex_t dsLock = PTHREAD_MUTEX_INITIALIZER;
59 #define IARM_BUS_Lock(lock) pthread_mutex_lock(&dsLock)
60 #define IARM_BUS_Unlock(lock) pthread_mutex_unlock(&dsLock)
62 IARM_Result_t _dsDisplayInit(
void *arg);
63 IARM_Result_t _dsGetDisplay(
void *arg);
64 IARM_Result_t _dsGetDisplayAspectRatio(
void *arg);
65 IARM_Result_t _dsGetEDID(
void *arg);
66 IARM_Result_t _dsGetEDIDBytes(
void *arg);
67 IARM_Result_t _dsDisplayTerm(
void *arg);
68 void _dsDisplayEventCallback(intptr_t handle, dsDisplayEvent_t event,
void *eventData);
69 static void filterEDIDResolution(intptr_t Shandle,
dsDisplayEDID_t *edid);
71 extern void resetColorDepthOnHdmiReset(intptr_t handle);
72 static intptr_t _hdmiVideoPortHandle = 0;
74 IARM_Result_t dsDisplayMgr_init()
77 if (!m_isPlatInitialized) {
82 m_isPlatInitialized++;
84 IARM_BUS_Unlock(lock);
86 return IARM_RESULT_SUCCESS;
89 IARM_Result_t dsDisplayMgr_term()
91 return IARM_RESULT_SUCCESS;
94 IARM_Result_t _dsDisplayInit(
void *arg)
98 if (!m_isInitialized) {
112 if (!m_isPlatInitialized) {
116 m_isPlatInitialized++;
117 IARM_BUS_Unlock(lock);
118 return IARM_RESULT_SUCCESS;
122 IARM_Result_t _dsGetDisplay(
void *arg)
129 dsGetDisplay(param->type, param->index, ¶m->handle);
131 IARM_BUS_Unlock(lock);
133 return IARM_RESULT_SUCCESS;
136 IARM_Result_t _dsGetDisplayAspectRatio(
void *arg)
146 IARM_BUS_Unlock(lock);
148 return IARM_RESULT_SUCCESS;
151 IARM_Result_t _dsGetEDID(
void *arg)
162 filterEDIDResolution(param->handle, ¶m->edid);
164 IARM_BUS_Unlock(lock);
166 return IARM_RESULT_SUCCESS;
169 IARM_Result_t _dsGetEDIDBytes(
void *arg)
172 #ifndef RDK_DSHAL_NAME
173 #warning "RDK_DSHAL_NAME is not defined"
174 #define RDK_DSHAL_NAME "RDK_DSHAL_NAME is not defined"
181 printf(
"dsSRV::getEDIDBytes \r\n");
183 typedef dsError_t (*dsGetEDIDBytes_t)(intptr_t handle,
unsigned char **edid,
int *length);
184 static dsGetEDIDBytes_t func = 0;
186 void *dllib = dlopen(RDK_DSHAL_NAME, RTLD_LAZY);
188 func = (dsGetEDIDBytes_t) dlsym(dllib,
"dsGetEDIDBytes");
190 printf(
"dsGetEDIDBytes(void) is defined and loaded\r\n");
193 printf(
"dsGetEDIDBytes(void) is not defined\r\n");
198 printf(
"Opening RDK_DSHAL_NAME [%s] failed\r\n", RDK_DSHAL_NAME);
205 unsigned char *edid = NULL;
207 dsError_t ret = func(param->handle, &edid, &length);
209 printf(
"dsSRV ::getEDIDBytes returns %d bytes\r\n", length);
210 rc = memcpy_s(param->bytes,
sizeof(param->bytes),edid,length);
215 param->length = length;
224 IARM_BUS_Unlock(lock);
226 return IARM_RESULT_SUCCESS;
229 IARM_Result_t _dsDisplayTerm(
void *arg)
235 m_isPlatInitialized--;
237 if (0 == m_isPlatInitialized)
242 IARM_BUS_Unlock(lock);
243 return IARM_RESULT_SUCCESS;
248 void _dsDisplayEventCallback(intptr_t handle, dsDisplayEvent_t event,
void *eventData)
254 if (NULL_HANDLE == handle)
256 printf(
"Err:HDMI Hot plug back has NULL Handle... !!!!!!..\r\n");
261 __TIMESTAMP();printf(
"connecting HDMI to display !!!!!!..\r\n");
267 __TIMESTAMP();printf(
"Disconnecting HDMI from display !!!!!!!! ..\r\n");
273 __TIMESTAMP();printf(
"Rx Sense Status ON !!!!!!!! ..\r\n");
279 __TIMESTAMP();printf(
"Rx Sense Status OFF !!!!!!!! ..\r\n");
285 __TIMESTAMP();printf(
"HDCP Protocol Version Change !!!!!!!! ..\r\n");
290 printf(
"Error: Unsupported event in _dsHdmiCallback...\r\n");
297 if (!_hdmiVideoPortHandle){
300 _hdmiVideoPortHandle = 0;
303 if (_hdmiVideoPortHandle){
304 resetColorDepthOnHdmiReset(_hdmiVideoPortHandle);
306 __TIMESTAMP();printf(
"HDMI get port handle failed %d \r\n", eRet);
311 static void filterEDIDResolution(intptr_t handle,
dsDisplayEDID_t *edid)
318 int numOfSupportedResolution = 0;
322 printf(
"EDID for HDMI Port\r\n");
326 memset(&edidData,0,
sizeof(edidData));
328 rc = memcpy_s(&edidData,
sizeof(edidData),edid,
sizeof(edidData));
335 for (
size_t i = 0; i < iCount; i++)
337 presolution = &kResolutions[i];
342 if (0 == (strcmp(presolution->
name,edidResn->
name)))
346 numOfSupportedResolution++;
347 printf(
"[DsMgr] presolution->name : %s, resolution count : %d\r\n",presolution->
name,numOfSupportedResolution);
354 printf(
"EDID for Non HDMI Port\r\n");
361 intptr_t halhandle = 0;
363 numPorts =
dsUTL_DIM(kSupportedPortTypes);
364 for(i=0; i< numPorts; i++)
366 dsGetDisplay(kPorts[i].
id.type, kPorts[i].
id.index, &halhandle);
367 if (handle == halhandle)
369 return kPorts[i].id.type;
372 printf(
"Error: The Requested Display is not part of Platform Port Configuration \r\n");