Eventhandler机制
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
- 点赞
- 收藏
- 关注作者
评论(0)