camera callback

 
android_hardware_Camera.cpp

void JNICameraContext::notify(int32_t msgType, int32_t ext1, int32_t ext2){
    env->CallStaticVoidMethod(mCameraJClass, fields.post_event, mCameraJObjectWeak, msgType, ext1, ext2, NULL);
}


----------->

fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative", "(Ljava/lang/Object;IIILjava/lang/Object;)V");

----------->frameworks/base/core/java/android/hardware/camera.java


    private static void postEventFromNative(Object camera_ref,
                                            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);
        }
    }

----------->

   mEventHandler = new EventHandler(this, looper);

----------->
    private class EventHandler extends Handler
    {
        private Camera mCamera;

        public EventHandler(Camera c, Looper looper) {
            super(looper);
            mCamera = c;
        }

        @Override
        public void handleMessage(Message msg) {
            switch(msg.what) {
            case CAMERA_MSG_SHUTTER:
                if (mShutterCallback != null) {
                    mShutterCallback.onShutter();
                }
                return;
    .
    .
    .
        }
    }

---------->

    public final void takePicture(ShutterCallback shutter, PictureCallback raw,
            PictureCallback postview, PictureCallback jpeg) {
        mShutterCallback = shutter;
        mRawImageCallback = raw;
        mPostviewCallback = postview;
        mJpegCallback = jpeg;
        native_takePicture();
    }


--------->packages/apps/camera/src/com/android/camera/camera.java
framework层的takePicture在这里初调用。

    mCameraDevice.takePicture(mShutterCallback, mRawPictureCallback, mPostViewPictureCallback, new JpegPictureCallback(loc));

--------->

    private final ShutterCallback mShutterCallback = new ShutterCallback();

--------->

    private final class ShutterCallback
            implements android.hardware.Camera.ShutterCallback {
        public void onShutter() {
            mShutterCallbackTime = System.currentTimeMillis();
            mShutterLag = mShutterCallbackTime - mCaptureStartTime;
            Log.v(TAG, "mShutterLag = " + mShutterLag + "ms");
            clearFocusState();
        }
    }

阅读更多
个人分类: android 架构
上一篇android camera recording[转]
下一篇[OpenCore] Android的多媒体框架OpenCore介绍
想对作者说点什么? 我来说一句

CALLBACK

 static~this~callback~

drf003 drf003

2007-01-21 22:34:00

阅读数:352

没有更多推荐了,返回首页

关闭
关闭