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_SERVICE_ADAPTER_H 17 #define ST_AUDIO_SERVICE_ADAPTER_H 18 19 #include <memory> 20 #include <string> 21 #include <unistd.h> 22 #include <vector> 23 24 #include "audio_info.h" 25 #include "audio_effect.h" 26 27 namespace OHOS { 28 namespace AudioStandard { 29 class AudioServiceAdapterCallback { 30 public: 31 /** 32 * @brief computes the volume to be set in audioserver 33 * 34 * @param streamType streamType for which volume will be computed 35 * @return Returns volume level in float 36 */ 37 virtual std::pair<float, int32_t> OnGetVolumeDbCb(AudioStreamType streamType) = 0; 38 39 virtual void OnAudioStreamRemoved(const uint64_t sessionID) = 0; 40 41 virtual void OnSetVolumeDbCb() = 0; 42 ~AudioServiceAdapterCallback()43 virtual ~AudioServiceAdapterCallback() {} 44 }; 45 46 class AudioServiceAdapter { 47 public: 48 /** 49 * @brief create audioserviceadapter instance 50 * 51 * @param cb callback reference for AudioServiceAdapterCallback class 52 * @return Returns instance of class that extends AudioServiceAdapter 53 */ 54 static std::unique_ptr<AudioServiceAdapter> CreateAudioAdapter(std::unique_ptr<AudioServiceAdapterCallback> cb); 55 56 /** 57 * @brief Connect to underlining audio server 58 * 59 * @return Returns true if connection is success, else return false 60 * @since 1.0 61 * @version 1.0 62 */ 63 virtual bool Connect() = 0; 64 65 /** 66 * @brief Opens the audio port while loading the audio modules source and sink. 67 * 68 * @param audioPortName name of the audio modules to be loaded 69 * @param moduleArgs audio module info like rate, channel etc 70 * @return Returns module index if module loaded successfully; returns an error code 71 * defined in {@link audio_errors.h} otherwise. 72 */ 73 virtual uint32_t OpenAudioPort(std::string audioPortName, std::string moduleArgs) = 0; 74 75 /** 76 * @brief closes/unloads the audio modules loaded. 77 * 78 * @param audioHandleIndex the index of the loaded audio module 79 * @return Returns {@link SUCCESS} if module/port is closed successfully; returns an error code 80 * defined in {@link audio_errors.h} otherwise. 81 */ 82 virtual int32_t CloseAudioPort(int32_t audioHandleIndex) = 0; 83 84 /** 85 * @brief sets default audio sink. 86 * 87 * @param name name of default audio sink to be set 88 * @return Returns {@link SUCCESS} if default audio sink is set successfully; returns an error code 89 * defined in {@link audio_errors.h} otherwise. 90 */ 91 virtual int32_t SetDefaultSink(std::string name) = 0; 92 93 /** 94 * @brief sets default audio source. 95 * 96 * @param name name of default audio source to be set 97 * @return Returns {@link SUCCESS} if default audio source is set successfully; returns an error code 98 * defined in {@link audio_errors.h} otherwise. 99 */ 100 virtual int32_t SetDefaultSource(std::string name) = 0; 101 102 /** 103 * @brief sets all sink-input connect to one default dink 104 * 105 * @param name name of default audio sink to be set 106 * @return Returns {@link SUCCESS} if default audio sink is set successfully; returns an error code 107 * defined in {@link audio_errors.h} otherwise. 108 */ 109 virtual int32_t SetLocalDefaultSink(std::string name) = 0; 110 111 /** 112 * @brief get sinks by adapter name 113 * 114 * @param adapterName name of default audio sink to be set 115 * @return Returns sink ids. 116 */ 117 virtual std::vector<uint32_t> GetTargetSinks(std::string adapterName) = 0; 118 119 /** 120 * @brief get all sinks 121 * 122 * @return Returns sink infos. 123 */ 124 virtual std::vector<SinkInfo> GetAllSinks() = 0; 125 126 /** 127 * @brief sets audio volume db 128 * 129 * @param streamType the streamType for which volume will be set, streamType defined in{@link audio_info.h} 130 * @param volume the volume level to be set 131 * @return Returns {@link SUCCESS} if volume is set successfully; returns an error code 132 * defined in {@link audio_errors.h} otherwise. 133 */ 134 virtual int32_t SetVolumeDb(AudioStreamType streamType, float volume) = 0; 135 136 /** 137 * @brief set mute for give output streamType 138 * 139 * @param streamType the output streamType for which mute will be set, streamType defined in{@link audio_info.h} 140 * @param mute boolean value, true: Set mute; false: Set unmute 141 * @return Returns {@link SUCCESS} if mute/unmute is set successfully; returns an error code 142 * defined in {@link audio_errors.h} otherwise. 143 */ 144 virtual int32_t SetSourceOutputMute(int32_t uid, bool setMute) = 0; 145 146 /** 147 * @brief suspends the current active device 148 * 149 * @param audioPortName Name of the default audio sink to be suspended 150 * @return Returns {@link SUCCESS} if suspend is success; returns an error code 151 * defined in {@link audio_errors.h} otherwise. 152 */ 153 virtual int32_t SuspendAudioDevice(std::string &audioPortName, bool isSuspend) = 0; 154 155 /** 156 * @brief mute the device or unmute 157 * 158 * @param sinkName Name of the audio sink 159 * @return Returns {@link true} if mute is success; returns false otherwise. 160 */ 161 virtual bool SetSinkMute(const std::string &sinkName, bool isMute, bool isSync = false) = 0; 162 163 /** 164 * @brief returns the list of all sink inputs 165 * 166 * @return Returns : List of all sink inputs 167 */ 168 virtual std::vector<SinkInput> GetAllSinkInputs() = 0; 169 170 /** 171 * @brief returns the list of all source outputs 172 * 173 * @return Returns : List of all source outputs 174 */ 175 virtual std::vector<SourceOutput> GetAllSourceOutputs() = 0; 176 177 /** 178 * @brief Disconnects the connected audio server 179 * 180 * @return void 181 */ 182 virtual void Disconnect() = 0; 183 184 /** 185 * @brief Move one stream to target source. 186 * 187 * @return int32_t the result. 188 */ 189 virtual int32_t MoveSourceOutputByIndexOrName(uint32_t sourceOutputId, 190 uint32_t sourceIndex, std::string sourceName) = 0; 191 192 /** 193 * @brief Move one stream to target sink. 194 * 195 * @return int32_t the result. 196 */ 197 virtual int32_t MoveSinkInputByIndexOrName(uint32_t sinkInputId, uint32_t sinkIndex, std::string sinkName) = 0; 198 199 virtual ~AudioServiceAdapter(); 200 }; 201 } // namespace AudioStandard 202 } // namespace OHOS 203 #endif // ST_AUDIO_SERVICE_ADAPTER_H 204