1 /* 2 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 OHOS_SHARING_AUDIO_SOURCE_CAPTURE_H 17 #define OHOS_SHARING_AUDIO_SOURCE_CAPTURE_H 18 19 #include <iostream> 20 #include <mutex> 21 #include <queue> 22 #include "audio_aac_codec.h" 23 #include "audio_capturer.h" 24 25 namespace OHOS { 26 namespace Sharing { 27 28 class AudioSourceCapturer : public std::enable_shared_from_this<AudioSourceCapturer> { 29 public: AudioSourceCapturer(std::shared_ptr<AudioEncoder> audioEncoder)30 explicit AudioSourceCapturer(std::shared_ptr<AudioEncoder> audioEncoder) : audioEncoder_(audioEncoder) {} 31 ~AudioSourceCapturer(); 32 33 bool InitAudioCapture(); 34 bool StopAudioCapture(); 35 bool StartAudioCapture(); 36 void AudioCaptureThreadWorker(); 37 38 private: 39 size_t audioBufferLen_ = 0; 40 volatile bool isAudioCapturing_ = false; 41 std::shared_ptr<AudioEncoder> audioEncoder_ = nullptr; 42 std::unique_ptr<std::thread> audioCaptureThread_ = nullptr; 43 std::unique_ptr<AudioStandard::AudioCapturer> audioCapturer_ = nullptr; 44 }; 45 46 } // namespace Sharing 47 } // namespace OHOS 48 #endif 49