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 23 #include "audio_info.h" 24 25 namespace OHOS { 26 namespace AudioStandard { 27 class AudioServiceAdapterCallback { 28 public: 29 /** 30 * @brief computes the volume to be set in audioserver 31 * 32 * @param streamType streamType for which volume will be computed 33 * @return Returns volume level in float 34 */ 35 virtual float OnGetVolumeCb(std::string streamType) = 0; 36 37 virtual void OnSessionRemoved(const uint32_t sessionID) = 0; 38 ~AudioServiceAdapterCallback()39 virtual ~AudioServiceAdapterCallback() {} 40 }; 41 42 class AudioServiceAdapter { 43 public: 44 /** 45 * @brief creater audioserviceadapter instance 46 * 47 * @param cb callback reference for AudioServiceAdapterCallback class 48 * @return Returns instance of class that extends AudioServiceAdapter 49 */ 50 static std::unique_ptr<AudioServiceAdapter> CreateAudioAdapter(std::unique_ptr<AudioServiceAdapterCallback> cb); 51 52 /** 53 * @brief Connect to underlining audio server 54 * 55 * @return Returns true if connection is success, else return false 56 * @since 1.0 57 * @version 1.0 58 */ 59 virtual bool Connect() = 0; 60 61 /** 62 * @brief Opens the audio port while loading the audio modules source and sink. 63 * 64 * @param audioPortName name of the audio modules to be loaded 65 * @param moduleArgs audio module info like rate, channel etc 66 * @return Returns module index if module loaded successfully; returns an error code 67 * defined in {@link audio_errors.h} otherwise. 68 */ 69 virtual uint32_t OpenAudioPort(std::string audioPortName, std::string moduleArgs) = 0; 70 71 /** 72 * @brief closes/unloads the audio modules loaded. 73 * 74 * @param audioHandleIndex the index of the loaded audio module 75 * @return Returns {@link SUCCESS} if module/port is closed successfully; returns an error code 76 * defined in {@link audio_errors.h} otherwise. 77 */ 78 virtual int32_t CloseAudioPort(int32_t audioHandleIndex) = 0; 79 80 /** 81 * @brief sets default audio sink. 82 * 83 * @param name name of default audio sink to be set 84 * @return Returns {@link SUCCESS} if default audio sink is set successfully; returns an error code 85 * defined in {@link audio_errors.h} otherwise. 86 */ 87 virtual int32_t SetDefaultSink(std::string name) = 0; 88 89 /** 90 * @brief sets default audio source. 91 * 92 * @param name name of default audio source to be set 93 * @return Returns {@link SUCCESS} if default audio source is set successfully; returns an error code 94 * defined in {@link audio_errors.h} otherwise. 95 */ 96 virtual int32_t SetDefaultSource(std::string name) = 0; 97 98 /** 99 * @brief sets audio volume 100 * 101 * @param streamType the streamType for which volume will be set, streamType defined in{@link audio_info.h} 102 * @param volume the volume level to be set 103 * @return Returns {@link SUCCESS} if volume is set successfully; returns an error code 104 * defined in {@link audio_errors.h} otherwise. 105 */ 106 virtual int32_t SetVolume(AudioStreamType streamType, float volume) = 0; 107 108 /** 109 * @brief set mute for give streamType 110 * 111 * @param streamType the streamType for which mute will be set, streamType defined in{@link audio_info.h} 112 * @param mute boolean value, true: Set mute; false: Set unmute 113 * @return Returns {@link SUCCESS} if mute/unmute is set successfully; returns an error code 114 * defined in {@link audio_errors.h} otherwise. 115 */ 116 virtual int32_t SetMute(AudioStreamType streamType, bool mute) = 0; 117 118 /** 119 * @brief suspends the current active device 120 * 121 * @param audioPortName Name of the default audio sink to be suspended 122 * @return Returns {@link SUCCESS} if suspend is success; returns an error code 123 * defined in {@link audio_errors.h} otherwise. 124 */ 125 virtual int32_t SuspendAudioDevice(std::string &audioPortName, bool isSuspend) = 0; 126 127 /** 128 * @brief returns if given streamType is set to mute 129 * 130 * @param streamType the streamType for which mute status will be fetched, streamType defined in{@link audio_info.h} 131 * @return Returns true: Is streamType is set as mute; else returns false 132 */ 133 virtual bool IsMute(AudioStreamType streamType) = 0; 134 135 /** 136 * @brief returns if given streamType is active(currently the streamType audio is played) 137 * 138 * @param streamType the streamType for which status will be fetched streamType defined in{@link audio_info.h} 139 * @return Returns true: If streamType is active; else returns false 140 */ 141 virtual bool IsStreamActive(AudioStreamType streamType); 142 143 /** 144 * @brief Disconnects the connected audio server 145 * 146 * @return void 147 */ 148 virtual void Disconnect() = 0; 149 150 virtual ~AudioServiceAdapter(); 151 }; 152 } // namespace AudioStandard 153 } // namespace OHOS 154 #endif // ST_AUDIO_SERVICE_ADAPTER_H 155