Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 1 | /* |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 2 | * Copyright (C) 2013-2018 The Android Open Source Project |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 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, |
Eino-Ville Talvala | 3d82c0d | 2015-02-23 15:19:19 -0800 | [diff] [blame] | 36 | uint32_t width, uint32_t height, size_t maxSize, int format, |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 37 | android_dataspace dataSpace, camera3_stream_rotation_t rotation, |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 38 | const String8& physicalCameraId, |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 39 | int setId = CAMERA3_STREAM_SET_ID_INVALID); |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 40 | |
| 41 | public: |
| 42 | |
| 43 | virtual ~Camera3IOStreamBase(); |
| 44 | |
| 45 | /** |
| 46 | * Camera3Stream interface |
| 47 | */ |
| 48 | |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 49 | virtual void dump(int fd, const Vector<String16> &args) const; |
| 50 | |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 51 | int getMaxTotalBuffers() const { return mTotalBufferCount; } |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 52 | protected: |
| 53 | size_t mTotalBufferCount; |
| 54 | // sum of input and output buffers that are currently acquired by HAL |
Zhijun He | 6adc9cc | 2014-04-15 14:09:55 -0700 | [diff] [blame] | 55 | size_t mHandoutTotalBufferCount; |
| 56 | // number of output buffers that are currently acquired by HAL. This will be |
| 57 | // Redundant when camera3 streams are no longer bidirectional streams. |
| 58 | size_t mHandoutOutputBufferCount; |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 59 | uint32_t mFrameCount; |
| 60 | // Last received output buffer's timestamp |
| 61 | nsecs_t mLastTimestamp; |
| 62 | |
| 63 | // The merged release fence for all returned buffers |
| 64 | sp<Fence> mCombinedFence; |
| 65 | |
| 66 | status_t returnAnyBufferLocked( |
| 67 | const camera3_stream_buffer &buffer, |
| 68 | nsecs_t timestamp, |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 69 | bool output, |
| 70 | const std::vector<size_t>& surface_ids = std::vector<size_t>()); |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 71 | |
| 72 | virtual status_t returnBufferCheckedLocked( |
| 73 | const camera3_stream_buffer &buffer, |
| 74 | nsecs_t timestamp, |
| 75 | bool output, |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 76 | const std::vector<size_t>& surface_ids, |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 77 | /*out*/ |
| 78 | sp<Fence> *releaseFenceOut) = 0; |
| 79 | |
| 80 | /** |
| 81 | * Internal Camera3Stream interface |
| 82 | */ |
| 83 | virtual bool hasOutstandingBuffersLocked() const; |
| 84 | |
| 85 | virtual size_t getBufferCountLocked(); |
| 86 | |
Yin-Chia Yeh | d5cd5ff | 2018-10-01 14:43:04 -0700 | [diff] [blame] | 87 | virtual size_t getHandoutOutputBufferCountLocked() const; |
Zhijun He | 6adc9cc | 2014-04-15 14:09:55 -0700 | [diff] [blame] | 88 | |
| 89 | virtual size_t getHandoutInputBufferCountLocked(); |
| 90 | |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 91 | virtual status_t getEndpointUsage(uint64_t *usage) const = 0; |
Eino-Ville Talvala | b2f5b19 | 2013-07-30 14:36:03 -0700 | [diff] [blame] | 92 | |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 93 | status_t getBufferPreconditionCheckLocked() const; |
| 94 | status_t returnBufferPreconditionCheckLocked() const; |
| 95 | |
| 96 | // State check only |
| 97 | virtual status_t configureQueueLocked(); |
| 98 | // State checks only |
| 99 | virtual status_t disconnectLocked(); |
| 100 | |
| 101 | // Hand out the buffer to a native location, |
| 102 | // incrementing the internal refcount and dequeued buffer count |
| 103 | void handoutBufferLocked(camera3_stream_buffer &buffer, |
| 104 | buffer_handle_t *handle, |
| 105 | int acquire_fence, |
| 106 | int release_fence, |
Zhijun He | 6adc9cc | 2014-04-15 14:09:55 -0700 | [diff] [blame] | 107 | camera3_buffer_status_t status, |
| 108 | bool output); |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 109 | |
| 110 | }; // class Camera3IOStreamBase |
| 111 | |
| 112 | } // namespace camera3 |
| 113 | |
| 114 | } // namespace android |
| 115 | |
| 116 | #endif |