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; // minimum fps (repeat frame to achieve this) 65 float mMaxFps; // max fps (via frame drop) 66 float mCaptureFps; // capture fps 67 float mCodedFps; // coded fps 68 bool mSuspended; // suspended 69 int64_t mTimeOffsetUs; // time offset (input => codec) 70 int64_t mSuspendAtUs; // suspend/resume time 71 int64_t mStartAtUs; // start time 72 bool mStopped; // stopped 73 int64_t mStopAtUs; // stop time 74 75 // OUT PARAMS (GBS) 76 int64_t mInputDelayUs; // delay between encoder input and surface input 77 78 // IN PARAMS (CODEC WRAPPER) 79 float mFixedAdjustedFps; // fixed fps via PTS manipulation 80 float mMinAdjustedFps; // minimum fps via PTS manipulation 81 }; 82 83 /** 84 * Configures input surface. 85 * 86 * \param config configuration. This can be updated during this call to provide output 87 * parameters, but not to provide configured parameters (to avoid continually 88 * reconfiguring) 89 */ 90 virtual status_t configure(Config &config) = 0; 91 92 /** 93 * Configures desired data space. 94 * 95 * \param dataSpace desired data space 96 */ setDataSpace(android_dataspace dataSpace)97 inline void setDataSpace(android_dataspace dataSpace) { 98 mDataSpace = dataSpace; 99 } 100 101 protected: 102 android_dataspace mDataSpace; 103 }; 104 105 } // namespace android 106 107 #endif // INPUT_SURFACE_WRAPPER_H_ 108