diff options
author | magjed <magjed@chromium.org> | 2015-04-22 02:04:25 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-22 09:04:32 +0000 |
commit | df9c7fd3c4ba0f43fa27df0bbca0089e8cb94b01 (patch) | |
tree | e57f18892fd8201fb45c01754996d0e59a496b65 /media | |
parent | 69a10f1dd01ab6ec3b02473fc094e8112b50e683 (diff) | |
download | chromium_src-df9c7fd3c4ba0f43fa27df0bbca0089e8cb94b01.zip chromium_src-df9c7fd3c4ba0f43fa27df0bbca0089e8cb94b01.tar.gz chromium_src-df9c7fd3c4ba0f43fa27df0bbca0089e8cb94b01.tar.bz2 |
Revert of VideoCapture: add support for GpuMemoryBuffer allocation and lifetime mgmt in VideoCaptureBufferPool (patchset #7 id:480001 of https://codereview.chromium.org/1064963002/)
Reason for revert:
The reason for reverting is: Speculatively revert to address Android Tests (dbg) content_unittests failure:
http://build.chromium.org/p/chromium.linux/builders/Android%20Tests%20%28dbg%29/builds/27395
content_unittests content_unittests
failures:
VideoCaptureBufferPoolTest.BufferPool/2
GpuMemoryBufferFactoryTests/GpuMemoryBufferFactoryTest.CreateAndDestroy/1
VideoCaptureBufferPoolTest.BufferPool/0
VideoCaptureBufferPoolTest.BufferPool/1
[ RUN ] VideoCaptureBufferPoolTest.BufferPool/0
[FATAL:browser_gpu_memory_buffer_manager.cc(56)] Check failed: !g_gpu_memory_buffer_manager.
#00 0x764081d3 /data/app-lib/org.chromium.native_test-1/libcontent_unittests.so+0x00fdf1d3
#01 0x75cf95c3 /data/app-lib/org.chromium.native_test-1/libcontent_unittests.so+0x008d05c3
#02 0x75a3c697 /data/app-lib/org.chromium.native_test-1/libcontent_unittests.so+0x00613697
#03 0x75f8d1fb /data/app-lib/org.chromium.native_test-1/libcontent_unittests.so+0x00b641fb
#04 0x75f8d35b /data/app-lib/org.chromium.native_test-1/libcontent_unittests.so+0x00b6435b
#05 0x75f8d3e3 /data/app-lib/org.chromium.native_test-1/libcontent_unittests.so+0x00b643e3
#06 0x75f8d5e3 /data/app-lib/org.chromium.native_test-1/libcontent_unittests.so+0x00b645e3
#07 0x75f8c3c7 /data/app-lib/org.chromium.native_test-1/libcontent_unittests.so+0x00b633c7
#08 0x75f49bb7 /data/app-lib/org.chromium.native_test-1/libcontent_unittests.so+0x00b20bb7
#09 0x75f41c8b /data/app-lib/org.chromium.native_test-1/libcontent_unittests.so+0x00b18c8b
#10 0x75736087 /data/app-lib/org.chromium.native_test-1/libcontent_unittests.so+0x0030d087
#11 0x763de291 /data/app-lib/org.chromium.native_test-1/libcontent_unittests.so+0x00fb5291
#12 0x41503bcf /system/lib/libdvm.so+0x0001dbcf
#13 0x41534125 /system/lib/libdvm.so+0x0004e125
#14 0x4150cfe3 /system/lib/libdvm.so+0x00026fe3
#15 0x41513fa3 /system/lib/libdvm.so+0x0002dfa3
#16 0x4151163b /system/lib/libdvm.so+0x0002b63b
#17 0x41546863 /system/lib/libdvm.so+0x00060863
#18 0x4154e7c5 /system/lib/libdvm.so+0x000687c5
#19 0x4150cfe3 /system/lib/libdvm.so+0x00026fe3
#20 0x41513fa3 /system/lib/libdvm.so+0x0002dfa3
#21 0x4151163b /system/lib/libdvm.so+0x0002b63b
#22 0x4154657f /system/lib/libdvm.so+0x0006057f
#23 0x4152fd0d /system/lib/libdvm.so+0x00049d0d
#24 0x401a82b3 /system/lib/libandroid_runtime.so+0x0004d2b3
#25 0x401a8fd9 /system/lib/libandroid_runtime.so+0x0004dfd9
#26 0x4006b05d /system/bin/app_process+0x0000105d
#27 0x400a234b /system/lib/libc.so+0x0000e34b
This CL is the most suspect in the blame-list because it touches the VideoCaptureBufferPool.
Original issue's description:
> VideoCapture: add support for GpuMemoryBuffer allocation and lifetime mgmt in VideoCaptureBufferPool & relatives
>
> - This CL adds support for GpuMemoryBufferTracker in
> addition to the existing SharedMemTracker.
>
> - A GpuMemoryBufferTracker owns a GpuMemoryBuffer,
> which can only be accessed byte-wise between Map() and
> Unmap().
>
> - For that reason, instead of making a VCBP::Tracker
> directly accessible via |void* data| and |size|, a
> BufferHandle abstraction is introduced.
>
> - VideoCaptureDeviceClient then defines its own
> AutoReleaseBuffer in terms of this new BufferHandle.
> This BufferHandle is supposed to stay Map()ed and
> ready to use for the duration of its lifetime.
>
> Summing up:
> * VideoCaptureBufferPool has a pool of Trackers,
> * from the VCBP we can get a BufferHandle per |buffer_id|,
> * from a BufferHandle we can obtain data(), valid
> and Map()ed as long as the BufferHandle itself exists.
>
> - VideoCaptureDevice::ReserveOutputBuffer() changes to
> return a scoped_ptr<Buffer> ISO a scoped_refptr.
>
> - Added VideoCaptureDevice::OnIncomingCapturedBuffer()
> to pass directly a Buffer with the capture contents.
>
> - video_capture_texture_wrapper.{cc,h} is removed and
> its contents are merged into VideoCaptureDeviceClient.
>
> - FakeVideoCaptureDevice learns how to produce
> GpuMemoryBuffers. Also, PIXEL_FORMAT_GPUMEMORYBUFFER
> is added.
>
> Summing up, VCDClient accepts:
> * memory backed buffers (the usual)
> * texture-backed buffers
> * GMB-backed buffers (these are wrapped into a Texture
> VideoFrame indistinguishable from the previous case)
>
> - VideoCaptureTextureWrapper files are gone and
> its contents folded into VideoCaptureDeviceClient.
>
> - Unittests are updated, and so is FakeVideoCaptureDevice.
>
> BUG=440843
>
> Committed: https://crrev.com/abeb15fa955c570cd481accb04c2a677eb2865a9
> Cr-Commit-Position: refs/heads/master@{#326171}
TBR=miu@chromium.org,emircan@chromium.org,avi@chromium.org,dalecurtis@chromium.org,mcasas@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=440843
Review URL: https://codereview.chromium.org/1090273006
Cr-Commit-Position: refs/heads/master@{#326250}
Diffstat (limited to 'media')
-rw-r--r-- | media/base/video_capture_types.cc | 5 | ||||
-rw-r--r-- | media/base/video_capture_types.h | 1 | ||||
-rw-r--r-- | media/video/capture/fake_video_capture_device.cc | 128 | ||||
-rw-r--r-- | media/video/capture/fake_video_capture_device.h | 8 | ||||
-rw-r--r-- | media/video/capture/fake_video_capture_device_factory.cc | 11 | ||||
-rw-r--r-- | media/video/capture/fake_video_capture_device_unittest.cc | 59 | ||||
-rw-r--r-- | media/video/capture/video_capture_device.cc | 2 | ||||
-rw-r--r-- | media/video/capture/video_capture_device.h | 30 | ||||
-rw-r--r-- | media/video/capture/video_capture_device_unittest.cc | 48 |
9 files changed, 132 insertions, 160 deletions
diff --git a/media/base/video_capture_types.cc b/media/base/video_capture_types.cc index cc5f840..15280174 100644 --- a/media/base/video_capture_types.cc +++ b/media/base/video_capture_types.cc @@ -49,9 +49,6 @@ size_t VideoCaptureFormat::ImageAllocationSize() const { break; case PIXEL_FORMAT_RGB32: case PIXEL_FORMAT_ARGB: - // GpuMemoryBuffer is an endianness-agnostic 32bpp pixel format until - // http://crbug.com/439520 is closed. - case PIXEL_FORMAT_GPUMEMORYBUFFER: result_frame_size *= 4; break; case PIXEL_FORMAT_MJPEG: @@ -98,8 +95,6 @@ std::string VideoCaptureFormat::PixelFormatToString(VideoPixelFormat format) { return "YV12"; case PIXEL_FORMAT_TEXTURE: return "TEXTURE"; - case PIXEL_FORMAT_GPUMEMORYBUFFER: - return "GPUMEMORYBUFFER"; case PIXEL_FORMAT_MAX: break; } diff --git a/media/base/video_capture_types.h b/media/base/video_capture_types.h index 463873f..817e942 100644 --- a/media/base/video_capture_types.h +++ b/media/base/video_capture_types.h @@ -29,7 +29,6 @@ enum VideoPixelFormat { PIXEL_FORMAT_ARGB, PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_TEXTURE, // Capture format as a GL texture. - PIXEL_FORMAT_GPUMEMORYBUFFER, PIXEL_FORMAT_UNKNOWN, // Color format not set. PIXEL_FORMAT_MAX, }; diff --git a/media/video/capture/fake_video_capture_device.cc b/media/video/capture/fake_video_capture_device.cc index a2cd37d..4f3a8bb 100644 --- a/media/video/capture/fake_video_capture_device.cc +++ b/media/video/capture/fake_video_capture_device.cc @@ -101,25 +101,26 @@ void FakeVideoCaptureDevice::AllocateAndStart( 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::StopAndDeAllocate() { 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 @@ void FakeVideoCaptureDevice::CaptureUsingOwnBuffers() { 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) { +void FakeVideoCaptureDevice::CaptureUsingClientBuffers() { DCHECK(thread_checker_.CalledOnValidThread()); - scoped_ptr<VideoCaptureDevice::Client::Buffer> capture_buffer( - client_->ReserveOutputBuffer(pixel_format, capture_format_.frame_size)); + 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) + return; - 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()); - } + 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( diff --git a/media/video/capture/fake_video_capture_device.h b/media/video/capture/fake_video_capture_device.h index f4a19f9..e785ce6 100644 --- a/media/video/capture/fake_video_capture_device.h +++ b/media/video/capture/fake_video_capture_device.h @@ -23,9 +23,8 @@ class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice { public: enum FakeVideoCaptureDeviceType { USING_OWN_BUFFERS, - USING_OWN_BUFFERS_TRIPLANAR, - USING_CLIENT_BUFFERS_I420, - USING_CLIENT_BUFFERS_GPU, + USING_CLIENT_BUFFERS, + USING_GPU_MEMORY_BUFFERS, }; static int FakeCapturePeriodMs() { return kFakeCapturePeriodMs; } @@ -42,7 +41,8 @@ class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice { static const int kFakeCapturePeriodMs = 50; void CaptureUsingOwnBuffers(); - void CaptureUsingClientBuffers(VideoPixelFormat pixel_format); + void CaptureUsingClientBuffers(); + void CaptureUsingGpuMemoryBuffers(); void BeepAndScheduleNextCapture(const base::Closure& next_capture); // |thread_checker_| is used to check that all methods are called in the diff --git a/media/video/capture/fake_video_capture_device_factory.cc b/media/video/capture/fake_video_capture_device_factory.cc index 76de761..aea1909 100644 --- a/media/video/capture/fake_video_capture_device_factory.cc +++ b/media/video/capture/fake_video_capture_device_factory.cc @@ -26,12 +26,10 @@ scoped_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::Create( FakeVideoCaptureDevice::FakeVideoCaptureDeviceType fake_vcd_type; if (option.empty()) fake_vcd_type = FakeVideoCaptureDevice::USING_OWN_BUFFERS; - else if (base:: strcasecmp(option.c_str(), "triplanar") == 0) - fake_vcd_type = FakeVideoCaptureDevice::USING_OWN_BUFFERS_TRIPLANAR; else if (base:: strcasecmp(option.c_str(), "gpu") == 0) - fake_vcd_type = FakeVideoCaptureDevice::USING_CLIENT_BUFFERS_GPU; + fake_vcd_type = FakeVideoCaptureDevice::USING_GPU_MEMORY_BUFFERS; else - fake_vcd_type = FakeVideoCaptureDevice::USING_CLIENT_BUFFERS_I420; + fake_vcd_type = FakeVideoCaptureDevice::USING_CLIENT_BUFFERS; for (int n = 0; n < number_of_devices_; ++n) { std::string possible_id = base::StringPrintf("/dev/video%d", n); @@ -75,8 +73,9 @@ void FakeVideoCaptureDeviceFactory::GetDeviceSupportedFormats( gfx::Size(1920, 1080)}; supported_formats->clear(); for (const auto& size : supported_sizes) { - supported_formats->push_back( - VideoCaptureFormat(size, frame_rate, media::PIXEL_FORMAT_I420)); + supported_formats->push_back(VideoCaptureFormat(size, + frame_rate, + media::PIXEL_FORMAT_I420)); } } diff --git a/media/video/capture/fake_video_capture_device_unittest.cc b/media/video/capture/fake_video_capture_device_unittest.cc index e340ae4..e413c5e 100644 --- a/media/video/capture/fake_video_capture_device_unittest.cc +++ b/media/video/capture/fake_video_capture_device_unittest.cc @@ -24,23 +24,25 @@ namespace { static const FakeVideoCaptureDevice::FakeVideoCaptureDeviceType kCaptureTypes[] = { FakeVideoCaptureDevice::USING_OWN_BUFFERS, - FakeVideoCaptureDevice::USING_OWN_BUFFERS_TRIPLANAR, - FakeVideoCaptureDevice::USING_CLIENT_BUFFERS_I420, - FakeVideoCaptureDevice::USING_CLIENT_BUFFERS_GPU, + FakeVideoCaptureDevice::USING_CLIENT_BUFFERS, + // TODO(mcasas): Add FakeVideoCaptureDevice::USING_GPU_MEMORY_BUFFERS when + // implemented. }; // This class is a Client::Buffer that allocates and frees the requested |size|. class MockBuffer : public VideoCaptureDevice::Client::Buffer { public: MockBuffer(int buffer_id, size_t size) - : id_(buffer_id), size_(size), data_(new uint8[size_]) {} - ~MockBuffer() override { delete[] data_; } + : id_(buffer_id), + size_(size), + data_(new uint8[size_]) {} int id() const override { return id_; } + void* data() const override { return static_cast<void*>(data_); } size_t size() const override { return size_; } - void* data() override { return data_; } - ClientBuffer AsClientBuffer() override { return nullptr; } private: + ~MockBuffer() override { delete[] data_; } + const int id_; const size_t size_; uint8* const data_; @@ -48,12 +50,22 @@ class MockBuffer : public VideoCaptureDevice::Client::Buffer { class MockClient : public VideoCaptureDevice::Client { public: + MOCK_METHOD9(OnIncomingCapturedYuvData, + void (const uint8* y_data, + const uint8* u_data, + const uint8* v_data, + size_t y_stride, + size_t u_stride, + size_t v_stride, + const VideoCaptureFormat& frame_format, + int clockwise_rotation, + const base::TimeTicks& timestamp)); MOCK_METHOD1(OnError, void(const std::string& reason)); explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) : frame_cb_(frame_cb) {} - // Client virtual methods for capturing using Device Buffers. + // Client virtual method for capturing using Device Buffers. void OnIncomingCapturedData(const uint8* data, int length, const VideoCaptureFormat& format, @@ -61,35 +73,16 @@ class MockClient : public VideoCaptureDevice::Client { const base::TimeTicks& timestamp) { frame_cb_.Run(format); } - void OnIncomingCapturedYuvData(const uint8* y_data, - const uint8* u_data, - const uint8* v_data, - size_t y_stride, - size_t u_stride, - size_t v_stride, - const VideoCaptureFormat& frame_format, - int clockwise_rotation, - const base::TimeTicks& timestamp) { - frame_cb_.Run(frame_format); - } // Virtual methods for capturing using Client's Buffers. - scoped_ptr<Buffer> ReserveOutputBuffer(media::VideoPixelFormat format, - const gfx::Size& dimensions) { - EXPECT_TRUE(format == PIXEL_FORMAT_I420 || - format == PIXEL_FORMAT_GPUMEMORYBUFFER); + scoped_refptr<Buffer> ReserveOutputBuffer(media::VideoPixelFormat format, + const gfx::Size& dimensions) { + EXPECT_EQ(format, PIXEL_FORMAT_I420); EXPECT_GT(dimensions.GetArea(), 0); - const VideoCaptureFormat frame_format(dimensions, 0.0, format); - return make_scoped_ptr( - new MockBuffer(0, frame_format.ImageAllocationSize())); - } - void OnIncomingCapturedBuffer(scoped_ptr<Buffer> buffer, - const VideoCaptureFormat& frame_format, - const base::TimeTicks& timestamp) { - frame_cb_.Run(frame_format); + return make_scoped_refptr(new MockBuffer(0, dimensions.GetArea() * 3 / 2)); } void OnIncomingCapturedVideoFrame( - scoped_ptr<Buffer> buffer, + const scoped_refptr<Buffer>& buffer, const scoped_refptr<media::VideoFrame>& frame, const base::TimeTicks& timestamp) { VideoCaptureFormat format(frame->natural_size(), 30.0, PIXEL_FORMAT_I420); @@ -132,6 +125,8 @@ class FakeVideoCaptureDeviceTest } void SetUp() override { + EXPECT_CALL(*client_, OnIncomingCapturedYuvData(_,_,_,_,_,_,_,_,_)) + .Times(0); EXPECT_CALL(*client_, OnError(_)).Times(0); } diff --git a/media/video/capture/video_capture_device.cc b/media/video/capture/video_capture_device.cc index 44442c4..1eb205a 100644 --- a/media/video/capture/video_capture_device.cc +++ b/media/video/capture/video_capture_device.cc @@ -128,8 +128,6 @@ const char* VideoCaptureDevice::Name::GetCaptureApiTypeString() const { } #endif -VideoCaptureDevice::Client::Buffer::~Buffer() {} - VideoCaptureDevice::~VideoCaptureDevice() {} int VideoCaptureDevice::GetPowerLineFrequencyForLocation() const { diff --git a/media/video/capture/video_capture_device.h b/media/video/capture/video_capture_device.h index d3dfe72..e5e42f8 100644 --- a/media/video/capture/video_capture_device.h +++ b/media/video/capture/video_capture_device.h @@ -23,7 +23,6 @@ #include "media/base/media_export.h" #include "media/base/video_capture_types.h" #include "media/base/video_frame.h" -#include "ui/gfx/gpu_memory_buffer.h" namespace media { @@ -196,13 +195,15 @@ class MEDIA_EXPORT VideoCaptureDevice { class MEDIA_EXPORT Client { public: // Memory buffer returned by Client::ReserveOutputBuffer(). - class MEDIA_EXPORT Buffer { + class Buffer : public base::RefCountedThreadSafe<Buffer> { public: - virtual ~Buffer() = 0; virtual int id() const = 0; + virtual void* data() const = 0; virtual size_t size() const = 0; - virtual void* data() = 0; - virtual ClientBuffer AsClientBuffer() = 0; + + protected: + friend class base::RefCountedThreadSafe<Buffer>; + virtual ~Buffer() {} }; virtual ~Client() {} @@ -240,25 +241,20 @@ class MEDIA_EXPORT VideoCaptureDevice { // backing, but functions as a reservation for external input for the // purposes of buffer throttling. // - // The output buffer stays reserved and mapped for use until the Buffer - // object is destroyed or returned. - virtual scoped_ptr<Buffer> ReserveOutputBuffer( + // The output buffer stays reserved for use until the Buffer object is + // destroyed. + virtual scoped_refptr<Buffer> ReserveOutputBuffer( media::VideoPixelFormat format, const gfx::Size& dimensions) = 0; - // Captured new video data, held in |frame| or |buffer|, respectively for - // OnIncomingCapturedVideoFrame() and OnIncomingCapturedBuffer(). + // Captured a new video frame, held in |frame|. // - // In both cases, as the frame is backed by a reservation returned by + // As the frame is backed by a reservation returned by // ReserveOutputBuffer(), delivery is guaranteed and will require no // additional copies in the browser process. - virtual void OnIncomingCapturedBuffer( - scoped_ptr<Buffer> buffer, - const VideoCaptureFormat& frame_format, - const base::TimeTicks& timestamp) = 0; virtual void OnIncomingCapturedVideoFrame( - scoped_ptr<Buffer> buffer, - const scoped_refptr<VideoFrame>& frame, + const scoped_refptr<Buffer>& buffer, + const scoped_refptr<media::VideoFrame>& frame, const base::TimeTicks& timestamp) = 0; // An error has occurred that cannot be handled and VideoCaptureDevice must diff --git a/media/video/capture/video_capture_device_unittest.cc b/media/video/capture/video_capture_device_unittest.cc index 961957f..a01fbab 100644 --- a/media/video/capture/video_capture_device_unittest.cc +++ b/media/video/capture/video_capture_device_unittest.cc @@ -64,19 +64,23 @@ namespace { class MockClient : public VideoCaptureDevice::Client { public: + MOCK_METHOD2(ReserveOutputBuffer, + scoped_refptr<Buffer>(media::VideoPixelFormat format, + const gfx::Size& dimensions)); MOCK_METHOD9(OnIncomingCapturedYuvData, - void(const uint8* y_data, - const uint8* u_data, - const uint8* v_data, - size_t y_stride, - size_t u_stride, - size_t v_stride, - const VideoCaptureFormat& frame_format, - int clockwise_rotation, + void (const uint8* y_data, + const uint8* u_data, + const uint8* v_data, + size_t y_stride, + size_t u_stride, + size_t v_stride, + const VideoCaptureFormat& frame_format, + int clockwise_rotation, + const base::TimeTicks& timestamp)); + MOCK_METHOD3(OnIncomingCapturedVideoFrame, + void(const scoped_refptr<Buffer>& buffer, + const scoped_refptr<VideoFrame>& frame, const base::TimeTicks& timestamp)); - MOCK_METHOD0(DoReserveOutputBuffer, void(void)); - MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); - MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); MOCK_METHOD1(OnError, void(const std::string& reason)); explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) @@ -92,23 +96,6 @@ class MockClient : public VideoCaptureDevice::Client { main_thread_->PostTask(FROM_HERE, base::Bind(frame_cb_, format)); } - // Trampoline methods to workaround GMOCK problems with scoped_ptr<>. - scoped_ptr<Buffer> ReserveOutputBuffer(VideoPixelFormat format, - const gfx::Size& dimensions) override { - DoReserveOutputBuffer(); - return scoped_ptr<Buffer>(); - } - void OnIncomingCapturedBuffer(scoped_ptr<Buffer> buffer, - const VideoCaptureFormat& frame_format, - const base::TimeTicks& timestamp) override { - DoOnIncomingCapturedBuffer(); - } - void OnIncomingCapturedVideoFrame(scoped_ptr<Buffer> buffer, - const scoped_refptr<VideoFrame>& frame, - const base::TimeTicks& timestamp) override { - DoOnIncomingCapturedVideoFrame(); - } - private: scoped_refptr<base::SingleThreadTaskRunner> main_thread_; base::Callback<void(const VideoCaptureFormat&)> frame_cb_; @@ -152,9 +139,8 @@ class VideoCaptureDeviceTest : public testing::Test { #endif EXPECT_CALL(*client_, OnIncomingCapturedYuvData(_,_,_,_,_,_,_,_,_)) .Times(0); - EXPECT_CALL(*client_, DoReserveOutputBuffer()).Times(0); - EXPECT_CALL(*client_, DoOnIncomingCapturedBuffer()).Times(0); - EXPECT_CALL(*client_, DoOnIncomingCapturedVideoFrame()).Times(0); + EXPECT_CALL(*client_, ReserveOutputBuffer(_,_)).Times(0); + EXPECT_CALL(*client_, OnIncomingCapturedVideoFrame(_,_,_)).Times(0); } void ResetWithNewClient() { |