1 /* 2 * Copyright (c) 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 AVCODEC_AUDIO_DEFERRED_PROCESS_H 17 #define AVCODEC_AUDIO_DEFERRED_PROCESS_H 18 19 #include "refbase.h" 20 #include "audio_capturer.h" 21 #include "audio_record.h" 22 #include "audio_session_manager.h" 23 #include "offline_audio_effect_manager.h" 24 #include <cstdint> 25 #include <mutex> 26 27 namespace OHOS { 28 namespace CameraStandard { 29 using namespace AudioStandard; 30 class AudioDeferredProcess : public RefBase { 31 public: 32 explicit AudioDeferredProcess(); 33 ~AudioDeferredProcess(); 34 35 int32_t ConfigOfflineAudioEffectChain(const AudioStreamInfo& inputOptions, const AudioStreamInfo& outputOptions); 36 int32_t PrepareOfflineAudioEffectChain(); 37 int32_t GetMaxBufferSize(const AudioStreamInfo& inputOption, const AudioStreamInfo& outputOption); 38 int32_t GetOfflineEffectChain(); 39 AudioSamplingRate GetOutputSampleRate(); 40 AudioChannel GetOutputChannelCount(); 41 uint32_t GetOneUnprocessedSize(); 42 int32_t Process(vector<sptr<AudioRecord>>& audioRecords, vector<sptr<AudioRecord>>& processedRecords); 43 void Release(); 44 45 static constexpr int32_t ONE_THOUSAND = 1000; 46 static constexpr int32_t DURATION_EACH_AUDIO_FRAME = 32; 47 static constexpr int32_t PROCESS_BATCH_SIZE = 5; 48 49 private: 50 std::string chainName_ = "offline_record_algo"; 51 std::mutex mutex_; 52 std::unique_ptr<OfflineAudioEffectManager> offlineAudioEffectManager_ = nullptr; 53 std::unique_ptr<OfflineAudioEffectChain> offlineEffectChain_ = nullptr; 54 uint32_t maxUnprocessedBufferSize_ = 0; 55 uint32_t maxProcessedBufferSize_ = 0; 56 AudioStreamInfo inputOptions_; 57 AudioStreamInfo outputOptions_; 58 uint32_t oneUnprocessedSize_ = 0; 59 uint32_t oneProcessedSize_ = 0; 60 }; 61 } // CameraStandard 62 } // OHOS 63 #endif // AVCODEC_AUDIO_PRE_PROCESS_H 64