xref: /aosp_15_r20/hardware/libhardware/modules/camera/3_0/Camera.h (revision e01b6f769022e40d0923dee176e8dc7cd1d52984)
1*e01b6f76SAndroid Build Coastguard Worker /*
2*e01b6f76SAndroid Build Coastguard Worker  * Copyright (C) 2012 The Android Open Source Project
3*e01b6f76SAndroid Build Coastguard Worker  *
4*e01b6f76SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*e01b6f76SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*e01b6f76SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*e01b6f76SAndroid Build Coastguard Worker  *
8*e01b6f76SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*e01b6f76SAndroid Build Coastguard Worker  *
10*e01b6f76SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*e01b6f76SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*e01b6f76SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*e01b6f76SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*e01b6f76SAndroid Build Coastguard Worker  * limitations under the License.
15*e01b6f76SAndroid Build Coastguard Worker  */
16*e01b6f76SAndroid Build Coastguard Worker 
17*e01b6f76SAndroid Build Coastguard Worker #ifndef CAMERA_H_
18*e01b6f76SAndroid Build Coastguard Worker #define CAMERA_H_
19*e01b6f76SAndroid Build Coastguard Worker 
20*e01b6f76SAndroid Build Coastguard Worker #include <hardware/hardware.h>
21*e01b6f76SAndroid Build Coastguard Worker #include <hardware/camera3.h>
22*e01b6f76SAndroid Build Coastguard Worker #include <utils/Mutex.h>
23*e01b6f76SAndroid Build Coastguard Worker #include "Metadata.h"
24*e01b6f76SAndroid Build Coastguard Worker #include "Stream.h"
25*e01b6f76SAndroid Build Coastguard Worker 
26*e01b6f76SAndroid Build Coastguard Worker namespace default_camera_hal {
27*e01b6f76SAndroid Build Coastguard Worker // Camera represents a physical camera on a device.
28*e01b6f76SAndroid Build Coastguard Worker // This is constructed when the HAL module is loaded, one per physical camera.
29*e01b6f76SAndroid Build Coastguard Worker // It is opened by the framework, and must be closed before it can be opened
30*e01b6f76SAndroid Build Coastguard Worker // again.
31*e01b6f76SAndroid Build Coastguard Worker // This is an abstract class, containing all logic and data shared between all
32*e01b6f76SAndroid Build Coastguard Worker // camera devices (front, back, etc) and common to the ISP.
33*e01b6f76SAndroid Build Coastguard Worker class Camera {
34*e01b6f76SAndroid Build Coastguard Worker     public:
35*e01b6f76SAndroid Build Coastguard Worker         // id is used to distinguish cameras. 0 <= id < NUM_CAMERAS.
36*e01b6f76SAndroid Build Coastguard Worker         // module is a handle to the HAL module, used when the device is opened.
37*e01b6f76SAndroid Build Coastguard Worker         explicit Camera(int id);
38*e01b6f76SAndroid Build Coastguard Worker         virtual ~Camera();
39*e01b6f76SAndroid Build Coastguard Worker 
40*e01b6f76SAndroid Build Coastguard Worker         // Common Camera Device Operations (see <hardware/camera_common.h>)
41*e01b6f76SAndroid Build Coastguard Worker         int open(const hw_module_t *module, hw_device_t **device);
42*e01b6f76SAndroid Build Coastguard Worker         int getInfo(struct camera_info *info);
43*e01b6f76SAndroid Build Coastguard Worker         int close();
44*e01b6f76SAndroid Build Coastguard Worker 
45*e01b6f76SAndroid Build Coastguard Worker         // Camera v3 Device Operations (see <hardware/camera3.h>)
46*e01b6f76SAndroid Build Coastguard Worker         int initialize(const camera3_callback_ops_t *callback_ops);
47*e01b6f76SAndroid Build Coastguard Worker         int configureStreams(camera3_stream_configuration_t *stream_list);
48*e01b6f76SAndroid Build Coastguard Worker         int registerStreamBuffers(const camera3_stream_buffer_set_t *buf_set);
49*e01b6f76SAndroid Build Coastguard Worker         const camera_metadata_t *constructDefaultRequestSettings(int type);
50*e01b6f76SAndroid Build Coastguard Worker         int processCaptureRequest(camera3_capture_request_t *request);
51*e01b6f76SAndroid Build Coastguard Worker         void dump(int fd);
52*e01b6f76SAndroid Build Coastguard Worker 
53*e01b6f76SAndroid Build Coastguard Worker 
54*e01b6f76SAndroid Build Coastguard Worker     protected:
55*e01b6f76SAndroid Build Coastguard Worker         // Initialize static camera characteristics for individual device
56*e01b6f76SAndroid Build Coastguard Worker         virtual camera_metadata_t *initStaticInfo() = 0;
57*e01b6f76SAndroid Build Coastguard Worker         // Verify settings are valid for a capture
58*e01b6f76SAndroid Build Coastguard Worker         virtual bool isValidCaptureSettings(const camera_metadata_t *) = 0;
59*e01b6f76SAndroid Build Coastguard Worker         // Separate initialization method for individual devices when opened
60*e01b6f76SAndroid Build Coastguard Worker         virtual int initDevice() = 0;
61*e01b6f76SAndroid Build Coastguard Worker         // Accessor used by initDevice() to set the templates' metadata
62*e01b6f76SAndroid Build Coastguard Worker         int setTemplate(int type, camera_metadata_t *static_info);
63*e01b6f76SAndroid Build Coastguard Worker         // Prettyprint template names
64*e01b6f76SAndroid Build Coastguard Worker         const char* templateToString(int type);
65*e01b6f76SAndroid Build Coastguard Worker 
66*e01b6f76SAndroid Build Coastguard Worker     private:
67*e01b6f76SAndroid Build Coastguard Worker         // Camera device handle returned to framework for use
68*e01b6f76SAndroid Build Coastguard Worker         camera3_device_t mDevice;
69*e01b6f76SAndroid Build Coastguard Worker         // Reuse a stream already created by this device
70*e01b6f76SAndroid Build Coastguard Worker         Stream *reuseStream(camera3_stream_t *astream);
71*e01b6f76SAndroid Build Coastguard Worker         // Destroy all streams in a stream array, and the array itself
72*e01b6f76SAndroid Build Coastguard Worker         void destroyStreams(Stream **array, int count);
73*e01b6f76SAndroid Build Coastguard Worker         // Verify a set of streams is valid in aggregate
74*e01b6f76SAndroid Build Coastguard Worker         bool isValidStreamSet(Stream **array, int count);
75*e01b6f76SAndroid Build Coastguard Worker         // Calculate usage and max_bufs of each stream
76*e01b6f76SAndroid Build Coastguard Worker         void setupStreams(Stream **array, int count);
77*e01b6f76SAndroid Build Coastguard Worker         // Copy new settings for re-use and clean up old settings.
78*e01b6f76SAndroid Build Coastguard Worker         void setSettings(const camera_metadata_t *new_settings);
79*e01b6f76SAndroid Build Coastguard Worker         // Verify settings are valid for reprocessing an input buffer
80*e01b6f76SAndroid Build Coastguard Worker         bool isValidReprocessSettings(const camera_metadata_t *settings);
81*e01b6f76SAndroid Build Coastguard Worker         // Process an output buffer
82*e01b6f76SAndroid Build Coastguard Worker         int processCaptureBuffer(const camera3_stream_buffer_t *in,
83*e01b6f76SAndroid Build Coastguard Worker                 camera3_stream_buffer_t *out);
84*e01b6f76SAndroid Build Coastguard Worker         // Send a shutter notify message with start of exposure time
85*e01b6f76SAndroid Build Coastguard Worker         void notifyShutter(uint32_t frame_number, uint64_t timestamp);
86*e01b6f76SAndroid Build Coastguard Worker         // Is type a valid template type (and valid index into mTemplates)
87*e01b6f76SAndroid Build Coastguard Worker         bool isValidTemplateType(int type);
88*e01b6f76SAndroid Build Coastguard Worker 
89*e01b6f76SAndroid Build Coastguard Worker         // Identifier used by framework to distinguish cameras
90*e01b6f76SAndroid Build Coastguard Worker         const int mId;
91*e01b6f76SAndroid Build Coastguard Worker         // Metadata containing persistent camera characteristics
92*e01b6f76SAndroid Build Coastguard Worker         Metadata mMetadata;
93*e01b6f76SAndroid Build Coastguard Worker         // camera_metadata structure containing static characteristics
94*e01b6f76SAndroid Build Coastguard Worker         camera_metadata_t *mStaticInfo;
95*e01b6f76SAndroid Build Coastguard Worker         // Busy flag indicates camera is in use
96*e01b6f76SAndroid Build Coastguard Worker         bool mBusy;
97*e01b6f76SAndroid Build Coastguard Worker         // Camera device operations handle shared by all devices
98*e01b6f76SAndroid Build Coastguard Worker         const static camera3_device_ops_t sOps;
99*e01b6f76SAndroid Build Coastguard Worker         // Methods used to call back into the framework
100*e01b6f76SAndroid Build Coastguard Worker         const camera3_callback_ops_t *mCallbackOps;
101*e01b6f76SAndroid Build Coastguard Worker         // Lock protecting the Camera object for modifications
102*e01b6f76SAndroid Build Coastguard Worker         android::Mutex mDeviceLock;
103*e01b6f76SAndroid Build Coastguard Worker         // Lock protecting only static camera characteristics, which may
104*e01b6f76SAndroid Build Coastguard Worker         // be accessed without the camera device open
105*e01b6f76SAndroid Build Coastguard Worker         android::Mutex mStaticInfoLock;
106*e01b6f76SAndroid Build Coastguard Worker         // Array of handles to streams currently in use by the device
107*e01b6f76SAndroid Build Coastguard Worker         Stream **mStreams;
108*e01b6f76SAndroid Build Coastguard Worker         // Number of streams in mStreams
109*e01b6f76SAndroid Build Coastguard Worker         int mNumStreams;
110*e01b6f76SAndroid Build Coastguard Worker         // Static array of standard camera settings templates
111*e01b6f76SAndroid Build Coastguard Worker         camera_metadata_t *mTemplates[CAMERA3_TEMPLATE_COUNT];
112*e01b6f76SAndroid Build Coastguard Worker         // Most recent request settings seen, memoized to be reused
113*e01b6f76SAndroid Build Coastguard Worker         camera_metadata_t *mSettings;
114*e01b6f76SAndroid Build Coastguard Worker };
115*e01b6f76SAndroid Build Coastguard Worker } // namespace default_camera_hal
116*e01b6f76SAndroid Build Coastguard Worker 
117*e01b6f76SAndroid Build Coastguard Worker #endif // CAMERA_H_
118