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