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 static constexpr int32_t ONE_THOUSAND = 1000; 33 static constexpr int32_t DURATION_EACH_AUDIO_FRAME = 32; 34 static constexpr int32_t PROCESS_BATCH_SIZE = 5; 35 static constexpr int32_t MAX_UNPROCESSED_SIZE = 12288; 36 static constexpr int32_t MAX_PROCESSED_SIZE = 2048; 37 38 explicit AudioDeferredProcess(); 39 ~AudioDeferredProcess(); 40 41 void StoreOptions(const AudioStreamInfo& inputOptions, const AudioStreamInfo& outputOptions); 42 int32_t ConfigOfflineAudioEffectChain(); 43 int32_t PrepareOfflineAudioEffectChain(); 44 int32_t GetMaxBufferSize(const AudioStreamInfo& inputOption, const AudioStreamInfo& outputOption); 45 int32_t GetOfflineEffectChain(); 46 uint32_t GetOneUnprocessedSize(); 47 void FadeOneBatch(std::array<uint8_t, MAX_PROCESSED_SIZE * PROCESS_BATCH_SIZE>& processedArr); 48 void EffectChainProcess(std::array<uint8_t, MAX_UNPROCESSED_SIZE * PROCESS_BATCH_SIZE>& rawArr, 49 std::array<uint8_t, MAX_PROCESSED_SIZE * PROCESS_BATCH_SIZE>& processedArr); 50 void ReturnToRecords(std::array<uint8_t, MAX_PROCESSED_SIZE * PROCESS_BATCH_SIZE>& processedArr, 51 vector<sptr<AudioRecord>>& processedRecords, uint32_t i, uint32_t batchSize); 52 int32_t Process(vector<sptr<AudioRecord>>& audioRecords, vector<sptr<AudioRecord>>& processedRecords); 53 void Release(); 54 55 private: 56 std::string chainName_ = "offline_record_algo"; 57 std::mutex mutex_; 58 std::unique_ptr<OfflineAudioEffectManager> offlineAudioEffectManager_ = nullptr; 59 std::unique_ptr<OfflineAudioEffectChain> offlineEffectChain_ = nullptr; 60 AudioStreamInfo inputOptions_; 61 AudioStreamInfo outputOptions_; 62 uint32_t oneUnprocessedSize_ = 0; 63 uint32_t oneProcessedSize_ = 0; 64 }; 65 } // CameraStandard 66 } // OHOS 67 #endif // AVCODEC_AUDIO_PRE_PROCESS_H