1 /* 2 * Copyright (c) 2021-2022 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 ST_AUDIO_SERVER_H 17 #define ST_AUDIO_SERVER_H 18 19 #include <mutex> 20 #include <unordered_map> 21 #include <pthread.h> 22 #include "iremote_stub.h" 23 #include "system_ability.h" 24 #include "audio_system_manager.h" 25 #include "audio_manager_base.h" 26 27 namespace OHOS { 28 namespace AudioStandard { 29 class AudioServer : public SystemAbility, public AudioManagerStub { 30 DECLARE_SYSTEM_ABILITY(AudioServer); 31 public: 32 DISALLOW_COPY_AND_MOVE(AudioServer); 33 explicit AudioServer(int32_t systemAbilityId, bool runOnCreate = true); 34 virtual ~AudioServer() = default; 35 void OnDump() override; 36 void OnStart() override; 37 void OnStop() override; 38 int32_t GetMaxVolume(AudioSystemManager::AudioVolumeType volumeType) override; 39 int32_t GetMinVolume(AudioSystemManager::AudioVolumeType volumeType) override; 40 int32_t SetMicrophoneMute(bool isMute) override; 41 bool IsMicrophoneMute() override; 42 int32_t SetAudioScene(AudioScene audioScene) override; 43 std::vector<sptr<AudioDeviceDescriptor>> GetDevices(DeviceFlag deviceFlag) override; 44 static void *paDaemonThread(void *arg); 45 void SetAudioParameter(const std::string &key, const std::string &value) override; 46 const std::string GetAudioParameter(const std::string &key) override; 47 const char *RetrieveCookie(int32_t &size) override; 48 int32_t UpdateActiveDeviceRoute(DeviceType type, DeviceFlag flag) override; 49 private: 50 static constexpr int32_t MAX_VOLUME = 15; 51 static constexpr int32_t MIN_VOLUME = 0; 52 static std::unordered_map<int, float> AudioStreamVolumeMap; 53 static std::map<std::string, std::string> audioParameters; 54 pthread_t m_paDaemonThread; 55 }; 56 } // namespace AudioStandard 57 } // namespace OHOS 58 #endif // ST_AUDIO_SERVER_H 59