Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 CAMERA_H_ |
| 18 | #define CAMERA_H_ |
| 19 | |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 20 | #include <hardware/hardware.h> |
| 21 | #include <hardware/camera3.h> |
Alex Ray | 5556764 | 2013-11-12 12:58:39 -0800 | [diff] [blame] | 22 | #include <utils/Mutex.h> |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 23 | #include "Metadata.h" |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 24 | #include "Stream.h" |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 25 | |
| 26 | namespace default_camera_hal { |
| 27 | // Camera represents a physical camera on a device. |
| 28 | // This is constructed when the HAL module is loaded, one per physical camera. |
| 29 | // It is opened by the framework, and must be closed before it can be opened |
| 30 | // again. |
Alex Ray | 61f7a0c | 2013-07-03 17:54:19 -0700 | [diff] [blame] | 31 | // This is an abstract class, containing all logic and data shared between all |
| 32 | // camera devices (front, back, etc) and common to the ISP. |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 33 | class Camera { |
| 34 | public: |
| 35 | // id is used to distinguish cameras. 0 <= id < NUM_CAMERAS. |
| 36 | // module is a handle to the HAL module, used when the device is opened. |
Chih-Hung Hsieh | 928e679 | 2016-06-30 14:17:31 -0700 | [diff] [blame] | 37 | explicit Camera(int id); |
Alex Ray | 61f7a0c | 2013-07-03 17:54:19 -0700 | [diff] [blame] | 38 | virtual ~Camera(); |
Alex Ray | a48dd3f | 2012-12-19 12:21:38 -0800 | [diff] [blame] | 39 | |
| 40 | // Common Camera Device Operations (see <hardware/camera_common.h>) |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 41 | int open(const hw_module_t *module, hw_device_t **device); |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 42 | int getInfo(struct camera_info *info); |
Alex Ray | a48dd3f | 2012-12-19 12:21:38 -0800 | [diff] [blame] | 43 | int close(); |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 44 | |
| 45 | // Camera v3 Device Operations (see <hardware/camera3.h>) |
| 46 | int initialize(const camera3_callback_ops_t *callback_ops); |
| 47 | int configureStreams(camera3_stream_configuration_t *stream_list); |
| 48 | int registerStreamBuffers(const camera3_stream_buffer_set_t *buf_set); |
| 49 | const camera_metadata_t *constructDefaultRequestSettings(int type); |
| 50 | int processCaptureRequest(camera3_capture_request_t *request); |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 51 | void dump(int fd); |
| 52 | |
Alex Ray | 61f7a0c | 2013-07-03 17:54:19 -0700 | [diff] [blame] | 53 | |
| 54 | protected: |
| 55 | // Initialize static camera characteristics for individual device |
| 56 | virtual camera_metadata_t *initStaticInfo() = 0; |
| 57 | // Verify settings are valid for a capture |
| 58 | virtual bool isValidCaptureSettings(const camera_metadata_t *) = 0; |
| 59 | // Separate initialization method for individual devices when opened |
| 60 | virtual int initDevice() = 0; |
Alex Ray | 6273508 | 2013-10-21 12:55:24 -0700 | [diff] [blame] | 61 | // Accessor used by initDevice() to set the templates' metadata |
| 62 | int setTemplate(int type, camera_metadata_t *static_info); |
| 63 | // Prettyprint template names |
| 64 | const char* templateToString(int type); |
Alex Ray | a48dd3f | 2012-12-19 12:21:38 -0800 | [diff] [blame] | 65 | |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 66 | private: |
Alex Ray | 61f7a0c | 2013-07-03 17:54:19 -0700 | [diff] [blame] | 67 | // Camera device handle returned to framework for use |
| 68 | camera3_device_t mDevice; |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 69 | // Reuse a stream already created by this device |
| 70 | Stream *reuseStream(camera3_stream_t *astream); |
| 71 | // Destroy all streams in a stream array, and the array itself |
| 72 | void destroyStreams(Stream **array, int count); |
| 73 | // Verify a set of streams is valid in aggregate |
| 74 | bool isValidStreamSet(Stream **array, int count); |
| 75 | // Calculate usage and max_bufs of each stream |
| 76 | void setupStreams(Stream **array, int count); |
Alex Ray | bfcbd95 | 2013-03-20 13:20:02 -0700 | [diff] [blame] | 77 | // Copy new settings for re-use and clean up old settings. |
| 78 | void setSettings(const camera_metadata_t *new_settings); |
Alex Ray | 11bbeef | 2013-04-26 14:47:08 -0700 | [diff] [blame] | 79 | // Verify settings are valid for reprocessing an input buffer |
| 80 | bool isValidReprocessSettings(const camera_metadata_t *settings); |
Alex Ray | 083315c | 2013-04-26 19:32:29 -0700 | [diff] [blame] | 81 | // Process an output buffer |
| 82 | int processCaptureBuffer(const camera3_stream_buffer_t *in, |
| 83 | camera3_stream_buffer_t *out); |
Alex Ray | 764e442 | 2013-06-04 12:38:07 -0700 | [diff] [blame] | 84 | // Send a shutter notify message with start of exposure time |
| 85 | void notifyShutter(uint32_t frame_number, uint64_t timestamp); |
Alex Ray | 61f7a0c | 2013-07-03 17:54:19 -0700 | [diff] [blame] | 86 | // Is type a valid template type (and valid index into mTemplates) |
| 87 | bool isValidTemplateType(int type); |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 88 | |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 89 | // Identifier used by framework to distinguish cameras |
Alex Ray | 1f8af67 | 2013-02-28 15:40:08 -0800 | [diff] [blame] | 90 | const int mId; |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 91 | // Metadata containing persistent camera characteristics |
| 92 | Metadata mMetadata; |
| 93 | // camera_metadata structure containing static characteristics |
| 94 | camera_metadata_t *mStaticInfo; |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 95 | // Busy flag indicates camera is in use |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 96 | bool mBusy; |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 97 | // Camera device operations handle shared by all devices |
| 98 | const static camera3_device_ops_t sOps; |
| 99 | // Methods used to call back into the framework |
| 100 | const camera3_callback_ops_t *mCallbackOps; |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 101 | // Lock protecting the Camera object for modifications |
Alex Ray | 5556764 | 2013-11-12 12:58:39 -0800 | [diff] [blame] | 102 | android::Mutex mDeviceLock; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 103 | // Lock protecting only static camera characteristics, which may |
| 104 | // be accessed without the camera device open |
Alex Ray | 5556764 | 2013-11-12 12:58:39 -0800 | [diff] [blame] | 105 | android::Mutex mStaticInfoLock; |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 106 | // Array of handles to streams currently in use by the device |
| 107 | Stream **mStreams; |
| 108 | // Number of streams in mStreams |
| 109 | int mNumStreams; |
Alex Ray | 89a8266 | 2013-05-28 20:32:48 -0700 | [diff] [blame] | 110 | // Static array of standard camera settings templates |
Alex Ray | 61f7a0c | 2013-07-03 17:54:19 -0700 | [diff] [blame] | 111 | camera_metadata_t *mTemplates[CAMERA3_TEMPLATE_COUNT]; |
Alex Ray | bfcbd95 | 2013-03-20 13:20:02 -0700 | [diff] [blame] | 112 | // Most recent request settings seen, memoized to be reused |
| 113 | camera_metadata_t *mSettings; |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 114 | }; |
| 115 | } // namespace default_camera_hal |
| 116 | |
| 117 | #endif // CAMERA_H_ |