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