Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 1 | /* |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 2 | * Copyright (C) 2016-2018 The Android Open Source Project |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 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 | |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 20 | #include <array> |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 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, |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 37 | uint32_t width, uint32_t height, int format, |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 38 | uint64_t consumerUsage, android_dataspace dataSpace, |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 39 | camera_stream_rotation_t rotation, nsecs_t timestampOffset, |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 40 | const String8& physicalCameraId, |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 41 | const std::unordered_set<int32_t> &sensorPixelModesUsed, |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 42 | int setId = CAMERA3_STREAM_SET_ID_INVALID, |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame] | 43 | bool useHalBufManager = false, |
Shuzhen Wang | c8ab452 | 2021-12-14 20:12:42 -0800 | [diff] [blame] | 44 | int dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD, |
Shuzhen Wang | e420892 | 2022-02-01 16:52:48 -0800 | [diff] [blame^] | 45 | int streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT, |
| 46 | bool deviceTimeBaseIsRealtime = false, |
| 47 | int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT); |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 48 | |
| 49 | virtual ~Camera3SharedOutputStream(); |
| 50 | |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 51 | virtual status_t notifyBufferReleased(ANativeWindowBuffer *buffer); |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 52 | |
| 53 | virtual bool isConsumerConfigurationDeferred(size_t surface_id) const; |
| 54 | |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 55 | virtual status_t setConsumers(const std::vector<sp<Surface>>& consumers); |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 56 | |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 57 | virtual ssize_t getSurfaceId(const sp<Surface> &surface); |
| 58 | |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 59 | /** |
| 60 | * Query the unique surface IDs of current surfaceIds. |
| 61 | * When passing unique surface IDs in returnBuffer(), if the |
| 62 | * surfaceId has been removed from the stream, the output corresponding to |
| 63 | * the unique surface ID will be ignored and not delivered to client. |
| 64 | */ |
| 65 | virtual status_t getUniqueSurfaceIds(const std::vector<size_t>& surfaceIds, |
| 66 | /*out*/std::vector<size_t>* outUniqueIds) override; |
| 67 | |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 68 | virtual status_t updateStream(const std::vector<sp<Surface>> &outputSurfaces, |
| 69 | const std::vector<OutputStreamInfo> &outputInfo, |
| 70 | const std::vector<size_t> &removedSurfaceIds, |
| 71 | KeyedVector<sp<Surface>, size_t> *outputMap/*out*/); |
| 72 | |
Emilian Peev | cc0b795 | 2020-01-07 13:54:47 -0800 | [diff] [blame] | 73 | virtual bool getOfflineProcessingSupport() const { |
| 74 | // As per Camera spec. shared streams currently do not support |
| 75 | // offline mode. |
| 76 | return false; |
| 77 | } |
| 78 | |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 79 | private: |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 80 | |
| 81 | static const size_t kMaxOutputs = 4; |
| 82 | |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 83 | // Whether HAL is in control for buffer management. Surface sharing behavior |
| 84 | // depends on this flag. |
| 85 | const bool mUseHalBufManager; |
| 86 | |
| 87 | // Pair of an output Surface and its unique ID |
| 88 | typedef std::pair<sp<Surface>, size_t> SurfaceUniqueId; |
| 89 | |
| 90 | // Map surfaceId -> (output surface, unique surface ID) |
| 91 | std::array<SurfaceUniqueId, kMaxOutputs> mSurfaceUniqueIds; |
| 92 | |
| 93 | size_t mNextUniqueSurfaceId = 0; |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 94 | |
| 95 | ssize_t getNextSurfaceIdLocked(); |
| 96 | |
| 97 | status_t revertPartialUpdateLocked(const KeyedVector<sp<Surface>, size_t> &removedSurfaces, |
| 98 | const KeyedVector<sp<Surface>, size_t> &attachedSurfaces); |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 99 | |
| 100 | /** |
| 101 | * The Camera3StreamSplitter object this stream uses for stream |
| 102 | * sharing. |
| 103 | */ |
| 104 | sp<Camera3StreamSplitter> mStreamSplitter; |
| 105 | |
| 106 | /** |
| 107 | * Initialize stream splitter. |
| 108 | */ |
| 109 | status_t connectStreamSplitterLocked(); |
| 110 | |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 111 | /** |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 112 | * Attach the output buffer to stream splitter. |
| 113 | * When camera service is doing buffer management, this method will be called |
| 114 | * before the buffer is handed out to HAL in request thread. |
| 115 | * When HAL is doing buffer management, this method will be called when |
| 116 | * the buffer is returned from HAL in hwbinder callback thread. |
| 117 | */ |
| 118 | status_t attachBufferToSplitterLocked(ANativeWindowBuffer* anb, |
| 119 | const std::vector<size_t>& surface_ids); |
| 120 | |
| 121 | /** |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 122 | * Internal Camera3Stream interface |
| 123 | */ |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 124 | virtual status_t getBufferLocked(camera_stream_buffer *buffer, |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 125 | const std::vector<size_t>& surface_ids); |
| 126 | |
| 127 | virtual status_t queueBufferToConsumer(sp<ANativeWindow>& consumer, |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 128 | ANativeWindowBuffer* buffer, int anwReleaseFence, |
| 129 | const std::vector<size_t>& uniqueSurfaceIds); |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 130 | |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 131 | virtual status_t configureQueueLocked(); |
| 132 | |
| 133 | virtual status_t disconnectLocked(); |
| 134 | |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 135 | virtual status_t getEndpointUsage(uint64_t *usage) const; |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 136 | |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 137 | }; // class Camera3SharedOutputStream |
| 138 | |
| 139 | } // namespace camera3 |
| 140 | |
| 141 | } // namespace android |
| 142 | |
| 143 | #endif // ANDROID_SERVERS_CAMERA3_SHARED_OUTPUT_STREAM_H |