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