Home | History | Annotate | Download | only in camera
      1 <html devsite>
      2   <head>
      3     <title>Output streams and cropping</title>
      4     <meta name="project_path" value="/_project.yaml" />
      5     <meta name="book_path" value="/_book.yaml" />
      6   </head>
      7   <body>
      8   <!--
      9       Copyright 2017 The Android Open Source Project
     10 
     11       Licensed under the Apache License, Version 2.0 (the "License");
     12       you may not use this file except in compliance with the License.
     13       You may obtain a copy of the License at
     14 
     15           http://www.apache.org/licenses/LICENSE-2.0
     16 
     17       Unless required by applicable law or agreed to in writing, software
     18       distributed under the License is distributed on an "AS IS" BASIS,
     19       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     20       See the License for the specific language governing permissions and
     21       limitations under the License.
     22   -->
     23 
     24 
     25 
     26 <h2 id="output-stream">Output streams</h2>
     27 <p> Unlike the old camera subsystem, which has 3-4 different ways of producing data
     28   from the camera (ANativeWindow-based preview operations, preview callbacks,
     29   video callbacks, and takePicture callbacks), the new subsystem operates solely
     30   on the ANativeWindow-based pipeline for all resolutions and output formats.
     31   Multiple such streams can be configured at once, to send a single frame to many
     32   targets such as the GPU, the video encoder, RenderScript, or app-visible buffers
     33   (RAW Bayer, processed YUV buffers, or JPEG-encoded buffers).</p>
     34 <p>As an optimization, these output streams must be configured ahead of time, and
     35   only a limited number may exist at once. This allows for pre-allocation of
     36   memory buffers and configuration of the camera hardware, so that when requests
     37   are submitted with multiple or varying output pipelines listed, there won't be
     38   delays or latency in fulfilling the request.</p>
     39 <p>To support backwards compatibility with the current camera API, at least 3
     40   simultaneous YUV output streams must be supported, plus one JPEG stream. This is
     41   required for video snapshot support with the application also receiving YUV
     42   buffers:</p>
     43 <ul>
     44   <li>One stream to the GPU/SurfaceView (opaque YUV format) for preview</li>
     45   <li>One stream to the video encoder (opaque YUV format) for recording</li>
     46   <li>One stream to the application (known YUV format) for preview frame callbacks</li>
     47   <li>One stream to the application (JPEG) for video snapshots.</li>
     48 </ul>
     49 <p>The exact requirements are still being defined since the corresponding API
     50 isn't yet finalized.</p>
     51 <h2>Cropping</h2>
     52 <p>Cropping of the full pixel array (for digital zoom and other use cases where a
     53   smaller FOV is desirable) is communicated through the ANDROID_SCALER_CROP_REGION
     54   setting. This is a per-request setting, and can change on a per-request basis,
     55   which is critical for implementing smooth digital zoom.</p>
     56 <p>The region is defined as a rectangle (x, y, width, height), with (x, y)
     57   describing the top-left corner of the rectangle. The rectangle is defined on the
     58   coordinate system of the sensor active pixel array, with (0,0) being the
     59   top-left pixel of the active pixel array. Therefore, the width and height cannot
     60   be larger than the dimensions reported in the ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY
     61   static info field. The minimum allowed width and height are reported by the HAL
     62   through the ANDROID_SCALER_MAX_DIGITAL_ZOOM static info field, which describes
     63   the maximum supported zoom factor. Therefore, the minimum crop region width and
     64   height are:</p>
     65 <pre class="devsite-click-to-copy">
     66   {width, height} =
     67    { floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[0] /
     68        ANDROID_SCALER_MAX_DIGITAL_ZOOM),
     69      floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[1] /
     70        ANDROID_SCALER_MAX_DIGITAL_ZOOM) }
     71 </pre>
     72 <p>If the crop region needs to fulfill specific requirements (for example, it needs
     73   to start on even coordinates, and its width/height needs to be even), the HAL
     74   must do the necessary rounding and write out the final crop region used in the
     75   output result metadata. Similarly, if the HAL implements video stabilization, it
     76   must adjust the result crop region to describe the region actually included in
     77   the output after video stabilization is applied. In general, a camera-using
     78   application must be able to determine the field of view it is receiving based on
     79   the crop region, the dimensions of the image sensor, and the lens focal length.</p>
     80 <p>Since the crop region applies to all streams, which may have different aspect
     81   ratios than the crop region, the exact sensor region used for each stream may be
     82   smaller than the crop region. Specifically, each stream should maintain square
     83   pixels and its aspect ratio by minimally further cropping the defined crop
     84   region. If the stream's aspect ratio is wider than the crop region, the stream
     85   should be further cropped vertically, and if the stream's aspect ratio is
     86   narrower than the crop region, the stream should be further cropped
     87   horizontally.</p>
     88 <p>In all cases, the stream crop must be centered within the full crop region, and
     89   each stream is only either cropped horizontally or vertical relative to the full
     90   crop region, never both.</p>
     91 <p>For example, if two streams are defined, a 640x480 stream (4:3 aspect), and a
     92   1280x720 stream (16:9 aspect), below demonstrates the expected output regions
     93   for each stream for a few sample crop regions, on a hypothetical 3 MP (2000 x
     94   1500 pixel array) sensor.</p>
     95 </p>
     96   Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)<br/>
     97   640x480 stream crop: (500, 375, 1000, 750) (equal to crop region)<br/>
     98   1280x720 stream crop: (500, 469, 1000, 562)
     99 </p>
    100   <img src="images/crop-region-43-ratio.png" alt="crop-region-43-ratio" id="figure1" />
    101 <p class="img-caption">
    102   <strong>Figure 1.</strong> 4:3 aspect ratio
    103 </p>
    104 <p>Crop region: (500, 375, 1333, 750) (16:9 aspect ratio)<br/>
    105   640x480 stream crop: (666, 375, 1000, 750)<br/>
    106   1280x720 stream crop: (500, 375, 1333, 750) (equal to crop region)
    107 </p>
    108   <img src="images/crop-region-169-ratio.png" alt="crop-region-169-ratio" id="figure2" />
    109 <p class="img-caption">
    110   <strong>Figure 2.</strong> 16:9 aspect ratio
    111 </p>
    112 <p>Crop region: (500, 375, 750, 750) (1:1 aspect ratio)<br/>
    113   640x480 stream crop: (500, 469, 750, 562)<br/>
    114   1280x720 stream crop: (500, 543, 750, 414)
    115 </p>
    116   <img src="images/crop-region-11-ratio.png" alt="crop-region-11-ratio" id="figure3" />
    117 <p class="img-caption">
    118   <strong>Figure 3.</strong> 1:1 aspect ratio
    119 </p>
    120 <p>
    121   And a final example, a 1024x1024 square aspect ratio stream instead of the 480p
    122   stream:<br/>
    123   Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)<br/>
    124   1024x1024 stream crop: (625, 375, 750, 750)<br/>
    125   1280x720 stream crop: (500, 469, 1000, 562)
    126 </p>
    127   <img src="images/crop-region-43-square-ratio.png" alt="crop-region-43-square-ratio" id="figure4" />
    128 <p class="img-caption">
    129   <strong>Figure 4.</strong> 4:3 aspect ratio, square
    130 </p>
    131 <h2 id="reprocessing">Reprocessing</h2>
    132 <p> Additional support for raw image files is provided by reprocessing support for RAW Bayer
    133   data. This support allows the camera pipeline to process a previously captured
    134   RAW buffer and metadata (an entire frame that was recorded previously), to
    135   produce a new rendered YUV or JPEG output.</p>
    136 
    137   </body>
    138 </html>
    139