Home | History | Annotate | Download | only in camera
      1 <html devsite>
      2   <head>
      3     <title>Error and stream handling</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="error-mgmt">Error management</h2>
     27 <p>Camera HAL device ops functions that have a return value will all return <code>-ENODEV
     28   / NULL</code> in case of a serious error. This means the device cannot continue
     29   operation and must be closed by the framework. Once this error is returned by
     30   some method, or if <code>notify()</code> is called with <code>ERROR_DEVICE</code>, only the <code>close()</code> method
     31   can be called successfully. All other methods will return <code>-ENODEV / NULL</code>.</p>
     32 <p>If a device op is called in the wrong sequence, for example if the framework
     33 calls <code>configure_streams()</code> before <code>initialize()</code>, the device must return
     34 <code>-ENOSYS</code> from the call, and do nothing.</p>
     35 <p>Transient errors in image capture must be reported through <code>notify()</code> as follows:</p>
     36 <ul>
     37   <li>The failure of an entire capture to occur must be reported by the HAL by
     38     calling <code>notify()</codE> with <code>ERROR_REQUEST</code>. Individual errors for the result metadata
     39     or the output buffers must not be reported in this case.</li>
     40   <li>If the metadata for a capture cannot be produced, but some image buffers were
     41     filled, the HAL must call <code>notify()</code> with <code>ERROR_RESULT</code>.</li>
     42   <li>If an output image buffer could not be filled, but either the metadata was
     43     produced or some other buffers were filled, the HAL must call <code>notify()</code> with
     44     <code>ERROR_BUFFER</code> for each failed buffer.</li>
     45 </ul>
     46 <p>In each of these transient failure cases, the HAL must still call
     47 <code>process_capture_result</code>, with valid output <code>buffer_handle_t</code>. If the result
     48 metadata could not be produced, it should be <code>NULL</code>. If some buffers could not be
     49   filled, their sync fences must be set to the error state.</p>
     50 <p>Invalid input arguments result in <code>-EINVAL</code> from the appropriate methods. In that
     51   case, the framework must act as if that call had never been made.</p>
     52 <h2 id="stream-mgmt">Stream management</h2>
     53 <h3 id="configure_streams">configure_streams</h3>
     54 <p>Reset the HAL camera device processing pipeline and set up new input and output
     55   streams. This call replaces any existing stream configuration with the streams
     56   defined in the <code>stream_list</code>. This method will be called at least once after
     57   <code>initialize()</code> before a request is submitted with <code>process_capture_request()</code>.</p>
     58 <p>The <code>stream_list</code> must contain at least one output-capable stream, and may not
     59   contain more than one input-capable stream.
     60   The <code>stream_list</code> may contain streams that are also in the currently-active set of
     61   streams (from the previous call to <code>configure_stream()</code>). These streams will
     62   already have valid values for usage, maxbuffers, and the private pointer. If
     63   such a stream has already had its buffers registered, <code>register_stream_buffers()</code>
     64   will not be called again for the stream, and buffers from the stream can be
     65   immediately included in input requests.</p>
     66 <p>If the HAL needs to change the stream configuration for an existing stream due
     67   to the new configuration, it may rewrite the values of usage and/or maxbuffers
     68   during the configure call. The framework will detect such a change, and will
     69   then reallocate the stream buffers, and call <code>register_stream_buffers()</code> again
     70   before using buffers from that stream in a request.</p>
     71 <p>If a currently-active stream is not included in <code>stream_list</code>, the HAL may safely
     72   remove any references to that stream. It will not be reused in a later
     73   <code>configure()</code> call by the framework, and all the gralloc buffers for it will be
     74   freed after the <code>configure_streams()</code> call returns.</p>
     75 <p>The <code>stream_list</code> structure is owned by the framework, and may not be accessed
     76 once this call completes. The address of an individual <code>camera3streamt</code>
     77   structure will remain valid for access by the HAL until the end of the first
     78   <code>configure_stream()</code> call which no longer includes that <code>camera3streamt</code> in the
     79   <code>stream_list</code> argument. The HAL may not change values in the stream structure
     80   outside of the private pointer, except for the usage and maxbuffers members
     81   during the <code>configure_streams()</code> call itself.</p>
     82 <p>If the stream is new, the usage, maxbuffer, and private pointer fields of the
     83   stream structure will all be set to 0. The HAL device must set these fields
     84   before the <code>configure_streams()</code> call returns. These fields are then used by the
     85   framework and the platform gralloc module to allocate the gralloc buffers for
     86   each stream.</p>
     87 <p>Before such a new stream can have its buffers included in a capture request, the
     88 framework will call <code>register_stream_buffers()</code> with that stream. However, the
     89   framework is not required to register buffers for _all streams before
     90   submitting a request. This allows for quick startup of (for example) a preview
     91   stream, with allocation for other streams happening later or concurrently.</p>
     92 <h4><strong>Preconditions</strong></h4>
     93 <p>The framework will only call this method when no captures are being processed.
     94   That is, all results have been returned to the framework, and all in-flight
     95   input and output buffers have been returned and their release sync fences have
     96   been signaled by the HAL. The framework will not submit new requests for capture
     97   while the <code>configure_streams()</code> call is underway.</p>
     98 <h4><strong>Postconditions</strong></h4>
     99 <p>The HAL device must configure itself to provide maximum possible output frame
    100   rate given the sizes and formats of the output streams, as documented in the
    101   camera device's static metadata.</p>
    102 <h4><strong>Performance expectations</strong></h4>
    103 <p>This call is expected to be heavyweight and possibly take several hundred
    104   milliseconds to complete, since it may require resetting and reconfiguring the
    105   image sensor and the camera processing pipeline. Nevertheless, the HAL device
    106   should attempt to minimize the reconfiguration delay to minimize the
    107   user-visible pauses during application operational mode changes (such as
    108   switching from still capture to video recording).</p>
    109 <h4><strong>Return values</strong></h4>
    110 <ul>
    111   <li><code>0</code>: On successful stream configuration</li>
    112   <li><code>undefined</code></li>
    113   <li><code>-EINVAL</code>: If the requested stream configuration is invalid. Some examples of
    114     invalid stream configurations include:
    115     <ul>
    116       <li>Including more than 1 input-capable stream (<code>INPUT</code> or <code>BIDIRECTIONAL</code>)</li>
    117       <li>Not including any output-capable streams (<code>OUTPUT</code> or <code>BIDIRECTIONAL</code>)</li>
    118       <li>Including streams with unsupported formats, or an unsupported size for
    119         that format.</li>
    120       <li>Including too many output streams of a certain format.</li>
    121       <li>Note that the framework submitting an invalid stream configuration is not
    122         normal operation, since stream configurations are checked before
    123         configure. An invalid configuration means that a bug exists in the
    124         framework code, or there is a mismatch between the HAL's static metadata
    125         and the requirements on streams.</li>
    126     </ul>
    127   </li>
    128   <li><code>-ENODEV</code>: If there has been a fatal error and the device is no longer
    129     operational. Only <code>close()</code> can be called successfully by the framework after
    130     this error is returned.</li>
    131 </ul>
    132 <h3 id="register-stream">register_stream_buffers</h3>
    133 <p>Register buffers for a given stream with the HAL device. This method is called
    134 by the framework after a new stream is defined by <code>configure_streams</code>, and before
    135   buffers from that stream are included in a capture request. If the same stream
    136   is listed in a subsequent <code>configure_streams()</code> call, <code>register_stream_buffers</code> will
    137   not be called again for that stream.</p>
    138 <p>The framework does not need to register buffers for all configured streams
    139   before it submits the first capture request. This allows quick startup for
    140   preview (or similar use cases) while other streams are still being allocated.</p>
    141 <p>This method is intended to allow the HAL device to map or otherwise prepare the
    142   buffers for later use. The buffers passed in will already be locked for use. At
    143   the end of the call, all the buffers must be ready to be returned to the stream.
    144   The bufferset argument is only valid for the duration of this call.</p>
    145 <p>If the stream format was set to <code>HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED</code>, the
    146   camera HAL should inspect the passed-in buffers here to determine any
    147   platform-private pixel format information.</p>
    148 <h4><strong>Return values</strong></h4>
    149 <ul>
    150   <li><code>0</code>: On successful registration of the new stream buffers</li>
    151   <li><code>-EINVAL</code>: If the streambufferset does not refer to a valid active stream, or
    152     if the buffers array is invalid.</li>
    153   <li><code>-ENOMEM</code>: If there was a failure in registering the buffers. The framework must
    154     consider all the stream buffers to be unregistered, and can try to register
    155     again later.</li>
    156   <li><code>-ENODEV</code>: If there is a fatal error, and the device is no longer operational.
    157     Only <code>close()</code> can be called successfully by the framework after this error is
    158     returned.</li>
    159 </ul>
    160 
    161   </body>
    162 </html>
    163