Add a simple ring buffer and use it for holding TFLite model inputs.
Bug: 167946763
Test: atest libinput_tests
Change-Id: I7e50d38ed0c593aebc5fdc6af4b25868505d48bc
diff --git a/libs/input/TfLiteMotionPredictor.cpp b/libs/input/TfLiteMotionPredictor.cpp
index 1a337ad..40653d3 100644
--- a/libs/input/TfLiteMotionPredictor.cpp
+++ b/libs/input/TfLiteMotionPredictor.cpp
@@ -104,13 +104,13 @@
} // namespace
-TfLiteMotionPredictorBuffers::TfLiteMotionPredictorBuffers(size_t inputLength) {
+TfLiteMotionPredictorBuffers::TfLiteMotionPredictorBuffers(size_t inputLength)
+ : mInputR(inputLength, 0),
+ mInputPhi(inputLength, 0),
+ mInputPressure(inputLength, 0),
+ mInputTilt(inputLength, 0),
+ mInputOrientation(inputLength, 0) {
LOG_ALWAYS_FATAL_IF(inputLength == 0, "Buffer input size must be greater than 0");
- mInputR.resize(inputLength);
- mInputPhi.resize(inputLength);
- mInputPressure.resize(inputLength);
- mInputTilt.resize(inputLength);
- mInputOrientation.resize(inputLength);
}
void TfLiteMotionPredictorBuffers::reset() {
@@ -186,17 +186,11 @@
mAxisTo = sample;
// Push the current sample onto the end of the input buffers.
- mInputR.erase(mInputR.begin());
- mInputPhi.erase(mInputPhi.begin());
- mInputPressure.erase(mInputPressure.begin());
- mInputTilt.erase(mInputTilt.begin());
- mInputOrientation.erase(mInputOrientation.begin());
-
- mInputR.push_back(r);
- mInputPhi.push_back(phi);
- mInputPressure.push_back(sample.pressure);
- mInputTilt.push_back(sample.tilt);
- mInputOrientation.push_back(orientation);
+ mInputR.pushBack(r);
+ mInputPhi.pushBack(phi);
+ mInputPressure.pushBack(sample.pressure);
+ mInputTilt.pushBack(sample.tilt);
+ mInputOrientation.pushBack(orientation);
}
std::unique_ptr<TfLiteMotionPredictorModel> TfLiteMotionPredictorModel::create(