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 (cameraBase_ == nullptr) {
26 cameraBase_ = std::make_shared<TestCameraBase>();
27 }
28 cameraBase_->Init();
29 }
TearDown(void)30 void CameraStabiliTest::TearDown(void)
31 {
32 cameraBase_->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 CAMERA_LOGE("get OHOS_ABILITY_VIDEO_STABILIZATION_MODES error.");
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 CAMERA_LOGI("videoStabilizationAvailableModes: %{public}d", static_cast<int>(*it));
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 (cameraBase_->ability == nullptr) {
65 CAMERA_LOGE("ability is null.");
66 return;
67 }
68 GetAvalialbleVideoStabilizationModes(cameraBase_->ability);
69
70 // get the stream manager
71 cameraBase_->AchieveStreamOperator();
72
73 // start stream
74 cameraBase_->intents = {PREVIEW, VIDEO};
75 cameraBase_->StartStream(cameraBase_->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 = cameraBase_->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 cameraBase_->rc = (CamRetCode)cameraBase_->cameraDevice->UpdateSettings(setting);
91 if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
92 CAMERA_LOGI("UpdateSettings success");
93 } else {
94 CAMERA_LOGE("UpdateSettings fail, rc = %{public}d", cameraBase_->rc);
95 }
96
97 // get preview
98 cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
99 cameraBase_->StartCapture(cameraBase_->STREAM_ID_VIDEO, cameraBase_->CAPTURE_ID_VIDEO, false, true);
100
101 // release stream
102 cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_VIDEO};
103 cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_VIDEO};
104 cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
105 }