1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *     http://www.apache.org/licenses/LICENSE-2.0
7  * Unless required by applicable law or agreed to in writing, software
8  * distributed under the License is distributed on an "AS IS" BASIS,
9  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10  * See the License for the specific language governing permissions and
11  * limitations under the License.
12  */
13 
14 #ifndef HOS_CAMERA_RKFACE_NODE_H
15 #define HOS_CAMERA_RKFACE_NODE_H
16 
17 #include <vector>
18 #include <condition_variable>
19 #include <ctime>
20 #include "device_manager_adapter.h"
21 #include "utils.h"
22 #include "camera.h"
23 #include "source_node.h"
24 
25 enum FaceRectanglesIndex : int32_t {
26     INDEX_0 = 0,
27     INDEX_1,
28     INDEX_2,
29     INDEX_3,
30 };
31 
32 namespace OHOS::Camera {
33 std::vector<uint32_t> FaceDetectMetadataTag = {
34     OHOS_STATISTICS_FACE_DETECT_SWITCH,
35     OHOS_STATISTICS_FACE_RECTANGLES,
36     OHOS_STATISTICS_FACE_IDS
37 };
38 
39 class FaceNode : public NodeBase {
40 public:
41     FaceNode(const std::string &name, const std::string &type, const std::string &cameraId);
42     ~FaceNode() override;
43     RetCode Start(const int32_t streamId) override;
44     RetCode Stop(const int32_t streamId) override;
45     void DeliverBuffer(std::shared_ptr<IBuffer>& buffer) override;
46     virtual RetCode Capture(const int32_t streamId, const int32_t captureId) override;
47     RetCode CancelCapture(const int32_t streamId) override;
48     RetCode Flush(const int32_t streamId);
49     RetCode Config(const int32_t streamId, const CaptureMeta& meta) override;
50 
51 private:
52     RetCode GetFaceDetectMetaData(std::shared_ptr<CameraMetadata> &metadata);
53     RetCode GetCameraFaceDetectSwitch(std::shared_ptr<CameraMetadata> &metadata);
54     RetCode GetCameraFaceRectangles(std::shared_ptr<CameraMetadata> &metadata);
55     RetCode GetCameraFaceIds(std::shared_ptr<CameraMetadata> &metadata);
56     RetCode CopyBuffer(uint8_t *sourceBuffer, std::shared_ptr<IBuffer>& outPutBuffer, int32_t dataSize);
57     RetCode CopyMetadataBuffer(std::shared_ptr<CameraMetadata> &metadata,
58         std::shared_ptr<IBuffer>& outPutBuffer, int32_t dataSize);
59     RetCode CreateMetadataInfo();
60 
61 private:
62     std::vector<std::shared_ptr<IPort>> outPutPorts_;
63     std::mutex mLock_;
64     std::shared_ptr<CameraMetadata> metaData_ = nullptr;
65     std::condition_variable cv_;
66     int32_t metaDataSize_;
67 };
68 } // namespace OHOS::Camera
69 #endif
70