* Copyright (c) 2021-2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ST_AUDIO_SERVER_H
#define ST_AUDIO_SERVER_H
#include <condition_variable>
#include <pthread.h>
#include "accesstoken_kit.h"
#include "ipc_skeleton.h"
#include "iremote_stub.h"
#include "system_ability.h"
#include "audio_server_death_recipient.h"
#ifdef SUPPORT_OLD_ENGINE
#include "audio_server_dump.h"
#endif
#include "i_audio_server_hpae_dump.h"
#include "audio_inner_call.h"
#include "common/hdi_adapter_info.h"
#include "sink/i_audio_render_sink.h"
#include "source/i_audio_capture_source.h"
#include "audio_effect_server.h"
#include "audio_asr.h"
#include "policy_handler.h"
#include "audio_resource_service.h"
#include "audio_stream_monitor.h"
#include "standard_audio_service_stub.h"
#include "async_action_handler.h"
#include "iaudio_engine_callback_handle.h"
#include "audio_engine_callback_types.h"
#include "audio_stream_types.h"
#include "audio_capturer_types.h"
#include "audio_device_enhance_manager.h"
#include "adapter/i_device_manager.h"
namespace OHOS {
namespace AudioStandard {
enum WakeupStageCode {
STAGE_CREATE_ENTER = 0x0100,
STAGE_CREATE_EXIT = 0x015F,
STAGE_START_ENTER = 0x0160,
STAGE_START_EXIT = 0x01AF,
STAGE_END = 0x01FF,
};
enum WakeupErrorCode {
WAKEUP_NO_ERROR = 0x1000,
WAKEUP_CREATE_ERROR,
WAKEUP_START_ERROR
};
enum WakeupResult {
RESULT_DEFAULT,
RESULT_SUCC,
RESULT_FAIL
};
struct WakeupTrackInfo {
enum WakeupStageCode stage;
enum WakeupResult result;
enum WakeupErrorCode errCode;
};
class AudioServer;
class ProxyDeathRecipient : public IRemoteObject::DeathRecipient {
public:
ProxyDeathRecipient(int32_t pid, AudioServer *audioServer) : pid_(pid), audioServer_(audioServer) {};
virtual ~ProxyDeathRecipient() = default;
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
private:
int32_t pid_ = 0;
AudioServer *audioServer_ = nullptr;
};
class PipeInfoGuard {
public:
PipeInfoGuard(uint32_t sessionId);
~PipeInfoGuard();
void SetReleaseFlag(bool flag);
private:
bool releaseFlag_ = true;
uint32_t sessionId_ = 0;
};
class AudioServer : public SystemAbility, public StandardAudioServiceStub,
public IAudioSinkCallback, IAudioSourceCallback,
public IAudioServerInnerCall, public DataTransferStateChangeCallbackForMonitor,
public IDeviceManagerCallback {
DECLARE_SYSTEM_ABILITY(AudioServer);
public:
DISALLOW_COPY_AND_MOVE(AudioServer);
explicit AudioServer(int32_t systemAbilityId, bool runOnCreate = true);
virtual ~AudioServer() = default;
void OnDump() override;
void OnStart() override;
void OnStop() override;
int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override;
int32_t LoadAudioEffectLibraries(const std::vector<Library>& libraries, const std::vector<Effect>& effects,
std::vector<Effect>& successEffectList, bool& hasEffectsLoaded) override;
int32_t CreatePlaybackCapturerManager(bool& isSuccess) override;
int32_t CreateEffectChainManager(const std::vector<EffectChain> &effectChains,
const EffectChainManagerParam &effectParam, const EffectChainManagerParam &enhanceParam) override;
int32_t SetOutputDeviceSink(int32_t deviceType, const std::string &sinkName) override;
int32_t SetActiveOutputDevice(int32_t deviceType) override;
int32_t SetMicrophoneMute(bool isMute) override;
int32_t SetVoiceVolume(float volume) override;
int32_t OffloadSetVolume(float volume, uint32_t renderId) override;
int32_t SetAudioScene(int32_t audioScene, int32_t a2dpOffloadFlag, bool scoExcludeFlag,
int32_t phoneCallSceneType = SCENE_TYPE_INVALID) override;
int32_t SetAudioSceneForPipe(uint32_t pipeId, int32_t audioScene, bool scoExcludeFlag) override;
int32_t CreateCallTransferProxy() override;
static void *paDaemonThread(void *arg);
int32_t SetExtraParameters(const std::string& key,
const std::vector<StringPair>& kvpairs) override;
int32_t SetAudioParameter(const std::string& key, const std::string& value) override;
int32_t SetAudioParameter(const std::string& networkId, int32_t key, const std::string& condition,
const std::string& value) override;
int32_t GetExtraParameters(const std::string &mainKey, const std::vector<std::string> &subKeys,
std::vector<StringPair> &result) override;
int32_t GetAudioParameter(const std::string &key, std::string& value) override;
int32_t GetAudioParameter(const std::string& networkId, int32_t key,
const std::string& condition, std::string& value) override;
int32_t UpdateActiveDevicesRoute(const std::vector<IntPair> &activeDevices,
int32_t a2dpOffloadFlag, const uint32_t pipeId, const std::string &networkId = LOCAL_NETWORK_ID) override;
int32_t ReleaseActiveDeviceRoute(int32_t deviceType, int32_t deviceFlag, const std::string &networkId) override;
int32_t SetDmDeviceType(uint16_t dmDeviceType, int32_t deviceType) override;
int32_t UpdateDualToneState(bool enable, int32_t sessionId, const std::string &dupSinkName) override;
int32_t SetAudioMonoState(bool audioMono) override;
int32_t SetAudioBalanceValue(float audioBalance) override;
int32_t SuspendRenderSink(const std::string &sinkName) override;
int32_t RestoreRenderSink(const std::string &sinkName) override;
int32_t SetAsrAecMode(int32_t asrAecMode) override;
int32_t GetAsrAecMode(int32_t &asrAecMode) override;
int32_t SetAsrNoiseSuppressionMode(int32_t asrNoiseSuppressionMode) override;
int32_t GetAsrNoiseSuppressionMode(int32_t &asrNoiseSuppressionMode) override;
int32_t SetAsrWhisperDetectionMode(int32_t asrWhisperDetectionMode) override;
int32_t GetAsrWhisperDetectionMode(int32_t &asrWhisperDetectionMode) override;
int32_t SetAsrVoiceControlMode(int32_t asrVoiceControlMode, bool on) override;
int32_t SetAsrVoiceMuteMode(int32_t asrVoiceMuteMode, bool on) override;
int32_t IsWhispering(int32_t& whisperRes) override;
int32_t SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray,
int32_t deviceType) override;
int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray,
int32_t deviceType) override;
int32_t NotifyDeviceInfo(const std::string &networkId, bool connected) override;
int32_t NotifyTaskIdProxy(const std::string &taskId, bool connected) override;
int32_t CheckRemoteDeviceState(const std::string& networkId, int32_t deviceRole, bool isStartDevice) override;
int32_t CreateAudioProcess(const AudioProcessConfig &config, int32_t &errorCode,
const AudioPlaybackCaptureConfig &filterConfig, sptr<IRemoteObject>& client) override;
void OnRenderSinkParamChange(const std::string &networkId, const AudioParamKey key,
const std::string &condition, const std::string &value) override;
void OnRenderSinkStateChange(uint32_t sinkId, bool started) override;
void OnOutputPipeChange(AudioPipeChangeType changeType,
std::shared_ptr<AudioOutputPipeInfo> &changedPipeInfo) override;
void OnHdiRouteStateChange(const std::string &networkId, bool enable) override;
void OnWakeupClose() override;
void OnCaptureSourceParamChange(const std::string &networkId, const AudioParamKey key,
const std::string &condition, const std::string &value) override;
void OnInputPipeChange(AudioPipeChangeType changeType,
std::shared_ptr<AudioInputPipeInfo> &changedPipeInfo) override;
int32_t SetParameterCallback(const sptr<IRemoteObject>& object) override;
int32_t RegiestPolicyProvider(const sptr<IRemoteObject> &object) override;
int32_t RegistCoreServiceProvider(const sptr<IRemoteObject> &object) override;
int32_t SetWakeupSourceCallback(const sptr<IRemoteObject>& object) override;
int32_t UpdateSpatializationState(const AudioSpatializationState& spatializationState) override;
int32_t UpdateDeviceSpatialEnabled(const std::string &address,
const AudioSpatializationState &state) override;
int32_t RemoveDeviceSpatialEnabled(const std::string &address) override;
int32_t ClearDeviceSpatialEnabled() override;
int32_t UpdateSpatialDeviceType(int32_t spatialDeviceType) override;
int32_t NotifyStreamVolumeChanged(int32_t streamType, float volume) override;
int32_t SetSpatializationSceneType(int32_t spatializationSceneType) override;
int32_t ResetRouteForDisconnect(int32_t type) override;
int32_t GetEffectLatency(const std::string &sessionId, uint32_t& latency) override;
int32_t GetMaxAmplitude(bool isOutputDevice, const std::string& deviceClass, int32_t sourceType,
float& maxAmplitude) override;
int32_t GetInputMaxAmplitude(const std::string &sourceName, float &maxAmplitude) override;
int32_t GetVolumeDataCount(const std::string &sinkName, int64_t &volumeData) override;
int32_t GetSinkLatency(uint32_t renderId, uint32_t &sinkLatency) override;
int32_t UpdateLatencyTimestamp(const std::string ×tamp, bool isRenderer) override;
int32_t GetEffectOffloadEnabled(bool& isEffectOffloadEnabled) override;
void OnCapturerState(bool isActive, size_t preNum, size_t curNum);
int32_t SetSinkRenderEmpty(const std::string &deviceClass, int32_t durationUs) final;
int32_t SetSinkMuteForSwitchDevice(const std::string &deviceClass, int32_t durationUs, bool mute,
const std::string &networkId = LOCAL_NETWORK_ID) override;
int32_t LoadHdiEffectModel() override;
int32_t UpdateEffectBtOffloadSupported(bool isSupported) override;
int32_t RestoreSession(uint32_t sessionID, const RestoreInfoIpc& restoreInfoIpc) override;
int32_t SetRotationToEffect(uint32_t rotate) override;
int32_t UpdateSessionConnectionState(int32_t sessionID, int32_t state) override;
int32_t SetNonInterruptMute(uint32_t sessionId, bool muteFlag) override;
int32_t SetOffloadMode(uint32_t sessionId, int32_t state, bool isAppBack) override;
int32_t UnsetOffloadMode(uint32_t sessionId) override;
int32_t CheckHibernateState(bool hibernate) override;
int32_t CreateIpcOfflineStream(int32_t &errorCode, sptr<IRemoteObject>& client) override;
int32_t GetOfflineAudioEffectChains(std::vector<std::string> &effectChains) override;
int32_t SetForegroundList(const std::vector<std::string>& list) override;
int32_t SetRenderWhitelist(const std::vector<std::string>& list) override;
int32_t GetStandbyStatus(uint32_t sessionId, bool &isStandby, int64_t &enterStandbyTime) override;
int32_t GenerateSessionId(uint32_t &sessionId) override;
int32_t NotifyAccountsChanged() override;
int32_t NotifySettingsDataReady() override;
int32_t GetAllSinkInputs(std::vector<SinkInput> &sinkInputs) override;
int32_t NotifyAudioPolicyReady() override;
int32_t SetInnerCapLimit(uint32_t innerCapLimit) override;
int32_t CheckCaptureLimit(const AudioPlaybackCaptureConfig &config, int32_t &innerCapId) override;
int32_t ReleaseCaptureLimit(int32_t innerCapId) override;
int32_t LoadHdiAdapter(uint32_t devMgrType, const std::string &adapterName) override;
int32_t UnloadHdiAdapter(uint32_t devMgrType, const std::string &adapterName, bool force) override;
int32_t CreateHdiSinkPort(const std::string &deviceClass, const std::string &idInfo,
const IAudioSinkAttr &attr, uint32_t& renderId) override;
int32_t CreateSinkPort(uint32_t idBase, uint32_t idType, const std::string &idInfo,
const IAudioSinkAttr &attr, uint32_t& renderId) override;
int32_t CreateHdiSourcePort(const std::string &deviceClass, const std::string &idInfo,
const IAudioSourceAttr &attr, uint32_t& captureId) override;
int32_t CreateSourcePort(uint32_t idBase, uint32_t idType, const std::string &idInfo,
const IAudioSourceAttr &attr, uint32_t& captureId) override;
int32_t RegisterVADeviceController(const std::string &macAddress,
const sptr<IRemoteObject> &controller) override;
int32_t UnregisterVADeviceController(const std::string &macAddress) override;
int32_t DestroyHdiPort(uint32_t id) override;
int32_t SetDeviceConnectedFlag(bool flag) override;
int32_t IsAcousticEchoCancelerSupported(int32_t sourceType, bool& isSupported) override;
int32_t SetKaraokeParameters(int32_t deviceType, int32_t paramType, int32_t value, bool &ret) override;
int32_t IsAudioLoopbackSupported(int32_t mode, int32_t deviceType, bool &isSupported) override;
int32_t SetLatestMuteState(uint32_t sessionId, bool muteFlag) override;
int32_t ForceStopAudioStream(int32_t audioType) override;
void RemoveRendererDataTransferCallback(const int32_t &pid);
int32_t RegisterDataTransferCallback(const sptr<IRemoteObject> &object) override;
int32_t RegisterDataTransferMonitorParam(int32_t callbackId,
const DataTransferMonitorParam ¶m) override;
int32_t UnregisterDataTransferMonitorParam(int32_t callbackId) override;
void OnDataTransferStateChange(const int32_t &pid, const int32_t &callbackId,
const AudioRendererDataTransferStateChangeInfo &info) override;
void OnMuteStateChange(const int32_t &pid, const int32_t &callbackId,
const int32_t &uid, const uint32_t &sessionId, const bool &isMuted) override;
int32_t SetBtHdiInvalidState() override;
int32_t GetVolumeBySessionId(uint32_t sessionId, float &volume) override;
int32_t AddCaptureInjector(uint32_t sinkPortidx, std::string &rate, std::string &format,
std::string &channels, std::string &bufferSize) override;
int32_t RemoveCaptureInjector(uint32_t sinkPortidx) override;
int32_t RegisterCallbackHandle(const sptr<IRemoteObject> &object) override;
int32_t SetCallbackHandleEnable(uint32_t callbackId, bool enable) override;
int32_t GetCurrentOutputPipeChangeInfos(
std::vector<std::shared_ptr<AudioOutputPipeInfo>> &pipeChangeInfos) override;
int32_t GetCurrentInputPipeChangeInfos(
std::vector<std::shared_ptr<AudioInputPipeInfo>> &pipeChangeInfos) override;
int32_t RequestUserPrivacyAuthority(uint32_t sessionId) override;
int32_t RegistAdapterManagerCallback(const sptr<IRemoteObject>& object, const std::string& networkId) override;
int32_t UnRegistAdapterManagerCallback(const std::string& networkId) override;
void OnAdapterParamChange(std::string networkId, const AudioParamKey key,
std::string condition, std::string value) override;
void OnDeviceStateChange(const std::string &networkId, DeviceRole role, bool isAvailable) override;
int32_t GetRemoteAudioParameter(const std::string& networkId, int32_t key,
const std::string& condition, std::string& value) override;
int32_t SetAuxiliarySinkEnable(bool isEnabled) override;
int32_t ReportPlaybackCaptureUserChoice(uint32_t sessionId, bool choice) override;
int32_t ReportWakeupEvent(const AudioWakeupTrackInfo &audioWakeupTrackInfo) override;
int32_t SetAncoRecordingConfigChanged(const std::vector<std::string> &bundleNameList) override;
int32_t NotifySensitiveRecordPermit(uint32_t sessionId, bool isPermitted) override;
protected:
void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
private:
class CallbackHandle : public IRemoteObject::DeathRecipient {
public:
CallbackHandle(AudioServer *owner,
const sptr<IAudioEngineCallbackHandle> &cbHandle, pid_t pid, uid_t uid);
virtual ~CallbackHandle() = default;
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
void OnOutputPipeChange(AudioPipeChangeType changeType,
std::shared_ptr<AudioOutputPipeInfo> &changedPipeInfo);
void OnInputPipeChange(AudioPipeChangeType changeType,
std::shared_ptr<AudioInputPipeInfo> &changedPipeInfo);
void SetCallbackHandleEnable(uint32_t callbackId, bool enable);
private:
AudioServer *owner_;
const sptr<IAudioEngineCallbackHandle> cbHandle_;
const pid_t pid_;
const uid_t uid_;
std::map<AudioEngineCallbackId, bool> cbEnableMap_;
std::mutex lock_;
};
class OutputChangeCallbackAction : public AsyncActionHandler::AsyncAction {
public:
explicit OutputChangeCallbackAction(AudioServer *owner, AudioPipeChangeType changeType,
std::shared_ptr<AudioOutputPipeInfo> &changedPipeInfo)
: owner_(owner), changeType_(changeType), changedPipeInfo_(changedPipeInfo)
{}
void Exec() override;
private:
AudioServer *owner_;
AudioPipeChangeType changeType_;
std::shared_ptr<AudioOutputPipeInfo> changedPipeInfo_;
};
class InputChangeCallbackAction : public AsyncActionHandler::AsyncAction {
public:
explicit InputChangeCallbackAction(AudioServer *owner, AudioPipeChangeType changeType,
std::shared_ptr<AudioInputPipeInfo> &changedPipeInfo)
: owner_(owner), changeType_(changeType), changedPipeInfo_(changedPipeInfo)
{}
void Exec() override;
private:
AudioServer *owner_;
AudioPipeChangeType changeType_;
std::shared_ptr<AudioInputPipeInfo> changedPipeInfo_;
};
class DeviceStateChangeCallbackAction : public AsyncActionHandler::AsyncAction {
public:
explicit DeviceStateChangeCallbackAction(const std::string &networkId, DeviceRole role, bool isAvailable)
: networkId_(networkId), role_(role), isAvailable_(isAvailable)
{}
void Exec() override;
private:
std::string networkId_;
DeviceRole role_;
bool isAvailable_;
};
private:
void InitHdiEventCallback();
#ifdef HAS_FEATURE_INNERCAPTURER
bool HandleCheckCaptureLimit(AudioProcessConfig &resetConfig,
const AudioPlaybackCaptureConfig &filterConfig);
int32_t InnerCheckCaptureLimit(const AudioPlaybackCaptureConfig &config, int32_t &innerCapId);
#endif
int32_t GetAudioEnhancePropertyArray(AudioEffectPropertyArray &propertyArray,
const DeviceType& deviceType);
int32_t GetAudioEffectPropertyArray(AudioEffectPropertyArray &propertyArray);
int32_t SetAudioEffectChainProperty(const AudioEffectPropertyArray &propertyArray);
int32_t SetAudioEnhanceChainProperty(const AudioEffectPropertyArray &propertyArray,
const DeviceType& deviceType);
void SetA2dpAudioParameter(const std::string &renderValue);
bool CheckAndPreStoreA2dpParam(std::shared_ptr<IAudioRenderSink> btSink,
AudioParamKey parmKey, const std::string &renderValue);
bool VerifyClientPermission(const std::string &permissionName,
Security::AccessToken::AccessTokenID tokenId = Security::AccessToken::INVALID_TOKENID);
bool PermissionChecker(const AudioProcessConfig &config);
bool CheckPlaybackPermission(const AudioProcessConfig &config);
int32_t CheckInnerRecorderPermission(const AudioProcessConfig &config);
bool CheckRecorderPermission(const AudioProcessConfig &config);
bool HandleCheckRecorderBackgroundCapture(const AudioProcessConfig &config);
bool CheckVoiceDownlinkPermission(const AudioProcessConfig &config);
bool CheckVoiceCallRecorderPermission(Security::AccessToken::AccessTokenID tokenId);
void RegisterSinkLatencyFetcher(uint32_t renderId);
void RegisterSinkLatencyFetcher(uint32_t renderId, uint32_t sinkLatency);
void ResetRecordConfig(AudioProcessConfig &config,
const AudioPlaybackCaptureConfig &filterConfig);
AudioProcessConfig ResetProcessConfig(const AudioProcessConfig &config,
const AudioPlaybackCaptureConfig &filterConfig);
bool CheckStreamInfoFormat(const AudioProcessConfig &config);
bool CheckRendererFormat(const AudioProcessConfig &config);
bool CheckRecorderFormat(const AudioProcessConfig &config);
bool CheckConfigFormat(const AudioProcessConfig &config);
int32_t GetHapBuildApiVersion(int32_t callerUid);
void AudioServerDied(pid_t pid, pid_t uid);
void RegisterPolicyServerDeathRecipient();
void RegisterAudioCapturerSourceCallback();
void RegisterAudioRendererSinkCallback();
void RegisterDataTransferStateChangeCallback();
void RemoveCallbackHandle(pid_t pid);
void DispatchOutputPipeChangeEvent(AudioPipeChangeType changeType,
std::shared_ptr<AudioOutputPipeInfo> &changedPipeInfo);
void DispatchInputPipeChangeEvent(AudioPipeChangeType changeType,
std::shared_ptr<AudioInputPipeInfo> &changedPipeInfo);
int32_t SetIORoutes(std::vector<std::pair<DeviceType, DeviceFlag>> &activeDevices,
BluetoothOffloadState a2dpOffloadFlag, const uint32_t pipeId, const std::string &networkId = LOCAL_NETWORK_ID);
int32_t SetIORoutes(const DeviceType type, const DeviceFlag flag, std::vector<DeviceType> deviceTypes);
int32_t SetIORoutesForRemote(const DeviceFlag flag, std::vector<DeviceType> &deviceTypes,
const std::string &networkId);
int32_t SetIORoutesForSpecificPipe(const DeviceType type, const DeviceFlag flag,
std::vector<DeviceType> &deviceTypes, const uint32_t pipeId, const std::string &networkId);
const std::string GetDPParameter(const std::string &condition);
const std::string GetUsbParameter(const std::string &condition);
void WriteServiceStartupError();
void ParseAudioParameter();
void NotifyAudioParameterParsed();
bool WaitAudioParameterParsed();
int32_t SetHomeMusicExtraParameters(const std::vector<std::pair<std::string, std::string>> &kvpairs);
int32_t SetEffectLiveExtraParameters(const std::vector<std::pair<std::string, std::string>> &kvpairs);
int32_t SetPcmDumpExtraParameters(const std::vector<std::pair<std::string, std::string>> &kvpairs);
int32_t SetCockpitDirectExtraParameters(const std::vector<std::pair<std::string, std::string>> &kvpairs);
int32_t SetCommonExtraParameters(const std::string &key,
const std::vector<std::pair<std::string, std::string>> &kvpairs);
bool IsNormalIpcStream(const AudioProcessConfig &config) const;
void RecognizeAudioEffectType(const std::string &mainkey, const std::string &subkey,
const std::string &extraSceneType);
bool IsFastBlocked(int32_t uid, PlayerType playerType);
int32_t SetVolumeInfoForEnhanceChain(const AudioStreamType &streamType);
int32_t SetMicrophoneMuteForEnhanceChain(const bool &isMute);
void InitMaxRendererStreamCntPerUid();
bool IsSatellite(const AudioProcessConfig &config, int32_t callingUid);
void SendCreateErrorInfo(const AudioProcessConfig &config, int32_t errorCode);
int32_t CheckMaxRendererInstances();
int32_t CheckMaxLoopbackInstances(AudioMode audioMode);
bool SetPcmDumpParameter(const std::vector<std::pair<std::string, std::string>> ¶ms);
bool GetPcmDumpParameter(const std::vector<std::string> &subKeys,
std::vector<std::pair<std::string, std::string>> &result);
int32_t GetTaskIdParameter(const std::vector<std::string> &subKeys,
std::vector<std::pair<std::string, std::string>> &result);
sptr<IRemoteObject> CreateAudioStream(const AudioProcessConfig &config, int32_t callingUid,
std::shared_ptr<PipeInfoGuard> &pipeInfoGuard);
int32_t SetAsrVoiceSuppressionControlMode(const AudioParamKey paramKey, AsrVoiceControlMode asrVoiceControlMode,
bool on, int32_t modifyVolume);
int32_t CheckAndWaitAudioPolicyReady();
void NotifyProcessStatus();
bool ProcessKeyValuePairs(const std::string &key, const std::vector<std::pair<std::string, std::string>> &kvpairs,
const std::unordered_map<std::string, std::set<std::string>> &subKeyMap, std::string &value);
bool SetEffectLiveParameter(const std::vector<std::pair<std::string, std::string>> ¶ms);
bool GetEffectLiveParameter(const std::vector<std::string> &subKeys,
std::vector<std::pair<std::string, std::string>> &result);
int32_t CreateAudioWorkgroup(const sptr<IRemoteObject> &object, int32_t &workgroupId) override;
int32_t ReleaseAudioWorkgroup(int32_t workgroupId) override;
int32_t AddThreadToGroup(int32_t workgroupId, int32_t tokenId) override;
int32_t RemoveThreadFromGroup(int32_t workgroupId, int32_t tokenId) override;
int32_t StartGroup(int32_t workgroupId, uint64_t startTime, uint64_t deadlineTime) override;
int32_t StopGroup(int32_t workgroupId) override;
bool NeedDelayCreateSink(const uint32_t idBase, const uint32_t idType, const std::string &idInfo);
bool NeedDelayCreateSource(const uint32_t idBase, const uint32_t idType, const std::string &idInfo);
const std::string GetAudioParameterInner(const std::string &key);
const std::string GetAudioParameterInner(const std::string& networkId, const AudioParamKey key,
const std::string& condition);
bool UpdateAudioParameterInfo(const std::string &key, const std::string &value,
AudioParamKey &parmKey, std::string &valueNew, std::string &halName);
const std::string GetVAParameter(const std::string &key);
int32_t SetAudioSceneInner(AudioScene audioScene, BluetoothOffloadState a2dpOffloadFlag,
bool scoExcludeFlag, int32_t phoneCallSceneType = SCENE_TYPE_INVALID);
sptr<IRemoteObject> CreateAudioProcessInner(const AudioProcessConfig &config, int32_t &errorCode,
const AudioPlaybackCaptureConfig &filterConfig);
int32_t GetExtraParametersInner(const std::string &mainKey,
const std::vector<std::string> &subKeys, std::vector<std::pair<std::string, std::string>> &result);
int32_t ImproveAudioWorkgroupPrio(const std::unordered_map<int32_t, bool> &threads) override;
int32_t RestoreAudioWorkgroupPrio(const std::unordered_map<int32_t, int32_t> &threads) override;
int32_t GetPrivacyTypeAudioServer(uint32_t sessionId, int32_t &privacyType, int32_t &ret) override;
int32_t SetAudioBalanceStatus();
int32_t SetAudioBalanceValueInner(bool isAudioBalanceEnable, float audioBalance);
void OnStartExpansion();
bool AudioParameterValueCheck(const std::string &key, const std::string &value);
void RecordBootStateTime(AudioServerBootState state, int64_t curTime);
void InitAudioEngine();
void RegisterResSchedSys();
void HapReportWakeupEvent(const std::string &key,
const std::vector<std::pair<std::string, std::string>> &kvpairs);
int32_t TrySetAudioEffectParameterToRemote(std::vector<std::pair<std::string, std::string>> &newPair);
private:
static constexpr int32_t MEDIA_SERVICE_UID = 1013;
static constexpr int32_t VASSISTANT_UID = 3001;
static constexpr int32_t MAX_VOLUME = 15;
static constexpr int32_t MIN_VOLUME = 0;
static constexpr int32_t ROOT_UID = 0;
static uint32_t paDaemonTid_;
static std::unordered_map<int, float> AudioStreamVolumeMap;
static std::map<std::string, std::string> audioParameters;
static std::unordered_map<std::string, std::unordered_map<std::string, std::set<std::string>>> audioParameterKeys;
pthread_t m_paDaemonThread;
std::shared_ptr<SoundCardInfo> cacheSoundCardInfo_;
AudioScene audioScene_ = AUDIO_SCENE_DEFAULT;
std::string playTaskId_ = "0";
bool isEarpiece_ = false;
float audioBalanceValue_ = 0.0f;
float audioD2DValue_ = 0.0f;
std::atomic<uint64_t> capturerStateFlag_ = 0;
std::shared_ptr<AudioParameterCallback> audioParamCb_;
std::mutex onCapturerStateCbMutex_;
std::shared_ptr<WakeUpSourceCallback> wakeupCallback_;
std::mutex audioParamCbMtx_;
std::mutex setWakeupCloseCallbackMutex_;
std::mutex audioParameterMutex_;
std::mutex audioSceneMutex_;
std::unique_ptr<AudioEffectServer> audioEffectServer_;
std::shared_ptr<AsyncActionHandler> asyncHandler_ = nullptr;
std::atomic<bool> isAudioParameterParsed_ = false;
std::condition_variable isAudioParameterParsedCv_;
std::mutex audioParameterCacheMutex_;
int32_t maxRendererStreamCntPerUid_ = 0;
std::mutex streamLifeCycleMutex_ {};
std::map<std::string, std::string> usbInfoMap_;
std::mutex mtxGetUsbParameter_;
std::atomic<bool> isAudioPolicyReady_ = false;
std::mutex isAudioPolicyReadyMutex_;
std::condition_variable isAudioPolicyReadyCv_;
int32_t waitCreateStreamInServerCount_ = 0;
std::mutex hpaeDumpMutex_;
std::shared_ptr<IAudioServerHpaeDump> hpaeDumpObj_ = nullptr;
std::mutex audioDataTransferMutex_;
std::map<int32_t, std::shared_ptr<DataTransferStateChangeCallbackInner>> audioDataTransferCbMap_;
std::mutex setA2dpParamMutex_;
std::map<pid_t, sptr<CallbackHandle>> cbHandles_;
std::mutex cbLock_;
std::mutex audioAdapterCbMutex_;
std::shared_ptr<AudioParameterCallback> audioAdapterCb_;
std::unordered_set<std::string> audioAdapterNetworkIdSet_;
};
class DataTransferStateChangeCallbackInnerImpl : public DataTransferStateChangeCallbackInner {
public:
DataTransferStateChangeCallbackInnerImpl() = default;
virtual ~DataTransferStateChangeCallbackInnerImpl() = default;
void OnDataTransferStateChange(const int32_t &callbackId,
const AudioRendererDataTransferStateChangeInfo &info) override;
void OnMuteStateChange(const int32_t &callbackId, const int32_t &uid,
const uint32_t &sessionId, const bool &isMuted) override {}
void SetDataTransferMonitorParam(const DataTransferMonitorParam ¶m);
private:
void ReportEvent(const AudioRendererDataTransferStateChangeInfo &info);
void ReportStandbyEvent(const AudioRendererDataTransferStateChangeInfo &info, int32_t standbyDurationS);
bool IsNeedNotifyStandbyState(const AudioRendererDataTransferStateChangeInfo &info, bool isStandby);
void NotifyStreamStandbyState(const AudioRendererDataTransferStateChangeInfo &info, bool isStandby);
DataTransferMonitorParam param_;
std::mutex standbyMutex_;
std::map<uint32_t, int64_t> standbyStartTimeMap_;
};
}
}
#endif