17ec681f3Smrg/*
27ec681f3Smrg * Copyright (C) 2011 The Android Open Source Project
37ec681f3Smrg *
47ec681f3Smrg * Licensed under the Apache License, Version 2.0 (the "License");
57ec681f3Smrg * you may not use this file except in compliance with the License.
67ec681f3Smrg * You may obtain a copy of the License at
77ec681f3Smrg *
87ec681f3Smrg *      http://www.apache.org/licenses/LICENSE-2.0
97ec681f3Smrg *
107ec681f3Smrg * Unless required by applicable law or agreed to in writing, software
117ec681f3Smrg * distributed under the License is distributed on an "AS IS" BASIS,
127ec681f3Smrg * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137ec681f3Smrg * See the License for the specific language governing permissions and
147ec681f3Smrg * limitations under the License.
157ec681f3Smrg */
167ec681f3Smrg
177ec681f3Smrg#ifndef SYSTEM_CORE_INCLUDE_ANDROID_CAMERA_H
187ec681f3Smrg#define SYSTEM_CORE_INCLUDE_ANDROID_CAMERA_H
197ec681f3Smrg
207ec681f3Smrg#include <stdint.h>
217ec681f3Smrg#include <sys/cdefs.h>
227ec681f3Smrg#include <sys/types.h>
237ec681f3Smrg#include <cutils/native_handle.h>
247ec681f3Smrg#include <hardware/hardware.h>
257ec681f3Smrg#include <hardware/gralloc.h>
267ec681f3Smrg
277ec681f3Smrg__BEGIN_DECLS
287ec681f3Smrg
297ec681f3Smrg/**
307ec681f3Smrg * A set of bit masks for specifying how the received preview frames are
317ec681f3Smrg * handled before the previewCallback() call.
327ec681f3Smrg *
337ec681f3Smrg * The least significant 3 bits of an "int" value are used for this purpose:
347ec681f3Smrg *
357ec681f3Smrg * ..... 0 0 0
367ec681f3Smrg *       ^ ^ ^
377ec681f3Smrg *       | | |---------> determine whether the callback is enabled or not
387ec681f3Smrg *       | |-----------> determine whether the callback is one-shot or not
397ec681f3Smrg *       |-------------> determine whether the frame is copied out or not
407ec681f3Smrg *
417ec681f3Smrg * WARNING: When a frame is sent directly without copying, it is the frame
427ec681f3Smrg * receiver's responsiblity to make sure that the frame data won't get
437ec681f3Smrg * corrupted by subsequent preview frames filled by the camera. This flag is
447ec681f3Smrg * recommended only when copying out data brings significant performance price
457ec681f3Smrg * and the handling/processing of the received frame data is always faster than
467ec681f3Smrg * the preview frame rate so that data corruption won't occur.
477ec681f3Smrg *
487ec681f3Smrg * For instance,
497ec681f3Smrg * 1. 0x00 disables the callback. In this case, copy out and one shot bits
507ec681f3Smrg *    are ignored.
517ec681f3Smrg * 2. 0x01 enables a callback without copying out the received frames. A
527ec681f3Smrg *    typical use case is the Camcorder application to avoid making costly
537ec681f3Smrg *    frame copies.
547ec681f3Smrg * 3. 0x05 is enabling a callback with frame copied out repeatedly. A typical
557ec681f3Smrg *    use case is the Camera application.
567ec681f3Smrg * 4. 0x07 is enabling a callback with frame copied out only once. A typical
577ec681f3Smrg *    use case is the Barcode scanner application.
587ec681f3Smrg */
597ec681f3Smrg
607ec681f3Smrgenum {
617ec681f3Smrg    CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK = 0x01,
627ec681f3Smrg    CAMERA_FRAME_CALLBACK_FLAG_ONE_SHOT_MASK = 0x02,
637ec681f3Smrg    CAMERA_FRAME_CALLBACK_FLAG_COPY_OUT_MASK = 0x04,
647ec681f3Smrg    /** Typical use cases */
657ec681f3Smrg    CAMERA_FRAME_CALLBACK_FLAG_NOOP = 0x00,
667ec681f3Smrg    CAMERA_FRAME_CALLBACK_FLAG_CAMCORDER = 0x01,
677ec681f3Smrg    CAMERA_FRAME_CALLBACK_FLAG_CAMERA = 0x05,
687ec681f3Smrg    CAMERA_FRAME_CALLBACK_FLAG_BARCODE_SCANNER = 0x07
697ec681f3Smrg};
707ec681f3Smrg
717ec681f3Smrg/** msgType in notifyCallback and dataCallback functions */
727ec681f3Smrgenum {
737ec681f3Smrg    CAMERA_MSG_ERROR = 0x0001,            // notifyCallback
747ec681f3Smrg    CAMERA_MSG_SHUTTER = 0x0002,          // notifyCallback
757ec681f3Smrg    CAMERA_MSG_FOCUS = 0x0004,            // notifyCallback
767ec681f3Smrg    CAMERA_MSG_ZOOM = 0x0008,             // notifyCallback
777ec681f3Smrg    CAMERA_MSG_PREVIEW_FRAME = 0x0010,    // dataCallback
787ec681f3Smrg    CAMERA_MSG_VIDEO_FRAME = 0x0020,      // data_timestamp_callback
797ec681f3Smrg    CAMERA_MSG_POSTVIEW_FRAME = 0x0040,   // dataCallback
807ec681f3Smrg    CAMERA_MSG_RAW_IMAGE = 0x0080,        // dataCallback
817ec681f3Smrg    CAMERA_MSG_COMPRESSED_IMAGE = 0x0100, // dataCallback
827ec681f3Smrg    CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x0200, // dataCallback
837ec681f3Smrg    // Preview frame metadata. This can be combined with
847ec681f3Smrg    // CAMERA_MSG_PREVIEW_FRAME in dataCallback. For example, the apps can
857ec681f3Smrg    // request FRAME and METADATA. Or the apps can request only FRAME or only
867ec681f3Smrg    // METADATA.
877ec681f3Smrg    CAMERA_MSG_PREVIEW_METADATA = 0x0400, // dataCallback
887ec681f3Smrg    // Notify on autofocus start and stop. This is useful in continuous
897ec681f3Smrg    // autofocus - FOCUS_MODE_CONTINUOUS_VIDEO and FOCUS_MODE_CONTINUOUS_PICTURE.
907ec681f3Smrg    CAMERA_MSG_FOCUS_MOVE = 0x0800,       // notifyCallback
917ec681f3Smrg    CAMERA_MSG_ALL_MSGS = 0xFFFF
927ec681f3Smrg};
937ec681f3Smrg
947ec681f3Smrg/** cmdType in sendCommand functions */
957ec681f3Smrgenum {
967ec681f3Smrg    CAMERA_CMD_START_SMOOTH_ZOOM = 1,
977ec681f3Smrg    CAMERA_CMD_STOP_SMOOTH_ZOOM = 2,
987ec681f3Smrg
997ec681f3Smrg    /**
1007ec681f3Smrg     * Set the clockwise rotation of preview display (setPreviewDisplay) in
1017ec681f3Smrg     * degrees. This affects the preview frames and the picture displayed after
1027ec681f3Smrg     * snapshot. This method is useful for portrait mode applications. Note
1037ec681f3Smrg     * that preview display of front-facing cameras is flipped horizontally
1047ec681f3Smrg     * before the rotation, that is, the image is reflected along the central
1057ec681f3Smrg     * vertical axis of the camera sensor. So the users can see themselves as
1067ec681f3Smrg     * looking into a mirror.
1077ec681f3Smrg     *
1087ec681f3Smrg     * This does not affect the order of byte array of
1097ec681f3Smrg     * CAMERA_MSG_PREVIEW_FRAME, CAMERA_MSG_VIDEO_FRAME,
1107ec681f3Smrg     * CAMERA_MSG_POSTVIEW_FRAME, CAMERA_MSG_RAW_IMAGE, or
1117ec681f3Smrg     * CAMERA_MSG_COMPRESSED_IMAGE. This is allowed to be set during preview
1127ec681f3Smrg     * since API level 14.
1137ec681f3Smrg     */
1147ec681f3Smrg    CAMERA_CMD_SET_DISPLAY_ORIENTATION = 3,
1157ec681f3Smrg
1167ec681f3Smrg    /**
1177ec681f3Smrg     * cmdType to disable/enable shutter sound. In sendCommand passing arg1 =
1187ec681f3Smrg     * 0 will disable, while passing arg1 = 1 will enable the shutter sound.
1197ec681f3Smrg     */
1207ec681f3Smrg    CAMERA_CMD_ENABLE_SHUTTER_SOUND = 4,
1217ec681f3Smrg
1227ec681f3Smrg    /* cmdType to play recording sound */
1237ec681f3Smrg    CAMERA_CMD_PLAY_RECORDING_SOUND = 5,
1247ec681f3Smrg
1257ec681f3Smrg    /**
1267ec681f3Smrg     * Start the face detection. This should be called after preview is started.
1277ec681f3Smrg     * The camera will notify the listener of CAMERA_MSG_FACE and the detected
1287ec681f3Smrg     * faces in the preview frame. The detected faces may be the same as the
1297ec681f3Smrg     * previous ones. Apps should call CAMERA_CMD_STOP_FACE_DETECTION to stop
1307ec681f3Smrg     * the face detection. This method is supported if CameraParameters
1317ec681f3Smrg     * KEY_MAX_NUM_HW_DETECTED_FACES or KEY_MAX_NUM_SW_DETECTED_FACES is
1327ec681f3Smrg     * bigger than 0. Hardware and software face detection should not be running
1337ec681f3Smrg     * at the same time. If the face detection has started, apps should not send
1347ec681f3Smrg     * this again.
1357ec681f3Smrg     *
1367ec681f3Smrg     * In hardware face detection mode, CameraParameters KEY_WHITE_BALANCE,
1377ec681f3Smrg     * KEY_FOCUS_AREAS and KEY_METERING_AREAS have no effect.
1387ec681f3Smrg     *
1397ec681f3Smrg     * arg1 is the face detection type. It can be CAMERA_FACE_DETECTION_HW or
1407ec681f3Smrg     * CAMERA_FACE_DETECTION_SW. If the type of face detection requested is not
1417ec681f3Smrg     * supported, the HAL must return BAD_VALUE.
1427ec681f3Smrg     */
1437ec681f3Smrg    CAMERA_CMD_START_FACE_DETECTION = 6,
1447ec681f3Smrg
1457ec681f3Smrg    /**
1467ec681f3Smrg     * Stop the face detection.
1477ec681f3Smrg     */
1487ec681f3Smrg    CAMERA_CMD_STOP_FACE_DETECTION = 7,
1497ec681f3Smrg
1507ec681f3Smrg    /**
1517ec681f3Smrg     * Enable/disable focus move callback (CAMERA_MSG_FOCUS_MOVE). Passing
1527ec681f3Smrg     * arg1 = 0 will disable, while passing arg1 = 1 will enable the callback.
1537ec681f3Smrg     */
1547ec681f3Smrg    CAMERA_CMD_ENABLE_FOCUS_MOVE_MSG = 8,
1557ec681f3Smrg
1567ec681f3Smrg    /**
1577ec681f3Smrg     * Ping camera service to see if camera hardware is released.
1587ec681f3Smrg     *
1597ec681f3Smrg     * When any camera method returns error, the client can use ping command
1607ec681f3Smrg     * to see if the camera has been taken away by other clients. If the result
1617ec681f3Smrg     * is OK, it means the camera hardware is not released. If the result
1627ec681f3Smrg     * is not OK, the camera has been released and the existing client
1637ec681f3Smrg     * can silently finish itself or show a dialog.
1647ec681f3Smrg     */
1657ec681f3Smrg    CAMERA_CMD_PING = 9,
1667ec681f3Smrg
1677ec681f3Smrg    /**
1687ec681f3Smrg     * Configure the number of video buffers used for recording. The intended
1697ec681f3Smrg     * video buffer count for recording is passed as arg1, which must be
1707ec681f3Smrg     * greater than 0. This command must be sent before recording is started.
1717ec681f3Smrg     * This command returns INVALID_OPERATION error if it is sent after video
1727ec681f3Smrg     * recording is started, or the command is not supported at all. This
1737ec681f3Smrg     * command also returns a BAD_VALUE error if the intended video buffer
1747ec681f3Smrg     * count is non-positive or too big to be realized.
1757ec681f3Smrg     */
1767ec681f3Smrg    CAMERA_CMD_SET_VIDEO_BUFFER_COUNT = 10,
1777ec681f3Smrg
1787ec681f3Smrg    /**
1797ec681f3Smrg     * Configure an explicit format to use for video recording metadata mode.
1807ec681f3Smrg     * This can be used to switch the format from the
1817ec681f3Smrg     * default IMPLEMENTATION_DEFINED gralloc format to some other
1827ec681f3Smrg     * device-supported format, and the default dataspace from the BT_709 color
1837ec681f3Smrg     * space to some other device-supported dataspace. arg1 is the HAL pixel
1847ec681f3Smrg     * format, and arg2 is the HAL dataSpace. This command returns
1857ec681f3Smrg     * INVALID_OPERATION error if it is sent after video recording is started,
1867ec681f3Smrg     * or the command is not supported at all.
1877ec681f3Smrg     *
1887ec681f3Smrg     * If the gralloc format is set to a format other than
1897ec681f3Smrg     * IMPLEMENTATION_DEFINED, then HALv3 devices will use gralloc usage flags
1907ec681f3Smrg     * of SW_READ_OFTEN.
1917ec681f3Smrg     */
1927ec681f3Smrg    CAMERA_CMD_SET_VIDEO_FORMAT = 11
1937ec681f3Smrg};
1947ec681f3Smrg
1957ec681f3Smrg/** camera fatal errors */
1967ec681f3Smrgenum {
1977ec681f3Smrg    CAMERA_ERROR_UNKNOWN = 1,
1987ec681f3Smrg    /**
1997ec681f3Smrg     * Camera was released because another client has connected to the camera.
2007ec681f3Smrg     * The original client should call Camera::disconnect immediately after
2017ec681f3Smrg     * getting this notification. Otherwise, the camera will be released by
2027ec681f3Smrg     * camera service in a short time. The client should not call any method
2037ec681f3Smrg     * (except disconnect and sending CAMERA_CMD_PING) after getting this.
2047ec681f3Smrg     */
2057ec681f3Smrg    CAMERA_ERROR_RELEASED = 2,
2067ec681f3Smrg
2077ec681f3Smrg    /**
2087ec681f3Smrg     * Camera was released because device policy change or the client application
2097ec681f3Smrg     * is going to background. The client should call Camera::disconnect
2107ec681f3Smrg     * immediately after getting this notification. Otherwise, the camera will be
2117ec681f3Smrg     * released by camera service in a short time. The client should not call any
2127ec681f3Smrg     * method (except disconnect and sending CAMERA_CMD_PING) after getting this.
2137ec681f3Smrg     */
2147ec681f3Smrg    CAMERA_ERROR_DISABLED = 3,
2157ec681f3Smrg    CAMERA_ERROR_SERVER_DIED = 100
2167ec681f3Smrg};
2177ec681f3Smrg
2187ec681f3Smrgenum {
2197ec681f3Smrg    /** The facing of the camera is opposite to that of the screen. */
2207ec681f3Smrg    CAMERA_FACING_BACK = 0,
2217ec681f3Smrg    /** The facing of the camera is the same as that of the screen. */
2227ec681f3Smrg    CAMERA_FACING_FRONT = 1,
2237ec681f3Smrg    /**
2247ec681f3Smrg     * The facing of the camera is not fixed relative to the screen.
2257ec681f3Smrg     * The cameras with this facing are external cameras, e.g. USB cameras.
2267ec681f3Smrg     */
2277ec681f3Smrg    CAMERA_FACING_EXTERNAL = 2
2287ec681f3Smrg};
2297ec681f3Smrg
2307ec681f3Smrgenum {
2317ec681f3Smrg    /** Hardware face detection. It does not use much CPU. */
2327ec681f3Smrg    CAMERA_FACE_DETECTION_HW = 0,
2337ec681f3Smrg    /**
2347ec681f3Smrg     * Software face detection. It uses some CPU. Applications must use
2357ec681f3Smrg     * Camera.setPreviewTexture for preview in this mode.
2367ec681f3Smrg     */
2377ec681f3Smrg    CAMERA_FACE_DETECTION_SW = 1
2387ec681f3Smrg};
2397ec681f3Smrg
2407ec681f3Smrg/**
2417ec681f3Smrg * The information of a face from camera face detection.
2427ec681f3Smrg */
2437ec681f3Smrgtypedef struct camera_face {
2447ec681f3Smrg    /**
2457ec681f3Smrg     * Bounds of the face [left, top, right, bottom]. (-1000, -1000) represents
2467ec681f3Smrg     * the top-left of the camera field of view, and (1000, 1000) represents the
2477ec681f3Smrg     * bottom-right of the field of view. The width and height cannot be 0 or
2487ec681f3Smrg     * negative. This is supported by both hardware and software face detection.
2497ec681f3Smrg     *
2507ec681f3Smrg     * The direction is relative to the sensor orientation, that is, what the
2517ec681f3Smrg     * sensor sees. The direction is not affected by the rotation or mirroring
2527ec681f3Smrg     * of CAMERA_CMD_SET_DISPLAY_ORIENTATION.
2537ec681f3Smrg     */
2547ec681f3Smrg    int32_t rect[4];
2557ec681f3Smrg
2567ec681f3Smrg    /**
2577ec681f3Smrg     * The confidence level of the face. The range is 1 to 100. 100 is the
2587ec681f3Smrg     * highest confidence. This is supported by both hardware and software
2597ec681f3Smrg     * face detection.
2607ec681f3Smrg     */
2617ec681f3Smrg    int32_t score;
2627ec681f3Smrg
2637ec681f3Smrg    /**
2647ec681f3Smrg     * An unique id per face while the face is visible to the tracker. If
2657ec681f3Smrg     * the face leaves the field-of-view and comes back, it will get a new
2667ec681f3Smrg     * id. If the value is 0, id is not supported.
2677ec681f3Smrg     */
2687ec681f3Smrg    int32_t id;
2697ec681f3Smrg
2707ec681f3Smrg    /**
2717ec681f3Smrg     * The coordinates of the center of the left eye. The range is -1000 to
2727ec681f3Smrg     * 1000. -2000, -2000 if this is not supported.
2737ec681f3Smrg     */
2747ec681f3Smrg    int32_t left_eye[2];
2757ec681f3Smrg
2767ec681f3Smrg    /**
2777ec681f3Smrg     * The coordinates of the center of the right eye. The range is -1000 to
2787ec681f3Smrg     * 1000. -2000, -2000 if this is not supported.
2797ec681f3Smrg     */
2807ec681f3Smrg    int32_t right_eye[2];
2817ec681f3Smrg
2827ec681f3Smrg    /**
2837ec681f3Smrg     * The coordinates of the center of the mouth. The range is -1000 to 1000.
2847ec681f3Smrg     * -2000, -2000 if this is not supported.
2857ec681f3Smrg     */
2867ec681f3Smrg    int32_t mouth[2];
2877ec681f3Smrg
2887ec681f3Smrg} camera_face_t;
2897ec681f3Smrg
2907ec681f3Smrg/**
2917ec681f3Smrg * The metadata of the frame data.
2927ec681f3Smrg */
2937ec681f3Smrgtypedef struct camera_frame_metadata {
2947ec681f3Smrg    /**
2957ec681f3Smrg     * The number of detected faces in the frame.
2967ec681f3Smrg     */
2977ec681f3Smrg    int32_t number_of_faces;
2987ec681f3Smrg
2997ec681f3Smrg    /**
3007ec681f3Smrg     * An array of the detected faces. The length is number_of_faces.
3017ec681f3Smrg     */
3027ec681f3Smrg    camera_face_t *faces;
3037ec681f3Smrg} camera_frame_metadata_t;
3047ec681f3Smrg
3057ec681f3Smrg__END_DECLS
3067ec681f3Smrg
3077ec681f3Smrg#endif /* SYSTEM_CORE_INCLUDE_ANDROID_CAMERA_H */
308