blob: 818ce17193f0ad5a6df8d9d428b36563b5e20891 [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>
Shuzhen Wang0129d522016-10-30 22:43:41 -070021#include "Camera3StreamSplitter.h"
22#include "Camera3OutputStream.h"
23
24namespace android {
25
26namespace camera3 {
27
28class Camera3SharedOutputStream :
29 public Camera3OutputStream {
30public:
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 Wang758c2152017-01-10 18:26:18 -080037 uint32_t width, uint32_t height, int format,
Emilian Peev050f5dc2017-05-18 14:43:56 +010038 uint64_t consumerUsage, android_dataspace dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -070039 camera_stream_rotation_t rotation, nsecs_t timestampOffset,
Austin Borger1c1bee02023-06-01 16:51:35 -070040 const std::string& physicalCameraId,
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000041 const std::unordered_set<int32_t> &sensorPixelModesUsed, IPCTransport transport,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070042 int setId = CAMERA3_STREAM_SET_ID_INVALID,
Emilian Peev2295df72021-11-12 18:14:10 -080043 bool useHalBufManager = false,
Emilian Peevc81a7592022-02-14 17:38:18 -080044 int64_t dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -080045 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
Shuzhen Wange4208922022-02-01 16:52:48 -080046 bool deviceTimeBaseIsRealtime = false,
Shuzhen Wang610d7b82022-02-08 14:37:22 -080047 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT,
Austin Borger9e2b27c2022-07-15 11:27:24 -070048 int mirrorMode = OutputConfiguration::MIRROR_MODE_AUTO,
Shuzhen Wangbce53db2022-12-03 00:38:20 +000049 int32_t colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED,
50 bool useReadoutTimestamp = false);
Shuzhen Wang0129d522016-10-30 22:43:41 -070051
52 virtual ~Camera3SharedOutputStream();
53
Jayant Chowdhary9d3a6492023-11-22 07:23:59 +000054 void setHalBufferManager(bool enabled) override;
55
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -080056 virtual status_t notifyBufferReleased(ANativeWindowBuffer *buffer);
Shuzhen Wang0129d522016-10-30 22:43:41 -070057
58 virtual bool isConsumerConfigurationDeferred(size_t surface_id) const;
59
Shuzhen Wang758c2152017-01-10 18:26:18 -080060 virtual status_t setConsumers(const std::vector<sp<Surface>>& consumers);
Shuzhen Wang0129d522016-10-30 22:43:41 -070061
Emilian Peev40ead602017-09-26 15:46:36 +010062 virtual ssize_t getSurfaceId(const sp<Surface> &surface);
63
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070064 /**
65 * Query the unique surface IDs of current surfaceIds.
66 * When passing unique surface IDs in returnBuffer(), if the
67 * surfaceId has been removed from the stream, the output corresponding to
68 * the unique surface ID will be ignored and not delivered to client.
69 */
70 virtual status_t getUniqueSurfaceIds(const std::vector<size_t>& surfaceIds,
71 /*out*/std::vector<size_t>* outUniqueIds) override;
72
Emilian Peev40ead602017-09-26 15:46:36 +010073 virtual status_t updateStream(const std::vector<sp<Surface>> &outputSurfaces,
74 const std::vector<OutputStreamInfo> &outputInfo,
75 const std::vector<size_t> &removedSurfaceIds,
76 KeyedVector<sp<Surface>, size_t> *outputMap/*out*/);
77
Emilian Peevcc0b7952020-01-07 13:54:47 -080078 virtual bool getOfflineProcessingSupport() const {
79 // As per Camera spec. shared streams currently do not support
80 // offline mode.
81 return false;
82 }
83
Shuzhen Wang0129d522016-10-30 22:43:41 -070084private:
Emilian Peev40ead602017-09-26 15:46:36 +010085
86 static const size_t kMaxOutputs = 4;
87
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070088 // Whether HAL is in control for buffer management. Surface sharing behavior
89 // depends on this flag.
Jayant Chowdhary9d3a6492023-11-22 07:23:59 +000090 bool mUseHalBufManager;
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070091
92 // Pair of an output Surface and its unique ID
93 typedef std::pair<sp<Surface>, size_t> SurfaceUniqueId;
94
95 // Map surfaceId -> (output surface, unique surface ID)
96 std::array<SurfaceUniqueId, kMaxOutputs> mSurfaceUniqueIds;
97
98 size_t mNextUniqueSurfaceId = 0;
Emilian Peev40ead602017-09-26 15:46:36 +010099
100 ssize_t getNextSurfaceIdLocked();
101
102 status_t revertPartialUpdateLocked(const KeyedVector<sp<Surface>, size_t> &removedSurfaces,
103 const KeyedVector<sp<Surface>, size_t> &attachedSurfaces);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700104
105 /**
106 * The Camera3StreamSplitter object this stream uses for stream
107 * sharing.
108 */
109 sp<Camera3StreamSplitter> mStreamSplitter;
110
111 /**
112 * Initialize stream splitter.
113 */
114 status_t connectStreamSplitterLocked();
115
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800116 /**
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700117 * Attach the output buffer to stream splitter.
118 * When camera service is doing buffer management, this method will be called
119 * before the buffer is handed out to HAL in request thread.
120 * When HAL is doing buffer management, this method will be called when
121 * the buffer is returned from HAL in hwbinder callback thread.
122 */
123 status_t attachBufferToSplitterLocked(ANativeWindowBuffer* anb,
124 const std::vector<size_t>& surface_ids);
125
126 /**
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800127 * Internal Camera3Stream interface
128 */
Emilian Peevf4816702020-04-03 15:44:51 -0700129 virtual status_t getBufferLocked(camera_stream_buffer *buffer,
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800130 const std::vector<size_t>& surface_ids);
131
132 virtual status_t queueBufferToConsumer(sp<ANativeWindow>& consumer,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700133 ANativeWindowBuffer* buffer, int anwReleaseFence,
134 const std::vector<size_t>& uniqueSurfaceIds);
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800135
Shuzhen Wang0129d522016-10-30 22:43:41 -0700136 virtual status_t configureQueueLocked();
137
138 virtual status_t disconnectLocked();
139
Emilian Peev3b93acb2024-03-11 21:09:48 +0000140 virtual status_t getEndpointUsage(uint64_t *usage);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700141
Shuzhen Wang0129d522016-10-30 22:43:41 -0700142}; // class Camera3SharedOutputStream
143
144} // namespace camera3
145
146} // namespace android
147
148#endif // ANDROID_SERVERS_CAMERA3_SHARED_OUTPUT_STREAM_H