Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 23 | namespace android { |
| 24 | |
| 25 | /** |
| 26 | * Wrapper interface around InputSurface. |
| 27 | */ |
| 28 | class InputSurfaceWrapper { |
| 29 | public: |
| 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 B | a1ab7eb | 2020-10-13 20:36:31 +0530 | [diff] [blame] | 64 | 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 Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 74 | |
| 75 | // OUT PARAMS (GBS) |
Shrikara B | a1ab7eb | 2020-10-13 20:36:31 +0530 | [diff] [blame] | 76 | int64_t mInputDelayUs = 0; // delay between encoder input and surface input |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 77 | |
| 78 | // IN PARAMS (CODEC WRAPPER) |
Shrikara B | a1ab7eb | 2020-10-13 20:36:31 +0530 | [diff] [blame] | 79 | 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 |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | /** |
| 85 | * Configures input surface. |
| 86 | * |
| 87 | * \param config configuration. This can be updated during this call to provide output |
| 88 | * parameters, but not to provide configured parameters (to avoid continually |
| 89 | * reconfiguring) |
| 90 | */ |
| 91 | virtual status_t configure(Config &config) = 0; |
| 92 | |
| 93 | /** |
| 94 | * Configures desired data space. |
| 95 | * |
| 96 | * \param dataSpace desired data space |
| 97 | */ |
| 98 | inline void setDataSpace(android_dataspace dataSpace) { |
| 99 | mDataSpace = dataSpace; |
| 100 | } |
| 101 | |
Wonsik Kim | 4f3314d | 2019-03-26 17:00:34 -0700 | [diff] [blame] | 102 | /** |
| 103 | * Clean up C2Work related references if necessary. No-op by default. |
| 104 | * |
| 105 | * \param index index of input work. |
| 106 | */ |
| 107 | virtual void onInputBufferDone(c2_cntr64_t /* index */) {} |
| 108 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 109 | protected: |
| 110 | android_dataspace mDataSpace; |
| 111 | }; |
| 112 | |
| 113 | } // namespace android |
| 114 | |
| 115 | #endif // INPUT_SURFACE_WRAPPER_H_ |