RDK Documentation (Open Sourced RDK Components)
videoOutputPortType.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 "videoOutputPortType.hpp"
31 #include "videoOutputPort.hpp"
32 #include "list.hpp"
33 #include "dsUtl.h"
34 #include "dsError.h"
35 #include "illegalArgumentException.hpp"
36 #include "videoOutputPortConfig.hpp"
37 #include "dslogger.h"
38 
39 
40 
41 #include <iostream>
42 #include <string.h>
43 #include <sstream>
44 
45 /**
46  * @file videoOutputPortType.cpp
47  * @brief VideoOutputPortType objects are instantiated by the Device Settings module upon initialization.
48  * Applications do not need to create any such objects on its own.
49  * References to these objects can be retrieved using a VideoOutputPort object invoking VideoOutputPort::getType().
50  * A VideoOutputPortType object represent the shared properties of all output ports of same type.
51  * Control over a specific instance of Video Output Port is access over a Video Output Port object
52  */
53 
54 using namespace std;
55 
56 
57 extern "C" dsError_t dsEnableHDCP(intptr_t handle, bool contentProtect, char *hdcpKey, size_t keySize);
58 
59 namespace {
60  const char *_names[] = {
61  "RF",
62  "Baseband",
63  "SVideo",
64  "1394",
65  "DVI",
66  "Component",
67  "HDMI",
68  "HDMIInput",
69  "Internal",
70  "SCART",
71  };
72 
73  inline const bool isValid(int id) {
74  return dsVideoPortType_isValid(id);
75  }
76 
77 }
78 
79 namespace device {
80 
81 typedef int _SafetyCheck[(dsUTL_DIM(_names) == dsVIDEOPORT_TYPE_MAX) ? 1 : -1];
82 
83 const int VideoOutputPortType::kRF = dsVIDEOPORT_TYPE_RF;
84 const int VideoOutputPortType::kBaseband = dsVIDEOPORT_TYPE_BB;
85 const int VideoOutputPortType::kSVideo = dsVIDEOPORT_TYPE_SVIDEO;
86 const int VideoOutputPortType::k1394 = dsVIDEOPORT_TYPE_1394;
87 const int VideoOutputPortType::kDVI = dsVIDEOPORT_TYPE_DVI;
88 const int VideoOutputPortType::kComponent = dsVIDEOPORT_TYPE_COMPONENT;
89 const int VideoOutputPortType::kHDMI = dsVIDEOPORT_TYPE_HDMI;
90 const int VideoOutputPortType::kInternal = dsVIDEOPORT_TYPE_INTERNAL;
91 const int VideoOutputPortType::kScart = dsVIDEOPORT_TYPE_SCART;
92 const int VideoOutputPortType::kMax = dsVIDEOPORT_TYPE_MAX;
93 
94 
95 /**
96  * @addtogroup dssettingsvidoutporttypeapi
97  * @{
98  */
99 
100 /**
101  * @fn VideoOutputPortType::getInstance(int id)
102  * @brief This function is used to get the instance of the video output port type based on the port id. If the 'id'
103  * passed is invalid then it throws an IllegalArgumentException.
104  *
105  * @param[in] id port id
106  *
107  * @return Reference to the instance of the port type id
108  */
109 VideoOutputPortType & VideoOutputPortType::getInstance(int id)
110 {
111  if (::isValid(id)) {
112  return VideoOutputPortConfig::getInstance().getPortType(id);
113  }
114  else {
115  throw IllegalArgumentException();
116  }
117 }
118 
119 
120 
121 /**
122  * @fn VideoOutputPortType::getInstance(const std::string &name)
123  * @brief This function is used to get the instance of the video output port type based on the port name. If the "name"
124  * passed is invalid then it throws an IllegalArgumentException.
125  *
126  * @param[in] name port name
127  *
128  * @return Reference to the instance of the port type name
129  */
130 VideoOutputPortType & VideoOutputPortType::getInstance(const std::string &name)
131 {
132  for (size_t i = 0; i < dsUTL_DIM(_names); i++) {
133  if (name.compare(_names[i]) == 0) {
134  return VideoOutputPortConfig::getInstance().getPortType(i);
135  }
136  }
137  throw IllegalArgumentException();
138 }
139 
140 
141 /*
142  * @fn VideoOutputPortType::VideoOutputPortType(const int id)
143  * @brief This function is a parameterised constructor. It initialises the VideoOutputPortType instance
144  * with the id and name corresponding to the id passed. If the 'id' passed is invalid then it throws an
145  * IllegalArgumentException.
146  *
147  * @param[in] id Videooutput port type id.
148  * @return Reference to the instance of the videooutputport type id.
149  */
150 VideoOutputPortType::VideoOutputPortType(const int id)
151 {
152  _dtcpSupported = false;
153  _hdcpSupported = false;
154  _dynamic = false;
155  _restrictedResolution = 0;
156  if (::isValid(id)) {
157  _id = id;
158  _name = std::string(_names[id]);
159  }
160  else {
161  throw IllegalArgumentException();
162  }
163 
164 }
165 
166 
167 /**
168  * @fn VideoOutputPortType::~VideoOutputPortType()
169  * @brief This is a default destructor of the class VideoOutputPortType.
170  *
171  * @return None.
172  */
173 VideoOutputPortType::~VideoOutputPortType()
174 {
175 }
176 
177 
178 /**
179  * @fn const List<VideoOutputPort> VideoOutputPortType::getPorts() const
180  * @brief This function is used to get the list of videooutputporttype.
181  *
182  * @return List of videooutputport type.
183  */
184 const List<VideoOutputPort> VideoOutputPortType::getPorts() const
185 {
186  return _vPorts;
187 }
188 
189 
190 /**
191  * @fn void VideoOutputPortType::enabledDTCP()
192  * @brief This function is used to enable the DTCP for videooutputport type.
193  *
194  * @return None.
195  */
196 void VideoOutputPortType::enabledDTCP()
197 {
198  _dtcpSupported = true;
199 }
200 
201 
202 /**
203  * @fn void VideoOutputPortType::enabledHDCP(bool contentProtect , char *hdcpKey , size_t keySize )
204  * @brief This function is used to enable the HDCP content protection.
205  *
206  * @param[in] contentProtect True If Content protection needs to be enabled, false otherwise.
207  * @param[in] hdcpKey HDCP key.
208  * @param[in] keySize HDCP key size.
209  *
210  * @return None.
211  */
212 void VideoOutputPortType::enabledHDCP(bool contentProtect , char *hdcpKey , size_t keySize )
213 {
214  dsError_t ret = dsERR_NONE;
215  ret = dsEnableHDCP(0, contentProtect, hdcpKey, keySize);
216  if (ret != dsERR_NONE)
217  {
218  throw IllegalArgumentException();
219  }
220  _hdcpSupported = true;
221 }
222 
223 
224 /**
225  * @fn void VideoOutputPortType::setRestrictedResolution(int resolution)
226  * @brief This function is used to set the restricted resolution of the videooutput port type.
227  *
228  * @param[in] resolution Restricted resolution.
229  * @return None.
230  */
231 void VideoOutputPortType::setRestrictedResolution(int resolution)
232 {
233  _restrictedResolution = resolution;
234 }
235 
236 
237 /**
238  * @fn void VideoOutputPortType::addPort(const VideoOutputPort & port)
239  * @brief This function is used to add video output port type in the videooutputport list.
240  *
241  * @param[in] port Videooutputport type.
242  * @return None.
243  */
244 void VideoOutputPortType::addPort(const VideoOutputPort & port)
245 {
246  _vPorts.push_back(port);
247 }
248 
249 
250 /**
251  * @fn VideoOutputPortType::isDTCPSupported() const
252  * @brief This API is used to query if DTCP is supported by the port type.
253  *
254  * @return True or False
255  * @retval 1 if DTCP is supported
256  * @retval 0 if DTCP is not supported
257  */
258 bool VideoOutputPortType::isDTCPSupported() const
259 {
260  return _dtcpSupported;
261 }
262 
263 
264 /**
265  * @fn bool VideoOutputPortType::isHDCPSupported() const
266  * @brief This API is used to query if HDCP is supported by the port type.
267  *
268  * @return True or False
269  * @retval 1 if HDCP is supported
270  * @retval 0 if HDCP is not supported
271  */
272 bool VideoOutputPortType::isHDCPSupported() const
273 {
274  return _hdcpSupported;
275 }
276 
277 
278 /**
279  * @fn bool VideoOutputPortType::isDynamicResolutionsSupported() const
280  * @brief This function is used to query if dynamic resolutions are supported by the port type.
281  *
282  * @return True or False
283  * @retval 1 If dynamic resolutions is supported.
284  * @retval 0 if dynamic resolutions is not supported.
285  */
286 bool VideoOutputPortType::isDynamicResolutionsSupported() const
287 {
288  return true;
289 }
290 
291 
292 /**
293  * @fn int VideoOutputPortType::getRestrictedResolution() const
294  * @brief This function is used to get the resolution type which has been restricted from usage.
295  *
296  * @return _restrictedResolution Any Restricted resolution type.
297  */
298 int VideoOutputPortType::getRestrictedResolution() const
299 {
300  return _restrictedResolution;
301 }
302 
303 
304 /**
305  * @fn const List<VideoResolution > VideoOutputPortType::getSupportedResolutions() const
306  * @brief This API is used to get a list of supported Video Resolutions by the port type.
307  *
308  * @return A list of video resolutions supported
309  */
310 
311 const List<VideoResolution > VideoOutputPortType::getSupportedResolutions() const
312 {
313  return VideoOutputPortConfig::getInstance().getSupportedResolutions();
314 }
315 
316 }
317 
318 /* @} */ //End of Doxygen Tag
319 
320 /** @} */
321 /** @} */
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
dsVIDEOPORT_TYPE_HDMI
@ dsVIDEOPORT_TYPE_HDMI
Definition: dsTypes.h:441
device::VideoOutputPort
Class extending enumerable to implement the videoooutputport interface.
Definition: videoOutputPort.hpp:59
dsVIDEOPORT_TYPE_1394
@ dsVIDEOPORT_TYPE_1394
Definition: dsTypes.h:438
dsError.h
Device Settings HAL error codes.
dsUtl.h
Device Settings HAL utilities.
dsVIDEOPORT_TYPE_INTERNAL
@ dsVIDEOPORT_TYPE_INTERNAL
Definition: dsTypes.h:443
dsVIDEOPORT_TYPE_RF
@ dsVIDEOPORT_TYPE_RF
Definition: dsTypes.h:435
videoOutputPortType.hpp
It contains structures and class referenced by the videoOutputportTypes.cpp file.
dsERR_NONE
@ dsERR_NONE
Definition: dsError.h:85
dsVIDEOPORT_TYPE_BB
@ dsVIDEOPORT_TYPE_BB
Definition: dsTypes.h:436
dsVIDEOPORT_TYPE_SCART
@ dsVIDEOPORT_TYPE_SCART
Definition: dsTypes.h:444
dsVIDEOPORT_TYPE_SVIDEO
@ dsVIDEOPORT_TYPE_SVIDEO
Definition: dsTypes.h:437
videoOutputPort.hpp
It contains class and structure refrenced by the videooutputport.cpp file.
dsVIDEOPORT_TYPE_DVI
@ dsVIDEOPORT_TYPE_DVI
Definition: dsTypes.h:439
dsVIDEOPORT_TYPE_MAX
@ dsVIDEOPORT_TYPE_MAX
Definition: dsTypes.h:445
dsVIDEOPORT_TYPE_COMPONENT
@ dsVIDEOPORT_TYPE_COMPONENT
Definition: dsTypes.h:440
device::VideoOutputPortType
Class extending DSConstant to implement the VideoOutputporttype interface.
Definition: videoOutputPortType.hpp:59
dsVideoPortType_isValid
#define dsVideoPortType_isValid(t)
Definition: dsTypes.h:451
device::IllegalArgumentException
This class extends Exception class to manage the expections caused due to illegal arguments.
Definition: illegalArgumentException.hpp:51
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