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 void dump(int fd, const Vector<String16> &args) const; 47 48 protected: 49 size_t mTotalBufferCount; 50 // sum of input and output buffers that are currently acquired by HAL 51 size_t mDequeuedBufferCount; 52 Condition mBufferReturnedSignal; 53 uint32_t mFrameCount; 54 // Last received output buffer's timestamp 55 nsecs_t mLastTimestamp; 56 57 // The merged release fence for all returned buffers 58 sp<Fence> mCombinedFence; 59 60 status_t returnAnyBufferLocked( 61 const camera3_stream_buffer &buffer, 62 nsecs_t timestamp, 63 bool output); 64 65 virtual status_t returnBufferCheckedLocked( 66 const camera3_stream_buffer &buffer, 67 nsecs_t timestamp, 68 bool output, 69 /*out*/ 70 sp<Fence> *releaseFenceOut) = 0; 71 72 /** 73 * Internal Camera3Stream interface 74 */ 75 virtual bool hasOutstandingBuffersLocked() const; 76 77 virtual size_t getBufferCountLocked(); 78 79 virtual status_t getEndpointUsage(uint32_t *usage) = 0; 80 81 status_t getBufferPreconditionCheckLocked() const; 82 status_t returnBufferPreconditionCheckLocked() const; 83 84 // State check only 85 virtual status_t configureQueueLocked(); 86 // State checks only 87 virtual status_t disconnectLocked(); 88 89 // Hand out the buffer to a native location, 90 // incrementing the internal refcount and dequeued buffer count 91 void handoutBufferLocked(camera3_stream_buffer &buffer, 92 buffer_handle_t *handle, 93 int acquire_fence, 94 int release_fence, 95 camera3_buffer_status_t status); 96 97 }; // class Camera3IOStreamBase 98 99 } // namespace camera3 100 101 } // namespace android 102 103 #endif 104