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_stabili_test.h"
16
17 using namespace testing::ext;
18
SetUpTestCase(void)19 void CameraStabiliTest::SetUpTestCase(void)
20 {}
TearDownTestCase(void)21 void CameraStabiliTest::TearDownTestCase(void)
22 {}
SetUp(void)23 void CameraStabiliTest::SetUp(void)
24 {
25 if (display_ == nullptr) {
26 display_ = std::make_shared<TestDisplay>();
27 }
28 display_->Init();
29 }
TearDown(void)30 void CameraStabiliTest::TearDown(void)
31 {
32 display_->Close();
33 }
34
GetAvalialbleVideoStabilizationModes(std::shared_ptr<CameraAbility> & ability)35 void CameraStabiliTest::GetAvalialbleVideoStabilizationModes(
36 std::shared_ptr<CameraAbility> &ability)
37 {
38 common_metadata_header_t* data = ability->get();
39 videoStabilizationAvailableModes_.clear();
40 camera_metadata_item_t entry;
41 int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_VIDEO_STABILIZATION_MODES, &entry);
42 if (ret != 0) {
43 std::cout << "==========[test log] get OHOS_ABILITY_VIDEO_STABILIZATION_MODES error." << std::endl;
44 }
45 uint32_t count = entry.count;
46 for (int i = 0 ; i < count; i++) {
47 videoStabilizationAvailableModes_.push_back(*(entry.data.u8 + i));
48 }
49 for (auto it = videoStabilizationAvailableModes_.begin(); it != videoStabilizationAvailableModes_.end(); it++) {
50 std::cout << "==========[test log] videoStabilizationAvailableModes : " << (int)*it << std::endl;
51 }
52 }
53
54 /**
55 * @tc.name: stabili setting
56 * @tc.desc: UpdateSettings, OHOS_CONTROL_VIDEO_STABILIZATION_MODE.
57 * @tc.level: Level1
58 * @tc.size: MediumTest
59 * @tc.type: Function
60 */
61 static HWTEST_F(CameraStabiliTest, camera_stabili_001, TestSize.Level1)
62 {
63 // get camera ability
64 if (display_->ability == nullptr) {
65 std::cout << "==========[test log] ability is null." << std::endl;
66 return;
67 }
68 GetAvalialbleVideoStabilizationModes(display_->ability);
69
70 // get the stream manager
71 display_->AchieveStreamOperator();
72
73 // start stream
74 display_->intents = {PREVIEW, VIDEO};
75 display_->StartStream(display_->intents);
76
77 // updateSettings
78 constexpr uint32_t ITEM_CAPACITY = 100;
79 constexpr uint32_t DATA_CAPACITY = 2000;
80 constexpr uint32_t DATA_COUNT = 1;
81 std::shared_ptr<CameraSetting> meta = std::make_shared<CameraSetting>(
82 ITEM_CAPACITY, DATA_CAPACITY);
83 uint8_t videoStabiliMode = videoStabilizationAvailableModes_[0];
84 meta->addEntry(OHOS_CONTROL_VIDEO_STABILIZATION_MODE, &videoStabiliMode, DATA_COUNT);
85 const int32_t deviceStreamId = display_->STREAM_ID_VIDEO;
86 meta->addEntry(OHOS_CAMERA_STREAM_ID, &deviceStreamId, 1);
87 std::vector<uint8_t> setting;
88 MetadataUtils::ConvertMetadataToVec(meta, setting);
89
90 display_->rc = (CamRetCode)display_->cameraDevice->UpdateSettings(setting);
91 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
92 std::cout << "==========[test log] UpdateSettings success" << std::endl;
93 } else {
94 std::cout << "==========[test log] UpdateSettings fail, rc = " << display_->rc << std::endl;
95 }
96
97 // get preview
98 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
99 display_->StartCapture(display_->STREAM_ID_VIDEO, display_->CAPTURE_ID_VIDEO, false, true);
100
101 // release stream
102 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_VIDEO};
103 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_VIDEO};
104 display_->StopStream(display_->captureIds, display_->streamIds);
105 }