• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #ifndef AUDIO_CAPTURER_CLIENT_H
16 #define AUDIO_CAPTURER_CLIENT_H
17 
18 #include <mutex>
19 #include "audio_capturer.h"
20 #include "iproxy_client.h"
21 #include "media_info.h"
22 #include "surface.h"
23 
24 using OHOS::Surface;
25 using std::mutex;
26 using OHOS::SurfaceBuffer;
27 using OHOS::IBufferConsumerListener;
28 using OHOS::Audio::Timestamp;
29 using OHOS::Audio::AudioCapturerInfo;
30 
31 namespace OHOS {
32 namespace Audio {
33 class AudioCapturer::AudioCapturerClient : public IBufferConsumerListener {
34 public:
35     AudioCapturerClient();
36     ~AudioCapturerClient();
37     static bool GetMinFrameCount(int32_t sampleRate, int32_t channelCount, AudioCodecFormat audioFormat,
38                                 size_t &frameCount);
39     uint64_t GetFrameCount();
40     int32_t SetCapturerInfo(const AudioCapturerInfo info);
41     int32_t GetCapturerInfo(AudioCapturerInfo &info);
42     bool Start();
43     int32_t Read(uint8_t *buffer, size_t userSize, bool isBlockingRead);
44     State GetStatus();
45     bool GetAudioTime(Timestamp &timestamp, Timestamp::Timebase base);
46     bool Stop();
47     bool Release();
48     void OnBufferAvailable() override;
49     static AudioCapturerClient *GetInstance();
50 
51 private:
52     bool InitAudioCapturerClient();
53     IClientProxy *GetIClientProxy();
54     int32_t InitSurface(void);
55     void ReleaseAllBuffer();
56 
57     SvcIdentity sid_;
58     IClientProxy *proxy_ = nullptr;
59     std::shared_ptr<Surface> surface_;
60     std::mutex lock_;
61     Timestamp curTimestamp_;
62     bool timeStampValid_ = false;
63 };
64 }  // namespace Audio
65 }  // namespace OHOS
66 #endif // AUDIO_CAPTURER_CLIENT_H
67