• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef HPAE_CAPTURER_STREAM_IMPL_H
17 #define HPAE_CAPTURER_STREAM_IMPL_H
18 
19 #include <shared_mutex>
20 #include "i_capturer_stream.h"
21 
22 namespace OHOS {
23 namespace AudioStandard {
24 class HpaeCapturerStreamImpl : public std::enable_shared_from_this<HpaeCapturerStreamImpl>,
25                                public IStreamStatusCallback,
26                                public ICapturerStreamCallback,
27                                public ICapturerStream {
28 public:
29     HpaeCapturerStreamImpl(AudioProcessConfig processConfig);
30     ~HpaeCapturerStreamImpl();
31     int32_t InitParams(const std::string &deviceName = "");
32     int32_t Start() override;
33     int32_t Pause(bool isStandby = false) override;
34     int32_t Flush() override;
35     int32_t Drain(bool stopFlag = false) override { return 0; };
36     int32_t Stop() override;
37     int32_t Release() override;
38     int32_t GetStreamFramesRead(uint64_t &framesRead) override;
39     int32_t GetCurrentTimeStamp(uint64_t &timestamp) override;
40     int32_t GetLatency(uint64_t &latency) override;
41 
42     void RegisterStatusCallback(const std::weak_ptr<IStatusCallback> &callback) override;
43     void RegisterReadCallback(const std::weak_ptr<IReadCallback> &callback) override;
44     BufferDesc DequeueBuffer(size_t length) override;
45     int32_t EnqueueBuffer(const BufferDesc &bufferDesc) override;
46     int32_t GetMinimumBufferSize(size_t &minBufferSize) const override;
47     void GetByteSizePerFrame(size_t &byteSizePerFrame) const override;
48     void GetSpanSizePerFrame(size_t &spanSizeInFrame) const override;
49     void SetStreamIndex(uint32_t index) override;
50     uint32_t GetStreamIndex() override;
51     int32_t DropBuffer() override;
52     void AbortCallback(int32_t abortTimes);
53     int32_t OnStreamData(AudioCallBackCapturerStreamInfo &callBackStreamInfo) override;
54     void OnStatusUpdate(IOperation operation, uint32_t streamIndex) override;
55 
56 private:
57 
58     uint32_t streamIndex_ = static_cast<uint32_t>(-1); // invalid index
59 
60     AudioProcessConfig processConfig_ = {};
61     std::weak_ptr<IStatusCallback> statusCallback_;
62     std::weak_ptr<IReadCallback> readCallback_;
63     State state_ = INVALID;
64 
65     size_t byteSizePerFrame_ = 0;
66     size_t spanSizeInFrame_ = 0;
67     size_t minBufferSize_ = 0;
68 
69     size_t totalBytesRead_ = 0;
70 
71     FILE *capturerServerDumpFile_ = nullptr;
72 
73     // Only for debug
74     int32_t abortFlag_ = 0;
75 
76     uint32_t capturerId_ = 0;
77 
78     std::shared_mutex latencyMutex_;
79     uint64_t framesRead_ = 0;
80     uint64_t timestamp_ = 0;
81     uint64_t latency_ = 0;
82 };
83 } // namespace AudioStandard
84 } // namespace OHOS
85 #endif // hpae_capturer_stream_impl_H
86