RDK Documentation (Open Sourced RDK Components)
audioOutputPortType.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 #include <unistd.h>
30 #include "dsHALConfig.h"
31 #include "audioOutputPortType.hpp"
32 #include "audioOutputPortConfig.hpp"
33 #include "illegalArgumentException.hpp"
34 #include "list.hpp"
35 #include "dsTypes.h"
36 #include "dsUtl.h"
37 #include <iostream>
38 #include "dslogger.h"
39 
40 
41 /**
42  * @file audioOutputPortType.cpp
43  * @brief AudioOutputPortType objects are instantiated by the Device Settings module upon initialization.
44  * Applications do not need to create any such objects on its own.
45  * References to these objects can be retrieved using a AudioOutputPort object invoking AudioOutputPort::getType()
46  */
47 namespace {
48  const char *_names[] = {
49  "IDLR",
50  "HDMI",
51  "SPDIF",
52  "SPEAKER",
53  "HDMI_ARC",
54  "HEADPHONE",
55  };
56 
57  inline const bool isValid(int id) {
58  return dsAudioType_isValid(id);
59  }
60 }
61 
62 namespace device {
63 
64 typedef int _SafetyCheck[(dsUTL_DIM(_names) == dsAUDIOPORT_TYPE_MAX) ? 1 : -1];
65 
66 const int AudioOutputPortType::kIDLR = dsAUDIOPORT_TYPE_ID_LR;
67 const int AudioOutputPortType::kHDMI = dsAUDIOPORT_TYPE_HDMI;
68 const int AudioOutputPortType::kSPDIF = dsAUDIOPORT_TYPE_SPDIF;
69 const int AudioOutputPortType::kSPEAKER = dsAUDIOPORT_TYPE_SPEAKER;
70 const int AudioOutputPortType::kARC = dsAUDIOPORT_TYPE_HDMI_ARC;
71 const int AudioOutputPortType::kHEADPHONE = dsAUDIOPORT_TYPE_HEADPHONE;
72 
73 
74 
75 /**
76  * @addtogroup dssettingsaudoutporttypeapi
77  * @{
78  */
79 
80 /**
81  * @fn AudioOutputPortType & AudioOutputPortType::getInstance(int id)
82  * @brief This function is used to get the instance of the AudioOutputPortType based on the port id,
83  * only if the id passed is valid.
84  *
85  * @param[in] id Port id
86  *
87  * @return Returns a reference to the instance of the audioOutputPortType. If the id passed
88  * is invalid then it throws an IllegalArgumentException.
89  */
91 {
92  if (::isValid(id)) {
93  return AudioOutputPortConfig::getInstance().getPortType(id);
94  }
95  else {
97  }
98 }
99 
100 
101 /**
102  * @fn AudioOutputPortType::AudioOutputPortType(int id)
103  * @brief This is a default constructor of class AudioOutputPortType. It initializes the AudioOutputPortType
104  * instance based on the port id. If the id passed is invalid then it throws an IllegalArgumentException.
105  *
106  * @param[in] id Port id
107  * @return None.
108  */
110 {
111  if (::isValid(id)) {
112  _id = id;
113  _name = std::string(_names[id]);
114  }
115  else {
116  throw IllegalArgumentException();
117  }
118 }
119 
120 
121 /**
122  * @fn AudioOutputPortType::~AudioOutputPortType()
123  * @brief This is a default destructor of class AudioOutputPortType.
124  *
125  * @return None.
126  */
128 {
129 }
130 
131 
132 /**
133  * @fn AudioOutputPortType::getSupportedCompressions() const
134  * @brief This API is used to get the list of audio compressions supported by the audio port.
135  *
136  * @return Returns a list of audio compressions supported.
137  */
139 {
140  return _compressions;
141 }
142 
143 
144 /**
145  * @fn AudioOutputPortType::getSupportedEncodings() const
146  * @brief This API is used to get the list of audio encodings supported by the audio port .
147  *
148  * @return A list of audio encodings supported.
149  */
151 {
152  return _encodings;
153 }
154 
155 
156 /**
157  * @fn AudioOutputPortType::getSupportedStereoModes() const
158  * @brief This API is used to get the list of audio stereo modes supported by the audio port.
159  *
160  * @param None
161  *
162  * @return A list of stereo modes supported
163  */
165 {
166  return _stereoModes;
167 }
168 
169 
170 /**
171  * @fn const List<AudioOutputPort> AudioOutputPortType::getPorts() const
172  * @brief This function is used to get the list of platform supported audio output ports.
173  *
174  * @return _aPorts List of audiooutputports.
175  */
177 {
178  return _aPorts;
179 }
180 
181 
182 /**
183  * @fn AudioOutputPort &AudioOutputPortType::getPort(int index)
184  * @brief This function is used to get the AudioOutputPort instance based on the index.
185  *
186  * @param[in] index Index of the audio output port.
187  * @return Reference to the instance of the audiooutputport.
188  */
190 {
191  for (size_t i = 0; i < _aPorts.size(); i++) {
192  if (_aPorts.at(i).getIndex() == index) {
193  return _aPorts.at(i);
194  }
195  }
196 
197  throw IllegalArgumentException();
198 }
199 
200 
201 /**
202  * @fn void AudioOutputPortType::addEncoding(const AudioEncoding & encoding)
203  * @brief This function is used to add the specified encoding types to the list of supported encodings for
204  * AudioOutputPortType.
205  *
206  * @param[in] encoding Type of encoding used in the audio output port type.
207  */
209 {
210  _encodings.push_back(encoding);
211 }
212 
213 
214 /**
215  * @fn void AudioOutputPortType::addCompression(const AudioCompression & compression)
216  * @brief This function is used to add the specified compression types to the list of supported compressions for
217  * AudioOutputPortType.
218  *
219  * @param[in] compression Type of compression used in the audio output port type.
220  *
221  * @return None.
222  */
224 {
225  _compressions.push_back(compression);
226 }
227 
228 
229 /**
230  * @fn void AudioOutputPortType::addStereoMode(const AudioStereoMode & stereoMode)
231  * @brief This function is used to add the specified stereoMode types to the list of supported stereo modes for
232  * AudioOutputPortType.
233  *
234  * @param[in] stereoMode Type of stereoMode used in the audio output port type.
235  *
236  * @return None.
237  */
239 {
240  _stereoModes.push_back(stereoMode);
241 }
242 
243 
244 /**
245  * @fn void AudioOutputPortType::addPort(const AudioOutputPort & port)
246  * @brief This function is used to add the specified audio port to the list of supported audio ports.
247  *
248  * @param[in] port Indicates the port to be added to the list of supported audio portsi.
249  *
250  * @return None.
251  */
253 {
254  _aPorts.push_back(port);
255 }
256 
257 /**
258  * @fn void AudioOutputPortType::isModeSupported(int newMode)
259  * @brief This function is used to find out if requested Audio mode is supported by Platform
260  *
261  * @param[in] newMode Indicates the requested Audio mode to be validated against supported Audio modes.
262  *
263  * @return True means Supported..
264  */
266 {
267  bool supported = false;
269 
270  for (size_t j = 0; j < aStereoModes.size(); j++)
271  {
272  //std::cout << "StereoModes requested = " << newMode << std::endl;
273  //std::cout << "StereoModes supported = " << aStereoModes.at(j).getId() << std::endl;
274  if(newMode == aStereoModes.at(j).getId())
275  {
276  supported = true;
277  break;
278  }
279  }
280  return supported;
281 }
282 
283 }
284 
285 /** @} */
286 
287 /** @} */
288 /** @} */
dsAUDIOPORT_TYPE_SPEAKER
@ dsAUDIOPORT_TYPE_SPEAKER
Definition: dsTypes.h:169
device::DSConstant::_id
int _id
Indicates the id of the instance inheriting this class.
Definition: dsConstant.hpp:57
device::AudioOutputPortType::~AudioOutputPortType
virtual ~AudioOutputPortType()
This is a default destructor of class AudioOutputPortType.
Definition: audioOutputPortType.cpp:127
device::AudioOutputPortType::getPorts
const List< AudioOutputPort > getPorts() const
This function is used to get the list of platform supported audio output ports.
Definition: audioOutputPortType.cpp:176
device::AudioOutputPortType::_aPorts
List< AudioOutputPort > _aPorts
List of audio ports.
Definition: audioOutputPortType.hpp:62
dsAUDIOPORT_TYPE_MAX
@ dsAUDIOPORT_TYPE_MAX
Definition: dsTypes.h:172
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
device::AudioOutputPortType::addPort
void addPort(const AudioOutputPort &port)
This function is used to add the specified audio port to the list of supported audio ports.
Definition: audioOutputPortType.cpp:252
device::AudioCompression
This class extends DSConstant for implementing AudioCompression. It helps to maintain different audio...
Definition: audioCompression.hpp:49
device::AudioOutputPortType::_stereoModes
List< AudioStereoMode > _stereoModes
List of stereo modes.
Definition: audioOutputPortType.hpp:61
device::AudioOutputPortType::getInstance
static AudioOutputPortType & getInstance(int id)
This function is used to get the instance of the AudioOutputPortType based on the port id,...
Definition: audioOutputPortType.cpp:90
dsTypes.h
Device Settings HAL types.
device::AudioOutputPortType::_compressions
List< AudioCompression > _compressions
List of compression types.
Definition: audioOutputPortType.hpp:60
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
device::AudioStereoMode
This class extends DSConstant to implement AudioStereoMode. It manages the information related to aud...
Definition: audioStereoMode.hpp:52
dsAUDIOPORT_TYPE_HEADPHONE
@ dsAUDIOPORT_TYPE_HEADPHONE
Definition: dsTypes.h:171
device::AudioOutputPortType::getSupportedStereoModes
const List< AudioStereoMode > getSupportedStereoModes() const
This API is used to get the list of audio stereo modes supported by the audio port.
Definition: audioOutputPortType.cpp:164
device::List::size
size_t size()
This function gets the size of the container.
Definition: list.hpp:118
dsUtl.h
Device Settings HAL utilities.
device::AudioOutputPort
Class extending Enumerable to implement the audiooutputport interface.
Definition: audioOutputPort.hpp:60
device::AudioOutputPortType::addCompression
void addCompression(const AudioCompression &compression)
This function is used to add the specified compression types to the list of supported compressions fo...
Definition: audioOutputPortType.cpp:223
device::AudioOutputPortType::addStereoMode
void addStereoMode(const AudioStereoMode &stereoMode)
This function is used to add the specified stereoMode types to the list of supported stereo modes for...
Definition: audioOutputPortType.cpp:238
device::AudioOutputPortType::AudioOutputPortType
AudioOutputPortType(int id)
This is a default constructor of class AudioOutputPortType. It initializes the AudioOutputPortType in...
Definition: audioOutputPortType.cpp:109
device::AudioOutputPortType::addEncoding
void addEncoding(const AudioEncoding &encoding)
This function is used to add the specified encoding types to the list of supported encodings for Audi...
Definition: audioOutputPortType.cpp:208
device::DSConstant::_name
std::string _name
Indicates the name string of the instance inheriting this class.
Definition: dsConstant.hpp:58
device::AudioOutputPortType::getPort
AudioOutputPort & getPort(int index)
This function is used to get the AudioOutputPort instance based on the index.
Definition: audioOutputPortType.cpp:189
dsAUDIOPORT_TYPE_SPDIF
@ dsAUDIOPORT_TYPE_SPDIF
Definition: dsTypes.h:168
device::AudioOutputPortType
Class extending DSConstant to implement the audiooutputport interface.
Definition: audioOutputPortType.hpp:56
device::AudioOutputPortType::getSupportedEncodings
const List< AudioEncoding > getSupportedEncodings() const
This API is used to get the list of audio encodings supported by the audio port .
Definition: audioOutputPortType.cpp:150
device::AudioOutputPortType::isModeSupported
bool isModeSupported(int newMode)
This function is used to find out if requested Audio mode is supported by Platform.
Definition: audioOutputPortType.cpp:265
device::List< device::AudioStereoMode >
audioOutputPortType.hpp
It contain variables,stuctures,class and functions referenced by audiooutputportType code.
device::IllegalArgumentException
This class extends Exception class to manage the expections caused due to illegal arguments.
Definition: illegalArgumentException.hpp:51
device::AudioEncoding
This class extends DSConstant to implement AudioEncoding which manages audio encodings.
Definition: audioEncoding.hpp:51
dsUTL_DIM
#define dsUTL_DIM(arr)
Device Settings general Array dimension calculation inline definition.
Definition: dsUtl.h:85
dsAudioType_isValid
#define dsAudioType_isValid(t)
Definition: dsTypes.h:178
dsAUDIOPORT_TYPE_ID_LR
@ dsAUDIOPORT_TYPE_ID_LR
Definition: dsTypes.h:166
device::AudioOutputPortType::getSupportedCompressions
const List< AudioCompression > getSupportedCompressions() const
This API is used to get the list of audio compressions supported by the audio port.
Definition: audioOutputPortType.cpp:138
device::DSConstant::getId
virtual int getId() const
This function is used to get the id.
Definition: dsConstant.hpp:130
device::AudioOutputPortType::_encodings
List< AudioEncoding > _encodings
List of encoding types.
Definition: audioOutputPortType.hpp:59
dsAUDIOPORT_TYPE_HDMI
@ dsAUDIOPORT_TYPE_HDMI
Definition: dsTypes.h:167