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 VDecSignal *signal_; 56 const uint8_t *fuzzData; 57 size_t fuzzSize; 58 int32_t sendFrameIndex; 59 protected: 60 std::shared_ptr<CodecBase> codec_; 61 std::atomic<bool> isRunning_ { false }; 62 std::unique_ptr<std::thread> inputLoop_; 63 struct CallBack : public MediaCodecCallback { CallBackCallBack64 explicit CallBack(VDecServerSample* tester) : tester(tester) {} 65 ~CallBack() override = default; 66 void OnError(AVCodecErrorType errorType, int32_t errorCode) override; 67 void OnOutputFormatChanged(const Format &format) override; 68 void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override; 69 void OnOutputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override; 70 private: 71 VDecServerSample* tester; 72 }; 73 }; 74 } // namespace Media 75 } // namespace OHOS 76 77 #endif // SERVERDEC_SAMPLE_H 78