RDK Documentation (Open Sourced RDK Components)
Components_VideoDecoder.cpp
Go to the documentation of this file.
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  * @file Components_VideoDecoder.cpp
22  * @brief This source file contains the APIs of TR069 Components Video decoder.
23  */
24 
25 /**
26 * @defgroup tr69hostif
27 * @{
28 * @defgroup hostif
29 * @{
30 **/
31 
32 
33 #include "dsTypes.h"
35 
36 #define BASE_NAME "Device.Services.STBService.1.Components.VideoDecoder"
37 #define UPDATE_FORMAT_STRING "%s.%d.%s"
38 
39 #define STATUS_STRING "Status"
40 #define CONTENT_AR_STRING "ContentAspectRatio"
41 #define COMCAST_STANDBY_STRING "X_COMCAST-COM_Standby"
42 #define HEVC_STRING "X_RDKCENTRAL-COM_MPEGHPart2"
43 #define HEVC_PROFILE_PATH ".Capabilities.VideoDecoder.X_RDKCENTRAL-COM_MPEGHPart2.ProfileLevel.1"
44 #define NAME_STRING "Name"
45 
46 #define ENABLE_STRING "Enable"
47 #define ENABLED_STRING "Enabled"
48 #define DISABLED_STRING "Disabled"
49 #define ERROR_STRING "Error"
50 
51 GHashTable * hostIf_STBServiceVideoDecoder::ifHash = NULL;
52 GMutex * hostIf_STBServiceVideoDecoder::m_mutex = NULL;
53 
54 hostIf_STBServiceVideoDecoder* hostIf_STBServiceVideoDecoder::getInstance(int dev_id)
55 {
56  hostIf_STBServiceVideoDecoder* pRet = NULL;
57 
58  if(ifHash)
59  {
60  pRet = (hostIf_STBServiceVideoDecoder *)g_hash_table_lookup(ifHash,(gpointer) dev_id);
61  }
62  else
63  {
64  ifHash = g_hash_table_new(NULL,NULL);
65  }
66 
67  if(!pRet)
68  {
69  try {
70  pRet = new hostIf_STBServiceVideoDecoder(dev_id);
71  } catch(int e)
72  {
73  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"Caught exception, not able create STB service Video Interface instance..\n");
74  }
75  g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
76  }
77  return pRet;
78 }
79 
80 GList* hostIf_STBServiceVideoDecoder::getAllInstances()
81 {
82  if(ifHash)
83  return g_hash_table_get_keys(ifHash);
84  return NULL;
85 }
86 
87 void hostIf_STBServiceVideoDecoder::closeInstance(hostIf_STBServiceVideoDecoder *pDev)
88 {
89  if(pDev)
90  {
91  g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
92  delete pDev;
93  }
94 }
95 
96 void hostIf_STBServiceVideoDecoder::closeAllInstances()
97 {
98  if(ifHash)
99  {
100  GList* tmp_list = g_hash_table_get_values (ifHash);
101 
102  while(tmp_list)
103  {
105  tmp_list = tmp_list->next;
106  closeInstance(pDev);
107  }
108  }
109 }
110 
111 void hostIf_STBServiceVideoDecoder::getLock()
112 {
113  if(!m_mutex)
114  {
115  m_mutex = g_mutex_new();
116  }
117  g_mutex_lock(m_mutex);
118 }
119 
120 void hostIf_STBServiceVideoDecoder::releaseLock()
121 {
122  g_mutex_unlock(m_mutex);
123 }
124 
125 /**
126  * @brief Class Constructor of the class hostIf_STBServiceVideoDecoder.
127  *
128  * It will initialize the device id.
129  *
130  * @param[in] devid Identification number of the device.
131  */
133 {
134  dev_id = devid;
135 
136  strcpy(backupContentAspectRatio," ");
137  backupStandby = false;
138  strcpy(backupVideoDecoderStatus," ");
139 
140  bCalledContentAspectRatio = false;
141  bCalledStandby = false;
142  bCalledVideoDecoderStatus = false;
143 }
144 
145 /**
146  * @brief This function sets the video decoder interface updates such as Status,
147  * ContentAspectRatio, X_COMCAST-COM_Standby, Name in a connected video decoder.
148  * Currently X_COMCAST-COM_Standby is handled.
149  *
150  * @param[in] paramName Video decoder service name string.
151  * @param[in] stMsgData HostIf Message Request param contains the video decoder attribute value.
152  *
153  * @return Returns an Integer value.
154  * @retval 0 If successfully set the hostIf video decoder interface attribute.
155  * @retval -1 If Not able to set the hostIf video decoder interface attribute.
156  * @retval -2 If Not handle the hostIf video decoder interface attribute.
157  * @ingroup TR69_HOSTIF_STBSERVICES_VIDEODECODER_API
158  */
160 {
161  int ret = NOT_HANDLED;
162  if (strcasecmp(pSetting, COMCAST_STANDBY_STRING) == 0)
163  {
164  ret = setX_COMCAST_COM_Standby(stMsgData);
165  }
166  return ret;
167 }
168 
169 /**
170  * @brief This function get the video decoder interface updates such as Status,
171  * ContentAspectRatio, X_COMCAST-COM_Standby, Name in a connected video decoder.
172  *
173  * @param[in] paramName Video decoder service name string.
174  * @param[in] stMsgData HostIf Message Request param contains the video decoder attribute value.
175  *
176  * @return Returns an Integer value.
177  * @retval 0 If successfully get the hostIf video decoder interface attribute.
178  * @retval -1 If Not able to get the hostIf video decoder interface attribute.
179  * @retval -2 If Not handle the hostIf video decoder interface attribute.
180  * @ingroup TR69_HOSTIF_STBSERVICES_VIDEODECODER_API
181  */
182 int hostIf_STBServiceVideoDecoder::handleGetMsg(const char *paramName, HOSTIF_MsgData_t *stMsgData)
183 {
184  int ret = NOT_HANDLED;
185  if(strcasecmp(paramName, COMCAST_STANDBY_STRING) == 0)
186  {
187  ret = getX_COMCAST_COM_Standby(stMsgData);
188  }
189  else if(strcasecmp(paramName, ENABLE_STRING) == 0)
190  {
191  put_boolean(stMsgData->paramValue,true);
192  stMsgData->paramtype = hostIf_BooleanType;
193  stMsgData->paramLen = sizeof(bool);
194  ret = OK;
195  }
196  else if(strcasecmp(paramName, STATUS_STRING) == 0)
197  {
198  ret = getStatus(stMsgData);
199  }
200  else if(strcasecmp(paramName, NAME_STRING) == 0)
201  {
202  strncpy(stMsgData->paramValue,"VideoDecoderHDMI0", strlen("VideoDecoderHDMI0")+1); // Questionable relationship.
203  stMsgData->paramtype = hostIf_StringType;
204  stMsgData->paramLen = strlen(stMsgData->paramValue);
205  ret = OK;
206  }
207  else if(strcasecmp(paramName, CONTENT_AR_STRING) == 0)
208  {
209  ret = getContentAspectRatio(stMsgData);
210  }
211  else if(strcasecmp(paramName, HEVC_STRING) == 0)
212  {
213  strncpy(stMsgData->paramValue, HEVC_PROFILE_PATH, strlen(HEVC_PROFILE_PATH)+1);
214  stMsgData->paramtype = hostIf_StringType;
215  stMsgData->paramLen = strlen(stMsgData->paramValue);
216  ret = OK;
217  }
218  return ret;
219 }
220 
221 /**
222  * @brief This function updates the video decoder interface updates such as
223  * Status, ContentAspectRatio, X_COMCAST-COM_Standby, Name in a connected video decoder.
224  *
225  * @param[in] mUpdateCallback Callback function which updates the hostIf video decoder interface.
226  * @ingroup TR69_HOSTIF_STBSERVICES_VIDEODECODER_API
227  */
228 void hostIf_STBServiceVideoDecoder::doUpdates(updateCallback mUpdateCallback)
229 {
230  HOSTIF_MsgData_t msgData;
231  bool bChanged;
232  char tmp_buff[PARAM_LEN];
233 
234  memset(&msgData,0,sizeof(msgData));
235  memset(tmp_buff,0,PARAM_LEN);
236  bChanged = false;
237  msgData.instanceNum=dev_id;
238  getX_COMCAST_COM_Standby(&msgData,&bChanged);
239  if(bChanged)
240  {
241  snprintf(tmp_buff, PARAM_LEN, UPDATE_FORMAT_STRING, BASE_NAME, dev_id, COMCAST_STANDBY_STRING);
242  if(mUpdateCallback)
243  {
244  mUpdateCallback(IARM_BUS_TR69HOSTIFMGR_EVENT_VALUECHANGED,tmp_buff, msgData.paramValue, msgData.paramtype);
245  }
246  }
247  memset(&msgData,0,sizeof(msgData));
248  memset(tmp_buff,0,PARAM_LEN);
249  bChanged = false;
250  msgData.instanceNum=dev_id;
251  getStatus(&msgData,&bChanged);
252  if(bChanged)
253  {
254  snprintf(tmp_buff, PARAM_LEN, UPDATE_FORMAT_STRING, BASE_NAME, dev_id, STATUS_STRING);
255  if(mUpdateCallback)
256  {
257  mUpdateCallback(IARM_BUS_TR69HOSTIFMGR_EVENT_VALUECHANGED,tmp_buff, msgData.paramValue, msgData.paramtype);
258  }
259  }
260  memset(&msgData,0,sizeof(msgData));
261  memset(tmp_buff,0,PARAM_LEN);
262  bChanged = false;
263  msgData.instanceNum=dev_id;
264  getContentAspectRatio(&msgData,&bChanged);
265  if(bChanged)
266  {
267  snprintf(tmp_buff, PARAM_LEN, UPDATE_FORMAT_STRING, BASE_NAME, dev_id, CONTENT_AR_STRING);
268  if(mUpdateCallback)
269  {
270  mUpdateCallback(IARM_BUS_TR69HOSTIFMGR_EVENT_VALUECHANGED,tmp_buff, msgData.paramValue, msgData.paramtype);
271  }
272  }
273 }
274 
275 // Impl of accessors below.
276 
277 /************************************************************
278  * Description : Get VideoDecoder ContentAspectRatio
279  * Precondition : None
280  * Input : stMsgData for result return.
281  pChanged
282 
283  * Return : OK -> Success
284  NOK -> Failure
285  value -> "4x3"
286  "16x9"
287 
288 // TODO: This is implemented incorrectly, in that it returns the AR of the attached display, and not the Content.
289 
290 ************************************************************/
291 
292 int hostIf_STBServiceVideoDecoder::getContentAspectRatio(HOSTIF_MsgData_t *stMsgData,bool *pChanged)
293 {
294  try {
295  std::string strVideoPort = device::Host::getInstance().getDefaultVideoPortName();
296  std::string videoPortName = strVideoPort.substr(0, strVideoPort.size()-1);
297  device::VideoOutputPort vPort = device::Host::getInstance().getVideoOutputPort(videoPortName.append(int_to_string(stMsgData->instanceNum-1)));
298  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s] vPort.isDisplayConnected(): %d \n",__FUNCTION__, vPort.isDisplayConnected());
299 
300  if (true == vPort.isDisplayConnected()) {
301  const device::VideoOutputPort::Display disp = vPort.getDisplay();
302  const device::AspectRatio aspect_ratio = disp.getAspectRatio();
303  const std::string str = aspect_ratio.getName();
304  strncpy(stMsgData->paramValue, str.c_str(),str.length());
305  }
306  else {
307  memset(stMsgData->paramValue, '\0', sizeof (stMsgData->paramValue));
308  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s] %s Display is NOT connected, vPort.isDisplayConnected() %d \r\n",__FUNCTION__, "HDMI", vPort.isDisplayConnected());
309  }
310  stMsgData->paramValue[PARAM_LEN-1] = '\0';
311  stMsgData->paramtype = hostIf_StringType;
312  stMsgData->paramLen = strlen(stMsgData->paramValue);
313  if(bCalledContentAspectRatio && pChanged && strcmp(backupContentAspectRatio,stMsgData->paramValue))
314  {
315  *pChanged = true;
316  }
317  bCalledContentAspectRatio = true;
318  strncpy(backupContentAspectRatio,stMsgData->paramValue,_BUF_LEN_16-1);
319  backupContentAspectRatio[_BUF_LEN_16-1] = '\0';
320  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s] In getVideoDecoderContentAspectRatio(): Value: %s \n",__FUNCTION__, stMsgData->paramValue);
321  }
322  catch (const std::exception e) {
323  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Exception\r\n",__FUNCTION__);
324  return NOK;
325  }
326 
327  return OK;
328 }
329 
330 /************************************************************
331  * Description : Get if Video decoder is in Standby or not.
332  * Precondition : None
333  * Input : stMsgData for result return.
334  pChanged
335 
336  * Return : OK -> Success
337  NOK -> Failure
338  stMsgData->paramValue -> 1 : Decoder in Standby
339  2 : Decoder not in Standby
340 ************************************************************/
341 
342 int hostIf_STBServiceVideoDecoder::getX_COMCAST_COM_Standby(HOSTIF_MsgData_t *stMsgData,bool *pChanged)
343 {
344  try {
345  int iPowerMode = device::Host::getInstance().getPowerMode();
346 
347  /*If the decoder in Standby mode, display true.*/
348  /* If the decoder in PowerON mode, display false */
349  if(iPowerMode == dsPOWER_STANDBY)
350  put_boolean(stMsgData->paramValue, true);
351  else
352  put_boolean(stMsgData->paramValue, false);
353 
354  stMsgData->paramtype=hostIf_BooleanType;
355  stMsgData->paramLen = sizeof(bool);
356  if(bCalledStandby && pChanged && (backupStandby != get_boolean(stMsgData->paramValue)))
357  {
358  *pChanged = true;
359  }
360  bCalledStandby = true;
361  backupStandby = get_boolean(stMsgData->paramValue);
362  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s()] PowerMode: [%d , %s] \n", __FUNCTION__, iPowerMode, stMsgData->paramValue);
363  }
364  catch (const std::exception e) {
365  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Exception\r\n",__FUNCTION__);
366  return NOK;
367  }
368 
369  return OK;
370 }
371 /************************************************************
372  * Description : Get if Video decoder is in Standby or not.
373  * Precondition : None
374  * Input : stMsgData for result return.
375  pChanged
376 
377  * Return : OK -> Success
378  NOK -> Failure
379  stMsgData->paramValue -> "Enabled", "Disabled", "Error", "X_COMCAST-COM_Standby"
380 ************************************************************/
381 
382 int hostIf_STBServiceVideoDecoder::getStatus(HOSTIF_MsgData_t *stMsgData,bool *pChanged)
383 {
384  try {
385  int iPowerMode = device::Host::getInstance().getPowerMode();
386  switch(iPowerMode)
387  {
388  case dsPOWER_ON:
389  strncpy(stMsgData->paramValue, ENABLED_STRING, strlen(ENABLED_STRING)+1);
390  break;
391  case dsPOWER_STANDBY:
392  strncpy(stMsgData->paramValue, COMCAST_STANDBY_STRING, strlen(COMCAST_STANDBY_STRING)+1);
393  break;
394  case dsPOWER_OFF:
395  strncpy(stMsgData->paramValue, DISABLED_STRING, strlen(DISABLED_STRING)+1);
396  break;
397  default:
398  strncpy(stMsgData->paramValue, ERROR_STRING, strlen(ERROR_STRING)+1);
399  }
400  stMsgData->paramValue[PARAM_LEN-1] = '\0';
401  stMsgData->paramtype = hostIf_StringType;
402  stMsgData->paramLen = strlen(stMsgData->paramValue);
403  if(bCalledVideoDecoderStatus && pChanged && strcmp(backupVideoDecoderStatus, stMsgData->paramValue))
404  {
405  *pChanged = true;
406  }
407  bCalledVideoDecoderStatus = true;
408  strncpy(backupVideoDecoderStatus,stMsgData->paramValue,_BUF_LEN_32-1);
409  backupVideoDecoderStatus[_BUF_LEN_32-1] = '\0';
410  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s()] PowerMode: [%d , %s] \n", __FUNCTION__, iPowerMode, stMsgData->paramValue);
411  }
412  catch (const std::exception e) {
413  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Exception\r\n",__FUNCTION__);
414  return NOK;
415  }
416 
417  return OK;
418 }
419 /************************************************************
420  * Description : Set Video decoder in Standby.
421  * Precondition : None
422  * Input : stMsgData->paramValue -> 1: POWER_ON
423  2: POWER_STANDBY
424  3: POWER_OFF
425 
426  * Return : OK -> Success
427  NOK -> Failure
428 
429 ************************************************************/
430 int hostIf_STBServiceVideoDecoder::setX_COMCAST_COM_Standby(const HOSTIF_MsgData_t *stMsgData)
431 {
432  try
433  {
434  int iPowerMode;
435  bool val = get_boolean(stMsgData->paramValue);
436 
437  if(val) {
438  iPowerMode = dsPOWER_STANDBY;
439  } else {
440  iPowerMode = dsPOWER_ON;
441  }
442 
443  if((iPowerMode < dsPOWER_ON) || (iPowerMode > dsPOWER_OFF))
444  {
445  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s] Failed to set [%s] due to Invalid input value [%d]\r\n",__FUNCTION__, stMsgData->paramName, val);
446  return NOK;
447  }
448  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s] Get value as \'%d\' and Set as: \'%d\' \n", __FILE__, __FUNCTION__, get_boolean(stMsgData->paramValue), iPowerMode);
450  }
451  catch (const std::exception e) {
452  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Exception\r\n",__FUNCTION__);
453  return NOK;
454  }
455 
456  return OK;
457 }
458 
459 
460 
461 /** @} */
462 /** @} */
dsPOWER_OFF
@ dsPOWER_OFF
Definition: dsTypes.h:929
_HostIf_MsgData_t::instanceNum
short instanceNum
Definition: hostIf_tr69ReqHandler.h:176
Components_VideoDecoder.h
The header file provides capabilities video output information APIs.
hostIf_STBServiceVideoDecoder
This class provides the TR069 components video decoder information.
Definition: Components_VideoDecoder.h:79
device::VideoOutputPort::Display::getAspectRatio
const AspectRatio & getAspectRatio() const
This function returns the instance of the aspect ratio that is used currently in connected display de...
Definition: videoOutputPort.hpp:182
device::VideoOutputPort::isDisplayConnected
bool isDisplayConnected() const
This API is used to Check if the port is currently connected to any display device.
Definition: videoOutputPort.cpp:381
device::VideoOutputPort
Class extending enumerable to implement the videoooutputport interface.
Definition: videoOutputPort.hpp:59
dsTypes.h
Device Settings HAL types.
dsPOWER_STANDBY
@ dsPOWER_STANDBY
Definition: dsTypes.h:928
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
put_boolean
void put_boolean(char *ptr, bool val)
This function converts the input data to Boolean type.
Definition: hostIf_utils.cpp:191
hostIf_STBServiceVideoDecoder::handleGetMsg
int handleGetMsg(const char *paramName, HOSTIF_MsgData_t *stMsgData)
This function get the video decoder interface updates such as Status, ContentAspectRatio,...
Definition: Components_VideoDecoder.cpp:182
device::VideoOutputPort::getDisplay
const VideoOutputPort::Display & getDisplay()
This API is used to get the display device information currently connected to the output port....
Definition: videoOutputPort.cpp:328
_HostIf_MsgData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:177
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
_HostIf_MsgData_t::paramName
char paramName[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:171
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
device::AspectRatio
This class extends DSConstant to implement AspectRatio. It manages the aspect ratios of the videos.
Definition: aspectRatio.hpp:50
device::Host::getVideoOutputPort
VideoOutputPort & getVideoOutputPort(const std::string &name)
This API is used to get the reference to the video output port by its name. The name of the port must...
Definition: host.cpp:350
device::Host::getInstance
static Host & getInstance(void)
This API is used to get a reference to the single instance of the Host object.
Definition: host.cpp:88
device::VideoOutputPort::Display
Definition: videoOutputPort.hpp:80
IARM_BUS_TR69HOSTIFMGR_EVENT_VALUECHANGED
@ IARM_BUS_TR69HOSTIFMGR_EVENT_VALUECHANGED
Definition: hostIf_tr69ReqHandler.h:189
device::Host::setPowerMode
bool setPowerMode(int mode)
This API is used to change the power mode of the device. This function will set the power mode to act...
Definition: host.cpp:256
device::Host::getPowerMode
int getPowerMode()
This API is used to get the current power mode of the device. This function is currently not supporte...
Definition: host.cpp:269
hostIf_STBServiceVideoDecoder::doUpdates
void doUpdates(updateCallback mUpdateCallback)
This function updates the video decoder interface updates such as Status, ContentAspectRatio,...
Definition: Components_VideoDecoder.cpp:228
dsPOWER_ON
@ dsPOWER_ON
Definition: dsTypes.h:927
_HostIf_MsgData_t::paramLen
short paramLen
Definition: hostIf_tr69ReqHandler.h:175
hostIf_STBServiceVideoDecoder::handleSetMsg
int handleSetMsg(const char *paramName, HOSTIF_MsgData_t *stMsgData)
This function sets the video decoder interface updates such as Status, ContentAspectRatio,...
Definition: Components_VideoDecoder.cpp:159
hostIf_STBServiceVideoDecoder::hostIf_STBServiceVideoDecoder
hostIf_STBServiceVideoDecoder(int devid)
Class Constructor of the class hostIf_STBServiceVideoDecoder.
Definition: Components_VideoDecoder.cpp:132