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: InputSurfaceWrapper()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) 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 74 75 // OUT PARAMS (GBS) 76 int64_t mInputDelayUs = 0; // delay between encoder input and surface input 77 78 // IN PARAMS (CODEC WRAPPER) 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 82 int mPriority = INT_MAX; // priority of queue thread (if any); INT_MAX for no-op 83 }; 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 */ setDataSpace(android_dataspace dataSpace)99 inline void setDataSpace(android_dataspace dataSpace) { 100 mDataSpace = dataSpace; 101 } 102 103 /** 104 * Clean up C2Work related references if necessary. No-op by default. 105 * 106 * \param index index of input work. 107 */ onInputBufferDone(c2_cntr64_t)108 virtual void onInputBufferDone(c2_cntr64_t /* index */) {} 109 110 /** 111 * Returns dataspace information from GraphicBufferSource. 112 */ getDataspace()113 virtual android_dataspace getDataspace() { return mDataSpace; } 114 115 protected: 116 android_dataspace mDataSpace; 117 }; 118 119 } // namespace android 120 121 #endif // INPUT_SURFACE_WRAPPER_H_ 122