1 /* 2 * Copyright (c) 2025 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 SERVERDEC_SAMPLE_H 17 #define SERVERDEC_SAMPLE_H 18 19 #include <atomic> 20 #include <cstdio> 21 #include <fstream> 22 #include <iostream> 23 #include <mutex> 24 #include <queue> 25 #include <string> 26 #include <thread> 27 #include <unistd.h> 28 #include <unordered_map> 29 #include "hcodec.h" 30 namespace OHOS { 31 namespace MediaAVCodec { 32 33 class VEncSignal { 34 public: 35 std::mutex inMutex_; 36 std::condition_variable inCond_; 37 std::queue<uint32_t> inIdxQueue_; 38 std::queue<std::shared_ptr<AVBuffer>> inBufferQueue_; 39 }; 40 41 class VEncServerSample : public NoCopyable { 42 public: 43 VEncServerSample() = default; 44 ~VEncServerSample(); 45 46 void RunVideoServerDecoder(); 47 int32_t ConfigServerDecoder(); 48 int32_t SetCallback(); 49 void GetOutputFormat(); 50 void Flush(); 51 void Reset(); 52 int32_t SetParameter(); 53 void InputFunc(); 54 void WaitForEos(); 55 VEncSignal *signal_; 56 const uint8_t *fuzzData; 57 size_t fuzzSize; 58 int sendFrameIndex = 0; 59 int32_t defaultWidth = 1920; 60 int32_t defaultHeight = 1080; 61 int32_t defaultFrameRate = 30; 62 int32_t defaultPixelFormat = 1; 63 int32_t frameIndex = 10; 64 protected: 65 std::shared_ptr<CodecBase> codec_; 66 std::atomic<bool> isRunning_ { false }; 67 std::unique_ptr<std::thread> inputLoop_; 68 struct CallBack : public MediaCodecCallback { CallBackCallBack69 explicit CallBack(VEncServerSample* tester) : tester(tester) {} 70 ~CallBack() override = default; 71 void OnError(AVCodecErrorType errorType, int32_t errorCode) override; 72 void OnOutputFormatChanged(const Format &format) override; 73 void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override; 74 void OnOutputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override; 75 private: 76 VEncServerSample* tester; 77 }; 78 }; 79 } // namespace Media 80 } // namespace OHOS 81 82 #endif // SERVERDEC_SAMPLE_H 83