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 | |
| 20 | #include <pthread.h> |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 21 | #include <hardware/hardware.h> |
| 22 | #include <hardware/camera3.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 | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 31 | class Camera { |
| 32 | public: |
| 33 | // id is used to distinguish cameras. 0 <= id < NUM_CAMERAS. |
| 34 | // module is a handle to the HAL module, used when the device is opened. |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 35 | Camera(int id); |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 36 | ~Camera(); |
Alex Ray | a48dd3f | 2012-12-19 12:21:38 -0800 | [diff] [blame] | 37 | |
| 38 | // Common Camera Device Operations (see <hardware/camera_common.h>) |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 39 | int open(const hw_module_t *module, hw_device_t **device); |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 40 | int getInfo(struct camera_info *info); |
Alex Ray | a48dd3f | 2012-12-19 12:21:38 -0800 | [diff] [blame] | 41 | int close(); |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 42 | |
| 43 | // Camera v3 Device Operations (see <hardware/camera3.h>) |
| 44 | int initialize(const camera3_callback_ops_t *callback_ops); |
| 45 | int configureStreams(camera3_stream_configuration_t *stream_list); |
| 46 | int registerStreamBuffers(const camera3_stream_buffer_set_t *buf_set); |
| 47 | const camera_metadata_t *constructDefaultRequestSettings(int type); |
| 48 | int processCaptureRequest(camera3_capture_request_t *request); |
| 49 | void getMetadataVendorTagOps(vendor_tag_query_ops_t *ops); |
| 50 | void dump(int fd); |
| 51 | |
| 52 | // Camera device handle returned to framework for use |
| 53 | camera3_device_t mDevice; |
Alex Ray | a48dd3f | 2012-12-19 12:21:38 -0800 | [diff] [blame] | 54 | |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 55 | private: |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 56 | // Separate initialization method for static metadata |
| 57 | int initStaticInfo(); |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 58 | // Reuse a stream already created by this device |
| 59 | Stream *reuseStream(camera3_stream_t *astream); |
| 60 | // Destroy all streams in a stream array, and the array itself |
| 61 | void destroyStreams(Stream **array, int count); |
| 62 | // Verify a set of streams is valid in aggregate |
| 63 | bool isValidStreamSet(Stream **array, int count); |
| 64 | // Calculate usage and max_bufs of each stream |
| 65 | void setupStreams(Stream **array, int count); |
Alex Ray | bfcbd95 | 2013-03-20 13:20:02 -0700 | [diff] [blame] | 66 | // Copy new settings for re-use and clean up old settings. |
| 67 | void setSettings(const camera_metadata_t *new_settings); |
Alex Ray | 11bbeef | 2013-04-26 14:47:08 -0700 | [diff] [blame] | 68 | // Verify settings are valid for a capture |
| 69 | bool isValidCaptureSettings(const camera_metadata_t *settings); |
| 70 | // Verify settings are valid for reprocessing an input buffer |
| 71 | bool isValidReprocessSettings(const camera_metadata_t *settings); |
Alex Ray | 083315c | 2013-04-26 19:32:29 -0700 | [diff] [blame] | 72 | // Process an output buffer |
| 73 | int processCaptureBuffer(const camera3_stream_buffer_t *in, |
| 74 | camera3_stream_buffer_t *out); |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 75 | |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 76 | // Identifier used by framework to distinguish cameras |
Alex Ray | 1f8af67 | 2013-02-28 15:40:08 -0800 | [diff] [blame] | 77 | const int mId; |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 78 | // Metadata containing persistent camera characteristics |
| 79 | Metadata mMetadata; |
| 80 | // camera_metadata structure containing static characteristics |
| 81 | camera_metadata_t *mStaticInfo; |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 82 | // Busy flag indicates camera is in use |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 83 | bool mBusy; |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 84 | // Camera device operations handle shared by all devices |
| 85 | const static camera3_device_ops_t sOps; |
| 86 | // Methods used to call back into the framework |
| 87 | const camera3_callback_ops_t *mCallbackOps; |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 88 | // Lock protecting the Camera object for modifications |
| 89 | pthread_mutex_t mMutex; |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 90 | // Array of handles to streams currently in use by the device |
| 91 | Stream **mStreams; |
| 92 | // Number of streams in mStreams |
| 93 | int mNumStreams; |
Alex Ray | 89a8266 | 2013-05-28 20:32:48 -0700 | [diff] [blame^] | 94 | // Static array of standard camera settings templates |
| 95 | Metadata *mTemplates[CAMERA3_TEMPLATE_COUNT]; |
Alex Ray | bfcbd95 | 2013-03-20 13:20:02 -0700 | [diff] [blame] | 96 | // Most recent request settings seen, memoized to be reused |
| 97 | camera_metadata_t *mSettings; |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 98 | }; |
| 99 | } // namespace default_camera_hal |
| 100 | |
| 101 | #endif // CAMERA_H_ |