• 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 except 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 
16 #ifndef OHOS_CAMERA_METADATA_OUTPUT_H
17 #define OHOS_CAMERA_METADATA_OUTPUT_H
18 
19 #include <iostream>
20 #include "capture_output.h"
21 #include "istream_metadata.h"
22 
23 #include "camera_metadata_operator.h"
24 #include "surface.h"
25 
26 namespace OHOS {
27 namespace CameraStandard {
28 enum class MetadataObjectType : int32_t {
29     FACE = 0,
30 };
31 
32 enum MetadataOutputErrorCode : int32_t {
33     ERROR_UNKNOWN = 1,
34     ERROR_INSUFFICIENT_RESOURCES,
35 };
36 
37 typedef struct {
38     double topLeftX;
39     double topLeftY;
40     double width;
41     double height;
42 } Rect;
43 
44 class MetadataObject : public RefBase {
45 public:
46     MetadataObject(MetadataObjectType type, double timestamp, Rect rect);
47     virtual ~MetadataObject() = default;
48     MetadataObjectType GetType();
49     double GetTimestamp();
50     Rect GetBoundingBox();
51 
52 private:
53     MetadataObjectType type_;
54     double timestamp_;
55     Rect box_;
56 };
57 
58 class MetadataFaceObject : public MetadataObject {
59 public:
60     MetadataFaceObject(double timestamp, Rect rect);
61     ~MetadataFaceObject() = default;
62 };
63 
64 class MetadataObjectCallback {
65 public:
66     MetadataObjectCallback() = default;
67     virtual ~MetadataObjectCallback() = default;
68     virtual void OnMetadataObjectsAvailable(std::vector<sptr<MetadataObject>> metaObjects) const = 0;
69 };
70 
71 class MetadataStateCallback {
72 public:
73     MetadataStateCallback() = default;
74     virtual ~MetadataStateCallback() = default;
75     virtual void OnError(int32_t errorCode) const = 0;
76 };
77 
78 class MetadataOutput : public CaptureOutput {
79 public:
80     MetadataOutput(sptr<Surface> surface, sptr<IStreamMetadata> &streamMetadata);
81     ~MetadataOutput();
82 
83     /**
84      * @brief Get the supported metadata object types.
85      *
86      * @return Returns vector of MetadataObjectType.
87      */
88     std::vector<MetadataObjectType> GetSupportedMetadataObjectTypes();
89 
90     /**
91      * @brief Set the metadata object types
92      *
93      * @param Vector of MetadataObjectType
94      */
95     void SetCapturingMetadataObjectTypes(std::vector<MetadataObjectType> objectTypes);
96 
97     /**
98      * @brief Set the metadata object callback for the metadata output.
99      *
100      * @param MetadataObjectCallback pointer to be triggered.
101      */
102     void SetCallback(std::shared_ptr<MetadataObjectCallback> metadataObjectCallback);
103 
104     /**
105      * @brief Set the metadata state callback for the metadata output.
106      *
107      * @param MetadataStateCallback pointer to be triggered.
108      */
109     void SetCallback(std::shared_ptr<MetadataStateCallback> metadataStateCallback);
110 
111     /**
112      * @brief Start the metadata capture.
113      */
114     int32_t Start();
115 
116     /**
117      * @brief Stop the metadata capture.
118      */
119     int32_t Stop();
120 
121     /**
122      * @brief Releases a instance of the MetadataOutput.
123      */
124     int32_t Release() override;
125 
126     friend class MetadataObjectListener;
127 private:
128     sptr<Surface> surface_;
129     std::shared_ptr<MetadataObjectCallback> appObjectCallback_;
130     std::shared_ptr<MetadataStateCallback> appStateCallback_;
131 };
132 
133 class MetadataObjectListener : public IBufferConsumerListener {
134 public:
135     MetadataObjectListener(sptr<MetadataOutput> metadata);
~MetadataObjectListener()136     virtual ~MetadataObjectListener()
137     {
138         metadata_ = nullptr;
139     }
140     void OnBufferAvailable() override;
141 
142 private:
143     int32_t ProcessMetadataBuffer(void* buffer, int64_t timestamp);
144     int32_t ProcessFaceRectangles(int64_t timestamp, const camera_metadata_item_t &metadataItem,
145                                   std::vector<sptr<MetadataObject>> &metaObjects);
146     sptr<MetadataOutput> metadata_;
147 };
148 } // namespace CameraStandard
149 } // namespace OHOS
150 #endif // OHOS_CAMERA_METADATA_OUTPUT_H
151