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 "audio_deferred_process.h" 24 #include <atomic> 25 #include <cstdint> 26 27 namespace OHOS { 28 namespace CameraStandard { 29 using namespace AudioStandard; 30 using namespace std::chrono; 31 using namespace DeferredProcessing; 32 constexpr uint32_t DEFAULT_AUDIO_CACHE_NUMBER = 400; 33 class AudioCapturerSession : public RefBase, public std::enable_shared_from_this<AudioCapturerSession> { 34 public: 35 explicit AudioCapturerSession(); 36 ~AudioCapturerSession(); 37 bool StartAudioCapture(); 38 void ProcessAudioBuffer(); 39 void Stop(); 40 void Release(); 41 void GetAudioRecords(int64_t startTime, int64_t endTime, vector<sptr<AudioRecord>> &audioRecords); 42 sptr<AudioDeferredProcess> GetAudioDeferredProcess(); 43 AudioChannel getMicNum(); 44 45 private: 46 bool CreateAudioCapturer(); 47 // Already guard by hcapture_session 48 std::unique_ptr<AudioCapturer> audioCapturer_ = nullptr; 49 BlockingQueue<sptr<AudioRecord>> audioBufferQueue_; 50 std::atomic<bool> startAudioCapture_ { false }; 51 std::unique_ptr<std::thread> audioThread_ = nullptr; 52 sptr<AudioDeferredProcess> audioDeferredProcess_ = nullptr; 53 }; 54 } // CameraStandard 55 } // OHOS 56 #endif // AUDIO_CAPTURER_SESSION_H