| 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() | 
| Songyue Han | ad01f6a | 2023-08-17 05:45:35 +0000 | [diff] [blame] | 31 | : mDataSpace(HAL_DATASPACE_UNKNOWN), | 
|  | 32 | mPixelFormat(PIXEL_FORMAT_UNKNOWN) { | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 33 | } | 
|  | 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 B | 1a44b34 | 2020-10-13 20:36:31 +0530 | [diff] [blame] | 65 | 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 Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 75 |  | 
|  | 76 | // OUT PARAMS (GBS) | 
| Shrikara B | 1a44b34 | 2020-10-13 20:36:31 +0530 | [diff] [blame] | 77 | int64_t mInputDelayUs = 0; // delay between encoder input and surface input | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 78 |  | 
|  | 79 | // IN PARAMS (CODEC WRAPPER) | 
| Shrikara B | 1a44b34 | 2020-10-13 20:36:31 +0530 | [diff] [blame] | 80 | 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 Kim | a1335e1 | 2021-04-22 16:28:29 -0700 | [diff] [blame] | 83 | int mPriority = INT_MAX; // priority of queue thread (if any); INT_MAX for no-op | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 84 | }; | 
|  | 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 Kim | 4f3314d | 2019-03-26 17:00:34 -0700 | [diff] [blame] | 104 | /** | 
|  | 105 | * Clean up C2Work related references if necessary. No-op by default. | 
|  | 106 | * | 
|  | 107 | * \param index index of input work. | 
|  | 108 | */ | 
|  | 109 | virtual void onInputBufferDone(c2_cntr64_t /* index */) {} | 
|  | 110 |  | 
| Wonsik Kim | 673dd19 | 2021-01-29 14:58:12 -0800 | [diff] [blame] | 111 | /** | 
|  | 112 | * Returns dataspace information from GraphicBufferSource. | 
|  | 113 | */ | 
|  | 114 | virtual android_dataspace getDataspace() { return mDataSpace; } | 
|  | 115 |  | 
| Songyue Han | ad01f6a | 2023-08-17 05:45:35 +0000 | [diff] [blame] | 116 | /** | 
|  | 117 | * Returns pixel format information from GraphicBufferSource. | 
|  | 118 | */ | 
|  | 119 | virtual uint32_t getPixelFormat() { return mPixelFormat; } | 
|  | 120 |  | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 121 | protected: | 
|  | 122 | android_dataspace mDataSpace; | 
| Songyue Han | ad01f6a | 2023-08-17 05:45:35 +0000 | [diff] [blame] | 123 | uint32_t mPixelFormat; | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 124 | }; | 
|  | 125 |  | 
|  | 126 | }  // namespace android | 
|  | 127 |  | 
|  | 128 | #endif  // INPUT_SURFACE_WRAPPER_H_ |