1 /* 2 * Copyright (C) 2014-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_FAKE_STREAM_H 18 #define ANDROID_SERVERS_CAMERA3_FAKE_STREAM_H 19 20 #include <utils/RefBase.h> 21 #include <gui/Surface.h> 22 23 #include "Camera3Stream.h" 24 #include "Camera3IOStreamBase.h" 25 #include "Camera3OutputStreamInterface.h" 26 27 namespace android { 28 namespace camera3 { 29 30 /** 31 * A fake output stream class, to be used as a placeholder when no valid 32 * streams are configured by the client. 33 * This is necessary because camera HAL v3.2 or older disallow configuring 34 * 0 output streams, while the public camera2 API allows for it. 35 */ 36 class Camera3FakeStream : 37 public Camera3IOStreamBase, 38 public Camera3OutputStreamInterface { 39 40 public: 41 /** 42 * Set up a fake stream; doesn't actually connect to anything, and uses 43 * a default fake format and size. 44 */ 45 explicit Camera3FakeStream(int id); 46 47 virtual ~Camera3FakeStream(); 48 49 /** 50 * Camera3Stream interface 51 */ 52 53 virtual void dump(int fd, const Vector<String16> &args); 54 55 status_t setTransform(int transform, bool mayChangeMirror); 56 57 virtual status_t detachBuffer(sp<GraphicBuffer>* buffer, int* fenceFd); 58 59 /** 60 * Drop buffers for stream of streamId if dropping is true. If dropping is false, do not 61 * drop buffers for stream of streamId. 62 */ 63 virtual status_t dropBuffers(bool /*dropping*/) override; 64 65 /** 66 * Query the physical camera id for the output stream. 67 */ 68 virtual const std::string& getPhysicalCameraId() const override; 69 70 /** 71 * Return if this output stream is for video encoding. 72 */ 73 bool isVideoStream(); 74 75 /** 76 * Return if the consumer configuration of this stream is deferred. 77 */ 78 virtual bool isConsumerConfigurationDeferred(size_t surface_id) const; 79 80 /** 81 * Set the consumer surfaces to the output stream. 82 */ 83 virtual status_t setConsumers(const std::vector<sp<Surface>>& consumers); 84 85 /** 86 * Query the output surface id. 87 */ getSurfaceId(const sp<Surface> &)88 virtual ssize_t getSurfaceId(const sp<Surface> &/*surface*/) { return 0; } 89 getUniqueSurfaceIds(const std::vector<size_t> &,std::vector<size_t> *)90 virtual status_t getUniqueSurfaceIds(const std::vector<size_t>&, 91 /*out*/std::vector<size_t>*) { return INVALID_OPERATION; }; 92 93 /** 94 * Update the stream output surfaces. 95 */ 96 virtual status_t updateStream(const std::vector<sp<Surface>> &outputSurfaces, 97 const std::vector<OutputStreamInfo> &outputInfo, 98 const std::vector<size_t> &removedSurfaceIds, 99 KeyedVector<sp<Surface>, size_t> *outputMap/*out*/); 100 101 virtual status_t setBatchSize(size_t batchSize) override; 102 onMinDurationChanged(nsecs_t,bool)103 virtual void onMinDurationChanged(nsecs_t /*duration*/, bool /*fixedFps*/) {} 104 setStreamUseCase(int64_t)105 virtual void setStreamUseCase(int64_t /*streamUseCase*/) {} 106 protected: 107 108 /** 109 * Note that we release the lock briefly in this function 110 */ 111 virtual status_t returnBufferCheckedLocked( 112 const camera_stream_buffer &buffer, 113 nsecs_t timestamp, 114 nsecs_t readoutTimestamp, 115 bool output, 116 int32_t transform, 117 const std::vector<size_t>& surface_ids, 118 /*out*/ 119 sp<Fence> *releaseFenceOut); 120 121 virtual status_t disconnectLocked(); 122 123 private: 124 125 // Default fake parameters; 320x240 is a required size for all devices, 126 // otherwise act like a SurfaceView would. 127 static const int FAKE_WIDTH = 320; 128 static const int FAKE_HEIGHT = 240; 129 static const int FAKE_FORMAT = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED; 130 static const android_dataspace FAKE_DATASPACE = HAL_DATASPACE_UNKNOWN; 131 static const camera_stream_rotation_t FAKE_ROTATION = CAMERA_STREAM_ROTATION_0; 132 static const uint64_t FAKE_USAGE = GRALLOC_USAGE_HW_COMPOSER; 133 static const std::string FAKE_ID; 134 135 /** 136 * Internal Camera3Stream interface 137 */ 138 virtual status_t getBufferLocked(camera_stream_buffer *buffer, 139 const std::vector<size_t>& surface_ids = std::vector<size_t>()); 140 virtual status_t returnBufferLocked( 141 const camera_stream_buffer &buffer, 142 nsecs_t timestamp, nsecs_t readoutTimestamp, int32_t transform, 143 const std::vector<size_t>& surface_ids); 144 145 virtual status_t configureQueueLocked(); 146 147 virtual status_t getEndpointUsage(uint64_t *usage); 148 149 }; // class Camera3FakeStream 150 151 } // namespace camera3 152 153 } // namespace android 154 155 #endif 156