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 HCODEC_TESTER_CODECBASE_H 17 #define HCODEC_TESTER_CODECBASE_H 18 19 #include "tester_common.h" 20 #include "codecbase.h" 21 22 namespace OHOS::MediaAVCodec { 23 struct TesterCodecBase : TesterCommon { TesterCodecBaseTesterCodecBase24 explicit TesterCodecBase(const CommandOpt& opt) : TesterCommon(opt) {} 25 26 protected: 27 bool Create() override; 28 bool SetCallback() override; 29 bool GetInputFormat() override; 30 bool GetOutputFormat() override; 31 bool Start() override; 32 bool Stop() override; 33 bool Release() override; 34 bool Flush() override; 35 void ClearAllBuffer() override; 36 bool WaitForInput(BufInfo& buf) override; 37 bool WaitForOutput(BufInfo& buf) override; 38 bool ReturnInput(const BufInfo& buf) override; 39 bool ReturnOutput(uint32_t idx) override; 40 void EnableHighPerf(Format& fmt) const; 41 42 bool ConfigureEncoder() override; 43 bool SetEncoderParameter(const SetParameterParams& param) override; 44 bool SetEncoderPerFrameParam(BufInfo& buf, const PerFrameParams& param) override; 45 sptr<Surface> CreateInputSurface() override; 46 bool NotifyEos() override; 47 bool RequestIDR() override; 48 std::optional<uint32_t> GetInputStride() override; 49 50 bool SetOutputSurface(sptr<Surface>& surface) override; 51 bool ConfigureDecoder() override; 52 53 struct CallBack : public MediaCodecCallback { CallBackTesterCodecBase::CallBack54 explicit CallBack(TesterCodecBase* tester) : tester_(tester) {} 55 ~CallBack() override = default; 56 void OnError(AVCodecErrorType errorType, int32_t errorCode) override; 57 void OnOutputFormatChanged(const Format &format) override; 58 void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override; 59 void OnOutputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override; 60 private: 61 TesterCodecBase* tester_; 62 }; 63 64 std::shared_ptr<CodecBase> codec_; 65 std::list<std::pair<uint32_t, std::shared_ptr<AVBuffer>>> inputList_; 66 std::list<std::pair<uint32_t, std::shared_ptr<AVBuffer>>> outputList_; 67 68 Format inputFmt_; 69 }; 70 } 71 #endif