fixup! Reset dump values when pause function is called
[platform/core/api/audio-io.git] / include / CAudioInfo.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __TIZEN_MEDIA_AUDIO__IO_CAUDIO_INFO_H__
18 #define __TIZEN_MEDIA_AUDIO__IO_CAUDIO_INFO_H__
19
20
21 #ifdef __cplusplus
22
23 #include <type_traits>
24 #include <string>
25 #include <optional>
26 #include <tuple>
27
28 #include <sound_manager.h>
29 #include <sound_manager_internal.h>
30
31 namespace tizen_media_audio {
32
33     template<typename E>
34     constexpr auto to_integral(E e) -> typename std::underlying_type<E>::type {
35         return static_cast<typename std::underlying_type<E>::type>(e);
36     }
37
38     /**
39      * Audio Information
40      */
41     class CAudioInfo {
42     public:
43         enum class EChannel : unsigned int {
44             CHANNEL_MONO = 1,               /**< 1 channel, mono */
45             CHANNEL_STEREO,                 /**< 2 channel, stereo */
46             CHANNEL_MULTI_3,                /**< 3 channel */
47             CHANNEL_MULTI_4,                /**< 4 channel */
48             CHANNEL_MULTI_5,                /**< 5 channel */
49             CHANNEL_MULTI_6,                /**< 6 channel */
50             CHANNEL_MULTI_7,                /**< 7 channel */
51             CHANNEL_MULTI_8,                /**< 8 channel */
52             CHANNEL_MULTI_9,                /**< 9 channel */
53             CHANNEL_MULTI_10,               /**< 10 channel */
54             CHANNEL_MULTI_11,               /**< 11 channel */
55             CHANNEL_MULTI_12,               /**< 12 channel */
56             CHANNEL_MULTI_13,               /**< 13 channel */
57             CHANNEL_MULTI_14,               /**< 14 channel */
58             CHANNEL_MULTI_15,               /**< 15 channel */
59             CHANNEL_MULTI_16,               /**< 16 channel */
60             CHANNEL_MAX
61         };
62
63         enum class ESampleType : unsigned int {
64             SAMPLE_TYPE_U8 = 1,             /**< Unsigned 8-bit audio samples */
65             SAMPLE_TYPE_S16_LE,             /**< Signed 16-bit audio samples */
66             SAMPLE_TYPE_S24_LE,             /**< Signed 24-bit audio samples */
67             SAMPLE_TYPE_S24_32_LE,          /**< Signed 24-bit packed in 32-bit audio samples */
68             SAMPLE_TYPE_S32_LE,             /**< Signed 32-bit audio samples */
69             SAMPLE_TYPE_MAX
70         };
71
72         enum class EAudioType : unsigned int {
73             /* Input Type */
74             AUDIO_IN_TYPE_MEDIA = 0,
75             //AUDIO_IN_TYPE_SYSTEM,
76             //AUDIO_IN_TYPE_ALARM,
77             //AUDIO_IN_TYPE_NOTIFICATION,
78             //AUDIO_IN_TYPE_EMERGENCY,
79             //AUDIO_IN_TYPE_VOICE_INFORMATION,
80             AUDIO_IN_TYPE_VOICE_RECOGNITION,
81             //AUDIO_IN_TYPE_RINGTONE_VOIP,
82             AUDIO_IN_TYPE_VOIP,
83             AUDIO_IN_TYPE_MEDIA_EXTERNAL_ONLY,
84             //AUDIO_IN_TYPE_RINGTONE_CALL,
85             //AUDIO_IN_TYPE_VOICE_CALL,
86             //AUDIO_IN_TYPE_VIDEO_CALL,
87             //AUDIO_IN_TYPE_RADIO,
88             AUDIO_IN_TYPE_LOOPBACK,
89             AUDIO_IN_TYPE_VOICE_RECOGNITION_SERVICE,
90             //AUDIO_IN_TYPE_MEDIA_NETWORK_SOURCE,
91
92             /* Output Type */
93             AUDIO_OUT_TYPE_MEDIA,
94             AUDIO_OUT_TYPE_SYSTEM,
95             AUDIO_OUT_TYPE_ALARM,
96             AUDIO_OUT_TYPE_NOTIFICATION,
97             AUDIO_OUT_TYPE_EMERGENCY,
98             AUDIO_OUT_TYPE_VOICE_INFORMATION,
99             //AUDIO_OUT_TYPE_VOICE_RECOGNITION,
100             AUDIO_OUT_TYPE_RINGTONE_VOIP,
101             AUDIO_OUT_TYPE_VOIP,
102             AUDIO_OUT_TYPE_MEDIA_EXTERNAL_ONLY,
103             AUDIO_OUT_TYPE_RINGTONE_CALL,
104             //AUDIO_OUT_TYPE_VOICE_CALL,
105             //AUDIO_OUT_TYPE_VIDEO_CALL,
106             //AUDIO_OUT_TYPE_RADIO,
107             //AUDIO_OUT_TYPE_LOOPBACK,
108             //AUDIO_OUT_TYPE_VOICE_RECOGNITION_SERVICE,
109             AUDIO_OUT_TYPE_MEDIA_NETWORK_SOURCE,
110
111             AUDIO_TYPE_MAX
112         };
113
114         enum class EAudioIOState : unsigned int {
115             AUDIO_IO_STATE_NONE,      /**< Audio-io handle is not created */
116             AUDIO_IO_STATE_IDLE,      /**< Audio-io handle is created, but not prepared */
117             AUDIO_IO_STATE_RUNNING,   /**< Audio-io handle is ready and the stream is running */
118             AUDIO_IO_STATE_PAUSED,    /**< Audio-io handle is ready and the stream is paused */
119             AUDIO_IO_STATE_MAX
120         };
121
122         enum class EAudioDirection : unsigned int {
123             AUDIO_DIRECTION_IN,       /**< Audio direction input */
124             AUDIO_DIRECTION_OUT,      /**< Audio direction output */
125             AUDIO_DIRECTION_MAX
126         };
127
128         static constexpr auto MIN_SYSTEM_SAMPLERATE = 8000;
129         static constexpr auto MAX_SYSTEM_SAMPLERATE = 192000;
130
131         static constexpr auto MIN_RECORD_VOLUME = 0.0;
132         static constexpr auto MAX_RECORD_VOLUME = 2.0;
133         static constexpr auto DEFAULT_RECORD_VOLUME = 1.0;
134
135         /* Constructor & Destructor */
136         CAudioInfo(unsigned int sampleRate, EChannel channel, ESampleType sampleType, EAudioType audioType, int audioIndex);
137         virtual ~CAudioInfo() = default;
138
139         /* Audio Specification */
140         std::tuple<ESampleType, unsigned int, EChannel> getSpec() const noexcept;
141         int getSampleSize() const noexcept;
142
143         /* Stream Properties */
144         void setAudioIndex(int audioIndex) noexcept;
145         void setAudioTypeByInputStreamType(const char* streamType);
146         void setAudioTypeByOutputStreamType(const char* streamType);
147         EAudioType getAudioType() const noexcept;
148         std::pair<const char*, int> getStreamProperties() const;
149
150         /* Effect */
151         void setEffectMethod(int method) noexcept;
152         std::string getEffectNoiseSuppressionMethod() const noexcept;
153         std::string getEffectAutomaticGainControlMethod() const noexcept;
154
155         void setEffectMethodWithReference(sound_effect_method_with_reference_e method, int id) noexcept;
156         std::pair<std::string, int> getEffectMethodWithReference() const noexcept;
157
158         /* Utilities */
159         size_t msToBytes(size_t milliseconds) const noexcept;
160         size_t bytesToMs(size_t bytes) const noexcept;
161
162     private:
163         const char *__STREAM_TYPE_TABLE[(unsigned int)EAudioType::AUDIO_TYPE_MAX] = {
164             /* Input Type */
165             "media",                  /**< AUDIO_IN_TYPE_MEDIA */
166             //"system",               /**< AUDIO_IN_TYPE_SYSTEM */
167             //"alarm",                /**< AUDIO_IN_TYPE_ALARM */
168             //"notification",         /**< AUDIO_IN_TYPE_NOTIFICATION */
169             //"emergency",            /**< AUDIO_IN_TYPE_EMERGENCY */
170             //"voice-information",    /**< AUDIO_IN_TYPE_VOICE_INFORMATION */
171             "voice-recognition",      /**< AUDIO_IN_TYPE_VOICE_RECOGNITION */
172             //"ringtone-voip",        /**< AUDIO_IN_TYPE_RINGTONE_VOIP */
173             "voip",                   /**< AUDIO_IN_TYPE_VOIP */
174             "ext-media",              /**< AUDIO_IN_TYPE_MEDIA_EXTERNAL_ONLY */
175             //"ringtone-call",        /**< AUDIO_IN_TYPE_RINGTONE_CALL */
176             //"call-voice",           /**< AUDIO_IN_TYPE_VOICE_CALL */
177             //"call-video",           /**< AUDIO_IN_TYPE_VIDEO_CALL */
178             //"radio",                /**< AUDIO_IN_TYPE_RADIO */
179             "loopback-mirroring",     /**< AUDIO_IN_TYPE_LOOPBACK */
180             "voice-recognition-service",     /**< AUDIO_IN_TYPE_VOICE_RECOGNITION_SERVICE */
181             //"network-source-media", /**< AUDIO_IN_TYPE_MEDIA_NETWORK_SOURCE */
182
183             /* Output Type */
184             "media",                  /**< AUDIO_OUT_TYPE_MEDIA */
185             "system",                 /**< AUDIO_OUT_TYPE_SYSTEM */
186             "alarm",                  /**< AUDIO_OUT_TYPE_ALARM */
187             "notification",           /**< AUDIO_OUT_TYPE_NOTIFICATION */
188             "emergency",              /**< AUDIO_OUT_TYPE_EMERGENCY */
189             "voice-information",      /**< AUDIO_OUT_TYPE_VOICE_INFORMATION */
190             //"voice-recognition",    /**< AUDIO_OUT_TYPE_VOICE_RECOGNITION */
191             "ringtone-voip",          /**< AUDIO_OUT_TYPE_RINGTONE_VOIP */
192             "voip",                   /**< AUDIO_OUT_TYPE_VOIP */
193             "ext-media",              /**< AUDIO_OUT_TYPE_MEDIA_EXTERNAL_ONLY */
194             "ringtone-call",          /**< AUDIO_OUT_TYPE_RINGTONE_CALL */
195             //"call-voice",           /**< AUDIO_OUT_TYPE_VOICE_CALL */
196             //"call-video",           /**< AUDIO_OUT_TYPE_VIDEO_CALL */
197             //"radio",                /**< AUDIO_OUT_TYPE_RADIO */
198             //"loopback-mirroring",   /**< AUDIO_OUT_TYPE_LOOPBACK */
199             //"voice-recognition-service",/**< AUDIO_OUT_TYPE_VOICE_RECOGNITION_SERVICE */
200             "network-source-media",   /**< AUDIO_OUT_TYPE_MEDIA_NETWORK_SOURCE */
201         };
202
203         EAudioType convertInputStreamTypeToAudioType(const char *streamType);
204         EAudioType convertOutputStreamTypeToAudioType(const char *streamType);
205
206         unsigned int __mSampleRate { MAX_SYSTEM_SAMPLERATE };
207         EChannel     __mChannel { EChannel::CHANNEL_MAX };
208         ESampleType  __mSampleType { ESampleType::SAMPLE_TYPE_MAX };
209         EAudioType   __mAudioType { EAudioType::AUDIO_TYPE_MAX };
210         int          __mAudioIndex { -1 };
211
212         std::optional<sound_effect_method_with_reference_e>
213                      __mEffectMethodWithReference;
214         int          __mEffectMethodReferenceDeviceId { 0 };
215         int          __mEffectMethod { 0 };
216     };
217
218
219 } /* namespace tizen_media_audio */
220
221 #endif
222 #endif /* __TIZEN_MEDIA_AUDIO__IO_CAUDIO_INFO_H__ */