Camera HAL 2.0

Android在4.2的时候对Camera HAL做了比较大的改动,基本是废弃了原先的CameraHardwareInterface,又弄了一套新的。所以它提供了两种方式实现,根据厂商实现HAL的版本在Camera Service层自动加载对应版本的fwk HAL。目前这块的介绍还是比较少,实现的厂商也比较少,大概有Qualcomm和Samsung在其platform上有去实现。
以下文字是以Qualcomm平台为基础,在AOSP代码基础上得出的一些理解,存在错误的地方请指出,本文也会随着进一步的学习而对错误的地方进行修正!

我有观看这样一个介绍的视频(题外话,开挂国家的男人讲的英语基本听不懂),自己想法出去看,因为视频无法下载下来,所以我截图了一些,放在Flickr上。
www.youtube.com/watch?v=Lald5txnoHw
以下是一段有关这段视频以及HAL 2.0的简单介绍

The Linux Foundation
Android Builders Summit 2013
Camera 2.0: The New Camera Hardware Interface in Android 4.2
By Balwinder Kaur & Ashutosh Gupta
San Francisco, California

Android 4.2 was released with a new Camera Hardware Abstraction Layer (HAL) Camera 2.0. Camera 2.0 has a big emphasis on collection and providing metadata associated with each frame. It also provides the ability to re-process streams. Although the APIs at the SDK level are yet to expose any new APIS to the end user, the Camera HAL and the Camera Service architecture has been revamped to a different architecture. This presentation provides an insight into the new architecture as well as covering some of the challenges faced in building production quality Camera HAL implementations.
The intended audience for this conference session is engineers who want to learn more about the Android Camera Internals. This talk should facilitate engineers wanting to integrate, improve or innovate using the Camera subsystem.

以下是我自己的一些理解。

HAL2如何同DRV沟通的?

HAL2 fwk和Vendor implementation是通过/path/to/aosp/hardware/qcom/camera/QCamera/HAL2/wrapper/QualcommCamera.cpp来绑定的,初始化名字为HMI的struct,这个跟原先的是一样的。

static hw_module_methods_t camera_module_methods = {
    open: camera_device_open,
};
 
static hw_module_t camera_common  = {
    tag: HARDWARE_MODULE_TAG,
    module_api_version: CAMERA_MODULE_API_VERSION_2_0,
    hal_api_version: HARDWARE_HAL_API_VERSION,
    id: CAMERA_HARDWARE_MODULE_ID,
    name: "Qcamera",
    author:"Qcom",
    methods: &camera_module_methods,
    dso: NULL,
    reserved:  {0},
};
 
camera_module_t HAL_MODULE_INFO_SYM = {
    common: camera_common,
    get_number_of_cameras: get_number_of_cameras,
    get_camera_info: get_camera_info,
};
 
camera2_device_ops_t camera_ops = {
    set_request_queue_src_ops:           android::set_request_queue_src_ops,
    notify_request_queue_not_empty:      android::notify_request_queue_not_empty,
    set_frame_queue_dst_ops:             android::set_frame_queue_dst_ops,
    get_in_progress_count:               android::get_in_progress_count,
    flush_captures_in_progress:          android::flush_captures_in_progress,
    construct_default_request:           android::construct_default_request,
 
    allocate_stream:                     android::allocate_stream,
    register_stream_buffers:             android::register_stream_buffers,
    release_stream:                      android::release_stream,
 
    allocate_reprocess_stream:           android::allocate_reprocess_stream,
    allocate_reprocess_stream_from_stream: android::allocate_reprocess_stream_from_stream,
    release_reprocess_stream:            android::release_reprocess_stream,
 
    trigger_action:                      android::trigger_action,
    set_notify_callback:                 android::set_notify_callback,
    get_metadata_vendor_tag_ops:         android::get_metadata_vendor_tag_ops,
    dump:                                android::dump,
};



QCameraHWI当中

QCameraHardwareInterface::
QCameraHardwareInterface(int cameraId, int mode)
                  : mCameraId(cameraId)
{
 
    cam_ctrl_dimension_t mDimension;
 
    /* Open camera stack! */
    memset(&mMemHooks, 0, sizeof(mm_camear_mem_vtbl_t));
    mMemHooks.user_data=this;
    mMemHooks.get_buf=get_buffer_hook;
    mMemHooks.put_buf=put_buffer_hook;
 
    mCameraHandle=camera_open(mCameraId, &mMemHooks);
    ALOGV("Cam open returned %p",mCameraHandle);
    if(mCameraHandle == NULL) {
        ALOGE("startCamera: cam_ops_open failed: id = %d", mCameraId);
        return;
    }
    mCameraHandle->ops->sync(mCameraHandle->camera_handle);
 
    mChannelId=mCameraHandle->ops->ch_acquire(mCameraHandle->camera_handle);
    if(mChannelId<=0)
    {
        ALOGE("%s:Channel aquire failed",__func__);
        mCameraHandle->ops->camera_close(mCameraHandle->camera_handle);
        return;
    }
 
    /* Initialize # of frame requests the HAL is handling to zero*/
    mPendingRequests=0;
}



调用mm_camera_interface当中的camera_open()

进而调用mm_camera当中的mm_camera_open()

这里还是是通过V4L2去同DRV沟通的

但是为什么wrapper当中有一些操作Qualcomm没有去实现呢?

int trigger_action(const struct camera2_device *,
        uint32_t trigger_id,
        int32_t ext1,
        int32_t ext2)
{
    return INVALID_OPERATION;
}



比如这个上面理论上来说auto focus等等一些操作需要通过它来触发,但是它却是stub实现,这些不是必须的,还是藏在了某个角落我没有发现?

目前用的是libmmcamera_interface还是libmmcamera_interface2?
从代码看应该是libmmcamera_interface

再看一个实例,start preview 这是一个怎样的过程?
Camera2Client::startPreview(...)
Camera2Client::startPreviewL(...)
StreamingProcessor::updatePreviewStream(...)
Camera2Device::createStream(...)
Camera2Device::StreamAdapter::connectToDevice(...)
camera2_device_t->ops->allocate_stream(...)

这个allocate_stream是Vendor实现的,对于Qualcomm的Camera,位于/path/to/aosp/hardware/qcom/camera/QCamera/HAL2/wrapper/QualcommCamera.cpp

android::allocate_stream(...)
QCameraHardwareInterface::allocate_stream(...)
QCameraStream::createInstance(...)

QCameraStream_preview::createInstance(uint32_t CameraHandle,
                        uint32_t ChannelId,
                        uint32_t Width,
                        uint32_t Height,
                        int requestedFormat,
                        mm_camera_vtbl_t *mm_ops,
                        camera_mode_t mode)
{
  QCameraStream* pme = new QCameraStream_preview(CameraHandle,
                        ChannelId,
                        Width,
                        Height,
                        requestedFormat,
                        mm_ops,
                        mode);
  return pme;
}



尽管这改进目前还是还是算比较“新”的一个东西,但这是趋势,所以了解下也无妨!
P.S. 4.3 在今天都发布了,我还在看4.2的东西,吼吼

转载于:https://my.oschina.net/jerikc/blog/215650

好的,以下是一个简单的 audio HAL 2.0 接口的示例: ```c++ #include <hardware/hardware.h> #include <hardware/audio.h> // 定义音频硬件抽象层(HAL)接口 struct audio_hw_device { struct hw_device_t common; // 添加音频通道(Audio Channel)接口 void (*register_audio_channel)(struct audio_hw_device* dev, audio_channel_t* channel); void (*unregister_audio_channel)(struct audio_hw_device* dev, audio_channel_t* channel); // 保留音频 HAL 1.0 接口 int (*set_voice_volume)(struct audio_hw_device* dev, float volume); int (*set_master_volume)(struct audio_hw_device* dev, float volume); int (*set_mode)(struct audio_hw_device* dev, audio_mode_t mode); int (*set_mic_mute)(struct audio_hw_device* dev, bool state); int (*set_parameters)(struct audio_hw_device* dev, const char* kvpairs); char* (*get_parameters)(struct audio_hw_device* dev, const char* keys); int (*set_input_device)(struct audio_hw_device* dev, audio_devices_t device); int (*set_output_device)(struct audio_hw_device* dev, audio_devices_t device); int (*init_check)(const struct audio_hw_device* dev); }; // 定义音频通道(Audio Channel)接口 struct audio_channel { audio_channel_handle_t handle; void (*set_config)(struct audio_channel* channel, audio_config_t* config); void (*get_config)(struct audio_channel* channel, audio_config_t* config); }; // 定义音频硬件抽象层(HAL)模块 struct audio_module { struct hw_module_t common; }; // 定义音频硬件抽象层(HAL)模块方法 struct audio_module_methods { int (*open)(const struct hw_module_t* module, const char* name, struct hw_device_t** device); int (*close)(struct hw_device_t* device); }; // 定义音频硬件抽象层(HAL)模块实例 struct audio_module HAL_MODULE_INFO_SYM = { .common = { .tag = HARDWARE_MODULE_TAG, .module_api_version = AUDIO_MODULE_API_VERSION_2_0, // 升级到音频模块 API 版本 2.0 .hal_api_version = HARDWARE_HAL_API_VERSION, .id = "audio.default", .name = "Default audio HW HAL", .author = "The Android Open Source Project", .methods = &audio_module_methods, }, }; // 定义音频硬件抽象层(HAL)模块方法实现 static struct audio_hw_device* open_audio_device(const struct hw_module_t* module, const char* name, uint32_t device) { struct audio_hw_device* dev; dev = (struct audio_hw_device*)calloc(1, sizeof(struct audio_hw_device)); dev->common.tag = HARDWARE_DEVICE_TAG; dev->common.version = AUDIO_DEVICE_API_VERSION_2_0; // 升级到音频设备 API 版本 2.0 dev->common.module = (struct hw_module_t*)module; dev->register_audio_channel = NULL; dev->unregister_audio_channel = NULL; dev->set_voice_volume = NULL; dev->set_master_volume = NULL; dev->set_mode = NULL; dev->set_mic_mute = NULL; dev->set_parameters = NULL; dev->get_parameters = NULL; dev->set_input_device = NULL; dev->set_output_device = NULL; dev->init_check = NULL; return dev; } static int close_audio_device(struct audio_hw_device* dev) { free(dev); return 0; } static struct audio_module_methods audio_module_methods = { .open = open_audio_device, .close = close_audio_device, }; ``` 这段代码演示了如何定义一个简单的 audio HAL 2.0 接口,它在 audio HAL 1.0 接口的基础上新增了音频通道(Audio Channel)接口。通过音频通道接口,音频 HAL 驱动程序可以管理多个音频通道,每个通道可以使用不同的音频格式和采样率。这样,音频 HAL 驱动程序可以更灵活地处理音频数据,提高音频性能。在实现音频 HAL 2.0 接口时,需要注意兼容性问题,以确保它与 Android 系统的其他组件正常运行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值