forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FileVideoCaptureDevice: support Mac NV12 GMB.
This capturer didn't previously support GMB capturing. This patch changes this by supplying a new GpuMemoryBufferTrackerMac supporting IOSurface generation. With capture & display in HD at 60 fps, we routinely run out of buffers. This patch increases the max number of outstanding buffers for macOS. Because the FileVideoCaptureDevice writes to GMBs using mode gfx::BufferUsage::SCANOUT_VEA_READ_CAMERA_AND_CPU_READ_WRITE which previously implied kIOSurfaceLockReadOnly locking mode, a new buffer usage constant gfx::BufferUsage::SCANOUT_VEA_CPU_READ is introduced which is used for buffers shipped from video capture. This fixes the related TODO in gpu_memory_buffer_impl_io_surface.cc by mapping SCANOUT_VEA_CPU_READ to kIOSurfaceLockReadOnly. Bug: 1134165, 1130101 Change-Id: I4d2d1624214659bd232a6fe064dc1de9362c5958 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2487341 Commit-Queue: Markus Handell <handellm@google.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: ccameron <ccameron@chromium.org> Reviewed-by: Guido Urdaneta <guidou@chromium.org> Reviewed-by: Robert Sesek <rsesek@chromium.org> Reviewed-by: Daniele Castagna <dcastagna@chromium.org> Cr-Commit-Position: refs/heads/master@{#820611}
- Loading branch information
Showing
22 changed files
with
172 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "media/capture/video/mac/gpu_memory_buffer_tracker_mac.h" | ||
|
||
#include "base/logging.h" | ||
|
||
namespace media { | ||
|
||
GpuMemoryBufferTrackerMac::GpuMemoryBufferTrackerMac() {} | ||
|
||
GpuMemoryBufferTrackerMac::~GpuMemoryBufferTrackerMac() {} | ||
|
||
bool GpuMemoryBufferTrackerMac::Init(const gfx::Size& dimensions, | ||
VideoPixelFormat format, | ||
const mojom::PlaneStridesPtr& strides) { | ||
if (format != PIXEL_FORMAT_NV12) { | ||
NOTREACHED() << "Unsupported VideoPixelFormat " | ||
<< VideoPixelFormatToString(format); | ||
return false; | ||
} | ||
if (IOSurfaceRef io_surface = | ||
CreateIOSurface(dimensions, gfx::BufferFormat::YUV_420_BIPLANAR, | ||
/*should_clear=*/false)) { | ||
io_surface_.reset(io_surface, base::scoped_policy::ASSUME); | ||
DVLOG(2) << __func__ << " id " << IOSurfaceGetID(io_surface_); | ||
return true; | ||
} else { | ||
LOG(ERROR) << "Unable to create IOSurface!"; | ||
return false; | ||
} | ||
} | ||
|
||
bool GpuMemoryBufferTrackerMac::IsReusableForFormat( | ||
const gfx::Size& dimensions, | ||
VideoPixelFormat format, | ||
const mojom::PlaneStridesPtr& strides) { | ||
gfx::Size surface_size(IOSurfaceGetWidth(io_surface_), | ||
IOSurfaceGetHeight(io_surface_)); | ||
return format == PIXEL_FORMAT_NV12 && dimensions == surface_size; | ||
} | ||
|
||
uint32_t GpuMemoryBufferTrackerMac::GetMemorySizeInBytes() { | ||
return IOSurfaceGetAllocSize(io_surface_); | ||
} | ||
|
||
std::unique_ptr<VideoCaptureBufferHandle> | ||
GpuMemoryBufferTrackerMac::GetMemoryMappedAccess() { | ||
NOTREACHED() << "Unsupported operation"; | ||
return std::make_unique<NullHandle>(); | ||
} | ||
|
||
base::UnsafeSharedMemoryRegion | ||
GpuMemoryBufferTrackerMac::DuplicateAsUnsafeRegion() { | ||
NOTREACHED() << "Unsupported operation"; | ||
return base::UnsafeSharedMemoryRegion(); | ||
} | ||
|
||
mojo::ScopedSharedBufferHandle | ||
GpuMemoryBufferTrackerMac::DuplicateAsMojoBuffer() { | ||
NOTREACHED() << "Unsupported operation"; | ||
return mojo::ScopedSharedBufferHandle(); | ||
} | ||
|
||
gfx::GpuMemoryBufferHandle | ||
GpuMemoryBufferTrackerMac::GetGpuMemoryBufferHandle() { | ||
DVLOG(2) << __func__ << " id " << IOSurfaceGetID(io_surface_); | ||
gfx::GpuMemoryBufferHandle gmb_handle; | ||
gmb_handle.type = gfx::GpuMemoryBufferType::IO_SURFACE_BUFFER; | ||
gmb_handle.id.id = -1; | ||
gmb_handle.io_surface = io_surface_; | ||
return gmb_handle; | ||
} | ||
|
||
} // namespace media |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef MEDIA_CAPTURE_VIDEO_MAC_GPU_MEMORY_BUFFER_TRACKER_MAC_H_ | ||
#define MEDIA_CAPTURE_VIDEO_MAC_GPU_MEMORY_BUFFER_TRACKER_MAC_H_ | ||
|
||
#include "media/capture/video/video_capture_buffer_tracker.h" | ||
#include "ui/gfx/geometry/size.h" | ||
#include "ui/gfx/mac/io_surface.h" | ||
|
||
namespace media { | ||
|
||
class CAPTURE_EXPORT GpuMemoryBufferTrackerMac final | ||
: public VideoCaptureBufferTracker { | ||
public: | ||
GpuMemoryBufferTrackerMac(); | ||
~GpuMemoryBufferTrackerMac() override; | ||
|
||
// VideoCaptureBufferTracker | ||
bool Init(const gfx::Size& dimensions, | ||
VideoPixelFormat format, | ||
const mojom::PlaneStridesPtr& strides) override; | ||
bool IsReusableForFormat(const gfx::Size& dimensions, | ||
VideoPixelFormat format, | ||
const mojom::PlaneStridesPtr& strides) override; | ||
uint32_t GetMemorySizeInBytes() override; | ||
std::unique_ptr<VideoCaptureBufferHandle> GetMemoryMappedAccess() override; | ||
base::UnsafeSharedMemoryRegion DuplicateAsUnsafeRegion() override; | ||
mojo::ScopedSharedBufferHandle DuplicateAsMojoBuffer() override; | ||
gfx::GpuMemoryBufferHandle GetGpuMemoryBufferHandle() override; | ||
|
||
private: | ||
base::ScopedCFTypeRef<IOSurfaceRef> io_surface_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferTrackerMac); | ||
}; | ||
|
||
} // namespace media | ||
|
||
#endif // MEDIA_CAPTURE_VIDEO_MAC_GPU_MEMORY_BUFFER_TRACKER_MAC_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.