1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file expected 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 "camera_fps_test.h"
16
17 using namespace testing::ext;
18
SetUpTestCase(void)19 void CameraFpsTest::SetUpTestCase(void)
20 {}
TearDownTestCase(void)21 void CameraFpsTest::TearDownTestCase(void)
22 {}
SetUp(void)23 void CameraFpsTest::SetUp(void)
24 {
25 if (display_ == nullptr) {
26 display_ = std::make_shared<TestDisplay>();
27 }
28 display_->Init();
29 }
TearDown(void)30 void CameraFpsTest::TearDown(void)
31 {
32 display_->Close();
33 }
34
GetFpsRange(std::shared_ptr<CameraAbility> & ability)35 void CameraFpsTest::GetFpsRange(std::shared_ptr<CameraAbility> &ability)
36 {
37 common_metadata_header_t* data = ability->get();
38 fpsRange_.clear();
39 camera_metadata_item_t entry;
40 int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_FPS_RANGES, &entry);
41 if (ret != 0) {
42 std::cout << "==========[test log] get OHOS_ABILITY_FPS_RANGES error." << std::endl;
43 }
44
45 uint32_t count = entry.count;
46 for (int i = 0 ; i < count; i++) {
47 fpsRange_.push_back(*(entry.data.i32 + i));
48 }
49
50 for (auto it = fpsRange_.begin(); it != fpsRange_.end(); it++) {
51 std::cout << "==========[test log] fpsRange : " << *it << std::endl;
52 }
53 }
54
55 /**
56 * @tc.name: fps Setting
57 * @tc.desc: UpdateSettings, fps.
58 * @tc.level: Level1
59 * @tc.size: MediumTest
60 * @tc.type: Function
61 */
62 static HWTEST_F(CameraFpsTest, camera_fps_001, TestSize.Level1)
63 {
64 // get camera ability
65 if (display_->ability == nullptr) {
66 std::cout << "==========[test log] ability is null." << std::endl;
67 return;
68 }
69 GetFpsRange(display_->ability);
70
71 // get the stream manager
72 display_->AchieveStreamOperator();
73
74 // enable result
75 std::vector<int32_t> resultsList;
76 resultsList.push_back(OHOS_CAMERA_STREAM_ID);
77 resultsList.push_back(OHOS_CONTROL_FPS_RANGES);
78 display_->cameraDevice->EnableResult(resultsList);
79
80 // start stream
81 display_->intents = {PREVIEW};
82 display_->StartStream(display_->intents);
83
84 // updateSettings
85 constexpr uint32_t ITEM_CAPACITY = 100;
86 constexpr uint32_t DATA_CAPACITY = 2000;
87 std::shared_ptr<CameraSetting> meta = std::make_shared<CameraSetting>(
88 ITEM_CAPACITY, DATA_CAPACITY);
89 std::vector<int32_t> fpsRange;
90 fpsRange.push_back(fpsRange_[0]);
91 fpsRange.push_back(fpsRange_[1]);
92 meta->addEntry(OHOS_CONTROL_FPS_RANGES, fpsRange.data(), fpsRange.size());
93 const int32_t deviceStreamId = 0;
94 meta->addEntry(OHOS_CAMERA_STREAM_ID, &deviceStreamId, 1);
95 std::vector<uint8_t> setting;
96 MetadataUtils::ConvertMetadataToVec(meta, setting);
97 display_->rc = (CamRetCode)display_->cameraDevice->UpdateSettings(setting);
98 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
99 std::cout << "==========[test log] UpdateSettings success." << std::endl;
100 } else {
101 std::cout << "==========[test log] UpdateSettings fail, rc = " << display_->rc << std::endl;
102 }
103
104 // get preview
105 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
106
107 // release stream
108 display_->captureIds = {display_->CAPTURE_ID_PREVIEW};
109 display_->streamIds = {display_->STREAM_ID_PREVIEW};
110 display_->StopStream(display_->captureIds, display_->streamIds);
111 }