blob: a4621f84b65a2df7f4ede6ad1218b132e7acfbe7 [file] [log] [blame]
Ari Hausman-Cohen73442152016-06-08 15:50:49 -07001/*
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-Cohen3841a7f2016-07-19 17:27:52 -070019#ifndef V4L2_CAMERA_HAL_V4L2_CAMERA_H_
20#define V4L2_CAMERA_HAL_V4L2_CAMERA_H_
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070021
Ari Hausman-Cohen49925842016-06-21 14:07:58 -070022#include <array>
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070023#include <string>
Ari Hausman-Cohen49925842016-06-21 14:07:58 -070024#include <vector>
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070025
26#include <system/camera_metadata.h>
Ari Hausman-Cohen345bd3a2016-06-13 15:33:53 -070027
Ari Hausman-Cohen3841a7f2016-07-19 17:27:52 -070028#include "camera.h"
29#include "common.h"
Ari Hausman-Cohenb41aade2016-08-02 10:28:37 -070030#include "metadata/array_vector.h"
Ari Hausman-Cohen3841a7f2016-07-19 17:27:52 -070031#include "v4l2_gralloc.h"
32#include "v4l2_wrapper.h"
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070033
34namespace 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.
39class V4L2Camera : public default_camera_hal::Camera {
40public:
Ari Hausman-Cohen681eaa22016-07-21 16:28:17 -070041 // 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-Cohen73442152016-06-08 15:50:49 -070044 ~V4L2Camera();
45
46private:
Ari Hausman-Cohen681eaa22016-07-21 16:28:17 -070047 // Constructor private to allow failing on bad input.
48 // Use NewV4L2Camera instead.
Ari Hausman-Cohen9e6fd982016-08-02 16:29:53 -070049 V4L2Camera(int id, std::shared_ptr<V4L2Wrapper> v4l2_wrapper);
Ari Hausman-Cohen681eaa22016-07-21 16:28:17 -070050
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070051 // default_camera_hal::Camera virtual methods.
Ari Hausman-Cohen345bd3a2016-06-13 15:33:53 -070052 // Connect to the device: open dev nodes, etc.
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070053 int connect() override;
Ari Hausman-Cohen345bd3a2016-06-13 15:33:53 -070054 // Disconnect from the device: close dev nodes, etc.
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070055 void disconnect() override;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070056 // Initialize static camera characteristics for individual device.
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070057 int initStaticInfo(camera_metadata_t** out) override;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070058 // Initialize device info: facing, orientation, resource cost,
59 // and conflicting devices (/conflicting devices length).
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070060 void initDeviceInfo(camera_info_t* info) override;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070061 // Initialize whole device (templates/etc) when opened.
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070062 int initDevice() override;
Ari Hausman-Cohen72fddb32016-06-30 16:53:31 -070063 // 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-Cohen73442152016-06-08 15:50:49 -070070 // Verify settings are valid for a capture with this device.
Ari Hausman-Cohen900c1e32016-06-20 16:52:41 -070071 bool isValidCaptureSettings(const camera_metadata_t* settings) override;
Ari Hausman-Cohen24e541c2016-07-21 11:20:30 -070072 // 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-Cohen73442152016-06-08 15:50:49 -070078
Ari Hausman-Cohen660f8b82016-07-19 17:27:52 -070079 // V4L2 helper.
Ari Hausman-Cohen9e6fd982016-08-02 16:29:53 -070080 std::shared_ptr<V4L2Wrapper> mV4L2Device;
81 std::unique_ptr<V4L2Wrapper::Connection> mConnection;
Ari Hausman-Cohen73442152016-06-08 15:50:49 -070082
Ari Hausman-Cohen49925842016-06-21 14:07:58 -070083 bool mTemplatesInitialized;
84 int initTemplates();
85
86 // Camera characteristics.
87 bool mCharacteristicsInitialized; // If false, characteristics are invalid.
88 // Fixed characteristics.
89 float mAperture;
90 float mFilterDensity;
91 float mFocalLength;
92 int32_t mOrientation;
93 std::array<float, 2> mPhysicalSize; // {width, height}, in mm.
94 std::array<int32_t, 4> mPixelArraySize; // {xmin, ymin, width, height}.
95 uint8_t mCropType;
96 float mMaxZoom;
97 std::array<int32_t, 2> mAeCompensationRange; // {min, max}.
98 camera_metadata_rational mAeCompensationStep;
99 uint8_t mAeLockAvailable;
100 uint8_t mAwbLockAvailable;
101 uint8_t mFlashAvailable;
102 float mFocusDistance;
Ari Hausman-Cohen72fddb32016-06-30 16:53:31 -0700103 int32_t mMaxRawOutputStreams;
Ari Hausman-Cohen660f8b82016-07-19 17:27:52 -0700104 int32_t mMaxStallingOutputStreams;
105 int32_t mMaxNonStallingOutputStreams;
Ari Hausman-Cohen72fddb32016-06-30 16:53:31 -0700106 int32_t mMaxInputStreams;
107 std::vector<int32_t> mSupportedFormats;
Ari Hausman-Cohen49925842016-06-21 14:07:58 -0700108 // Variable characteristics available options.
109 std::vector<uint8_t> mAeModes;
110 std::vector<uint8_t> mAeAntibandingModes;
111 std::vector<uint8_t> mAfModes;
112 std::vector<uint8_t> mAwbModes;
113 std::vector<uint8_t> mSceneModes;
114 std::vector<uint8_t> mControlModes;
115 std::vector<uint8_t> mEffects;
116 std::vector<uint8_t> mLeds;
117 std::vector<uint8_t> mOpticalStabilizationModes;
118 std::vector<uint8_t> mVideoStabilizationModes;
119 // {format, width, height, direction} (input or output).
120 ArrayVector<int32_t, 4> mStreamConfigs;
121 // {format, width, height, duration} (duration in ns).
122 ArrayVector<int64_t, 4> mMinFrameDurations;
123 int64_t mMaxFrameDuration;
124 // {format, width, height, duration} (duration in ns).
125 ArrayVector<int64_t, 4> mStallDurations;
126 // {min, max} (in fps).
127 ArrayVector<int32_t, 2> mFpsRanges;
128
129 // Initialize characteristics and set mCharacteristicsInitialized to True.
130 int initCharacteristics();
131
Ari Hausman-Cohen73442152016-06-08 15:50:49 -0700132 DISALLOW_COPY_AND_ASSIGN(V4L2Camera);
133};
134
Ari Hausman-Cohen3841a7f2016-07-19 17:27:52 -0700135} // namespace v4l2_camera_hal
Ari Hausman-Cohen73442152016-06-08 15:50:49 -0700136
Ari Hausman-Cohen3841a7f2016-07-19 17:27:52 -0700137#endif // V4L2_CAMERA_HAL_V4L2_CAMERA_H