1 /* 2 * Copyright (C) 2013-2018 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, camera_stream_type_t type, 36 uint32_t width, uint32_t height, size_t maxSize, int format, 37 android_dataspace dataSpace, camera_stream_rotation_t rotation, 38 const String8& physicalCameraId, 39 const std::unordered_set<int32_t> &sensorPixelModesUsed, 40 int setId = CAMERA3_STREAM_SET_ID_INVALID, bool isMultiResolution = false, 41 int64_t dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD, 42 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT, 43 bool deviceTimeBaseIsRealtime = false, 44 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT); 45 46 public: 47 48 virtual ~Camera3IOStreamBase(); 49 50 /** 51 * Camera3Stream interface 52 */ 53 54 virtual void dump(int fd, const Vector<String16> &args) const; 55 getMaxTotalBuffers()56 int getMaxTotalBuffers() const { return mTotalBufferCount; } 57 protected: 58 size_t mTotalBufferCount; 59 // The maximum number of cached buffers allowed for this stream 60 size_t mMaxCachedBufferCount; 61 62 // sum of input and output buffers that are currently acquired by HAL 63 size_t mHandoutTotalBufferCount; 64 // number of output buffers that are currently acquired by HAL. This will be 65 // Redundant when camera3 streams are no longer bidirectional streams. 66 size_t mHandoutOutputBufferCount; 67 // number of cached output buffers that are currently queued in the camera 68 // server but not yet queued to the buffer queue. 69 size_t mCachedOutputBufferCount; 70 71 uint32_t mFrameCount; 72 // Last received output buffer's timestamp 73 nsecs_t mLastTimestamp; 74 75 // The merged release fence for all returned buffers 76 sp<Fence> mCombinedFence; 77 78 status_t returnAnyBufferLocked( 79 const camera_stream_buffer &buffer, 80 nsecs_t timestamp, 81 nsecs_t readoutTimestamp, 82 bool output, 83 int32_t transform, 84 const std::vector<size_t>& surface_ids = std::vector<size_t>()); 85 86 virtual status_t returnBufferCheckedLocked( 87 const camera_stream_buffer &buffer, 88 nsecs_t timestamp, 89 nsecs_t readoutTimestamp, 90 bool output, 91 int32_t transform, 92 const std::vector<size_t>& surface_ids, 93 /*out*/ 94 sp<Fence> *releaseFenceOut) = 0; 95 96 /** 97 * Internal Camera3Stream interface 98 */ 99 virtual bool hasOutstandingBuffersLocked() const; 100 101 virtual size_t getBufferCountLocked(); 102 103 virtual size_t getHandoutOutputBufferCountLocked() const; 104 105 virtual size_t getHandoutInputBufferCountLocked(); 106 107 virtual size_t getCachedOutputBufferCountLocked() const; 108 virtual size_t getMaxCachedOutputBuffersLocked() const; 109 110 virtual status_t getEndpointUsage(uint64_t *usage) const = 0; 111 112 status_t getBufferPreconditionCheckLocked() const; 113 status_t returnBufferPreconditionCheckLocked() const; 114 115 // State check only 116 virtual status_t configureQueueLocked(); 117 // State checks only 118 virtual status_t disconnectLocked(); 119 120 // Hand out the buffer to a native location, 121 // incrementing the internal refcount and dequeued buffer count 122 void handoutBufferLocked(camera_stream_buffer &buffer, 123 buffer_handle_t *handle, 124 int acquire_fence, 125 int release_fence, 126 camera_buffer_status_t status, 127 bool output); 128 129 }; // class Camera3IOStreamBase 130 131 } // namespace camera3 132 133 } // namespace android 134 135 #endif 136