• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "hdfcamera_facedetect.h"
16 
17 using namespace testing::ext;
18 
SetUpTestCase(void)19 void HdfCameraFaceDetect::SetUpTestCase(void)
20 {}
TearDownTestCase(void)21 void HdfCameraFaceDetect::TearDownTestCase(void)
22 {}
SetUp(void)23 void HdfCameraFaceDetect::SetUp(void)
24 {
25     if (display_ == nullptr) {
26         display_ = std::make_shared<TestDisplay>();
27     }
28     display_->Init();
29 }
TearDown(void)30 void HdfCameraFaceDetect::TearDown(void)
31 {
32     display_->Close();
33 }
34 
35 /**
36   * @tc.name: preview and capture and face detect
37   * @tc.desc: Commit 3 streams together, Preview , still_capture and analyze streams, isStreaming is true.
38   * @tc.level: Level0
39   * @tc.size: MediumTest
40   * @tc.type: Function
41   */
42 static HWTEST_F(HdfCameraFaceDetect, CameraFaceDetect_001, TestSize.Level1)
43 {
44     // Get the stream manager
45     display_->AchieveStreamOperator();
46     // start stream
47     display_->intents = {PREVIEW, STILL_CAPTURE, ANALYZE};
48     display_->StartStream(display_->intents);
49     // Get preview
50     display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
51     display_->StartCapture(display_->STREAM_ID_ANALYZE, display_->CAPTURE_ID_ANALYZE, false, true);
52 
53     // add dumy exif info
54     constexpr double latitude = 27.987500; // dummy data: Qomolangma latitde
55     constexpr double longitude = 86.927500; // dummy data: Qomolangma longituude
56     constexpr double altitude = 8848.86; // dummy data: Qomolangma altitude
57     constexpr size_t entryCapacity = 100;
58     constexpr size_t dataCapacity = 2000;
59     std::shared_ptr<CameraSetting>  captureSetting =
60         std::make_shared<CameraSetting>(entryCapacity, dataCapacity);
61     uint8_t captureQuality = OHOS_CAMERA_JPEG_LEVEL_HIGH;
62     int32_t captureOrientation = OHOS_CAMERA_JPEG_ROTATION_270;
63     uint8_t mirrorSwitch = OHOS_CAMERA_MIRROR_ON;
64     std::vector<double> gps;
65     gps.push_back(latitude);
66     gps.push_back(longitude);
67     gps.push_back(altitude);
68     captureSetting->addEntry(OHOS_JPEG_QUALITY, static_cast<void*>(&captureQuality),
69         sizeof(captureQuality));
70     captureSetting->addEntry(OHOS_JPEG_ORIENTATION, static_cast<void*>(&captureOrientation),
71         sizeof(captureOrientation));
72     captureSetting->addEntry(OHOS_CONTROL_CAPTURE_MIRROR, static_cast<void*>(&mirrorSwitch),
73         sizeof(mirrorSwitch));
74     captureSetting->addEntry(OHOS_JPEG_GPS_COORDINATES, gps.data(), gps.size());
75     std::vector<uint8_t> setting;
76     MetadataUtils::ConvertMetadataToVec(captureSetting, setting);
77 
78     CaptureInfo captureInfo = {};
79     captureInfo.streamIds_ = {display_->STREAM_ID_CAPTURE};
80     captureInfo.captureSetting_ = setting;
81     captureInfo.enableShutterCallback_ = false;
82     display_->rc = (CamRetCode)display_->streamOperator->Capture(display_->CAPTURE_ID_CAPTURE, captureInfo, true);
83     EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
84     if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
85         CAMERA_LOGI("check Capture: Capture success, captureId = %{public}d", display_->CAPTURE_ID_CAPTURE);
86     } else {
87         CAMERA_LOGE("check Capture: Capture fail, captureId = %{public}d, rc = %{public}d",
88             display_->CAPTURE_ID_CAPTURE, display_->rc);
89     }
__anonb9fd86ed0102(const unsigned char *addr, const uint32_t size) 90     display_->streamCustomerCapture_->ReceiveFrameOn([this](const unsigned char *addr, const uint32_t size) {
91         display_->StoreImage(addr, size);
92     });
93     sleep(2);
94     // release stream
95     display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_ANALYZE, display_->CAPTURE_ID_CAPTURE};
96     display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_ANALYZE, display_->STREAM_ID_CAPTURE};
97     display_->StopStream(display_->captureIds, display_->streamIds);
98 }
99 
100 /**
101   * @tc.name: preview and capture and face detect
102   * @tc.desc: Commit 2 streams together, Preview and analyze streams, isStreaming is true.
103   * @tc.level: Level0
104   * @tc.size: MediumTest
105   * @tc.type: Function
106   */
107 static HWTEST_F(HdfCameraFaceDetect, CameraFaceDetect_002, TestSize.Level1)
108 {
109     // Get the stream manager
110     display_->AchieveStreamOperator();
111     // start stream
112     display_->intents = {PREVIEW, ANALYZE};
113     display_->StartStream(display_->intents);
114     // Get preview
115     display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
116     display_->StartCapture(display_->STREAM_ID_ANALYZE, display_->CAPTURE_ID_ANALYZE, false, true);
117     sleep(2);
118     // release stream
119     display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_ANALYZE};
120     display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_ANALYZE};
121     display_->StopStream(display_->captureIds, display_->streamIds);
122 }