RDK Documentation (Open Sourced RDK Components)
audioCompression.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 audioCompression.cpp
22  * @brief This file contains implementation of audioCompression class methods,
23  * variable assignments and support functions to manage the audio compression types.
24  */
25 
26 
27 
28 /**
29 * @defgroup devicesettings
30 * @{
31 * @defgroup ds
32 * @{
33 **/
34 
35 
36 #include "audioCompression.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  "LIGHT",
48  "MEDIUM",
49  "HEAVY",
50  };
51 
52  inline const bool isValid(int id) {
53  return dsAudioCompression_isValid(id);
54  }
55 
56 }
57 
58 namespace device {
59 typedef int _SafetyCheck[(dsUTL_DIM(_names) == dsAUDIO_CMP_MAX) ? 1 : -1];
60 
66 
67 
68 /**
69  * @fn AudioCompression::getInstance(int id)
70  * @brief This function gets an instance of AudioCompression against the specified id, only if
71  * the id passed is valid.
72  *
73  * @param[in] id Indicates id/index into the list of AudioCompression to get required instance.
74  * Id is used to identify the type of compression like light, heavy or medium.
75  *
76  * @return Returns an instance of AudioCompression against the id specified or else throws an
77  * IllegalArgumentException indicating that the instance against specified id was not found.
78  */
80 {
81  if (::isValid(id)) {
82  return AudioOutputPortConfig::getInstance().getCompression(id);
83  }
84  else {
86  }
87 }
88 
89 
90 /**
91  * @fn AudioCompression::getInstance(const std::string &name)
92  * @brief This function gets an instance of AudioCompression against the specified name, only if the
93  * name passed is valid.
94  *
95  * @param[in] name Indicates the name against which the AudioCompression instance is required.
96  * The name string indicates the audio compression type like "NONE", "LIGHT", "MEDIUM" and
97  * "HEAVY"
98  *
99  * @return Returns an instance of AudioCompression against the name specified or else throws an
100  * IllegalArgumentException indicating that the instance against specified name was not found.
101  */
102 const AudioCompression & AudioCompression::getInstance(const std::string &name)
103 {
104  for (size_t i = 0; i < dsUTL_DIM(_names); i++) {
105  if (name.compare(_names[i]) == 0) {
107  }
108  }
109 
110  throw IllegalArgumentException();
111 }
112 
113 
114 /**
115  * @fn AudioCompression::AudioCompression(int id)
116  * @brief This function is a parameterised constructor. It initializes the AudioCompression
117  * instance with the parameters passed as input, only if the id passed is valid.
118  *
119  * @param[in] id Indicates the id for the instance created. The id is used to identify the
120  * audio compression types. For example:
121  * <ul>
122  * <li> id 0 indicates no audio compression.
123  * <li> id 1 indicates light audio compression.
124  * <li> id 2 indicates medium audio compression.
125  * <li> id 3 indicates heavy audio compression.
126  * <ul/"
127  *
128  * @return None
129  */
131 {
132  if (::isValid(id)) {
133  _id = id;
134  _name = std::string(_names[id]);
135  }
136  else {
137  throw IllegalArgumentException();
138  }
139 }
140 
141 
142 /**
143  * @fn AudioCompression::~AudioCompression()
144  * @brief This function is the default destructor for AudioCompression.
145  *
146  * @return None
147  */
149 {
150 }
151 
152 }
153 
154 
155 /** @} */
156 /** @} */
device::DSConstant::_id
int _id
Indicates the id of the instance inheriting this class.
Definition: dsConstant.hpp:57
dsAUDIO_CMP_MAX
@ dsAUDIO_CMP_MAX
Definition: dsTypes.h:205
device::AudioCompression
This class extends DSConstant for implementing AudioCompression. It helps to maintain different audio...
Definition: audioCompression.hpp:49
dsTypes.h
Device Settings HAL types.
device::AudioCompression::kMax
static const int kMax
Indicates number of audio compression supported.
Definition: audioCompression.hpp:56
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::AudioCompression::getInstance
static const AudioCompression & getInstance(int id)
This function gets an instance of AudioCompression against the specified id, only if the id passed is...
Definition: audioCompression.cpp:79
device::AudioCompression::kHeavy
static const int kHeavy
Indicates heavy audio compression.
Definition: audioCompression.hpp:55
dsUtl.h
Device Settings HAL utilities.
device::AudioCompression::AudioCompression
AudioCompression(int id)
This function is a parameterised constructor. It initializes the AudioCompression instance with the p...
Definition: audioCompression.cpp:130
device::AudioCompression::~AudioCompression
virtual ~AudioCompression()
This function is the default destructor for AudioCompression.
Definition: audioCompression.cpp:148
device::AudioCompression::kNone
static const int kNone
Indicates audio compression None.
Definition: audioCompression.hpp:52
device::AudioCompression::kMedium
static const int kMedium
Indicates medium audio compression.
Definition: audioCompression.hpp:54
device::DSConstant::_name
std::string _name
Indicates the name string of the instance inheriting this class.
Definition: dsConstant.hpp:58
dsAudioCompression_isValid
#define dsAudioCompression_isValid(t)
Definition: dsTypes.h:368
dsAUDIO_CMP_LIGHT
@ dsAUDIO_CMP_LIGHT
Definition: dsTypes.h:202
device::AudioCompression::kLight
static const int kLight
Indicates light audio compression.
Definition: audioCompression.hpp:53
dsAUDIO_CMP_HEAVY
@ dsAUDIO_CMP_HEAVY
Definition: dsTypes.h:204
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
dsAUDIO_CMP_NONE
@ dsAUDIO_CMP_NONE
Definition: dsTypes.h:201
audioCompression.hpp
This file defines AudioCompression class for managing audio compression levels.
dsAUDIO_CMP_MEDIUM
@ dsAUDIO_CMP_MEDIUM
Definition: dsTypes.h:203