1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
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 "gtest/gtest.h"
17 #include "plugin/core/plugin_register.h"
18 #include "plugin/plugins/ffmpeg_adapter/video_decoder/video_ffmpeg_decoder_plugin.h"
19 #include "plugin/common/plugin_caps_builder.h"
20 #include "plugin/core/plugin_manager.h"
21 
22 namespace OHOS {
23 namespace Media {
24 namespace Test {
25     using namespace Plugin;
26     using namespace Ffmpeg;
27     using namespace testing::ext;
VideoFfmpegDecoderCreator(const std::string & name)28     std::shared_ptr<CodecPlugin> VideoFfmpegDecoderCreator(const std::string& name)
29     {
30         return std::make_shared<VideoFfmpegDecoderPlugin>(name);
31     }
32 
33 HWTEST(VideoFfmpegDecoderPluginTest, test_State, TestSize.Level1)
34 {
35     std::shared_ptr<CodecPlugin> videoDecoderPlugin = VideoFfmpegDecoderCreator("VideoFfmpegDecoderPluginTest");
36     ASSERT_TRUE(videoDecoderPlugin != nullptr);
37 
38     auto status = videoDecoderPlugin->Init();
39     ASSERT_TRUE(status == Status::ERROR_UNSUPPORTED_FORMAT);
40 
41     auto prepareStatus = videoDecoderPlugin->Prepare();
42     ASSERT_TRUE(prepareStatus == Status::ERROR_WRONG_STATE);
43 
44     auto deInitStatus = videoDecoderPlugin->Deinit();
45     ASSERT_TRUE(deInitStatus == Status::OK);
46 
47     auto resetStatus = videoDecoderPlugin->Reset();
48     ASSERT_TRUE(resetStatus == Status::OK);
49 
50     auto startStatus = videoDecoderPlugin->Start();
51     ASSERT_FALSE(startStatus == Status::OK);
52 
53     auto flushStatus = videoDecoderPlugin->Flush();
54     ASSERT_TRUE(flushStatus == Status::OK);
55 }
56 
57 HWTEST(VideoFfmpegDecoderPluginTest, test_Parameter, TestSize.Level1)
58 {
59     std::shared_ptr<CodecPlugin> videoDecoderPlugin = VideoFfmpegDecoderCreator("VideoFfmpegDecoderPluginTest");
60     ASSERT_TRUE(videoDecoderPlugin != nullptr);
61 
62     auto status = videoDecoderPlugin->SetParameter(Tag::VIDEO_FRAME_RATE, 30);
63     ASSERT_TRUE(status == Status::OK);
64 
65     ValueType parameterValue;
66     auto prepareStatus = videoDecoderPlugin->GetParameter(Tag::VIDEO_FRAME_RATE, parameterValue);
67     ASSERT_TRUE(prepareStatus == Status::OK);
68 }
69 
70 HWTEST(VideoFfmpegDecoderPluginTest, test_QueueInputBuffer, TestSize.Level1)
71 {
72     std::shared_ptr<CodecPlugin> videoDecoderPlugin = VideoFfmpegDecoderCreator("VideoFfmpegDecoderPluginTest");
73     std::shared_ptr<Buffer> inputBuffer = std::make_shared<Buffer>(BufferMetaType::VIDEO);
74     int32_t timeoutMs = 100;
75     ASSERT_EQ(Status::ERROR_INVALID_DATA, videoDecoderPlugin->QueueInputBuffer(inputBuffer, timeoutMs));
76     uint32_t size = 16;
77     inputBuffer->AllocMemory(nullptr, size);
78     ASSERT_EQ(Status::ERROR_WRONG_STATE, videoDecoderPlugin->QueueInputBuffer(inputBuffer, timeoutMs));
79     inputBuffer->flag = 1;
80     ASSERT_EQ(Status::ERROR_WRONG_STATE, videoDecoderPlugin->QueueInputBuffer(inputBuffer, timeoutMs));
81 }
82 
83 } //namespace Test
84 } //namespace Media
85 } //namespace OHOS