• 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 (cameraBase_ == nullptr) {
26         cameraBase_ = std::make_shared<TestCameraBase>();
27     }
28     cameraBase_->Init();
29 }
TearDown(void)30 void HdfCameraFaceDetect::TearDown(void)
31 {
32     cameraBase_->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     cameraBase_->AchieveStreamOperator();
46     // start stream
47     cameraBase_->intents = {PREVIEW, STILL_CAPTURE, ANALYZE};
48     cameraBase_->StartStream(cameraBase_->intents);
49     // Get preview
50     cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
51     cameraBase_->StartCapture(cameraBase_->STREAM_ID_ANALYZE, cameraBase_->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_ = {cameraBase_->STREAM_ID_CAPTURE};
80     captureInfo.captureSetting_ = setting;
81     captureInfo.enableShutterCallback_ = false;
82     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->Capture(cameraBase_->CAPTURE_ID_CAPTURE,
83         captureInfo, true);
84     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
85     if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
86         CAMERA_LOGI("check Capture: Capture success, captureId = %{public}d", cameraBase_->CAPTURE_ID_CAPTURE);
87     } else {
88         CAMERA_LOGE("check Capture: Capture fail, captureId = %{public}d, rc = %{public}d",
89             cameraBase_->CAPTURE_ID_CAPTURE, cameraBase_->rc);
90     }
__anone152159a0102(const unsigned char *addr, const uint32_t size) 91     cameraBase_->streamCustomerCapture_->ReceiveFrameOn([this](const unsigned char *addr, const uint32_t size) {
92         cameraBase_->StoreImage(addr, size);
93     });
94     sleep(2);
95     // release stream
96     cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_ANALYZE,
97         cameraBase_->CAPTURE_ID_CAPTURE};
98     cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_ANALYZE,
99         cameraBase_->STREAM_ID_CAPTURE};
100     cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
101 }
102 
103 /**
104   * @tc.name: preview and capture and face detect
105   * @tc.desc: Commit 2 streams together, Preview and analyze streams, isStreaming is true.
106   * @tc.level: Level0
107   * @tc.size: MediumTest
108   * @tc.type: Function
109   */
110 static HWTEST_F(HdfCameraFaceDetect, CameraFaceDetect_002, TestSize.Level1)
111 {
112     // Get the stream manager
113     cameraBase_->AchieveStreamOperator();
114     // start stream
115     cameraBase_->intents = {PREVIEW, ANALYZE};
116     cameraBase_->StartStream(cameraBase_->intents);
117     // Get preview
118     cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
119     cameraBase_->StartCapture(cameraBase_->STREAM_ID_ANALYZE, cameraBase_->CAPTURE_ID_ANALYZE, false, true);
120     sleep(2);
121     // release stream
122     cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_ANALYZE};
123     cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_ANALYZE};
124     cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
125 }