blob: 44ba78aef83c391d278a11460a67215d02b97ba1 [file] [log] [blame]
Pawin Vongmasa36653902018-11-15 00:10:25 -08001/*
2 * Copyright 2018, 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 INPUT_SURFACE_WRAPPER_H_
18#define INPUT_SURFACE_WRAPPER_H_
19
20#include <codec2/hidl/client.h>
21#include <system/graphics.h>
22
23namespace android {
24
25/**
26 * Wrapper interface around InputSurface.
27 */
28class InputSurfaceWrapper {
29public:
30 InputSurfaceWrapper()
31 : mDataSpace(HAL_DATASPACE_UNKNOWN) {
32 }
33
34 virtual ~InputSurfaceWrapper() = default;
35
36 /**
37 * Connect the surface with |comp|. A surface can
38 * connect to at most one component at a time.
39 *
40 * \return OK successfully connected to |comp|
41 * \return ALREADY_EXISTS already connected to another component.
42 */
43 virtual status_t connect(
44 const std::shared_ptr<Codec2Client::Component> &comp) = 0;
45
46 /**
47 * Disconnect the surface from the component if any.
48 */
49 virtual void disconnect() = 0;
50
51 /**
52 * Start pushing buffers to the surface.
53 */
54 virtual status_t start() = 0;
55
56 /**
57 * Ref: GraphicBufferSource::signalEndOfInputStream.
58 */
59 virtual status_t signalEndOfInputStream() = 0;
60
61 /// Input Surface configuration
62 struct Config {
63 // IN PARAMS (GBS)
Shrikara B1a44b342020-10-13 20:36:31 +053064 float mMinFps = 0.0; // minimum fps (repeat frame to achieve this)
65 float mMaxFps = 0.0; // max fps (via frame drop)
66 float mCaptureFps = 0.0; // capture fps
67 float mCodedFps = 0.0; // coded fps
68 bool mSuspended = false; // suspended
69 int64_t mTimeOffsetUs = 0; // time offset (input => codec)
70 int64_t mSuspendAtUs = 0; // suspend/resume time
71 int64_t mStartAtUs = 0; // start time
72 bool mStopped = false; // stopped
73 int64_t mStopAtUs = 0; // stop time
Pawin Vongmasa36653902018-11-15 00:10:25 -080074
75 // OUT PARAMS (GBS)
Shrikara B1a44b342020-10-13 20:36:31 +053076 int64_t mInputDelayUs = 0; // delay between encoder input and surface input
Pawin Vongmasa36653902018-11-15 00:10:25 -080077
78 // IN PARAMS (CODEC WRAPPER)
Shrikara B1a44b342020-10-13 20:36:31 +053079 float mFixedAdjustedFps = 0.0; // fixed fps via PTS manipulation
80 float mMinAdjustedFps = 0.0; // minimum fps via PTS manipulation
81 uint64_t mUsage = 0; // consumer usage
Wonsik Kima1335e12021-04-22 16:28:29 -070082 int mPriority = INT_MAX; // priority of queue thread (if any); INT_MAX for no-op
Pawin Vongmasa36653902018-11-15 00:10:25 -080083 };
84
85 /**
86 * Configures input surface.
87 *
88 * \param config configuration. This can be updated during this call to provide output
89 * parameters, but not to provide configured parameters (to avoid continually
90 * reconfiguring)
91 */
92 virtual status_t configure(Config &config) = 0;
93
94 /**
95 * Configures desired data space.
96 *
97 * \param dataSpace desired data space
98 */
99 inline void setDataSpace(android_dataspace dataSpace) {
100 mDataSpace = dataSpace;
101 }
102
Wonsik Kim4f3314d2019-03-26 17:00:34 -0700103 /**
104 * Clean up C2Work related references if necessary. No-op by default.
105 *
106 * \param index index of input work.
107 */
108 virtual void onInputBufferDone(c2_cntr64_t /* index */) {}
109
Wonsik Kim673dd192021-01-29 14:58:12 -0800110 /**
111 * Returns dataspace information from GraphicBufferSource.
112 */
113 virtual android_dataspace getDataspace() { return mDataSpace; }
114
Pawin Vongmasa36653902018-11-15 00:10:25 -0800115protected:
116 android_dataspace mDataSpace;
117};
118
119} // namespace android
120
121#endif // INPUT_SURFACE_WRAPPER_H_