Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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_SHARED_OUTPUT_STREAM_H |
| 18 | #define ANDROID_SERVERS_CAMERA3_SHARED_OUTPUT_STREAM_H |
| 19 | |
| 20 | #include "Camera3StreamSplitter.h" |
| 21 | #include "Camera3OutputStream.h" |
| 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | namespace camera3 { |
| 26 | |
| 27 | class Camera3SharedOutputStream : |
| 28 | public Camera3OutputStream { |
| 29 | public: |
| 30 | /** |
| 31 | * Set up a stream for formats that have 2 dimensions, with multiple |
| 32 | * surfaces. A valid stream set id needs to be set to support buffer |
| 33 | * sharing between multiple streams. |
| 34 | */ |
| 35 | Camera3SharedOutputStream(int id, const std::vector<sp<Surface>>& surfaces, |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 36 | uint32_t width, uint32_t height, int format, |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 37 | uint64_t consumerUsage, android_dataspace dataSpace, |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 38 | camera3_stream_rotation_t rotation, nsecs_t timestampOffset, |
| 39 | int setId = CAMERA3_STREAM_SET_ID_INVALID); |
| 40 | |
| 41 | virtual ~Camera3SharedOutputStream(); |
| 42 | |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 43 | virtual status_t notifyBufferReleased(ANativeWindowBuffer *buffer); |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 44 | |
| 45 | virtual bool isConsumerConfigurationDeferred(size_t surface_id) const; |
| 46 | |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 47 | virtual status_t setConsumers(const std::vector<sp<Surface>>& consumers); |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 48 | |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame^] | 49 | virtual ssize_t getSurfaceId(const sp<Surface> &surface); |
| 50 | |
| 51 | virtual status_t updateStream(const std::vector<sp<Surface>> &outputSurfaces, |
| 52 | const std::vector<OutputStreamInfo> &outputInfo, |
| 53 | const std::vector<size_t> &removedSurfaceIds, |
| 54 | KeyedVector<sp<Surface>, size_t> *outputMap/*out*/); |
| 55 | |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 56 | private: |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame^] | 57 | |
| 58 | static const size_t kMaxOutputs = 4; |
| 59 | |
| 60 | // Map surfaceId -> output surfaces |
| 61 | sp<Surface> mSurfaces[kMaxOutputs]; |
| 62 | |
| 63 | ssize_t getNextSurfaceIdLocked(); |
| 64 | |
| 65 | status_t revertPartialUpdateLocked(const KeyedVector<sp<Surface>, size_t> &removedSurfaces, |
| 66 | const KeyedVector<sp<Surface>, size_t> &attachedSurfaces); |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * The Camera3StreamSplitter object this stream uses for stream |
| 70 | * sharing. |
| 71 | */ |
| 72 | sp<Camera3StreamSplitter> mStreamSplitter; |
| 73 | |
| 74 | /** |
| 75 | * Initialize stream splitter. |
| 76 | */ |
| 77 | status_t connectStreamSplitterLocked(); |
| 78 | |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 79 | /** |
| 80 | * Internal Camera3Stream interface |
| 81 | */ |
| 82 | virtual status_t getBufferLocked(camera3_stream_buffer *buffer, |
| 83 | const std::vector<size_t>& surface_ids); |
| 84 | |
| 85 | virtual status_t queueBufferToConsumer(sp<ANativeWindow>& consumer, |
| 86 | ANativeWindowBuffer* buffer, int anwReleaseFence); |
| 87 | |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 88 | virtual status_t configureQueueLocked(); |
| 89 | |
| 90 | virtual status_t disconnectLocked(); |
| 91 | |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 92 | virtual status_t getEndpointUsage(uint64_t *usage) const; |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 93 | |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 94 | }; // class Camera3SharedOutputStream |
| 95 | |
| 96 | } // namespace camera3 |
| 97 | |
| 98 | } // namespace android |
| 99 | |
| 100 | #endif // ANDROID_SERVERS_CAMERA3_SHARED_OUTPUT_STREAM_H |