Commit 3a429fc0 authored by Chih-Yu Huang's avatar Chih-Yu Huang Committed by Commit Bot

media/gpu/chromeos/PlatformVFPool: don't request frames with same format.

Buffer allocation is time-consuming action. This CL makes
PlatformVideoFramePool not try to allocate new buffers if all the
arguments that affects the physical layout of buffer are not changed.

Bug: 1018817
Bug: 1028406
Test: media_unittests --gtest_filter=PlatformVideoFramePool.*
Test: video_decode_accelerator_tests on Kevin and Eve

Change-Id: I3f1a2b91b0f8c762d7c16f3a873648274176a6d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1948009Reviewed-by: default avatarHirokazu Honda <hiroh@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721362}
parent ebaf95c5
......@@ -133,16 +133,18 @@ base::Optional<GpuBufferLayout> PlatformVideoFramePool::RequestFrames(
if (!IsSameFormat_Locked(format, coded_size)) {
DVLOGF(4) << "The video frame format is changed. Clearing the pool.";
free_frames_.clear();
}
// Create a temporary frame in order to know VideoFrameLayout that VideoFrame
// that will be allocated in GetFrame() has.
auto frame =
create_frame_cb_.Run(gpu_memory_buffer_factory_, format, coded_size,
visible_rect_, natural_size_, base::TimeDelta());
if (!frame) {
VLOGF(1) << "Failed to create video frame";
return base::nullopt;
// Create a temporary frame in order to know VideoFrameLayout that
// VideoFrame that will be allocated in GetFrame() has.
auto frame =
create_frame_cb_.Run(gpu_memory_buffer_factory_, format, coded_size,
visible_rect_, natural_size_, base::TimeDelta());
if (!frame) {
VLOGF(1) << "Failed to create video frame";
return base::nullopt;
}
frame_layout_ = GpuBufferLayout::Create(fourcc, frame->coded_size(),
frame->layout().planes());
}
// The pool might become available because of |max_num_frames_| increased.
......@@ -150,8 +152,6 @@ base::Optional<GpuBufferLayout> PlatformVideoFramePool::RequestFrames(
if (frame_available_cb_ && !IsExhausted_Locked())
std::move(frame_available_cb_).Run();
frame_layout_ = GpuBufferLayout::Create(fourcc, frame->coded_size(),
frame->layout().planes());
return frame_layout_;
}
......
......@@ -179,6 +179,23 @@ TEST_F(PlatformVideoFramePoolTest, UnwrapVideoFrame) {
EXPECT_FALSE(frame_1->IsSameDmaBufsAs(*frame_3));
}
TEST_F(PlatformVideoFramePoolTest, FormatNotChange) {
RequestFrames(Fourcc(Fourcc::YV12));
scoped_refptr<VideoFrame> frame1 = GetFrame(10);
DmabufId id1 = DmabufVideoFramePool::GetDmabufId(*frame1);
// Clear frame references to return the frames to the pool.
frame1 = nullptr;
task_environment_.RunUntilIdle();
// Request frame with the same format. The pool should not request new frames.
RequestFrames(Fourcc(Fourcc::YV12));
scoped_refptr<VideoFrame> frame2 = GetFrame(20);
DmabufId id2 = DmabufVideoFramePool::GetDmabufId(*frame2);
EXPECT_EQ(id1, id2);
}
// TODO(akahuang): Add a testcase to verify calling RequestFrames() only with
// different |max_num_frames|.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment