• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 SHARED_AUDIO_CAPTURER_WRAPPER_H
17 #define SHARED_AUDIO_CAPTURER_WRAPPER_H
18 
19 #include "audio_capturer.h"
20 
21 namespace OHOS {
22 namespace AudioStandard {
23 
24 class SharedCapturerWrapper : public AudioCapturer {
25 public:
SharedCapturerWrapper(std::shared_ptr<AudioCapturer> sharedAudioCapturer)26     explicit SharedCapturerWrapper(std::shared_ptr<AudioCapturer> sharedAudioCapturer)
27         : sharedAudioCapturer_(sharedAudioCapturer)
28     {
29     }
30 
SetParams(const AudioCapturerParams params)31     int32_t SetParams(const AudioCapturerParams params) override
32     {
33         return sharedAudioCapturer_->SetParams(params);
34     }
35 
UpdatePlaybackCaptureConfig(const AudioPlaybackCaptureConfig & config)36     int32_t UpdatePlaybackCaptureConfig(const AudioPlaybackCaptureConfig &config) override
37     {
38         return sharedAudioCapturer_->UpdatePlaybackCaptureConfig(config);
39     }
40 
SetCapturerCallback(const std::shared_ptr<AudioCapturerCallback> & callback)41     int32_t SetCapturerCallback(const std::shared_ptr<AudioCapturerCallback> &callback) override
42     {
43         return sharedAudioCapturer_->SetCapturerCallback(callback);
44     }
45 
GetParams(AudioCapturerParams & params)46     int32_t GetParams(AudioCapturerParams &params) const override
47     {
48         return sharedAudioCapturer_->GetParams(params);
49     }
50 
GetCapturerInfo(AudioCapturerInfo & capturerInfo)51     int32_t GetCapturerInfo(AudioCapturerInfo &capturerInfo) const override
52     {
53         return sharedAudioCapturer_->GetCapturerInfo(capturerInfo);
54     }
55 
GetStreamInfo(AudioStreamInfo & streamInfo)56     int32_t GetStreamInfo(AudioStreamInfo &streamInfo) const override
57     {
58         return sharedAudioCapturer_->GetStreamInfo(streamInfo);
59     }
60 
Start()61     bool Start() override
62     {
63         return sharedAudioCapturer_->Start();
64     }
65 
Read(uint8_t & buffer,size_t userSize,bool isBlockingRead)66     int32_t Read(uint8_t &buffer, size_t userSize, bool isBlockingRead) override
67     {
68         return sharedAudioCapturer_->Read(buffer, userSize, isBlockingRead);
69     }
70 
GetStatus()71     CapturerState GetStatus() const override
72     {
73         return sharedAudioCapturer_->GetStatus();
74     }
75 
GetAudioTime(Timestamp & timestamp,Timestamp::Timestampbase base)76     bool GetAudioTime(Timestamp &timestamp, Timestamp::Timestampbase base) const override
77     {
78         return sharedAudioCapturer_->GetAudioTime(timestamp, base);
79     }
80 
Pause()81     bool Pause() const override
82     {
83         return sharedAudioCapturer_->Pause();
84     }
85 
Stop()86     bool Stop() const override
87     {
88         return sharedAudioCapturer_->Stop();
89     }
90 
Flush()91     bool Flush() const override
92     {
93         return sharedAudioCapturer_->Flush();
94     }
95 
Release()96     bool Release() override
97     {
98         return sharedAudioCapturer_->Release();
99     }
100 
GetBufferSize(size_t & bufferSize)101     int32_t GetBufferSize(size_t &bufferSize) const override
102     {
103         return sharedAudioCapturer_->GetBufferSize(bufferSize);
104     }
105 
GetAudioStreamId(uint32_t & sessionID)106     int32_t GetAudioStreamId(uint32_t &sessionID) const override
107     {
108         return sharedAudioCapturer_->GetAudioStreamId(sessionID);
109     }
110 
GetFrameCount(uint32_t & frameCount)111     int32_t GetFrameCount(uint32_t &frameCount) const override
112     {
113         return sharedAudioCapturer_->GetFrameCount(frameCount);
114     }
115 
SetCapturerPositionCallback(int64_t markPosition,const std::shared_ptr<CapturerPositionCallback> & callback)116     int32_t SetCapturerPositionCallback(int64_t markPosition,
117         const std::shared_ptr<CapturerPositionCallback> &callback) override
118     {
119         return sharedAudioCapturer_->SetCapturerPositionCallback(markPosition, callback);
120     }
121 
UnsetCapturerPositionCallback()122     void UnsetCapturerPositionCallback() override
123     {
124         sharedAudioCapturer_->UnsetCapturerPositionCallback();
125     }
126 
SetCapturerPeriodPositionCallback(int64_t frameNumber,const std::shared_ptr<CapturerPeriodPositionCallback> & callback)127     int32_t SetCapturerPeriodPositionCallback(int64_t frameNumber,
128         const std::shared_ptr<CapturerPeriodPositionCallback> &callback) override
129     {
130         return sharedAudioCapturer_->SetCapturerPeriodPositionCallback(frameNumber, callback);
131     }
132 
UnsetCapturerPeriodPositionCallback()133     void UnsetCapturerPeriodPositionCallback() override
134     {
135         sharedAudioCapturer_->UnsetCapturerPeriodPositionCallback();
136     }
137 
SetBufferDuration(uint64_t bufferDuration)138     int32_t SetBufferDuration(uint64_t bufferDuration) const override
139     {
140         return sharedAudioCapturer_->SetBufferDuration(bufferDuration);
141     }
142 
SetCaptureMode(AudioCaptureMode captureMode)143     int32_t SetCaptureMode(AudioCaptureMode captureMode) override
144     {
145         return sharedAudioCapturer_->SetCaptureMode(captureMode);
146     }
147 
GetCaptureMode()148     AudioCaptureMode GetCaptureMode() const override
149     {
150         return sharedAudioCapturer_->GetCaptureMode();
151     }
152 
SetCapturerReadCallback(const std::shared_ptr<AudioCapturerReadCallback> & callback)153     int32_t SetCapturerReadCallback(const std::shared_ptr<AudioCapturerReadCallback> &callback) override
154     {
155         return sharedAudioCapturer_->SetCapturerReadCallback(callback);
156     }
157 
GetBufferDesc(BufferDesc & bufDesc)158     int32_t GetBufferDesc(BufferDesc &bufDesc) override
159     {
160         return sharedAudioCapturer_->GetBufferDesc(bufDesc);
161     }
162 
Enqueue(const BufferDesc & bufDesc)163     int32_t Enqueue(const BufferDesc &bufDesc) override
164     {
165         return sharedAudioCapturer_->Enqueue(bufDesc);
166     }
167 
Clear()168     int32_t Clear() const override
169     {
170         return sharedAudioCapturer_->Clear();
171     }
172 
GetBufQueueState(BufferQueueState & bufState)173     int32_t GetBufQueueState(BufferQueueState &bufState) const override
174     {
175         return sharedAudioCapturer_->GetBufQueueState(bufState);
176     }
177 
SetValid(bool valid)178     void SetValid(bool valid) override
179     {
180         sharedAudioCapturer_->SetValid(valid);
181     }
182 
GetFramesRead()183     int64_t GetFramesRead() const override
184     {
185         return sharedAudioCapturer_->GetFramesRead();
186     }
187 
SetAudioCapturerDeviceChangeCallback(const std::shared_ptr<AudioCapturerDeviceChangeCallback> & callback)188     int32_t SetAudioCapturerDeviceChangeCallback(
189         const std::shared_ptr<AudioCapturerDeviceChangeCallback> &callback) override
190     {
191         return sharedAudioCapturer_->SetAudioCapturerDeviceChangeCallback(callback);
192     }
193 
RemoveAudioCapturerDeviceChangeCallback(const std::shared_ptr<AudioCapturerDeviceChangeCallback> & callback)194     int32_t RemoveAudioCapturerDeviceChangeCallback(
195         const std::shared_ptr<AudioCapturerDeviceChangeCallback> &callback) override
196     {
197         return sharedAudioCapturer_->RemoveAudioCapturerDeviceChangeCallback(callback);
198     }
199 
SetAudioCapturerInfoChangeCallback(const std::shared_ptr<AudioCapturerInfoChangeCallback> & callback)200     int32_t SetAudioCapturerInfoChangeCallback(
201         const std::shared_ptr<AudioCapturerInfoChangeCallback> &callback) override
202     {
203         return sharedAudioCapturer_->SetAudioCapturerInfoChangeCallback(callback);
204     }
205 
RemoveAudioCapturerInfoChangeCallback(const std::shared_ptr<AudioCapturerInfoChangeCallback> & callback)206     int32_t RemoveAudioCapturerInfoChangeCallback(
207         const std::shared_ptr<AudioCapturerInfoChangeCallback> &callback) override
208     {
209         return sharedAudioCapturer_->RemoveAudioCapturerInfoChangeCallback(callback);
210     }
211 
RegisterAudioCapturerEventListener()212     int32_t RegisterAudioCapturerEventListener() override
213     {
214         return sharedAudioCapturer_->RegisterAudioCapturerEventListener();
215     }
216 
UnregisterAudioCapturerEventListener()217     int32_t UnregisterAudioCapturerEventListener() override
218     {
219         return sharedAudioCapturer_->UnregisterAudioCapturerEventListener();
220     }
221 
GetCurrentInputDevices(AudioDeviceDescriptor & deviceInfo)222     int32_t GetCurrentInputDevices(AudioDeviceDescriptor &deviceInfo) const override
223     {
224         return sharedAudioCapturer_->GetCurrentInputDevices(deviceInfo);
225     }
226 
GetCurrentCapturerChangeInfo(AudioCapturerChangeInfo & changeInfo)227     int32_t GetCurrentCapturerChangeInfo(AudioCapturerChangeInfo &changeInfo) const override
228     {
229         return sharedAudioCapturer_->GetCurrentCapturerChangeInfo(changeInfo);
230     }
231 
GetCurrentMicrophones()232     std::vector<sptr<MicrophoneDescriptor>> GetCurrentMicrophones() const override
233     {
234         return sharedAudioCapturer_->GetCurrentMicrophones();
235     }
236 
GetOverflowCount()237     uint32_t GetOverflowCount() const override
238     {
239         return sharedAudioCapturer_->GetOverflowCount();
240     }
241 
SetAudioSourceConcurrency(const std::vector<SourceType> & targetSources)242     int32_t SetAudioSourceConcurrency(const std::vector<SourceType> &targetSources) override
243     {
244         return sharedAudioCapturer_->SetAudioSourceConcurrency(targetSources);
245     }
246 
SetAudioCapturerErrorCallback(std::shared_ptr<AudioCapturerErrorCallback> errorCallback)247     void SetAudioCapturerErrorCallback(std::shared_ptr<AudioCapturerErrorCallback> errorCallback) override
248     {
249         return sharedAudioCapturer_->SetAudioCapturerErrorCallback(errorCallback);
250     }
251 
RegisterAudioPolicyServerDiedCb(const int32_t clientPid,const std::shared_ptr<AudioCapturerPolicyServiceDiedCallback> & callback)252     int32_t RegisterAudioPolicyServerDiedCb(const int32_t clientPid,
253         const std::shared_ptr<AudioCapturerPolicyServiceDiedCallback> &callback) override
254     {
255         return sharedAudioCapturer_->RegisterAudioPolicyServerDiedCb(clientPid, callback);
256     }
257 
GetAudioTimestampInfo(Timestamp & timestamp,Timestamp::Timestampbase base)258     int32_t GetAudioTimestampInfo(Timestamp &timestamp, Timestamp::Timestampbase base) const override
259     {
260         return sharedAudioCapturer_->GetAudioTimestampInfo(timestamp, base);
261     }
262 
263     ~SharedCapturerWrapper() override = default;
264 
265     SharedCapturerWrapper(const SharedCapturerWrapper&) = delete;
266     SharedCapturerWrapper(SharedCapturerWrapper&&) = delete;
267     SharedCapturerWrapper& operator=(const SharedCapturerWrapper&) = delete;
268     SharedCapturerWrapper& operator=(SharedCapturerWrapper&&) = delete;
269 private:
270     std::shared_ptr<AudioCapturer> sharedAudioCapturer_;
271 };
272 }  // namespace AudioStandard
273 }  // namespace OHOS
274 #endif // SHARED_AUDIO_CAPTURER_WRAPPER_H