1 /* 2 * Copyright (c) 2022-2024 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 OHOS_AUDIO_CAPTURE_INTERFACE_IMPL_H 17 #define OHOS_AUDIO_CAPTURE_INTERFACE_IMPL_H 18 19 #include <mutex> 20 #include <string> 21 22 #include "audio_capture_interface_impl_base.h" 23 24 #include <v1_0/audio_types.h> 25 #include <v1_0/iaudio_capture.h> 26 #include <v2_0/id_audio_manager.h> 27 28 namespace OHOS { 29 namespace HDI { 30 namespace DistributedAudio { 31 namespace Audio { 32 namespace V1_0 { 33 using OHOS::HDI::DistributedAudio::Audioext::V2_0::AudioData; 34 using OHOS::HDI::DistributedAudio::Audioext::V2_0::AudioParameter; 35 using OHOS::HDI::DistributedAudio::Audioext::V2_0::DAudioEvent; 36 using OHOS::HDI::DistributedAudio::Audioext::V2_0::IDAudioCallback; 37 38 class AudioCaptureInterfaceImpl : public AudioCaptureInterfaceImplBase { 39 public: 40 AudioCaptureInterfaceImpl(const std::string &adpName, const AudioDeviceDescriptor &desc, 41 const AudioSampleAttributes &attrs, const sptr<IDAudioCallback> &callback); 42 ~AudioCaptureInterfaceImpl() override; 43 44 int32_t CaptureFrame(std::vector<int8_t> &frame, uint64_t &replyBytes) override; 45 int32_t GetCapturePosition(uint64_t &frames, AudioTimeStamp &time) override; 46 int32_t CheckSceneCapability(const AudioSceneDescriptor &scene, bool &supported) override; 47 int32_t SelectScene(const AudioSceneDescriptor &scene) override; 48 int32_t SetMute(bool mute) override; 49 int32_t GetMute(bool &mute) override; 50 int32_t SetVolume(float volume) override; 51 int32_t GetVolume(float &volume) override; 52 int32_t GetGainThreshold(float &min, float &max) override; 53 int32_t GetGain(float &gain) override; 54 int32_t SetGain(float gain) override; 55 int32_t GetFrameSize(uint64_t &size) override; 56 int32_t GetFrameCount(uint64_t &count) override; 57 int32_t SetSampleAttributes(const AudioSampleAttributes &attrs) override; 58 int32_t GetSampleAttributes(AudioSampleAttributes &attrs) override; 59 int32_t GetCurrentChannelId(uint32_t &channelId) override; 60 int32_t SetExtraParams(const std::string &keyValueList) override; 61 int32_t GetExtraParams(std::string &keyValueList) override; 62 int32_t ReqMmapBuffer(int32_t reqSize, AudioMmapBufferDescriptor &desc) override; 63 int32_t GetMmapPosition(uint64_t &frames, AudioTimeStamp &time) override; 64 int32_t AddAudioEffect(uint64_t effectid) override; 65 int32_t RemoveAudioEffect(uint64_t effectid) override; 66 int32_t GetFrameBufferSize(uint64_t &bufferSize) override; 67 int32_t Start() override; 68 int32_t Stop() override; 69 int32_t Pause() override; 70 int32_t Resume() override; 71 int32_t Flush() override; 72 int32_t TurnStandbyMode() override; 73 int32_t AudioDevDump(int32_t range, int32_t fd) override; 74 int32_t IsSupportsPauseAndResume(bool &supportPause, bool &supportResume) override; 75 const AudioDeviceDescriptor &GetCaptureDesc() override; 76 void SetAttrs(const std::string &adpName, const AudioDeviceDescriptor &desc, 77 const AudioSampleAttributes &attrs, const sptr<IDAudioCallback> &callback, const int32_t dhId) override; 78 void SetDumpFlagInner() override; 79 80 private: 81 static constexpr int64_t AUDIO_OFFSET_FRAME_NUM = 10; 82 const std::string HDF_CAPTURE_FILENAME = "/data/data/daudio/hdf_capture_from_sa.pcm"; 83 std::string adapterName_; 84 AudioDeviceDescriptor devDesc_; 85 AudioSampleAttributes devAttrs_; 86 uint32_t captureId_ = 0; 87 bool dumpFlag_ = false; 88 int64_t frameIndex_ = 0; 89 int64_t framePeriodNs_ = 0; 90 int64_t startTime_ = 0; 91 int64_t lastCaptureStartTime_ = 0; 92 std::atomic<bool> muteState_ = false; 93 94 std::mutex captureMtx_; 95 AudioCaptureStatus captureStatus_ = CAPTURE_STATUS_CLOSE; 96 sptr<IDAudioCallback> audioExtCallback_ = nullptr; 97 }; 98 } // V1_0 99 } // Audio 100 } // Distributedaudio 101 } // HDI 102 } // OHOS 103 #endif // OHOS_AUDIO_CAPTURE_INTERFACE_IMPL_H