• 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") = 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 #include "audio_hdiadapter_info.h"
23 
24 namespace OHOS {
25 namespace AudioStandard {
26 typedef struct IAudioSourceAttr {
27     const char *adapterName = NULL;
28     uint32_t openMicSpeaker = 0;
29     HdiAdapterFormat format = HdiAdapterFormat::INVALID_WIDTH;
30     uint32_t sampleRate = 0;
31     uint32_t channel = 0;
32     float volume = 0.0f;
33     uint32_t bufferSize = 0;
34     bool isBigEndian = false;
35     const char *filePath = NULL;
36     const char *deviceNetworkId = NULL;
37     int32_t deviceType = 0;
38     int32_t sourceType = 0;
39     uint64_t channelLayout = 0;
40     int32_t audioStreamFlag = 0;
41     bool hasEcConfig = false;
42     HdiAdapterFormat formatEc = HdiAdapterFormat::INVALID_WIDTH;
43     uint32_t sampleRateEc = 0;
44     uint32_t channelEc = 0;
45 } IAudioSourceAttr;
46 
47 class IAudioSourceCallback {
48 public:
49     virtual void OnWakeupClose() = 0;
50     virtual void OnAudioSourceParamChange(const std::string &netWorkId, const AudioParamKey key,
51         const std::string &condition, const std::string &value) = 0;
52 };
53 
54 class ICapturerStateCallback {
55 public:
56     virtual void OnCapturerState(bool isActive) = 0;
57     virtual ~ICapturerStateCallback() = default;
58 };
59 
60 class IAudioCapturerSource {
61 public:
62     static IAudioCapturerSource *GetInstance(const char *deviceClass, const char *deviceNetworkId,
63            const SourceType sourceType = SourceType::SOURCE_TYPE_MIC, const char *sourceName = "Built_in_wakeup");
64     static IAudioCapturerSource *Create(CaptureAttr *attr);
65     static void GetAllInstance(std::vector<IAudioCapturerSource *> &allInstance);
66     virtual ~IAudioCapturerSource() = default;
67 
68     virtual int32_t Init(const IAudioSourceAttr &attr) = 0;
InitWithoutAttr()69     virtual int32_t InitWithoutAttr() { return 0; }
70     virtual bool IsInited(void) = 0;
71     virtual void DeInit(void) = 0;
72 
73     virtual int32_t Start(void) = 0;
74     virtual int32_t Stop(void) = 0;
75     virtual int32_t Flush(void) = 0;
76     virtual int32_t Reset(void) = 0;
77     virtual int32_t Pause(void) = 0;
78     virtual int32_t Resume(void) = 0;
79 
80     virtual int32_t CaptureFrame(char *frame, uint64_t requestBytes, uint64_t &replyBytes) = 0;
81     virtual int32_t CaptureFrameWithEc(
82         FrameDesc *fdesc, uint64_t &replyBytes,
83         FrameDesc *fdescEc, uint64_t &replyBytesEc) = 0;
84 
85     virtual int32_t SetVolume(float left, float right) = 0;
86     virtual int32_t GetVolume(float &left, float &right) = 0;
87     virtual int32_t SetMute(bool isMute) = 0;
88     virtual int32_t GetMute(bool &isMute) = 0;
89     virtual int32_t SetAudioScene(AudioScene audioScene, DeviceType activeDevice,
90         const std::string &deviceName = "") = 0;
91     virtual int32_t SetInputRoute(DeviceType deviceType, const std::string &deviceName = "") = 0;
92     virtual uint64_t GetTransactionId() = 0;
93     virtual int32_t GetPresentationPosition(uint64_t& frames, int64_t& timeSec, int64_t& timeNanoSec) = 0;
94     virtual std::string GetAudioParameter(const AudioParamKey key, const std::string &condition) = 0;
95 
96     virtual void RegisterWakeupCloseCallback(IAudioSourceCallback *callback) = 0;
97     virtual void RegisterAudioCapturerSourceCallback(std::unique_ptr<ICapturerStateCallback> callback) = 0;
98     virtual void RegisterParameterCallback(IAudioSourceCallback *callback) = 0;
99     virtual float GetMaxAmplitude() = 0;
100     virtual int32_t GetCaptureId(uint32_t &captureId) const = 0;
101 
102     virtual int32_t UpdateAppsUid(const int32_t appsUid[PA_MAX_OUTPUTS_PER_SOURCE],
103         const size_t size) = 0;
104     virtual int32_t UpdateAppsUid(const std::vector<int32_t> &appsUid) = 0;
105 
Preload(const std::string & usbInfoStr)106     virtual int32_t Preload(const std::string &usbInfoStr)
107     {
108         return 0;
109     }
110 
UpdateSourceType(SourceType sourceType)111     virtual int32_t UpdateSourceType(SourceType sourceType)
112     {
113         return 0;
114     }
115 
SetAddress(const std::string & address)116     virtual void SetAddress(const std::string &address)
117     {
118         return;
119     }
120 };
121 
122 class IMmapAudioCapturerSource : public IAudioCapturerSource {
123 public:
124     IMmapAudioCapturerSource() = default;
125     virtual ~IMmapAudioCapturerSource() = default;
126     virtual int32_t GetMmapBufferInfo(int &fd, uint32_t &totalSizeInframe, uint32_t &spanSizeInframe,
127         uint32_t &byteSizePerFrame) = 0;
128     virtual int32_t GetMmapHandlePosition(uint64_t &frames, int64_t &timeSec, int64_t &timeNanoSec) = 0;
129 };
130 }  // namespace AudioStandard
131 }  // namespace OHOS
132 #endif  // AUDIO_CAPTURER_SOURCE_H
133