{"id":667,"date":"2013-07-25T09:41:07","date_gmt":"2013-07-25T01:41:07","guid":{"rendered":"http:\/\/guoh.ai\/lifelog\/?p=667"},"modified":"2013-07-25T09:41:07","modified_gmt":"2013-07-25T01:41:07","slug":"glance-at-camera-hal-2-0","status":"publish","type":"post","link":"https:\/\/guoh.ai\/lifelog\/2013\/07\/glance-at-camera-hal-2-0\/","title":{"rendered":"\u521d\u63a2Camera HAL 2.0"},"content":{"rendered":"<p>Android\u57284.2\u7684\u65f6\u5019\u5bf9Camera HAL\u505a\u4e86\u6bd4\u8f83\u5927\u7684\u6539\u52a8\uff0c\u57fa\u672c\u662f\u5e9f\u5f03\u4e86\u539f\u5148\u7684CameraHardwareInterface\uff0c\u53c8\u5f04\u4e86\u4e00\u5957\u65b0\u7684\u3002\u6240\u4ee5\u5b83\u63d0\u4f9b\u4e86\u4e24\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c\u6839\u636e\u5382\u5546\u5b9e\u73b0HAL\u7684\u7248\u672c\u5728Camera Service\u5c42\u81ea\u52a8\u52a0\u8f7d\u5bf9\u5e94\u7248\u672c\u7684fwk HAL\u3002\u76ee\u524d\u8fd9\u5757\u7684\u4ecb\u7ecd\u8fd8\u662f\u6bd4\u8f83\u5c11\uff0c\u5b9e\u73b0\u7684\u5382\u5546\u4e5f\u6bd4\u8f83\u5c11\uff0c\u5927\u6982\u6709Qualcomm\u548cSamsung\u5728\u5176platform\u4e0a\u6709\u53bb\u5b9e\u73b0\u3002<br \/>\n\u4ee5\u4e0b\u6587\u5b57\u662f\u4ee5Qualcomm\u5e73\u53f0\u4e3a\u57fa\u7840\uff0c\u5728AOSP\u4ee3\u7801\u57fa\u7840\u4e0a\u5f97\u51fa\u7684\u4e00\u4e9b\u7406\u89e3\uff0c\u5b58\u5728\u9519\u8bef\u7684\u5730\u65b9\u8bf7\u6307\u51fa\uff0c\u672c\u6587\u4e5f\u4f1a\u968f\u7740\u8fdb\u4e00\u6b65\u7684\u5b66\u4e60\u800c\u5bf9\u9519\u8bef\u7684\u5730\u65b9\u8fdb\u884c\u4fee\u6b63\uff01<\/p>\n<p>\u6211\u6709\u89c2\u770b\u8fd9\u6837\u4e00\u4e2a\u4ecb\u7ecd\u7684\u89c6\u9891(\u9898\u5916\u8bdd\uff0c\u5f00\u6302\u56fd\u5bb6\u7684\u7537\u4eba\u8bb2\u7684\u82f1\u8bed\u57fa\u672c\u542c\u4e0d\u61c2)\uff0c\u81ea\u5df1\u60f3\u6cd5\u51fa\u53bb\u770b\uff0c\u56e0\u4e3a\u89c6\u9891\u65e0\u6cd5\u4e0b\u8f7d\u4e0b\u6765\uff0c\u6240\u4ee5\u6211\u622a\u56fe\u4e86\u4e00\u4e9b\uff0c\u653e\u5728<a href=\"http:\/\/www.flickr.com\/photos\/46848122@N08\/sets\/72157634786452102\/\" target=\"_blank\">Flickr<\/a>\u4e0a\u3002<br \/>\nwww.youtube.com\/watch?v=Lald5txnoHw<br \/>\n\u4ee5\u4e0b\u662f\u4e00\u6bb5\u6709\u5173\u8fd9\u6bb5\u89c6\u9891\u4ee5\u53caHAL 2.0\u7684\u7b80\u5355\u4ecb\u7ecd<\/p>\n<blockquote><p>The Linux Foundation<br \/>\nAndroid Builders Summit 2013<br \/>\nCamera 2.0: The New Camera Hardware Interface in Android 4.2<br \/>\nBy Balwinder Kaur &#038; Ashutosh Gupta<br \/>\nSan Francisco, California<\/p>\n<p>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.<br \/>\nThe 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.<\/p><\/blockquote>\n<p>\u4ee5\u4e0b\u662f\u6211\u81ea\u5df1\u7684\u4e00\u4e9b\u7406\u89e3\u3002<\/p>\n<p>HAL2\u5982\u4f55\u540cDRV\u6c9f\u901a\u7684\uff1f<\/p>\n<p>HAL2 fwk\u548cVendor implementation\u662f\u901a\u8fc7\/path\/to\/aosp\/hardware\/qcom\/camera\/QCamera\/HAL2\/wrapper\/QualcommCamera.cpp\u6765\u7ed1\u5b9a\u7684\uff0c\u521d\u59cb\u5316\u540d\u5b57\u4e3aHMI\u7684struct\uff0c\u8fd9\u4e2a\u8ddf\u539f\u5148\u7684\u662f\u4e00\u6837\u7684\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">static hw_module_methods_t camera_module_methods = {\r\n    open: camera_device_open,\r\n};\r\n\r\nstatic hw_module_t camera_common  = {\r\n    tag: HARDWARE_MODULE_TAG,\r\n    module_api_version: CAMERA_MODULE_API_VERSION_2_0,\r\n    hal_api_version: HARDWARE_HAL_API_VERSION,\r\n    id: CAMERA_HARDWARE_MODULE_ID,\r\n    name: &quot;Qcamera&quot;,\r\n    author:&quot;Qcom&quot;,\r\n    methods: &amp;camera_module_methods,\r\n    dso: NULL,\r\n    reserved:  {0},\r\n};\r\n\r\ncamera_module_t HAL_MODULE_INFO_SYM = {\r\n    common: camera_common,\r\n    get_number_of_cameras: get_number_of_cameras,\r\n    get_camera_info: get_camera_info,\r\n};\r\n\r\ncamera2_device_ops_t camera_ops = {\r\n    set_request_queue_src_ops:           android::set_request_queue_src_ops,\r\n    notify_request_queue_not_empty:      android::notify_request_queue_not_empty,\r\n    set_frame_queue_dst_ops:             android::set_frame_queue_dst_ops,\r\n    get_in_progress_count:               android::get_in_progress_count,\r\n    flush_captures_in_progress:          android::flush_captures_in_progress,\r\n    construct_default_request:           android::construct_default_request,\r\n\r\n    allocate_stream:                     android::allocate_stream,\r\n    register_stream_buffers:             android::register_stream_buffers,\r\n    release_stream:                      android::release_stream,\r\n\r\n    allocate_reprocess_stream:           android::allocate_reprocess_stream,\r\n    allocate_reprocess_stream_from_stream: android::allocate_reprocess_stream_from_stream,\r\n    release_reprocess_stream:            android::release_reprocess_stream,\r\n\r\n    trigger_action:                      android::trigger_action,\r\n    set_notify_callback:                 android::set_notify_callback,\r\n    get_metadata_vendor_tag_ops:         android::get_metadata_vendor_tag_ops,\r\n    dump:                                android::dump,\r\n};\r\n<\/pre>\n<p>QCameraHWI\u5f53\u4e2d<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">QCameraHardwareInterface::\r\nQCameraHardwareInterface(int cameraId, int mode)\r\n                  : mCameraId(cameraId)\r\n{\r\n\r\n    cam_ctrl_dimension_t mDimension;\r\n\r\n    \/* Open camera stack! *\/\r\n    memset(&amp;mMemHooks, 0, sizeof(mm_camear_mem_vtbl_t));\r\n    mMemHooks.user_data=this;\r\n    mMemHooks.get_buf=get_buffer_hook;\r\n    mMemHooks.put_buf=put_buffer_hook;\r\n\r\n    mCameraHandle=camera_open(mCameraId, &amp;mMemHooks);\r\n    ALOGV(&quot;Cam open returned %p&quot;,mCameraHandle);\r\n    if(mCameraHandle == NULL) {\r\n        ALOGE(&quot;startCamera: cam_ops_open failed: id = %d&quot;, mCameraId);\r\n        return;\r\n    }\r\n    mCameraHandle-&gt;ops-&gt;sync(mCameraHandle-&gt;camera_handle);\r\n\r\n    mChannelId=mCameraHandle-&gt;ops-&gt;ch_acquire(mCameraHandle-&gt;camera_handle);\r\n    if(mChannelId&lt;=0)\r\n    {\r\n        ALOGE(&quot;%s:Channel aquire failed&quot;,__func__);\r\n        mCameraHandle-&gt;ops-&gt;camera_close(mCameraHandle-&gt;camera_handle);\r\n        return;\r\n    }\r\n\r\n    \/* Initialize # of frame requests the HAL is handling to zero*\/\r\n    mPendingRequests=0;\r\n}\r\n<\/pre>\n<p>\u8c03\u7528mm_camera_interface\u5f53\u4e2d\u7684camera_open()<\/p>\n<p>\u8fdb\u800c\u8c03\u7528mm_camera\u5f53\u4e2d\u7684mm_camera_open()<\/p>\n<p>\u8fd9\u91cc\u8fd8\u662f\u662f\u901a\u8fc7V4L2\u53bb\u540cDRV\u6c9f\u901a\u7684<\/p>\n<p>\u4f46\u662f\u4e3a\u4ec0\u4e48wrapper\u5f53\u4e2d\u6709\u4e00\u4e9b\u64cd\u4f5cQualcomm\u6ca1\u6709\u53bb\u5b9e\u73b0\u5462\uff1f<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">int trigger_action(const struct camera2_device *,\r\n        uint32_t trigger_id,\r\n        int32_t ext1,\r\n        int32_t ext2)\r\n{\r\n    return INVALID_OPERATION;\r\n}<\/pre>\n<p>\u6bd4\u5982\u8fd9\u4e2a\u4e0a\u9762\u7406\u8bba\u4e0a\u6765\u8bf4auto focus\u7b49\u7b49\u4e00\u4e9b\u64cd\u4f5c\u9700\u8981\u901a\u8fc7\u5b83\u6765\u89e6\u53d1\uff0c\u4f46\u662f\u5b83\u5374\u662fstub\u5b9e\u73b0\uff0c\u8fd9\u4e9b\u4e0d\u662f\u5fc5\u987b\u7684\uff0c\u8fd8\u662f\u85cf\u5728\u4e86\u67d0\u4e2a\u89d2\u843d\u6211\u6ca1\u6709\u53d1\u73b0\uff1f<\/p>\n<p>\u76ee\u524d\u7528\u7684\u662flibmmcamera_interface\u8fd8\u662flibmmcamera_interface2\uff1f<br \/>\n\u4ece\u4ee3\u7801\u770b\u5e94\u8be5\u662flibmmcamera_interface<\/p>\n<p>\u518d\u770b\u4e00\u4e2a\u5b9e\u4f8b\uff0cstart preview \u8fd9\u662f\u4e00\u4e2a\u600e\u6837\u7684\u8fc7\u7a0b\uff1f<br \/>\nCamera2Client::startPreview(&#8230;)<br \/>\nCamera2Client::startPreviewL(&#8230;)<br \/>\nStreamingProcessor::updatePreviewStream(&#8230;)<br \/>\nCamera2Device::createStream(&#8230;)<br \/>\nCamera2Device::StreamAdapter::connectToDevice(&#8230;)<br \/>\ncamera2_device_t->ops->allocate_stream(&#8230;)<\/p>\n<p>\u8fd9\u4e2aallocate_stream\u662fVendor\u5b9e\u73b0\u7684\uff0c\u5bf9\u4e8eQualcomm\u7684Camera\uff0c\u4f4d\u4e8e\/path\/to\/aosp\/hardware\/qcom\/camera\/QCamera\/HAL2\/wrapper\/QualcommCamera.cpp<\/p>\n<p>android::allocate_stream(&#8230;)<br \/>\nQCameraHardwareInterface::allocate_stream(&#8230;)<br \/>\nQCameraStream::createInstance(&#8230;)<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">QCameraStream_preview::createInstance(uint32_t CameraHandle,\r\n                        uint32_t ChannelId,\r\n                        uint32_t Width,\r\n                        uint32_t Height,\r\n                        int requestedFormat,\r\n                        mm_camera_vtbl_t *mm_ops,\r\n                        camera_mode_t mode)\r\n{\r\n  QCameraStream* pme = new QCameraStream_preview(CameraHandle,\r\n                        ChannelId,\r\n                        Width,\r\n                        Height,\r\n                        requestedFormat,\r\n                        mm_ops,\r\n                        mode);\r\n  return pme;\r\n}<\/pre>\n<p>\u5c3d\u7ba1\u8fd9\u6539\u8fdb\u76ee\u524d\u8fd8\u662f\u8fd8\u662f\u7b97\u6bd4\u8f83\u201c\u65b0\u201d\u7684\u4e00\u4e2a\u4e1c\u897f\uff0c\u4f46\u8fd9\u662f\u8d8b\u52bf\uff0c\u6240\u4ee5\u4e86\u89e3\u4e0b\u4e5f\u65e0\u59a8\uff01<br \/>\nP.S. 4.3 \u5728\u4eca\u5929\u90fd\u53d1\u5e03\u4e86\uff0c\u6211\u8fd8\u5728\u770b4.2\u7684\u4e1c\u897f\uff0c\u543c\u543c<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Android\u57284.2\u7684\u65f6\u5019\u5bf9Camera HAL\u505a\u4e86\u6bd4\u8f83\u5927\u7684\u6539\u52a8\uff0c\u57fa\u672c\u662f\u5e9f\u5f03\u4e86\u539f\u5148\u7684CameraHardwareInterface\uff0c\u53c8\u5f04\u4e86\u4e00\u5957\u65b0\u7684\u3002\u6240\u4ee5\u5b83\u63d0\u4f9b\u4e86\u4e24\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c\u6839\u636e\u5382\u5546\u5b9e\u73b0HAL\u7684\u7248\u672c\u5728Camera Service\u5c42\u81ea\u52a8\u52a0\u8f7d\u5bf9\u5e94\u7248\u672c\u7684fwk HAL\u3002\u76ee\u524d\u8fd9\u5757\u7684\u4ecb\u7ecd\u8fd8\u662f\u6bd4\u8f83\u5c11\uff0c\u5b9e\u73b0\u7684\u5382\u5546\u4e5f\u6bd4\u8f83\u5c11\uff0c\u5927\u6982\u6709Qualcomm\u548cSamsung\u5728\u5176platform\u4e0a\u6709\u53bb\u5b9e\u73b0\u3002 \u4ee5\u4e0b\u6587\u5b57\u662f\u4ee5Qualcomm\u5e73\u53f0\u4e3a\u57fa\u7840\uff0c\u5728AOSP\u4ee3\u7801\u57fa\u7840\u4e0a\u5f97\u51fa\u7684\u4e00\u4e9b\u7406\u89e3\uff0c\u5b58\u5728\u9519\u8bef\u7684\u5730\u65b9\u8bf7\u6307\u51fa\uff0c\u672c\u6587\u4e5f\u4f1a\u968f\u7740\u8fdb\u4e00\u6b65\u7684\u5b66\u4e60\u800c\u5bf9\u9519\u8bef\u7684\u5730\u65b9\u8fdb\u884c\u4fee\u6b63\uff01 \u6211\u6709\u89c2\u770b\u8fd9\u6837\u4e00\u4e2a\u4ecb\u7ecd\u7684\u89c6\u9891(\u9898\u5916\u8bdd\uff0c\u5f00\u6302\u56fd\u5bb6\u7684\u7537\u4eba\u8bb2\u7684\u82f1\u8bed\u57fa\u672c\u542c\u4e0d\u61c2)\uff0c\u81ea\u5df1\u60f3\u6cd5\u51fa\u53bb\u770b\uff0c\u56e0\u4e3a\u89c6\u9891\u65e0\u6cd5\u4e0b\u8f7d\u4e0b\u6765\uff0c\u6240\u4ee5\u6211\u622a\u56fe\u4e86\u4e00\u4e9b\uff0c\u653e\u5728Flickr\u4e0a\u3002 www.youtube.com\/watch?v=Lald5txnoHw \u4ee5\u4e0b\u662f\u4e00\u6bb5\u6709\u5173\u8fd9\u6bb5\u89c6\u9891\u4ee5\u53caHAL 2.0\u7684\u7b80\u5355\u4ecb\u7ecd The Linux Foundation Android Builders Summit 2013 Camera 2.0: The New Camera Hardware Interface in Android 4.2 By Balwinder Kaur &#038; 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 &hellip; <a href=\"https:\/\/guoh.ai\/lifelog\/2013\/07\/glance-at-camera-hal-2-0\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">\u521d\u63a2Camera HAL 2.0<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,28,34],"tags":[27],"class_list":["post-667","post","type-post","status-publish","format-standard","hentry","category-android","category-cpp","category-multimedia","tag-camera"],"_links":{"self":[{"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts\/667","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/comments?post=667"}],"version-history":[{"count":2,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts\/667\/revisions"}],"predecessor-version":[{"id":669,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts\/667\/revisions\/669"}],"wp:attachment":[{"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/media?parent=667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/categories?post=667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/tags?post=667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}