• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 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 <v1_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::V1_0::AudioData;
34 using OHOS::HDI::DistributedAudio::Audioext::V1_0::AudioParameter;
35 using OHOS::HDI::DistributedAudio::Audioext::V1_0::DAudioEvent;
36 using OHOS::HDI::DistributedAudio::Audioext::V1_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 requestBytes) 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) override;
78 
79 private:
80     static constexpr int64_t AUDIO_OFFSET_FRAME_NUM = 10;
81     std::string adapterName_;
82     AudioDeviceDescriptor devDesc_;
83     AudioSampleAttributes devAttrs_;
84     uint32_t timeInterval_ = 5;
85     int64_t frameIndex_ = 0;
86     int64_t framePeriodNs_ = 0;
87     int64_t startTime_ = 0;
88 
89     std::mutex captureMtx_;
90     AudioCaptureStatus captureStatus_ = CAPTURE_STATUS_CLOSE;
91     sptr<IDAudioCallback> audioExtCallback_ = nullptr;
92 };
93 } // V1_0
94 } // Audio
95 } // Distributedaudio
96 } // HDI
97 } // OHOS
98 #endif // OHOS_AUDIO_CAPTURE_INTERFACE_IMPL_H