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 #include <string>
16 #include "gtest/gtest.h"
17 #include "native_avcodec_videodecoder.h"
18 #include "native_averrors.h"
19 #include "videodec_sample.h"
20 #include "native_avcodec_base.h"
21 #include "avcodec_codec_name.h"
22 #include "native_avcapability.h"
23 
24 
25 using namespace std;
26 using namespace OHOS;
27 using namespace OHOS::Media;
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace Media {
32 class HwdecConfigureNdkTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp() override;
37     void TearDown() override;
38     void InputFunc();
39     void OutputFunc();
40     void Release();
41     int32_t Stop();
42 
43 protected:
44     const char *INP_DIR_720_30 = "/data/test/media/1280_720_30_10Mb.h264";
45     const char *INP_DIR_1080_30 = "/data/test/media/1920_1080_10_30Mb.h264";
46 };
47 } // namespace Media
48 } // namespace OHOS
49 
50 namespace {
51 static OH_AVCapability *cap = nullptr;
52 static OH_AVCapability *cap_hevc = nullptr;
53 static string g_codecName = "";
54 static string g_codecNameHEVC = "";
55 constexpr int32_t DEFAULT_WIDTH = 1920;
56 constexpr int32_t DEFAULT_HEIGHT = 1080;
57 } // namespace
58 
SetUpTestCase()59 void HwdecConfigureNdkTest::SetUpTestCase()
60 {
61     cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, false, HARDWARE);
62     g_codecName = OH_AVCapability_GetName(cap);
63     cout << "codecname: " << g_codecName << endl;
64     cap_hevc = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_HEVC, false, HARDWARE);
65     g_codecNameHEVC = OH_AVCapability_GetName(cap_hevc);
66     cout << "g_codecNameHEVC: " << g_codecNameHEVC << endl;
67 }
TearDownTestCase()68 void HwdecConfigureNdkTest::TearDownTestCase() {}
SetUp()69 void HwdecConfigureNdkTest::SetUp() {}
TearDown()70 void HwdecConfigureNdkTest::TearDown() {
71 }
72 
73 namespace {
74 /**
75  * @tc.number    : VIDEO_HWDEC_CONFIGURE_0010
76  * @tc.name      : set max input size with illegal value
77  * @tc.desc      : configure test
78  */
79 HWTEST_F(HwdecConfigureNdkTest, VIDEO_HWDEC_CONFIGURE_0010, TestSize.Level1)
80 {
81     OH_AVCodec *vdec = OH_VideoDecoder_CreateByName(g_codecName.c_str());
82     ASSERT_NE(NULL, vdec);
83     OH_AVFormat *format = OH_AVFormat_Create();
84     ASSERT_NE(NULL, format);
85     (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
86     (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
87     (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
88     (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, -1);
89     ASSERT_EQ(AV_ERR_OK, OH_VideoDecoder_Configure(vdec, format));
90     OH_VideoDecoder_Destroy(vdec);
91     OH_AVFormat_Destroy(format);
92 }
93 
94 /**
95  * @tc.number    : VIDEO_HWDEC_CONFIGURE_0020
96  * @tc.name      : set max input size with illegal value
97  * @tc.desc      : configure test
98  */
99 HWTEST_F(HwdecConfigureNdkTest, VIDEO_HWDEC_CONFIGURE_0020, TestSize.Level1)
100 {
101     OH_AVCodec *vdec = OH_VideoDecoder_CreateByName(g_codecName.c_str());
102     ASSERT_NE(NULL, vdec);
103     OH_AVFormat *format = OH_AVFormat_Create();
104     ASSERT_NE(NULL, format);
105     (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
106     (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
107     (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
108     (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, 0);
109     ASSERT_EQ(AV_ERR_OK, OH_VideoDecoder_Configure(vdec, format));
110     OH_VideoDecoder_Destroy(vdec);
111     OH_AVFormat_Destroy(format);
112 }
113 
114 /**
115  * @tc.number    : VIDEO_HWDEC_CONFIGURE_0030
116  * @tc.name      : set max input size with illegal value HEVC
117  * @tc.desc      : configure test
118  */
119 HWTEST_F(HwdecConfigureNdkTest, VIDEO_HWDEC_CONFIGURE_0030, TestSize.Level1)
120 {
121     OH_AVCodec *vdec = OH_VideoDecoder_CreateByName(g_codecNameHEVC.c_str());
122     ASSERT_NE(NULL, vdec);
123     OH_AVFormat *format = OH_AVFormat_Create();
124     ASSERT_NE(NULL, format);
125     (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
126     (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
127     (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
128     (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, -1);
129     ASSERT_EQ(AV_ERR_OK, OH_VideoDecoder_Configure(vdec, format));
130     OH_VideoDecoder_Destroy(vdec);
131     OH_AVFormat_Destroy(format);
132 }
133 
134 /**
135  * @tc.number    : VIDEO_HWDEC_CONFIGURE_0040
136  * @tc.name      : set max input size with illegal value HEVC
137  * @tc.desc      : configure test
138  */
139 HWTEST_F(HwdecConfigureNdkTest, VIDEO_HWDEC_CONFIGURE_0040, TestSize.Level1)
140 {
141     OH_AVCodec *vdec = OH_VideoDecoder_CreateByName(g_codecNameHEVC.c_str());
142     ASSERT_NE(NULL, vdec);
143     OH_AVFormat *format = OH_AVFormat_Create();
144     ASSERT_NE(NULL, format);
145     (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
146     (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
147     (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
148     (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, 0);
149     ASSERT_EQ(AV_ERR_OK, OH_VideoDecoder_Configure(vdec, format));
150     OH_VideoDecoder_Destroy(vdec);
151     OH_AVFormat_Destroy(format);
152 }
153 }