1 /* 2 * Copyright (c) 2023 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 AUDIO_ENDPOINT_H 17 #define AUDIO_ENDPOINT_H 18 19 #include <sstream> 20 #include <memory> 21 #include <thread> 22 23 #include "common/hdi_adapter_info.h" 24 #include "sink/i_audio_render_sink.h" 25 #include "source/i_audio_capture_source.h" 26 #include "i_process_status_listener.h" 27 #include "linear_pos_time_model.h" 28 #include "audio_device_descriptor.h" 29 #include "i_stream_manager.h" 30 #include "i_renderer_stream.h" 31 #include "audio_utils.h" 32 33 namespace OHOS { 34 namespace AudioStandard { 35 // When AudioEndpoint is offline, notify the owner. 36 class IAudioEndpointStatusListener { 37 public: 38 enum HdiDeviceStatus : uint32_t { 39 STATUS_ONLINE = 0, 40 STATUS_OFFLINE, 41 STATUS_INVALID, 42 }; 43 44 /** 45 * When AudioEndpoint changed status, we need to notify AudioProcessStream. 46 */ 47 virtual int32_t OnEndpointStatusChange(HdiDeviceStatus status) = 0; 48 }; 49 50 class AudioEndpoint : public IProcessStatusListener { 51 public: 52 static constexpr int32_t MAX_LINKED_PROCESS = 6; // 6 53 enum EndpointType : uint32_t { 54 TYPE_MMAP = 0, 55 TYPE_INVALID, 56 TYPE_VOIP_MMAP 57 }; 58 59 enum EndpointStatus : uint32_t { 60 INVALID = 0, 61 UNLINKED, // no process linked 62 IDEL, // no running process 63 STARTING, // calling start sink 64 RUNNING, // at least one process is running 65 STOPPING, // calling stop sink 66 STOPPED // sink stoped 67 }; 68 69 static std::shared_ptr<AudioEndpoint> CreateEndpoint(EndpointType type, uint64_t id, 70 const AudioProcessConfig &clientConfig, const AudioDeviceDescriptor &deviceInfo, AudioStreamInfo &streamInfo); 71 static std::string GenerateEndpointKey(AudioDeviceDescriptor &deviceInfo, int32_t endpointFlag); 72 73 virtual std::string GetEndpointName() = 0; 74 75 virtual EndpointType GetEndpointType() = 0; 76 virtual int32_t SetVolume(AudioStreamType streamType, float volume) = 0; 77 78 virtual std::shared_ptr<OHAudioBufferBase> GetBuffer() = 0; 79 80 virtual EndpointStatus GetStatus() = 0; 81 82 virtual void Release() = 0; 83 84 virtual bool ShouldInnerCap(int32_t innerCapId) = 0; 85 virtual int32_t EnableFastInnerCap(int32_t innerCapId) = 0; 86 virtual int32_t DisableFastInnerCap() = 0; 87 virtual int32_t DisableFastInnerCap(int32_t innerCapId) = 0; 88 89 virtual int32_t LinkProcessStream(IAudioProcessStream *processStream, bool startWhenLinking = true) = 0; 90 virtual int32_t UnlinkProcessStream(IAudioProcessStream *processStream) = 0; 91 92 virtual int32_t GetPreferBufferInfo(uint32_t &totalSizeInframe, uint32_t &spanSizeInframe) = 0; 93 94 virtual void Dump(std::string &dumpString) = 0; 95 96 virtual DeviceRole GetDeviceRole(); 97 virtual AudioDeviceDescriptor &GetDeviceInfo(); 98 virtual AudioStreamInfo &GetAudioStreamInfo(); 99 virtual float GetMaxAmplitude() = 0; 100 virtual uint32_t GetLinkedProcessCount() = 0; 101 102 virtual AudioMode GetAudioMode() const = 0; 103 104 virtual ~AudioEndpoint() = default; 105 106 protected: 107 // SamplingRate EncodingType SampleFormat Channel 108 AudioStreamInfo dstStreamInfo_; 109 AudioDeviceDescriptor deviceInfo_ = AudioDeviceDescriptor(AudioDeviceDescriptor::DEVICE_INFO); 110 111 private: 112 virtual bool Config(const AudioDeviceDescriptor &deviceInfo, AudioStreamInfo &streamInfo) = 0; 113 }; 114 } // namespace AudioStandard 115 } // namespace OHOS 116 #endif // AUDIO_ENDPOINT_H 117