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_STREAM_INTERFACE_H 18 #define ANDROID_SERVERS_CAMERA3_STREAM_INTERFACE_H 19 20 #include <utils/RefBase.h> 21 #include "Camera3StreamBufferListener.h" 22 23 struct camera3_stream_buffer; 24 25 namespace android { 26 27 namespace camera3 { 28 29 class StatusTracker; 30 31 /** 32 * An interface for managing a single stream of input and/or output data from 33 * the camera device. 34 */ 35 class Camera3StreamInterface : public virtual RefBase { 36 public: 37 /** 38 * Get the stream's ID 39 */ 40 virtual int getId() const = 0; 41 42 /** 43 * Get the stream's dimensions and format 44 */ 45 virtual uint32_t getWidth() const = 0; 46 virtual uint32_t getHeight() const = 0; 47 virtual int getFormat() const = 0; 48 49 /** 50 * Start the stream configuration process. Returns a handle to the stream's 51 * information to be passed into the HAL device's configure_streams call. 52 * 53 * Until finishConfiguration() is called, no other methods on the stream may 54 * be called. The usage and max_buffers fields of camera3_stream may be 55 * modified between start/finishConfiguration, but may not be changed after 56 * that. The priv field of camera3_stream may be modified at any time after 57 * startConfiguration. 58 * 59 * Returns NULL in case of error starting configuration. 60 */ 61 virtual camera3_stream* startConfiguration() = 0; 62 63 /** 64 * Check if the stream is mid-configuration (start has been called, but not 65 * finish). Used for lazy completion of configuration. 66 */ 67 virtual bool isConfiguring() const = 0; 68 69 /** 70 * Completes the stream configuration process. During this call, the stream 71 * may call the device's register_stream_buffers() method. The stream 72 * information structure returned by startConfiguration() may no longer be 73 * modified after this call, but can still be read until the destruction of 74 * the stream. 75 * 76 * Returns: 77 * OK on a successful configuration 78 * NO_INIT in case of a serious error from the HAL device 79 * NO_MEMORY in case of an error registering buffers 80 * INVALID_OPERATION in case connecting to the consumer failed 81 */ 82 virtual status_t finishConfiguration(camera3_device *hal3Device) = 0; 83 84 /** 85 * Fill in the camera3_stream_buffer with the next valid buffer for this 86 * stream, to hand over to the HAL. 87 * 88 * This method may only be called once finishConfiguration has been called. 89 * For bidirectional streams, this method applies to the output-side 90 * buffers. 91 * 92 */ 93 virtual status_t getBuffer(camera3_stream_buffer *buffer) = 0; 94 95 /** 96 * Return a buffer to the stream after use by the HAL. 97 * 98 * This method may only be called for buffers provided by getBuffer(). 99 * For bidirectional streams, this method applies to the output-side buffers 100 */ 101 virtual status_t returnBuffer(const camera3_stream_buffer &buffer, 102 nsecs_t timestamp) = 0; 103 104 /** 105 * Fill in the camera3_stream_buffer with the next valid buffer for this 106 * stream, to hand over to the HAL. 107 * 108 * This method may only be called once finishConfiguration has been called. 109 * For bidirectional streams, this method applies to the input-side 110 * buffers. 111 * 112 */ 113 virtual status_t getInputBuffer(camera3_stream_buffer *buffer) = 0; 114 115 /** 116 * Return a buffer to the stream after use by the HAL. 117 * 118 * This method may only be called for buffers provided by getBuffer(). 119 * For bidirectional streams, this method applies to the input-side buffers 120 */ 121 virtual status_t returnInputBuffer(const camera3_stream_buffer &buffer) = 0; 122 123 /** 124 * Whether any of the stream's buffers are currently in use by the HAL, 125 * including buffers that have been returned but not yet had their 126 * release fence signaled. 127 */ 128 virtual bool hasOutstandingBuffers() const = 0; 129 130 enum { 131 TIMEOUT_NEVER = -1 132 }; 133 134 /** 135 * Set the state tracker to use for signaling idle transitions. 136 */ 137 virtual status_t setStatusTracker(sp<StatusTracker> statusTracker) = 0; 138 139 /** 140 * Disconnect stream from its non-HAL endpoint. After this, 141 * start/finishConfiguration must be called before the stream can be used 142 * again. This cannot be called if the stream has outstanding dequeued 143 * buffers. 144 */ 145 virtual status_t disconnect() = 0; 146 147 /** 148 * Debug dump of the stream's state. 149 */ 150 virtual void dump(int fd, const Vector<String16> &args) const = 0; 151 152 virtual void addBufferListener( 153 wp<Camera3StreamBufferListener> listener) = 0; 154 virtual void removeBufferListener( 155 const sp<Camera3StreamBufferListener>& listener) = 0; 156 }; 157 158 } // namespace camera3 159 160 } // namespace android 161 162 #endif 163