Commit 47364f1e authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

media/capture/video: Follow GbmWrapper change, one file descriptor for each plane

crrev.com/c/1437036 makes GbmWrapper create GbmPixmap which has one file
descriptor for each plane. This CL follows the change in chrome os capture
stack.

Bug: 911370
Test: capture_unittests
Change-Id: Ia498f36d9f4edd074cba4dc8ea5bc863364297c1
Reviewed-on: https://chromium-review.googlesource.com/c/1438858
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: default avatarRicky Liang <jcliang@chromium.org>
Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626935}
parent 645e596f
...@@ -71,9 +71,9 @@ class GpuMemoryBufferImplGbm : public gfx::GpuMemoryBuffer { ...@@ -71,9 +71,9 @@ class GpuMemoryBufferImplGbm : public gfx::GpuMemoryBuffer {
handle_.type = gfx::NATIVE_PIXMAP; handle_.type = gfx::NATIVE_PIXMAP;
// Set a dummy id since this is for testing only. // Set a dummy id since this is for testing only.
handle_.id = gfx::GpuMemoryBufferId(0); handle_.id = gfx::GpuMemoryBufferId(0);
handle_.native_pixmap_handle.fds.push_back(
base::FileDescriptor(gbm_bo_get_fd(buffer_object), false));
for (size_t i = 0; i < gbm_bo_get_num_planes(buffer_object); ++i) { for (size_t i = 0; i < gbm_bo_get_num_planes(buffer_object); ++i) {
handle_.native_pixmap_handle.fds.push_back(
base::FileDescriptor(gbm_bo_get_plane_fd(buffer_object, i), true));
handle_.native_pixmap_handle.planes.push_back( handle_.native_pixmap_handle.planes.push_back(
gfx::NativePixmapPlane(gbm_bo_get_plane_stride(buffer_object, i), gfx::NativePixmapPlane(gbm_bo_get_plane_stride(buffer_object, i),
gbm_bo_get_plane_offset(buffer_object, i), gbm_bo_get_plane_offset(buffer_object, i),
...@@ -85,7 +85,12 @@ class GpuMemoryBufferImplGbm : public gfx::GpuMemoryBuffer { ...@@ -85,7 +85,12 @@ class GpuMemoryBufferImplGbm : public gfx::GpuMemoryBuffer {
if (mapped_) { if (mapped_) {
Unmap(); Unmap();
} }
close(gbm_bo_get_fd(buffer_object_));
for (const auto& fd : handle_.native_pixmap_handle.fds) {
// Close fds.
DCHECK(fd.auto_close);
close(fd.fd);
}
gbm_bo_destroy(buffer_object_); gbm_bo_destroy(buffer_object_);
} }
......
...@@ -356,25 +356,18 @@ void StreamBufferManager::RegisterBuffer(StreamType stream_type) { ...@@ -356,25 +356,18 @@ void StreamBufferManager::RegisterBuffer(StreamType stream_type) {
gfx::NativePixmapHandle buffer_handle = gfx::NativePixmapHandle buffer_handle =
buffer->CloneHandle().native_pixmap_handle; buffer->CloneHandle().native_pixmap_handle;
// Take ownership of FD at index 0.
base::ScopedFD fd(buffer_handle.fds[0].fd);
// There should be only one FD. Close all remaining FDs if there are any.
DCHECK_EQ(buffer_handle.fds.size(), 1U);
for (size_t i = 1; i < buffer_handle.fds.size(); ++i)
base::ScopedFD scoped_fd(buffer_handle.fds[i].fd);
size_t num_planes = buffer_handle.planes.size(); size_t num_planes = buffer_handle.planes.size();
DCHECK_EQ(num_planes, buffer_handle.fds.size());
// Take ownership of fds.
std::vector<base::ScopedFD> fds(num_planes);
for (size_t i = 0; i < num_planes; ++i)
fds[i] = base::ScopedFD(buffer_handle.fds[i].fd);
std::vector<StreamCaptureInterface::Plane> planes(num_planes); std::vector<StreamCaptureInterface::Plane> planes(num_planes);
for (size_t i = 0; i < num_planes; ++i) { for (size_t i = 0; i < num_planes; ++i) {
int dup_fd = dup(fd.get());
if (dup_fd == -1) {
device_context_->SetErrorState(
media::VideoCaptureError::kCrosHalV3BufferManagerFailedToDupFd,
FROM_HERE, "Failed to dup fd");
return;
}
planes[i].fd = planes[i].fd =
mojo::WrapPlatformHandle(mojo::PlatformHandle(base::ScopedFD(dup_fd))); mojo::WrapPlatformHandle(mojo::PlatformHandle(std::move(fds[i])));
if (!planes[i].fd.is_valid()) { if (!planes[i].fd.is_valid()) {
device_context_->SetErrorState( device_context_->SetErrorState(
media::VideoCaptureError:: media::VideoCaptureError::
......
...@@ -37,12 +37,15 @@ class FakeGpuMemoryBuffer : public gfx::GpuMemoryBuffer { ...@@ -37,12 +37,15 @@ class FakeGpuMemoryBuffer : public gfx::GpuMemoryBuffer {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Set a dummy fd since this is for testing only. // Set a dummy fd since this is for testing only.
handle_.native_pixmap_handle.fds.push_back(base::FileDescriptor(0, false)); handle_.native_pixmap_handle.fds.push_back(base::FileDescriptor(0, true));
handle_.native_pixmap_handle.planes.push_back( handle_.native_pixmap_handle.planes.push_back(
gfx::NativePixmapPlane(size_.width(), 0, y_plane_size)); gfx::NativePixmapPlane(size_.width(), 0, y_plane_size));
handle_.native_pixmap_handle.planes.push_back(gfx::NativePixmapPlane( if (format == gfx::BufferFormat::YUV_420_BIPLANAR) {
size_.width(), handle_.native_pixmap_handle.planes[0].size, handle_.native_pixmap_handle.fds.push_back(base::FileDescriptor(0, true));
uv_plane_size)); handle_.native_pixmap_handle.planes.push_back(gfx::NativePixmapPlane(
size_.width(), handle_.native_pixmap_handle.planes[0].size,
uv_plane_size));
}
// For faking a valid JPEG blob buffer. // For faking a valid JPEG blob buffer.
if (base::checked_cast<size_t>(size_.width()) >= sizeof(Camera3JpegBlob)) { if (base::checked_cast<size_t>(size_.width()) >= sizeof(Camera3JpegBlob)) {
......
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