RDK Documentation (Open Sourced RDK Components)
audioStereoMode.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 audioStereoMode.cpp
22  * @brief This file This file contains implementation of AudioStereoMode class methods,
23  * support functions and variable assignments to manage the audio modes like stereo, mono
24  * pass through and so on.
25  */
26 
27 
28 
29 /**
30 * @defgroup devicesettings
31 * @{
32 * @defgroup ds
33 * @{
34 **/
35 
36 
37 #include "audioStereoMode.hpp"
38 #include "audioOutputPortConfig.hpp"
39 #include "illegalArgumentException.hpp"
40 #include "dsTypes.h"
41 #include "dsUtl.h"
42 #include <string.h>
43 #include "dslogger.h"
44 
45 
46 namespace {
47  const char *_names[] = {
48  "UNKNOWN",
49  "MONO",
50  "STEREO",
51  "SURROUND",
52  "PASSTHRU",
53  "DOLBYDIGITAL",
54  "DOLBYDIGITALPLUS",
55  };
56 
57  inline const bool isValid(int id) {
58  return dsAudioStereoMode_isValid(id);
59  }
60 }
61 
62 namespace device {
63 typedef int _SafetyCheck[(dsUTL_DIM(_names) == dsAUDIO_STEREO_MAX) ? 1 : -1];
64 
72 
73 
74 /**
75  * @fn AudioStereoMode::getInstance(int id)
76  * @brief This function gets an instance of AudioStereoMode against the specified id, only
77  * if the id passed is valid.
78  *
79  * @param[in] id Indicates id against which the AudioStereoMode instance is required.
80  *
81  * @return Returns an instance of AudioStereoMode if the id is valid else throws an
82  * IllegalArgumentException.
83  */
85 {
86  if (::isValid(id)) {
87  return AudioOutputPortConfig::getInstance().getStereoMode(id);
88  }
89  else {
91  }
92 }
93 
94 
95 /**
96  * @fn AudioStereoMode::getInstance(const std::string &name)
97  * @brief This function gets an instance of AudioStereoMode against the specified name, only if
98  * the name passed is valid.
99  *
100  * @param[in] name Indicates name string against which the AudioStereoMode instance is required.
101  *
102  * @return Returns an instance of AudioStereoMode if an instance with the specified
103  * name is present else throws an IllegalArgumentException.
104  */
105 const AudioStereoMode & AudioStereoMode::getInstance(const std::string &name)
106 {
107  for (size_t i = 0; i < dsUTL_DIM(_names); i++) {
108  if (name.compare(_names[i]) == 0) {
110  }
111  }
112 
113  throw IllegalArgumentException();
114 }
115 
116 
117 /**
118  * @fn AudioStereoMode::AudioStereoMode(int id)
119  * @brief This function is a parameterised constructor of AudioStereoMode class.
120  * It initializes the instance with the specified id and the name corresponding to it.
121  *
122  * @param[in] id Indicates the id for initializing the instance. The id
123  * can be used to identify the audio stereo mode. Ex: Id of 0 indicates mono
124  * audio whereas id of 1 indicates surround audio.
125  *
126  * @return None
127  */
129 {
130  if (::isValid(id)) {
131  _id = id;
132  _name = std::string(_names[id]);
133  }
134  else {
135  throw IllegalArgumentException();
136  }
137 }
138 
139 
140 /**
141  * @fn AudioStereoMode::~AudioStereoMode()
142  * @brief This function is the default destructor of AudioStereoMode class.
143  *
144  * @return None
145  */
147 {
148 }
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
device::AudioStereoMode::kStereo
static const int kStereo
Indicates audio mode of type stereo.
Definition: audioStereoMode.hpp:56
dsTypes.h
Device Settings HAL types.
device::AudioStereoMode::kDD
static const int kDD
Indicates audio mode of type dolby digital.
Definition: audioStereoMode.hpp:59
device::AudioStereoMode::~AudioStereoMode
virtual ~AudioStereoMode()
This function is the default destructor of AudioStereoMode class.
Definition: audioStereoMode.cpp:146
device::AudioStereoMode::kSurround
static const int kSurround
Indicates audio mode of type surround.
Definition: audioStereoMode.hpp:57
dsAUDIO_STEREO_STEREO
@ dsAUDIO_STEREO_STEREO
Definition: dsTypes.h:376
dsAudioStereoMode_isValid
#define dsAudioStereoMode_isValid(t)
Definition: dsTypes.h:395
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
dsUtl.h
Device Settings HAL utilities.
device::AudioStereoMode::kDDPlus
static const int kDDPlus
Indicates audio mode of type dolby digital plus.
Definition: audioStereoMode.hpp:60
audioStereoMode.hpp
This file defines AudioStereoMode class for managing audio mode types.
dsAUDIO_STEREO_SURROUND
@ dsAUDIO_STEREO_SURROUND
Definition: dsTypes.h:377
device::AudioStereoMode::getInstance
static const AudioStereoMode & getInstance(int id)
This function gets an instance of AudioStereoMode against the specified id, only if the id passed is ...
Definition: audioStereoMode.cpp:84
dsAUDIO_STEREO_DDPLUS
@ dsAUDIO_STEREO_DDPLUS
Definition: dsTypes.h:380
device::DSConstant::_name
std::string _name
Indicates the name string of the instance inheriting this class.
Definition: dsConstant.hpp:58
device::AudioStereoMode::kMax
static const int kMax
Indicates maximum number of audio modes supported.
Definition: audioStereoMode.hpp:61
dsAUDIO_STEREO_PASSTHRU
@ dsAUDIO_STEREO_PASSTHRU
Definition: dsTypes.h:378
device::AudioStereoMode::AudioStereoMode
AudioStereoMode(int id)
This function is a parameterised constructor of AudioStereoMode class. It initializes the instance wi...
Definition: audioStereoMode.cpp:128
device::AudioStereoMode::kMono
static const int kMono
Indicates audio mode of type mono.
Definition: audioStereoMode.hpp:55
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_STEREO_DD
@ dsAUDIO_STEREO_DD
Definition: dsTypes.h:379
dsAUDIO_STEREO_MAX
@ dsAUDIO_STEREO_MAX
Definition: dsTypes.h:381
device::AudioStereoMode::kPassThru
static const int kPassThru
Indicates audio mode of type pass through.
Definition: audioStereoMode.hpp:58
dsAUDIO_STEREO_MONO
@ dsAUDIO_STEREO_MONO
Definition: dsTypes.h:375