Home | History | Annotate | Download | only in camera
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef STREAM_H_
     18 #define STREAM_H_
     19 
     20 #include <hardware/camera3.h>
     21 #include <hardware/gralloc.h>
     22 #include <system/graphics.h>
     23 
     24 namespace default_camera_hal {
     25 // Stream represents a single input or output stream for a camera device.
     26 class Stream {
     27     public:
     28         Stream(int id, camera3_stream_t *s);
     29         ~Stream();
     30 
     31         // validate that astream's parameters match this stream's parameters
     32         bool isValidReuseStream(int id, camera3_stream_t *s);
     33 
     34         // Register buffers with hardware
     35         int registerBuffers(const camera3_stream_buffer_set_t *buf_set);
     36 
     37         void setUsage(uint32_t usage);
     38         void setMaxBuffers(uint32_t max_buffers);
     39 
     40         int getType();
     41         bool isInputType();
     42         bool isOutputType();
     43         bool isRegistered();
     44 
     45         // This stream is being reused. Used in stream configuration passes
     46         bool mReuse;
     47 
     48     private:
     49         // Clean up buffer state. must be called with mMutex held.
     50         void unregisterBuffers_L();
     51 
     52         // The camera device id this stream belongs to
     53         const int mId;
     54         // Handle to framework's stream, used as a cookie for buffers
     55         camera3_stream_t *mStream;
     56         // Stream type: CAMERA3_STREAM_* (see <hardware/camera3.h>)
     57         const int mType;
     58         // Width in pixels of the buffers in this stream
     59         const uint32_t mWidth;
     60         // Height in pixels of the buffers in this stream
     61         const uint32_t mHeight;
     62         // Gralloc format: HAL_PIXEL_FORMAT_* (see <system/graphics.h>)
     63         const int mFormat;
     64         // Gralloc usage mask : GRALLOC_USAGE_* (see <hardware/gralloc.h>)
     65         uint32_t mUsage;
     66         // Max simultaneous in-flight buffers for this stream
     67         uint32_t mMaxBuffers;
     68         // Buffers have been registered for this stream and are ready
     69         bool mRegistered;
     70         // Array of handles to buffers currently in use by the stream
     71         buffer_handle_t **mBuffers;
     72         // Number of buffers in mBuffers
     73         unsigned int mNumBuffers;
     74         // Lock protecting the Stream object for modifications
     75         pthread_mutex_t mMutex;
     76 };
     77 } // namespace default_camera_hal
     78 
     79 #endif // STREAM_H_
     80