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

Unified Diff: media/video/capture/fake_video_capture_device.cc

Issue 1090273006: Revert of VideoCapture: add support for GpuMemoryBuffer allocation and lifetime mgmt in VideoCaptureBufferPool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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: media/video/capture/fake_video_capture_device.cc
diff --git a/media/video/capture/fake_video_capture_device.cc b/media/video/capture/fake_video_capture_device.cc
index a2cd37d65a035a6b1bab5000be54e57fe715205e..4f3a8bb7d62ae73569cf634d7c8991239f89f5a0 100644
--- a/media/video/capture/fake_video_capture_device.cc
+++ b/media/video/capture/fake_video_capture_device.cc
@@ -101,25 +101,26 @@
else
capture_format_.frame_size.SetSize(320, 240);
- if (device_type_ == USING_OWN_BUFFERS ||
- device_type_ == USING_OWN_BUFFERS_TRIPLANAR) {
- fake_frame_.reset(new uint8[VideoFrame::AllocationSize(
- VideoFrame::I420, capture_format_.frame_size)]);
- BeepAndScheduleNextCapture(
- base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers,
- weak_factory_.GetWeakPtr()));
- } else if (device_type_ == USING_CLIENT_BUFFERS_I420 ||
- device_type_ == USING_CLIENT_BUFFERS_GPU) {
- DVLOG(1) << "starting with " << (device_type_ == USING_CLIENT_BUFFERS_I420
- ? "Client buffers"
- : "GpuMemoryBuffers");
- BeepAndScheduleNextCapture(base::Bind(
- &FakeVideoCaptureDevice::CaptureUsingClientBuffers,
- weak_factory_.GetWeakPtr(), (device_type_ == USING_CLIENT_BUFFERS_I420
- ? PIXEL_FORMAT_I420
- : PIXEL_FORMAT_GPUMEMORYBUFFER)));
- } else {
- client_->OnError("Unknown Fake Video Capture Device type.");
+ switch (device_type_) {
+ case USING_OWN_BUFFERS:
+ fake_frame_.reset(new uint8[VideoFrame::AllocationSize(
+ VideoFrame::I420, capture_format_.frame_size)]);
+ BeepAndScheduleNextCapture(
+ base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers,
+ weak_factory_.GetWeakPtr()));
+ break;
+ case USING_CLIENT_BUFFERS:
+ BeepAndScheduleNextCapture(
+ base::Bind(&FakeVideoCaptureDevice::CaptureUsingClientBuffers,
+ weak_factory_.GetWeakPtr()));
+ break;
+ case USING_GPU_MEMORY_BUFFERS:
+ BeepAndScheduleNextCapture(
+ base::Bind(&FakeVideoCaptureDevice::CaptureUsingGpuMemoryBuffers,
+ weak_factory_.GetWeakPtr()));
+ break;
+ default:
+ client_->OnError("Unknown Fake Video Capture Device type.");
}
}
@@ -130,7 +131,8 @@
void FakeVideoCaptureDevice::CaptureUsingOwnBuffers() {
DCHECK(thread_checker_.CalledOnValidThread());
- const size_t frame_size = capture_format_.ImageAllocationSize();
+ const size_t frame_size =
+ VideoFrame::AllocationSize(VideoFrame::I420, capture_format_.frame_size);
memset(fake_frame_.get(), 0, frame_size);
DrawPacman(false /* use_argb */,
@@ -140,60 +142,62 @@
capture_format_.frame_size);
// Give the captured frame to the client.
- if (device_type_ == USING_OWN_BUFFERS) {
- client_->OnIncomingCapturedData(fake_frame_.get(),
- frame_size,
- capture_format_,
- 0 /* rotation */,
- base::TimeTicks::Now());
- } else if (device_type_ == USING_OWN_BUFFERS_TRIPLANAR) {
- client_->OnIncomingCapturedYuvData(
- fake_frame_.get(),
- fake_frame_.get() + capture_format_.frame_size.GetArea(),
- fake_frame_.get() + capture_format_.frame_size.GetArea() * 5 / 4,
- capture_format_.frame_size.width(),
- capture_format_.frame_size.width() / 2,
- capture_format_.frame_size.width() / 2,
- capture_format_,
- 0 /* rotation */,
- base::TimeTicks::Now());
- }
+ client_->OnIncomingCapturedData(fake_frame_.get(),
+ frame_size,
+ capture_format_,
+ 0,
+ base::TimeTicks::Now());
BeepAndScheduleNextCapture(
base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers,
weak_factory_.GetWeakPtr()));
}
-void FakeVideoCaptureDevice::CaptureUsingClientBuffers(
- VideoPixelFormat pixel_format) {
- DCHECK(thread_checker_.CalledOnValidThread());
-
- scoped_ptr<VideoCaptureDevice::Client::Buffer> capture_buffer(
- client_->ReserveOutputBuffer(pixel_format, capture_format_.frame_size));
+void FakeVideoCaptureDevice::CaptureUsingClientBuffers() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ const scoped_refptr<VideoCaptureDevice::Client::Buffer> capture_buffer =
+ client_->ReserveOutputBuffer(capture_format_.pixel_format,
+ capture_format_.frame_size);
DLOG_IF(ERROR, !capture_buffer) << "Couldn't allocate Capture Buffer";
-
- if (capture_buffer.get()) {
- uint8_t* const data_ptr = static_cast<uint8_t*>(capture_buffer->data());
- DCHECK(data_ptr) << "Buffer has NO backing memory";
- memset(data_ptr, 0, capture_buffer->size());
-
- DrawPacman(
- (pixel_format == media::PIXEL_FORMAT_GPUMEMORYBUFFER), /* use_argb */
- data_ptr,
- frame_count_,
- kFakeCapturePeriodMs,
- capture_format_.frame_size);
-
- // Give the captured frame to the client.
- const VideoCaptureFormat format(capture_format_.frame_size,
- capture_format_.frame_rate,
- pixel_format);
- client_->OnIncomingCapturedBuffer(capture_buffer.Pass(), format,
- base::TimeTicks::Now());
- }
-
+ if (!capture_buffer)
+ return;
+
+ uint8_t* const data_ptr = static_cast<uint8_t*>(capture_buffer->data());
+ memset(data_ptr, 0, capture_buffer->size());
+ DCHECK(data_ptr) << "Buffer has NO backing memory";
+
+ DrawPacman(false /* use_argb */,
+ data_ptr,
+ frame_count_,
+ kFakeCapturePeriodMs,
+ capture_format_.frame_size);
+
+ scoped_refptr<VideoFrame> video_frame =
+ VideoFrame::WrapExternalPackedMemory(
+ VideoFrame::I420,
+ capture_format_.frame_size,
+ gfx::Rect(capture_format_.frame_size),
+ capture_format_.frame_size,
+ static_cast<uint8*>(capture_buffer->data()),
+ capture_buffer->size(),
+ base::SharedMemory::NULLHandle(),
+ 0,
+ base::TimeDelta(),
+ base::Closure());
+
+ // Give the captured frame to the client.
+ client_->OnIncomingCapturedVideoFrame(capture_buffer,
+ video_frame,
+ base::TimeTicks::Now());
BeepAndScheduleNextCapture(
base::Bind(&FakeVideoCaptureDevice::CaptureUsingClientBuffers,
- weak_factory_.GetWeakPtr(), pixel_format));
+ weak_factory_.GetWeakPtr()));
+}
+
+void FakeVideoCaptureDevice::CaptureUsingGpuMemoryBuffers() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ NOTIMPLEMENTED();
}
void FakeVideoCaptureDevice::BeepAndScheduleNextCapture(
« no previous file with comments | « media/video/capture/fake_video_capture_device.h ('k') | media/video/capture/fake_video_capture_device_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698