blob: ae1150792c6e10de2fa4d7a03420da4152647f76 [file] [log] [blame]
Shuzhen Wang0129d522016-10-30 22:43:41 -07001/*
Shuzhen Wangc28189a2017-11-27 23:05:10 -08002 * Copyright (C) 2016-2018 The Android Open Source Project
Shuzhen Wang0129d522016-10-30 22:43:41 -07003 *
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 Yeh58b1b4e2018-10-15 12:18:36 -070020#include <array>
Jim Shargoc50928e2024-07-03 05:00:43 +000021
22#include "Flags.h"
23
Shuzhen Wang0129d522016-10-30 22:43:41 -070024#include "Camera3OutputStream.h"
25
Jim Shargoc50928e2024-07-03 05:00:43 +000026#if USE_NEW_STREAM_SPLITTER
27#include "Camera3StreamSplitter.h"
28#else
29#include "deprecated/DeprecatedCamera3StreamSplitter.h"
30#endif // USE_NEW_STREAM_SPLITTER
31
Shuzhen Wang0129d522016-10-30 22:43:41 -070032namespace android {
33
34namespace camera3 {
35
36class Camera3SharedOutputStream :
37 public Camera3OutputStream {
38public:
39 /**
40 * Set up a stream for formats that have 2 dimensions, with multiple
41 * surfaces. A valid stream set id needs to be set to support buffer
42 * sharing between multiple streams.
43 */
44 Camera3SharedOutputStream(int id, const std::vector<sp<Surface>>& surfaces,
Shuzhen Wang758c2152017-01-10 18:26:18 -080045 uint32_t width, uint32_t height, int format,
Emilian Peev050f5dc2017-05-18 14:43:56 +010046 uint64_t consumerUsage, android_dataspace dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -070047 camera_stream_rotation_t rotation, nsecs_t timestampOffset,
Austin Borger1c1bee02023-06-01 16:51:35 -070048 const std::string& physicalCameraId,
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000049 const std::unordered_set<int32_t> &sensorPixelModesUsed, IPCTransport transport,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070050 int setId = CAMERA3_STREAM_SET_ID_INVALID,
Emilian Peev2295df72021-11-12 18:14:10 -080051 bool useHalBufManager = false,
Emilian Peevc81a7592022-02-14 17:38:18 -080052 int64_t dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -080053 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
Shuzhen Wange4208922022-02-01 16:52:48 -080054 bool deviceTimeBaseIsRealtime = false,
Shuzhen Wang610d7b82022-02-08 14:37:22 -080055 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT,
Austin Borger9e2b27c2022-07-15 11:27:24 -070056 int mirrorMode = OutputConfiguration::MIRROR_MODE_AUTO,
Shuzhen Wangbce53db2022-12-03 00:38:20 +000057 int32_t colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED,
58 bool useReadoutTimestamp = false);
Shuzhen Wang0129d522016-10-30 22:43:41 -070059
60 virtual ~Camera3SharedOutputStream();
61
Jayant Chowdhary9d3a6492023-11-22 07:23:59 +000062 void setHalBufferManager(bool enabled) override;
63
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -080064 virtual status_t notifyBufferReleased(ANativeWindowBuffer *buffer);
Shuzhen Wang0129d522016-10-30 22:43:41 -070065
66 virtual bool isConsumerConfigurationDeferred(size_t surface_id) const;
67
Shuzhen Wang758c2152017-01-10 18:26:18 -080068 virtual status_t setConsumers(const std::vector<sp<Surface>>& consumers);
Shuzhen Wang0129d522016-10-30 22:43:41 -070069
Emilian Peev40ead602017-09-26 15:46:36 +010070 virtual ssize_t getSurfaceId(const sp<Surface> &surface);
71
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070072 /**
73 * Query the unique surface IDs of current surfaceIds.
74 * When passing unique surface IDs in returnBuffer(), if the
75 * surfaceId has been removed from the stream, the output corresponding to
76 * the unique surface ID will be ignored and not delivered to client.
77 */
78 virtual status_t getUniqueSurfaceIds(const std::vector<size_t>& surfaceIds,
79 /*out*/std::vector<size_t>* outUniqueIds) override;
80
Emilian Peev40ead602017-09-26 15:46:36 +010081 virtual status_t updateStream(const std::vector<sp<Surface>> &outputSurfaces,
82 const std::vector<OutputStreamInfo> &outputInfo,
83 const std::vector<size_t> &removedSurfaceIds,
84 KeyedVector<sp<Surface>, size_t> *outputMap/*out*/);
85
Emilian Peevcc0b7952020-01-07 13:54:47 -080086 virtual bool getOfflineProcessingSupport() const {
87 // As per Camera spec. shared streams currently do not support
88 // offline mode.
89 return false;
90 }
91
Shuzhen Wang0129d522016-10-30 22:43:41 -070092private:
Emilian Peev40ead602017-09-26 15:46:36 +010093
94 static const size_t kMaxOutputs = 4;
95
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070096 // Whether HAL is in control for buffer management. Surface sharing behavior
97 // depends on this flag.
Jayant Chowdhary9d3a6492023-11-22 07:23:59 +000098 bool mUseHalBufManager;
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070099
100 // Pair of an output Surface and its unique ID
101 typedef std::pair<sp<Surface>, size_t> SurfaceUniqueId;
102
103 // Map surfaceId -> (output surface, unique surface ID)
104 std::array<SurfaceUniqueId, kMaxOutputs> mSurfaceUniqueIds;
105
106 size_t mNextUniqueSurfaceId = 0;
Emilian Peev40ead602017-09-26 15:46:36 +0100107
108 ssize_t getNextSurfaceIdLocked();
109
110 status_t revertPartialUpdateLocked(const KeyedVector<sp<Surface>, size_t> &removedSurfaces,
111 const KeyedVector<sp<Surface>, size_t> &attachedSurfaces);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700112
113 /**
114 * The Camera3StreamSplitter object this stream uses for stream
115 * sharing.
116 */
Jim Shargoc50928e2024-07-03 05:00:43 +0000117#if USE_NEW_STREAM_SPLITTER
Shuzhen Wang0129d522016-10-30 22:43:41 -0700118 sp<Camera3StreamSplitter> mStreamSplitter;
Jim Shargoc50928e2024-07-03 05:00:43 +0000119#else
120 sp<DeprecatedCamera3StreamSplitter> mStreamSplitter;
121#endif // USE_NEW_STREAM_SPLITTER
Shuzhen Wang0129d522016-10-30 22:43:41 -0700122 /**
123 * Initialize stream splitter.
124 */
125 status_t connectStreamSplitterLocked();
126
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800127 /**
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700128 * Attach the output buffer to stream splitter.
129 * When camera service is doing buffer management, this method will be called
130 * before the buffer is handed out to HAL in request thread.
131 * When HAL is doing buffer management, this method will be called when
132 * the buffer is returned from HAL in hwbinder callback thread.
133 */
134 status_t attachBufferToSplitterLocked(ANativeWindowBuffer* anb,
135 const std::vector<size_t>& surface_ids);
136
137 /**
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800138 * Internal Camera3Stream interface
139 */
Emilian Peevf4816702020-04-03 15:44:51 -0700140 virtual status_t getBufferLocked(camera_stream_buffer *buffer,
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800141 const std::vector<size_t>& surface_ids);
142
143 virtual status_t queueBufferToConsumer(sp<ANativeWindow>& consumer,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700144 ANativeWindowBuffer* buffer, int anwReleaseFence,
145 const std::vector<size_t>& uniqueSurfaceIds);
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800146
Shuzhen Wang0129d522016-10-30 22:43:41 -0700147 virtual status_t configureQueueLocked();
148
149 virtual status_t disconnectLocked();
150
Emilian Peev3b93acb2024-03-11 21:09:48 +0000151 virtual status_t getEndpointUsage(uint64_t *usage);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700152
Shuzhen Wang0129d522016-10-30 22:43:41 -0700153}; // class Camera3SharedOutputStream
154
155} // namespace camera3
156
157} // namespace android
158
159#endif // ANDROID_SERVERS_CAMERA3_SHARED_OUTPUT_STREAM_H