Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 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_OUTPUT_STREAM_INTERFACE_H |
| 18 | #define ANDROID_SERVERS_CAMERA3_OUTPUT_STREAM_INTERFACE_H |
| 19 | |
| 20 | #include "Camera3StreamInterface.h" |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 21 | #include <utils/KeyedVector.h> |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | namespace camera3 { |
| 26 | |
| 27 | /** |
| 28 | * An interface for managing a single stream of output data from the camera |
| 29 | * device. |
| 30 | */ |
| 31 | class Camera3OutputStreamInterface : public virtual Camera3StreamInterface { |
| 32 | public: |
| 33 | /** |
| 34 | * Set the transform on the output stream; one of the |
| 35 | * HAL_TRANSFORM_* / NATIVE_WINDOW_TRANSFORM_* constants. |
| 36 | */ |
| 37 | virtual status_t setTransform(int transform) = 0; |
Chien-Yu Chen | 85a6455 | 2015-08-28 15:46:12 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Return if this output stream is for video encoding. |
| 41 | */ |
| 42 | virtual bool isVideoStream() const = 0; |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Return if the consumer configuration of this stream is deferred. |
| 46 | */ |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 47 | virtual bool isConsumerConfigurationDeferred(size_t surface_id = 0) const = 0; |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 48 | |
| 49 | /** |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 50 | * Set the consumer surfaces to the output stream. |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 51 | */ |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 52 | virtual status_t setConsumers(const std::vector<sp<Surface>>& consumers) = 0; |
Eino-Ville Talvala | d58445d | 2016-06-17 22:58:43 -0700 | [diff] [blame] | 53 | |
| 54 | /** |
Eino-Ville Talvala | 77c1a35 | 2016-06-13 12:32:43 -0700 | [diff] [blame] | 55 | * Detach an unused buffer from the stream. |
| 56 | * |
| 57 | * buffer must be non-null; fenceFd may null, and if it is non-null, but |
| 58 | * there is no valid fence associated with the detached buffer, it will be |
| 59 | * set to -1. |
| 60 | * |
| 61 | */ |
| 62 | virtual status_t detachBuffer(sp<GraphicBuffer>* buffer, int* fenceFd) = 0; |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 63 | |
| 64 | /** |
| 65 | * Query the surface id. |
| 66 | */ |
| 67 | virtual ssize_t getSurfaceId(const sp<Surface> &surface) = 0; |
| 68 | |
| 69 | /** |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 70 | * Query the unique surface IDs of current surfaceIds. |
| 71 | * When passing unique surface IDs in returnBuffer(), if the |
| 72 | * surfaceId has been removed from the stream, the output corresponding to |
| 73 | * the unique surface ID will be ignored and not delivered to client. |
| 74 | * |
| 75 | * Return INVALID_OPERATION if and only if the stream does not support |
| 76 | * surface sharing. |
| 77 | */ |
| 78 | virtual status_t getUniqueSurfaceIds(const std::vector<size_t>& surfaceIds, |
| 79 | /*out*/std::vector<size_t>* outUniqueIds) = 0; |
| 80 | |
| 81 | /** |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 82 | * Update the stream output surfaces. |
| 83 | */ |
| 84 | virtual status_t updateStream(const std::vector<sp<Surface>> &outputSurfaces, |
| 85 | const std::vector<OutputStreamInfo> &outputInfo, |
| 86 | const std::vector<size_t> &removedSurfaceIds, |
| 87 | KeyedVector<sp<Surface>, size_t> *outputMap/*out*/) = 0; |
Chien-Yu Chen | a936ac2 | 2017-10-23 15:59:49 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * Drop buffers if dropping is true. If dropping is false, do not drop buffers. |
| 91 | */ |
| 92 | virtual status_t dropBuffers(bool /*dropping*/) = 0; |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * Query the physical camera id for the output stream. |
| 96 | */ |
| 97 | virtual const String8& getPhysicalCameraId() const = 0; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 100 | // Helper class to organize a synchronized mapping of stream IDs to stream instances |
| 101 | class StreamSet { |
| 102 | public: |
| 103 | status_t add(int streamId, sp<camera3::Camera3OutputStreamInterface>); |
| 104 | ssize_t remove(int streamId); |
| 105 | sp<camera3::Camera3OutputStreamInterface> get(int streamId); |
| 106 | // get by (underlying) vector index |
| 107 | sp<camera3::Camera3OutputStreamInterface> operator[] (size_t index); |
| 108 | size_t size() const; |
| 109 | std::vector<int> getStreamIds(); |
| 110 | void clear(); |
| 111 | |
| 112 | StreamSet() {}; |
| 113 | StreamSet(const StreamSet& other); |
| 114 | |
| 115 | private: |
| 116 | mutable std::mutex mLock; |
| 117 | KeyedVector<int, sp<camera3::Camera3OutputStreamInterface>> mData; |
| 118 | }; |
| 119 | |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 120 | } // namespace camera3 |
| 121 | |
| 122 | } // namespace android |
| 123 | |
| 124 | #endif |