Android camera: android.hardware.camera2 package

2024-06-03 15:18

本文主要是介绍Android camera: android.hardware.camera2 package,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

frameworks/base/core/java/android/hardware/camera2/CameraManager.java


android.hardware.camera2包为每个连接到android device的camera device提供一个接口;
android.hardware.camera2用于取代android.hardware.Camera
The android.hardware.camera2 package provides an interface to
individual camera devices connected to an Android device. It replaces
the deprecated android.hardware.Camera class.


android.hardware.camera2把camera device建模为管道,该管道接收捕捉一帧的请求,然后输出捕捉结果metadata packet和一组输出图像buffer.
请求按顺序处理且多个请求可一次性处理。因为camera device管道包括多个阶段??
This package models a camera device as a pipeline, which takes in
input requests for capturing a single frame, captures the single image
per the request, and then outputs one capture result metadata packet,
plus a set of output image buffers for the request. The requests are
processed in-order, and multiple requests can be in flight at
once. Since the camera device is a pipeline with multiple stages,
having multiple requests in flight is required to maintain full
framerate on most Android devices.


为了枚举、查询、打开可用的camera devices, 需要获得一个android.hardware.camera2.CameraManager实例。
To enumerate, query, and open available camera devices, obtain a
android.hardware.camera2.CameraManager instance.


每个android.hardware.camera2.CameraDevice提供一系列的属性,该属性通过
android.hardware.camera2.CameraManager#getCameraCharacteristics函数获得。
Individual android.hardware.camera2.CameraDevice
provide a set of static property information that
describes the hardware device and the available settings and output
parameters for the device. This information is provided through the
android.hardware.camera2.CameraCharacteristics object, and is
available through android.hardware.camera2.CameraManager#getCameraCharacteristics


为了从camera device捕捉图像,app必须创建一个回话:Capture Session,该回话需要一组输出surface用于camera device.
该功能通过调用函数android.hardware.camera2.CameraDevice#createCaptureSession实现。
To capture or stream images from a camera device, the application
must first create a android.hardware.camera2.CameraCaptureSession camera capture session
with a set of output Surfaces for use with the camera device, with
android.hardware.camera2.CameraDevice#createCaptureSession. 


根据camera device支持的大小和格式通过函数android.hardware.camera2.params.StreamConfigurationMap配置surface.
surface可通过下面的函数获得。
Each Surface has to be pre-configured with an android.hardware.camera2.params.StreamConfigurationMap appropriate
size and format (if applicable) to match the sizes and formats
available from the camera device. A target Surface can be obtained
from a variety of classes, including 
{@link android.view.SurfaceView},
{@link android.graphics.SurfaceTexture} via
{@link android.view.Surface#Surface(SurfaceTexture)},
{@link android.media.MediaCodec}, {@link android.media.MediaRecorder},
{@link android.renderscript.Allocation}, and {@link android.media.ImageReader}.




Generally, camera preview images are sent to {android.view.SurfaceView} or {android.view.TextureView} (via its
{android.graphics.SurfaceTexture}). 
Capture of JPEG images or
RAW buffers for {android.hardware.camera2.DngCreator} can be
done with {android.media.ImageReader} with the {
android.graphics.ImageFormat#JPEG} and {
android.graphics.ImageFormat#RAW_SENSOR} formats.  


Application-driven processing of camera data in RenderScript, OpenGL ES, or directly in
managed or native code is best done through {
android.renderscript.Allocation} with a YUV {
android.renderscript.Type}, {android.graphics.SurfaceTexture},
and {android.media.ImageReader} with a {
android.graphics.ImageFormat#YUV_420_888} format, respectively.






The application then needs to construct a {
android.hardware.camera2.CaptureRequest}, which defines all the
capture parameters needed by a camera device to capture a single
image. The request also lists which of the configured output Surfaces
should be used as targets for this capture. The CameraDevice has a
{android.hardware.camera2.CameraDevice#createCaptureRequest
factory method} for creating a {
android.hardware.camera2.CaptureRequest.Builder request builder} for a
given use case, which is optimized for the Android device the
application is running on.




一旦请求构建后,该请求调用函数进行处理:one-shot(android.hardware.camera2.CameraCaptureSession#capture)
或者repeating(android.hardware.camera2.CameraCaptureSession#setRepeatingRequest).
Once the request has been set up, it can be handed to the active
capture session either for a one-shot {
android.hardware.camera2.CameraCaptureSession#capture capture} or for
an endlessly {
android.hardware.camera2.CameraCaptureSession#setRepeatingRequest
repeating} use. Both methods also have a variant that accepts a list
of requests to use as a burst capture / repeating burst. Repeating
requests have a lower priority than captures, so a request submitted
through <code>capture()</code> while there's a repeating request
configured will be captured before any new instances of the currently
repeating (burst) capture will begin capture.


请求处理后,camera device会生成一个android.hardware.camera2.TotalCaptureResult对象,
该对象包含捕捉时camera device的状态和设置;camera device也会发送image数据到输出surface.
数据的发送和输出CaptureResult是异步的。
After processing a request, the camera device will produce a {
android.hardware.camera2.TotalCaptureResult} object, which contains
information about the state of the camera device at time of capture,
and the final settings used. These may vary somewhat from the request,
if rounding or resolving contradictory parameters was necessary. The
camera device will also send a frame of image data into each of the
output {Surfaces} included in the request. These are produced
asynchronously relative to the output CaptureResult, sometimes
substantially later.

这篇关于Android camera: android.hardware.camera2 package的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1027354

相关文章

Android实现任意版本设置默认的锁屏壁纸和桌面壁纸(两张壁纸可不一致)

客户有些需求需要设置默认壁纸和锁屏壁纸  在默认情况下 这两个壁纸是相同的  如果需要默认的锁屏壁纸和桌面壁纸不一样 需要额外修改 Android13实现 替换默认桌面壁纸: 将图片文件替换frameworks/base/core/res/res/drawable-nodpi/default_wallpaper.*  (注意不能是bmp格式) 替换默认锁屏壁纸: 将图片资源放入vendo

Android平台播放RTSP流的几种方案探究(VLC VS ExoPlayer VS SmartPlayer)

技术背景 好多开发者需要遴选Android平台RTSP直播播放器的时候,不知道如何选的好,本文针对常用的方案,做个大概的说明: 1. 使用VLC for Android VLC Media Player(VLC多媒体播放器),最初命名为VideoLAN客户端,是VideoLAN品牌产品,是VideoLAN计划的多媒体播放器。它支持众多音频与视频解码器及文件格式,并支持DVD影音光盘,VCD影

android-opencv-jni

//------------------start opencv--------------------@Override public void onResume(){ super.onResume(); //通过OpenCV引擎服务加载并初始化OpenCV类库,所谓OpenCV引擎服务即是 //OpenCV_2.4.3.2_Manager_2.4_*.apk程序包,存

从状态管理到性能优化:全面解析 Android Compose

文章目录 引言一、Android Compose基本概念1.1 什么是Android Compose?1.2 Compose的优势1.3 如何在项目中使用Compose 二、Compose中的状态管理2.1 状态管理的重要性2.2 Compose中的状态和数据流2.3 使用State和MutableState处理状态2.4 通过ViewModel进行状态管理 三、Compose中的列表和滚动

Android 10.0 mtk平板camera2横屏预览旋转90度横屏拍照图片旋转90度功能实现

1.前言 在10.0的系统rom定制化开发中,在进行一些平板等默认横屏的设备开发的过程中,需要在进入camera2的 时候,默认预览图像也是需要横屏显示的,在上一篇已经实现了横屏预览功能,然后发现横屏预览后,拍照保存的图片 依然是竖屏的,所以说同样需要将图片也保存为横屏图标了,所以就需要看下mtk的camera2的相关横屏保存图片功能, 如何实现实现横屏保存图片功能 如图所示: 2.mtk

android应用中res目录说明

Android应用的res目录是一个特殊的项目,该项目里存放了Android应用所用的全部资源,包括图片、字符串、颜色、尺寸、样式等,类似于web开发中的public目录,js、css、image、style。。。。 Android按照约定,将不同的资源放在不同的文件夹中,这样可以方便的让AAPT(即Android Asset Packaging Tool , 在SDK的build-tools目

Android fill_parent、match_parent、wrap_content三者的作用及区别

这三个属性都是用来适应视图的水平或者垂直大小,以视图的内容或尺寸为基础的布局,比精确的指定视图的范围更加方便。 1、fill_parent 设置一个视图的布局为fill_parent将强制性的使视图扩展至它父元素的大小 2、match_parent 和fill_parent一样,从字面上的意思match_parent更贴切一些,于是从2.2开始,两个属性都可以使用,但2.3版本以后的建议使

Android Environment 获取的路径问题

1. 以获取 /System 路径为例 /*** Return root of the "system" partition holding the core Android OS.* Always present and mounted read-only.*/public static @NonNull File getRootDirectory() {return DIR_ANDR

Android逆向(反调,脱壳,过ssl证书脚本)

文章目录 总结 基础Android基础工具 定位关键代码页面activity定位数据包参数定位堆栈追踪 编写反调脱壳好用的脚本过ssl证书校验抓包反调的脚本打印堆栈bilibili反调的脚本 总结 暑假做了两个月的Android逆向,记录一下自己学到的东西。对于app渗透有了一些思路。 这两个月主要做的是代码分析,对于分析完后的持久化等没有学习。主要是如何反编译源码,如何找到

android系统源码12 修改默认桌面壁纸--SRO方式

1、aosp12修改默认桌面壁纸 代码路径 :frameworks\base\core\res\res\drawable-nodpi 替换成自己的图片即可,不过需要覆盖所有目录下的图片。 由于是静态修改,则需要make一下,重新编译。 2、方法二Overlay方式 由于上述方法有很大缺点,修改多了之后容易遗忘自己修改哪些文件,为此我们采用另外一种方法,使用Overlay方式。