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