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 | |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 24 | #include "Camera3OutputStream.h" |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | namespace camera3 { |
| 29 | |
| 30 | /** |
| 31 | * A class for managing a single opaque ZSL stream to/from the camera device. |
| 32 | * This acts as a bidirectional stream at the HAL layer, caching and discarding |
| 33 | * most output buffers, and when directed, pushes a buffer back to the HAL for |
| 34 | * processing. |
| 35 | */ |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 36 | class Camera3ZslStream : |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 37 | public Camera3OutputStream { |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 38 | public: |
| 39 | /** |
Igor Murashkin | 054aab3 | 2013-11-18 11:39:27 -0800 | [diff] [blame] | 40 | * Set up a ZSL stream of a given resolution. bufferCount is the number of buffers |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 41 | * cached within the stream that can be retrieved for input. |
| 42 | */ |
Igor Murashkin | 054aab3 | 2013-11-18 11:39:27 -0800 | [diff] [blame] | 43 | Camera3ZslStream(int id, uint32_t width, uint32_t height, int bufferCount); |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 44 | ~Camera3ZslStream(); |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 45 | |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 46 | virtual void dump(int fd, const Vector<String16> &args) const; |
| 47 | |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 48 | enum { NO_BUFFER_AVAILABLE = BufferQueue::NO_BUFFER_AVAILABLE }; |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 49 | |
| 50 | /** |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 51 | * Locate a buffer matching this timestamp in the RingBufferConsumer, |
| 52 | * and mark it to be queued at the next getInputBufferLocked invocation. |
| 53 | * |
| 54 | * Errors: Returns NO_BUFFER_AVAILABLE if we could not find a match. |
| 55 | * |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 56 | */ |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 57 | status_t enqueueInputBufferByTimestamp(nsecs_t timestamp, |
| 58 | nsecs_t* actualTimestamp); |
| 59 | |
| 60 | /** |
| 61 | * Clears the buffers that can be used by enqueueInputBufferByTimestamp |
Yin-Chia Yeh | 6b7a229 | 2014-09-09 13:31:46 -0700 | [diff] [blame] | 62 | * latestTimestamp will be filled with the largest timestamp of buffers |
| 63 | * being cleared, 0 if there is no buffer being clear. |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 64 | */ |
Yin-Chia Yeh | 6b7a229 | 2014-09-09 13:31:46 -0700 | [diff] [blame] | 65 | status_t clearInputRingBuffer(nsecs_t* latestTimestamp); |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 66 | |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 67 | protected: |
| 68 | |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 69 | /** |
| 70 | * Camera3OutputStreamInterface implementation |
| 71 | */ |
| 72 | status_t setTransform(int transform); |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 73 | |
| 74 | private: |
| 75 | |
| 76 | int mDepth; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 77 | // Input buffers pending to be queued into HAL |
| 78 | List<sp<RingBufferConsumer::PinnedBufferItem> > mInputBufferQueue; |
| 79 | sp<RingBufferConsumer> mProducer; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 80 | |
| 81 | // Input buffers in flight to HAL |
| 82 | Vector<sp<RingBufferConsumer::PinnedBufferItem> > mBuffersInFlight; |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 83 | |
| 84 | /** |
| 85 | * Camera3Stream interface |
| 86 | */ |
| 87 | |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 88 | // getInputBuffer/returnInputBuffer operate the input stream side of the |
| 89 | // ZslStream. |
| 90 | virtual status_t getInputBufferLocked(camera3_stream_buffer *buffer); |
| 91 | virtual status_t returnInputBufferLocked( |
| 92 | const camera3_stream_buffer &buffer); |
| 93 | |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 94 | // Actual body to return either input or output buffers |
| 95 | virtual status_t returnBufferCheckedLocked( |
| 96 | const camera3_stream_buffer &buffer, |
| 97 | nsecs_t timestamp, |
| 98 | bool output, |
| 99 | /*out*/ |
| 100 | sp<Fence> *releaseFenceOut); |
Zhijun He | 0a21051 | 2014-07-24 13:45:15 -0700 | [diff] [blame] | 101 | |
| 102 | // Disconnet the Camera3ZslStream specific bufferQueues. |
| 103 | virtual status_t disconnectLocked(); |
| 104 | |
Yin-Chia Yeh | 6b7a229 | 2014-09-09 13:31:46 -0700 | [diff] [blame] | 105 | status_t clearInputRingBufferLocked(nsecs_t* latestTimestamp); |
Zhijun He | 0a21051 | 2014-07-24 13:45:15 -0700 | [diff] [blame] | 106 | |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 107 | }; // class Camera3ZslStream |
| 108 | |
| 109 | }; // namespace camera3 |
| 110 | |
| 111 | }; // namespace android |
| 112 | |
| 113 | #endif |