RDK Documentation (Open Sourced RDK Components)
audioOutputPortConfig.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 #include "dsHALConfig.h"
30 #include "audioOutputPortConfig.hpp"
31 #include "dsAudioSettings.h"
32 #include "illegalArgumentException.hpp"
33 #include "dsError.h"
34 #include "dsUtl.h"
35 #include "stdlib.h"
36 #include "dslogger.h"
37 
38 namespace device {
39 
40 //To Make the instance as thread-safe, using = default, that can request special methods from the compiler. They are Special because only compiler can create them.
41 
42 AudioOutputPortConfig::AudioOutputPortConfig()= default;
43 
44 AudioOutputPortConfig::~AudioOutputPortConfig()= default;
45 
46 
47 AudioOutputPortConfig & AudioOutputPortConfig::getInstance()
48 {
49  static AudioOutputPortConfig _singleton; // _singleton instance is in thread-safe now.
50  return _singleton;
51 }
52 
53 const AudioEncoding &AudioOutputPortConfig::getEncoding(int id) const
54 {
55  return _aEncodings.at(id);
56 }
57 const AudioCompression &AudioOutputPortConfig::getCompression(int id) const
58 {
59  return _aCompressions.at(id);
60 
61 }
62 const AudioStereoMode &AudioOutputPortConfig::getStereoMode(int id) const
63 {
64  return _aStereoModes.at(id);
65 
66 }
67 AudioOutputPortType & AudioOutputPortConfig::getPortType(int id)
68 {
69  return _aPortTypes.at(id);
70 }
71 
72 AudioOutputPort &AudioOutputPortConfig::getPort(int id)
73 {
74  return _aPorts.at(id);
75 }
76 
77 AudioOutputPort &AudioOutputPortConfig::getPort(const std::string & name)
78 {
79  for (size_t i = 0; i < _aPorts.size(); i++) {
80  if (name.compare(_aPorts.at(i).getName()) == 0) {
81  return _aPorts.at(i);
82  }
83  }
84 
85  throw IllegalArgumentException();
86 }
87 
88 List<AudioOutputPort> AudioOutputPortConfig::getPorts()
89 {
90  List <AudioOutputPort> rPorts;
91 
92  for (size_t i = 0; i < _aPorts.size(); i++) {
93  rPorts.push_back(_aPorts.at(i));
94  }
95 
96  return rPorts;
97 }
98 
99 List<AudioOutputPortType> AudioOutputPortConfig::getSupportedTypes()
100 {
101  List<AudioOutputPortType> supportedTypes;
102  for (std::vector<AudioOutputPortType>::const_iterator it = _aPortTypes.begin(); it != _aPortTypes.end(); it++) {
103  if (it->isEnabled()) {
104  supportedTypes.push_back(*it);
105  }
106  }
107 
108  return supportedTypes;
109 }
110 
111 void AudioOutputPortConfig::load()
112 {
113  try {
114  /*
115  * Load Constants First.
116  */
117  for (int i = 0; i < dsAUDIO_ENC_MAX; i++) {
118  _aEncodings.push_back(AudioEncoding(i));
119  }
120 
121  for (int i = 0; i < dsAUDIO_CMP_MAX; i++) {
122  _aCompressions.push_back(AudioCompression(i));
123 
124  }
125 
126  for (int i = 0; i < dsAUDIO_STEREO_MAX; i++) {
127  _aStereoModes.push_back(AudioStereoMode(i));
128 
129  }
130 
131  for (int i = 0; i < dsAUDIOPORT_TYPE_MAX; i++) {
132  _aPortTypes.push_back(AudioOutputPortType(i));
133 
134  }
135 
136  /*
137  * Initialize Audio portTypes (encodings, compressions etc.)
138  * and its port instances (db, level etc)
139  */
140  for (size_t i = 0; i < dsUTL_DIM(kConfigs); i++) {
141  const dsAudioTypeConfig_t *typeCfg = &kConfigs[i];
142  AudioOutputPortType &aPortType = AudioOutputPortType::getInstance(typeCfg->typeId);
143  aPortType.enable();
144  for (size_t j = 0; j < typeCfg->numSupportedEncodings; j++) {
145  aPortType.addEncoding(AudioEncoding::getInstance(typeCfg->encodings[j]));
146  _aEncodings.at(typeCfg->encodings[j]).enable();
147  }
148  for (size_t j = 0; j < typeCfg->numSupportedCompressions; j++) {
149  aPortType.addCompression(typeCfg->compressions[j]);
150  _aCompressions.at(typeCfg->compressions[j]).enable();
151 
152  }
153  for (size_t j = 0; j < typeCfg->numSupportedStereoModes; j++) {
154  aPortType.addStereoMode(typeCfg->stereoModes[j]);
155  _aStereoModes.at(typeCfg->stereoModes[j]).enable();
156 
157  }
158  }
159 
160  /*
161  * set up ports based on kPorts[]
162  */
163  for (size_t i = 0; i < dsUTL_DIM(kPorts); i++) {
164  const dsAudioPortConfig_t *port = &kPorts[i];
165  _aPorts.push_back(AudioOutputPort((port->id.type), port->id.index, i));
166  _aPortTypes.at(port->id.type).addPort(_aPorts.at(i));
167  }
168 
169  }
170  catch(const Exception &e) {
171  throw e;
172  }
173 }
174 
175 void AudioOutputPortConfig::release()
176  {
177  try {
178  _aEncodings.clear();
179  _aCompressions.clear();
180  _aStereoModes.clear();
181  _aPortTypes.clear();
182  _aPorts.clear();
183  }
184  catch(const Exception &e) {
185  throw e;
186  }
187 
188  }
189 }
190 
191 
192 
193 /** @} */
194 /** @} */
_dsAudioPortConfig_t::id
dsAudioPortId_t id
Definition: dsTypes.h:727
_dsAudioTypeConfig_t::typeId
int32_t typeId
Definition: dsTypes.h:628
device::AudioEncoding::getInstance
static const AudioEncoding & getInstance(int id)
This function gets an AudioEncoding instance against the id parameter, only if the id passed is valid...
Definition: audioEncoding.cpp:82
dsAUDIO_CMP_MAX
@ dsAUDIO_CMP_MAX
Definition: dsTypes.h:205
dsAUDIOPORT_TYPE_MAX
@ dsAUDIOPORT_TYPE_MAX
Definition: dsTypes.h:172
_dsAudioTypeConfig_t::numSupportedStereoModes
size_t numSupportedStereoModes
Definition: dsTypes.h:634
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
_dsAudioTypeConfig_t::encodings
const dsAudioEncoding_t * encodings
Definition: dsTypes.h:633
_dsAudioPortId_t::index
int32_t index
Definition: dsTypes.h:657
dsAUDIO_ENC_MAX
@ dsAUDIO_ENC_MAX
Definition: dsTypes.h:189
dsError.h
Device Settings HAL error codes.
dsUtl.h
Device Settings HAL utilities.
_dsAudioTypeConfig_t
Structure that defines audio output device configuration.
Definition: dsTypes.h:627
_dsAudioTypeConfig_t::numSupportedEncodings
size_t numSupportedEncodings
Definition: dsTypes.h:632
_dsAudioTypeConfig_t::numSupportedCompressions
size_t numSupportedCompressions
Definition: dsTypes.h:630
_dsAudioTypeConfig_t::stereoModes
const dsAudioStereoMode_t * stereoModes
Definition: dsTypes.h:635
dsUTL_DIM
#define dsUTL_DIM(arr)
Device Settings general Array dimension calculation inline definition.
Definition: dsUtl.h:85
Exception
Definition: Exception.hpp:42
dsAUDIO_STEREO_MAX
@ dsAUDIO_STEREO_MAX
Definition: dsTypes.h:381
_dsAudioTypeConfig_t::compressions
const dsAudioCompression_t * compressions
Definition: dsTypes.h:631
_dsAudioPortConfig_t
Structure that defines audio port configuration.
Definition: dsTypes.h:726
_dsAudioPortId_t::type
dsAudioPortType_t type
Definition: dsTypes.h:656