Commit 3df4115c authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

media/gpu/test: AlignedDataHelper produces MojoSharedMemory VideoFrame

Originally AlignedDataHelper produces UNOWNED_MEMORY VideoFrame
from aligned data. This CL improves the AlignedDataHelper code
in order to return MojoSharedMemory VideoFrames. AlignedDataHelper
saves aligned data to mojo::ScopedSharedBufferHandle, and creates
a new MojoSharedMemoryHandle by duplicating the handle.

Bug: 1045825
Test: video_encode_accelerator_tests on eve
Change-Id: I2914891c4e37f76f35c4a32685f935b6d76b7c66
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2250144Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Reviewed-by: default avatarDavid Staessens <dstaessens@chromium.org>
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786192}
parent 13819e49
...@@ -75,6 +75,8 @@ source_set("test_helpers") { ...@@ -75,6 +75,8 @@ source_set("test_helpers") {
] ]
deps = [ deps = [
"//media/gpu", "//media/gpu",
"//media/mojo/common:mojo_shared_buffer_video_frame",
"//mojo/public/cpp/system",
"//testing/gtest", "//testing/gtest",
"//third_party/libyuv", "//third_party/libyuv",
] ]
......
include_rules = [
"+mojo/public",
]
...@@ -343,20 +343,32 @@ scoped_refptr<const VideoFrame> CreateVideoFrameFromImage(const Image& image) { ...@@ -343,20 +343,32 @@ scoped_refptr<const VideoFrame> CreateVideoFrameFromImage(const Image& image) {
return video_frame; return video_frame;
} }
base::Optional<VideoFrameLayout> CreateVideoFrameLayout(VideoPixelFormat format, base::Optional<VideoFrameLayout> CreateVideoFrameLayout(
const gfx::Size& size) { VideoPixelFormat pixel_format,
const size_t num_planes = VideoFrame::NumPlanes(format); const gfx::Size& dimension,
const uint32_t alignment,
std::vector<size_t>* plane_rows) {
const size_t num_planes = VideoFrame::NumPlanes(pixel_format);
std::vector<ColorPlaneLayout> planes(num_planes); std::vector<ColorPlaneLayout> planes(num_planes);
const auto strides = VideoFrame::ComputeStrides(format, size);
size_t offset = 0; size_t offset = 0;
if (plane_rows)
plane_rows->resize(num_planes);
for (size_t i = 0; i < num_planes; ++i) { for (size_t i = 0; i < num_planes; ++i) {
planes[i].stride = strides[i]; const int32_t stride =
VideoFrame::RowBytes(i, pixel_format, dimension.width());
const size_t rows = VideoFrame::Rows(i, pixel_format, dimension.height());
const size_t plane_size = stride * rows;
const size_t aligned_size = base::bits::Align(plane_size, alignment);
planes[i].stride = stride;
planes[i].offset = offset; planes[i].offset = offset;
planes[i].size = VideoFrame::PlaneSize(format, i, size).GetArea(); planes[i].size = aligned_size;
offset += planes[i].size; offset += planes[i].size;
if (plane_rows)
(*plane_rows)[i] = rows;
} }
return VideoFrameLayout::CreateWithPlanes(format, size, std::move(planes)); return VideoFrameLayout::CreateWithPlanes(pixel_format, dimension,
std::move(planes));
} }
} // namespace test } // namespace test
......
...@@ -85,12 +85,15 @@ scoped_refptr<VideoFrame> CreateGpuMemoryBufferVideoFrame( ...@@ -85,12 +85,15 @@ scoped_refptr<VideoFrame> CreateGpuMemoryBufferVideoFrame(
// own the data and thus must not be changed. // own the data and thus must not be changed.
scoped_refptr<const VideoFrame> CreateVideoFrameFromImage(const Image& image); scoped_refptr<const VideoFrame> CreateVideoFrameFromImage(const Image& image);
// Create a video frame layout for the specified |pixel_format| and // Create a video frame layout for the specified |pixel_format|, |dimension|
// |coded_size|. The created VideoFrameLayout represents all the planes are // and |alignment|. |plane_rows| is optional. If it is not nullptr, this fills
// stored in a single physical buffer. // the number of rows of each plane into it. The created VideoFrameLayout
// represents all the planes stored in a single physical buffer.
base::Optional<VideoFrameLayout> CreateVideoFrameLayout( base::Optional<VideoFrameLayout> CreateVideoFrameLayout(
VideoPixelFormat pixel_format, VideoPixelFormat pixel_format,
const gfx::Size& size); const gfx::Size& dimension,
const uint32_t alignment = VideoFrame::kFrameAddressAlignment,
std::vector<size_t>* plane_rows = nullptr);
} // namespace test } // namespace test
} // namespace media } // namespace media
......
This diff is collapsed.
...@@ -210,28 +210,32 @@ class AlignedDataHelper { ...@@ -210,28 +210,32 @@ class AlignedDataHelper {
bool AtEndOfStream() const; bool AtEndOfStream() const;
private: private:
// Align the video stream to platform requirements. struct VideoFrameData;
void CreateAlignedInputStream(const std::vector<uint8_t>& stream);
static VideoFrameLayout GetAlignedVideoFrameLayout(
// Current position in the video stream. VideoPixelFormat pixel_format,
size_t data_pos_ = 0; const gfx::Size& dimension,
const uint32_t alignment,
std::vector<size_t>* plane_rows,
size_t* video_frame_size);
// Create MojoSharedMemory VideoFrames whose memory are aligned by
// kPlatformBufferAlignment.
void InitializeAlignedMemoryFrames(const std::vector<uint8_t>& stream,
const VideoPixelFormat pixel_format,
const gfx::Size& coded_size);
// The index of VideoFrame to be read next.
uint32_t frame_index_ = 0;
// The number of frames in the video stream. // The number of frames in the video stream.
uint32_t num_frames_ = 0; const uint32_t num_frames_;
// The video stream's pixel format.
VideoPixelFormat pixel_format_ = VideoPixelFormat::PIXEL_FORMAT_UNKNOWN; // The layout of VideoFrames returned by GetNextFrame().
// The video stream's visible area. base::Optional<VideoFrameLayout> layout_;
gfx::Rect visible_area_; const gfx::Rect visible_area_;
// The video's coded size, as requested by the encoder.
gfx::Size coded_size_; // The frame data returned by GetNextFrame().
std::vector<VideoFrameData> video_frame_data_;
// Aligned data, each plane is aligned to the specified platform alignment
// requirements.
std::vector<char, AlignedAllocator<char, kPlatformBufferAlignment>>
aligned_data_;
// Byte size of each frame in |aligned_data_|.
size_t aligned_frame_size_ = 0;
// Byte size for each aligned plane in a frame.
std::vector<size_t> aligned_plane_size_;
}; };
// Small helper class to extract video frames from raw data streams. // Small helper class to extract video frames from raw data streams.
......
...@@ -163,6 +163,7 @@ scoped_refptr<MojoSharedBufferVideoFrame> MojoSharedBufferVideoFrame::Create( ...@@ -163,6 +163,7 @@ scoped_refptr<MojoSharedBufferVideoFrame> MojoSharedBufferVideoFrame::Create(
// range of an int) due to the IsValidConfig() check above. // range of an int) due to the IsValidConfig() check above.
// //
// TODO(sandersd): Allow non-sequential formats. // TODO(sandersd): Allow non-sequential formats.
std::vector<ColorPlaneLayout> planes(num_planes);
for (size_t i = 0; i < num_planes; ++i) { for (size_t i = 0; i < num_planes; ++i) {
if (strides[i] < 0) { if (strides[i] < 0) {
DLOG(ERROR) << __func__ << " Invalid stride"; DLOG(ERROR) << __func__ << " Invalid stride";
...@@ -190,10 +191,15 @@ scoped_refptr<MojoSharedBufferVideoFrame> MojoSharedBufferVideoFrame::Create( ...@@ -190,10 +191,15 @@ scoped_refptr<MojoSharedBufferVideoFrame> MojoSharedBufferVideoFrame::Create(
DLOG(ERROR) << __func__ << " Invalid offset"; DLOG(ERROR) << __func__ << " Invalid offset";
return nullptr; return nullptr;
} }
planes[i].stride = strides[i];
planes[i].offset = offsets[i];
planes[i].size = i + 1 < num_planes ? offsets[i + 1] - offsets[i]
: data_size - offsets.back();
} }
auto layout = VideoFrameLayout::CreateWithStrides(format, coded_size, auto layout =
std::move(strides)); VideoFrameLayout::CreateWithPlanes(format, coded_size, std::move(planes));
if (!layout) { if (!layout) {
return nullptr; return nullptr;
} }
......
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