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