RDK Documentation (Open Sourced RDK Components)
videoOutputPortConfig.cpp
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 "videoOutputPortConfig.hpp"
32 #include "audioOutputPortConfig.hpp"
33 #include "illegalArgumentException.hpp"
34 #include "dsVideoPortSettings.h"
35 #include "dsVideoResolutionSettings.h"
36 #include "dsDisplay.h"
37 #include "dsVideoPort.h"
38 #include "dsUtl.h"
39 #include "dsError.h"
40 #include "illegalArgumentException.hpp"
41 #include "list.hpp"
42 #include "videoResolution.hpp"
43 #include "dslogger.h"
44 #include "host.hpp"
45 
46 
47 #include <thread>
48 #include <mutex>
49 #include <iostream>
50 #include <string.h>
51 using namespace std;
52 
53 namespace device {
54 
55 static VideoResolution* defaultVideoResolution;
56 static std::mutex gSupportedResolutionsMutex;
57 VideoOutputPortConfig::VideoOutputPortConfig() {
58  // TODO Auto-generated constructor stub
59  defaultVideoResolution = new VideoResolution(
60  0, /* id */
61  std::string("720p"),
66  _PROGRESSIVE);
67 
68 }
69 
70 VideoOutputPortConfig::~VideoOutputPortConfig() {
71  // TODO Auto-generated destructor stub
72  delete defaultVideoResolution;
73 }
74 
75 VideoOutputPortConfig & VideoOutputPortConfig::getInstance() {
76  static VideoOutputPortConfig _singleton;
77  return _singleton;
78 }
79 
80 const PixelResolution &VideoOutputPortConfig::getPixelResolution(int id) const
81 {
82  return _vPixelResolutions.at(id);
83 }
84 
85 const AspectRatio &VideoOutputPortConfig::getAspectRatio(int id) const
86 {
87  return _vAspectRatios.at(id);
88 }
89 
90 const StereoScopicMode &VideoOutputPortConfig::getSSMode(int id) const
91 {
92  return _vStereoScopieModes.at(id);
93 }
94 
95 const VideoResolution &VideoOutputPortConfig::getVideoResolution (int id) const
96 {
97  {std::lock_guard<std::mutex> lock(gSupportedResolutionsMutex);
98  if (id < _supportedResolutions.size()){
99  return _supportedResolutions.at(id);
100  }
101  else {
102  cout<<"returns default resolution 720p"<<endl;
103  //If id not found return the 720p default resolution.
104  return *defaultVideoResolution;
105  }
106  }
107 }
108 
109 const FrameRate &VideoOutputPortConfig::getFrameRate(int id) const
110 {
111  return _vFrameRates.at(id);
112 }
113 
114 VideoOutputPortType &VideoOutputPortConfig::getPortType(int id)
115 {
116  return _vPortTypes.at(id);
117 }
118 
119 VideoOutputPort &VideoOutputPortConfig::getPort(int id)
120 {
121  return _vPorts.at(id);
122 }
123 
124 VideoOutputPort &VideoOutputPortConfig::getPort(const std::string & name)
125 {
126  for (size_t i = 0; i < _vPorts.size(); i++) {
127  if (name.compare(_vPorts.at(i).getName()) == 0) {
128  return _vPorts.at(i);
129  }
130  }
131 
132  throw IllegalArgumentException();
133 }
134 
135 List<VideoOutputPort> VideoOutputPortConfig::getPorts()
136 {
137  List <VideoOutputPort> rPorts;
138 
139  for (size_t i = 0; i < _vPorts.size(); i++) {
140  rPorts.push_back(_vPorts.at(i));
141  }
142 
143  return rPorts;
144 }
145 
146 List<VideoOutputPortType> VideoOutputPortConfig::getSupportedTypes()
147 {
148  List<VideoOutputPortType> supportedTypes;
149  for (std::vector<VideoOutputPortType>::const_iterator it = _vPortTypes.begin(); it != _vPortTypes.end(); it++) {
150  if (it->isEnabled()) {
151  supportedTypes.push_back(*it);
152  }
153  }
154 
155  return supportedTypes;
156 }
157 
158 List<VideoResolution> VideoOutputPortConfig::getSupportedResolutions(bool isIgnoreEdid)
159 {
160  List<VideoResolution> supportedResolutions;
161  std::vector<VideoResolution> tmpsupportedResolutions;
162  int isDynamicList = 0;
163  dsError_t dsError = dsERR_NONE;
164  intptr_t _handle = 0; //CID:98922 - Uninit
165  bool force_disable_4K = true;
166 
167  printf ("\nResOverride VideoOutputPortConfig::getSupportedResolutions isIgnoreEdid:%d\n", isIgnoreEdid);
168  if (!isIgnoreEdid) {
169  try {
170  std::string strVideoPort = device::Host::getInstance().getDefaultVideoPortName();
171  device::VideoOutputPort vPort = VideoOutputPortConfig::getInstance().getPort(strVideoPort.c_str());
172  if (vPort.isDisplayConnected())
173  {
174  dsDisplayEDID_t edid;
175 
176  /*Initialize the struct*/
177  memset(&edid, 0, sizeof(edid));
178 
179  edid.numOfSupportedResolution = 0;
180  dsGetDisplay((dsVideoPortType_t)vPort.getType().getId(), vPort.getIndex(), &_handle);
181  dsError = dsGetEDID(_handle, &edid);
182  if(dsError != dsERR_NONE)
183  {
184  cout <<" dsGetEDID failed so setting edid.numOfSupportedResolution to 0"<< endl;
185  edid.numOfSupportedResolution = 0;
186  }
187 
188  cout <<" EDID Num of Resolution ......."<< edid.numOfSupportedResolution << endl;
189  for (size_t i = 0; i < edid.numOfSupportedResolution; i++)
190  {
191  dsVideoPortResolution_t *resolution = &edid.suppResolutionList[i];
192  isDynamicList = 1;
193 
194  tmpsupportedResolutions.push_back(
195  VideoResolution(
196  i, /* id */
197  std::string(resolution->name),
198  resolution->pixelResolution,
199  resolution->aspectRatio,
200  resolution->stereoScopicMode,
201  resolution->frameRate,
202  resolution->interlaced));
203  }
204  }
205  }catch (...)
206  {
207  isDynamicList = 0;
208  cout << "VideoOutputPortConfig::getSupportedResolutions Thrown. Exception..."<<endl;
209  }
210  }
211  //If isIgnoreEdid is true isDynamicList is zero. Edid logic is skipped.
212  if (0 == isDynamicList )
213  {
214  size_t numResolutions = dsUTL_DIM(kResolutions);
215  for (size_t i = 0; i < numResolutions; i++)
216  {
217  dsVideoPortResolution_t *resolution = &kResolutions[i];
218  tmpsupportedResolutions.push_back(
219  VideoResolution(
220  i, /* id */
221  std::string(resolution->name),
222  resolution->pixelResolution,
223  resolution->aspectRatio,
224  resolution->stereoScopicMode,
225  resolution->frameRate,
226  resolution->interlaced));
227  }
228  }
229  if (!isIgnoreEdid) {
230  try {
231  dsGetForceDisable4KSupport(_handle, &force_disable_4K);
232  }
233  catch(...)
234  {
235  cout<<"Failed to get status of forceDisable4K!"<<endl;
236  }
237  for (std::vector<VideoResolution>::iterator it = tmpsupportedResolutions.begin(); it != tmpsupportedResolutions.end(); it++) {
238  if (it->isEnabled()) {
239  if((true == force_disable_4K) && (((it->getName() == "2160p60") || (it->getName() == "2160p30"))))
240  {
241  continue;
242  }
243  supportedResolutions.push_back(*it);
244  }
245  }
246  } else {
247  for (std::vector<VideoResolution>::iterator it = tmpsupportedResolutions.begin(); it != tmpsupportedResolutions.end(); it++) {
248  supportedResolutions.push_back(*it);
249  }
250  }
251  {std::lock_guard<std::mutex> lock(gSupportedResolutionsMutex);
252  cout<<"_supportedResolutions cache updated"<<endl;
253  _supportedResolutions.clear ();
254  for (VideoResolution resolution : tmpsupportedResolutions){
255  _supportedResolutions.push_back(resolution);
256  }
257  }
258  return supportedResolutions;
259 }
260 
261 
262 
263 void VideoOutputPortConfig::load()
264 {
265  try {
266  /*
267  * Load Constants First.
268  */
269  for (size_t i = 0; i < dsVIDEO_PIXELRES_MAX; i++) {
270  _vPixelResolutions.push_back(PixelResolution(i));
271  }
272  for (size_t i = 0; i < dsVIDEO_ASPECT_RATIO_MAX; i++) {
273  _vAspectRatios.push_back(AspectRatio(i));
274  }
275  for (size_t i = 0; i < dsVIDEO_SSMODE_MAX; i++) {
276  _vStereoScopieModes.push_back(StereoScopicMode(i));
277  }
278  for (size_t i = 0; i < dsVIDEO_FRAMERATE_MAX; i++) {
279  _vFrameRates.push_back(FrameRate((int)i));
280  }
281 
282  for (size_t i = 0; i < dsVIDEOPORT_TYPE_MAX; i++) {
283  _vPortTypes.push_back(VideoOutputPortType((int)i));
284  }
285 
286  /* Initialize a set of supported resolutions
287  *
288  */
289  size_t numResolutions = dsUTL_DIM(kResolutions);
290  for (size_t i = 0; i < numResolutions; i++) {
291  dsVideoPortResolution_t *resolution = &kResolutions[i];
292  {std::lock_guard<std::mutex> lock(gSupportedResolutionsMutex);
293  _supportedResolutions.push_back(
294  VideoResolution(
295  i, /* id */
296  std::string(resolution->name),
297  resolution->pixelResolution,
298  resolution->aspectRatio,
299  resolution->stereoScopicMode,
300  resolution->frameRate,
301  resolution->interlaced));
302  }
303  }
304 
305 
306  /*
307  * Initialize Video portTypes (Only Enable POrts)
308  * and its port instances (curr resolution)
309  */
310  for (size_t i = 0; i < dsUTL_DIM(kConfigs); i++)
311  {
312  const dsVideoPortTypeConfig_t *typeCfg = &kConfigs[i];
313  VideoOutputPortType &vPortType = VideoOutputPortType::getInstance(typeCfg->typeId);
314  vPortType.enable();
315  vPortType.setRestrictedResolution(typeCfg->restrictedResollution);
316  }
317 
318  /*
319  * set up ports based on kPorts[]
320  */
321  for (size_t i = 0; i < dsUTL_DIM(kPorts); i++) {
322  const dsVideoPortPortConfig_t *port = &kPorts[i];
323 
324  _vPorts.push_back(
325  VideoOutputPort((port->id.type), port->id.index, i,
326  AudioOutputPortType::getInstance(kPorts[i].connectedAOP.type).getPort(kPorts[i].connectedAOP.index).getId(),
327  std::string(port->defaultResolution)));
328 
329  _vPortTypes.at(port->id.type).addPort(_vPorts.at(i));
330 
331  }
332 
333  }
334  catch (...) {
335  cout << "VIdeo Outport Exception Thrown. ..."<<endl;
336  }
337 
338 }
339 
340 void VideoOutputPortConfig::release()
341  {
342  try {
343  _vPixelResolutions.clear();
344  _vAspectRatios.clear();
345  _vStereoScopieModes.clear();
346  _vFrameRates.clear();
347  _vPortTypes.clear();
348  {std::lock_guard<std::mutex> lock(gSupportedResolutionsMutex);
349  _supportedResolutions.clear();
350  }
351  _vPorts.clear();
352  }
353  catch (const Exception &e) {
354  throw e;
355  }
356  }
357 }
358 
359 
360 /** @} */
361 /** @} */
device::VideoOutputPort::getIndex
int getIndex() const
This function returns the index of the video output port.
Definition: videoOutputPort.hpp:234
dsVIDEO_SSMODE_MAX
@ dsVIDEO_SSMODE_MAX
Definition: dsTypes.h:566
dsVIDEO_FRAMERATE_59dot94
@ dsVIDEO_FRAMERATE_59dot94
Definition: dsTypes.h:511
dsVIDEO_ASPECT_RATIO_16x9
@ dsVIDEO_ASPECT_RATIO_16x9
Definition: dsTypes.h:549
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
_dsVideoPortResolution_t::stereoScopicMode
dsVideoStereoScopicMode_t stereoScopicMode
Definition: dsTypes.h:646
device::VideoOutputPort
Class extending enumerable to implement the videoooutputport interface.
Definition: videoOutputPort.hpp:59
dsVIDEO_FRAMERATE_MAX
@ dsVIDEO_FRAMERATE_MAX
Definition: dsTypes.h:512
dsVIDEO_PIXELRES_1280x720
@ dsVIDEO_PIXELRES_1280x720
Definition: dsTypes.h:461
dsGetEDID
dsError_t dsGetEDID(intptr_t handle, dsDisplayEDID_t *edid)
Get the EDID information from the specified display device.
Definition: dsDisplay.c:119
dsVideoPortType_t
enum _dsVideoPortType_t dsVideoPortType_t
_dsVideoPortTypeConfig_t::typeId
dsVideoPortType_t typeId
Definition: dsTypes.h:674
dsVideoPort.h
_dsVideoPortResolution_t::pixelResolution
dsVideoResolution_t pixelResolution
Definition: dsTypes.h:644
dsError.h
Device Settings HAL error codes.
dsGetDisplay
dsError_t dsGetDisplay(dsVideoPortType_t vType, int index, intptr_t *handle)
Get the handle of a display device.
Definition: dsDisplay.c:65
_dsVideoPortPortConfig_t::defaultResolution
const char * defaultResolution
Definition: dsTypes.h:740
dsUtl.h
Device Settings HAL utilities.
_dsVideoPortPortConfig_t::id
dsVideoPortPortId_t id
Definition: dsTypes.h:738
device::VideoOutputPort::getType
const VideoOutputPortType & getType() const
This API is used to get the type of the video output port. A type of the video output port represent ...
Definition: videoOutputPort.cpp:265
videoOutputPortType.hpp
It contains structures and class referenced by the videoOutputportTypes.cpp file.
dsERR_NONE
@ dsERR_NONE
Definition: dsError.h:85
_dsDisplayEDID_t::numOfSupportedResolution
int32_t numOfSupportedResolution
Definition: dsTypes.h:912
videoResolution.hpp
It contains class and structure refrenced by the videoResolution.cpp file.
_dsVideoPortPortConfig_t
Structure that defines video port configuration settings.
Definition: dsTypes.h:737
_dsVideoPortPortId_t::type
dsVideoPortType_t type
Definition: dsTypes.h:665
_dsVideoPortTypeConfig_t::restrictedResollution
int32_t restrictedResollution
Definition: dsTypes.h:678
_dsVideoPortTypeConfig_t
Structure that defines the video output port configuration.
Definition: dsTypes.h:673
_dsVideoPortResolution_t::aspectRatio
dsVideoAspectRatio_t aspectRatio
Definition: dsTypes.h:645
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
_dsVideoPortResolution_t::name
char name[32]
Definition: dsTypes.h:643
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
dsVIDEO_PIXELRES_MAX
@ dsVIDEO_PIXELRES_MAX
Definition: dsTypes.h:467
dsVIDEOPORT_TYPE_MAX
@ dsVIDEOPORT_TYPE_MAX
Definition: dsTypes.h:445
_dsVideoPortPortId_t::index
int32_t index
Definition: dsTypes.h:666
_dsVideoPortResolution_t::frameRate
dsVideoFrameRate_t frameRate
Definition: dsTypes.h:647
_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
Exception
Definition: Exception.hpp:42
dsError_t
dsError_t
Device Settings API Error return codes.
Definition: dsError.h:84
dsVIDEO_ASPECT_RATIO_MAX
@ dsVIDEO_ASPECT_RATIO_MAX
Definition: dsTypes.h:550
dsVIDEO_SSMODE_2D
@ dsVIDEO_SSMODE_2D
Definition: dsTypes.h:563
device::DSConstant::getId
virtual int getId() const
This function is used to get the id.
Definition: dsConstant.hpp:130
_dsVideoPortResolution_t::interlaced
bool interlaced
Definition: dsTypes.h:648