diff options
author | Shao-Chuan Lee <shaochuan@google.com> | 2022-06-02 14:58:56 +0900 |
---|---|---|
committer | Shao-Chuan Lee <shaochuan@google.com> | 2022-06-02 06:21:44 +0000 |
commit | 39f241ae60695c912854445caca3299f91fb590e (patch) | |
tree | dd2e1ded5775bf3df9c115c73f0c7741870e9654 | |
parent | 42116ed33f49bc473512bef2e81f2d135951783b (diff) | |
download | v4l2_codec2-39f241ae60695c912854445caca3299f91fb590e.tar.gz |
V4L2EncodeComponent: clamp framerate to at least 1 on dynamic framerate changeandroid13-dev
Dynamic framerate based on timestamps can become zero when input frames
are supplied at >1 sec intervals.
Bug: 228828942
Test: android.media.cts.EncodeVirtualDisplayWithCompositionTest#testVirtualDisplayRecycles
Test: com.google.android.media.gts.RtcVideoCodecTest#testDynamicFramerateChangeVp8
Change-Id: I3ceefaad9b420f86e4f0b524e6f0b5649af9997b
-rw-r--r-- | components/V4L2EncodeComponent.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/components/V4L2EncodeComponent.cpp b/components/V4L2EncodeComponent.cpp index a1b46ab..4ce4404 100644 --- a/components/V4L2EncodeComponent.cpp +++ b/components/V4L2EncodeComponent.cpp @@ -756,8 +756,8 @@ bool V4L2EncodeComponent::encode(C2ConstGraphicBlock block, uint64_t index, int6 // Dynamically adjust framerate based on the frame's timestamp if required. constexpr int64_t kMaxFramerateDiff = 5; if (mLastFrameTime && (timestamp > *mLastFrameTime)) { - int64_t newFramerate = - static_cast<int64_t>(std::round(1000000.0 / (timestamp - *mLastFrameTime))); + int64_t newFramerate = std::max( + static_cast<int64_t>(std::round(1000000.0 / (timestamp - *mLastFrameTime))), 1LL); if (abs(mFramerate - newFramerate) > kMaxFramerateDiff) { ALOGV("Adjusting framerate to %" PRId64 " based on frame timestamps", newFramerate); mInterface->setFramerate(static_cast<uint32_t>(newFramerate)); |