• 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 
16 #include <iostream>
17 #include <cstdio>
18 #include <atomic>
19 #include <fstream>
20 #include <thread>
21 #include <mutex>
22 #include <queue>
23 #include <string>
24 #include "native_avcapability.h"
25 #include "gtest/gtest.h"
26 #include "native_avcodec_videodecoder.h"
27 #include "native_avcodec_base.h"
28 #include "videodec_sample.h"
29 #include "videodec_api11_sample.h"
30 using namespace std;
31 using namespace OHOS;
32 using namespace OHOS::Media;
33 using namespace testing::ext;
34 
35 namespace OHOS {
36 namespace Media {
37 class Mpeg2SwdecReliNdkTest : public testing::Test {
38 public:
39     static void SetUpTestCase();    // 第一个测试用例执行前
40     static void TearDownTestCase(); // 最后一个测试用例执行后
41     void SetUp() override;          // 每个测试用例执行前
42     void TearDown() override;       // 每个测试用例执行后
43     void InputFunc();
44     void OutputFunc();
45     void Release();
46     int32_t Stop();
47 
48 protected:
49     bool createCodecSuccess_ = false;
50     OH_AVCodec *vdec_;
51 };
52 } // namespace Media
53 } // namespace OHOS
54 
55 namespace {
56     static OH_AVCapability *cap_mpeg2 = nullptr;
57     static string g_codecNameMpeg2 = "";
58 } // namespace
59 
SetUpTestCase()60 void Mpeg2SwdecReliNdkTest::SetUpTestCase()
61 {
62     cap_mpeg2 = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_MPEG2, false, SOFTWARE);
63     g_codecNameMpeg2 = OH_AVCapability_GetName(cap_mpeg2);
64     cout << "g_codecNameMpeg2: " << g_codecNameMpeg2 << endl;
65 }
TearDownTestCase()66 void Mpeg2SwdecReliNdkTest::TearDownTestCase() {}
SetUp()67 void Mpeg2SwdecReliNdkTest::SetUp() {}
TearDown()68 void Mpeg2SwdecReliNdkTest::TearDown() {}
69 
70 namespace {
71 /**
72  * @tc.number    : VIDEO_MPEG2SWDEC_RELI_0100
73  * @tc.name      : repeat create and destroy decoder in surface mode ,MPEG2
74  * @tc.desc      : reliable test
75  */
76 HWTEST_F(Mpeg2SwdecReliNdkTest, VIDEO_MPEG2SWDEC_RELI_0100, TestSize.Level3)
77 {
78     if (cap_mpeg2 != nullptr) {
79         shared_ptr<VDecNdkSample> vDecSample = make_shared<VDecNdkSample>();
80         const char *INP_DIR_1 = "/data/test/media/main@high14_level_1280_720_60.m2v";
81         vDecSample->SURFACE_OUTPUT = true;
82         vDecSample->INP_DIR = INP_DIR_1;
83         vDecSample->DEFAULT_WIDTH = 1280;
84         vDecSample->DEFAULT_HEIGHT = 720;
85         vDecSample->DEFAULT_FRAME_RATE = 60;
86         ASSERT_EQ(AV_ERR_OK, vDecSample->RunVideoDec_Surface("OH.Media.Codec.Decoder.Video.MPEG2"));
87         vDecSample->WaitForEOS();
88         ASSERT_EQ(AV_ERR_OK, vDecSample->errCount);
89     }
90 }
91 
92 /**
93  * @tc.number    : VIDEO_MPEG2SWDEC_RELI_0200
94  * @tc.name      : repeat create and destroy decoder in buffer mode ,MPEG2
95  * @tc.desc      : reliable test
96  */
97 HWTEST_F(Mpeg2SwdecReliNdkTest, VIDEO_MPEG2SWDEC_RELI_0200, TestSize.Level3)
98 {
99     if (cap_mpeg2 != nullptr) {
100         shared_ptr<VDecNdkSample> vDecSample = make_shared<VDecNdkSample>();
101         const char *INP_DIR_1 = "/data/test/media/main@high14_level_1280_720_60.m2v";
102         vDecSample->SURFACE_OUTPUT = false;
103         vDecSample->INP_DIR = INP_DIR_1;
104         vDecSample->DEFAULT_WIDTH = 1280;
105         vDecSample->DEFAULT_HEIGHT = 720;
106         vDecSample->DEFAULT_FRAME_RATE = 60;
107         ASSERT_EQ(AV_ERR_OK, vDecSample->CreateVideoDecoder("OH.Media.Codec.Decoder.Video.MPEG2"));
108         ASSERT_EQ(AV_ERR_OK, vDecSample->ConfigureVideoDecoder());
109         ASSERT_EQ(AV_ERR_OK, vDecSample->SetVideoDecoderCallback());
110         ASSERT_EQ(AV_ERR_OK, vDecSample->StartVideoDecoder());
111         vDecSample->WaitForEOS();
112         ASSERT_EQ(AV_ERR_OK, vDecSample->errCount);
113     }
114 }
115 
116 /**
117  * @tc.number    : VIDEO_MPEG2SWDEC_RELI_0300
118  * @tc.name      : long decode in surface mode ,MPEG2
119  * @tc.desc      : reliable test
120  */
121 HWTEST_F(Mpeg2SwdecReliNdkTest, VIDEO_MPEG2SWDEC_RELI_0300, TestSize.Level3)
122 {
123     if (cap_mpeg2 != nullptr) {
124         shared_ptr<VDecNdkSample> vDecSample = make_shared<VDecNdkSample>();
125         const char *INP_DIR_1 = "/data/test/media/main@high14_level_1280_720_60.m2v";
126         vDecSample->SURFACE_OUTPUT = true;
127         vDecSample->INP_DIR = INP_DIR_1;
128         vDecSample->DEFAULT_WIDTH = 1280;
129         vDecSample->DEFAULT_HEIGHT = 720;
130         vDecSample->DEFAULT_FRAME_RATE = 60;
131         vDecSample->repeatRun = true;
132         ASSERT_EQ(AV_ERR_OK, vDecSample->RunVideoDec_Surface("OH.Media.Codec.Decoder.Video.MPEG2"));
133         vDecSample->WaitForEOS();
134         ASSERT_EQ(AV_ERR_OK, vDecSample->errCount);
135     }
136 }
137 
138 /**
139  * @tc.number    : VIDEO_MPEG2SWDEC_RELI_0400
140  * @tc.name      : long decode in buffer mode ,MPEG2
141  * @tc.desc      : reliable test
142  */
143 HWTEST_F(Mpeg2SwdecReliNdkTest, VIDEO_MPEG2SWDEC_RELI_0400, TestSize.Level3)
144 {
145     if (cap_mpeg2 != nullptr) {
146         shared_ptr<VDecNdkSample> vDecSample = make_shared<VDecNdkSample>();
147         const char *INP_DIR_1 = "/data/test/media/main@high14_level_1280_720_60.m2v";
148         vDecSample->SURFACE_OUTPUT = false;
149         vDecSample->INP_DIR = INP_DIR_1;
150         vDecSample->DEFAULT_WIDTH = 1280;
151         vDecSample->DEFAULT_HEIGHT = 720;
152         vDecSample->DEFAULT_FRAME_RATE = 60;
153         vDecSample->repeatRun = true;
154         ASSERT_EQ(AV_ERR_OK, vDecSample->CreateVideoDecoder("OH.Media.Codec.Decoder.Video.MPEG2"));
155         ASSERT_EQ(AV_ERR_OK, vDecSample->ConfigureVideoDecoder());
156         ASSERT_EQ(AV_ERR_OK, vDecSample->SetVideoDecoderCallback());
157         ASSERT_EQ(AV_ERR_OK, vDecSample->StartVideoDecoder());
158         vDecSample->WaitForEOS();
159         ASSERT_EQ(AV_ERR_OK, vDecSample->errCount);
160     }
161 }
162 } // namespace