1 /*
2 * Copyright (c) 2022-2023 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 "media_log.h"
18
19 namespace OHOS {
20 namespace Audio {
AudioCapturerClient()21 AudioCapturer::AudioCapturerClient::AudioCapturerClient()
22 : impl_(new(std::nothrow) AudioCapturerImpl())
23 {
24 }
25
~AudioCapturerClient()26 AudioCapturer::AudioCapturerClient::~AudioCapturerClient()
27 {
28 if (impl_ != nullptr) {
29 impl_.reset();
30 impl_ = nullptr;
31 }
32 MEDIA_DEBUG_LOG("ctor");
33 }
34
GetMinFrameCount(int32_t sampleRate,int32_t channelCount,AudioCodecFormat audioFormat,size_t & frameCount)35 bool AudioCapturer::AudioCapturerClient::GetMinFrameCount(int32_t sampleRate, int32_t channelCount,
36 AudioCodecFormat audioFormat, size_t &frameCount)
37 {
38 return AudioCapturerImpl::GetMinFrameCount(sampleRate, channelCount, audioFormat, frameCount);
39 }
40
GetFrameCount()41 uint64_t AudioCapturer::AudioCapturerClient::GetFrameCount()
42 {
43 if (impl_ == nullptr) {
44 MEDIA_ERR_LOG("impl_ null");
45 return 0;
46 }
47 return impl_->GetFrameCount();
48 }
49
GetStatus()50 State AudioCapturer::AudioCapturerClient::GetStatus()
51 {
52 if (impl_ == nullptr) {
53 MEDIA_ERR_LOG("impl_ null");
54 return INITIALIZED;
55 }
56 return impl_->GetStatus();
57 }
58
GetAudioTime(Timestamp & timestamp,Timestamp::Timebase base)59 bool AudioCapturer::AudioCapturerClient::GetAudioTime(Timestamp ×tamp, Timestamp::Timebase base)
60 {
61 if (impl_ == nullptr) {
62 MEDIA_ERR_LOG("impl_ null");
63 return false;
64 }
65 return impl_->GetTimestamp(timestamp, base);
66 }
67
SetCapturerInfo(const AudioCapturerInfo info)68 int32_t AudioCapturer::AudioCapturerClient::SetCapturerInfo(const AudioCapturerInfo info)
69 {
70 if (impl_ == nullptr) {
71 MEDIA_ERR_LOG("impl_ null");
72 return -1;
73 }
74 return impl_->SetCapturerInfo(info);
75 }
76
GetCapturerInfo(AudioCapturerInfo & info)77 int32_t AudioCapturer::AudioCapturerClient::GetCapturerInfo(AudioCapturerInfo &info)
78 {
79 if (impl_ == nullptr) {
80 MEDIA_ERR_LOG("impl_ null");
81 return -1;
82 }
83 return impl_->GetCapturerInfo(info);
84 }
85
Start()86 bool AudioCapturer::AudioCapturerClient::Start()
87 {
88 if (impl_ == nullptr) {
89 MEDIA_ERR_LOG("impl_ null");
90 return false;
91 }
92 return impl_->Record();
93 }
94
Stop()95 bool AudioCapturer::AudioCapturerClient::Stop()
96 {
97 if (impl_ == nullptr) {
98 MEDIA_ERR_LOG("impl_ null");
99 return false;
100 }
101 return impl_->Stop();
102 }
103
Release()104 bool AudioCapturer::AudioCapturerClient::Release()
105 {
106 if (impl_ == nullptr) {
107 MEDIA_ERR_LOG("impl_ null");
108 return false;
109 }
110 return impl_->Release();
111 }
112
Read(uint8_t * buffer,size_t userSize,bool isBlockingRead)113 int32_t AudioCapturer::AudioCapturerClient::Read(uint8_t *buffer, size_t userSize, bool isBlockingRead)
114 {
115 if (impl_ == nullptr) {
116 MEDIA_ERR_LOG("impl_ null");
117 return -1;
118 }
119 return impl_->Read(buffer, userSize, isBlockingRead);
120 }
121 } // namespace Audio
122 } // namespace OHOS
123