2016-06-09 00:50:49 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Loosely based on hardware/libhardware/modules/camera/ExampleCamera.h
|
|
|
|
|
|
|
|
#ifndef V4L2_CAMERA_H
|
|
|
|
#define V4L2_CAMERA_H
|
|
|
|
|
2016-06-21 23:07:58 +02:00
|
|
|
#include <array>
|
2016-06-09 00:50:49 +02:00
|
|
|
#include <string>
|
2016-06-21 23:07:58 +02:00
|
|
|
#include <vector>
|
2016-06-09 00:50:49 +02:00
|
|
|
|
2016-06-14 00:33:53 +02:00
|
|
|
#include <nativehelper/ScopedFd.h>
|
2016-06-09 00:50:49 +02:00
|
|
|
#include <system/camera_metadata.h>
|
2016-06-14 00:33:53 +02:00
|
|
|
|
2016-06-21 23:07:58 +02:00
|
|
|
#include "ArrayVector.h"
|
2016-06-09 00:50:49 +02:00
|
|
|
#include "Camera.h"
|
|
|
|
#include "Common.h"
|
2016-07-21 20:08:24 +02:00
|
|
|
#include "V4L2Gralloc.h"
|
2016-06-09 00:50:49 +02:00
|
|
|
|
|
|
|
namespace v4l2_camera_hal {
|
|
|
|
// V4L2Camera is a specific V4L2-supported camera device. The Camera object
|
|
|
|
// contains all logic common between all cameras (e.g. front and back cameras),
|
|
|
|
// while a specific camera device (e.g. V4L2Camera) holds all specific
|
|
|
|
// metadata and logic about that device.
|
|
|
|
class V4L2Camera : public default_camera_hal::Camera {
|
|
|
|
public:
|
|
|
|
V4L2Camera(int id, const std::string path);
|
|
|
|
~V4L2Camera();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// default_camera_hal::Camera virtual methods.
|
2016-06-14 00:33:53 +02:00
|
|
|
// Connect to the device: open dev nodes, etc.
|
2016-06-21 01:52:41 +02:00
|
|
|
int connect() override;
|
2016-06-14 00:33:53 +02:00
|
|
|
// Disconnect from the device: close dev nodes, etc.
|
2016-06-21 01:52:41 +02:00
|
|
|
void disconnect() override;
|
2016-06-09 00:50:49 +02:00
|
|
|
// Initialize static camera characteristics for individual device.
|
2016-06-21 01:52:41 +02:00
|
|
|
int initStaticInfo(camera_metadata_t** out) override;
|
2016-06-09 00:50:49 +02:00
|
|
|
// Initialize device info: facing, orientation, resource cost,
|
|
|
|
// and conflicting devices (/conflicting devices length).
|
2016-06-21 01:52:41 +02:00
|
|
|
void initDeviceInfo(camera_info_t* info) override;
|
2016-06-09 00:50:49 +02:00
|
|
|
// Initialize whole device (templates/etc) when opened.
|
2016-06-21 01:52:41 +02:00
|
|
|
int initDevice() override;
|
2016-07-01 01:53:31 +02:00
|
|
|
// Verify stream configuration is device-compatible.
|
|
|
|
bool isSupportedStreamSet(default_camera_hal::Stream** streams,
|
|
|
|
int count, uint32_t mode) override;
|
|
|
|
// Set up the device for a stream, and get the maximum number of
|
|
|
|
// buffers that stream can handle (max_buffers is an output parameter).
|
|
|
|
int setupStream(default_camera_hal::Stream* stream,
|
|
|
|
uint32_t* max_buffers) override;
|
2016-06-09 00:50:49 +02:00
|
|
|
// Verify settings are valid for a capture with this device.
|
2016-06-21 01:52:41 +02:00
|
|
|
bool isValidCaptureSettings(const camera_metadata_t* settings) override;
|
2016-07-21 20:20:30 +02:00
|
|
|
// Enqueue a buffer to receive data from the camera.
|
|
|
|
int enqueueBuffer(const camera3_stream_buffer_t* camera_buffer) override;
|
|
|
|
// Get the shutter time and updated settings for the most recent frame.
|
|
|
|
// The metadata parameter is both an input and output; frame-specific
|
|
|
|
// result fields should be appended to what is passed in.
|
|
|
|
int getResultSettings(camera_metadata_t** metadata, uint64_t* timestamp);
|
2016-06-09 00:50:49 +02:00
|
|
|
|
2016-07-01 01:53:31 +02:00
|
|
|
// Helper functions for V4L2 functionality.
|
2016-07-21 20:20:30 +02:00
|
|
|
int streamOn();
|
|
|
|
int streamOff();
|
2016-07-01 01:53:31 +02:00
|
|
|
int setFormat(const default_camera_hal::Stream* stream);
|
|
|
|
int setupBuffers();
|
2016-07-21 20:20:30 +02:00
|
|
|
int dequeueBuffer(v4l2_buffer* buffer);
|
2016-07-01 01:53:31 +02:00
|
|
|
|
|
|
|
// HAL <-> V4L2 conversions.
|
|
|
|
uint32_t halToV4L2PixelFormat(int hal_format); // 0 for unrecognized.
|
|
|
|
int V4L2ToHalPixelFormat(uint32_t v4l2_format); // -1 for unrecognized.
|
|
|
|
|
2016-06-09 00:50:49 +02:00
|
|
|
// The camera device path. For example, /dev/video0.
|
|
|
|
const std::string mDevicePath;
|
2016-06-14 00:33:53 +02:00
|
|
|
// The opened device fd.
|
|
|
|
ScopedFd mDeviceFd;
|
2016-07-21 20:08:24 +02:00
|
|
|
// Gralloc helper.
|
|
|
|
V4L2Gralloc mGralloc;
|
2016-07-01 01:53:31 +02:00
|
|
|
// Lock protecting use of the device.
|
|
|
|
android::Mutex mDeviceLock;
|
|
|
|
// Wrapper around ioctl.
|
|
|
|
template<typename T>
|
|
|
|
int ioctlLocked(int request, T data);
|
|
|
|
|
|
|
|
// Current output stream settings.
|
2016-07-11 20:08:26 +02:00
|
|
|
uint32_t mOutStreamType;
|
2016-07-01 01:53:31 +02:00
|
|
|
uint32_t mOutStreamFormat;
|
|
|
|
uint32_t mOutStreamWidth;
|
|
|
|
uint32_t mOutStreamHeight;
|
2016-07-21 20:08:24 +02:00
|
|
|
uint32_t mOutStreamBytesPerLine;
|
2016-07-01 01:53:31 +02:00
|
|
|
uint32_t mOutStreamMaxBuffers;
|
2016-06-09 00:50:49 +02:00
|
|
|
|
2016-06-21 23:07:58 +02:00
|
|
|
bool mTemplatesInitialized;
|
|
|
|
int initTemplates();
|
|
|
|
|
|
|
|
// Camera characteristics.
|
|
|
|
bool mCharacteristicsInitialized; // If false, characteristics are invalid.
|
|
|
|
// Fixed characteristics.
|
|
|
|
float mAperture;
|
|
|
|
float mFilterDensity;
|
|
|
|
float mFocalLength;
|
|
|
|
int32_t mOrientation;
|
|
|
|
std::array<float, 2> mPhysicalSize; // {width, height}, in mm.
|
|
|
|
std::array<int32_t, 4> mPixelArraySize; // {xmin, ymin, width, height}.
|
|
|
|
uint8_t mCropType;
|
|
|
|
float mMaxZoom;
|
|
|
|
std::array<int32_t, 2> mAeCompensationRange; // {min, max}.
|
|
|
|
camera_metadata_rational mAeCompensationStep;
|
|
|
|
uint8_t mAeLockAvailable;
|
|
|
|
uint8_t mAwbLockAvailable;
|
|
|
|
uint8_t mFlashAvailable;
|
|
|
|
float mFocusDistance;
|
2016-07-01 01:53:31 +02:00
|
|
|
int32_t mMaxRawOutputStreams;
|
|
|
|
int32_t mMaxYuvOutputStreams;
|
|
|
|
int32_t mMaxJpegOutputStreams;
|
|
|
|
int32_t mMaxInputStreams;
|
|
|
|
std::vector<int32_t> mSupportedFormats;
|
2016-06-21 23:07:58 +02:00
|
|
|
// Variable characteristics available options.
|
|
|
|
std::vector<uint8_t> mAeModes;
|
|
|
|
std::vector<uint8_t> mAeAntibandingModes;
|
|
|
|
std::vector<uint8_t> mAfModes;
|
|
|
|
std::vector<uint8_t> mAwbModes;
|
|
|
|
std::vector<uint8_t> mSceneModes;
|
|
|
|
std::vector<uint8_t> mControlModes;
|
|
|
|
std::vector<uint8_t> mEffects;
|
|
|
|
std::vector<uint8_t> mLeds;
|
|
|
|
std::vector<uint8_t> mOpticalStabilizationModes;
|
|
|
|
std::vector<uint8_t> mVideoStabilizationModes;
|
|
|
|
// {format, width, height, direction} (input or output).
|
|
|
|
ArrayVector<int32_t, 4> mStreamConfigs;
|
|
|
|
// {format, width, height, duration} (duration in ns).
|
|
|
|
ArrayVector<int64_t, 4> mMinFrameDurations;
|
|
|
|
int64_t mMaxFrameDuration;
|
|
|
|
// {format, width, height, duration} (duration in ns).
|
|
|
|
ArrayVector<int64_t, 4> mStallDurations;
|
|
|
|
// {min, max} (in fps).
|
|
|
|
ArrayVector<int32_t, 2> mFpsRanges;
|
|
|
|
|
|
|
|
// Initialize characteristics and set mCharacteristicsInitialized to True.
|
|
|
|
int initCharacteristics();
|
|
|
|
|
2016-06-09 00:50:49 +02:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(V4L2Camera);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace v4l2_camera_hal
|
|
|
|
|
|
|
|
#endif // V4L2_CAMERA_H
|