Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -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 ANDROID_SERVERS_CAMERA3_ZSL_STREAM_H |
| 18 | #define ANDROID_SERVERS_CAMERA3_ZSL_STREAM_H |
| 19 | |
| 20 | #include <utils/RefBase.h> |
| 21 | #include <gui/Surface.h> |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame^] | 22 | #include <gui/RingBufferConsumer.h> |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 23 | |
| 24 | #include "Camera3Stream.h" |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame^] | 25 | #include "Camera3OutputStreamInterface.h" |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | namespace camera3 { |
| 30 | |
| 31 | /** |
| 32 | * A class for managing a single opaque ZSL stream to/from the camera device. |
| 33 | * This acts as a bidirectional stream at the HAL layer, caching and discarding |
| 34 | * most output buffers, and when directed, pushes a buffer back to the HAL for |
| 35 | * processing. |
| 36 | */ |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame^] | 37 | class Camera3ZslStream : |
| 38 | public Camera3Stream, |
| 39 | public Camera3OutputStreamInterface { |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 40 | public: |
| 41 | /** |
| 42 | * Set up a ZSL stream of a given resolution. Depth is the number of buffers |
| 43 | * cached within the stream that can be retrieved for input. |
| 44 | */ |
| 45 | Camera3ZslStream(int id, uint32_t width, uint32_t height, int depth); |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame^] | 46 | ~Camera3ZslStream(); |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 47 | |
| 48 | virtual status_t waitUntilIdle(nsecs_t timeout); |
| 49 | virtual void dump(int fd, const Vector<String16> &args) const; |
| 50 | |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame^] | 51 | enum { NO_BUFFER_AVAILABLE = BufferQueue::NO_BUFFER_AVAILABLE }; |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 52 | |
| 53 | /** |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame^] | 54 | * Locate a buffer matching this timestamp in the RingBufferConsumer, |
| 55 | * and mark it to be queued at the next getInputBufferLocked invocation. |
| 56 | * |
| 57 | * Errors: Returns NO_BUFFER_AVAILABLE if we could not find a match. |
| 58 | * |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 59 | */ |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame^] | 60 | status_t enqueueInputBufferByTimestamp(nsecs_t timestamp, |
| 61 | nsecs_t* actualTimestamp); |
| 62 | |
| 63 | /** |
| 64 | * Clears the buffers that can be used by enqueueInputBufferByTimestamp |
| 65 | */ |
| 66 | status_t clearInputRingBuffer(); |
| 67 | |
| 68 | /** |
| 69 | * Camera3OutputStreamInterface implementation |
| 70 | */ |
| 71 | status_t setTransform(int transform); |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 72 | |
| 73 | private: |
| 74 | |
| 75 | int mDepth; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame^] | 76 | // Input buffers pending to be queued into HAL |
| 77 | List<sp<RingBufferConsumer::PinnedBufferItem> > mInputBufferQueue; |
| 78 | sp<RingBufferConsumer> mProducer; |
| 79 | sp<ANativeWindow> mConsumer; |
| 80 | |
| 81 | // Input buffers in flight to HAL |
| 82 | Vector<sp<RingBufferConsumer::PinnedBufferItem> > mBuffersInFlight; |
| 83 | size_t mTotalBufferCount; |
| 84 | // sum of input and output buffers that are currently acquired by HAL |
| 85 | size_t mDequeuedBufferCount; |
| 86 | Condition mBufferReturnedSignal; |
| 87 | uint32_t mFrameCount; |
| 88 | // Last received output buffer's timestamp |
| 89 | nsecs_t mLastTimestamp; |
| 90 | |
| 91 | // The merged release fence for all returned buffers |
| 92 | sp<Fence> mCombinedFence; |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * Camera3Stream interface |
| 96 | */ |
| 97 | |
| 98 | // getBuffer/returnBuffer operate the output stream side of the ZslStream. |
| 99 | virtual status_t getBufferLocked(camera3_stream_buffer *buffer); |
| 100 | virtual status_t returnBufferLocked(const camera3_stream_buffer &buffer, |
| 101 | nsecs_t timestamp); |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame^] | 102 | // getInputBuffer/returnInputBuffer operate the input stream side of the |
| 103 | // ZslStream. |
| 104 | virtual status_t getInputBufferLocked(camera3_stream_buffer *buffer); |
| 105 | virtual status_t returnInputBufferLocked( |
| 106 | const camera3_stream_buffer &buffer); |
| 107 | |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 108 | virtual bool hasOutstandingBuffersLocked() const; |
| 109 | virtual status_t disconnectLocked(); |
| 110 | |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame^] | 111 | virtual status_t configureQueueLocked(); |
| 112 | virtual size_t getBufferCountLocked(); |
| 113 | |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 114 | }; // class Camera3ZslStream |
| 115 | |
| 116 | }; // namespace camera3 |
| 117 | |
| 118 | }; // namespace android |
| 119 | |
| 120 | #endif |