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_CAPI_H
17 #define HCODEC_TESTER_CAPI_H
18 
19 #include "tester_common.h"
20 
21 namespace OHOS::MediaAVCodec {
22 struct TesterCapi : TesterCommon {
TesterCapiTesterCapi23     explicit TesterCapi(const CommandOpt& opt) : TesterCommon(opt) {}
24 
25 protected:
26     bool Create() override;
27     bool GetInputFormat() override;
28     bool GetOutputFormat() override;
29     bool Start() override;
30     bool Stop() override;
31     bool Release() override;
32     bool Flush() override;
33 
34     bool ConfigureEncoder() override;
35     sptr<Surface> CreateInputSurface() override;
36     bool NotifyEos() override;
37     bool RequestIDR() override;
38     std::optional<uint32_t> GetInputStride() override;
39 
40     bool SetOutputSurface(sptr<Surface>& surface) override;
41     bool ConfigureDecoder() override;
42 
43     static void OnError(OH_AVCodec *codec, int32_t errorCode, void *userData);
44     static void OnStreamChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData);
45 
46     OH_AVCodec *codec_ = nullptr;
47     std::shared_ptr<OH_AVFormat> inputFmt_;
48     int32_t inputStride_ = -1;
49 };
50 
51 struct TesterCapiOld : TesterCapi {
TesterCapiOldTesterCapiOld52     explicit TesterCapiOld(const CommandOpt& opt) : TesterCapi(opt) {}
53 
54 private:
55     static void OnNeedInputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData);
56     static void OnNewOutputData(
57         OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, OH_AVCodecBufferAttr *attr, void *userData);
58 
59     bool SetCallback() override;
60     void ClearAllBuffer() override;
61     bool WaitForInput(BufInfo& buf) override;
62     bool WaitForOutput(BufInfo& buf) override;
63     bool ReturnInput(const BufInfo& buf) override;
64     bool ReturnOutput(uint32_t idx) override;
65 
66     std::list<std::pair<uint32_t, OH_AVMemory*>> inputList_;
67     std::list<std::tuple<uint32_t, OH_AVMemory*, OH_AVCodecBufferAttr>> outputList_;
68 };
69 
70 struct TesterCapiNew : TesterCapi {
TesterCapiNewTesterCapiNew71     explicit TesterCapiNew(const CommandOpt& opt) : TesterCapi(opt) {}
72 
73 private:
74     static void OnNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData);
75     static void OnNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData);
76 
77     bool SetCallback() override;
78     void ClearAllBuffer() override;
79     bool WaitForInput(BufInfo& buf) override;
80     bool WaitForOutput(BufInfo& buf) override;
81     bool ReturnInput(const BufInfo& buf) override;
82     bool ReturnOutput(uint32_t idx) override;
83 
84     std::list<std::pair<uint32_t, OH_AVBuffer*>> inputList_;
85     std::list<std::pair<uint32_t, OH_AVBuffer*>> outputList_;
86 };
87 }
88 #endif