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 22 #include "i_process_status_listener.h" 23 24 namespace OHOS { 25 namespace AudioStandard { 26 // When AudioEndpoint is offline, notify the owner. 27 class IAudioEndpointStatusListener { 28 public: 29 enum HdiDeviceStatus : uint32_t { 30 STATUS_ONLINE = 0, 31 STATUS_OFFLINE, 32 STATUS_INVALID, 33 }; 34 35 /** 36 * When AudioEndpoint changed status, we need to notify AudioProcessStream. 37 */ 38 virtual int32_t OnEndpointStatusChange(HdiDeviceStatus status) = 0; 39 }; 40 41 class AudioEndpoint : public IProcessStatusListener { 42 public: 43 static constexpr int32_t MAX_LINKED_PROCESS = 3; // 3 44 enum EndpointType : uint32_t { 45 TYPE_MMAP = 0, 46 TYPE_INVALID 47 }; 48 49 enum EndpointStatus : uint32_t { 50 INVALID = 0, 51 UNLINKED, // no process linked 52 IDEL, // no running process 53 STARTING, // calling start sink 54 RUNNING, // at least one process is running 55 STOPPING, // calling stop sink 56 STOPPED // sink stoped 57 }; 58 59 static std::shared_ptr<AudioEndpoint> GetInstance(EndpointType type, const DeviceInfo &deviceInfo); 60 61 virtual std::string GetEndpointName() = 0; 62 63 virtual EndpointStatus GetStatus() = 0; 64 65 virtual void Release() = 0; 66 67 virtual int32_t LinkProcessStream(IAudioProcessStream *processStream) = 0; 68 virtual int32_t UnlinkProcessStream(IAudioProcessStream *processStream) = 0; 69 70 virtual int32_t GetPreferBufferInfo(uint32_t &totalSizeInframe, uint32_t &spanSizeInframe) = 0; 71 72 virtual void Dump(std::stringstream &dumpStringStream) = 0; 73 74 virtual ~AudioEndpoint() = default; 75 }; 76 } // namespace AudioStandard 77 } // namespace OHOS 78 #endif // AUDIO_ENDPOINT_H 79