blob: c158c5b3ac97912348460bb5aa1beb02bb97cc53 [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()
Songyue Hanad01f6a2023-08-17 05:45:35 +000031 : mDataSpace(HAL_DATASPACE_UNKNOWN),
32 mPixelFormat(PIXEL_FORMAT_UNKNOWN) {
Pawin Vongmasa36653902018-11-15 00:10:25 -080033 }
34
35 virtual ~InputSurfaceWrapper() = default;
36
37 /**
38 * Connect the surface with |comp|. A surface can
39 * connect to at most one component at a time.
40 *
41 * \return OK successfully connected to |comp|
42 * \return ALREADY_EXISTS already connected to another component.
43 */
44 virtual status_t connect(
45 const std::shared_ptr<Codec2Client::Component> &comp) = 0;
46
47 /**
48 * Disconnect the surface from the component if any.
49 */
50 virtual void disconnect() = 0;
51
52 /**
53 * Start pushing buffers to the surface.
54 */
55 virtual status_t start() = 0;
56
57 /**
58 * Ref: GraphicBufferSource::signalEndOfInputStream.
59 */
60 virtual status_t signalEndOfInputStream() = 0;
61
62 /// Input Surface configuration
63 struct Config {
64 // IN PARAMS (GBS)
Shrikara B1a44b342020-10-13 20:36:31 +053065 float mMinFps = 0.0; // minimum fps (repeat frame to achieve this)
66 float mMaxFps = 0.0; // max fps (via frame drop)
67 float mCaptureFps = 0.0; // capture fps
68 float mCodedFps = 0.0; // coded fps
69 bool mSuspended = false; // suspended
70 int64_t mTimeOffsetUs = 0; // time offset (input => codec)
71 int64_t mSuspendAtUs = 0; // suspend/resume time
72 int64_t mStartAtUs = 0; // start time
73 bool mStopped = false; // stopped
74 int64_t mStopAtUs = 0; // stop time
Pawin Vongmasa36653902018-11-15 00:10:25 -080075
76 // OUT PARAMS (GBS)
Shrikara B1a44b342020-10-13 20:36:31 +053077 int64_t mInputDelayUs = 0; // delay between encoder input and surface input
Pawin Vongmasa36653902018-11-15 00:10:25 -080078
79 // IN PARAMS (CODEC WRAPPER)
Shrikara B1a44b342020-10-13 20:36:31 +053080 float mFixedAdjustedFps = 0.0; // fixed fps via PTS manipulation
81 float mMinAdjustedFps = 0.0; // minimum fps via PTS manipulation
82 uint64_t mUsage = 0; // consumer usage
Wonsik Kima1335e12021-04-22 16:28:29 -070083 int mPriority = INT_MAX; // priority of queue thread (if any); INT_MAX for no-op
Pawin Vongmasa36653902018-11-15 00:10:25 -080084 };
85
86 /**
87 * Configures input surface.
88 *
89 * \param config configuration. This can be updated during this call to provide output
90 * parameters, but not to provide configured parameters (to avoid continually
91 * reconfiguring)
92 */
93 virtual status_t configure(Config &config) = 0;
94
95 /**
96 * Configures desired data space.
97 *
98 * \param dataSpace desired data space
99 */
100 inline void setDataSpace(android_dataspace dataSpace) {
101 mDataSpace = dataSpace;
102 }
103
Wonsik Kim4f3314d2019-03-26 17:00:34 -0700104 /**
Wonsik Kim1951d932024-05-23 22:59:00 +0000105 * Notify that the input buffer reference is no longer needed.
Wonsik Kim4f3314d2019-03-26 17:00:34 -0700106 * Clean up C2Work related references if necessary. No-op by default.
107 *
108 * \param index index of input work.
109 */
110 virtual void onInputBufferDone(c2_cntr64_t /* index */) {}
111
Wonsik Kim673dd192021-01-29 14:58:12 -0800112 /**
Wonsik Kim1951d932024-05-23 22:59:00 +0000113 * Signal one input buffer as emptied.
114 * No-op by default.
115 */
116 virtual void onInputBufferEmptied() {}
117
118 /**
Wonsik Kim673dd192021-01-29 14:58:12 -0800119 * Returns dataspace information from GraphicBufferSource.
120 */
121 virtual android_dataspace getDataspace() { return mDataSpace; }
122
Songyue Hanad01f6a2023-08-17 05:45:35 +0000123 /**
124 * Returns pixel format information from GraphicBufferSource.
125 */
126 virtual uint32_t getPixelFormat() { return mPixelFormat; }
127
Pawin Vongmasa36653902018-11-15 00:10:25 -0800128protected:
129 android_dataspace mDataSpace;
Songyue Hanad01f6a2023-08-17 05:45:35 +0000130 uint32_t mPixelFormat;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800131};
132
133} // namespace android
134
135#endif // INPUT_SURFACE_WRAPPER_H_