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