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_avcodec_videoencoder.h"
19 #include "native_averrors.h"
20 #include "videodec_api11_sample.h"
21 #include "native_avcodec_base.h"
22 #include "avcodec_codec_name.h"
23 #include "native_avcapability.h"
24 #include "native_buffer.h"
25
26 #define MAX_THREAD 16
27
28 using namespace std;
29 using namespace OHOS;
30 using namespace OHOS::Media;
31 using namespace testing::ext;
32
33 namespace OHOS {
34 namespace Media {
35 class HwdecHdr2SdrNdkTest : public testing::Test {
36 public:
37 static void SetUpTestCase();
38 static void TearDownTestCase();
39 void SetUp() override;
40 void TearDown() override;
41 void InputFunc();
42 void OutputFunc();
43 void Release();
44 int32_t Stop();
45 };
46 } // namespace Media
47 } // namespace OHOS
48
49 namespace {
50 static OH_AVCapability *cap_hevc = nullptr;
51 static string g_codecNameAVC = "";
52 static string g_codecNameHEVC = "";
53 OH_AVCodec *vdec_ = NULL;
54 OH_AVFormat *format;
55 constexpr int32_t DEFAULT_WIDTH = 1920;
56 constexpr int32_t DEFAULT_HEIGHT = 1080;
57 } // namespace
58
SetUpTestCase()59 void HwdecHdr2SdrNdkTest::SetUpTestCase()
60 {
61 cap_hevc = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_HEVC, false, HARDWARE);
62 g_codecNameHEVC = OH_AVCapability_GetName(cap_hevc);
63 cout << "g_codecNameHEVC: " << g_codecNameHEVC << endl;
64 }
TearDownTestCase()65 void HwdecHdr2SdrNdkTest::TearDownTestCase() {}
66
SetUp(void)67 void HwdecHdr2SdrNdkTest::SetUp(void) {}
68
TearDown()69 void HwdecHdr2SdrNdkTest::TearDown()
70 {
71 if (format != nullptr) {
72 OH_AVFormat_Destroy(format);
73 format = nullptr;
74 }
75 if (vdec_ != NULL) {
76 OH_VideoDecoder_Destroy(vdec_);
77 vdec_ = nullptr;
78 }
79 }
80
81 namespace {
82
83 /**
84 * @tc.number : HEVC_HW_HDR2SDR_FUNC_002
85 * @tc.name : OH_MD_KEY_VIDEO_DECODER_OUTPUT_COLOR_SPACE设置为BT_709_LIMIT, pixel foramt RGBA
86 * @tc.desc : function test
87 */
88 HWTEST_F(HwdecHdr2SdrNdkTest, HEVC_HW_HDR2SDR_FUNC_002, TestSize.Level2)
89 {
90 if (cap_hevc) {
91 if (!access("/system/lib64/media/", 0)) {
92 vdec_ = OH_VideoDecoder_CreateByName(g_codecNameHEVC.c_str());
93 ASSERT_NE(NULL, vdec_);
94 format = OH_AVFormat_Create();
95 ASSERT_NE(NULL, format);
96 ASSERT_EQ(true, OH_AVFormat_SetIntValue(format, OH_MD_KEY_VIDEO_DECODER_OUTPUT_COLOR_SPACE,
97 OH_COLORSPACE_BT709_LIMIT));
98 ASSERT_EQ(true, OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_RGBA));
99 ASSERT_EQ(AV_ERR_INVALID_VAL, OH_VideoDecoder_Configure(vdec_, format));
100 }
101 else {
102 vdec_ = OH_VideoDecoder_CreateByName(g_codecNameHEVC.c_str());
103 ASSERT_NE(NULL, vdec_);
104 format = OH_AVFormat_Create();
105 ASSERT_NE(NULL, format);
106 ASSERT_EQ(true, OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT));
107 ASSERT_EQ(true, OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH));
108 ASSERT_EQ(true, OH_AVFormat_SetIntValue(format, OH_MD_KEY_VIDEO_DECODER_OUTPUT_COLOR_SPACE,
109 OH_COLORSPACE_BT709_LIMIT));
110 ASSERT_EQ(true, OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_RGBA));
111 ASSERT_EQ(AV_ERR_VIDEO_UNSUPPORTED_COLOR_SPACE_CONVERSION, OH_VideoDecoder_Configure(vdec_, format));
112 }
113 }
114 }
115 } //namespace