Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.55 KB | None | 0 0
  1. /*
  2.  * Copyright (C) 2008 The Android Open Source Project
  3.  * Copyright (C) 2010, Code Aurora Forum. All rights reserved.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17.  
  18. #ifndef ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H
  19. #define ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H
  20.  
  21. #include <binder/IMemory.h>
  22. #include <utils/RefBase.h>
  23. #include <surfaceflinger/ISurface.h>
  24. #include <camera/Camera.h>
  25. #include <camera/CameraParameters.h>
  26.  
  27. namespace android {
  28.  
  29. class Overlay;
  30.  
  31. /**
  32.  *  The size of image for display.
  33.  */
  34. typedef struct image_rect_struct
  35. {
  36.   uint32_t width;      /* Image width */
  37.   uint32_t height;     /* Image height */
  38. } image_rect_type;
  39.  
  40.  
  41. typedef void (*notify_callback)(int32_t msgType,
  42.                                 int32_t ext1,
  43.                                 int32_t ext2,
  44.                                 void* user);
  45.  
  46. typedef void (*data_callback)(int32_t msgType,
  47.                               const sp<IMemory>& dataPtr,
  48.                               void* user);
  49.  
  50. typedef void (*data_callback_timestamp)(nsecs_t timestamp,
  51.                                         int32_t msgType,
  52.                                         const sp<IMemory>& dataPtr,
  53.                                         void* user);
  54.  
  55. /**
  56.  * CameraHardwareInterface.h defines the interface to the
  57.  * camera hardware abstraction layer, used for setting and getting
  58.  * parameters, live previewing, and taking pictures.
  59.  *
  60.  * It is a referenced counted interface with RefBase as its base class.
  61.  * CameraService calls openCameraHardware() to retrieve a strong pointer to the
  62.  * instance of this interface and may be called multiple times. The
  63.  * following steps describe a typical sequence:
  64.  *
  65.  *   -# After CameraService calls openCameraHardware(), getParameters() and
  66.  *      setParameters() are used to initialize the camera instance.
  67.  *      CameraService calls getPreviewHeap() to establish access to the
  68.  *      preview heap so it can be registered with SurfaceFlinger for
  69.  *      efficient display updating while in preview mode.
  70.  *   -# startPreview() is called.  The camera instance then periodically
  71.  *      sends the message CAMERA_MSG_PREVIEW_FRAME (if enabled) each time
  72.  *      a new preview frame is available.  If data callback code needs to use
  73.  *      this memory after returning, it must copy the data.
  74.  *
  75.  * Prior to taking a picture, CameraService calls autofocus(). When auto
  76.  * focusing has completed, the camera instance sends a CAMERA_MSG_FOCUS notification,
  77.  * which informs the application whether focusing was successful. The camera instance
  78.  * only sends this message once and it is up  to the application to call autoFocus()
  79.  * again if refocusing is desired.
  80.  *
  81.  * CameraService calls takePicture() to request the camera instance take a
  82.  * picture. At this point, if a shutter, postview, raw, and/or compressed callback
  83.  * is desired, the corresponding message must be enabled. As with CAMERA_MSG_PREVIEW_FRAME,
  84.  * any memory provided in a data callback must be copied if it's needed after returning.
  85.  */
  86. class CameraHardwareInterface : public virtual RefBase {
  87. public:
  88.     virtual ~CameraHardwareInterface() { }
  89.  
  90.     /** Return the IMemoryHeap for the preview image heap */
  91.     virtual sp<IMemoryHeap>         getPreviewHeap() const = 0;
  92.  
  93.     /** Return the IMemoryHeap for the raw image heap */
  94.     virtual sp<IMemoryHeap>         getRawHeap() const = 0;
  95.  
  96.     /** Set the notification and data callbacks */
  97.     virtual void setCallbacks(notify_callback notify_cb,
  98.                               data_callback data_cb,
  99.                               data_callback_timestamp data_cb_timestamp,
  100.                               void* user) = 0;
  101.  
  102.     /**
  103.      * The following three functions all take a msgtype,
  104.      * which is a bitmask of the messages defined in
  105.      * include/ui/Camera.h
  106.      */
  107.  
  108.     /**
  109.      * Enable a message, or set of messages.
  110.      */
  111.     virtual void        enableMsgType(int32_t msgType) = 0;
  112.  
  113.     /**
  114.      * Disable a message, or a set of messages.
  115.      */
  116.     virtual void        disableMsgType(int32_t msgType) = 0;
  117.  
  118.     /**
  119.      * Query whether a message, or a set of messages, is enabled.
  120.      * Note that this is operates as an AND, if any of the messages
  121.      * queried are off, this will return false.
  122.      */
  123.     virtual bool        msgTypeEnabled(int32_t msgType) = 0;
  124.  
  125.     /**
  126.      * Start preview mode.
  127.      */
  128.     virtual status_t    startPreview() = 0;
  129.  
  130. #ifdef USE_GETBUFFERINFO
  131.     /**
  132.      * Query the recording buffer information from HAL.
  133.      * This is needed because the opencore expects the buffer
  134.      * information before starting the recording.
  135.      */
  136.     virtual status_t    getBufferInfo(sp<IMemory>& Frame, size_t *alignedSize) = 0;
  137.  
  138.     /**
  139.      * Encode the YUV data.
  140.      */
  141.     virtual void        encodeData() = 0;
  142. #endif
  143.  
  144.     /**
  145.      * Only used if overlays are used for camera preview.
  146.      */
  147.     virtual bool         useOverlay() {return false;}
  148.     virtual status_t     setOverlay(const sp<Overlay> &overlay) {return BAD_VALUE;}
  149.  
  150.     /**
  151.      * Stop a previously started preview.
  152.      */
  153.     virtual void        stopPreview() = 0;
  154.  
  155.     /**
  156.      * Returns true if preview is enabled.
  157.      */
  158.     virtual bool        previewEnabled() = 0;
  159.  
  160.     /**
  161.      * Start record mode. When a record image is available a CAMERA_MSG_VIDEO_FRAME
  162.      * message is sent with the corresponding frame. Every record frame must be released
  163.      * by calling releaseRecordingFrame().
  164.      */
  165.     virtual status_t    startRecording() = 0;
  166.  
  167.     /**
  168.      * Stop a previously started recording.
  169.      */
  170.     virtual void        stopRecording() = 0;
  171.  
  172.     /**
  173.      * Returns true if recording is enabled.
  174.      */
  175.     virtual bool        recordingEnabled() = 0;
  176.  
  177.     /**
  178.      * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
  179.      */
  180.     virtual void        releaseRecordingFrame(const sp<IMemory>& mem) = 0;
  181.  
  182.     /**
  183.      * Start auto focus, the notification callback routine is called
  184.      * with CAMERA_MSG_FOCUS once when focusing is complete. autoFocus()
  185.      * will be called again if another auto focus is needed.
  186.      */
  187.     virtual status_t    autoFocus() = 0;
  188.  
  189.     /**
  190.      * Cancels auto-focus function. If the auto-focus is still in progress,
  191.      * this function will cancel it. Whether the auto-focus is in progress
  192.      * or not, this function will return the focus position to the default.
  193.      * If the camera does not support auto-focus, this is a no-op.
  194.      */
  195.     virtual status_t    cancelAutoFocus() = 0;
  196.  
  197.     /**
  198.      * Take a picture.
  199.      */
  200.     virtual status_t    takePicture() = 0;
  201.  
  202.     /**
  203.      * Cancel a picture that was started with takePicture.  Calling this
  204.      * method when no picture is being taken is a no-op.
  205.      */
  206.     virtual status_t    cancelPicture() = 0;
  207.  
  208.     /**
  209.      * Set the camera parameters. This returns BAD_VALUE if any parameter is
  210.      * invalid or not supported. */
  211.     virtual status_t    setParameters(const CameraParameters& params) = 0;
  212.  
  213.     /** Return the camera parameters. */
  214.     virtual CameraParameters  getParameters() const = 0;
  215.  
  216.     /**
  217.      * Send command to camera driver.
  218.      */
  219.     virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0;
  220.  
  221.     /**
  222.      * Release the hardware resources owned by this object.  Note that this is
  223.      * *not* done in the destructor.
  224.      */
  225.     virtual void release() = 0;
  226.  
  227.     /**
  228.      * Dump state of the camera hardware
  229.      */
  230.     virtual status_t dump(int fd, const Vector<String16>& args) const = 0;
  231.  
  232. };
  233.  
  234. /**
  235.  * The functions need to be provided by the camera HAL.
  236.  *
  237.  * If getNumberOfCameras() returns N, the valid cameraId for getCameraInfo()
  238.  * and openCameraHardware() is 0 to N-1.
  239.  */
  240. extern "C" int HAL_getNumberOfCameras();
  241. extern "C" void HAL_getCameraInfo(int cameraId, struct CameraInfo* cameraInfo);
  242. /* HAL should return NULL if it fails to open camera hardware. */
  243. extern "C" sp<CameraHardwareInterface> HAL_openCameraHardware(int cameraId);
  244.  
  245. };  // namespace android
  246.  
  247. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement