Camera3OutputStream.h revision 125684aba1a11b7adbf5f9d607ee2bcc9449081c
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_OUTPUT_STREAM_H 18#define ANDROID_SERVERS_CAMERA3_OUTPUT_STREAM_H 19 20#include <utils/RefBase.h> 21#include <gui/IProducerListener.h> 22#include <gui/Surface.h> 23 24#include "Camera3Stream.h" 25#include "Camera3IOStreamBase.h" 26#include "Camera3OutputStreamInterface.h" 27#include "Camera3BufferManager.h" 28 29namespace android { 30 31namespace camera3 { 32 33class Camera3BufferManager; 34 35/** 36 * Stream info structure that holds the necessary stream info for buffer manager to use for 37 * buffer allocation and management. 38 */ 39struct StreamInfo { 40 int streamId; 41 int streamSetId; 42 uint32_t width; 43 uint32_t height; 44 uint32_t format; 45 android_dataspace dataSpace; 46 uint32_t combinedUsage; 47 size_t totalBufferCount; 48 bool isConfigured; 49 StreamInfo(int id = CAMERA3_STREAM_ID_INVALID, 50 int setId = CAMERA3_STREAM_SET_ID_INVALID, 51 uint32_t w = 0, 52 uint32_t h = 0, 53 uint32_t fmt = 0, 54 android_dataspace ds = HAL_DATASPACE_UNKNOWN, 55 uint32_t usage = 0, 56 size_t bufferCount = 0, 57 bool configured = false) : 58 streamId(id), 59 streamSetId(setId), 60 width(w), 61 height(h), 62 format(fmt), 63 dataSpace(ds), 64 combinedUsage(usage), 65 totalBufferCount(bufferCount), 66 isConfigured(configured){} 67}; 68 69/** 70 * A class for managing a single stream of output data from the camera device. 71 */ 72class Camera3OutputStream : 73 public Camera3IOStreamBase, 74 public Camera3OutputStreamInterface { 75 public: 76 /** 77 * Set up a stream for formats that have 2 dimensions, such as RAW and YUV. 78 * A valid stream set id needs to be set to support buffer sharing between multiple 79 * streams. 80 */ 81 Camera3OutputStream(int id, sp<Surface> consumer, 82 uint32_t width, uint32_t height, int format, 83 android_dataspace dataSpace, camera3_stream_rotation_t rotation, 84 int setId = CAMERA3_STREAM_SET_ID_INVALID); 85 86 /** 87 * Set up a stream for formats that have a variable buffer size for the same 88 * dimensions, such as compressed JPEG. 89 * A valid stream set id needs to be set to support buffer sharing between multiple 90 * streams. 91 */ 92 Camera3OutputStream(int id, sp<Surface> consumer, 93 uint32_t width, uint32_t height, size_t maxSize, int format, 94 android_dataspace dataSpace, camera3_stream_rotation_t rotation, 95 int setId = CAMERA3_STREAM_SET_ID_INVALID); 96 97 virtual ~Camera3OutputStream(); 98 99 /** 100 * Camera3Stream interface 101 */ 102 103 virtual void dump(int fd, const Vector<String16> &args) const; 104 105 /** 106 * Set the transform on the output stream; one of the 107 * HAL_TRANSFORM_* / NATIVE_WINDOW_TRANSFORM_* constants. 108 */ 109 status_t setTransform(int transform); 110 111 /** 112 * Return if this output stream is for video encoding. 113 */ 114 bool isVideoStream() const; 115 116 class BufferReleasedListener : public BnProducerListener { 117 public: 118 BufferReleasedListener(wp<Camera3OutputStream> parent) : mParent(parent) {} 119 120 /** 121 * Implementation of IProducerListener, used to notify this stream that the consumer 122 * has returned a buffer and it is ready to return to Camera3BufferManager for reuse. 123 */ 124 virtual void onBufferReleased(); 125 126 private: 127 wp<Camera3OutputStream> mParent; 128 }; 129 130 /** 131 * Set the graphic buffer manager to get/return the stream buffers. 132 * 133 * It is only legal to call this method when stream is in STATE_CONSTRUCTED state. 134 */ 135 status_t setBufferManager(sp<Camera3BufferManager> bufferManager); 136 137 protected: 138 Camera3OutputStream(int id, camera3_stream_type_t type, 139 uint32_t width, uint32_t height, int format, 140 android_dataspace dataSpace, camera3_stream_rotation_t rotation, 141 int setId = CAMERA3_STREAM_SET_ID_INVALID); 142 143 /** 144 * Note that we release the lock briefly in this function 145 */ 146 virtual status_t returnBufferCheckedLocked( 147 const camera3_stream_buffer &buffer, 148 nsecs_t timestamp, 149 bool output, 150 /*out*/ 151 sp<Fence> *releaseFenceOut); 152 153 virtual status_t disconnectLocked(); 154 155 sp<Surface> mConsumer; 156 private: 157 int mTransform; 158 159 virtual status_t setTransformLocked(int transform); 160 161 bool mTraceFirstBuffer; 162 163 // Name of Surface consumer 164 String8 mConsumerName; 165 166 /** 167 * GraphicBuffer manager this stream is registered to. Used to replace the buffer 168 * allocation/deallocation role of BufferQueue. 169 */ 170 sp<Camera3BufferManager> mBufferManager; 171 172 /** 173 * Buffer released listener, used to notify the buffer manager that a buffer is released 174 * from consumer side. 175 */ 176 sp<BufferReleasedListener> mBufferReleasedListener; 177 178 /** 179 * Flag indicating if the buffer manager is used to allocate the stream buffers 180 */ 181 bool mUseBufferManager; 182 /** 183 * Internal Camera3Stream interface 184 */ 185 virtual status_t getBufferLocked(camera3_stream_buffer *buffer); 186 virtual status_t returnBufferLocked( 187 const camera3_stream_buffer &buffer, 188 nsecs_t timestamp); 189 190 virtual status_t configureQueueLocked(); 191 192 virtual status_t getEndpointUsage(uint32_t *usage) const; 193 194}; // class Camera3OutputStream 195 196} // namespace camera3 197 198} // namespace android 199 200#endif 201