1 /* 2 * Copyright (c) 2025 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_POLICY_INTERFACE_H 17 #define ST_AUDIO_POLICY_INTERFACE_H 18 19 #include <list> 20 #include <mutex> 21 22 #include "audio_device_descriptor.h" 23 #include "audio_device_info.h" 24 #include "audio_info.h" 25 #include "audio_interrupt_info.h" 26 #include "audio_stream_change_info.h" 27 28 namespace OHOS { 29 namespace AudioStandard { 30 /** 31 * Describes the device change type and device information. 32 * 33 * @since 7 34 */ 35 struct DeviceChangeAction { 36 DeviceChangeType type; 37 DeviceFlag flag; 38 std::vector<std::shared_ptr<AudioDeviceDescriptor>> deviceDescriptors; 39 }; 40 41 class AudioFocusInfoChangeCallback { 42 public: 43 virtual ~AudioFocusInfoChangeCallback() = default; 44 /** 45 * Called when focus info change. 46 * 47 * @param focusInfoList Indicates the focusInfoList information needed by client. 48 * For details, refer audioFocusInfoList_ struct in audio_policy_server.h 49 * @since 9 50 */ 51 virtual void OnAudioFocusInfoChange(const std::list<std::pair<AudioInterrupt, AudioFocuState>> &focusInfoList) = 0; 52 OnAudioFocusRequested(const AudioInterrupt &)53 virtual void OnAudioFocusRequested(const AudioInterrupt &) {} 54 OnAudioFocusAbandoned(const AudioInterrupt &)55 virtual void OnAudioFocusAbandoned(const AudioInterrupt &) {} 56 }; 57 58 class AudioDeviceRefiner { 59 public: 60 virtual ~AudioDeviceRefiner() = default; 61 62 virtual int32_t OnAudioOutputDeviceRefined(std::vector<std::shared_ptr<AudioDeviceDescriptor>> &descs, 63 RouterType routerType, StreamUsage streamUsage, int32_t clientUid, AudioPipeType audioPipeType) = 0; 64 virtual int32_t OnAudioInputDeviceRefined(std::vector<std::shared_ptr<AudioDeviceDescriptor>> &descs, 65 RouterType routerType, SourceType sourceType, int32_t clientUid, AudioPipeType audioPipeType) = 0; 66 }; 67 68 class AudioClientInfoMgrCallback { 69 public: 70 virtual ~AudioClientInfoMgrCallback() = default; 71 virtual bool OnCheckClientInfo(const std::string &bundleName, int32_t &uid, int32_t pid) = 0; 72 }; 73 74 class AudioPreferredOutputDeviceChangeCallback { 75 public: 76 virtual ~AudioPreferredOutputDeviceChangeCallback() = default; 77 /** 78 * Called when the prefer output device changes 79 * 80 * @param vector<std::shared_ptr<AudioDeviceDescriptor>> deviceDescriptor. 81 */ 82 virtual void OnPreferredOutputDeviceUpdated(const std::vector<std::shared_ptr<AudioDeviceDescriptor>> &desc) = 0; 83 }; 84 85 class AudioPreferredInputDeviceChangeCallback { 86 public: 87 virtual ~AudioPreferredInputDeviceChangeCallback() = default; 88 /** 89 * Called when the prefer input device changes 90 * 91 * @param vector<std::shared_ptr<AudioDeviceDescriptor>> deviceDescriptor. 92 */ 93 virtual void OnPreferredInputDeviceUpdated(const std::vector<std::shared_ptr<AudioDeviceDescriptor>> &desc) = 0; 94 }; 95 96 class AudioManagerDeviceChangeCallback { 97 public: 98 virtual ~AudioManagerDeviceChangeCallback() = default; 99 /** 100 * Called when an interrupt is received. 101 * 102 * @param deviceChangeAction Indicates the DeviceChangeAction information needed by client. 103 * For details, refer DeviceChangeAction struct 104 * @since 8 105 */ 106 virtual void OnDeviceChange(const DeviceChangeAction &deviceChangeAction) = 0; 107 }; 108 109 class AudioDistribuitedOutputChangeCallback { 110 public: 111 virtual ~AudioDistribuitedOutputChangeCallback() = default; 112 /** 113 * Called when Distribuited output device changed 114 * 115 * @param deviceDesc selected device 116 * @param isRemote is cast direction remote 117 * @since 16 118 */ 119 virtual void OnDistribuitedOutputChange(const AudioDeviceDescriptor &deviceDesc, bool isRemote) = 0; 120 }; 121 122 class AudioQueryClientTypeCallback { 123 public: 124 virtual ~AudioQueryClientTypeCallback() = default; 125 virtual bool OnQueryClientType(const std::string &bundleName, uint32_t uid) = 0; 126 }; 127 128 class VolumeKeyEventCallback { 129 public: 130 virtual ~VolumeKeyEventCallback() = default; 131 /** 132 * @brief VolumeKeyEventCallback will be executed when hard volume key is pressed up/down 133 * 134 * @param volumeEvent the volume event info. 135 * @since 8 136 */ 137 virtual void OnVolumeKeyEvent(VolumeEvent volumeEvent) = 0; 138 }; 139 140 class AudioCapturerStateChangeCallback { 141 public: 142 virtual ~AudioCapturerStateChangeCallback() = default; 143 /** 144 * Called when the capturer state changes 145 * 146 * @param capturerChangeInfo Contains the renderer state information. 147 */ 148 virtual void OnCapturerStateChange( 149 const std::vector<std::shared_ptr<AudioCapturerChangeInfo>> &audioCapturerChangeInfos) = 0; 150 std::mutex cbMutex_; 151 }; 152 153 class AudioRendererStateChangeCallback { 154 public: 155 virtual ~AudioRendererStateChangeCallback() = default; 156 /** 157 * Called when the renderer state changes 158 * 159 * @param rendererChangeInfo Contains the renderer state information. 160 */ 161 virtual void OnRendererStateChange( 162 const std::vector<std::shared_ptr<AudioRendererChangeInfo>> &audioRendererChangeInfos) = 0; 163 }; 164 165 class AudioQueryAllowedPlaybackCallback { 166 public: 167 virtual ~AudioQueryAllowedPlaybackCallback() = default; 168 virtual bool OnQueryAllowedPlayback(int32_t uid, int32_t pid) = 0; 169 }; 170 171 class AudioManagerAudioSceneChangedCallback { 172 public: 173 virtual ~AudioManagerAudioSceneChangedCallback() = default; 174 /** 175 * Called when AudioScene changed. 176 * 177 * @param AudioScene audio scene 178 * @since 16 179 */ 180 virtual void OnAudioSceneChange(const AudioScene audioScene) = 0; 181 }; 182 } // namespace AudioStandard 183 } // namespace OHOS 184 #endif // ST_AUDIO_POLICY_INTERFACE_H 185 186