Eventhandler机制

举报
产品人卫朋 发表于 2021/10/29 23:02:02 2021/10/29
【摘要】 1) Eventhandle初始化: vim frameworks/base/core/java/android/hardware/Camera.java private int cameraInitVersion(int cameraId, int halVersion) {     mShutterCa...

1) Eventhandle初始化:
vim frameworks/base/core/java/android/hardware/Camera.java
private int cameraInitVersion(int cameraId, int halVersion) {
    mShutterCallback = null;
    mRawImageCallback = null;
    mJpegCallback = null;
    mPreviewCallback = null;
    mPostviewCallback = null;
    mUsingPreviewAllocation = false;
    mZoomListener = null;
    /* ### QC ADD-ONS: START */
    mCameraDataCallback = null;
    mCameraMetaDataCallback = null;
    /* ### QC ADD-ONS: END */
    Looper looper;
    if ((looper = Looper.myLooper()) != null) { //获得当前线程looper
        mEventHandler = new EventHandler(this, looper); //mEventHandler用于和looper交互
    } else if ((looper = Looper.getMainLooper()) != null) {
        mEventHandler = new EventHandler(this, looper);
    } else {
        mEventHandler = null;
    }
    return native_setup(new WeakReference<Camera>(this), cameraId, halVersion,
            ActivityThread.currentOpPackageName());
}
  2) 向线程队列发送数据:
private static void postEventFromNative(Object camera_ref, //该函数在jni中被调用(C++调用java接口函数)
                                        int what, int arg1, int arg2, Object obj)
{
    Camera c = (Camera)((WeakReference)camera_ref).get();
    if (c == null)
        return;
    if (c.mEventHandler != null) {
        Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj); //组合队列信息
        c.mEventHandler.sendMessage(m); //发送数据
    }
}
3) 接收队列数据:
private class EventHandler extends Handler
{
    private final Camera mCamera;
    public EventHandler(Camera c, Looper looper) {
        super(looper);
        mCamera = c;
    }
    @Override
    public void handleMessage(Message msg) {
        switch(msg.what) {
        …...
        case CAMERA_MSG_OBJECT_TRACKING:
            if (mObjectTrackingFWCallback != null) {
                Log.e(TAG, "jay test call back");  //将数据传递给callback函数
                mObjectTrackingFWCallback.onObjectTrackingFWCallback((ObjectTrackingResult)msg.obj, mCamera);
            }
            return;
         ……
        }
    }
}

文章来源: blog.csdn.net,作者:简一商业,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/liwei16611/article/details/51315868

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。