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

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

Issue 1154153003: Relanding 1143663007: VideoFrame: Separate Pixel Format from Storage Type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added NV12 support in CrOS Created 5 years, 7 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 894a6710d0ddfc8e7b91351f7d98b5984d877e0b..f636f3ac819e0b04c9eb4dc8f614983c6762aee5 100644
--- a/content/browser/renderer_host/media/video_capture_buffer_pool.cc
+++ b/content/browser/renderer_host/media/video_capture_buffer_pool.cc
@@ -25,8 +25,8 @@ VideoFrame::Format VideoPixelFormatToVideoFrameFormat(
VideoFrame::Format frame_format;
} const kVideoPixelFormatToVideoFrameFormat[] = {
{media::PIXEL_FORMAT_I420, VideoFrame::I420},
- {media::PIXEL_FORMAT_TEXTURE, VideoFrame::NATIVE_TEXTURE},
- {media::PIXEL_FORMAT_GPUMEMORYBUFFER, VideoFrame::NATIVE_TEXTURE},
+ {media::PIXEL_FORMAT_TEXTURE, VideoFrame::ARGB},
+ {media::PIXEL_FORMAT_GPUMEMORYBUFFER, VideoFrame::ARGB},
};
for (const auto& format_pair : kVideoPixelFormatToVideoFrameFormat) {
@@ -38,6 +38,26 @@ VideoFrame::Format VideoPixelFormatToVideoFrameFormat(
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_TEXTURE},
+ {media::PIXEL_FORMAT_GPUMEMORYBUFFER, VideoFrame::STORAGE_TEXTURE},
+ };
+
+ 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:
@@ -90,7 +110,9 @@ class GpuMemoryBufferBufferHandle
class VideoCaptureBufferPool::SharedMemTracker final : public Tracker {
public:
SharedMemTracker();
- bool Init(VideoFrame::Format format, const gfx::Size& dimensions) override;
+ bool Init(VideoFrame::Format format,
+ media::VideoFrame::StorageType storage_type,
+ const gfx::Size& dimensions) override;
size_t mapped_size() const override { return shared_memory_.mapped_size(); }
@@ -114,7 +136,9 @@ class VideoCaptureBufferPool::SharedMemTracker final : public Tracker {
class VideoCaptureBufferPool::GpuMemoryBufferTracker final : public Tracker {
public:
GpuMemoryBufferTracker();
- bool Init(VideoFrame::Format format, const gfx::Size& dimensions) override;
+ bool Init(VideoFrame::Format format,
+ media::VideoFrame::StorageType storage_type,
+ const gfx::Size& dimensions) override;
~GpuMemoryBufferTracker() override;
size_t mapped_size() const override { return packed_size_; }
@@ -138,9 +162,11 @@ VideoCaptureBufferPool::SharedMemTracker::SharedMemTracker() : Tracker() {
bool VideoCaptureBufferPool::SharedMemTracker::Init(
VideoFrame::Format format,
+ media::VideoFrame::StorageType 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.
@@ -161,12 +187,14 @@ VideoCaptureBufferPool::GpuMemoryBufferTracker::~GpuMemoryBufferTracker() {
bool VideoCaptureBufferPool::GpuMemoryBufferTracker::Init(
VideoFrame::Format format,
+ media::VideoFrame::StorageType storage_type,
const gfx::Size& dimensions) {
DVLOG(2) << "allocating GMB for " << dimensions.ToString();
// BrowserGpuMemoryBufferManager::current() may not be accessed on IO Thread.
DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(BrowserGpuMemoryBufferManager::current());
set_pixel_format(format);
+ set_storage_type(storage_type);
set_pixel_count(dimensions.GetArea());
gpu_memory_buffer_ =
BrowserGpuMemoryBufferManager::current()->AllocateGpuMemoryBuffer(
@@ -298,6 +326,10 @@ int VideoCaptureBufferPool::ReserveForProducerInternal(
*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;
@@ -308,8 +340,8 @@ int VideoCaptureBufferPool::ReserveForProducerInternal(
Tracker* const tracker = it->second;
if (!tracker->consumer_hold_count() && !tracker->held_by_producer()) {
if (tracker->pixel_count() >= size_in_pixels &&
- (tracker->pixel_format() ==
- VideoPixelFormatToVideoFrameFormat(format))) {
+ (tracker->pixel_format() == pixel_format) &&
+ (tracker->storage_type() == storage_type)) {
// Existing tracker is big enough and has correct format. Reuse it.
tracker->set_held_by_producer(true);
return it->first;
@@ -338,7 +370,7 @@ int VideoCaptureBufferPool::ReserveForProducerInternal(
scoped_ptr<Tracker> tracker =
Tracker::CreateTracker(format == media::PIXEL_FORMAT_GPUMEMORYBUFFER);
- if (!tracker->Init(VideoPixelFormatToVideoFrameFormat(format), dimensions)) {
+ if (!tracker->Init(pixel_format, storage_type, dimensions)) {
DLOG(ERROR) << "Error initializing Tracker";
return kInvalidId;
}

Powered by Google App Engine
This is Rietveld 408576698