1. 程式人生 > >高通第三方演算法(單幀資料)新增流程---hal1/hal3

高通第三方演算法(單幀資料)新增流程---hal1/hal3

這篇文件寫了很久了,當時腦袋打結用的英文,懶得改成中文了,將就看下,如有錯誤請指正,謝謝吐舌頭

上圖是我總結的高通camera架構。下面介紹怎麼新增單幀的演算法,其實就是對單幀資料進行處理。

Add 3rd algorithm of singleframe:

As we known,camera consists ofthree parts:preview,capture and video。

If we want to Add 3rdalgorithm,we must find out the data callbacked to the HAL that processed by ISP。

callback file:hardware\qcom\camera\QCamera2\HAL\QCamera2HWICallbacks.cpp

Preview/Video callback:

voidQCamera2HardwareInterface::synchronous_stream_cb_routine(

       mm_camera_super_buf_t *super_frame,QCameraStream * stream,

       void *userdata)

Capture callback:

voidQCamera2HardwareInterface::zsl_channel_cb(mm_camera_super_buf_t*recvd_frame,

 void *userdata)

voidQCamera2HardwareInterface::postproc_channel_cb_routine(mm_camera_super_buf_t

*recvd_frame, void *userdata)

The key is the structure mm_camera_super_buf_t,next show the struct of it。

typedef struct {

   uint32_t camera_handle;

    uint32_tch_id;

   uint32_t num_bufs;

   uint8_t bUnlockAEC;

   uint8_t bReadyForPrepareSnapshot;

    mm_camera_buf_def_t* bufs[MAX_STREAM_NUM_IN_BUNDLE];

} mm_camera_super_buf_t;

The buffer is inside in struct mm_camera_buf_def;

typedef struct mm_camera_buf_def {

   uint32_t stream_id;

   cam_stream_type_t stream_type;

   cam_stream_buf_type buf_type;

   uint32_t buf_idx;

   uint8_t is_uv_subsampled;

   struct timespec ts;

   uint32_t frame_idx;

   union {

       mm_camera_plane_buf_def_t planes_buf;

       mm_camera_user_buf_def_t user_buf;

   };

   int fd;

void *buffer;//this stored the data of frame,we shouldoperate it

   size_t frame_len;

   void *mem_info;

   uint32_t flags;

} mm_camera_buf_def_t;

(Samplecode)Add Face Detection Algorithm:

這裡面的so檔案就是我們的演算法庫,通過dlopen函式對其進行操作。

在最開始需要定義:typedef int (*CAC_FUNC)(unsigned char *data, int width, int height);這個與演算法介面是對應的。

也需要加入標頭檔案:#include “dlfcn.h"

Position:Because realize FaceDetection just need to operate the buffer (one frame)that stored the data inthe forms of YUV420,so we can add Face Detection Algorithm everywhere in the function synchronous_stream_cb_routine。

Add algorithm step by step:

1:Realize FaceDetection。

2:The Face Detection Algorithm depend on opencv lib。Compile it to be a so file (libmy.so) linked with libopencv_java3.so, then it will be private。

3:Push the related lib to the correct dir of your machine。
haarcascade_frontalface_alt2.xml---->system/vendor/lib/haarcascade_frontalface_alt2.xml
libopencv_java3.so            ---->/system/vendor/lib/libopencv_java3.so

libmy.so                     ---->/system/vendor/lib/libmy.so

以上是跑的hal1通道,如果跑的hal3通道的話,需要設定hal3 enable。(高通自帶的相機就算開啟hal3也是跑的hal1,應該是不支援hal3的,需另裝apk)

設定命令是:adb shell setprop persist.camera.HAL3.enabled 1

Hal3的回撥檔案是:Qcamera3Channel.cpp

預覽的回撥是在:

voidQCamera3ProcessingChannel::streamCbRoutine(mm_camera_super_buf_t *super_frame,

       QCamera3Stream *stream)

拍照的回撥是在:

voidQCamera3PicChannel::streamCbRoutine(mm_camera_super_buf_t *super_frame,

                           QCamera3Stream*stream)

如上圖所示就是在預覽回撥函式裡面處理buffer,實現預覽變灰的效果。