1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef HARDWARE_GOOGLE_CAMERA_LIB_DEPTH_TYPES_H_
18 #define HARDWARE_GOOGLE_CAMERA_LIB_DEPTH_TYPES_H_
19 
20 #include <cutils/native_handle.h>
21 #include <system/camera_metadata.h>
22 #include <system/graphics-base-v1.0.h>
23 #include <functional>
24 #include <vector>
25 
26 namespace android {
27 namespace depth_generator {
28 
29 enum class DepthResultStatus : uint32_t {
30   // Depth generator is able to successfully process the request
31   kOk = 0,
32   // Depth generator failed to process the request
33   kError,
34 };
35 
36 struct StreamBuffer {
37   // TODO(b/126379504): Add handle to Framework/HAL stream if needed.
38   // The client owns the buffer and should guarantee that they are valid during
39   // the entire life cycle that this buffer is passed into the depth_generator.
40   buffer_handle_t* buffer = nullptr;
41 };
42 
43 struct BufferPlane {
44   // The virtual address mapped to the UMD of the client process. The client
45   // should guarantee that this is valid and not unmapped during the entire life
46   // cycle that this buffer is passed into the depth_generator.
47   uint8_t* addr = nullptr;
48   // In bytes
49   uint32_t stride = 0;
50   // Number of lines actually allocated
51   uint32_t scanline = 0;
52 };
53 
54 struct Buffer {
55   // Format of the image buffer
56   android_pixel_format_t format = HAL_PIXEL_FORMAT_RGBA_8888;
57   // Image planes mapped to UMD
58   std::vector<BufferPlane> planes;
59   // Dimension of this image buffer
60   uint32_t width = 0;
61   uint32_t height = 0;
62   // Information of the framework buffer
63   StreamBuffer framework_buffer;
64 };
65 
66 struct DepthRequestInfo {
67   // Frame number used by the caller to identify this request
68   uint32_t frame_number = 0;
69   // Input buffers
70   // Sequence of buffers from color sensor
71   std::vector<Buffer> color_buffer;
72   // Sequence of buffers from multiple NIR sensors(e.g. {{d0, f0},{d1, f1}})
73   std::vector<std::vector<Buffer>> ir_buffer;
74   // Output buffer
75   Buffer depth_buffer;
76   // Place holder for input metadata(e.g. crop_region). The client should
77   // guarantee that the metadata is valid during the entire life cycle that this
78   // metadata is passed into the depth_generator.
79   const camera_metadata_t* settings = nullptr;
80   // input buffer metadata for the color_buffer. This metadata contains info on
81   // how the color_buffer is generated(e.g. crop info, FD result, etc.). The
82   // caller owns the data and guarantee that the data is valid during the func
83   // call. The callee should copy this if it still needs this after the call is
84   // returned.
85   const camera_metadata_t* color_buffer_metadata = nullptr;
86 };
87 
88 // Callback function invoked to notify depth buffer readiness. This method must
89 // be invoked by a thread different from the thread that enqueues the request to
90 // avoid deadlock.
91 using DepthResultCallbackFunction =
92     std::function<void(DepthResultStatus result, uint32_t frame_number)>;
93 
94 }  // namespace depth_generator
95 }  // namespace android
96 
97 #endif  // HARDWARE_GOOGLE_CAMERA_LIB_DEPTH_TYPES_H_