1 /* 2 * Copyright (C) 2023 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_AAC_ENCODER_DEMO_H 17 #define AVCODEC_AUDIO_AAC_ENCODER_DEMO_H 18 19 #include <atomic> 20 #include <condition_variable> 21 #include <fstream> 22 #include <queue> 23 #include <string> 24 #include <thread> 25 #include "nocopyable.h" 26 #include "native_avcodec_audioencoder.h" 27 28 namespace OHOS { 29 namespace MediaAVCodec { 30 namespace AudioAacDemo { 31 class AEncSignal { 32 public: 33 std::mutex inMutex_; 34 std::mutex outMutex_; 35 std::mutex startMutex_; 36 std::condition_variable inCond_; 37 std::condition_variable outCond_; 38 std::condition_variable startCond_; 39 std::queue<uint32_t> inQueue_; 40 std::queue<uint32_t> outQueue_; 41 std::queue<OH_AVMemory *> inBufferQueue_; 42 std::queue<OH_AVMemory *> outBufferQueue_; 43 std::queue<OH_AVCodecBufferAttr> attrQueue_; 44 }; 45 46 class AEncAacDemo : public NoCopyable { 47 public: 48 AEncAacDemo(); 49 virtual ~AEncAacDemo(); 50 void RunCase(); 51 52 private: 53 int32_t CreateEnc(); 54 int32_t Configure(OH_AVFormat *format); 55 int32_t Start(); 56 int32_t Stop(); 57 int32_t Flush(); 58 int32_t Reset(); 59 int32_t Release(); 60 void InputFunc(); 61 void OutputFunc(); 62 void HandleEOS(const uint32_t &index); 63 64 std::atomic<bool> isRunning_; 65 std::unique_ptr<std::ifstream> inputFile_; 66 std::unique_ptr<std::ofstream> outputFile_; 67 std::unique_ptr<std::thread> inputLoop_; 68 std::unique_ptr<std::thread> outputLoop_; 69 OH_AVCodec *audioEnc_; 70 AEncSignal *signal_; 71 struct OH_AVCodecAsyncCallback cb_; 72 bool isFirstFrame_ = true; 73 int64_t timeStamp_ = 0; 74 uint32_t frameCount_ = 0; 75 }; 76 } // namespace AudioAacDemo 77 } // namespace MediaAVCodec 78 } // namespace OHOS 79 #endif // AVCODEC_AUDIO_AAC_ENCODER_DEMO_H 80