1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef I_ST_AUDIO_MANAGER_BASE_H 17 #define I_ST_AUDIO_MANAGER_BASE_H 18 19 #include "ipc_types.h" 20 #include "iremote_broker.h" 21 #include "iremote_proxy.h" 22 #include "iremote_stub.h" 23 #include "audio_effect.h" 24 #include "pulseaudio_ipc_interface_code.h" 25 26 namespace OHOS { 27 namespace AudioStandard { 28 class AudioDeviceDescriptor; 29 class IStandardAudioService : public IRemoteBroker { 30 public: 31 /** 32 * Sets Microphone Mute status. 33 * 34 * @param isMute Mute status true or false to be set. 35 * @return Returns 0 if success. Otherwise returns Errocode defined in audio_errors.h. 36 */ 37 virtual int32_t SetMicrophoneMute(bool isMute) = 0; 38 39 /** 40 * @brief Set the Voice Volume. 41 * 42 * @param volume Voice colume to be set. 43 * @return int32_t Returns 0 if success. Otherwise returns Errocode defined in audio_errors.h. 44 */ 45 virtual int32_t SetVoiceVolume(float volume) = 0; 46 47 virtual int32_t GetCapturePresentationPosition(const std::string& deviceClass, uint64_t& frames, int64_t& timeSec, 48 int64_t& timeNanoSec) = 0; 49 50 virtual int32_t GetRenderPresentationPosition(const std::string& deviceClass, uint64_t& frames, int64_t& timeSec, 51 int64_t& timeNanoSec) = 0; 52 53 virtual int32_t OffloadSetVolume(float volume) = 0; 54 virtual int32_t OffloadDrain() = 0; 55 virtual int32_t OffloadGetPresentationPosition(uint64_t& frames, int64_t& timeSec, int64_t& timeNanoSec) = 0; 56 virtual int32_t OffloadSetBufferSize(uint32_t sizeMs) = 0; 57 58 /** 59 * Sets Audio modes. 60 * 61 * @param audioScene Audio scene type. 62 * @param activeDevice Currently active priority device 63 * @return Returns 0 if success. Otherwise returns Errocode defined in audio_errors.h. 64 */ 65 virtual int32_t SetAudioScene(AudioScene audioScene, DeviceType activeDevice) = 0; 66 67 /** 68 * Set Audio Parameter. 69 * 70 * @param key for the audio parameter to be set 71 * @param value associated with the key for the audio parameter to be set 72 * @return none. 73 */ 74 virtual void SetAudioParameter(const std::string &key, const std::string &value) = 0; 75 76 /** 77 * Set Audio Parameter. 78 * 79 * @param networkId for the distributed device 80 * @param key for the audio parameter to be set 81 * @param condition for the audio parameter to be set 82 * @param value associated with the key for the audio parameter to be set 83 * @return none. 84 */ 85 virtual void SetAudioParameter(const std::string& networkId, const AudioParamKey key, const std::string& condition, 86 const std::string& value) = 0; 87 88 /** 89 * Get Audio Parameter. 90 * 91 * @param key for the audio parameter to be set 92 * @return Returns value associated to the key requested. 93 */ 94 virtual const std::string GetAudioParameter(const std::string &key) = 0; 95 96 /** 97 * Set Audio Parameter. 98 * 99 * @param networkId for the distributed device 100 * @param key for the audio parameter to be set 101 * @param condition for the audio parameter to be set 102 * @return none. 103 */ 104 virtual const std::string GetAudioParameter(const std::string& networkId, const AudioParamKey key, 105 const std::string& condition) = 0; 106 107 /** 108 * Set Extra Audio Parameters. 109 * 110 * @param key main key for the extra audio parameter to be set 111 * @param kvpairs associated with the sub keys and values for the extra audio parameter to be set 112 * @return none. 113 */ 114 virtual void SetExtraParameters(const std::string &key, 115 const std::vector<std::pair<std::string, std::string>> &kvpairs) = 0; 116 117 /** 118 * Get Extra Audio Parameters. 119 * 120 * @param mainKey main key for the extra audio parameter to be get 121 * @param subKeys associated with the key for the extra audio parameter to be get 122 * @return Returns value associated to the key requested. 123 */ 124 virtual const std::vector<std::pair<std::string, std::string>> GetExtraParameters(const std::string &mainKey, 125 const std::vector<std::string> &subKyes) = 0; 126 127 /** 128 * Update the audio route after device is detected and route is decided 129 * 130 * @return Returns 0 if success. Otherwise returns Errocode defined in audio_errors.h. 131 */ 132 virtual int32_t UpdateActiveDeviceRoute(DeviceType type, DeviceFlag flag) = 0; 133 134 /** 135 * Get the transaction Id 136 * 137 * @return Returns transaction id. 138 */ GetTransactionId(DeviceType deviceType,DeviceRole deviceRole)139 virtual uint64_t GetTransactionId(DeviceType deviceType, DeviceRole deviceRole) 140 { 141 (void)deviceType; 142 (void)deviceRole; 143 return 0; 144 } 145 146 /** 147 * Notify device connect info 148 * 149 * @return Returns transaction id. 150 */ 151 virtual void NotifyDeviceInfo(std::string networkId, bool connected) = 0; 152 153 /** 154 * Check remote device state. 155 * 156 * @return Returns transaction id. 157 */ 158 virtual int32_t CheckRemoteDeviceState(std::string networkId, DeviceRole deviceRole, bool isStartDevice) = 0; 159 160 /** 161 * Set parameter callback 162 * 163 * @return Returns the setting result 164 */ 165 virtual int32_t SetParameterCallback(const sptr<IRemoteObject>& object) = 0; 166 167 /** 168 * Set wakeupSource callback 169 * 170 * @return Returns the setting result 171 */ 172 virtual int32_t SetWakeupSourceCallback(const sptr<IRemoteObject>& object) = 0; 173 174 /** 175 * Set audio mono state for accessibility 176 * 177 * @param audioMono the state of mono audio for accessibility 178 * @return none. 179 */ 180 virtual void SetAudioMonoState(bool audioMono) = 0; 181 182 /** 183 * Set audio balance value for accessibility 184 * 185 * @param audioBalance the value of audio balance for accessibility 186 * @return none. 187 */ 188 virtual void SetAudioBalanceValue(float audioBalance) = 0; 189 190 /** 191 * Create AudioProcess for play. 192 * 193 * @param config the config of the AudioProcess 194 * 195 * @return Returns AudioProcess client. 196 */ 197 virtual sptr<IRemoteObject> CreateAudioProcess(const AudioProcessConfig &config) = 0; 198 199 /** 200 * Use effect manager information to load effect libraries. 201 * 202 * @return true/false. 203 */ 204 virtual bool LoadAudioEffectLibraries(std::vector<Library> libraries, std::vector<Effect> effects, 205 std::vector<Effect> &successEffects) = 0; 206 207 /** 208 * Create effect chain manager for audio effect processing. 209 * 210 * @return true/false. 211 */ 212 virtual bool CreateEffectChainManager(std::vector<EffectChain> &effectChains, 213 std::unordered_map<std::string, std::string> &map) = 0; 214 215 /** 216 * Set output device sink for effect chain manager. 217 * 218 * @return true/false. 219 */ 220 virtual bool SetOutputDeviceSink(int32_t device, std::string &sinkName) = 0; 221 222 /** 223 * Regiest policy provider. 224 * 225 * @return result code. 226 */ 227 virtual int32_t RegiestPolicyProvider(const sptr<IRemoteObject> &object) = 0; 228 229 /** 230 * Request thread priority for client thread. 231 */ 232 virtual void RequestThreadPriority(uint32_t tid, std::string bundleName) = 0; 233 234 /** 235 * Create playback capturer manager. 236 * 237 * @return true/false. 238 */ 239 virtual bool CreatePlaybackCapturerManager() = 0; 240 241 /** 242 * Set StreamUsage set which support playback capturer. 243 * 244 * @param usage value of StreamUsage which support inner capturer. 245 * 246 * @return result of setting. 0 if success, error number else. 247 */ 248 virtual int32_t SetSupportStreamUsage(std::vector<int32_t> usage) = 0; 249 250 /** 251 * Mark if playback capture silently. 252 * 253 * @param state identify the capture state 254 * 255 * @return result of setting. 0 if success, error number else. 256 */ 257 virtual int32_t SetCaptureSilentState(bool state) = 0; 258 259 /** 260 * Update spatialization enabled state and head tracking enabled state. 261 * 262 * @param state identify the enabled state 263 * 264 * @return result of setting. 0 if success, error number else. 265 */ 266 virtual int32_t UpdateSpatializationState(AudioSpatializationState spatializationState) = 0; 267 268 /** 269 * Notify Stream volume changed. 270 * 271 * @param streamType specified streamType whose volume to be notified 272 * @param volume stream volume in float 273 * 274 * @return result of notify. 0 if success, error number else. 275 */ 276 virtual int32_t NotifyStreamVolumeChanged(AudioStreamType streamType, float volume) = 0; 277 278 public: 279 DECLARE_INTERFACE_DESCRIPTOR(u"IStandardAudioService"); 280 }; 281 282 class AudioManagerStub : public IRemoteStub<IStandardAudioService> { 283 public: 284 virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, 285 MessageOption &option) override; 286 287 private: 288 int HandleGetAudioParameter(MessageParcel &data, MessageParcel &reply); 289 int HandleSetAudioParameter(MessageParcel &data, MessageParcel &reply); 290 int HandleGetExtraAudioParameters(MessageParcel &data, MessageParcel &reply); 291 int HandleSetExtraAudioParameters(MessageParcel &data, MessageParcel &reply); 292 int HandleSetMicrophoneMute(MessageParcel &data, MessageParcel &reply); 293 int HandleSetAudioScene(MessageParcel &data, MessageParcel &reply); 294 int HandleUpdateActiveDeviceRoute(MessageParcel &data, MessageParcel &reply); 295 int HandleGetTransactionId(MessageParcel &data, MessageParcel &reply); 296 int HandleSetParameterCallback(MessageParcel &data, MessageParcel &reply); 297 int HandleGetRemoteAudioParameter(MessageParcel &data, MessageParcel &reply); 298 int HandleSetRemoteAudioParameter(MessageParcel &data, MessageParcel &reply); 299 int HandleNotifyDeviceInfo(MessageParcel &data, MessageParcel &reply); 300 int HandleCheckRemoteDeviceState(MessageParcel &data, MessageParcel &reply); 301 int HandleSetVoiceVolume(MessageParcel &data, MessageParcel &reply); 302 int HandleSetAudioMonoState(MessageParcel &data, MessageParcel &reply); 303 int HandleSetAudioBalanceValue(MessageParcel &data, MessageParcel &reply); 304 int HandleCreateAudioProcess(MessageParcel &data, MessageParcel &reply); 305 int HandleLoadAudioEffectLibraries(MessageParcel &data, MessageParcel &reply); 306 int HandleRequestThreadPriority(MessageParcel &data, MessageParcel &reply); 307 int HandleCreateAudioEffectChainManager(MessageParcel &data, MessageParcel &reply); 308 int HandleSetOutputDeviceSink(MessageParcel &data, MessageParcel &reply); 309 int HandleCreatePlaybackCapturerManager(MessageParcel &data, MessageParcel &reply); 310 int HandleSetSupportStreamUsage(MessageParcel &data, MessageParcel &reply); 311 int HandleRegiestPolicyProvider(MessageParcel &data, MessageParcel &reply); 312 int HandleSetWakeupSourceCallback(MessageParcel &data, MessageParcel &reply); 313 int HandleSetCaptureSilentState(MessageParcel &data, MessageParcel &reply); 314 int HandleUpdateSpatializationState(MessageParcel &data, MessageParcel &reply); 315 int HandleGetCapturePresentationPosition(MessageParcel &data, MessageParcel &reply); 316 int HandleGetRenderPresentationPosition(MessageParcel &data, MessageParcel &reply); 317 int HandleOffloadSetVolume(MessageParcel &data, MessageParcel &reply); 318 int HandleOffloadDrain(MessageParcel &data, MessageParcel &reply); 319 int HandleOffloadGetPresentationPosition(MessageParcel &data, MessageParcel &reply); 320 int HandleOffloadSetBufferSize(MessageParcel &data, MessageParcel &reply); 321 int HandleNotifyStreamVolumeChanged(MessageParcel &data, MessageParcel &reply); 322 323 using HandlerFunc = int (AudioManagerStub::*)(MessageParcel &data, MessageParcel &reply); 324 static inline HandlerFunc handlers[] = { 325 &AudioManagerStub::HandleGetAudioParameter, 326 &AudioManagerStub::HandleSetAudioParameter, 327 &AudioManagerStub::HandleGetExtraAudioParameters, 328 &AudioManagerStub::HandleSetExtraAudioParameters, 329 &AudioManagerStub::HandleSetMicrophoneMute, 330 &AudioManagerStub::HandleSetAudioScene, 331 &AudioManagerStub::HandleUpdateActiveDeviceRoute, 332 &AudioManagerStub::HandleGetTransactionId, 333 &AudioManagerStub::HandleSetParameterCallback, 334 &AudioManagerStub::HandleGetRemoteAudioParameter, 335 &AudioManagerStub::HandleSetRemoteAudioParameter, 336 &AudioManagerStub::HandleNotifyDeviceInfo, 337 &AudioManagerStub::HandleCheckRemoteDeviceState, 338 &AudioManagerStub::HandleSetVoiceVolume, 339 &AudioManagerStub::HandleSetAudioMonoState, 340 &AudioManagerStub::HandleSetAudioBalanceValue, 341 &AudioManagerStub::HandleCreateAudioProcess, 342 &AudioManagerStub::HandleLoadAudioEffectLibraries, 343 &AudioManagerStub::HandleRequestThreadPriority, 344 &AudioManagerStub::HandleCreateAudioEffectChainManager, 345 &AudioManagerStub::HandleSetOutputDeviceSink, 346 &AudioManagerStub::HandleCreatePlaybackCapturerManager, 347 &AudioManagerStub::HandleSetSupportStreamUsage, 348 &AudioManagerStub::HandleRegiestPolicyProvider, 349 &AudioManagerStub::HandleSetWakeupSourceCallback, 350 &AudioManagerStub::HandleSetCaptureSilentState, 351 &AudioManagerStub::HandleUpdateSpatializationState, 352 &AudioManagerStub::HandleOffloadSetVolume, 353 &AudioManagerStub::HandleOffloadDrain, 354 &AudioManagerStub::HandleOffloadGetPresentationPosition, 355 &AudioManagerStub::HandleOffloadSetBufferSize, 356 &AudioManagerStub::HandleNotifyStreamVolumeChanged, 357 &AudioManagerStub::HandleGetCapturePresentationPosition, 358 &AudioManagerStub::HandleGetRenderPresentationPosition, 359 }; 360 static constexpr size_t handlersNums = sizeof(handlers) / sizeof(HandlerFunc); 361 static_assert(handlersNums == (static_cast<size_t> (AudioServerInterfaceCode::AUDIO_SERVER_CODE_MAX) + 1), 362 "please check pulseaudio_ipc_interface_code"); 363 }; 364 } // namespace AudioStandard 365 } // namespace OHOS 366 #endif // I_ST_AUDIO_MANAGER_BASE_H 367