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 17using namespace testing::ext; 18 19void CameraFpsTest::SetUpTestCase(void) 20{} 21void CameraFpsTest::TearDownTestCase(void) 22{} 23void CameraFpsTest::SetUp(void) 24{ 25 if (cameraBase_ == nullptr) { 26 cameraBase_ = std::make_shared<TestCameraBase>(); 27 } 28 cameraBase_->Init(); 29} 30void CameraFpsTest::TearDown(void) 31{ 32 cameraBase_->Close(); 33} 34 35void 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 CAMERA_LOGE("get OHOS_ABILITY_FPS_RANGES error."); 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 CAMERA_LOGI("fpsRange : %{public}d", *it); 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 */ 62static HWTEST_F(CameraFpsTest, camera_fps_001, TestSize.Level1) 63{ 64 // get camera ability 65 if (cameraBase_->ability == nullptr) { 66 CAMERA_LOGE("ability is null."); 67 return; 68 } 69 GetFpsRange(cameraBase_->ability); 70 71 // get the stream manager 72 cameraBase_->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 cameraBase_->cameraDevice->EnableResult(resultsList); 79 80 // start stream 81 cameraBase_->intents = {PREVIEW}; 82 cameraBase_->StartStream(cameraBase_->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 cameraBase_->rc = (CamRetCode)cameraBase_->cameraDevice->UpdateSettings(setting); 98 if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) { 99 CAMERA_LOGI("UpdateSettings success."); 100 } else { 101 CAMERA_LOGE("UpdateSettings fail, rc = %{public}d", cameraBase_->rc); 102 } 103 104 // get preview 105 cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true); 106 107 // release stream 108 cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW}; 109 cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW}; 110 cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds); 111}