# V4L2 Camera HALv3
The camera.v4l2 library implements a Camera HALv3 using the
Video For Linux 2 (V4L2) interface. This allows it to theoretically
work with a wide variety of devices, though the limitations of V4L2
introduce some [caveats](#V4L2-Deficiencies), causing this HAL to
not be fully spec-compliant.
## Building a Device with the HAL
To ensure the HAL is built for a device, include the following in your
`<device>.mk`:
```
USE_CAMERA_V4L2_HAL := true
PRODUCT_PACKAGES += camera.v4l2
PRODUCT_PROPERTY_OVERRIDES += ro.hardware.camera=v4l2
```
The first line ensures the V4L2 HAL module is visible to the build system.
This prevents checkbuilds on devices that don't have the necessary support
from failing. The product packages tells the build system to include the V4L2
HALv3 library in the system image. The final line tells the hardware manager
to load the V4L2 HAL instead of a default Camera HAL.
## Requirements for Using the HAL
Devices and cameras wishing to use this HAL must meet
the following requirements:
* The camera must support BGR32, YUV420, and JPEG formats.
* The gralloc and other graphics modules used by the device must use
`HAL_PIXEL_FORMAT_RGBA_8888` as the `HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED`
## Understanding the HAL Code
There are three large pieces to the V4L2 Camera HAL: the general HALv3
Camera & HAL code, the specific implementation using V4L2,
and the Metadata system.
For context, you may also wish to read some of the documentation in
libhardware/include/camera3.h about how the framework interacts with the HAL.
### Camera & HAL Interface
The camera and HAL interfaces are implemented by the Camera and
V4L2CameraHAL classes.
The V4L2CameraHAL class deals primarily with initialization of the system.
On creation, it searches /dev/video* nodes for ones with the necessary
capabilities. These are then all presented to the framework as available
for use. Further operations are passed to the individual Cameras as appropriate.
The Camera class implements the general logic for handling the camera -
opening and closing, configuring streams, preparing and tracking requests, etc.
While it handles the logistics surrounding the camera, actual image
capture and settings logic are implemented by calling down into the
[V4L2 Camera](#V4L2-Camera). The Camera (using helper classes) enforces
restrictions given in the [Metadata](#Metadata) initialized by the V4L2Camera,
such as limits on the number of in-flight requests per stream.
Notably, this means you should be able to replace the V4L2 implementation
with something else, and as long as you fill in the metadata correctly the
Camera class should "just work".
### V4L2 Specific Implementation
The V4L2Camera class is the implementation of all the capture functionality.
It includes some methods for the Camera class to verify the setup, but the
bulk of the class is the request queue. The Camera class submits CaptureRequests
as they come in and are verified. The V4L2Camera runs these through a three
stage asynchronous pipeline:
* Acceptance: the V4L2Camera accepts the request, and puts it into waiting to be
picked up by the enqueuer.
* Enqueuing: the V4L2Camera reads the request settings, applies them to the
device, takes a snapshot of the settings, and hands the buffer over to the
V4L2 driver.
* Dequeueing: A completed frame is reclaimed from the driver, and sent
back to the Camera class for final processing (validation, filling in the
result object, and sending the data back to the framework).
Much of this work is aided by the V4L2Wrapper helper class,
which provides simpler inputs and outputs around the V4L2 ioctls
based on their known use by the HAL; filling in common values automatically
and extracting the information useful to the HAL from the results.
This wrapper is also used to expose V4L2 controls to their corresponding
Metadata components.
### Metadata
The Metadata subsystem attempts to organize and simplify handling of
camera metadata (system/media/camera/docs/docs.html). At the top level
is the Metadata class and the PartialMetadataInterface. The Metadata
class provides high level interaction with the individual components -
filling the static metadata, validating, getting, and setting settings,
etc. The Metadata class passes all of these things on to the component
PartialMetadataInterfaces, each of which filter for their specific
metadata components and perform the requested task.
Some generalized metadata classes are provided to simplify common logic
for this filtering and application. At a high level, there are three
types:
* Properties: a static value.
* Controls: dynamically adjustable values, and optionally an
associated static property indicating what allowable values are.
* States: a dynamic read-only value.
The Metadata system uses further interfaces and subclasses to distinguish
the variety of different functionalities necessary for different metadata
tags.
#### Metadata Factory
This V4L2 Camera HAL implementation utilizes a metadata factory method.
This method initializes all the 100+ required metadata components for
basic HAL spec compliance. Most do nothing/report fixed values,
but a few are hooked up to the V4L2 driver.
This HAL was initially designed for use with the Raspberry Pi camera module
v2.1, so the fixed defaults are usually assigned based on that camera.
## V4L2 Deficiencies
* One stream at a time is supported. Notably, this means you must re-configure
the stream between preview and capture if they're not the same format.
This makes this HAL not backwards compatible with the Android Camera (v1) API
as many of its methods attempt to do just that; Camera2 must be used instead.
* A variety of metadata properties can't be filled in from V4L2,
such as physical properties of the camera. Thus this HAL will never be capable
of providing perfectly accurate information for all cameras it can theoretically
support.
* Android requires HALs support YUV420, JPEG, and a format of the graphics
stack's choice ("implementation defined"). Very few cameras actually support
all of these formats (so far the Raspberry Pi cameras are the only known ones),
so some form of format conversion built in to the HAL would be a useful feature
to expand the reach/usefulness of this HAL.
* V4L2 doesn't make promises about how fast settings will apply, and there's no
good way to determine what settings were in effect for a given frame. Thus,
the settings passed into requests and out with results are applied/read as
a best effort and may be incorrect.
* Many features V4L2 is capable of are not hooked up to the HAL, so the HAL
is underfeatured compared to the ideal/what is possible.
## Other Known Issues
* A variety of features are unimplemented: High speed capture,
flash torch mode, hotplugging/unplugging.
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
v4l2_camera_hal.zip (98个子文件)
v4l2_camera_hal
arc
jpeg_compressor.h 3KB
exif_utils.cpp 21KB
frame_buffer.h 3KB
image_processor.h 2KB
cached_frame.cpp 7KB
exif_utils.h 7KB
common.h 877B
frame_buffer.cpp 3KB
image_processor.cpp 18KB
cached_frame.h 3KB
jpeg_compressor.cpp 6KB
common_types.h 2KB
stream_format.h 3KB
v4l2_camera.cpp 14KB
static_properties.cpp 18KB
capture_request.cpp 2KB
format_metadata_factory_test.cpp 8KB
Android.mk 5KB
LICENSE 10KB
request_tracker.cpp 5KB
stream_format.cpp 8KB
v4l2_camera_hal.cpp 7KB
camera.h 7KB
v4l2_wrapper.h 12KB
v4l2_metadata_factory.h 1KB
metadata
boottime_state_delegate.h 1KB
v4l2_control_delegate_test.cpp 4KB
state_delegate_interface.h 1KB
slider_control_options_test.cpp 4KB
array_vector.h 2KB
state.h 3KB
partial_metadata_factory.h 11KB
property_test.cpp 5KB
map_converter_test.cpp 3KB
tagged_control_options_test.cpp 3KB
ignored_control_delegate_test.cpp 1KB
enum_converter.h 1KB
control_test.cpp 15KB
boottime_state_delegate.cpp 1KB
partial_metadata_factory_test.cpp 17KB
test_common.h 3KB
tagged_control_options.h 2KB
metadata.cpp 6KB
v4l2_control_delegate.h 2KB
scaling_converter.h 3KB
ranged_converter.h 3KB
tagged_control_delegate_test.cpp 3KB
slider_control_options.h 2KB
types.h 3KB
control_options_interface_mock.h 1KB
metadata_test.cpp 12KB
no_effect_control_delegate_test.cpp 1KB
metadata_reader_mock.h 2KB
enum_converter_test.cpp 3KB
state_test.cpp 3KB
default_option_delegate_test.cpp 2KB
partial_metadata_interface.h 3KB
enum_converter.cpp 2KB
state_delegate_interface_mock.h 1KB
metadata_reader.cpp 8KB
metadata_common.h 10KB
map_converter.h 4KB
default_option_delegate.h 2KB
control_options_interface.h 2KB
control_delegate_interface.h 2KB
default_option_delegate_mock.h 1KB
menu_control_options_test.cpp 3KB
metadata_reader.h 3KB
converter_interface_mock.h 1KB
property.h 2KB
menu_control_options.h 2KB
control.h 6KB
converter_interface.h 1KB
control_delegate_interface_mock.h 1KB
ranged_converter_test.cpp 2KB
ignored_control_delegate.h 1KB
metadata.h 2KB
metadata_reader_test.cpp 12KB
tagged_control_delegate.h 2KB
no_effect_control_delegate.h 1KB
partial_metadata_interface_mock.h 2KB
v4l2_camera.h 5KB
request_tracker_test.cpp 8KB
camera.cpp 21KB
common.h 2KB
static_properties.h 5KB
format_metadata_factory.cpp 9KB
format_metadata_factory.h 1KB
v4l2_metadata_factory.cpp 31KB
v4l2_camera_hal.h 2KB
function_thread.h 1KB
capture_request.h 2KB
static_properties_test.cpp 24KB
request_tracker.h 3KB
v4l2_wrapper_mock.h 2KB
README.md 7KB
v4l2_wrapper.cpp 100KB
NOTICE 3KB
共 98 条
- 1
资源评论
以梦为马无处可栖
- 粉丝: 204
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功