blob: fafa26f27ccdad72b4fe86f2edd39f729a680742 [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,
Shuzhen Wangc28189a2017-11-27 23:05:10 -080040 const String8& physicalCameraId,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080041 const std::unordered_set<int32_t> &sensorPixelModesUsed,
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,
44 int dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD);
Shuzhen Wang0129d522016-10-30 22:43:41 -070045
46 virtual ~Camera3SharedOutputStream();
47
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -080048 virtual status_t notifyBufferReleased(ANativeWindowBuffer *buffer);
Shuzhen Wang0129d522016-10-30 22:43:41 -070049
50 virtual bool isConsumerConfigurationDeferred(size_t surface_id) const;
51
Shuzhen Wang758c2152017-01-10 18:26:18 -080052 virtual status_t setConsumers(const std::vector<sp<Surface>>& consumers);
Shuzhen Wang0129d522016-10-30 22:43:41 -070053
Emilian Peev40ead602017-09-26 15:46:36 +010054 virtual ssize_t getSurfaceId(const sp<Surface> &surface);
55
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070056 /**
57 * Query the unique surface IDs of current surfaceIds.
58 * When passing unique surface IDs in returnBuffer(), if the
59 * surfaceId has been removed from the stream, the output corresponding to
60 * the unique surface ID will be ignored and not delivered to client.
61 */
62 virtual status_t getUniqueSurfaceIds(const std::vector<size_t>& surfaceIds,
63 /*out*/std::vector<size_t>* outUniqueIds) override;
64
Emilian Peev40ead602017-09-26 15:46:36 +010065 virtual status_t updateStream(const std::vector<sp<Surface>> &outputSurfaces,
66 const std::vector<OutputStreamInfo> &outputInfo,
67 const std::vector<size_t> &removedSurfaceIds,
68 KeyedVector<sp<Surface>, size_t> *outputMap/*out*/);
69
Emilian Peevcc0b7952020-01-07 13:54:47 -080070 virtual bool getOfflineProcessingSupport() const {
71 // As per Camera spec. shared streams currently do not support
72 // offline mode.
73 return false;
74 }
75
Shuzhen Wang0129d522016-10-30 22:43:41 -070076private:
Emilian Peev40ead602017-09-26 15:46:36 +010077
78 static const size_t kMaxOutputs = 4;
79
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070080 // Whether HAL is in control for buffer management. Surface sharing behavior
81 // depends on this flag.
82 const bool mUseHalBufManager;
83
84 // Pair of an output Surface and its unique ID
85 typedef std::pair<sp<Surface>, size_t> SurfaceUniqueId;
86
87 // Map surfaceId -> (output surface, unique surface ID)
88 std::array<SurfaceUniqueId, kMaxOutputs> mSurfaceUniqueIds;
89
90 size_t mNextUniqueSurfaceId = 0;
Emilian Peev40ead602017-09-26 15:46:36 +010091
92 ssize_t getNextSurfaceIdLocked();
93
94 status_t revertPartialUpdateLocked(const KeyedVector<sp<Surface>, size_t> &removedSurfaces,
95 const KeyedVector<sp<Surface>, size_t> &attachedSurfaces);
Shuzhen Wang0129d522016-10-30 22:43:41 -070096
97 /**
98 * The Camera3StreamSplitter object this stream uses for stream
99 * sharing.
100 */
101 sp<Camera3StreamSplitter> mStreamSplitter;
102
103 /**
104 * Initialize stream splitter.
105 */
106 status_t connectStreamSplitterLocked();
107
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800108 /**
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700109 * Attach the output buffer to stream splitter.
110 * When camera service is doing buffer management, this method will be called
111 * before the buffer is handed out to HAL in request thread.
112 * When HAL is doing buffer management, this method will be called when
113 * the buffer is returned from HAL in hwbinder callback thread.
114 */
115 status_t attachBufferToSplitterLocked(ANativeWindowBuffer* anb,
116 const std::vector<size_t>& surface_ids);
117
118 /**
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800119 * Internal Camera3Stream interface
120 */
Emilian Peevf4816702020-04-03 15:44:51 -0700121 virtual status_t getBufferLocked(camera_stream_buffer *buffer,
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800122 const std::vector<size_t>& surface_ids);
123
124 virtual status_t queueBufferToConsumer(sp<ANativeWindow>& consumer,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700125 ANativeWindowBuffer* buffer, int anwReleaseFence,
126 const std::vector<size_t>& uniqueSurfaceIds);
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800127
Shuzhen Wang0129d522016-10-30 22:43:41 -0700128 virtual status_t configureQueueLocked();
129
130 virtual status_t disconnectLocked();
131
Emilian Peev050f5dc2017-05-18 14:43:56 +0100132 virtual status_t getEndpointUsage(uint64_t *usage) const;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700133
Shuzhen Wang0129d522016-10-30 22:43:41 -0700134}; // class Camera3SharedOutputStream
135
136} // namespace camera3
137
138} // namespace android
139
140#endif // ANDROID_SERVERS_CAMERA3_SHARED_OUTPUT_STREAM_H