1 /* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License") = 0; 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 I_AUDIO_CAPTURER_SOURCE_H 17 #define I_AUDIO_CAPTURER_SOURCE_H 18 19 #include <cstdint> 20 21 #include "audio_info.h" 22 23 namespace OHOS { 24 namespace AudioStandard { 25 typedef struct { 26 const char *adapterName; 27 uint32_t open_mic_speaker; 28 AudioSampleFormat format; 29 uint32_t sampleFmt; 30 uint32_t sampleRate; 31 uint32_t channel; 32 float volume; 33 uint32_t bufferSize; 34 bool isBigEndian; 35 const char *filePath; 36 const char *deviceNetworkId; 37 int32_t deviceType; 38 int32_t sourceType; 39 } IAudioSourceAttr; 40 41 class IAudioSourceCallback { 42 public: 43 virtual void OnWakeupClose() = 0; 44 virtual void OnCapturerState(bool isActive) = 0; 45 }; 46 47 class IAudioCapturerSource { 48 public: 49 static IAudioCapturerSource *GetInstance(const char *deviceClass, const char *deviceNetworkId, 50 const SourceType sourceType = SourceType::SOURCE_TYPE_MIC, const char *sourceName = "Built_in_wakeup"); 51 virtual int32_t Init(IAudioSourceAttr &attr) = 0; 52 virtual bool IsInited(void) = 0; 53 virtual void DeInit(void) = 0; 54 55 virtual int32_t Start(void) = 0; 56 virtual int32_t Stop(void) = 0; 57 virtual int32_t Flush(void) = 0; 58 virtual int32_t Reset(void) = 0; 59 virtual int32_t Pause(void) = 0; 60 virtual int32_t Resume(void) = 0; 61 virtual int32_t CaptureFrame(char *frame, uint64_t requestBytes, uint64_t &replyBytes) = 0; 62 virtual int32_t SetVolume(float left, float right) = 0; 63 virtual int32_t GetVolume(float &left, float &right) = 0; 64 virtual int32_t SetMute(bool isMute) = 0; 65 virtual int32_t GetMute(bool &isMute) = 0; 66 virtual int32_t SetAudioScene(AudioScene audioScene, DeviceType activeDevice) = 0; 67 virtual int32_t SetInputRoute(DeviceType deviceType) = 0; 68 virtual uint64_t GetTransactionId() = 0; 69 70 virtual void RegisterWakeupCloseCallback(IAudioSourceCallback* callback) = 0; 71 virtual void RegisterAudioCapturerSourceCallback(IAudioSourceCallback* callback) = 0; 72 73 virtual ~IAudioCapturerSource() = default; 74 }; 75 76 class IMmapAudioCapturerSource : public IAudioCapturerSource { 77 public: 78 IMmapAudioCapturerSource() = default; 79 virtual ~IMmapAudioCapturerSource() = default; 80 virtual int32_t GetMmapBufferInfo(int &fd, uint32_t &totalSizeInframe, uint32_t &spanSizeInframe, 81 uint32_t &byteSizePerFrame) = 0; 82 virtual int32_t GetMmapHandlePosition(uint64_t &frames, int64_t &timeSec, int64_t &timeNanoSec) = 0; 83 }; 84 } // namespace AudioStandard 85 } // namespace OHOS 86 #endif // AUDIO_CAPTURER_SOURCE_H 87