diff options
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() { |