Commit 6c3fecf0 authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

media/gpu/vaapi/VaapiDmabufVFMapper: Make a mapped frame outlive a source video frame

A VideoFrame mapped by the VaapiDmabufVideoFrameMapper holds a VAImage created
from the source VideoFrame. The VA surface associated the source video frame
should not be released until the mapped video frame is destroyed, so we bind a
reference to the source video frame to the mapped video frame's destructor.

Bug: 1020776
Test: VD test on atlas
Change-Id: Ia0b01b4bcb3e4312c0c2e91f8ad8c8beae20f393
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1911342
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: default avatarDavid Staessens <dstaessens@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714807}
parent 79aabb06
...@@ -22,15 +22,17 @@ constexpr VAImageFormat kImageFormatNV12{.fourcc = VA_FOURCC_NV12, ...@@ -22,15 +22,17 @@ constexpr VAImageFormat kImageFormatNV12{.fourcc = VA_FOURCC_NV12,
.byte_order = VA_LSB_FIRST, .byte_order = VA_LSB_FIRST,
.bits_per_pixel = 12}; .bits_per_pixel = 12};
void DeallocateBuffers(std::unique_ptr<ScopedVAImage> va_image) { void DeallocateBuffers(std::unique_ptr<ScopedVAImage> va_image,
scoped_refptr<const VideoFrame> /* video_frame */) {
// The |video_frame| will be released here and it will be returned to pool if
// client uses video frame pool.
// Destructing ScopedVAImage releases its owned memory. // Destructing ScopedVAImage releases its owned memory.
DCHECK(va_image->IsValid()); DCHECK(va_image->IsValid());
} }
scoped_refptr<VideoFrame> CreateMappedVideoFrame( scoped_refptr<VideoFrame> CreateMappedVideoFrame(
const VideoPixelFormat format, const VideoPixelFormat format,
const gfx::Rect& visible_rect, scoped_refptr<const VideoFrame> src_video_frame,
const base::TimeDelta timestamp,
std::unique_ptr<ScopedVAImage> va_image) { std::unique_ptr<ScopedVAImage> va_image) {
DCHECK(va_image); DCHECK(va_image);
// ScopedVAImage manages the resource of mapped data. That is, ScopedVAImage's // ScopedVAImage manages the resource of mapped data. That is, ScopedVAImage's
...@@ -71,13 +73,16 @@ scoped_refptr<VideoFrame> CreateMappedVideoFrame( ...@@ -71,13 +73,16 @@ scoped_refptr<VideoFrame> CreateMappedVideoFrame(
return nullptr; return nullptr;
} }
auto video_frame = VideoFrame::WrapExternalYuvDataWithLayout( auto video_frame = VideoFrame::WrapExternalYuvDataWithLayout(
*mapped_layout, visible_rect, visible_rect.size(), addrs[0], addrs[1], *mapped_layout, src_video_frame->visible_rect(),
addrs[2], timestamp); src_video_frame->visible_rect().size(), addrs[0], addrs[1], addrs[2],
src_video_frame->timestamp());
if (!video_frame) if (!video_frame)
return nullptr; return nullptr;
video_frame->AddDestructionObserver( // The source video frame should not be released until the mapped
base::BindOnce(DeallocateBuffers, std::move(va_image))); // |video_frame| is destructed, because |video_frame| holds |va_image|.
video_frame->AddDestructionObserver(base::BindOnce(
DeallocateBuffers, std::move(va_image), std::move(src_video_frame)));
return video_frame; return video_frame;
} }
...@@ -150,8 +155,8 @@ scoped_refptr<VideoFrame> VaapiDmaBufVideoFrameMapper::Map( ...@@ -150,8 +155,8 @@ scoped_refptr<VideoFrame> VaapiDmaBufVideoFrameMapper::Map(
return nullptr; return nullptr;
} }
return CreateMappedVideoFrame(kConvertedFormat, video_frame->visible_rect(), return CreateMappedVideoFrame(kConvertedFormat, std::move(video_frame),
video_frame->timestamp(), std::move(va_image)); std::move(va_image));
} }
} // namespace media } // namespace media
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