Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | // Modified from hardware/libhardware/modules/camera/Camera.h |
| 18 | |
Ari Hausman-Cohen | 3841a7f | 2016-07-19 17:27:52 -0700 | [diff] [blame] | 19 | #ifndef DEFAULT_CAMERA_HAL_CAMERA_H_ |
| 20 | #define DEFAULT_CAMERA_HAL_CAMERA_H_ |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 21 | |
Ari Hausman-Cohen | abbf9cc | 2016-08-23 11:59:59 -0700 | [diff] [blame] | 22 | #include <camera/CameraMetadata.h> |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 23 | #include <hardware/hardware.h> |
| 24 | #include <hardware/camera3.h> |
| 25 | #include <utils/Mutex.h> |
Ari Hausman-Cohen | abbf9cc | 2016-08-23 11:59:59 -0700 | [diff] [blame] | 26 | |
Ari Hausman-Cohen | 2738a9c | 2016-09-21 15:03:49 -0700 | [diff] [blame] | 27 | #include "capture_request.h" |
Ari Hausman-Cohen | abbf9cc | 2016-08-23 11:59:59 -0700 | [diff] [blame] | 28 | #include "metadata/metadata.h" |
Ari Hausman-Cohen | 0b2113c | 2016-10-03 13:43:13 -0700 | [diff] [blame] | 29 | #include "request_tracker.h" |
Ari Hausman-Cohen | e31e1f3 | 2016-11-16 15:02:07 -0800 | [diff] [blame] | 30 | #include "static_properties.h" |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 31 | |
| 32 | namespace default_camera_hal { |
| 33 | // Camera represents a physical camera on a device. |
| 34 | // This is constructed when the HAL module is loaded, one per physical camera. |
| 35 | // TODO(b/29185945): Support hotplugging. |
| 36 | // It is opened by the framework, and must be closed before it can be opened |
| 37 | // again. |
| 38 | // This is an abstract class, containing all logic and data shared between all |
| 39 | // camera devices (front, back, etc) and common to the ISP. |
| 40 | class Camera { |
| 41 | public: |
| 42 | // id is used to distinguish cameras. 0 <= id < NUM_CAMERAS. |
| 43 | // module is a handle to the HAL module, used when the device is opened. |
| 44 | Camera(int id); |
| 45 | virtual ~Camera(); |
| 46 | |
| 47 | // Common Camera Device Operations (see <hardware/camera_common.h>) |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 48 | int openDevice(const hw_module_t *module, hw_device_t **device); |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 49 | int getInfo(struct camera_info *info); |
| 50 | int close(); |
| 51 | |
| 52 | // Camera v3 Device Operations (see <hardware/camera3.h>) |
| 53 | int initialize(const camera3_callback_ops_t *callback_ops); |
| 54 | int configureStreams(camera3_stream_configuration_t *stream_list); |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 55 | const camera_metadata_t *constructDefaultRequestSettings(int type); |
Ari Hausman-Cohen | 2738a9c | 2016-09-21 15:03:49 -0700 | [diff] [blame] | 56 | int processCaptureRequest(camera3_capture_request_t *temp_request); |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 57 | void dump(int fd); |
Ari Hausman-Cohen | c5a4852 | 2016-11-16 10:53:52 -0800 | [diff] [blame] | 58 | int flush(); |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 59 | |
| 60 | protected: |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 61 | // Connect to the device: open dev nodes, etc. |
| 62 | virtual int connect() = 0; |
| 63 | // Disconnect from the device: close dev nodes, etc. |
| 64 | virtual void disconnect() = 0; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 65 | // Initialize static camera characteristics for individual device |
Ari Hausman-Cohen | abbf9cc | 2016-08-23 11:59:59 -0700 | [diff] [blame] | 66 | virtual int initStaticInfo(android::CameraMetadata* out) = 0; |
| 67 | // Initialize a template of the given type |
| 68 | virtual int initTemplate(int type, android::CameraMetadata* out) = 0; |
| 69 | // Initialize device info: resource cost and conflicting devices |
| 70 | // (/conflicting devices length) |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 71 | virtual void initDeviceInfo(struct camera_info *info) = 0; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 72 | // Separate initialization method for individual devices when opened |
| 73 | virtual int initDevice() = 0; |
Ari Hausman-Cohen | ef52310 | 2016-11-21 17:02:01 -0800 | [diff] [blame^] | 74 | // Verify stream configuration dataspaces and rotation values |
| 75 | virtual bool validateDataspacesAndRotations( |
| 76 | const camera3_stream_configuration_t* stream_config) = 0; |
| 77 | // Set up the streams, including seting usage & max_buffers |
| 78 | virtual int setupStreams( |
| 79 | camera3_stream_configuration_t* stream_config) = 0; |
| 80 | // Verify settings are valid for a capture or reprocessing |
| 81 | virtual bool isValidRequestSettings( |
| 82 | const android::CameraMetadata& settings) = 0; |
Ari Hausman-Cohen | 2738a9c | 2016-09-21 15:03:49 -0700 | [diff] [blame] | 83 | // Enqueue a request to receive data from the camera |
| 84 | virtual int enqueueRequest( |
| 85 | std::shared_ptr<CaptureRequest> request) = 0; |
Ari Hausman-Cohen | c5a4852 | 2016-11-16 10:53:52 -0800 | [diff] [blame] | 86 | // Flush in flight buffers. |
| 87 | virtual int flushBuffers() = 0; |
| 88 | |
Ari Hausman-Cohen | 2738a9c | 2016-09-21 15:03:49 -0700 | [diff] [blame] | 89 | |
| 90 | // Callback for when the device has filled in the requested data. |
| 91 | // Fills in the result struct, validates the data, sends appropriate |
| 92 | // notifications, and returns the result to the framework. |
| 93 | void completeRequest( |
| 94 | std::shared_ptr<CaptureRequest> request, int err); |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 95 | // Prettyprint template names |
| 96 | const char* templateToString(int type); |
| 97 | |
| 98 | private: |
| 99 | // Camera device handle returned to framework for use |
| 100 | camera3_device_t mDevice; |
Ari Hausman-Cohen | e31e1f3 | 2016-11-16 15:02:07 -0800 | [diff] [blame] | 101 | // Get static info from the device and store it in mStaticInfo. |
| 102 | int loadStaticInfo(); |
Ari Hausman-Cohen | ef52310 | 2016-11-21 17:02:01 -0800 | [diff] [blame^] | 103 | // Confirm that a stream configuration is valid. |
| 104 | int validateStreamConfiguration( |
| 105 | const camera3_stream_configuration_t* stream_config); |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 106 | // Verify settings are valid for reprocessing an input buffer |
| 107 | bool isValidReprocessSettings(const camera_metadata_t *settings); |
Ari Hausman-Cohen | 2738a9c | 2016-09-21 15:03:49 -0700 | [diff] [blame] | 108 | // Pre-process an output buffer |
| 109 | int preprocessCaptureBuffer(camera3_stream_buffer_t *buffer); |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 110 | // Send a shutter notify message with start of exposure time |
| 111 | void notifyShutter(uint32_t frame_number, uint64_t timestamp); |
Ari Hausman-Cohen | fb16111 | 2016-09-29 14:35:00 -0700 | [diff] [blame] | 112 | // Send an error message and return the errored out result. |
| 113 | void completeRequestWithError(std::shared_ptr<CaptureRequest> request); |
| 114 | // Send a capture result for a request. |
| 115 | void sendResult(std::shared_ptr<CaptureRequest> request); |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 116 | // Is type a valid template type (and valid index into mTemplates) |
| 117 | bool isValidTemplateType(int type); |
| 118 | |
| 119 | // Identifier used by framework to distinguish cameras |
| 120 | const int mId; |
Ari Hausman-Cohen | abbf9cc | 2016-08-23 11:59:59 -0700 | [diff] [blame] | 121 | // CameraMetadata containing static characteristics |
Ari Hausman-Cohen | e31e1f3 | 2016-11-16 15:02:07 -0800 | [diff] [blame] | 122 | std::unique_ptr<StaticProperties> mStaticInfo; |
Ari Hausman-Cohen | abbf9cc | 2016-08-23 11:59:59 -0700 | [diff] [blame] | 123 | // Flag indicating if settings have been set since |
| 124 | // the last configure_streams() call. |
| 125 | bool mSettingsSet; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 126 | // Busy flag indicates camera is in use |
| 127 | bool mBusy; |
| 128 | // Camera device operations handle shared by all devices |
| 129 | const static camera3_device_ops_t sOps; |
| 130 | // Methods used to call back into the framework |
| 131 | const camera3_callback_ops_t *mCallbackOps; |
| 132 | // Lock protecting the Camera object for modifications |
| 133 | android::Mutex mDeviceLock; |
| 134 | // Lock protecting only static camera characteristics, which may |
| 135 | // be accessed without the camera device open |
| 136 | android::Mutex mStaticInfoLock; |
Ari Hausman-Cohen | c5a4852 | 2016-11-16 10:53:52 -0800 | [diff] [blame] | 137 | android::Mutex mFlushLock; |
Ari Hausman-Cohen | abbf9cc | 2016-08-23 11:59:59 -0700 | [diff] [blame] | 138 | // Standard camera settings templates |
| 139 | std::unique_ptr<const android::CameraMetadata> mTemplates[CAMERA3_TEMPLATE_COUNT]; |
Ari Hausman-Cohen | 0b2113c | 2016-10-03 13:43:13 -0700 | [diff] [blame] | 140 | // Track in flight requests. |
| 141 | std::unique_ptr<RequestTracker> mInFlightTracker; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 142 | }; |
Ari Hausman-Cohen | 3841a7f | 2016-07-19 17:27:52 -0700 | [diff] [blame] | 143 | } // namespace default_camera_hal |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 144 | |
Ari Hausman-Cohen | 3841a7f | 2016-07-19 17:27:52 -0700 | [diff] [blame] | 145 | #endif // DEFAULT_CAMERA_HAL_CAMERA_H_ |