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 android_dataspace dataSpace, camera3_stream_rotation_t rotation); 38 39 public: 40 41 virtual ~Camera3IOStreamBase(); 42 43 /** 44 * Camera3Stream interface 45 */ 46 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 mHandoutTotalBufferCount; 53 // number of output buffers that are currently acquired by HAL. This will be 54 // Redundant when camera3 streams are no longer bidirectional streams. 55 size_t mHandoutOutputBufferCount; 56 Condition mBufferReturnedSignal; 57 uint32_t mFrameCount; 58 // Last received output buffer's timestamp 59 nsecs_t mLastTimestamp; 60 61 // The merged release fence for all returned buffers 62 sp<Fence> mCombinedFence; 63 64 status_t returnAnyBufferLocked( 65 const camera3_stream_buffer &buffer, 66 nsecs_t timestamp, 67 bool output); 68 69 virtual status_t returnBufferCheckedLocked( 70 const camera3_stream_buffer &buffer, 71 nsecs_t timestamp, 72 bool output, 73 /*out*/ 74 sp<Fence> *releaseFenceOut) = 0; 75 76 /** 77 * Internal Camera3Stream interface 78 */ 79 virtual bool hasOutstandingBuffersLocked() const; 80 81 virtual size_t getBufferCountLocked(); 82 83 virtual size_t getHandoutOutputBufferCountLocked(); 84 85 virtual size_t getHandoutInputBufferCountLocked(); 86 87 virtual status_t getEndpointUsage(uint32_t *usage) const = 0; 88 89 status_t getBufferPreconditionCheckLocked() const; 90 status_t returnBufferPreconditionCheckLocked() const; 91 92 // State check only 93 virtual status_t configureQueueLocked(); 94 // State checks only 95 virtual status_t disconnectLocked(); 96 97 // Hand out the buffer to a native location, 98 // incrementing the internal refcount and dequeued buffer count 99 void handoutBufferLocked(camera3_stream_buffer &buffer, 100 buffer_handle_t *handle, 101 int acquire_fence, 102 int release_fence, 103 camera3_buffer_status_t status, 104 bool output); 105 106 }; // class Camera3IOStreamBase 107 108 } // namespace camera3 109 110 } // namespace android 111 112 #endif 113