1 /* 2 * Copyright (C) 2016-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_SHARED_OUTPUT_STREAM_H 18 #define ANDROID_SERVERS_CAMERA3_SHARED_OUTPUT_STREAM_H 19 20 #include <array> 21 #include "Camera3StreamSplitter.h" 22 #include "Camera3OutputStream.h" 23 24 namespace android { 25 26 namespace camera3 { 27 28 class Camera3SharedOutputStream : 29 public Camera3OutputStream { 30 public: 31 /** 32 * Set up a stream for formats that have 2 dimensions, with multiple 33 * surfaces. A valid stream set id needs to be set to support buffer 34 * sharing between multiple streams. 35 */ 36 Camera3SharedOutputStream(int id, const std::vector<sp<Surface>>& surfaces, 37 uint32_t width, uint32_t height, int format, 38 uint64_t consumerUsage, android_dataspace dataSpace, 39 camera_stream_rotation_t rotation, nsecs_t timestampOffset, 40 const String8& physicalCameraId, 41 const std::unordered_set<int32_t> &sensorPixelModesUsed, 42 int setId = CAMERA3_STREAM_SET_ID_INVALID, 43 bool useHalBufManager = false); 44 45 virtual ~Camera3SharedOutputStream(); 46 47 virtual status_t notifyBufferReleased(ANativeWindowBuffer *buffer); 48 49 virtual bool isConsumerConfigurationDeferred(size_t surface_id) const; 50 51 virtual status_t setConsumers(const std::vector<sp<Surface>>& consumers); 52 53 virtual ssize_t getSurfaceId(const sp<Surface> &surface); 54 55 /** 56 * Query the unique surface IDs of current surfaceIds. 57 * When passing unique surface IDs in returnBuffer(), if the 58 * surfaceId has been removed from the stream, the output corresponding to 59 * the unique surface ID will be ignored and not delivered to client. 60 */ 61 virtual status_t getUniqueSurfaceIds(const std::vector<size_t>& surfaceIds, 62 /*out*/std::vector<size_t>* outUniqueIds) override; 63 64 virtual status_t updateStream(const std::vector<sp<Surface>> &outputSurfaces, 65 const std::vector<OutputStreamInfo> &outputInfo, 66 const std::vector<size_t> &removedSurfaceIds, 67 KeyedVector<sp<Surface>, size_t> *outputMap/*out*/); 68 getOfflineProcessingSupport()69 virtual bool getOfflineProcessingSupport() const { 70 // As per Camera spec. shared streams currently do not support 71 // offline mode. 72 return false; 73 } 74 75 private: 76 77 static const size_t kMaxOutputs = 4; 78 79 // Whether HAL is in control for buffer management. Surface sharing behavior 80 // depends on this flag. 81 const bool mUseHalBufManager; 82 83 // Pair of an output Surface and its unique ID 84 typedef std::pair<sp<Surface>, size_t> SurfaceUniqueId; 85 86 // Map surfaceId -> (output surface, unique surface ID) 87 std::array<SurfaceUniqueId, kMaxOutputs> mSurfaceUniqueIds; 88 89 size_t mNextUniqueSurfaceId = 0; 90 91 ssize_t getNextSurfaceIdLocked(); 92 93 status_t revertPartialUpdateLocked(const KeyedVector<sp<Surface>, size_t> &removedSurfaces, 94 const KeyedVector<sp<Surface>, size_t> &attachedSurfaces); 95 96 /** 97 * The Camera3StreamSplitter object this stream uses for stream 98 * sharing. 99 */ 100 sp<Camera3StreamSplitter> mStreamSplitter; 101 102 /** 103 * Initialize stream splitter. 104 */ 105 status_t connectStreamSplitterLocked(); 106 107 /** 108 * Attach the output buffer to stream splitter. 109 * When camera service is doing buffer management, this method will be called 110 * before the buffer is handed out to HAL in request thread. 111 * When HAL is doing buffer management, this method will be called when 112 * the buffer is returned from HAL in hwbinder callback thread. 113 */ 114 status_t attachBufferToSplitterLocked(ANativeWindowBuffer* anb, 115 const std::vector<size_t>& surface_ids); 116 117 /** 118 * Internal Camera3Stream interface 119 */ 120 virtual status_t getBufferLocked(camera_stream_buffer *buffer, 121 const std::vector<size_t>& surface_ids); 122 123 virtual status_t queueBufferToConsumer(sp<ANativeWindow>& consumer, 124 ANativeWindowBuffer* buffer, int anwReleaseFence, 125 const std::vector<size_t>& uniqueSurfaceIds); 126 127 virtual status_t configureQueueLocked(); 128 129 virtual status_t disconnectLocked(); 130 131 virtual status_t getEndpointUsage(uint64_t *usage) const; 132 133 }; // class Camera3SharedOutputStream 134 135 } // namespace camera3 136 137 } // namespace android 138 139 #endif // ANDROID_SERVERS_CAMERA3_SHARED_OUTPUT_STREAM_H 140