Add frame metadata parameter to camera data_callback.

bug:4460717
Change-Id: Ib47d7d7df20af8155a719f3dabefe030893bfebc
diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java
index d6dbc15..b487764 100644
--- a/core/java/android/hardware/Camera.java
+++ b/core/java/android/hardware/Camera.java
@@ -131,7 +131,7 @@
     private static final int CAMERA_MSG_RAW_IMAGE        = 0x080;
     private static final int CAMERA_MSG_COMPRESSED_IMAGE = 0x100;
     private static final int CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x200;
-    private static final int CAMERA_MSG_FACE             = 0x400;
+    private static final int CAMERA_MSG_METADATA_FACE    = 0x400;
     private static final int CAMERA_MSG_ALL_MSGS         = 0x4FF;
 
     private int mNativeContext; // accessed by native methods
@@ -721,9 +721,9 @@
                 }
                 return;
 
-            case CAMERA_MSG_FACE:
+            case CAMERA_MSG_METADATA_FACE:
                 if (mFaceListener != null) {
-                    mFaceListener.onFaceDetection((FaceMetadata[])msg.obj, mCamera);
+                    mFaceListener.onFaceDetection((Face[])msg.obj, mCamera);
                 }
                 return;
 
@@ -1078,11 +1078,11 @@
         /**
          * Notify the listener of the detected faces in the preview frame.
          *
-         * @param faceMetadata the face information. The list is sorted by the
-         *        score. The highest score is the first element.
+         * @param faces the detected faces. The list is sorted by the score.
+         *              The highest score is the first element.
          * @param camera  the Camera service object
          */
-        void onFaceDetection(FaceMetadata[] faceMetadata, Camera camera);
+        void onFaceDetection(Face[] faces, Camera camera);
     }
 
     /**
@@ -1151,20 +1151,24 @@
     private native final void _stopFaceDetection();
 
     /**
-     * The information of a face.
+     * The information of a face from camera face detection.
      *
      * @hide
      */
-    public static class FaceMetadata {
+    public static class Face {
         /**
          * Bounds of the face. (-1000, -1000) represents the top-left of the
          * camera field of view, and (1000, 1000) represents the bottom-right of
-         * the field of view. This is supported by both hardware and software
-         * face detection.
+         * the field of view. The width and height cannot be 0 or negative. This
+         * is supported by both hardware and software face detection.
+         *
+         * <p>The direction is relative to the sensor orientation, that is, what
+         * the sensor sees. The direction is not affected by the rotation or
+         * mirroring of {@link #setDisplayOrientation(int)}.</p>
          *
          * @see #startFaceDetection(int)
          */
-        Rect face;
+        Rect rect;
 
         /**
          * The confidence level of the face. The range is 1 to 100. 100 is the
@@ -1183,20 +1187,20 @@
         int id;
 
         /**
-         * The coordinates of the center of the left eye. null if this is not
-         * supported.
+         * The coordinates of the center of the left eye. The range is -1000 to
+         * 1000. null if this is not supported.
          */
         Point leftEye;
 
         /**
-         * The coordinates of the center of the right eye. null if this is not
-         * supported.
+         * The coordinates of the center of the right eye. The range is -1000 to
+         * 1000. null if this is not supported.
          */
         Point rightEye;
 
         /**
-         * The coordinates of the center of the mouth. null if this is not
-         * supported.
+         * The coordinates of the center of the mouth. The range is -1000 to
+         * 1000. null if this is not supported.
          */
         Point mouth;
     }
diff --git a/core/jni/android_hardware_Camera.cpp b/core/jni/android_hardware_Camera.cpp
index 3328fc8..3dcaa37 100644
--- a/core/jni/android_hardware_Camera.cpp
+++ b/core/jni/android_hardware_Camera.cpp
@@ -38,7 +38,7 @@
     jfieldID    surfaceTexture;
     jfieldID    facing;
     jfieldID    orientation;
-    jfieldID    face_rectangle;
+    jfieldID    face_rect;
     jfieldID    face_score;
     jfieldID    rect_left;
     jfieldID    rect_top;
@@ -859,8 +859,8 @@
           ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID, "I", &fields.surfaceTexture },
         { "android/hardware/Camera$CameraInfo", "facing",   "I", &fields.facing },
         { "android/hardware/Camera$CameraInfo", "orientation",   "I", &fields.orientation },
-        { "android/hardware/Camera$FaceMetadata", "face", "Landroid/graphics/Rect;", &fields.face_rectangle },
-        { "android/hardware/Camera$FaceMetadata", "score", "I", &fields.face_score },
+        { "android/hardware/Camera$Face", "rect", "Landroid/graphics/Rect;", &fields.face_rect },
+        { "android/hardware/Camera$Face", "score", "I", &fields.face_score },
         { "android/graphics/Rect", "left", "I", &fields.rect_left },
         { "android/graphics/Rect", "top", "I", &fields.rect_top },
         { "android/graphics/Rect", "right", "I", &fields.rect_right },
diff --git a/services/camera/libcameraservice/CameraHardwareInterface.h b/services/camera/libcameraservice/CameraHardwareInterface.h
index 09e88c4..31544b3 100644
--- a/services/camera/libcameraservice/CameraHardwareInterface.h
+++ b/services/camera/libcameraservice/CameraHardwareInterface.h
@@ -38,6 +38,7 @@
 
 typedef void (*data_callback)(int32_t msgType,
                             const sp<IMemory> &dataPtr,
+                            camera_frame_metadata_t *metadata,
                             void* user);
 
 typedef void (*data_callback_timestamp)(nsecs_t timestamp,
@@ -442,6 +443,7 @@
 
     static void __data_cb(int32_t msg_type,
                           const camera_memory_t *data, unsigned int index,
+                          camera_frame_metadata_t *metadata,
                           void *user)
     {
         LOGV("%s", __FUNCTION__);
@@ -453,7 +455,7 @@
                  index, mem->mNumBufs);
             return;
         }
-        __this->mDataCb(msg_type, mem->mBuffers[index], __this->mCbUser);
+        __this->mDataCb(msg_type, mem->mBuffers[index], metadata, __this->mCbUser);
     }
 
     static void __data_cb_timestamp(nsecs_t timestamp, int32_t msg_type,
diff --git a/services/camera/libcameraservice/CameraHardwareStub.cpp b/services/camera/libcameraservice/CameraHardwareStub.cpp
index 07b5a37..863f19e 100644
--- a/services/camera/libcameraservice/CameraHardwareStub.cpp
+++ b/services/camera/libcameraservice/CameraHardwareStub.cpp
@@ -180,7 +180,7 @@
 
         // Notify the client of a new frame.
         if (mMsgEnabled & CAMERA_MSG_PREVIEW_FRAME)
-            mDataCb(CAMERA_MSG_PREVIEW_FRAME, buffer, mCallbackCookie);
+            mDataCb(CAMERA_MSG_PREVIEW_FRAME, buffer, NULL, mCallbackCookie);
 
         // Advance the buffer pointer.
         mCurrentPreviewFrame = (mCurrentPreviewFrame + 1) % kBufferCount;
@@ -290,14 +290,14 @@
         sp<MemoryBase> mem = new MemoryBase(mRawHeap, 0, w * h * 3 / 2);
         FakeCamera cam(w, h);
         cam.getNextFrameAsYuv420((uint8_t *)mRawHeap->base());
-        mDataCb(CAMERA_MSG_RAW_IMAGE, mem, mCallbackCookie);
+        mDataCb(CAMERA_MSG_RAW_IMAGE, mem, NULL, mCallbackCookie);
     }
 
     if (mMsgEnabled & CAMERA_MSG_COMPRESSED_IMAGE) {
         sp<MemoryHeapBase> heap = new MemoryHeapBase(kCannedJpegSize);
         sp<MemoryBase> mem = new MemoryBase(heap, 0, kCannedJpegSize);
         memcpy(heap->base(), kCannedJpeg, kCannedJpegSize);
-        mDataCb(CAMERA_MSG_COMPRESSED_IMAGE, mem, mCallbackCookie);
+        mDataCb(CAMERA_MSG_COMPRESSED_IMAGE, mem, NULL, mCallbackCookie);
     }
     return NO_ERROR;
 }
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index 96b26e7..b03649e 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -988,7 +988,7 @@
 }
 
 void CameraService::Client::dataCallback(int32_t msgType,
-        const sp<IMemory>& dataPtr, void* user) {
+        const sp<IMemory>& dataPtr, camera_frame_metadata_t *metadata, void* user) {
     LOG2("dataCallback(%d)", msgType);
 
     sp<Client> client = getClientFromCookie(user);
diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h
index c5fefb8..af7f06e 100644
--- a/services/camera/libcameraservice/CameraService.h
+++ b/services/camera/libcameraservice/CameraService.h
@@ -140,7 +140,8 @@
 
         // these are static callback functions
         static void             notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2, void* user);
-        static void             dataCallback(int32_t msgType, const sp<IMemory>& dataPtr, void* user);
+        static void             dataCallback(int32_t msgType, const sp<IMemory>& dataPtr,
+                                             camera_frame_metadata_t *metadata, void* user);
         static void             dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr, void* user);
         // convert client from cookie
         static sp<Client>       getClientFromCookie(void* user);