Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 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> |
Alex Ray | 5556764 | 2013-11-12 12:58:39 -0800 | [diff] [blame] | 23 | #include <utils/Mutex.h> |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 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 | |
Alex Ray | 8a8f86b | 2013-03-01 01:32:21 -0800 | [diff] [blame] | 35 | // Register buffers with hardware |
| 36 | int registerBuffers(const camera3_stream_buffer_set_t *buf_set); |
| 37 | |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 38 | void setUsage(uint32_t usage); |
| 39 | void setMaxBuffers(uint32_t max_buffers); |
| 40 | |
| 41 | int getType(); |
| 42 | bool isInputType(); |
| 43 | bool isOutputType(); |
Alex Ray | 8a8f86b | 2013-03-01 01:32:21 -0800 | [diff] [blame] | 44 | bool isRegistered(); |
Alex Ray | 69f1f91 | 2013-10-21 00:46:44 -0700 | [diff] [blame] | 45 | const char* typeToString(int type); |
| 46 | const char* formatToString(int format); |
| 47 | void dump(int fd); |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 48 | |
| 49 | // This stream is being reused. Used in stream configuration passes |
| 50 | bool mReuse; |
| 51 | |
| 52 | private: |
Alex Ray | 5556764 | 2013-11-12 12:58:39 -0800 | [diff] [blame] | 53 | // Clean up buffer state. must be called with mLock held. |
Alex Ray | 8a8f86b | 2013-03-01 01:32:21 -0800 | [diff] [blame] | 54 | void unregisterBuffers_L(); |
| 55 | |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 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 |
Alex Ray | 2b286da | 2013-05-29 15:08:29 -0700 | [diff] [blame] | 59 | camera3_stream_t *mStream; |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 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; |
Alex Ray | 8a8f86b | 2013-03-01 01:32:21 -0800 | [diff] [blame] | 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; |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 78 | // Lock protecting the Stream object for modifications |
Alex Ray | 5556764 | 2013-11-12 12:58:39 -0800 | [diff] [blame] | 79 | android::Mutex mLock; |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 80 | }; |
| 81 | } // namespace default_camera_hal |
| 82 | |
| 83 | #endif // STREAM_H_ |