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 | |
| 19 | #ifndef V4L2_CAMERA_H |
| 20 | #define V4L2_CAMERA_H |
| 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 | |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 26 | #include <nativehelper/ScopedFd.h> |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 27 | #include <system/camera_metadata.h> |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 28 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame^] | 29 | #include "ArrayVector.h" |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 30 | #include "Camera.h" |
| 31 | #include "Common.h" |
| 32 | |
| 33 | namespace v4l2_camera_hal { |
| 34 | // V4L2Camera is a specific V4L2-supported camera device. The Camera object |
| 35 | // contains all logic common between all cameras (e.g. front and back cameras), |
| 36 | // while a specific camera device (e.g. V4L2Camera) holds all specific |
| 37 | // metadata and logic about that device. |
| 38 | class V4L2Camera : public default_camera_hal::Camera { |
| 39 | public: |
| 40 | V4L2Camera(int id, const std::string path); |
| 41 | ~V4L2Camera(); |
| 42 | |
| 43 | private: |
| 44 | // default_camera_hal::Camera virtual methods. |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 45 | // Connect to the device: open dev nodes, etc. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 46 | int connect() override; |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 47 | // Disconnect from the device: close dev nodes, etc. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 48 | void disconnect() override; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 49 | // Initialize static camera characteristics for individual device. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 50 | int initStaticInfo(camera_metadata_t** out) override; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 51 | // Initialize device info: facing, orientation, resource cost, |
| 52 | // and conflicting devices (/conflicting devices length). |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 53 | void initDeviceInfo(camera_info_t* info) override; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 54 | // Initialize whole device (templates/etc) when opened. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 55 | int initDevice() override; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 56 | // Verify settings are valid for a capture with this device. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 57 | bool isValidCaptureSettings(const camera_metadata_t* settings) override; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 58 | |
| 59 | // The camera device path. For example, /dev/video0. |
| 60 | const std::string mDevicePath; |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 61 | // The opened device fd. |
| 62 | ScopedFd mDeviceFd; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 63 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame^] | 64 | bool mTemplatesInitialized; |
| 65 | int initTemplates(); |
| 66 | |
| 67 | // Camera characteristics. |
| 68 | bool mCharacteristicsInitialized; // If false, characteristics are invalid. |
| 69 | // Fixed characteristics. |
| 70 | float mAperture; |
| 71 | float mFilterDensity; |
| 72 | float mFocalLength; |
| 73 | int32_t mOrientation; |
| 74 | std::array<float, 2> mPhysicalSize; // {width, height}, in mm. |
| 75 | std::array<int32_t, 4> mPixelArraySize; // {xmin, ymin, width, height}. |
| 76 | uint8_t mCropType; |
| 77 | float mMaxZoom; |
| 78 | std::array<int32_t, 2> mAeCompensationRange; // {min, max}. |
| 79 | camera_metadata_rational mAeCompensationStep; |
| 80 | uint8_t mAeLockAvailable; |
| 81 | uint8_t mAwbLockAvailable; |
| 82 | uint8_t mFlashAvailable; |
| 83 | float mFocusDistance; |
| 84 | // Variable characteristics available options. |
| 85 | std::vector<uint8_t> mAeModes; |
| 86 | std::vector<uint8_t> mAeAntibandingModes; |
| 87 | std::vector<uint8_t> mAfModes; |
| 88 | std::vector<uint8_t> mAwbModes; |
| 89 | std::vector<uint8_t> mSceneModes; |
| 90 | std::vector<uint8_t> mControlModes; |
| 91 | std::vector<uint8_t> mEffects; |
| 92 | std::vector<uint8_t> mLeds; |
| 93 | std::vector<uint8_t> mOpticalStabilizationModes; |
| 94 | std::vector<uint8_t> mVideoStabilizationModes; |
| 95 | // {format, width, height, direction} (input or output). |
| 96 | ArrayVector<int32_t, 4> mStreamConfigs; |
| 97 | // {format, width, height, duration} (duration in ns). |
| 98 | ArrayVector<int64_t, 4> mMinFrameDurations; |
| 99 | int64_t mMaxFrameDuration; |
| 100 | // {format, width, height, duration} (duration in ns). |
| 101 | ArrayVector<int64_t, 4> mStallDurations; |
| 102 | // {min, max} (in fps). |
| 103 | ArrayVector<int32_t, 2> mFpsRanges; |
| 104 | |
| 105 | // Initialize characteristics and set mCharacteristicsInitialized to True. |
| 106 | int initCharacteristics(); |
| 107 | |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 108 | DISALLOW_COPY_AND_ASSIGN(V4L2Camera); |
| 109 | }; |
| 110 | |
| 111 | } // namespace v4l2_camera_hal |
| 112 | |
| 113 | #endif // V4L2_CAMERA_H |