Fix play once video player

This commit is contained in:
2026-04-23 08:36:52 +10:00
parent c625898f61
commit 91bdb3f96b
2 changed files with 21 additions and 6 deletions

View File

@@ -480,10 +480,17 @@ namespace ANSCENTER {
// HW decode path (CFilePlayer)
// =====================================================================
if (_hwDecodeActive && _hwPlayer) {
// EOF: return black frame (same behavior as cv::VideoCapture path)
// EOF: return black frame with monotonically-increasing PTS so the
// caller can tell playback is still alive (not hung). Allocate the
// black buffer once and reuse it on repeat EOF calls — avoids a
// ~6 MB reallocation per GetImage() tick at 1080p.
if (_hwEOF) {
if (_resHeight <= 0 || _resWidth <= 0) { _resHeight = 1080; _resWidth = 1920; }
_previousImage = cv::Mat(_resHeight, _resWidth, CV_8UC3, cv::Scalar(0, 0, 0));
if (_previousImage.empty() ||
_previousImage.rows != _resHeight || _previousImage.cols != _resWidth ||
_previousImage.type() != CV_8UC3) {
_previousImage = cv::Mat(_resHeight, _resWidth, CV_8UC3, cv::Scalar(0, 0, 0));
}
width = _previousImage.cols;
height = _previousImage.rows;
if (_previousPTS < std::numeric_limits<int64_t>::max()) _previousPTS++;
@@ -620,7 +627,12 @@ namespace ANSCENTER {
_resWidth = static_cast<int>(cap.get(cv::CAP_PROP_FRAME_WIDTH));
}
_previousImage = cv::Mat(_resHeight, _resWidth, CV_8UC3, cv::Scalar(0, 0, 0));
// Reuse cached black buffer on repeat EOF ticks (~6 MB alloc avoided at 1080p).
if (_previousImage.empty() ||
_previousImage.rows != _resHeight || _previousImage.cols != _resWidth ||
_previousImage.type() != CV_8UC3) {
_previousImage = cv::Mat(_resHeight, _resWidth, CV_8UC3, cv::Scalar(0, 0, 0));
}
width = _previousImage.cols;
height = _previousImage.rows;