1 /* 2 * Copyright (c) 2024-2024 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_CAPTURER_SESSION_H 17 #define AUDIO_CAPTURER_SESSION_H 18 19 #include "audio_capturer.h" 20 #include "blocking_queue.h" 21 #include "refbase.h" 22 #include "audio_record.h" 23 #include <atomic> 24 #include <cstdint> 25 26 namespace OHOS { 27 namespace CameraStandard { 28 using namespace AudioStandard; 29 using namespace std::chrono; 30 using namespace DeferredProcessing; 31 constexpr uint32_t DEFAULT_AUDIO_CACHE_NUMBER = 200; 32 class AudioCapturerSession : public RefBase, public std::enable_shared_from_this<AudioCapturerSession> { 33 public: 34 explicit AudioCapturerSession(); 35 ~AudioCapturerSession(); 36 bool StartAudioCapture(); 37 void ProcessAudioBuffer(); 38 void Stop(); 39 void Release(); 40 void GetAudioRecords(int64_t startTime, int64_t endTime, vector<sptr<AudioRecord>> &audioRecords); 41 42 private: 43 bool CreateAudioCapturer(); 44 // Already guard by hcapture_session 45 std::unique_ptr<AudioCapturer> audioCapturer_ = nullptr; 46 BlockingQueue<sptr<AudioRecord>> audioBufferQueue_; 47 std::atomic<bool> startAudioCapture_ { false }; 48 std::unique_ptr<std::thread> audioThread_ = nullptr; 49 }; 50 } // CameraStandard 51 } // OHOS 52 #endif // AUDIO_CAPTURER_SESSION_H