{"id":635,"date":"2013-07-02T14:32:36","date_gmt":"2013-07-02T06:32:36","guid":{"rendered":"http:\/\/guoh.ai\/lifelog\/?p=635"},"modified":"2013-07-12T22:52:25","modified_gmt":"2013-07-12T14:52:25","slug":"the-relation-between-android-hal-and-vendor-hal","status":"publish","type":"post","link":"https:\/\/guoh.ai\/lifelog\/2013\/07\/the-relation-between-android-hal-and-vendor-hal\/","title":{"rendered":"Android\u7684HAL\u548cVendor\u7684HAL\u5b9e\u73b0\u662f\u5982\u4f55\u5173\u8054\u8d77\u6765\u7684"},"content":{"rendered":"<p>\u4ee5TI\u7684platform\u4e3a\u4f8b\u5b50\uff0c\u4e5f\u5c31\u662f\u8fd9\u4e24\u4e2a\u6587\u4ef6<br \/>\n\/path\/to\/aosp\/frameworks\/av\/services\/camera\/libcameraservice\/CameraHardwareInterface.h<br \/>\n\u548c<br \/>\n\/path\/to\/aosp\/hardware\/ti\/omap4xxx\/camera\/CameraHal.cpp<br \/>\n\u662f\u5982\u4f55\u5173\u8054\u7684\u3002<\/p>\n<p>\u8c01\u6765\u52a0\u8f7dcamera.$platform$.so\uff0c\u8fd9\u4e2a\u662f\u771f\u6b63\u7684HAL\u7684\u5b9e\u73b0\uff0c\u91cc\u9762\u5b9e\u9645\u6700\u7ec8\u4f1a\u53bb\u8c03\u7528Driver(\u4e2d\u95f4\u900f\u8fc7rpmsg-omx1)\u3002<br \/>\n\u597d\u7a81\u7136\uff0c\u53ef\u80fd\u4f60\u73b0\u5728\u8fd8\u4e0d\u77e5\u9053camera.$platform$.so\u662f\u4ec0\u4e48\uff1f\u662f\u8fd9\u6837\u7684\uff0c\u4f46\u662f\u5230\u4f60\u770b\u5230\u540e\u9762\u4f60\u5c31\u4f1a\u53d1\u73b0Vendor\u7684HAL\u5b9e\u73b0\u662f\u5305\u6210\u4e00\u4e2aso\u6863\u7684\uff0c\u4e5f\u5c31\u662f\u8fd9\u4e2a\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">void CameraService::onFirstRef()\r\n{\r\n    BnCameraService::onFirstRef();\r\n\r\n    if (hw_get_module(CAMERA_HARDWARE_MODULE_ID,\r\n                (const hw_module_t **)&amp;mModule) &lt; 0) {\r\n        ALOGE(&quot;Could not load camera HAL module&quot;);\r\n        mNumberOfCameras = 0;\r\n    }\r\n    else {\r\n        mNumberOfCameras = mModule-&gt;get_number_of_cameras();\r\n        if (mNumberOfCameras &gt; MAX_CAMERAS) {\r\n            ALOGE(&quot;Number of cameras(%d) &gt; MAX_CAMERAS(%d).&quot;,\r\n                    mNumberOfCameras, MAX_CAMERAS);\r\n            mNumberOfCameras = MAX_CAMERAS;\r\n        }\r\n        for (int i = 0; i &lt; mNumberOfCameras; i++) {\r\n            setCameraFree(i);\r\n        }\r\n    }\r\n}&amp;#91;\/code&amp;#93;\r\n\u5728\/path\/to\/aosp\/hardware\/libhardware\/hardware.c\u5f53\u4e2d\u6709\u4e0b\u9762\u8fd9\u4e9b\u65b9\u6cd5\r\n&amp;#91;code lang=&quot;java&quot;&amp;#93;hw_get_module(const char *id, const struct hw_module_t **module) \/\/ \u8fd9\u91cc\u5b9a\u4e49\u7684\u662fhw_module_t\uff0c\u4f46\u662fVendor HAL\u5f53\u4e2d\u5b9e\u73b0\u7684\u662fcamera_module_t&amp;#91;\/code&amp;#93;\r\n\r\n&amp;#91;code lang=&quot;java&quot;&amp;#93;\/* Loop through the configuration variants looking for a module *\/\r\nfor (i=0 ; i&lt;HAL_VARIANT_KEYS_COUNT+1 ; i++) {\r\n    if (i &lt; HAL_VARIANT_KEYS_COUNT) {\r\n        if (property_get(variant_keys&amp;#91;i&amp;#93;, prop, NULL) == 0) {\r\n            continue;\r\n        }\r\n        snprintf(path, sizeof(path), &quot;%s\/%s.%s.so&quot;,\r\n                 HAL_LIBRARY_PATH2, name, prop);\r\n        if (access(path, R_OK) == 0) break;\r\n\r\n        snprintf(path, sizeof(path), &quot;%s\/%s.%s.so&quot;,\r\n                 HAL_LIBRARY_PATH1, name, prop);\r\n        if (access(path, R_OK) == 0) break;\r\n    } else {\r\n        snprintf(path, sizeof(path), &quot;%s\/%s.default.so&quot;,\r\n                 HAL_LIBRARY_PATH1, name);\r\n        if (access(path, R_OK) == 0) break;\r\n    }\r\n}&amp;#91;\/code&amp;#93;\r\n\r\n&amp;#91;code lang=&quot;java&quot;&amp;#93;static const char *variant_keys&amp;#91;&amp;#93; = {\r\n    &quot;ro.hardware&quot;,  \/* This goes first so that it can pick up a different\r\n                       file on the emulator. *\/\r\n    &quot;ro.product.board&quot;,\r\n    &quot;ro.board.platform&quot;,\r\n    &quot;ro.arch&quot;\r\n};\r\n\r\nstatic const int HAL_VARIANT_KEYS_COUNT =\r\n    (sizeof(variant_keys)\/sizeof(variant_keys&amp;#91;0&amp;#93;));\r\n&amp;#91;\/code&amp;#93;\r\n\/path\/to\/aosp\/out\/target\/product\/panda\/system\/build.prop\r\n\u8fd9\u91cc\u9762\u6709platform\u6216\u8005arch\u76f8\u5173\u7684\u6570\u636e\r\n\r\n&amp;#91;code lang=&quot;java&quot;&amp;#93;\/*\r\n * load the symbols resolving undefined symbols before\r\n * dlopen returns. Since RTLD_GLOBAL is not or&#039;d in with\r\n * RTLD_NOW the external symbols will not be global\r\n *\/\r\nhandle = dlopen(path, RTLD_NOW);\r\n\r\n\/* Get the address of the struct hal_module_info. *\/\r\nconst char *sym = HAL_MODULE_INFO_SYM_AS_STR;\r\nhmi = (struct hw_module_t *)dlsym(handle, sym);\r\nif (hmi == NULL) {\r\n    ALOGE(&quot;load: couldn&#039;t find symbol %s&quot;, sym);\r\n    status = -EINVAL;\r\n    goto done;\r\n}\r\n\r\n*pHmi = hmi; \/\/ \u52a8\u6001\u52a0\u8f7dVendor HAL\u4e4b\u540e\u8981\u8fd4\u56de\u8fd9\u4e2ahw_module_t\u7ed3\u6784\u4f53\u4f9bAndroid Service\/HAL\u5c42\u4f7f\u7528&amp;#91;\/code&amp;#93;\r\n\r\n\u8fd9\u4e2aload\u51fa\u6765\u7684HAL_MODULE_INFO_SYM_AS_STR\u662f\u4ec0\u4e48\uff1f\r\n\r\n\u5148\u770b\u5b83\u662f\u4ec0\u4e48\uff0c\u5b9a\u4e49\u4f4d\u4e8ehardware.h\u5f53\u4e2d\r\n&amp;#91;code lang=&quot;java&quot;&amp;#93;\/**\r\n * Name of the hal_module_info\r\n *\/\r\n#define HAL_MODULE_INFO_SYM         HMI\r\n\r\n\/**\r\n * Name of the hal_module_info as a string\r\n *\/\r\n#define HAL_MODULE_INFO_SYM_AS_STR  &quot;HMI&quot;&amp;#91;\/code&amp;#93;\r\n\r\n\u7406\u8bba\u4e0a\u6765\u8bf4dlsym\u5c31\u662f\u4f1a\u53bbload\u4e00\u4e2a\u540d\u5b57\u4e3a&quot;HMI&quot;\u7684\u53d8\u91cf\/\u51fd\u6570\uff0c\u4e5f\u5c31\u662f\u8bf4\u5728Vendor HAL\u5f53\u4e2d\u5fc5\u7136\u6709\u540d\u5b57\u4e3a&quot;HMI&quot;\u7684\u8fd9\u6837\u4e00\u4e2a\u4e1c\u897f\u3002\r\n\u770b\u770bhw_module_t\u7684\u5b9a\u4e49\u3002\r\n&amp;#91;code lang=&quot;java&quot;&amp;#93;\/**\r\n * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM\r\n * and the fields of this data structure must begin with hw_module_t\r\n * followed by module specific information.\r\n *\/\r\ntypedef struct hw_module_t {\r\n    \/** tag must be initialized to HARDWARE_MODULE_TAG *\/\r\n    uint32_t tag;\r\n\r\n    \/**\r\n     * The API version of the implemented module. The module owner is\r\n     * responsible for updating the version when a module interface has\r\n     * changed.\r\n     *\r\n     * The derived modules such as gralloc and audio own and manage this field.\r\n     * The module user must interpret the version field to decide whether or\r\n     * not to inter-operate with the supplied module implementation.\r\n     * For example, SurfaceFlinger is responsible for making sure that\r\n     * it knows how to manage different versions of the gralloc-module API,\r\n     * and AudioFlinger must know how to do the same for audio-module API.\r\n     *\r\n     * The module API version should include a major and a minor component.\r\n     * For example, version 1.0 could be represented as 0x0100. This format\r\n     * implies that versions 0x0100-0x01ff are all API-compatible.\r\n     *\r\n     * In the future, libhardware will expose a hw_get_module_version()\r\n     * (or equivalent) function that will take minimum\/maximum supported\r\n     * versions as arguments and would be able to reject modules with\r\n     * versions outside of the supplied range.\r\n     *\/\r\n    uint16_t module_api_version;\r\n#define version_major module_api_version\r\n    \/**\r\n     * version_major\/version_minor defines are supplied here for temporary\r\n     * source code compatibility. They will be removed in the next version.\r\n     * ALL clients must convert to the new version format.\r\n     *\/\r\n\r\n    \/**\r\n     * The API version of the HAL module interface. This is meant to\r\n     * version the hw_module_t, hw_module_methods_t, and hw_device_t\r\n     * structures and definitions.\r\n     *\r\n     * The HAL interface owns this field. Module users\/implementations\r\n     * must NOT rely on this value for version information.\r\n     *\r\n     * Presently, 0 is the only valid value.\r\n     *\/\r\n    uint16_t hal_api_version;\r\n#define version_minor hal_api_version\r\n\r\n    \/** Identifier of module *\/\r\n    const char *id;\r\n\r\n    \/** Name of this module *\/\r\n    const char *name;\r\n\r\n    \/** Author\/owner\/implementor of the module *\/\r\n    const char *author;\r\n\r\n    \/** Modules methods *\/\r\n    struct hw_module_methods_t* methods;\r\n\r\n    \/** module&#039;s dso *\/\r\n    void* dso;\r\n\r\n    \/** padding to 128 bytes, reserved for future use *\/\r\n    uint32_t reserved&amp;#91;32-7&amp;#93;;\r\n\r\n} hw_module_t;&amp;#91;\/code&amp;#93;\r\n\u5b9a\u4e49\u4f4d\u4e8ehardware.h\u5f53\u4e2d\r\n\r\n\r\n\u5bf9\u4e8eTI\u7684hardware\u6765\u8bb2\uff0cload\u7684\u5c31\u662fcamera.omap4.so(\u4e5f\u5c31\u662f\u524d\u9762\u6240\u8bf4\u7684camera.$platform$.so)\u7684\u540d\u5b57\u4e3aHMI\u7684\u7ed3\u6784\u4f53\u3002\r\n\u8fd9\u4e2a\u9700\u8981\u4ed4\u7ec6\u770b\u4e0b\u624d\u80fd\u53d1\u73b0HAL_MODULE_INFO_SYM\u5b9e\u9645\u5c31\u662fHMI\uff0chardware.h\u5f53\u4e2d\u5b9a\u4e49\u7684\u90a3\u4e2amacro\u3002\r\nHMI\u4f4d\u4e8e\r\n\/path\/to\/aosp\/hardware\/ti\/omap4xxx\/camera\/CameraHal_Module.cpp\r\n\u5f53\u4e2d\r\n&amp;#91;code lang=&quot;java&quot;&amp;#93;camera_module_t HAL_MODULE_INFO_SYM = {\r\n    common: {\r\n         tag: HARDWARE_MODULE_TAG,\r\n         version_major: 1,\r\n         version_minor: 0,\r\n         id: CAMERA_HARDWARE_MODULE_ID,\r\n         name: &quot;TI OMAP CameraHal Module&quot;,\r\n         author: &quot;TI&quot;,\r\n         methods: &amp;camera_module_methods,\r\n         dso: NULL, \/* remove compilation warnings *\/\r\n         reserved: {0}, \/* remove compilation warnings *\/\r\n    },\r\n    get_number_of_cameras: camera_get_number_of_cameras,\r\n    get_camera_info: camera_get_camera_info,\r\n};&amp;#91;\/code&amp;#93;\r\n\u901a\u8fc7&#039;arm-eabi-objdump&#039; -t camera.omap4.so | grep &#039;HMI&#039;\r\n\u4e5f\u53ef\u4ee5\u9a8c\u8bc1\u8fd9\u4e00\u70b9\r\n\r\n\u800c\u518d\u4ed4\u7ec6\u770b\u770b\u8fd9\u4e2acommon\u5b9e\u9645\u4e0a\u5c31\u662fhw_module_t\u8fd9\u4e2a\u7ed3\u6784\u4f53\uff0c\u8fd9\u4e5f\u5c31\u5370\u8bc1\u4e86\u524d\u9762hw_module_t\u5b9a\u4e49\u7684\u5730\u65b9\u6240\u8bf4\u7684\r\n&lt;blockquote&gt;\/**\r\n * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM\r\n * and the fields of this data structure must begin with hw_module_t\r\n * followed by module specific information.\r\n *\/&lt;\/blockquote&gt;\r\n\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u7684\u662fhardware.h\u5f53\u4e2d\u5b9a\u4e49\u7684\u90fd\u662fhw_module_t\uff0c\u4f46\u662fVendor HAL\u5b9e\u73b0\u7684\u90fd\u662f\u81ea\u5df1\u7684xxx_module_t\uff0c\u6bd4\u5982\u65b9\u6cd5\u5b9a\u4e49\u7684\u7c7b\u578b\u548c\u5b9e\u9645\u7c7b\u578b\u4e0d\u4e00\u6837\uff0c\u8fd9\u4e2a\u80fd\u5de5\u4f5c\u6709\u4ec0\u4e48\u6837\u7684\u5965\u79d8\uff1f\r\n\u5176\u5b9e\u5c31\u662f\u6307\u9488\u7684\u7b2c\u4e00\u4e2a\u5730\u5740\uff0cVendor HAL\u5f53\u4e2d\u5b9a\u4e49\u7684\u7ed3\u6784\u5fc5\u987b\u8981\u6c42\u7b2c\u4e00\u4e2a\u57df\u662fhw_module_t\uff0c\u8fd9\u6837\u5730\u5740\u5c31\u53ef\u4ee5\u5bf9\u5e94\u8d77\u6765\u3002\r\n\u603b\u4e4bAndroid\u4f7f\u7528\u7684\u8fd9\u79cd\u6280\u6cd5\u9700\u8981\u7406\u89e3\uff0c\u8981\u4e0d\u7136\u90fd\u65e0\u6cd5\u77e5\u9053\u4ed6\u4eec\u4e4b\u95f4\u662f\u600e\u4e48\u4e32\u8d77\u6765\u7684\uff0c\u6307\u9488\u5f3a\u5927\uff0c\u4f46\u5c0f\u5fc3\u4f7f\u7528\uff0c\u5426\u5219\u4e5f\u53ef\u80fd\u4f24\u8eab\uff01\r\ncamera_device_t\u548chw_device_t\u4e5f\u662f\u4e00\u6837\u7684\u7528\u6cd5\uff01\r\n\r\n&#x5B;code lang=&quot;java&quot;]#define CAMERA_HARDWARE_MODULE_ID &quot;camera&quot;<\/pre>\n<p>\u5b9a\u4e49\u4f4d\u4e8ecamera_common.h\u5f53\u4e2d<\/p>\n<p>\u5176\u4ed6\u4e00\u4e9b\u4f7f\u7528\u5230\u7684\u5b8f\u4e4b\u7c7b\u7684<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">#ifndef _LINUX_LIMITS_H\r\n#define _LINUX_LIMITS_H\r\n#define NR_OPEN 1024\r\n#define NGROUPS_MAX 65536\r\n\/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS *\/\r\n#define ARG_MAX 131072\r\n#define CHILD_MAX 999\r\n#define OPEN_MAX 256\r\n#define LINK_MAX 127\r\n\/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS *\/\r\n#define MAX_CANON 255\r\n#define MAX_INPUT 255\r\n#define NAME_MAX 255\r\n#define PATH_MAX 4096\r\n\/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS *\/\r\n#define PIPE_BUF 4096\r\n#define XATTR_NAME_MAX 255\r\n#define XATTR_SIZE_MAX 65536\r\n#define XATTR_LIST_MAX 65536\r\n\/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS *\/\r\n#define RTSIG_MAX 32\r\n#endif\r\n<\/pre>\n<p>\u5bf9\u4e8eCamera HAL\u6765\u8bf4\uff0c\u4f60\u9700\u8981\u627e\u5230<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">typedef struct camera_device {\r\n    \/**\r\n     * camera_device.common.version must be in the range\r\n     * HARDWARE_DEVICE_API_VERSION(0,0)-(1,FF). CAMERA_DEVICE_API_VERSION_1_0 is\r\n     * recommended.\r\n     *\/\r\n    hw_device_t common;\r\n    camera_device_ops_t *ops;\r\n    void *priv;\r\n} camera_device_t;<\/pre>\n<p>\u4f4d\u4e8ecamera.h\u5f53\u4e2d<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">typedef struct camera_module {\r\n    hw_module_t common;\r\n    int (*get_number_of_cameras)(void);\r\n    int (*get_camera_info)(int camera_id, struct camera_info *info);\r\n} camera_module_t;<\/pre>\n<p>\u4f4d\u4e8ecamera_common.h\u5f53\u4e2d<\/p>\n<p>\u626b\u5e73\u8fd9\u4e9b\u969c\u788d\u4e4b\u540e\uff0c\u540e\u9762\u5c31\u4f1a\u987a\u5229\u591a\u4e86\u3002<br \/>\n\u6bd4\u5982takePicture\u8fd9\u4e2a\u52a8\u4f5c\uff0c\u5728CameraHal_Module\u5f53\u4e2d\u4f1a\u88ab\u4e8eCameraHal\u5173\u8054\u8d77\u6765\uff0c\u4e0a\u5c42\u8c03\u7528\u5c31\u4f1a\u8fdb\u5165\u5230CameraHal\u5f53\u4e2d\u5bf9\u5e94\u7684\u65b9\u6cd5<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">status_t CameraHal::takePicture( )\r\n{\r\n    status_t ret = NO_ERROR;\r\n    CameraFrame frame;\r\n    CameraAdapter::BuffersDescriptor desc;\r\n    int burst;\r\n    const char *valstr = NULL;\r\n    unsigned int bufferCount = 1;\r\n\r\n    Mutex::Autolock lock(mLock);\r\n\r\n#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS\r\n\r\n    gettimeofday(&amp;mStartCapture, NULL);\r\n\r\n#endif\r\n\r\n    LOG_FUNCTION_NAME;\r\n\r\n    if(!previewEnabled() &amp;&amp; !mDisplayPaused)\r\n        {\r\n        LOG_FUNCTION_NAME_EXIT;\r\n        CAMHAL_LOGEA(&quot;Preview not started...&quot;);\r\n        return NO_INIT;\r\n        }\r\n\r\n    \/\/ return error if we are already capturing\r\n    if ( (mCameraAdapter-&gt;getState() == CameraAdapter::CAPTURE_STATE &amp;&amp;\r\n          mCameraAdapter-&gt;getNextState() != CameraAdapter::PREVIEW_STATE) ||\r\n         (mCameraAdapter-&gt;getState() == CameraAdapter::VIDEO_CAPTURE_STATE &amp;&amp;\r\n          mCameraAdapter-&gt;getNextState() != CameraAdapter::VIDEO_STATE) ) {\r\n        CAMHAL_LOGEA(&quot;Already capturing an image...&quot;);\r\n        return NO_INIT;\r\n    }\r\n\r\n    \/\/ we only support video snapshot if we are in video mode (recording hint is set)\r\n    valstr = mParameters.get(TICameraParameters::KEY_CAP_MODE);\r\n    if ( (mCameraAdapter-&gt;getState() == CameraAdapter::VIDEO_STATE) &amp;&amp;\r\n         (valstr &amp;&amp; strcmp(valstr, TICameraParameters::VIDEO_MODE)) ) {\r\n        CAMHAL_LOGEA(&quot;Trying to capture while recording without recording hint set...&quot;);\r\n        return INVALID_OPERATION;\r\n    }\r\n\r\n    if ( !mBracketingRunning )\r\n        {\r\n\r\n         if ( NO_ERROR == ret )\r\n            {\r\n            burst = mParameters.getInt(TICameraParameters::KEY_BURST);\r\n            }\r\n\r\n         \/\/Allocate all buffers only in burst capture case\r\n         if ( burst &gt; 1 )\r\n             {\r\n             bufferCount = CameraHal::NO_BUFFERS_IMAGE_CAPTURE;\r\n             if ( NULL != mAppCallbackNotifier.get() )\r\n                 {\r\n                 mAppCallbackNotifier-&gt;setBurst(true);\r\n                 }\r\n             }\r\n         else\r\n             {\r\n             if ( NULL != mAppCallbackNotifier.get() )\r\n                 {\r\n                 mAppCallbackNotifier-&gt;setBurst(false);\r\n                 }\r\n             }\r\n\r\n        \/\/ \u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u6211\u4eec\u6b63\u5e38\u62cd\u7167\uff0cpreview\u5c31\u4f1astop\u4f4f\uff0c\u62cd\u5b8c\u4e00\u5f20\u4e4b\u540e\u9700\u8981\u53bbstartPreview\r\n        \/\/ pause preview during normal image capture\r\n        \/\/ do not pause preview if recording (video state)\r\n        if (NO_ERROR == ret &amp;&amp;\r\n                NULL != mDisplayAdapter.get() &amp;&amp;\r\n                burst &lt; 1) {\r\n            if (mCameraAdapter-&gt;getState() != CameraAdapter::VIDEO_STATE) {\r\n                mDisplayPaused = true;\r\n                mPreviewEnabled = false;\r\n                ret = mDisplayAdapter-&gt;pauseDisplay(mDisplayPaused);\r\n                \/\/ since preview is paused we should stop sending preview frames too\r\n                if(mMsgEnabled &amp; CAMERA_MSG_PREVIEW_FRAME) {\r\n                    mAppCallbackNotifier-&gt;disableMsgType (CAMERA_MSG_PREVIEW_FRAME);\r\n                }\r\n            }\r\n\r\n#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS\r\n            mDisplayAdapter-&gt;setSnapshotTimeRef(&amp;mStartCapture);\r\n#endif\r\n        }\r\n\r\n        \/\/ if we taking video snapshot...\r\n        if ((NO_ERROR == ret) &amp;&amp; (mCameraAdapter-&gt;getState() == CameraAdapter::VIDEO_STATE)) {\r\n            \/\/ enable post view frames if not already enabled so we can internally\r\n            \/\/ save snapshot frames for generating thumbnail\r\n            if((mMsgEnabled &amp; CAMERA_MSG_POSTVIEW_FRAME) == 0) {\r\n                mAppCallbackNotifier-&gt;enableMsgType(CAMERA_MSG_POSTVIEW_FRAME);\r\n            }\r\n        }\r\n\r\n        if ( (NO_ERROR == ret) &amp;&amp; (NULL != mCameraAdapter) )\r\n            {\r\n            if ( NO_ERROR == ret )\r\n                ret = mCameraAdapter-&gt;sendCommand(CameraAdapter::CAMERA_QUERY_BUFFER_SIZE_IMAGE_CAPTURE,\r\n                                                  ( int ) &amp;frame,\r\n                                                  bufferCount);\r\n\r\n            if ( NO_ERROR != ret )\r\n                {\r\n                CAMHAL_LOGEB(&quot;CAMERA_QUERY_BUFFER_SIZE_IMAGE_CAPTURE returned error 0x%x&quot;, ret);\r\n                }\r\n            }\r\n\r\n        if ( NO_ERROR == ret )\r\n            {\r\n            mParameters.getPictureSize(( int * ) &amp;frame.mWidth,\r\n                                       ( int * ) &amp;frame.mHeight);\r\n\r\n            \/\/ \u5206\u914dbuffer\r\n            ret = allocImageBufs(frame.mWidth,\r\n                                 frame.mHeight,\r\n                                 frame.mLength,\r\n                                 mParameters.getPictureFormat(),\r\n                                 bufferCount);\r\n            if ( NO_ERROR != ret )\r\n                {\r\n                CAMHAL_LOGEB(&quot;allocImageBufs returned error 0x%x&quot;, ret);\r\n                }\r\n            }\r\n\r\n        if (  (NO_ERROR == ret) &amp;&amp; ( NULL != mCameraAdapter ) )\r\n            {\r\n            desc.mBuffers = mImageBufs;\r\n            desc.mOffsets = mImageOffsets;\r\n            desc.mFd = mImageFd;\r\n            desc.mLength = mImageLength;\r\n            desc.mCount = ( size_t ) bufferCount;\r\n            desc.mMaxQueueable = ( size_t ) bufferCount;\r\n\r\n            ret = mCameraAdapter-&gt;sendCommand(CameraAdapter::CAMERA_USE_BUFFERS_IMAGE_CAPTURE,\r\n                                              ( int ) &amp;desc);\r\n            }\r\n        }\r\n\r\n    if ( ( NO_ERROR == ret ) &amp;&amp; ( NULL != mCameraAdapter ) )\r\n        {\r\n\r\n#if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS\r\n\r\n         \/\/pass capture timestamp along with the camera adapter command\r\n        ret = mCameraAdapter-&gt;sendCommand(CameraAdapter::CAMERA_START_IMAGE_CAPTURE,  (int) &amp;mStartCapture);\r\n\r\n#else\r\n\r\n        ret = mCameraAdapter-&gt;sendCommand(CameraAdapter::CAMERA_START_IMAGE_CAPTURE);\r\n\r\n#endif\r\n\r\n        }\r\n\r\n    return ret;\r\n}<\/pre>\n<p>\u7ecf\u8fc7BaseCameraAdapter(\u8fd9\u4e2a\u5f53\u4e2d\u7684takePicture\u5b9e\u73b0\u53ea\u662fStub)\u4f1a\u5230<br \/>\nstatus_t OMXCameraAdapter::takePicture()\uff0c\u7136\u540e\u4f1a\u5c06\u8be5\u52a8\u4f5c\u52a0\u5165\u5230Command\u961f\u5217\u5f53\u4e2d\u53bb\u6267\u884c\uff0c\u6700\u7ec8\u5b9e\u73b0\u5728OMXCapture::startImageCapture()\u5f53\u4e2d\u3002<br \/>\n\u8fd9\u91cc\u5c31\u4f1a\u900f\u8fc7OMX_FillThisBuffer\u538b\u5165buffer\u5230capture port\uff0c\u5f53capture\u5b8c\u6210\u4e4b\u540e\u4f1a\u6536\u5230FillBufferDone\u8fd9\u4e2acallback\uff0c\u8fdb\u5165\u56de\u8c03\u51fd\u6570\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">OMX_ERRORTYPE OMXCameraAdapter::OMXCameraGetHandle(OMX_HANDLETYPE *handle, OMX_PTR pAppData )\r\n{\r\n    OMX_ERRORTYPE eError = OMX_ErrorUndefined;\r\n\r\n    for ( int i = 0; i &lt; 5; ++i ) {\r\n        if ( i &gt; 0 ) {\r\n            \/\/ sleep for 100 ms before next attempt\r\n            usleep(100000);\r\n        }\r\n\r\n        \/\/ setup key parameters to send to Ducati during init\r\n        OMX_CALLBACKTYPE oCallbacks;\r\n\r\n        \/\/ initialize the callback handles \/\/ \u6ce8\u518ccallback\r\n        oCallbacks.EventHandler    = android::OMXCameraAdapterEventHandler;\r\n        oCallbacks.EmptyBufferDone = android::OMXCameraAdapterEmptyBufferDone;\r\n        oCallbacks.FillBufferDone  = android::OMXCameraAdapterFillBufferDone;\r\n\r\n        \/\/ get handle\r\n        eError = OMX_GetHandle(handle, (OMX_STRING)&quot;OMX.TI.DUCATI1.VIDEO.CAMERA&quot;, pAppData, &amp;oCallbacks);\r\n        \/\/ \u6ce8\u610f\u8fd9\u4e2alibrary\uff0c\u5b9e\u9645\u5c31\u662f\/path\/to\/aosp\/hardware\/ti\/omap4xxx\/domx\/omx_proxy_component\/omx_camera\/src\/omx_proxy_camera.c\r\n        \/\/ \u6700\u7ec8\u901a\u8fc7pRPCCtx-&gt;fd_omx = open(&quot;\/dev\/rpmsg-omx1&quot;, O_RDWR);\u8ddf\u5e95\u5c42\u4ea4\u4e92\r\n        if ( eError == OMX_ErrorNone ) {\r\n            return OMX_ErrorNone;\r\n        }\r\n\r\n        CAMHAL_LOGEB(&quot;OMX_GetHandle() failed, error: 0x%x&quot;, eError);\r\n    }\r\n\r\n    *handle = 0;\r\n    return eError;\r\n}<\/pre>\n<p>\u6709\u4e86\u56de\u8c03\u51fd\u6570\u5c31\u4f1a\u4e00\u76f4\u5f80\u4e0a\u5c42\u4f20\uff0c\u6700\u7ec8\u5c31\u7528\u6237\u5c31\u5f97\u5230\u4e86\u62cd\u6444\u7684\u7167\u7247\u6570\u636e\u3002<br \/>\nCameraAdapter_Factory(size_t sensor_index)\u5728OMXCameraAdapter\u5f53\u4e2d\u3002<\/p>\n<p>\u53e6\u5916TI Omap\u8fd8\u6709\u5b9e\u73b0\u4e00\u5957\u901a\u8fc7V4L2\u4ea4\u4e92\u7684\u65b9\u5f0f\uff0c\u53ea\u662f\u9ed8\u8ba4\u6ca1\u6709\u542f\u7528\u3002<br \/>\n\u5b83\u662f\u7ecf\u8fc7V4LCameraAdapter::UseBuffersPreview<br \/>\n\u6700\u7ec8\u4f1a\u8d70\u5411V4L2\u4e2d\u53bb<\/p>\n<p>\u800cCameraAdapter_Factory()\u5728V4LCameraAdapter\u5f53\u4e2d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5TI\u7684platform\u4e3a\u4f8b\u5b50\uff0c\u4e5f\u5c31\u662f\u8fd9\u4e24\u4e2a\u6587\u4ef6 \/path\/to\/aosp\/frameworks\/av\/services\/camera\/libcameraservice\/CameraHardwareInterface.h \u548c \/path\/to\/aosp\/hardware\/ti\/omap4xxx\/camera\/CameraHal.cpp \u662f\u5982\u4f55\u5173\u8054\u7684\u3002 \u8c01\u6765\u52a0\u8f7dcamera.$platform$.so\uff0c\u8fd9\u4e2a\u662f\u771f\u6b63\u7684HAL\u7684\u5b9e\u73b0\uff0c\u91cc\u9762\u5b9e\u9645\u6700\u7ec8\u4f1a\u53bb\u8c03\u7528Driver(\u4e2d\u95f4\u900f\u8fc7rpmsg-omx1)\u3002 \u597d\u7a81\u7136\uff0c\u53ef\u80fd\u4f60\u73b0\u5728\u8fd8\u4e0d\u77e5\u9053camera.$platform$.so\u662f\u4ec0\u4e48\uff1f\u662f\u8fd9\u6837\u7684\uff0c\u4f46\u662f\u5230\u4f60\u770b\u5230\u540e\u9762\u4f60\u5c31\u4f1a\u53d1\u73b0Vendor\u7684HAL\u5b9e\u73b0\u662f\u5305\u6210\u4e00\u4e2aso\u6863\u7684\uff0c\u4e5f\u5c31\u662f\u8fd9\u4e2a\u3002 void CameraService::onFirstRef() { BnCameraService::onFirstRef(); if (hw_get_module(CAMERA_HARDWARE_MODULE_ID, (const hw_module_t **)&amp;mModule) &lt; 0) { ALOGE(&quot;Could not load camera HAL module&quot;); mNumberOfCameras = 0; } else { mNumberOfCameras = mModule-&gt;get_number_of_cameras(); if (mNumberOfCameras &gt; MAX_CAMERAS) { ALOGE(&quot;Number of cameras(%d) &gt; MAX_CAMERAS(%d).&quot;, mNumberOfCameras, MAX_CAMERAS); mNumberOfCameras = MAX_CAMERAS; } for (int i = 0; &hellip; <a href=\"https:\/\/guoh.ai\/lifelog\/2013\/07\/the-relation-between-android-hal-and-vendor-hal\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Android\u7684HAL\u548cVendor\u7684HAL\u5b9e\u73b0\u662f\u5982\u4f55\u5173\u8054\u8d77\u6765\u7684<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_gfmr_meta_descriptions":[],"_gfmr_multilingual_taxonomy_terms":[],"footnotes":""},"categories":[7,28,34],"tags":[27],"class_list":["post-635","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\/635","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=635"}],"version-history":[{"count":5,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts\/635\/revisions"}],"predecessor-version":[{"id":654,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts\/635\/revisions\/654"}],"wp:attachment":[{"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/media?parent=635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/categories?post=635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/tags?post=635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}