RDK Documentation (Open Sourced RDK Components)
videoDevice.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 
22 /**
23 * @defgroup devicesettings
24 * @{
25 * @defgroup ds
26 * @{
27 **/
28 
29 
30 #include "videoDevice.hpp"
31 #include "videoDFC.hpp"
32 #include "dsVideoDevice.h"
33 #include "illegalArgumentException.hpp"
34 #include "exception.hpp"
35 #include "videoDeviceConfig.hpp"
36 #include "dsVideoResolutionSettings.h"
37 #include "host.hpp"
38 
39 #include "dslogger.h"
40 #include "dsError.h"
41 #include "dsTypes.h"
42 #include "dsUtl.h"
43 #include <iostream>
44 #include <sstream>
45 #include <string.h>
46 
47 #include "safec_lib.h"
48 
49 /**
50  * @file videoDevice.cpp
51  * @brief Video Device is also called "Decoder".
52  * VideoDevice objects are instantiated by the Device Settings module upon initialization.
53  * Applications do not need to create any such objects on its own.
54  * References to these objects can be retrieved by applications via Host::getVideoDevices()
55  */
56 extern int stringToNumber (std::string text);
57 
58 namespace {
59  const char *_names[] = {
60  "Decoder 0",
61  };
62 
63  inline const bool isValid(int id) {
64  return true;
65  }
66 }
67 
68 namespace device {
69 
70 const char * VideoDevice::kPropertyDFC = ".DFC";
71 
72 
73 /**
74  * @addtogroup dssettingsvideodeviceapi
75  * @{
76  */
77 /**
78  * @fn VideoDevice & VideoDevice::getInstance(int id)
79  * @brief This API is used to get the instance of the video device port based on the port id returned by the getsupported videodevice config.
80  *
81  * @param[in] id port id
82  * @return Reference to the instance of the port id
83  */
85 {
86  if (::isValid(id)) {
87  return VideoDeviceConfig::getInstance().getDevice(id);
88  }
89  else {
91  }
92 }
93 
94 
95 /**
96  * @fn VideoDevice::VideoDevice(int id)
97  * @brief Constructor for videodevice class.
98  * This function initializes the the handle for the corresponding video device based on id.
99  * IllegalArgumentException will be thrown if the specified id of the device is not recognized.
100  *
101  * @param[in] id Port id.
102  * @return None.
103  */
105 {
106  dsError_t ret = dsGetVideoDevice(id, &_handle);
107 
108 
109  if (ret == dsERR_NONE) {
110  _id = id;
111  {
112  /* Construct Port Name as "Type+Index", such as "HDMI0" */
113  std::stringstream out;
114  out << "VideoDevice" << _id;
115  _name = out.str();
116  }
117  }
118  if (ret != dsERR_NONE) {
119  throw IllegalArgumentException();
120  }
121 }
122 
123 
124 /**
125  * @fn VideoDevice::~VideoDevice()
126  * @brief This is a default destructor of the class VideoDevice.
127  *
128  * @return None.
129  */
131  // TODO Auto-generated destructor stub
132 }
133 
134 
135 /**
136  * @fn void VideoDevice::setDFC(const VideoDFC & dfc)
137  * @brief This API is used to set the DFC[Decoder format convention used for zoom purpose] setting by its property name.
138  * Exception will be thrown if the DFC name is not recognized.
139  *
140  * @param[in] dfc new zoom setting
141  *
142  * @return None
143  */
144 void VideoDevice::setDFC(const VideoDFC & dfc)
145 {
146  dsError_t ret = dsSetDFC(_handle, (dsVideoZoom_t)dfc.getId());
147  if (ret != dsERR_NONE) {
148  throw Exception(ret);
149  }
150  _dfc = dfc.getId();
151 }
152 
153 
154 /**
155  * @fn void VideoDevice::setDFC(int dfc)
156  * @brief This API is used to set the DFC with the passed dfc parameter.
157  * This function is used to get the instance of VideoDFC.
158  *
159  * @param[in] dfc new zoom setting
160  *
161  * @return None
162  */
163 void VideoDevice::setDFC(int dfc)
164 {
166 }
167 
168 
169 /**
170  * @fn void VideoDevice::setDFC(const std::string & dfc)
171  * @brief This API is used to set the DFC with the passed dfc parameter.
172  * This function is used to get the instance of VideoDFC
173  * IllegalArgumentException will be thrown if the DFC name is not recognized.
174  * UnsupportedOperationException will be thrown if DFC cannot be changed
175  *
176  * @param[in] dfc Name of the new zoom setting
177  *
178  * @return None
179  */
180 void VideoDevice::setDFC(const std::string & dfc)
181 {
183 }
184 
185 
186 /**
187  * @fn void VideoDevice::setDFC()
188  * @brief This API is used to set the default dfc.
189  *
190  * @return None
191  */
193 {
194  /* sets the default dfc */
195  setDFC(VideoDeviceConfig::getInstance().getDefaultDFC());
196 
197 }
198 
199 
200 /**
201  * @fn void VideoDevice::setPlatformDFC()
202  * @brief This API is used to set the DFC setting to the default one supported by the platform.
203  * The actual Platform DFC is determined by underlying platform implementation.
204  * Applications can use getDFC() API to query the actual DFC set after calling this API.
205  *
206  * @return None
207  */
209 {
211 }
212 
213 
214 /**
215  * @fn const VideoDFC & VideoDevice::getDFC()
216  * @brief This API is used to get the current DFC setting.
217  *
218  * @return Reference to the current DFC setting
219  */
221 
222  dsVideoZoom_t dfc;
223 
224  dsGetDFC(_handle,&dfc);
225 
226  _dfc = dfc;
227 
228  return VideoDFC::getInstance(_dfc);
229 }
230 
231 
232 /**
233  * @fn const List <VideoDFC> VideoDevice::getSupportedDFCs() const
234  * @brief This API is used to get the list of supported DFC (i.e. Zoom Settings) by the video device.
235  *
236  * @return A List of supported DFC settings
237  */
239 {
240  return _supportedDFCs;
241 }
242 
243 
244 /**
245  * @fn void VideoDevice::addDFC(const VideoDFC &dfc)
246  * @brief This function is used to push DFC into the list of supported DFC (i.e. Zoom Settings) by the device.
247  *
248  * @param[in] dfc Supported Zoom setting.
249  * @return None.
250  */
252 {
253  _supportedDFCs.push_back(dfc);
254 }
255 
256 void VideoDevice::getHDRCapabilities(int *capabilities)
257 {
258  dsGetHDRCapabilities(_handle, capabilities);
259 }
260 
261 void VideoDevice::getSettopSupportedResolutions(std::list<std::string>& stbSupportedResoltuions)
262 {
263  size_t numResolutions = dsUTL_DIM(kResolutions);
264  for (size_t i = 0; i < numResolutions; i++)
265  {
266  dsVideoPortResolution_t *resolution = &kResolutions[i];
267  stbSupportedResoltuions.push_back(std::string(resolution->name));
268  }
269 
270  return;
271 }
272 
273 unsigned int VideoDevice::getSupportedVideoCodingFormats() const
274 {
275  unsigned int formats = 0;
276  if(dsERR_NONE != dsGetSupportedVideoCodingFormats(_handle, &formats))
277  {
278  return 0;
279  }
280  else
281  {
282  return formats;
283  }
284 }
285 
286 dsVideoCodecInfo_t VideoDevice::getVideoCodecInfo(dsVideoCodingFormat_t format) const
287 {
288  dsVideoCodecInfo_t info = {0};
289  dsGetVideoCodecInfo(_handle, format, &info);
290  return info;
291 }
292 
293 int VideoDevice::forceDisableHDRSupport(bool disable)
294 {
295  dsForceDisableHDRSupport(_handle, disable);
296  return 0;
297 }
298 
299 int VideoDevice::setFRFMode(int frfmode) const
300 {
301  dsError_t ret;
302  ret = dsSetFRFMode(_handle, frfmode);
303  return 0;
304 }
305 
306 int VideoDevice::getFRFMode(int *frfmode) const
307 {
308  dsError_t ret;
309  int frfmode1;
310  ret = dsGetFRFMode(_handle, &frfmode1);
311  *frfmode = frfmode1;
312  return 0;
313 }
314 
315 int VideoDevice::setDisplayframerate(const char *framerate) const
316 {
317  dsError_t ret;
318  char buf[20] = {0};
319  errno_t rc = -1;
320  rc = strcpy_s(buf,sizeof(buf), framerate);
321  if(rc!=EOK)
322  {
323  ERR_CHK(rc);
324  }
325  ret = dsSetDisplayframerate(_handle, buf);
326  return 0;
327 }
328 
329 int VideoDevice::getCurrentDisframerate(char *framerate) const
330 {
331  dsError_t ret;
332  char getframerate[20];
333  ret = dsGetCurrentDisplayframerate(_handle, getframerate);
334  errno_t rc = -1;
335  rc = strcpy_s(framerate ,sizeof(getframerate) ,getframerate);
336  if(rc!=EOK)
337  {
338  ERR_CHK(rc);
339  }
340  return 0;
341 }
342 
343 }
344 
345 /** @} */
346 
347 /** @} */
348 /** @} */
device::DSConstant::_id
int _id
Indicates the id of the instance inheriting this class.
Definition: dsConstant.hpp:57
device::VideoDevice::getInstance
static VideoDevice & getInstance(int id)
This API is used to get the instance of the video device port based on the port id returned by the ge...
Definition: videoDevice.cpp:84
device::List
This class is implemented using templates and it is used to maintain a container with the list of sup...
Definition: list.hpp:51
dsGetSupportedVideoCodingFormats
dsError_t dsGetSupportedVideoCodingFormats(intptr_t handle, unsigned int *supported_formats)
To find the Video formats supported by the SoC.
Definition: dsVideoDevice.c:183
dsTypes.h
Device Settings HAL types.
device::VideoDevice::VideoDevice
VideoDevice(int id)
Constructor for videodevice class. This function initializes the the handle for the corresponding vid...
Definition: videoDevice.cpp:104
device::DSConstant::isValid
static bool isValid(int min, int max, int val)
This function checks if the given value lies between min and max values provided.
Definition: dsConstant.hpp:72
dsError.h
Device Settings HAL error codes.
dsUtl.h
Device Settings HAL utilities.
dsGetHDRCapabilities
dsError_t dsGetHDRCapabilities(intptr_t handle, int *capabilities)
To find the HDR capabilities of SoC.
Definition: dsVideoDevice.c:162
device::VideoDevice::setPlatformDFC
void setPlatformDFC()
This API is used to set the DFC setting to the default one supported by the platform....
Definition: videoDevice.cpp:208
device::VideoDFC::kPlatform
static const int kPlatform
Indicates decoding format conversion will be managed by the platform.
Definition: videoDFC.hpp:68
dsERR_NONE
@ dsERR_NONE
Definition: dsError.h:85
device::VideoDevice::~VideoDevice
virtual ~VideoDevice()
This is a default destructor of the class VideoDevice.
Definition: videoDevice.cpp:130
device::VideoDFC::getInstance
static const VideoDFC & getInstance(int id)
This function gets an instance of VideoDFC against the id specified, only if the id passed is valid.
Definition: videoDFC.cpp:95
device::VideoDFC
This class extends DSConstant to manage the video Decoder Format Conversion.
Definition: videoDFC.hpp:50
dsVideoDevice.h
device::DSConstant::_name
std::string _name
Indicates the name string of the instance inheriting this class.
Definition: dsConstant.hpp:58
dsVideoZoom_t
enum _dsVideoZoom_t dsVideoZoom_t
videoDevice.hpp
It contains class referenced by videoDevice.cpp file.
device::VideoDevice::getDFC
const VideoDFC & getDFC()
This API is used to get the current DFC setting.
Definition: videoDevice.cpp:220
dsSetDFC
dsError_t dsSetDFC(intptr_t handle, dsVideoZoom_t dfc)
This function is used to set the screen zoom mode (decoder format conversion). This function sets the...
Definition: dsVideoDevice.c:89
device::VideoDevice::_supportedDFCs
List< VideoDFC > _supportedDFCs
List of supported dfc's.
Definition: videoDevice.hpp:56
_dsVideoPortResolution_t
Structure that defines video port resolution settings of output video device.
Definition: dsTypes.h:642
device::Exception
This class handles exceptions occurring in DS module.
Definition: exception.hpp:52
dsGetVideoCodecInfo
dsError_t dsGetVideoCodecInfo(intptr_t handle, dsVideoCodingFormat_t codec, dsVideoCodecInfo_t *info)
This API is used to get the video codec information.
Definition: dsVideoDevice.c:203
device::VideoDevice::addDFC
void addDFC(const VideoDFC &dfc)
This function is used to push DFC into the list of supported DFC (i.e. Zoom Settings) by the device.
Definition: videoDevice.cpp:251
_dsVideoPortResolution_t::name
char name[32]
Definition: dsTypes.h:643
device::VideoDevice
class extending DSConstant to implement the videoDevice interface.
Definition: videoDevice.hpp:53
dsGetDFC
dsError_t dsGetDFC(intptr_t handle, dsVideoZoom_t *dfc)
This function is used to get the screen zoom mode (decoder format conversion). This function Gets the...
Definition: dsVideoDevice.c:117
dsVideoCodecInfo_t
Definition: dsTypes.h:1111
device::VideoDevice::_dfc
int _dfc
Decoder format converter variable.
Definition: videoDevice.hpp:55
device::IllegalArgumentException
This class extends Exception class to manage the expections caused due to illegal arguments.
Definition: illegalArgumentException.hpp:51
device::VideoDevice::setDFC
void setDFC()
This API is used to set the default dfc.
Definition: videoDevice.cpp:192
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
device::DSConstant::getId
virtual int getId() const
This function is used to get the id.
Definition: dsConstant.hpp:130
videoDFC.hpp
This file defines VideoDFC class for managing video decoder format conversion types.
dsGetVideoDevice
dsError_t dsGetVideoDevice(int index, intptr_t *handle)
This function gets the handle for the video device requested.
Definition: dsVideoDevice.c:64
device::VideoDevice::getSupportedDFCs
const List< VideoDFC > getSupportedDFCs() const
This API is used to get the list of supported DFC (i.e. Zoom Settings) by the video device.
Definition: videoDevice.cpp:238