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