• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "accesstoken_kit.h"
23 #include "ipc_skeleton.h"
24 #include "iremote_stub.h"
25 #include "system_ability.h"
26 #include "audio_renderer_sink.h"
27 #include "remote_audio_renderer_sink.h"
28 #include "i_standard_audio_server_manager_listener.h"
29 #include "audio_manager_base.h"
30 #include "audio_system_manager.h"
31 #include "audio_server_death_recipient.h"
32 
33 namespace OHOS {
34 namespace AudioStandard {
35 class AudioServer : public SystemAbility, public AudioManagerStub, public AudioSinkCallback {
36     DECLARE_SYSTEM_ABILITY(AudioServer);
37 public:
38     DISALLOW_COPY_AND_MOVE(AudioServer);
39     explicit AudioServer(int32_t systemAbilityId, bool runOnCreate = true);
40     virtual ~AudioServer() = default;
41     void OnDump() override;
42     void OnStart() override;
43     void OnStop() override;
44     int32_t GetMaxVolume(AudioVolumeType volumeType) override;
45     int32_t GetMinVolume(AudioVolumeType volumeType) override;
46     int32_t SetMicrophoneMute(bool isMute) override;
47     bool IsMicrophoneMute() override;
48     int32_t SetVoiceVolume(float volume) override;
49     int32_t SetAudioScene(AudioScene audioScene, DeviceType activeDevice) override;
50     std::vector<sptr<AudioDeviceDescriptor>> GetDevices(DeviceFlag deviceFlag) override;
51     static void *paDaemonThread(void *arg);
52     void SetAudioParameter(const std::string& key, const std::string& value) override;
53     void SetAudioParameter(const std::string& networkId, const AudioParamKey key, const std::string& condition,
54         const std::string& value) override;
55     const std::string GetAudioParameter(const std::string &key) override;
56     const std::string GetAudioParameter(const std::string& networkId, const AudioParamKey key,
57         const std::string& condition) override;
58     const char *RetrieveCookie(int32_t &size) override;
59     uint64_t GetTransactionId(DeviceType deviceType, DeviceRole deviceRole) override;
60     int32_t UpdateActiveDeviceRoute(DeviceType type, DeviceFlag flag) override;
61     void SetAudioMonoState(bool audioMono) override;
62     void SetAudioBalanceValue(float audioBalance) override;
63 
64     void NotifyDeviceInfo(std::string networkId, bool connected) override;
65 
66     int32_t CheckRemoteDeviceState(std::string networkId, DeviceRole deviceRole, bool isStartDevice) override;
67 
68     // ISinkParameterCallback
69     void OnAudioParameterChange(std::string netWorkId, const AudioParamKey key,
70         const std::string& condition, const std::string value) override;
71 
72     int32_t SetParameterCallback(const sptr<IRemoteObject>& object) override;
73 protected:
74     void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
75 private:
76     bool VerifyClientPermission(const std::string &permissionName);
77     static constexpr int32_t MAX_VOLUME = 15;
78     static constexpr int32_t MIN_VOLUME = 0;
79     static std::unordered_map<int, float> AudioStreamVolumeMap;
80     static std::map<std::string, std::string> audioParameters;
81     void AudioServerDied(pid_t pid);
82     void RegisterPolicyServerDeathRecipient();
83     pthread_t m_paDaemonThread;
84     AudioScene audioScene_ = AUDIO_SCENE_DEFAULT;
85     std::shared_ptr<AudioParameterCallback> callback_;
86 };
87 } // namespace AudioStandard
88 } // namespace OHOS
89 #endif // ST_AUDIO_SERVER_H
90