RDK Documentation (Open Sourced RDK Components)
aspectRatio.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 aspectRatio.cpp
22  * @brief This file contains implementation of AspectRatio class methods,
23  * variable assignments and support functions to manage the aspect ratio types.
24  */
25 
26 
27 
28 /**
29 * @defgroup devicesettings
30 * @{
31 * @defgroup ds
32 * @{
33 **/
34 
35 
36 #include "aspectRatio.hpp"
37 #include "illegalArgumentException.hpp"
38 #include "videoOutputPortConfig.hpp"
39 #include "dsTypes.h"
40 #include "dsUtl.h"
41 #include "dslogger.h"
42 
43 namespace {
44  const char *_names[] = {
45  "4x3",
46  "16x9",
47  };
48 
49  inline const bool isValid(int id) {
51  }
52 }
53 
54 namespace device {
55 typedef int _SafetyCheck[(dsUTL_DIM(_names) == dsVIDEO_ASPECT_RATIO_MAX) ? 1 : -1];
56 
60 
61 
62 /**
63  * @fn AspectRatio::getInstance(int id)
64  * @brief This function gets the instance of the AspectRatio against the id specified, only if
65  * the id passed is valid.
66  *
67  * @param[in] id Indicates the id against which the AspectRatio instance is required. The id
68  * is used to identify the type of aspect ratio. For example: id of 0 and 1 may correspond to
69  * "4x3" and "16x9" aspect ratio respectively.
70  *
71  * @return Returns an instance of AspectRatio against the id parameter or else throws an
72  * IllegalArgumentException indicating that the specified id is invalid.
73  */
75 {
76  if (::isValid(id)) {
77  return VideoOutputPortConfig::getInstance().getAspectRatio(id);
78  }
79  else {
81  }
82 }
83 
84 
85 /**
86  * @fn AspectRatio::getInstance(const std::string &name)
87  * @brief This function gets the instance of the AspectRatio against the name specified, only if
88  * the name passed is valid.
89  *
90  * @param[in] name Indicates the name against which the AspectRatio instance is required. The name
91  * is used to identify the type of aspect ratio. For example: id of 0 and 1 may correspond to
92  * 4x3 and 16x9 aspect ratio respectively.
93  *
94  * @return Returns an AspectRatio instance against the name specified or else throws an
95  * IllegalArgumentException indicating that the specified name is invalid.
96  */
97 const AspectRatio & AspectRatio::getInstance(const std::string &name)
98 {
99  for (size_t i = 0; i < dsUTL_DIM(_names); i++) {
100  if (name.compare(_names[i]) == 0) {
101  return AspectRatio::getInstance(i);
102  }
103  }
104 
105  throw IllegalArgumentException();
106 }
107 
108 
109 /**
110  * @fn AspectRatio::AspectRatio(int id)
111  * @brief This function is a parameterised constructor. It initializes the instance with
112  * the specified id and also the name which is predefined for the id. It throws an
113  * IllegalArgumentException if the id specified is invalid.
114  *
115  * @param[in] id Indicates the aspect ratio for the instance created. For example: 0 indicates "4x3"
116  * aspect ratio and 1 indicates "16x9" aspect ratio .
117  *
118  * @return None
119  */
121 {
122  if (::isValid(id)) {
123  _id = id;
124  _name = std::string(_names[id]);
125  }
126  else {
127  throw IllegalArgumentException();
128  }
129 }
130 
131 
132 /**
133  * @fn AspectRatio::~AspectRatio()
134  * @brief This function is the default destructor of AspectRatio class.
135  *
136  * @return None
137  */
139 {
140 }
141 
142 }
143 
144 
145 /** @} */
146 /** @} */
device::DSConstant::_id
int _id
Indicates the id of the instance inheriting this class.
Definition: dsConstant.hpp:57
device::AspectRatio::AspectRatio
AspectRatio(int id)
This function is a parameterised constructor. It initializes the instance with the specified id and a...
Definition: aspectRatio.cpp:120
dsVIDEO_ASPECT_RATIO_16x9
@ dsVIDEO_ASPECT_RATIO_16x9
Definition: dsTypes.h:549
aspectRatio.hpp
This file defines AspectRatio class for managing aspect ratio types.
dsTypes.h
Device Settings HAL types.
dsVideoPortAspectRatio_isValid
#define dsVideoPortAspectRatio_isValid(t)
Definition: dsTypes.h:556
device::AspectRatio::k16x9
static const int k16x9
Indicates 16x9 aspect ratio.
Definition: aspectRatio.hpp:54
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
dsUtl.h
Device Settings HAL utilities.
device::AspectRatio::getInstance
static const AspectRatio & getInstance(int id)
This function gets the instance of the AspectRatio against the id specified, only if the id passed is...
Definition: aspectRatio.cpp:74
device::DSConstant::_name
std::string _name
Indicates the name string of the instance inheriting this class.
Definition: dsConstant.hpp:58
device::AspectRatio::k4x3
static const int k4x3
Indicates 4x3 aspect ratio.
Definition: aspectRatio.hpp:53
dsVIDEO_ASPECT_RATIO_4x3
@ dsVIDEO_ASPECT_RATIO_4x3
Definition: dsTypes.h:548
device::AspectRatio::kMax
static const int kMax
Indicates maximum number of aspect ratios supported.
Definition: aspectRatio.hpp:55
device::AspectRatio
This class extends DSConstant to implement AspectRatio. It manages the aspect ratios of the videos.
Definition: aspectRatio.hpp:50
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
device::AspectRatio::~AspectRatio
virtual ~AspectRatio()
This function is the default destructor of AspectRatio class.
Definition: aspectRatio.cpp:138
dsVIDEO_ASPECT_RATIO_MAX
@ dsVIDEO_ASPECT_RATIO_MAX
Definition: dsTypes.h:550