Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(710)

Unified Diff: content/browser/renderer_host/media/video_capture_buffer_pool.cc

Issue 1179323002: Video Capture: extract storage info from pixel format in VideoCaptureFormat. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: hubbe@s comments and minor rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/media/video_capture_buffer_pool.cc
diff --git a/content/browser/renderer_host/media/video_capture_buffer_pool.cc b/content/browser/renderer_host/media/video_capture_buffer_pool.cc
index eeeafc6ce986d7f85984a8c6f669f1fcc580772c..f4b3f85a76d975138454f35115fbb55ca99af409 100644
--- a/content/browser/renderer_host/media/video_capture_buffer_pool.cc
+++ b/content/browser/renderer_host/media/video_capture_buffer_pool.cc
@@ -10,54 +10,11 @@
#include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
#include "content/common/gpu/client/gpu_memory_buffer_impl.h"
#include "content/public/browser/browser_thread.h"
-#include "media/base/video_frame.h"
-
-using media::VideoFrame;
namespace content {
const int VideoCaptureBufferPool::kInvalidId = -1;
-VideoFrame::Format VideoPixelFormatToVideoFrameFormat(
- media::VideoPixelFormat pixel_format) {
- static struct {
- media::VideoPixelFormat pixel_format;
- VideoFrame::Format frame_format;
- } const kVideoPixelFormatToVideoFrameFormat[] = {
- {media::PIXEL_FORMAT_I420, VideoFrame::I420},
- {media::PIXEL_FORMAT_TEXTURE, VideoFrame::ARGB},
- {media::PIXEL_FORMAT_GPUMEMORYBUFFER, VideoFrame::ARGB},
- };
-
- for (const auto& format_pair : kVideoPixelFormatToVideoFrameFormat) {
- if (format_pair.pixel_format == pixel_format)
- return format_pair.frame_format;
- }
- LOG(ERROR) << "Unsupported VideoPixelFormat "
- << media::VideoCaptureFormat::PixelFormatToString(pixel_format);
- return VideoFrame::UNKNOWN;
-}
-
-VideoFrame::StorageType VideoPixelFormatToVideoFrameStorageType(
- media::VideoPixelFormat pixel_format) {
- static struct {
- media::VideoPixelFormat pixel_format;
- VideoFrame::StorageType storage_type;
- } const kVideoPixelFormatToVideoFrameStorageType[] = {
- {media::PIXEL_FORMAT_I420, VideoFrame::STORAGE_SHMEM},
- {media::PIXEL_FORMAT_TEXTURE, VideoFrame::STORAGE_OPAQUE},
- {media::PIXEL_FORMAT_GPUMEMORYBUFFER, VideoFrame::STORAGE_OPAQUE},
- };
-
- for (const auto& format_pair : kVideoPixelFormatToVideoFrameStorageType) {
- if (format_pair.pixel_format == pixel_format)
- return format_pair.storage_type;
- }
- LOG(ERROR) << "Unsupported VideoPixelFormat "
- << media::VideoCaptureFormat::PixelFormatToString(pixel_format);
- return VideoFrame::STORAGE_UNKNOWN;
-}
-
// A simple holder of a memory-backed buffer and accesors to it.
class SimpleBufferHandle final : public VideoCaptureBufferPool::BufferHandle {
public:
@@ -127,8 +84,8 @@ class GpuMemoryBufferBufferHandle
class VideoCaptureBufferPool::SharedMemTracker final : public Tracker {
public:
SharedMemTracker();
- bool Init(VideoFrame::Format format,
- media::VideoFrame::StorageType storage_type,
+ bool Init(media::VideoPixelFormat format,
+ media::VideoPixelStorage storage_type,
const gfx::Size& dimensions) override;
size_t mapped_size() const override { return shared_memory_.mapped_size(); }
@@ -153,8 +110,8 @@ class VideoCaptureBufferPool::SharedMemTracker final : public Tracker {
class VideoCaptureBufferPool::GpuMemoryBufferTracker final : public Tracker {
public:
GpuMemoryBufferTracker();
- bool Init(VideoFrame::Format format,
- media::VideoFrame::StorageType storage_type,
+ bool Init(media::VideoPixelFormat format,
+ media::VideoPixelStorage storage_type,
const gfx::Size& dimensions) override;
~GpuMemoryBufferTracker() override;
@@ -178,24 +135,24 @@ VideoCaptureBufferPool::SharedMemTracker::SharedMemTracker() : Tracker() {
}
bool VideoCaptureBufferPool::SharedMemTracker::Init(
- VideoFrame::Format format,
- media::VideoFrame::StorageType storage_type,
+ media::VideoPixelFormat format,
+ media::VideoPixelStorage storage_type,
const gfx::Size& dimensions) {
DVLOG(2) << "allocating ShMem of " << dimensions.ToString();
set_pixel_format(format);
set_storage_type(storage_type);
- // Input |dimensions| can be 0x0 for trackers that do not require memory
- // backing. The allocated size is calculated using VideoFrame methods since
- // this will be the abstraction used to wrap the underlying data.
+ // |dimensions| can be 0x0 for trackers that do not require memory backing.
set_pixel_count(dimensions.GetArea());
- const size_t byte_count = VideoFrame::AllocationSize(format, dimensions);
hubbe 2015/06/18 19:23:10 Being able to re-use VideoFrame code seems like a
mcasas 2015/06/19 02:58:35 Yes but VideoCaptureBufferPool actually operates w
+ const media::VideoCaptureFormat capture_format(dimensions, 0.0f, format,
+ storage_type);
+ const size_t byte_count = capture_format.ImageAllocationSize();
if (!byte_count)
return true;
return shared_memory_.CreateAndMapAnonymous(byte_count);
}
VideoCaptureBufferPool::GpuMemoryBufferTracker::GpuMemoryBufferTracker()
- : Tracker(), gpu_memory_buffer_(nullptr) {}
+ : Tracker(), packed_size_(0u), gpu_memory_buffer_(nullptr) {}
VideoCaptureBufferPool::GpuMemoryBufferTracker::~GpuMemoryBufferTracker() {
if (gpu_memory_buffer_->IsMapped())
@@ -203,8 +160,8 @@ VideoCaptureBufferPool::GpuMemoryBufferTracker::~GpuMemoryBufferTracker() {
}
bool VideoCaptureBufferPool::GpuMemoryBufferTracker::Init(
- VideoFrame::Format format,
- media::VideoFrame::StorageType storage_type,
+ media::VideoPixelFormat format,
+ media::VideoPixelStorage storage_type,
const gfx::Size& dimensions) {
DVLOG(2) << "allocating GMB for " << dimensions.ToString();
// BrowserGpuMemoryBufferManager::current() may not be accessed on IO Thread.
@@ -213,6 +170,9 @@ bool VideoCaptureBufferPool::GpuMemoryBufferTracker::Init(
set_pixel_format(format);
set_storage_type(storage_type);
set_pixel_count(dimensions.GetArea());
+ // |dimensions| can be 0x0 for trackers that do not require memory backing.
+ if (dimensions.GetArea() == 0u)
+ return true;
gpu_memory_buffer_ =
BrowserGpuMemoryBufferManager::current()->AllocateGpuMemoryBuffer(
dimensions,
@@ -283,10 +243,12 @@ VideoCaptureBufferPool::GetBufferHandle(int buffer_id) {
}
int VideoCaptureBufferPool::ReserveForProducer(media::VideoPixelFormat format,
+ media::VideoPixelStorage storage,
const gfx::Size& dimensions,
int* buffer_id_to_drop) {
base::AutoLock lock(lock_);
- return ReserveForProducerInternal(format, dimensions, buffer_id_to_drop);
+ return ReserveForProducerInternal(format, storage, dimensions,
+ buffer_id_to_drop);
}
void VideoCaptureBufferPool::RelinquishProducerReservation(int buffer_id) {
@@ -344,20 +306,14 @@ double VideoCaptureBufferPool::GetBufferPoolUtilization() const {
}
int VideoCaptureBufferPool::ReserveForProducerInternal(
- media::VideoPixelFormat format,
+ media::VideoPixelFormat pixel_format,
+ media::VideoPixelStorage storage_type,
const gfx::Size& dimensions,
int* buffer_id_to_drop) {
- DCHECK(format == media::PIXEL_FORMAT_I420 ||
- format == media::PIXEL_FORMAT_TEXTURE ||
- format == media::PIXEL_FORMAT_GPUMEMORYBUFFER );
lock_.AssertAcquired();
*buffer_id_to_drop = kInvalidId;
const size_t size_in_pixels = dimensions.GetArea();
- const media::VideoFrame::Format pixel_format =
- VideoPixelFormatToVideoFrameFormat(format);
- const media::VideoFrame::StorageType storage_type =
- VideoPixelFormatToVideoFrameStorageType(format);
// Look for a tracker that's allocated, big enough, and not in use. Track the
// largest one that's not big enough, in case we have to reallocate a tracker.
*buffer_id_to_drop = kInvalidId;
@@ -396,8 +352,9 @@ int VideoCaptureBufferPool::ReserveForProducerInternal(
// Create the new tracker.
const int buffer_id = next_buffer_id_++;
- scoped_ptr<Tracker> tracker =
- Tracker::CreateTracker(format == media::PIXEL_FORMAT_GPUMEMORYBUFFER);
+ const bool use_gmb_tracker =
hubbe 2015/06/18 19:23:10 Why not inline this?
mcasas 2015/06/19 02:58:35 Done.
+ storage_type == media::PIXEL_STORAGE_GPUMEMORYBUFFER;
+ scoped_ptr<Tracker> tracker = Tracker::CreateTracker(use_gmb_tracker);
if (!tracker->Init(pixel_format, storage_type, dimensions)) {
DLOG(ERROR) << "Error initializing Tracker";
return kInvalidId;

Powered by Google App Engine
This is Rietveld 408576698