• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 <limits>
17 #include "gtest/gtest.h"
18 #include "native_avcodec_videoencoder.h"
19 #include "native_averrors.h"
20 #include "videoenc_api11_sample.h"
21 #include "native_avcodec_base.h"
22 #include "avcodec_codec_name.h"
23 #include "native_avcapability.h"
24 namespace {
25 OH_AVCodec *venc_ = NULL;
26 OH_AVCapability *cap = nullptr;
27 constexpr uint32_t CODEC_NAME_SIZE = 128;
28 constexpr uint32_t DEFAULT_BITRATE = 1000000;
29 char g_codecName[CODEC_NAME_SIZE] = {};
30 const char *INP_DIR_720 = "/data/test/media/1280_720_nv.yuv";
31 constexpr uint32_t DEFAULT_WIDTH = 1280;
32 constexpr uint32_t DEFAULT_HEIGHT = 720;
33 } // namespace
34 namespace OHOS {
35 namespace Media {
36 class AvcSwEncGetParamNdkTest : public testing::Test {
37 public:
38     static void SetUpTestCase();
39     static void TearDownTestCase();
40     void SetUp() override;
41     void TearDown() override;
42     void InputFunc();
43     void OutputFunc();
44     void Release();
45     int32_t Stop();
46 };
47 } // namespace Media
48 } // namespace OHOS
49 
50 using namespace std;
51 using namespace OHOS;
52 using namespace OHOS::Media;
53 using namespace testing::ext;
54 
SetUpTestCase()55 void AvcSwEncGetParamNdkTest::SetUpTestCase()
56 {
57     cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, SOFTWARE);
58     const char *tmpCodecName = OH_AVCapability_GetName(cap);
59     if (memcpy_s(g_codecName, sizeof(g_codecName), tmpCodecName, strlen(tmpCodecName)) != 0)
60         cout << "memcpy failed" << endl;
61     cout << "codecname: " << g_codecName << endl;
62 }
TearDownTestCase()63 void AvcSwEncGetParamNdkTest::TearDownTestCase() {}
SetUp()64 void AvcSwEncGetParamNdkTest::SetUp() {}
TearDown()65 void AvcSwEncGetParamNdkTest::TearDown()
66 {
67     if (venc_ != NULL) {
68         OH_VideoEncoder_Destroy(venc_);
69         venc_ = nullptr;
70     }
71 }
72 namespace {
73 
74 /**
75  * @tc.number    : VIDEO_ENCODE_MSE_QP_0100
76  * @tc.name      : encode Avbuffer h264 buffer,get QP and MSE
77  * @tc.desc      : function test
78  */
79 HWTEST_F(AvcSwEncGetParamNdkTest, VIDEO_ENCODE_MSE_QP_0100, TestSize.Level0)
80 {
81     if (strlen(g_codecName) == 0) {
82         return;
83     }
84     auto vEncSample = make_unique<VEncAPI11Sample>();
85     vEncSample->INP_DIR = INP_DIR_720;
86     vEncSample->DEFAULT_WIDTH = DEFAULT_WIDTH;
87     vEncSample->DEFAULT_HEIGHT = DEFAULT_HEIGHT;
88     vEncSample->DEFAULT_FRAME_RATE = 30;
89     vEncSample->DEFAULT_BITRATE = DEFAULT_BITRATE;
90     vEncSample->getQpMse = true;
91     vEncSample->SURF_INPUT = false;
92     vEncSample->OUT_DIR = "/data/test/media/qp_mse_0300.h264";
93     ASSERT_EQ(AV_ERR_OK, vEncSample->CreateVideoEncoder(g_codecName));
94     ASSERT_EQ(AV_ERR_OK, vEncSample->SetVideoEncoderCallback());
95     ASSERT_EQ(AV_ERR_OK, vEncSample->ConfigureVideoEncoder());
96     ASSERT_EQ(AV_ERR_OK, vEncSample->StartVideoEncoder());
97     vEncSample->WaitForEOS();
98     ASSERT_EQ(AV_ERR_OK, vEncSample->errCount);
99 }
100 
101 /**
102  * @tc.number    : VIDEO_ENCODE_MSE_QP_0200
103  * @tc.name      : encode Avbuffer h264 surf,get QP and MSE
104  * @tc.desc      : function test
105  */
106 HWTEST_F(AvcSwEncGetParamNdkTest, VIDEO_ENCODE_MSE_QP_0200, TestSize.Level0)
107 {
108     if (strlen(g_codecName) == 0) {
109         return;
110     }
111     auto vEncSample = make_unique<VEncAPI11Sample>();
112     vEncSample->INP_DIR = INP_DIR_720;
113     vEncSample->DEFAULT_WIDTH = DEFAULT_WIDTH;
114     vEncSample->DEFAULT_HEIGHT = DEFAULT_HEIGHT;
115     vEncSample->DEFAULT_FRAME_RATE = 30;
116     vEncSample->DEFAULT_BITRATE = DEFAULT_BITRATE;
117     vEncSample->getQpMse = true;
118     vEncSample->SURF_INPUT = true;
119     vEncSample->OUT_DIR = "/data/test/media/qp_mse_0400.h264";
120     ASSERT_EQ(AV_ERR_OK, vEncSample->CreateVideoEncoder(g_codecName));
121     ASSERT_EQ(AV_ERR_OK, vEncSample->SetVideoEncoderCallback());
122     ASSERT_EQ(AV_ERR_OK, vEncSample->ConfigureVideoEncoder());
123     ASSERT_EQ(AV_ERR_OK, vEncSample->StartVideoEncoder());
124     vEncSample->WaitForEOS();
125     ASSERT_EQ(AV_ERR_OK, vEncSample->errCount);
126 }
127 }