1 /*
2 * Copyright (c) 2020-2021 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 #include "audio_capturer.h"
17 #include "audio_capturer_client.h"
18 #include "media_log.h"
19
20 namespace OHOS {
21 namespace Audio {
22 #define CHK_NULL_RETURN(ptr, ret) \
23 do { \
24 if ((ptr) == nullptr) { \
25 MEDIA_ERR_LOG("ptr null"); \
26 return (ret); \
27 } \
28 } while (0)
29
AudioCapturer()30 AudioCapturer::AudioCapturer()
31 : impl_(new(std::nothrow) AudioCapturerClient())
32 {
33 }
34
~AudioCapturer()35 AudioCapturer::~AudioCapturer()
36 {
37 }
38
GetMinFrameCount(int32_t sampleRate,int32_t channelCount,AudioCodecFormat audioFormat,size_t & frameCount)39 bool AudioCapturer::GetMinFrameCount(int32_t sampleRate, int32_t channelCount, AudioCodecFormat audioFormat,
40 size_t &frameCount)
41 {
42 return AudioCapturerClient::GetMinFrameCount(sampleRate, channelCount, audioFormat, frameCount);
43 }
44
GetFrameCount()45 uint64_t AudioCapturer::GetFrameCount()
46 {
47 CHK_NULL_RETURN(impl_, 0);
48 return impl_->GetFrameCount();
49 }
50
GetStatus()51 State AudioCapturer::GetStatus()
52 {
53 CHK_NULL_RETURN(impl_, INITIALIZED);
54 return impl_->GetStatus();
55 }
56
GetAudioTime(Timestamp & timestamp,Timestamp::Timebase base)57 bool AudioCapturer::GetAudioTime(Timestamp ×tamp, Timestamp::Timebase base)
58 {
59 CHK_NULL_RETURN(impl_, false);
60 return impl_->GetAudioTime(timestamp, base);
61 }
62
SetCapturerInfo(const AudioCapturerInfo info)63 int32_t AudioCapturer::SetCapturerInfo(const AudioCapturerInfo info)
64 {
65 CHK_NULL_RETURN(impl_, -1);
66 return impl_->SetCapturerInfo(info);
67 }
68
GetCapturerInfo(AudioCapturerInfo & info)69 int32_t AudioCapturer::GetCapturerInfo(AudioCapturerInfo &info)
70 {
71 CHK_NULL_RETURN(impl_, -1);
72 return impl_->GetCapturerInfo(info);
73 }
74
Start()75 bool AudioCapturer::Start()
76 {
77 CHK_NULL_RETURN(impl_, false);
78 return impl_->Start();
79 }
80
Stop()81 bool AudioCapturer::Stop()
82 {
83 CHK_NULL_RETURN(impl_, false);
84 return impl_->Stop();
85 }
86
Release()87 bool AudioCapturer::Release()
88 {
89 CHK_NULL_RETURN(impl_, false);
90 return impl_->Release();
91 }
92
Read(uint8_t * buffer,size_t userSize,bool isBlockingRead)93 int32_t AudioCapturer::Read(uint8_t *buffer, size_t userSize, bool isBlockingRead)
94 {
95 CHK_NULL_RETURN(impl_, -1);
96 return impl_->Read(buffer, userSize, isBlockingRead);
97 }
98
99 } // namespace Audio
100 } // namespace OHOS
101