From f24d1461f64365b3430d6bfacd29de68eb10637d Mon Sep 17 00:00:00 2001 From: wanghaizhou Date: Wed, 1 Nov 2023 22:06:04 +0800 Subject: [PATCH] hdi buffer add timeout release Signed-off-by: wanghaizhou Change-Id: I68be7be5b1b60ca2e4c9215dcf4d0546d4e822cc --- .../codec/hdi_plugins/hdi_out_buffer_mgr.cpp | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/services/engine/gstreamer/plugins/codec/hdi_plugins/hdi_out_buffer_mgr.cpp b/services/engine/gstreamer/plugins/codec/hdi_plugins/hdi_out_buffer_mgr.cpp index ac1c95a5e..5d97badb1 100644 --- a/services/engine/gstreamer/plugins/codec/hdi_plugins/hdi_out_buffer_mgr.cpp +++ b/services/engine/gstreamer/plugins/codec/hdi_plugins/hdi_out_buffer_mgr.cpp @@ -90,27 +90,33 @@ int32_t HdiOutBufferMgr::PullBuffer(GstBuffer **buffer) MEDIA_LOGD("Enter PullBuffer"); CHECK_AND_RETURN_RET_LOG(buffer != nullptr, GST_CODEC_ERROR, "buffer is nullptr"); std::unique_lock lock(mutex_); - bufferCond_.wait(lock, [this]() { return !mBuffers.empty() || isFlushed_ || !isStart_ || isFormatChange_; }); - if (isFormatChange_ && !mBuffers.empty()) { - MEDIA_LOGD("format change, waiting mBuffers empty"); - } else if (isFlushed_ || !isStart_) { - MEDIA_LOGD("isFlush %{public}d isStart %{public}d", isFlushed_, isStart_); - return GST_CODEC_FLUSH; - } - if (!mBuffers.empty()) { - MEDIA_LOGD("mBuffers %{public}zu, available %{public}zu", mBuffers.size(), availableBuffers_.size()); - MediaTrace::CounterTrace("WaitingForDisplayBuffers", mBuffers.size()); - GstBufferWrap bufferWarp = mBuffers.front(); - mBuffers.pop_front(); - if (bufferWarp.isEos) { - gst_buffer_unref(bufferWarp.gstBuffer); - MEDIA_LOGD("buffer is in eos"); - return GST_CODEC_EOS; + static constexpr int32_t timeout = 5; + if (bufferCond_.wait_for(lock, std::chrono::seconds(timeout), + [this]() { return !mBuffers.empty() || isFlushed_ || !isStart_ || isFormatChange_; })) { + if (isFormatChange_ && !mBuffers.empty()) { + MEDIA_LOGD("format change, waiting mBuffers empty"); + } else if (isFlushed_ || !isStart_) { + MEDIA_LOGD("isFlush %{public}d isStart %{public}d", isFlushed_, isStart_); + return GST_CODEC_FLUSH; + } + if (!mBuffers.empty()) { + MEDIA_LOGD("mBuffers %{public}zu, available %{public}zu", mBuffers.size(), availableBuffers_.size()); + MediaTrace::CounterTrace("WaitingForDisplayBuffers", mBuffers.size()); + GstBufferWrap bufferWarp = mBuffers.front(); + mBuffers.pop_front(); + if (bufferWarp.isEos) { + gst_buffer_unref(bufferWarp.gstBuffer); + MEDIA_LOGD("buffer is in eos"); + return GST_CODEC_EOS; + } + (*buffer) = bufferWarp.gstBuffer; + return GST_CODEC_OK; } - (*buffer) = bufferWarp.gstBuffer; + return GST_CODEC_ERROR; + } else { + MEDIA_LOGI("PullBuffer bufferCond timeout"); return GST_CODEC_OK; } - return GST_CODEC_ERROR; } int32_t HdiOutBufferMgr::FreeBuffers() -- Gitee