Commit a7f53f8a authored by Jeffrey Kardatzke's avatar Jeffrey Kardatzke Committed by Commit Bot

media/gpu/VEAtest: Cleanup memory allocation for input buffers

This code appeared wrong because it was locally allocating buffers for
the planes and then wrapping them in a VideoFrame which marked them as
unowned memory. The memory would be deallocated after the call to Encode
completes, and that posts a task so when the memory is actually accessed
later it would be invalid.  The V4L2 VEA also expects to receive owned
memory on input buffers as well.

other patches for buffer allocation unrelated to this)

Bug: None
Test: CacheLineUnalignedInputTest/** passes for I420 on trogdor (w/
Change-Id: I4552d803e5572f3f155dd984a273a1c0ffbc4b9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2032050Reviewed-by: default avatarHirokazu Honda <hiroh@chromium.org>
Reviewed-by: default avatarAlexandre Courbot <acourbot@chromium.org>
Commit-Queue: Jeffrey Kardatzke <jkardatzke@google.com>
Cr-Commit-Position: refs/heads/master@{#737431}
parent d5f8eabc
...@@ -2677,34 +2677,28 @@ void VEACacheLineUnalignedInputClient::FeedEncoderWithOneInput( ...@@ -2677,34 +2677,28 @@ void VEACacheLineUnalignedInputClient::FeedEncoderWithOneInput(
const VideoPixelFormat pixel_format = g_env->test_streams_[0]->pixel_format; const VideoPixelFormat pixel_format = g_env->test_streams_[0]->pixel_format;
size_t num_planes = VideoFrame::NumPlanes(pixel_format); size_t num_planes = VideoFrame::NumPlanes(pixel_format);
CHECK_LE(num_planes, 3u); CHECK_LE(num_planes, 3u);
std::vector<char, AlignedAllocator<char, kPlatformBufferAlignment>>
aligned_data[3];
std::vector<ColorPlaneLayout> planes(num_planes); std::vector<ColorPlaneLayout> planes(num_planes);
std::vector<size_t> buffer_sizes(num_planes); size_t offset = 0;
uint8_t* frame_data[3] = {};
// This VideoFrame is dummy. Each plane is stored in a separate buffer and
// each buffer size is the same as the plane size.
for (size_t i = 0; i < num_planes; i++) { for (size_t i = 0; i < num_planes; i++) {
size_t plane_size = size_t plane_size = base::bits::Align(
VideoFrame::PlaneSize(pixel_format, i, input_coded_size).GetArea(); VideoFrame::PlaneSize(pixel_format, i, input_coded_size).GetArea(),
aligned_data[i].resize(plane_size); kPlatformBufferAlignment);
frame_data[i] = reinterpret_cast<uint8_t*>(aligned_data[i].data());
planes[i].stride = planes[i].stride =
VideoFrame::RowBytes(i, pixel_format, input_coded_size.width()); VideoFrame::RowBytes(i, pixel_format, input_coded_size.width());
planes[i].offset = 0; planes[i].offset = offset;
planes[i].size = plane_size; planes[i].size = plane_size;
offset += plane_size;
} }
auto layout = VideoFrameLayout::CreateWithPlanes( auto layout = VideoFrameLayout::CreateWithPlanes(
pixel_format, input_coded_size, std::move(planes)); pixel_format, input_coded_size, std::move(planes),
kPlatformBufferAlignment);
ASSERT_TRUE(layout); ASSERT_TRUE(layout);
scoped_refptr<VideoFrame> video_frame = VideoFrame::CreateFrameWithLayout(
scoped_refptr<VideoFrame> video_frame = *layout, gfx::Rect(input_coded_size), input_coded_size,
VideoFrame::WrapExternalYuvDataWithLayout( base::TimeDelta().FromMilliseconds(base::Time::kMillisecondsPerSecond /
*layout, gfx::Rect(input_coded_size), input_coded_size, frame_data[0], fps_),
frame_data[1], frame_data[2], true);
base::TimeDelta().FromMilliseconds(
base::Time::kMillisecondsPerSecond / fps_));
encoder_->Encode(video_frame, false); encoder_->Encode(video_frame, false);
} }
......
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