RDK Documentation (Open Sourced RDK Components)
audioEncoding.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 audioEncoding.cpp
22  * @brief This file contains implementation of AudioEncoding class methods,
23  * support functions and variable assignments to manage the audio encoding types.
24  */
25 
26 
27 
28 /**
29 * @defgroup devicesettings
30 * @{
31 * @defgroup ds
32 * @{
33 **/
34 
35 
36 #include "audioEncoding.hpp"
37 #include "audioOutputPortConfig.hpp"
38 #include "illegalArgumentException.hpp"
39 #include "dsTypes.h"
40 #include "dsUtl.h"
41 #include <string.h>
42 #include "dslogger.h"
43 
44 namespace {
45  const char *_names[] = {
46  "NONE",
47  "DISPLAY",
48  "PCM",
49  "AC3",
50  "EAC3",
51  };
52 
53  inline const bool isValid(int id) {
54  return dsAudioEncoding_isValid(id);
55  }
56 
57 }
58 
59 namespace device {
60 typedef int _SafetyCheck[(dsUTL_DIM(_names) == dsAUDIO_ENC_MAX) ? 1 : -1];
61 
67 
68 /**
69  * @addtogroup dssettingsaudencodingapi
70  * @{
71  */
72 /**
73  * @fn AudioEncoding::getInstance(int id)
74  * @brief This function gets an AudioEncoding instance against the id parameter, only if the id
75  * passed is valid.
76  *
77  * @param[in] id Indicates the id against which the AudioEncoding instance is required. The id
78  * is used to identify the audio encoding types.
79  *
80  * @return Returns AudioEncoding instance if the id is valid else throws an IllegalArgumentException.
81  */
83 {
84  if (::isValid(id)) {
85  return AudioOutputPortConfig::getInstance().getEncoding(id);
86  }
87  else {
89  }
90 }
91 
92 
93 /**
94  * @fn AudioEncoding::getInstance(const std::string &name)
95  * @brief This function gets an AudioEncoding instance against the specified name, only if the name
96  * passed is valid.
97  *
98  * @param[in] name Indicates the name against which the AudioEncoding instance is required and it is also
99  * used to identify the audio encoding types.
100  *
101  * @return Returns AudioEncoding instance if the name is valid else throws an IllegalArgumentException.
102  */
103 const AudioEncoding & AudioEncoding::getInstance(const std::string &name)
104 {
105  for (size_t i = 0; i < dsUTL_DIM(_names); i++) {
106  if (name.compare(_names[i]) == 0) {
107  return AudioEncoding::getInstance(i);
108  }
109  }
110 
111  throw IllegalArgumentException();
112 }
113 
114 
115 /**
116  * @fn AudioEncoding::AudioEncoding(int id)
117  * @brief This function is the default constructor for AudioEncoding. It initializes the instance with
118  * the id passed as input. If the id parameter is invalid then it throws an IllegalArgumentException.
119  *
120  * @param[in] id Indicates the audio encoding type.
121  * <ul>
122  * <li> id 0 indicates encoding type None
123  * <li> id 1 indicates digital audio encoding format
124  * <li> id 2 indicates PCM encoding type
125  * <li> id 3 indicates AC3 encoding type
126  * </ul>
127  *
128  * @return None
129  */
131 {
132 
133  if (::isValid(id)) {
134  _id = id;
135  _name = std::string(_names[id]);
136 
137  }
138  else {
139  throw IllegalArgumentException();
140  }
141 }
142 
143 
144 /**
145  * @fn AudioEncoding::~AudioEncoding()
146  * @brief This function is the default destructor of AudioEncoding class.
147  *
148  * @return None
149  */
151 {
152 }
153 
154 
155 }
156 
157 /** @} */
158 
159 /** @} */
160 /** @} */
device::DSConstant::_id
int _id
Indicates the id of the instance inheriting this class.
Definition: dsConstant.hpp:57
device::AudioEncoding::AudioEncoding
AudioEncoding(int id)
This function is the default constructor for AudioEncoding. It initializes the instance with the id p...
Definition: audioEncoding.cpp:130
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
device::AudioEncoding::kMax
static const int kMax
Indicates the maximum encoding formats supported.
Definition: audioEncoding.hpp:58
device::AudioEncoding::~AudioEncoding
virtual ~AudioEncoding()
This function is the default destructor of AudioEncoding class.
Definition: audioEncoding.cpp:150
device::AudioEncoding::kDisplay
static const int kDisplay
Value indicating digital audio encoding format.
Definition: audioEncoding.hpp:55
dsTypes.h
Device Settings HAL types.
device::AudioEncoding::kNone
static const int kNone
Value indicating encoding type None.
Definition: audioEncoding.hpp:54
dsAudioEncoding_isValid
#define dsAudioEncoding_isValid(t)
Definition: dsTypes.h:195
dsAUDIO_ENC_MAX
@ dsAUDIO_ENC_MAX
Definition: dsTypes.h:189
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
dsAUDIO_ENC_NONE
@ dsAUDIO_ENC_NONE
Definition: dsTypes.h:184
dsAUDIO_ENC_PCM
@ dsAUDIO_ENC_PCM
Definition: dsTypes.h:186
dsUtl.h
Device Settings HAL utilities.
device::DSConstant::_name
std::string _name
Indicates the name string of the instance inheriting this class.
Definition: dsConstant.hpp:58
device::AudioEncoding::kAC3
static const int kAC3
Value indicating AC3 digital audio encoding format.
Definition: audioEncoding.hpp:57
device::AudioEncoding::kPCM
static const int kPCM
Value indicating PCM digital audio encoding format.
Definition: audioEncoding.hpp:56
dsAUDIO_ENC_AC3
@ dsAUDIO_ENC_AC3
Definition: dsTypes.h:187
dsAUDIO_ENC_DISPLAY
@ dsAUDIO_ENC_DISPLAY
Definition: dsTypes.h:185
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
audioEncoding.hpp
This file defines AudioEncoding class for managing audio encoding types.