RDK Documentation (Open Sourced RDK Components)
dsDisplay.c
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 
21 
22 /**
23 * @defgroup devicesettings
24 * @{
25 * @defgroup rpc
26 * @{
27 **/
28 
29 
30 #include "dsDisplay.h"
31 
32 #include <sys/types.h>
33 #include <stdint.h>
34 #include <string.h>
35 #include <stdlib.h>
36 #include <dlfcn.h>
37 #include "dsError.h"
38 #include "dsUtl.h"
39 #include "dsTypes.h"
40 #include "pthread.h"
41 #include <pthread.h>
42 #include "libIARM.h"
43 #include "libIBus.h"
44 #include "iarmUtil.h"
45 #include "dsRpc.h"
46 #include "dsMgr.h"
47 #include "dsserverlogger.h"
48 #include "dsVideoPort.h"
49 #include "dsVideoPortSettings.h"
50 #include "dsVideoResolutionSettings.h"
51 
52 #include "safec_lib.h"
53 
54 static int m_isInitialized = 0;
55 static int m_isPlatInitialized = 0;
56 static pthread_mutex_t dsLock = PTHREAD_MUTEX_INITIALIZER;
57 
58 #define NULL_HANDLE 0
59 #define IARM_BUS_Lock(lock) pthread_mutex_lock(&dsLock)
60 #define IARM_BUS_Unlock(lock) pthread_mutex_unlock(&dsLock)
61 
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);
70 static dsVideoPortType_t _GetDisplayPortType(intptr_t handle);
71 extern void resetColorDepthOnHdmiReset(intptr_t handle);
72 static intptr_t _hdmiVideoPortHandle = 0;
73 
74 IARM_Result_t dsDisplayMgr_init()
75 {
76  IARM_BUS_Lock(lock);
77  if (!m_isPlatInitialized) {
78  /* Nexus init, if any here */
79  dsDisplayInit();
80  }
81  /*coverity[missing_lock] CID-19379 using Coverity Annotation to ignore error*/
82  m_isPlatInitialized++;
83 
84  IARM_BUS_Unlock(lock); //CID:136387 - Data race condition
85  IARM_Bus_RegisterCall(IARM_BUS_DSMGR_API_dsDisplayInit, _dsDisplayInit);
86  return IARM_RESULT_SUCCESS;
87 }
88 
89 IARM_Result_t dsDisplayMgr_term()
90 {
91  return IARM_RESULT_SUCCESS;
92 }
93 
94 IARM_Result_t _dsDisplayInit(void *arg)
95 {
96  IARM_BUS_Lock(lock);
97 
98  if (!m_isInitialized) {
99 
100  /* Register appropriate dsRegisterDisplayEventCallback here*/
101  dsRegisterDisplayEventCallback(NULL,_dsDisplayEventCallback);
102 
103  IARM_Bus_RegisterCall(IARM_BUS_DSMGR_API_dsGetDisplay,_dsGetDisplay);
104  IARM_Bus_RegisterCall(IARM_BUS_DSMGR_API_dsGetDisplayAspectRatio,_dsGetDisplayAspectRatio);
105  IARM_Bus_RegisterCall(IARM_BUS_DSMGR_API_dsGetEDID,_dsGetEDID);
106  IARM_Bus_RegisterCall(IARM_BUS_DSMGR_API_dsGetEDIDBytes,_dsGetEDIDBytes);
107  IARM_Bus_RegisterCall(IARM_BUS_DSMGR_API_dsDisplayTerm,_dsDisplayTerm);
108 
109  m_isInitialized = 1;
110  }
111 
112  if (!m_isPlatInitialized) {
113  /* Nexus init, if any here */
114  dsDisplayInit();
115  }
116  m_isPlatInitialized++;
117  IARM_BUS_Unlock(lock);
118  return IARM_RESULT_SUCCESS;
119 
120 }
121 
122 IARM_Result_t _dsGetDisplay(void *arg)
123 {
124  _DEBUG_ENTER();
125 
126  IARM_BUS_Lock(lock);
127 
129  dsGetDisplay(param->type, param->index, &param->handle);
130 
131  IARM_BUS_Unlock(lock);
132 
133  return IARM_RESULT_SUCCESS;
134 }
135 
136 IARM_Result_t _dsGetDisplayAspectRatio(void *arg)
137 {
138  _DEBUG_ENTER();
139 
140  IARM_BUS_Lock(lock);
141 
143  dsGetDisplayAspectRatio(param->handle, &param->aspectRatio);
144 
145 
146  IARM_BUS_Unlock(lock);
147 
148  return IARM_RESULT_SUCCESS;
149 }
150 
151 IARM_Result_t _dsGetEDID(void *arg)
152 {
153  _DEBUG_ENTER();
154 
155  IARM_BUS_Lock(lock);
156 
158  dsVideoPortType_t _VPortType;
159 
160  dsGetEDID(param->handle, &param->edid);
161 
162  filterEDIDResolution(param->handle, &param->edid);
163 
164  IARM_BUS_Unlock(lock);
165 
166  return IARM_RESULT_SUCCESS;
167 }
168 
169 IARM_Result_t _dsGetEDIDBytes(void *arg)
170 {
171 
172 #ifndef RDK_DSHAL_NAME
173 #warning "RDK_DSHAL_NAME is not defined"
174 #define RDK_DSHAL_NAME "RDK_DSHAL_NAME is not defined"
175 #endif
176  errno_t rc = -1;
177  _DEBUG_ENTER();
178 
179  IARM_BUS_Lock(lock);
180 
181  printf("dsSRV::getEDIDBytes \r\n");
182 
183  typedef dsError_t (*dsGetEDIDBytes_t)(intptr_t handle, unsigned char **edid, int *length);
184  static dsGetEDIDBytes_t func = 0;
185  if (func == 0) {
186  void *dllib = dlopen(RDK_DSHAL_NAME, RTLD_LAZY);
187  if (dllib) {
188  func = (dsGetEDIDBytes_t) dlsym(dllib, "dsGetEDIDBytes");
189  if (func) {
190  printf("dsGetEDIDBytes(void) is defined and loaded\r\n");
191  }
192  else {
193  printf("dsGetEDIDBytes(void) is not defined\r\n");
194  }
195  dlclose(dllib);
196  }
197  else {
198  printf("Opening RDK_DSHAL_NAME [%s] failed\r\n", RDK_DSHAL_NAME);
199  }
200  }
201 
203 
204  if (func != 0) {
205  unsigned char *edid = NULL;
206  int length = 0;
207  dsError_t ret = func(param->handle, &edid, &length);
208  if (ret == dsERR_NONE && length <= 1024) {
209  printf("dsSRV ::getEDIDBytes returns %d bytes\r\n", length);
210  rc = memcpy_s(param->bytes,sizeof(param->bytes),edid,length);
211  if(rc!=EOK)
212  {
213  ERR_CHK(rc);
214  }
215  param->length = length;
216  free(edid);
217  }
218  param->result = ret;
219  }
220  else {
221  param->result = dsERR_OPERATION_NOT_SUPPORTED;
222  }
223 
224  IARM_BUS_Unlock(lock);
225 
226  return IARM_RESULT_SUCCESS;
227 }
228 
229 IARM_Result_t _dsDisplayTerm(void *arg)
230 {
231  _DEBUG_ENTER();
232 
233  IARM_BUS_Lock(lock);
234 
235  m_isPlatInitialized--;
236 
237  if (0 == m_isPlatInitialized)
238  {
239  dsDisplayTerm();
240  }
241 
242  IARM_BUS_Unlock(lock);
243  return IARM_RESULT_SUCCESS;
244 }
245 
246 
247 /*HDMI Call back */
248 void _dsDisplayEventCallback(intptr_t handle, dsDisplayEvent_t event, void *eventData)
249 {
250  IARM_Bus_DSMgr_EventData_t _eventData;
251  IARM_Bus_DSMgr_EventId_t _eventId;
252 
253 
254  if (NULL_HANDLE == handle)
255  {
256  printf("Err:HDMI Hot plug back has NULL Handle... !!!!!!..\r\n");
257  }
258  switch(event)
259  {
261  __TIMESTAMP();printf("connecting HDMI to display !!!!!!..\r\n");
262  _eventData.data.hdmi_hpd.event = dsDISPLAY_EVENT_CONNECTED;
264  break;
265 
267  __TIMESTAMP();printf("Disconnecting HDMI from display !!!!!!!! ..\r\n");
268  _eventData.data.hdmi_hpd.event = dsDISPLAY_EVENT_DISCONNECTED ;
270  break;
271 
273  __TIMESTAMP();printf("Rx Sense Status ON !!!!!!!! ..\r\n");
274  _eventData.data.hdmi_rxsense.status = dsDISPLAY_RXSENSE_ON ;
276  break;
277 
279  __TIMESTAMP();printf("Rx Sense Status OFF !!!!!!!! ..\r\n");
280  _eventData.data.hdmi_rxsense.status = dsDISPLAY_RXSENSE_OFF ;
282  break;
283 
285  __TIMESTAMP();printf("HDCP Protocol Version Change !!!!!!!! ..\r\n");
287  break;
288 
289  default:
290  printf("Error: Unsupported event in _dsHdmiCallback...\r\n");
291  return;
292 
293  }
294  IARM_Bus_BroadcastEvent(IARM_BUS_DSMGR_NAME,(IARM_EventId_t)_eventId,(void *)&_eventData, sizeof(_eventData));
295  if (dsDISPLAY_EVENT_CONNECTED == event) {
296  dsError_t eRet = dsERR_NONE;
297  if (!_hdmiVideoPortHandle){
298  eRet = dsGetVideoPort(dsVIDEOPORT_TYPE_HDMI,0,&_hdmiVideoPortHandle);
299  if (dsERR_NONE != eRet) {
300  _hdmiVideoPortHandle = 0;
301  }
302  }
303  if (_hdmiVideoPortHandle){
304  resetColorDepthOnHdmiReset(_hdmiVideoPortHandle);
305  } else {
306  __TIMESTAMP();printf("HDMI get port handle failed %d \r\n", eRet);
307  }
308  }
309 }
310 
311 static void filterEDIDResolution(intptr_t handle, dsDisplayEDID_t *edid)
312 {
313  errno_t rc = -1;
314  dsVideoPortResolution_t *edidResn = NULL;
315  dsVideoPortResolution_t *presolution = NULL;
316  dsDisplayEDID_t edidData;
317  dsVideoPortType_t _VPortType = _GetDisplayPortType(handle);
318  int numOfSupportedResolution = 0;
319 
320  if(_VPortType == dsVIDEOPORT_TYPE_HDMI)
321  {
322  printf("EDID for HDMI Port\r\n");
323  size_t iCount = dsUTL_DIM(kResolutions);
324 
325  /*Initialize the struct*/
326  memset(&edidData,0,sizeof(edidData));
327  /*Copy the content */
328  rc = memcpy_s(&edidData,sizeof(edidData),edid,sizeof(edidData));
329  if(rc!=EOK)
330  {
331  ERR_CHK(rc);
332  }
333  printf("[DsMgr] Total Resolution Count from HAL: %d\r\n",edid->numOfSupportedResolution);
334  edid->numOfSupportedResolution = 0;
335  for (size_t i = 0; i < iCount; i++)
336  {
337  presolution = &kResolutions[i];
338  for (size_t j = 0; j < edidData.numOfSupportedResolution; j++)
339  {
340  edidResn = &(edidData.suppResolutionList[j]);
341 
342  if (0 == (strcmp(presolution->name,edidResn->name)))
343  {
344  edid->suppResolutionList[edid->numOfSupportedResolution] = kResolutions[i];
345  edid->numOfSupportedResolution++;
346  numOfSupportedResolution++;
347  printf("[DsMgr] presolution->name : %s, resolution count : %d\r\n",presolution->name,numOfSupportedResolution);
348  }
349  }
350  }
351  }
352  else
353  {
354  printf("EDID for Non HDMI Port\r\n");
355  }
356 }
357 
358 static dsVideoPortType_t _GetDisplayPortType(intptr_t handle)
359 {
360  int numPorts,i;
361  intptr_t halhandle = 0;
362 
363  numPorts = dsUTL_DIM(kSupportedPortTypes);
364  for(i=0; i< numPorts; i++)
365  {
366  dsGetDisplay(kPorts[i].id.type, kPorts[i].id.index, &halhandle);
367  if (handle == halhandle)
368  {
369  return kPorts[i].id.type;
370  }
371  }
372  printf("Error: The Requested Display is not part of Platform Port Configuration \r\n");
373  return dsVIDEOPORT_TYPE_MAX;
374 }
375 
376 /** @} */
377 /** @} */
_dsDisplayGetAspectRatioParam_t
Definition: dsRpc.h:597
dsDISPLAY_EVENT_DISCONNECTED
@ dsDISPLAY_EVENT_DISCONNECTED
Display disconnected event.
Definition: dsDisplay.h:52
dsGetDisplayAspectRatio
dsError_t dsGetDisplayAspectRatio(intptr_t handle, dsVideoAspectRatio_t *aspect)
This function gets the aspect ratio for the dsiaply device. This function returns the aspect ratio of...
Definition: dsDisplay.c:93
_dsDisplayGetEDIDParam_t
Definition: dsRpc.h:602
dsGetDisplay
dsError_t dsGetDisplay(dsVideoPortType_t vType, int index, intptr_t *handle)
Get the handle of a display device.
Definition: dsDisplay.c:65
dsVIDEOPORT_TYPE_HDMI
@ dsVIDEOPORT_TYPE_HDMI
Definition: dsTypes.h:441
dsTypes.h
Device Settings HAL types.
dsDISPLAY_RXSENSE_OFF
@ dsDISPLAY_RXSENSE_OFF
Rx Sense OFF event.
Definition: dsDisplay.h:54
dsVideoPortType_t
enum _dsVideoPortType_t dsVideoPortType_t
dsVideoPort.h
dsError.h
Device Settings HAL error codes.
IARM_Bus_RegisterCall
IARM_Result_t IARM_Bus_RegisterCall(const char *methodName, IARM_BusCall_t handler)
This API is used to register an RPC method that can be invoked by other applications.
dsUtl.h
Device Settings HAL utilities.
IARM_BUS_DSMGR_EVENT_HDCP_STATUS
@ IARM_BUS_DSMGR_EVENT_HDCP_STATUS
Definition: dsMgr.h:52
dsGetEDID
dsError_t dsGetEDID(intptr_t handle, dsDisplayEDID_t *edid)
Get the EDID information from the specified display device.
Definition: dsDisplay.c:119
dsDISPLAY_RXSENSE_ON
@ dsDISPLAY_RXSENSE_ON
Rx Sense ON event.
Definition: dsDisplay.h:53
dsDisplayTerm
dsError_t dsDisplayTerm(void)
This function deinitialize the display sub-system. This function deallocates the data structures used...
Definition: dsDisplay.c:194
dsDisplayInit
dsError_t dsDisplayInit()
Initialize the Display sub-system.
Definition: dsDisplay.c:47
dsERR_NONE
@ dsERR_NONE
Definition: dsError.h:85
_dsDisplayEDID_t::numOfSupportedResolution
int32_t numOfSupportedResolution
Definition: dsTypes.h:912
_dsDisplayGetEDIDBytesParam_t
Definition: dsRpc.h:613
IARM_Bus_BroadcastEvent
IARM_Result_t IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *data, size_t len)
This API is used to publish an Asynchronous event to all IARM client registered for this perticular e...
libIBus.h
RDK IARM-Bus API Declarations.
dsDISPLAY_EVENT_CONNECTED
@ dsDISPLAY_EVENT_CONNECTED
Display connected event.
Definition: dsDisplay.h:51
dsRegisterDisplayEventCallback
dsError_t dsRegisterDisplayEventCallback(intptr_t handle, dsDisplayEventCallback_t cb)
Register a callback function to listen for display events.
dsDisplay.h
_dsDisplayEDID_t
Defines the structure that is used to get the EDID information of the video display.
Definition: dsTypes.h:901
_dsVideoPortResolution_t
Structure that defines video port resolution settings of output video device.
Definition: dsTypes.h:642
_dsDisplayGetHandleParam_t
Definition: dsRpc.h:591
_dsVideoPortResolution_t::name
char name[32]
Definition: dsTypes.h:643
dsVIDEOPORT_TYPE_MAX
@ dsVIDEOPORT_TYPE_MAX
Definition: dsTypes.h:445
IARM_BUS_DSMGR_EVENT_HDMI_HOTPLUG
@ IARM_BUS_DSMGR_EVENT_HDMI_HOTPLUG
Definition: dsMgr.h:50
dsERR_OPERATION_NOT_SUPPORTED
@ dsERR_OPERATION_NOT_SUPPORTED
Definition: dsError.h:89
dsDISPLAY_HDCPPROTOCOL_CHANGE
@ dsDISPLAY_HDCPPROTOCOL_CHANGE
HDCP Protocol Version Change event.
Definition: dsDisplay.h:55
IARM_Bus_DSMgr_EventId_t
enum _DSMgr_EventId_t IARM_Bus_DSMgr_EventId_t
_dsDisplayEDID_t::suppResolutionList
dsVideoPortResolution_t suppResolutionList[64 *dsVIDEO_SSMODE_MAX]
Definition: dsTypes.h:913
dsUTL_DIM
#define dsUTL_DIM(arr)
Device Settings general Array dimension calculation inline definition.
Definition: dsUtl.h:85
dsError_t
dsError_t
Device Settings API Error return codes.
Definition: dsError.h:84
IARM_BUS_DSMGR_EVENT_RX_SENSE
@ IARM_BUS_DSMGR_EVENT_RX_SENSE
Definition: dsMgr.h:53
dsGetVideoPort
dsError_t dsGetVideoPort(dsVideoPortType_t type, int index, intptr_t *handle)
Get the video port handle.
Definition: dsVideoPort.c:64
_DSMgr_EventData_t
Definition: dsMgr.h:81