From 4c3eee45a4d4885432b076d45b420b2d841bd4e5 Mon Sep 17 00:00:00 2001 From: kevingpqi Date: Wed, 26 Mar 2025 19:46:39 +0800 Subject: [PATCH] Modify the maximum number of software decoding sending frames to maxReorderSize + 1 for HarmonyOS. --- src/platform/ohos/OHOSVideoDecoder.cpp | 17 +++++++++++------ src/platform/ohos/OHOSVideoDecoder.h | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/platform/ohos/OHOSVideoDecoder.cpp b/src/platform/ohos/OHOSVideoDecoder.cpp index 7975eda771..8461a41a0c 100644 --- a/src/platform/ohos/OHOSVideoDecoder.cpp +++ b/src/platform/ohos/OHOSVideoDecoder.cpp @@ -146,6 +146,15 @@ bool OHOSVideoDecoder::initDecoder(const OH_AVCodecCategory avCodecCategory) { LOGE("video decoder prepare failed!, ret:%d", ret); return false; } + /** + * According to HarmonyOS recommendations, temporarily modify the maximum number of hardware + * decoding frames to 16 and the maximum number of software decoding frames to maxReorderSize + 1 + * to avoid stuttering on some HarmonyOS devices due to insufficient decoding data. However, this + * modification will increase memory usage. Subsequent adjustments will be made once the + * HarmonyOS system is improved. + */ + maxPendingFramesCount = + (codecCategory == HARDWARE) ? 16 : static_cast(videoFormat.maxReorderSize) + 1; if (!start()) { LOGE("video decoder start failed!, ret:%d", ret); return false; @@ -197,12 +206,8 @@ DecodingResult OHOSVideoDecoder::onDecodeFrame() { releaseOutputBuffer(); std::unique_lock lock(codecUserData->outputMutex); codecUserData->outputCondition.wait(lock, [this]() { - /** - * According to HarmonyOS recommendations, temporarily modify the maximum frame delivery count to 16 to avoid - * freezing issues caused by the lack of decoded data on certain HarmonyOS devices. However, this change will - * result in increased memory usage. Once HarmonyOS are improved, appropriate adjustments will be made here. - */ - return codecUserData->outputBufferInfoQueue.size() > 0 || pendingFrames.size() <= 16; + return codecUserData->outputBufferInfoQueue.size() > 0 || + pendingFrames.size() <= maxPendingFramesCount; }); if (codecUserData->outputBufferInfoQueue.size() > 0) { codecBufferInfo = codecUserData->outputBufferInfoQueue.front(); diff --git a/src/platform/ohos/OHOSVideoDecoder.h b/src/platform/ohos/OHOSVideoDecoder.h index 1af8e6bc6d..e663608d56 100644 --- a/src/platform/ohos/OHOSVideoDecoder.h +++ b/src/platform/ohos/OHOSVideoDecoder.h @@ -97,6 +97,7 @@ class OHOSVideoDecoder : public VideoDecoder { int64_t yBufferSize = 0; int64_t uvBufferSize = 0; std::weak_ptr weakThis; + size_t maxPendingFramesCount = 0; explicit OHOSVideoDecoder(const VideoFormat& format, bool hardware); bool initDecoder(const OH_AVCodecCategory avCodecCategory);