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 #include <utils/Mutex.h>
     24 
     25 namespace default_camera_hal {
     26 // Stream represents a single input or output stream for a camera device.
     27 class Stream {
     28     public:
     29         Stream(int id, camera3_stream_t *s);
     30         ~Stream();
     31 
     32         // validate that astream's parameters match this stream's parameters
     33         bool isValidReuseStream(int id, camera3_stream_t *s);
     34 
     35         // Register buffers with hardware
     36         int registerBuffers(const camera3_stream_buffer_set_t *buf_set);
     37 
     38         void setUsage(uint32_t usage);
     39         void setMaxBuffers(uint32_t max_buffers);
     40 
     41         int getType();
     42         bool isInputType();
     43         bool isOutputType();
     44         bool isRegistered();
     45         const char* typeToString(int type);
     46         const char* formatToString(int format);
     47         void dump(int fd);
     48 
     49         // This stream is being reused. Used in stream configuration passes
     50         bool mReuse;
     51 
     52     private:
     53         // Clean up buffer state. must be called with mLock held.
     54         void unregisterBuffers_L();
     55 
     56         // The camera device id this stream belongs to
     57         const int mId;
     58         // Handle to framework's stream, used as a cookie for buffers
     59         camera3_stream_t *mStream;
     60         // Stream type: CAMERA3_STREAM_* (see <hardware/camera3.h>)
     61         const int mType;
     62         // Width in pixels of the buffers in this stream
     63         const uint32_t mWidth;
     64         // Height in pixels of the buffers in this stream
     65         const uint32_t mHeight;
     66         // Gralloc format: HAL_PIXEL_FORMAT_* (see <system/graphics.h>)
     67         const int mFormat;
     68         // Gralloc usage mask : GRALLOC_USAGE_* (see <hardware/gralloc.h>)
     69         uint32_t mUsage;
     70         // Max simultaneous in-flight buffers for this stream
     71         uint32_t mMaxBuffers;
     72         // Buffers have been registered for this stream and are ready
     73         bool mRegistered;
     74         // Array of handles to buffers currently in use by the stream
     75         buffer_handle_t **mBuffers;
     76         // Number of buffers in mBuffers
     77         unsigned int mNumBuffers;
     78         // Lock protecting the Stream object for modifications
     79         android::Mutex mLock;
     80 };
     81 } // namespace default_camera_hal
     82 
     83 #endif // STREAM_H_
     84