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