Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [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_IO_STREAM_BASE_H |
| 18 | #define ANDROID_SERVERS_CAMERA3_IO_STREAM_BASE_H |
| 19 | |
| 20 | #include <utils/RefBase.h> |
| 21 | #include <gui/Surface.h> |
| 22 | |
| 23 | #include "Camera3Stream.h" |
| 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | namespace camera3 { |
| 28 | |
| 29 | /** |
| 30 | * A base class for managing a single stream of I/O data from the camera device. |
| 31 | */ |
| 32 | class Camera3IOStreamBase : |
| 33 | public Camera3Stream { |
| 34 | protected: |
| 35 | Camera3IOStreamBase(int id, camera3_stream_type_t type, |
| 36 | uint32_t width, uint32_t height, size_t maxSize, int format); |
| 37 | |
| 38 | public: |
| 39 | |
| 40 | virtual ~Camera3IOStreamBase(); |
| 41 | |
| 42 | /** |
| 43 | * Camera3Stream interface |
| 44 | */ |
| 45 | |
| 46 | virtual status_t waitUntilIdle(nsecs_t timeout); |
| 47 | virtual void dump(int fd, const Vector<String16> &args) const; |
| 48 | |
| 49 | protected: |
| 50 | size_t mTotalBufferCount; |
| 51 | // sum of input and output buffers that are currently acquired by HAL |
| 52 | size_t mDequeuedBufferCount; |
| 53 | Condition mBufferReturnedSignal; |
| 54 | uint32_t mFrameCount; |
| 55 | // Last received output buffer's timestamp |
| 56 | nsecs_t mLastTimestamp; |
| 57 | |
| 58 | // The merged release fence for all returned buffers |
| 59 | sp<Fence> mCombinedFence; |
| 60 | |
| 61 | status_t returnAnyBufferLocked( |
| 62 | const camera3_stream_buffer &buffer, |
| 63 | nsecs_t timestamp, |
| 64 | bool output); |
| 65 | |
| 66 | virtual status_t returnBufferCheckedLocked( |
| 67 | const camera3_stream_buffer &buffer, |
| 68 | nsecs_t timestamp, |
| 69 | bool output, |
| 70 | /*out*/ |
| 71 | sp<Fence> *releaseFenceOut) = 0; |
| 72 | |
| 73 | /** |
| 74 | * Internal Camera3Stream interface |
| 75 | */ |
| 76 | virtual bool hasOutstandingBuffersLocked() const; |
| 77 | |
| 78 | virtual size_t getBufferCountLocked(); |
| 79 | |
| 80 | status_t getBufferPreconditionCheckLocked() const; |
| 81 | status_t returnBufferPreconditionCheckLocked() const; |
| 82 | |
| 83 | // State check only |
| 84 | virtual status_t configureQueueLocked(); |
| 85 | // State checks only |
| 86 | virtual status_t disconnectLocked(); |
| 87 | |
| 88 | // Hand out the buffer to a native location, |
| 89 | // incrementing the internal refcount and dequeued buffer count |
| 90 | void handoutBufferLocked(camera3_stream_buffer &buffer, |
| 91 | buffer_handle_t *handle, |
| 92 | int acquire_fence, |
| 93 | int release_fence, |
| 94 | camera3_buffer_status_t status); |
| 95 | |
| 96 | }; // class Camera3IOStreamBase |
| 97 | |
| 98 | } // namespace camera3 |
| 99 | |
| 100 | } // namespace android |
| 101 | |
| 102 | #endif |