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