• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     std::optional<uint32_t> GetInputIndex(Span& span) override;
37     bool QueueInput(uint32_t idx, OH_AVCodecBufferAttr attr) override;
38     std::optional<uint32_t> GetOutputIndex() override;
39     bool ReturnOutput(uint32_t idx) override;
40 
41     bool ConfigureEncoder() override;
42     bool CreateInputSurface() override;
43     bool NotifyEos() override;
44     bool RequestIDR() override;
45     std::optional<uint32_t> GetInputStride() override;
46 
47     bool SetOutputSurface(sptr<Surface>& surface) override;
48     bool ConfigureDecoder() override;
49 
50     struct CallBack : public AVCodecCallback {
CallBackTesterCodecBase::CallBack51         explicit CallBack(TesterCodecBase* tester) : tester_(tester) {}
52         ~CallBack() override = default;
53         void OnError(AVCodecErrorType errorType, int32_t errorCode) override;
54         void OnOutputFormatChanged(const Format &format) override;
55         void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVSharedMemory> buffer) override;
56         void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag,
57             std::shared_ptr<AVSharedMemory> buffer) override;
58     private:
59         TesterCodecBase* tester_;
60     };
61 
62     std::shared_ptr<CodecBase> codec_;
63     std::list<std::pair<uint32_t, std::shared_ptr<AVSharedMemory>>> inputList_;
64     std::list<std::tuple<uint32_t, AVCodecBufferInfo, AVCodecBufferFlag, std::shared_ptr<AVSharedMemory>>> outputList_;
65 
66     Format inputFmt_;
67 };
68 }
69 #endif