• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 #ifndef AUDIO_CAPTURE_AS_IMPL_H
17 #define AUDIO_CAPTURE_AS_IMPL_H
18 
19 #include <mutex>
20 #include "audio_capture.h"
21 #include "audio_capturer.h"
22 #include "nocopyable.h"
23 
24 namespace OHOS {
25 namespace Media {
26 class AudioCaptureAsImpl : public AudioCapture, public NoCopyable {
27 public:
28     AudioCaptureAsImpl();
29     virtual ~AudioCaptureAsImpl();
30 
31     int32_t SetCaptureParameter(uint32_t bitrate, uint32_t channels, uint32_t sampleRate) override;
32     int32_t GetCaptureParameter(uint32_t &bitrate, uint32_t &channels, uint32_t &sampleRate) override;
33     int32_t GetSegmentInfo(uint64_t &start) override;
34     int32_t StartAudioCapture() override;
35     int32_t StopAudioCapture() override;
36     int32_t PauseAudioCapture() override;
37     int32_t ResumeAudioCapture() override;
38     std::shared_ptr<AudioBuffer> GetBuffer() override;
39 
40 private:
41     std::unique_ptr<OHOS::AudioStandard::AudioCapturer> audioCapturer_ = nullptr;
42     size_t bufferSize_ = 0; // minimum size of each buffer acquired from AudioServer
43     uint64_t bufferDurationNs_ = 0; // each buffer
44     uint64_t timestamp_ = 0;
45     uint64_t pausedTime_ = 0; // the timestamp when audio pause called
46     uint64_t resumeTime_ = 0; // the timestamp when audio resume called
47     uint32_t pausedCount_ = 0; // the paused count times
48     uint64_t persistTime_ = 0;
49     uint64_t totalPauseTime_ = 0;
50     bool isResume_ = false;
51     bool isPause_ = false;
52     std::mutex pauseMutex_;
53 };
54 } // namespace Media
55 } // namespace OHOS
56 
57 #endif // AUDIO_CAPTURE_AS_IMPL_H
58