146f34cbfSopenharmony_ci/* 246f34cbfSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 346f34cbfSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 446f34cbfSopenharmony_ci * you may not use this file except in compliance with the License. 546f34cbfSopenharmony_ci * You may obtain a copy of the License at 646f34cbfSopenharmony_ci * 746f34cbfSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 846f34cbfSopenharmony_ci * 946f34cbfSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1046f34cbfSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1146f34cbfSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1246f34cbfSopenharmony_ci * See the License for the specific language governing permissions and 1346f34cbfSopenharmony_ci * limitations under the License. 1446f34cbfSopenharmony_ci */ 1546f34cbfSopenharmony_ci 1646f34cbfSopenharmony_ci#ifndef OH_AUDIO_CAPTURER_H 1746f34cbfSopenharmony_ci#define OH_AUDIO_CAPTURER_H 1846f34cbfSopenharmony_ci 1946f34cbfSopenharmony_ci#include "native_audiocapturer.h" 2046f34cbfSopenharmony_ci#include "audio_capturer.h" 2146f34cbfSopenharmony_ci#include "audio_common_log.h" 2246f34cbfSopenharmony_ci 2346f34cbfSopenharmony_cinamespace OHOS { 2446f34cbfSopenharmony_cinamespace AudioStandard { 2546f34cbfSopenharmony_ciclass OHAudioCapturerModeCallback : public AudioCapturerReadCallback { 2646f34cbfSopenharmony_cipublic: 2746f34cbfSopenharmony_ci OHAudioCapturerModeCallback(OH_AudioCapturer_Callbacks callbacks, OH_AudioCapturer* audioCapturer, void* userData) 2846f34cbfSopenharmony_ci : callbacks_(callbacks), ohAudioCapturer_(audioCapturer), userData_(userData) 2946f34cbfSopenharmony_ci { 3046f34cbfSopenharmony_ci } 3146f34cbfSopenharmony_ci 3246f34cbfSopenharmony_ci void OnReadData(size_t length) override; 3346f34cbfSopenharmony_ciprivate: 3446f34cbfSopenharmony_ci OH_AudioCapturer_Callbacks callbacks_; 3546f34cbfSopenharmony_ci OH_AudioCapturer* ohAudioCapturer_; 3646f34cbfSopenharmony_ci void* userData_; 3746f34cbfSopenharmony_ci}; 3846f34cbfSopenharmony_ci 3946f34cbfSopenharmony_ciclass OHAudioCapturerCallback : public AudioCapturerCallback { 4046f34cbfSopenharmony_cipublic: 4146f34cbfSopenharmony_ci OHAudioCapturerCallback(OH_AudioCapturer_Callbacks callbacks, OH_AudioCapturer* audioCapturer, void* userData) 4246f34cbfSopenharmony_ci : callbacks_(callbacks), ohAudioCapturer_(audioCapturer), userData_(userData) 4346f34cbfSopenharmony_ci { 4446f34cbfSopenharmony_ci } 4546f34cbfSopenharmony_ci 4646f34cbfSopenharmony_ci void OnInterrupt(const InterruptEvent &interruptEvent) override; 4746f34cbfSopenharmony_ci 4846f34cbfSopenharmony_ci void OnStateChange(const CapturerState state) override 4946f34cbfSopenharmony_ci { 5046f34cbfSopenharmony_ci AUDIO_DEBUG_LOG("OHAudioCapturerCallback:: OnStateChange"); 5146f34cbfSopenharmony_ci } 5246f34cbfSopenharmony_ci 5346f34cbfSopenharmony_ciprivate: 5446f34cbfSopenharmony_ci OH_AudioCapturer_Callbacks callbacks_; 5546f34cbfSopenharmony_ci OH_AudioCapturer* ohAudioCapturer_; 5646f34cbfSopenharmony_ci void* userData_; 5746f34cbfSopenharmony_ci}; 5846f34cbfSopenharmony_ci 5946f34cbfSopenharmony_ciclass OHAudioCapturer { 6046f34cbfSopenharmony_ci public: 6146f34cbfSopenharmony_ci OHAudioCapturer(); 6246f34cbfSopenharmony_ci ~OHAudioCapturer(); 6346f34cbfSopenharmony_ci 6446f34cbfSopenharmony_ci bool Initialize(const AudioCapturerOptions& capturerOptions); 6546f34cbfSopenharmony_ci bool Start(); 6646f34cbfSopenharmony_ci bool Pause(); 6746f34cbfSopenharmony_ci bool Stop(); 6846f34cbfSopenharmony_ci bool Flush(); 6946f34cbfSopenharmony_ci bool Release(); 7046f34cbfSopenharmony_ci CapturerState GetCurrentState(); 7146f34cbfSopenharmony_ci void GetStreamId(uint32_t& streamId); 7246f34cbfSopenharmony_ci AudioChannel GetChannelCount(); 7346f34cbfSopenharmony_ci int32_t GetSamplingRate(); 7446f34cbfSopenharmony_ci AudioEncodingType GetEncodingType(); 7546f34cbfSopenharmony_ci AudioSampleFormat GetSampleFormat(); 7646f34cbfSopenharmony_ci void GetCapturerInfo(AudioCapturerInfo& capturerInfo); 7746f34cbfSopenharmony_ci int64_t GetFramesRead(); 7846f34cbfSopenharmony_ci bool GetAudioTime(Timestamp ×tamp, Timestamp::Timestampbase base); 7946f34cbfSopenharmony_ci int32_t GetFrameSizeInCallback(); 8046f34cbfSopenharmony_ci int32_t GetBufferDesc(BufferDesc &bufDesc) const; 8146f34cbfSopenharmony_ci int32_t Enqueue(const BufferDesc &bufDesc) const; 8246f34cbfSopenharmony_ci uint32_t GetOverflowCount() const; 8346f34cbfSopenharmony_ci 8446f34cbfSopenharmony_ci void SetCapturerCallback(OH_AudioCapturer_Callbacks callbacks, void* userData); 8546f34cbfSopenharmony_ci 8646f34cbfSopenharmony_ci private: 8746f34cbfSopenharmony_ci std::unique_ptr<AudioCapturer> audioCapturer_; 8846f34cbfSopenharmony_ci std::shared_ptr<AudioCapturerCallback> audioCapturerCallback_; 8946f34cbfSopenharmony_ci}; 9046f34cbfSopenharmony_ci} // namespace AudioStandard 9146f34cbfSopenharmony_ci} // namespace OHOS 9246f34cbfSopenharmony_ci 9346f34cbfSopenharmony_ci#endif // OH_AUDIO_CAPTURER_H 94