blob: fbf37e6e7efc39ada755be77ea2c27ebfd2c441d [file] [log] [blame]
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -07001/*
Shuzhen Wangc28189a2017-11-27 23:05:10 -08002 * Copyright (C) 2014-2018 The Android Open Source Project
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -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
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -040017#ifndef ANDROID_SERVERS_CAMERA3_FAKE_STREAM_H
18#define ANDROID_SERVERS_CAMERA3_FAKE_STREAM_H
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -070019
20#include <utils/RefBase.h>
21#include <gui/Surface.h>
22
23#include "Camera3Stream.h"
24#include "Camera3IOStreamBase.h"
25#include "Camera3OutputStreamInterface.h"
26
27namespace android {
28namespace camera3 {
29
30/**
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -040031 * A fake output stream class, to be used as a placeholder when no valid
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -070032 * streams are configured by the client.
33 * This is necessary because camera HAL v3.2 or older disallow configuring
34 * 0 output streams, while the public camera2 API allows for it.
35 */
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -040036class Camera3FakeStream :
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -070037 public Camera3IOStreamBase,
38 public Camera3OutputStreamInterface {
39
40 public:
41 /**
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -040042 * Set up a fake stream; doesn't actually connect to anything, and uses
43 * a default fake format and size.
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -070044 */
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -040045 explicit Camera3FakeStream(int id);
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -070046
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -040047 virtual ~Camera3FakeStream();
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -070048
49 /**
50 * Camera3Stream interface
51 */
52
53 virtual void dump(int fd, const Vector<String16> &args) const;
54
55 status_t setTransform(int transform);
56
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -070057 virtual status_t detachBuffer(sp<GraphicBuffer>* buffer, int* fenceFd);
58
Chien-Yu Chen85a64552015-08-28 15:46:12 -070059 /**
Chien-Yu Chena936ac22017-10-23 15:59:49 -070060 * Drop buffers for stream of streamId if dropping is true. If dropping is false, do not
61 * drop buffers for stream of streamId.
62 */
63 virtual status_t dropBuffers(bool /*dropping*/) override;
64
65 /**
Shuzhen Wang5c22c152017-12-31 17:12:25 -080066 * Query the physical camera id for the output stream.
67 */
68 virtual const String8& getPhysicalCameraId() const override;
69
70 /**
Chien-Yu Chen85a64552015-08-28 15:46:12 -070071 * Return if this output stream is for video encoding.
72 */
73 bool isVideoStream() const;
74
Zhijun He5d677d12016-05-29 16:52:39 -070075 /**
76 * Return if the consumer configuration of this stream is deferred.
77 */
Shuzhen Wang0129d522016-10-30 22:43:41 -070078 virtual bool isConsumerConfigurationDeferred(size_t surface_id) const;
Zhijun He5d677d12016-05-29 16:52:39 -070079
80 /**
Shuzhen Wang758c2152017-01-10 18:26:18 -080081 * Set the consumer surfaces to the output stream.
Zhijun He5d677d12016-05-29 16:52:39 -070082 */
Shuzhen Wang758c2152017-01-10 18:26:18 -080083 virtual status_t setConsumers(const std::vector<sp<Surface>>& consumers);
Zhijun He5d677d12016-05-29 16:52:39 -070084
Emilian Peev40ead602017-09-26 15:46:36 +010085 /**
86 * Query the output surface id.
87 */
88 virtual ssize_t getSurfaceId(const sp<Surface> &/*surface*/) { return 0; }
89
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -070090 virtual status_t getUniqueSurfaceIds(const std::vector<size_t>&,
91 /*out*/std::vector<size_t>*) { return INVALID_OPERATION; };
92
Emilian Peev40ead602017-09-26 15:46:36 +010093 /**
94 * Update the stream output surfaces.
95 */
96 virtual status_t updateStream(const std::vector<sp<Surface>> &outputSurfaces,
97 const std::vector<OutputStreamInfo> &outputInfo,
98 const std::vector<size_t> &removedSurfaceIds,
99 KeyedVector<sp<Surface>, size_t> *outputMap/*out*/);
100
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700101 protected:
102
103 /**
104 * Note that we release the lock briefly in this function
105 */
106 virtual status_t returnBufferCheckedLocked(
107 const camera3_stream_buffer &buffer,
108 nsecs_t timestamp,
109 bool output,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700110 const std::vector<size_t>& surface_ids,
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700111 /*out*/
112 sp<Fence> *releaseFenceOut);
113
114 virtual status_t disconnectLocked();
115
116 private:
117
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -0400118 // Default fake parameters; 320x240 is a required size for all devices,
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700119 // otherwise act like a SurfaceView would.
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -0400120 static const int FAKE_WIDTH = 320;
121 static const int FAKE_HEIGHT = 240;
122 static const int FAKE_FORMAT = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
123 static const android_dataspace FAKE_DATASPACE = HAL_DATASPACE_UNKNOWN;
124 static const camera3_stream_rotation_t FAKE_ROTATION = CAMERA3_STREAM_ROTATION_0;
125 static const uint64_t FAKE_USAGE = GRALLOC_USAGE_HW_COMPOSER;
126 static const String8 FAKE_ID;
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700127
128 /**
129 * Internal Camera3Stream interface
130 */
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800131 virtual status_t getBufferLocked(camera3_stream_buffer *buffer,
132 const std::vector<size_t>& surface_ids = std::vector<size_t>());
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700133 virtual status_t returnBufferLocked(
134 const camera3_stream_buffer &buffer,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700135 nsecs_t timestamp, const std::vector<size_t>& surface_ids);
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700136
137 virtual status_t configureQueueLocked();
138
Emilian Peev050f5dc2017-05-18 14:43:56 +0100139 virtual status_t getEndpointUsage(uint64_t *usage) const;
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700140
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -0400141}; // class Camera3FakeStream
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700142
143} // namespace camera3
144
145} // namespace android
146
147#endif