OSDN Git Service

Camera2: Use HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED
authorEino-Ville Talvala <etalvala@google.com>
Tue, 28 Aug 2012 21:01:26 +0000 (14:01 -0700)
committerEino-Ville Talvala <etalvala@google.com>
Tue, 28 Aug 2012 21:22:53 +0000 (14:22 -0700)
Align camera2's management of platform-opaque formats with rest of
framework. Instead of using CAMERA2_PIXEL_FORMAT_OPAQUE, use
HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED as the format for both the
camera HAL and for gralloc, and depend on the gralloc usage flags to
let the gralloc module select the appropriate real format for specific
stream endpoints.

Add a new gralloc usage for ZSL mode, where the camera service will
hold a streaming circular buffer of opaque full-resolution images
during camera preview. Since this is an opaque format that needs to be
optimized for 30fps operation, need gralloc to be aware of this use
case.

Bug: 6243944
Change-Id: If7f2516649381ce9bcffe4e319b63cbc068f643f

include/hardware/camera2.h
include/hardware/gralloc.h
tests/camera2/camera2.cpp
tests/camera2/camera2_utils.cpp
tests/camera2/camera2_utils.h

index 518130b..8209985 100644 (file)
@@ -96,22 +96,11 @@ typedef struct camera2_stream_ops {
 
 } camera2_stream_ops_t;
 
+/**
+ * Temporary definition during transition. TODO: Remove once HALs no longer
+ * reference this */
 enum {
-    /**
-     * Special pixel format value used to indicate that the framework does not care
-     * what exact pixel format is to be used for an output stream. The device HAL is
-     * free to select any pixel format, platform-specific and otherwise, and this
-     * opaque value will be passed on to the platform gralloc module when buffers
-     * need to be allocated for the stream.
-     */
-    CAMERA2_HAL_PIXEL_FORMAT_OPAQUE     = -1,
-    /**
-     * Special pixel format value used to indicate that the framework will use
-     * the output buffers for zero-shutter-lag mode; these buffers should be
-     * efficient to produce at full sensor resolution, and efficient to send
-     * into a reprocess stream for final output processing.
-     */
-    CAMERA2_HAL_PIXEL_FORMAT_ZSL = -2
+    CAMERA2_HAL_PIXEL_FORMAT_OPAQUE = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED
 };
 
 /**
@@ -564,11 +553,12 @@ typedef struct camera2_device_ops {
      * Input parameters:
      *
      * - width, height, format: Specification for the buffers to be sent through
-     *   this stream. Format is a value from the HAL_PIXEL_FORMAT_* list, or
-     *   CAMERA2_HAL_PIXEL_FORMAT_OPAQUE. In the latter case, the camera device
-     *   must select an appropriate (possible platform-specific) HAL pixel
-     *   format to return in format_actual. In the former case, format_actual
-     *   must be set to match format.
+     *   this stream. Format is a value from the HAL_PIXEL_FORMAT_* list. If
+     *   HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, then the platform
+     *   gralloc module will select a format based on the usage flags provided
+     *   by the camera HAL and the consumer of the stream. The camera HAL should
+     *   inspect the buffers handed to it in the register_stream_buffers call to
+     *   obtain the implementation-specific format if necessary.
      *
      * - stream_ops: A structure of function pointers for obtaining and queuing
      *   up buffers for this stream. The underlying stream will be configured
@@ -581,15 +571,6 @@ typedef struct camera2_device_ops {
      *   used in incoming requests to identify the stream, and in releasing the
      *   stream.
      *
-     * - format_actual: If the input format is CAMERA2_HAL_PIXEL_FORMAT_OPAQUE,
-     *   then device must select the appropriate (possible platform-specific)
-     *   pixel format and return it in *format_actual. It will be treated as an
-     *   opaque value by the framework, and simply passed to the gralloc module
-     *   when new buffers need to be allocated. If the input format is one of
-     *   the values from HAL_PIXEL_FORMAT_* list, then *format_actual must be
-     *   set equal to format. In the latter case, format_actual may also be
-     *   NULL, in which case it can be ignored as an output.
-     *
      * - usage: The gralloc usage mask needed by the HAL device for producing
      *   the requested type of data. This is used in allocating new gralloc
      *   buffers for the stream buffer queue.
@@ -608,7 +589,7 @@ typedef struct camera2_device_ops {
             const camera2_stream_ops_t *stream_ops,
             // outputs
             uint32_t *stream_id,
-            uint32_t *format_actual,
+            uint32_t *format_actual, // IGNORED, will be removed
             uint32_t *usage,
             uint32_t *max_buffers);
 
@@ -619,7 +600,10 @@ typedef struct camera2_device_ops {
      * otherwise prepare the buffers for later use. num_buffers is guaranteed to
      * be at least max_buffers (from allocate_stream), but may be larger. The
      * buffers will already be locked for use. At the end of the call, all the
-     * buffers must be ready to be returned to the queue.
+     * buffers must be ready to be returned to the queue. If the stream format
+     * was set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, the camera HAL should
+     * inspect the passed-in buffers here to determine any platform-private
+     * pixel format information.
      */
     int (*register_stream_buffers)(
             const struct camera2_device *,
index 86ed95c..4fdd2e6 100644 (file)
@@ -80,6 +80,8 @@ enum {
     GRALLOC_USAGE_HW_CAMERA_WRITE       = 0x00020000,
     /* buffer will be read by the HW camera pipeline */
     GRALLOC_USAGE_HW_CAMERA_READ        = 0x00040000,
+    /* buffer will be used as part of zero-shutter-lag queue */
+    GRALLOC_USAGE_HW_CAMERA_ZSL         = 0x00080000,
     /* mask for the software usage bit-mask */
     GRALLOC_USAGE_HW_MASK               = 0x00071F00,
 
index 29eef68..f43513e 100644 (file)
@@ -240,7 +240,7 @@ class Camera2Test: public testing::Test {
             size_t *count) {
         ALOGV("Getting resolutions for format %x", format);
         status_t res;
-        if (format != CAMERA2_HAL_PIXEL_FORMAT_OPAQUE) {
+        if (format != HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) {
             camera_metadata_ro_entry_t availableFormats;
             res = find_camera_metadata_ro_entry(mStaticInfo,
                     ANDROID_SCALER_AVAILABLE_FORMATS,
index ba938d9..cefe29a 100644 (file)
@@ -317,7 +317,7 @@ void NotifierListener::notify_callback_dispatch(int32_t msg_type,
 StreamAdapter::StreamAdapter(sp<ISurfaceTexture> consumer):
         mState(UNINITIALIZED), mDevice(NULL),
         mId(-1),
-        mWidth(0), mHeight(0), mFormatRequested(0)
+        mWidth(0), mHeight(0), mFormat(0)
 {
     mConsumerInterface = new SurfaceTextureClient(consumer);
     camera2_stream_ops::dequeue_buffer = dequeue_buffer;
@@ -342,16 +342,16 @@ status_t StreamAdapter::connectToDevice(camera2_device_t *d,
 
     mWidth = width;
     mHeight = height;
-    mFormatRequested = format;
+    mFormat = format;
 
     // Allocate device-side stream interface
 
     uint32_t id;
-    uint32_t formatActual;
+    uint32_t formatActual; // ignored
     uint32_t usage;
     uint32_t maxBuffers = 2;
     res = d->ops->allocate_stream(d,
-            mWidth, mHeight, mFormatRequested, getStreamOps(),
+            mWidth, mHeight, mFormat, getStreamOps(),
             &id, &formatActual, &usage, &maxBuffers);
     if (res != OK) {
         ALOGE("%s: Device stream allocation failed: %s (%d)",
@@ -362,7 +362,6 @@ status_t StreamAdapter::connectToDevice(camera2_device_t *d,
     mDevice = d;
 
     mId = id;
-    mFormat = formatActual;
     mUsage = usage;
     mMaxProducerBuffers = maxBuffers;
 
index 2c9f801..7822f5b 100644 (file)
@@ -194,8 +194,6 @@ class StreamAdapter: public camera2_stream_ops {
     uint32_t mMaxProducerBuffers;
     uint32_t mMaxConsumerBuffers;
 
-    int mFormatRequested;
-
     const camera2_stream_ops *getStreamOps();
 
     static ANativeWindow* toANW(const camera2_stream_ops_t *w);