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 | // Loosely based on hardware/libhardware/modules/camera/ExampleCamera.h |
| 18 | |
Ari Hausman-Cohen | 3841a7f | 2016-07-19 17:27:52 -0700 | [diff] [blame] | 19 | #ifndef V4L2_CAMERA_HAL_V4L2_CAMERA_H_ |
| 20 | #define V4L2_CAMERA_HAL_V4L2_CAMERA_H_ |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 21 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 22 | #include <array> |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 23 | #include <string> |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 24 | #include <vector> |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 25 | |
| 26 | #include <system/camera_metadata.h> |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 27 | |
Ari Hausman-Cohen | 3841a7f | 2016-07-19 17:27:52 -0700 | [diff] [blame] | 28 | #include "camera.h" |
| 29 | #include "common.h" |
Ari Hausman-Cohen | b41aade | 2016-08-02 10:28:37 -0700 | [diff] [blame^] | 30 | #include "metadata/array_vector.h" |
Ari Hausman-Cohen | 3841a7f | 2016-07-19 17:27:52 -0700 | [diff] [blame] | 31 | #include "v4l2_gralloc.h" |
| 32 | #include "v4l2_wrapper.h" |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 33 | |
| 34 | namespace v4l2_camera_hal { |
| 35 | // V4L2Camera is a specific V4L2-supported camera device. The Camera object |
| 36 | // contains all logic common between all cameras (e.g. front and back cameras), |
| 37 | // while a specific camera device (e.g. V4L2Camera) holds all specific |
| 38 | // metadata and logic about that device. |
| 39 | class V4L2Camera : public default_camera_hal::Camera { |
| 40 | public: |
Ari Hausman-Cohen | 681eaa2 | 2016-07-21 16:28:17 -0700 | [diff] [blame] | 41 | // Use this method to create V4L2Camera objects. Functionally equivalent |
| 42 | // to "new V4L2Camera", except that it may return nullptr in case of failure. |
| 43 | static V4L2Camera* NewV4L2Camera(int id, const std::string path); |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 44 | ~V4L2Camera(); |
| 45 | |
| 46 | private: |
Ari Hausman-Cohen | 681eaa2 | 2016-07-21 16:28:17 -0700 | [diff] [blame] | 47 | // Constructor private to allow failing on bad input. |
| 48 | // Use NewV4L2Camera instead. |
Ari Hausman-Cohen | 660f8b8 | 2016-07-19 17:27:52 -0700 | [diff] [blame] | 49 | V4L2Camera(int id, std::unique_ptr<V4L2Wrapper> v4l2_wrapper); |
Ari Hausman-Cohen | 681eaa2 | 2016-07-21 16:28:17 -0700 | [diff] [blame] | 50 | |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 51 | // default_camera_hal::Camera virtual methods. |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 52 | // Connect to the device: open dev nodes, etc. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 53 | int connect() override; |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 54 | // Disconnect from the device: close dev nodes, etc. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 55 | void disconnect() override; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 56 | // Initialize static camera characteristics for individual device. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 57 | int initStaticInfo(camera_metadata_t** out) override; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 58 | // Initialize device info: facing, orientation, resource cost, |
| 59 | // and conflicting devices (/conflicting devices length). |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 60 | void initDeviceInfo(camera_info_t* info) override; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 61 | // Initialize whole device (templates/etc) when opened. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 62 | int initDevice() override; |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 63 | // Verify stream configuration is device-compatible. |
| 64 | bool isSupportedStreamSet(default_camera_hal::Stream** streams, |
| 65 | int count, uint32_t mode) override; |
| 66 | // Set up the device for a stream, and get the maximum number of |
| 67 | // buffers that stream can handle (max_buffers is an output parameter). |
| 68 | int setupStream(default_camera_hal::Stream* stream, |
| 69 | uint32_t* max_buffers) override; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 70 | // Verify settings are valid for a capture with this device. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 71 | bool isValidCaptureSettings(const camera_metadata_t* settings) override; |
Ari Hausman-Cohen | 24e541c | 2016-07-21 11:20:30 -0700 | [diff] [blame] | 72 | // Enqueue a buffer to receive data from the camera. |
| 73 | int enqueueBuffer(const camera3_stream_buffer_t* camera_buffer) override; |
| 74 | // Get the shutter time and updated settings for the most recent frame. |
| 75 | // The metadata parameter is both an input and output; frame-specific |
| 76 | // result fields should be appended to what is passed in. |
| 77 | int getResultSettings(camera_metadata_t** metadata, uint64_t* timestamp); |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 78 | |
Ari Hausman-Cohen | 660f8b8 | 2016-07-19 17:27:52 -0700 | [diff] [blame] | 79 | // V4L2 helper. |
| 80 | std::unique_ptr<V4L2Wrapper> mV4L2Device; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 81 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 82 | bool mTemplatesInitialized; |
| 83 | int initTemplates(); |
| 84 | |
| 85 | // Camera characteristics. |
| 86 | bool mCharacteristicsInitialized; // If false, characteristics are invalid. |
| 87 | // Fixed characteristics. |
| 88 | float mAperture; |
| 89 | float mFilterDensity; |
| 90 | float mFocalLength; |
| 91 | int32_t mOrientation; |
| 92 | std::array<float, 2> mPhysicalSize; // {width, height}, in mm. |
| 93 | std::array<int32_t, 4> mPixelArraySize; // {xmin, ymin, width, height}. |
| 94 | uint8_t mCropType; |
| 95 | float mMaxZoom; |
| 96 | std::array<int32_t, 2> mAeCompensationRange; // {min, max}. |
| 97 | camera_metadata_rational mAeCompensationStep; |
| 98 | uint8_t mAeLockAvailable; |
| 99 | uint8_t mAwbLockAvailable; |
| 100 | uint8_t mFlashAvailable; |
| 101 | float mFocusDistance; |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 102 | int32_t mMaxRawOutputStreams; |
Ari Hausman-Cohen | 660f8b8 | 2016-07-19 17:27:52 -0700 | [diff] [blame] | 103 | int32_t mMaxStallingOutputStreams; |
| 104 | int32_t mMaxNonStallingOutputStreams; |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 105 | int32_t mMaxInputStreams; |
| 106 | std::vector<int32_t> mSupportedFormats; |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 107 | // Variable characteristics available options. |
| 108 | std::vector<uint8_t> mAeModes; |
| 109 | std::vector<uint8_t> mAeAntibandingModes; |
| 110 | std::vector<uint8_t> mAfModes; |
| 111 | std::vector<uint8_t> mAwbModes; |
| 112 | std::vector<uint8_t> mSceneModes; |
| 113 | std::vector<uint8_t> mControlModes; |
| 114 | std::vector<uint8_t> mEffects; |
| 115 | std::vector<uint8_t> mLeds; |
| 116 | std::vector<uint8_t> mOpticalStabilizationModes; |
| 117 | std::vector<uint8_t> mVideoStabilizationModes; |
| 118 | // {format, width, height, direction} (input or output). |
| 119 | ArrayVector<int32_t, 4> mStreamConfigs; |
| 120 | // {format, width, height, duration} (duration in ns). |
| 121 | ArrayVector<int64_t, 4> mMinFrameDurations; |
| 122 | int64_t mMaxFrameDuration; |
| 123 | // {format, width, height, duration} (duration in ns). |
| 124 | ArrayVector<int64_t, 4> mStallDurations; |
| 125 | // {min, max} (in fps). |
| 126 | ArrayVector<int32_t, 2> mFpsRanges; |
| 127 | |
| 128 | // Initialize characteristics and set mCharacteristicsInitialized to True. |
| 129 | int initCharacteristics(); |
| 130 | |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 131 | DISALLOW_COPY_AND_ASSIGN(V4L2Camera); |
| 132 | }; |
| 133 | |
Ari Hausman-Cohen | 3841a7f | 2016-07-19 17:27:52 -0700 | [diff] [blame] | 134 | } // namespace v4l2_camera_hal |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 135 | |
Ari Hausman-Cohen | 3841a7f | 2016-07-19 17:27:52 -0700 | [diff] [blame] | 136 | #endif // V4L2_CAMERA_HAL_V4L2_CAMERA_H |