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 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 "hevc_decoder.h" 30 #include "codecbase.h" 31 namespace OHOS { 32 namespace MediaAVCodec { 33 34 class VDecSignal { 35 public: 36 std::mutex inMutex_; 37 std::condition_variable inCond_; 38 std::queue<uint32_t> inIdxQueue_; 39 std::queue<std::shared_ptr<AVBuffer>> inBufferQueue_; 40 }; 41 42 class VDecServerSample : public NoCopyable { 43 public: 44 VDecServerSample() = default; 45 ~VDecServerSample(); 46 47 void RunVideoServerDecoder(); 48 int32_t ConfigServerDecoder(); 49 int32_t SetCallback(); 50 void GetOutputFormat(); 51 void Flush(); 52 void Reset(); 53 void InputFunc(); 54 void WaitForEos(); 55 int32_t kWidth = 1920; 56 int32_t kHeight = 1080; 57 int32_t kFormat = 2; 58 int32_t kFormatRate = 30; 59 int32_t kRotation = 0; 60 int32_t kAngle = 0; 61 VDecSignal *signal_; 62 const uint8_t *fuzzData = nullptr; 63 size_t fuzzSize = 0; 64 int32_t sendFrameIndex; 65 protected: 66 std::shared_ptr<CodecBase> codec_; 67 std::atomic<bool> isRunning_ { false }; 68 std::unique_ptr<std::thread> inputLoop_; 69 struct CallBack : public MediaCodecCallback { CallBackCallBack70 explicit CallBack(VDecServerSample* tester) : tester(tester) {} 71 ~CallBack() override = default; 72 void OnError(AVCodecErrorType errorType, int32_t errorCode) override; 73 void OnOutputFormatChanged(const Format &format) override; 74 void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override; 75 void OnOutputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override; 76 private: 77 VDecServerSample* tester; 78 }; 79 }; 80 } // namespace Media 81 } // namespace OHOS 82 83 #endif // SERVERDEC_SAMPLE_H 84