• 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 VCODEC_MOCK_H
17 #define VCODEC_MOCK_H
18 
19 #include <string>
20 #include "avcodec_codec_name.h"
21 #include "avcodec_common.h"
22 #include "avcodec_errors.h"
23 #include "avcodec_info.h"
24 #include "avformat_mock.h"
25 #include "codeclist_mock.h"
26 #include "common_mock.h"
27 #include "iconsumer_surface.h"
28 #include "media_description.h"
29 #include "native_avcodec_base.h"
30 #include "nocopyable.h"
31 #include "surface/window.h"
32 #include "unittest_log.h"
33 
34 namespace OHOS {
35 namespace MediaAVCodec {
36 class VideoDecMock : public NoCopyable {
37 public:
38     virtual ~VideoDecMock() = default;
39     virtual int32_t Release() = 0;
40     virtual int32_t SetCallback(std::shared_ptr<AVCodecCallbackMock> cb) = 0;
41     virtual int32_t SetOutputSurface(std::shared_ptr<SurfaceMock> surface) = 0;
42     virtual int32_t Configure(std::shared_ptr<FormatMock> format) = 0;
43     virtual int32_t Start() = 0;
44     virtual int32_t Stop() = 0;
45     virtual int32_t Flush() = 0;
46     virtual int32_t Reset() = 0;
47     virtual std::shared_ptr<FormatMock> GetOutputDescription() = 0;
48     virtual int32_t SetParameter(std::shared_ptr<FormatMock> format) = 0;
49     virtual int32_t PushInputData(uint32_t index, OH_AVCodecBufferAttr &attr) = 0;
50     virtual int32_t RenderOutputData(uint32_t index) = 0;
51     virtual int32_t FreeOutputData(uint32_t index) = 0;
52     virtual bool IsValid() = 0;
53 };
54 
55 class VideoEncMock : public NoCopyable {
56 public:
57     virtual ~VideoEncMock() = default;
58     virtual int32_t Release() = 0;
59     virtual int32_t SetCallback(std::shared_ptr<AVCodecCallbackMock> cb) = 0;
60     virtual int32_t Configure(std::shared_ptr<FormatMock> format) = 0;
61     virtual int32_t Start() = 0;
62     virtual int32_t Stop() = 0;
63     virtual int32_t Flush() = 0;
64     virtual int32_t Reset() = 0;
65     virtual std::shared_ptr<FormatMock> GetOutputDescription() = 0;
66     virtual int32_t SetParameter(std::shared_ptr<FormatMock> format) = 0;
67     virtual int32_t FreeOutputData(uint32_t index) = 0;
68     virtual int32_t NotifyEos() = 0;
69     virtual int32_t PushInputData(uint32_t index, OH_AVCodecBufferAttr &attr) = 0;
70     virtual std::shared_ptr<SurfaceMock> CreateInputSurface() = 0;
71     virtual bool IsValid() = 0;
72 };
73 
74 class __attribute__((visibility("default"))) VCodecMockFactory {
75 public:
76     static std::shared_ptr<VideoDecMock> CreateVideoDecMockByMime(const std::string &mime);
77     static std::shared_ptr<VideoDecMock> CreateVideoDecMockByName(const std::string &name);
78     static std::shared_ptr<VideoEncMock> CreateVideoEncMockByMime(const std::string &mime);
79     static std::shared_ptr<VideoEncMock> CreateVideoEncMockByName(const std::string &name);
80 private:
81     VCodecMockFactory() = delete;
82     ~VCodecMockFactory() = delete;
83 };
84 
85 namespace VCodecTestParam {
86 const std::string VDEC_AVC_NAME = std::string(AVCodecCodecName::VIDEO_DECODER_AVC_NAME);
87 enum VCodecTestCode : int32_t  { SW_AVC, HW_AVC, HW_HEVC };
88 constexpr uint32_t DEFAULT_BITRATE = 12000;
89 
90 constexpr uint32_t SAMPLE_TIMEOUT = 10;
91 constexpr uint32_t DEFAULT_WIDTH = 320;
92 constexpr uint32_t DEFAULT_HEIGHT = 240;
93 constexpr uint32_t DEFAULT_FRAME_RATE = 20;
94 
95 constexpr uint32_t EOS_COUNT = 100;
96 } // namespace VCodecTestParam
97 } // namespace MediaAVCodec
98 } // namespace OHOS
99 #endif // VCODEC_MOCK_H