diff options
author | mcasas@chromium.org <mcasas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-23 16:29:06 +0000 |
---|---|---|
committer | mcasas@chromium.org <mcasas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-23 16:29:06 +0000 |
commit | 1c8c38904d8f881a493293f06c08f74f4efaa3a3 (patch) | |
tree | fa8ef8181e6d6cedf59d54c433d7a0a6d9ee8465 | |
parent | b5d8fb9853f92fc48c2e6e6af04f543669507a36 (diff) | |
download | chromium_src-1c8c38904d8f881a493293f06c08f74f4efaa3a3.zip chromium_src-1c8c38904d8f881a493293f06c08f74f4efaa3a3.tar.gz chromium_src-1c8c38904d8f881a493293f06c08f74f4efaa3a3.tar.bz2 |
Wire VideoCaptureManager device capture formats to the renderer side.
The intended sequence of method calls, from the renderer side
VideoCaptureImpl to browser side VideoCaptureManager and back
follows this draft:
-VideoCaptureImpl::GetDeviceSupportedFormats()
---VideoCaptureMessageFilter::Send()
----VideoCaptureHost::OnGetDeviceSupportedFormats()
----Send(new VideoCaptureMsg_DeviceSupportedFormatsEnumerated...)
---VideoCaptureMessageFilter::OnDeviceSupportedFormatsEnumerated(<list>)
--VideoCaptureImpl::OnDeviceSupportedFormatsEnumerated(<list>)
The last call happens via callback passed at VCI:GetDeviceSupportedFormats().
call time.
UT Added where applicable.
BUG=309554
Review URL: https://codereview.chromium.org/100053004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@246609 0039d316-1c4b-4281-b951-d872f2087c98
17 files changed, 208 insertions, 2 deletions
diff --git a/content/browser/renderer_host/media/video_capture_host.cc b/content/browser/renderer_host/media/video_capture_host.cc index 292ecb7..4651f01 100644 --- a/content/browser/renderer_host/media/video_capture_host.cc +++ b/content/browser/renderer_host/media/video_capture_host.cc @@ -158,6 +158,8 @@ bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message, IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Pause, OnPauseCapture) IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Stop, OnStopCapture) IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady, OnReceiveEmptyBuffer) + IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceSupportedFormats, + OnGetDeviceSupportedFormats) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP_EX() @@ -255,6 +257,24 @@ void VideoCaptureHost::OnReceiveEmptyBuffer(int device_id, int buffer_id) { } } +void VideoCaptureHost::OnGetDeviceSupportedFormats( + int device_id, + media::VideoCaptureSessionId capture_session_id) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + DVLOG(1) << "VideoCaptureHost::OnGetDeviceFormats, capture_session_id " + << capture_session_id; + media::VideoCaptureFormats device_supported_formats; + if (!media_stream_manager_->video_capture_manager() + ->GetDeviceSupportedFormats(capture_session_id, + &device_supported_formats)) { + DLOG(WARNING) + << "Could not retrieve device supported formats for device_id=" + << device_id << " capture_session_id=" << capture_session_id; + } + Send(new VideoCaptureMsg_DeviceSupportedFormatsEnumerated( + device_id, device_supported_formats)); +} + void VideoCaptureHost::DeleteVideoCaptureControllerOnIOThread( const VideoCaptureControllerID& controller_id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); diff --git a/content/browser/renderer_host/media/video_capture_host.h b/content/browser/renderer_host/media/video_capture_host.h index bd1db0a..ad428e4 100644 --- a/content/browser/renderer_host/media/video_capture_host.h +++ b/content/browser/renderer_host/media/video_capture_host.h @@ -122,6 +122,12 @@ class CONTENT_EXPORT VideoCaptureHost // referenced by |device_id|. void OnReceiveEmptyBuffer(int device_id, int buffer_id); + // IPC message: Get supported formats referenced by |capture_session_id|. + // |device_id| is needed for message back-routing purposes. + void OnGetDeviceSupportedFormats( + int device_id, + media::VideoCaptureSessionId capture_session_id); + // Send a newly created buffer to the VideoCaptureMessageFilter. void DoSendNewBufferOnIOThread( const VideoCaptureControllerID& controller_id, diff --git a/content/browser/renderer_host/media/video_capture_manager.cc b/content/browser/renderer_host/media/video_capture_manager.cc index 307a1b1..ace6565 100644 --- a/content/browser/renderer_host/media/video_capture_manager.cc +++ b/content/browser/renderer_host/media/video_capture_manager.cc @@ -289,7 +289,7 @@ bool VideoCaptureManager::GetDeviceSupportedFormats( media::VideoCaptureSessionId capture_session_id, media::VideoCaptureFormats* supported_formats) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - supported_formats->clear(); + DCHECK(supported_formats->empty()); std::map<media::VideoCaptureSessionId, MediaStreamDevice>::iterator it = sessions_.find(capture_session_id); diff --git a/content/browser/renderer_host/media/video_capture_manager_unittest.cc b/content/browser/renderer_host/media/video_capture_manager_unittest.cc index 86d9e77..b9a329e 100644 --- a/content/browser/renderer_host/media/video_capture_manager_unittest.cc +++ b/content/browser/renderer_host/media/video_capture_manager_unittest.cc @@ -239,6 +239,7 @@ TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { // Before enumerating the devices, requesting formats should return false. int video_session_id = 0; media::VideoCaptureFormats supported_formats; + supported_formats.clear(); EXPECT_FALSE( vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); @@ -254,6 +255,7 @@ TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { message_loop_->RunUntilIdle(); // Right after opening the device, we should see all its formats. + supported_formats.clear(); EXPECT_TRUE( vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); ASSERT_GT(supported_formats.size(), 1u); @@ -267,6 +269,7 @@ TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { VideoCaptureControllerID client_id = StartClient(video_session_id, true); message_loop_->RunUntilIdle(); // After StartClient(), device's supported formats should stay the same. + supported_formats.clear(); EXPECT_TRUE( vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); ASSERT_GE(supported_formats.size(), 2u); @@ -279,6 +282,7 @@ TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1); StopClient(client_id); + supported_formats.clear(); EXPECT_TRUE( vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); ASSERT_GE(supported_formats.size(), 2u); diff --git a/content/common/media/video_capture_messages.h b/content/common/media/video_capture_messages.h index a1e913f..a7745a6 100644 --- a/content/common/media/video_capture_messages.h +++ b/content/common/media/video_capture_messages.h @@ -49,6 +49,12 @@ IPC_MESSAGE_CONTROL4(VideoCaptureMsg_BufferReady, base::TimeTicks /* timestamp */, media::VideoCaptureFormat /* resolution */) +// Notify the renderer about a device's supported formats; this is a response +// to a VideoCaptureHostMsg_GetDeviceSupportedFormats request. +IPC_MESSAGE_CONTROL2(VideoCaptureMsg_DeviceSupportedFormatsEnumerated, + int /* device_id */, + media::VideoCaptureFormats /* supported_formats */) + // Start a video capture as |device_id|, a new id picked by the renderer // process. The session to be started is determined by |params.session_id|. IPC_MESSAGE_CONTROL3(VideoCaptureHostMsg_Start, @@ -69,3 +75,8 @@ IPC_MESSAGE_CONTROL1(VideoCaptureHostMsg_Stop, IPC_MESSAGE_CONTROL2(VideoCaptureHostMsg_BufferReady, int /* device_id */, int /* buffer_id */) + +// Get the formats supported by device referenced by |capture_session_id|. +IPC_MESSAGE_CONTROL2(VideoCaptureHostMsg_GetDeviceSupportedFormats, + int /* device_id */, + media::VideoCaptureSessionId /* session_id */) diff --git a/content/renderer/media/video_capture_impl.cc b/content/renderer/media/video_capture_impl.cc index b7d195d..38be11f 100644 --- a/content/renderer/media/video_capture_impl.cc +++ b/content/renderer/media/video_capture_impl.cc @@ -91,6 +91,14 @@ void VideoCaptureImpl::StopCapture( base::Unretained(this), handler)); } +void VideoCaptureImpl::GetDeviceSupportedFormats( + const DeviceFormatsCallback& callback) { + DCHECK(!callback.is_null()); + io_message_loop_proxy_->PostTask(FROM_HERE, + base::Bind(&VideoCaptureImpl::GetDeviceSupportedFormatsOnIOThread, + base::Unretained(this), media::BindToCurrentLoop(callback))); +} + void VideoCaptureImpl::InitOnIOThread() { DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); message_filter_->AddDelegate(this); @@ -172,6 +180,15 @@ void VideoCaptureImpl::StopCaptureOnIOThread( } } +void VideoCaptureImpl::GetDeviceSupportedFormatsOnIOThread( + const DeviceFormatsCallback& callback) { + DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); + device_formats_callback_queue_.push_back(callback); + if (device_formats_callback_queue_.size() == 1) + Send(new VideoCaptureHostMsg_GetDeviceSupportedFormats(device_id_, + session_id_)); +} + void VideoCaptureImpl::OnBufferCreated( base::SharedMemoryHandle handle, int length, int buffer_id) { @@ -301,6 +318,15 @@ void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { } } +void VideoCaptureImpl::OnDeviceSupportedFormatsEnumerated( + const media::VideoCaptureFormats& supported_formats) { + DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); + for (size_t i = 0; i < device_formats_callback_queue_.size(); ++i) + device_formats_callback_queue_[i].Run(supported_formats); + device_formats_callback_queue_.clear(); + +} + void VideoCaptureImpl::OnDelegateAdded(int32 device_id) { DVLOG(1) << "OnDelegateAdded: device_id " << device_id; DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); diff --git a/content/renderer/media/video_capture_impl.h b/content/renderer/media/video_capture_impl.h index 0e8fea7..e70d846 100644 --- a/content/renderer/media/video_capture_impl.h +++ b/content/renderer/media/video_capture_impl.h @@ -67,6 +67,8 @@ class CONTENT_EXPORT VideoCaptureImpl virtual void StopCapture(media::VideoCapture::EventHandler* handler) OVERRIDE; virtual bool CaptureStarted() OVERRIDE; virtual int CaptureFrameRate() OVERRIDE; + virtual void GetDeviceSupportedFormats( + const DeviceFormatsCallback& callback) OVERRIDE; media::VideoCaptureSessionId session_id() const { return session_id_; } @@ -85,6 +87,8 @@ class CONTENT_EXPORT VideoCaptureImpl media::VideoCapture::EventHandler* handler, const media::VideoCaptureParams& params); void StopCaptureOnIOThread(media::VideoCapture::EventHandler* handler); + void GetDeviceSupportedFormatsOnIOThread( + const DeviceFormatsCallback& callback); // VideoCaptureMessageFilter::Delegate interface. virtual void OnBufferCreated(base::SharedMemoryHandle handle, @@ -96,8 +100,13 @@ class CONTENT_EXPORT VideoCaptureImpl base::TimeTicks timestamp, const media::VideoCaptureFormat& format) OVERRIDE; virtual void OnStateChanged(VideoCaptureState state) OVERRIDE; + virtual void OnDeviceSupportedFormatsEnumerated( + const media::VideoCaptureFormats& supported_formats) OVERRIDE; virtual void OnDelegateAdded(int32 device_id) OVERRIDE; + void OnDeviceFormatsEnumeratedOnMainThread( + const media::VideoCaptureFormats& supported_formats); + // Sends an IPC message to browser process when all clients are done with the // buffer. void OnClientBufferFinished( @@ -107,6 +116,7 @@ class CONTENT_EXPORT VideoCaptureImpl void StopDevice(); void RestartCapture(); void StartCaptureInternal(); + virtual void Send(IPC::Message* message); // Helpers. @@ -118,6 +128,10 @@ class CONTENT_EXPORT VideoCaptureImpl int device_id_; const int session_id_; + // Vector of callbacks to be notified of device format enumerations, used only + // on IO Thread. + std::vector<DeviceFormatsCallback> device_formats_callback_queue_; + // Buffers available for sending to the client. typedef std::map<int32, scoped_refptr<ClientBuffer> > ClientBufferMap; ClientBufferMap client_buffers_; diff --git a/content/renderer/media/video_capture_impl_manager.cc b/content/renderer/media/video_capture_impl_manager.cc index 2b41cc3..4d27c2a 100644 --- a/content/renderer/media/video_capture_impl_manager.cc +++ b/content/renderer/media/video_capture_impl_manager.cc @@ -40,6 +40,11 @@ int VideoCaptureHandle::CaptureFrameRate() { return impl_->CaptureFrameRate(); } +void VideoCaptureHandle::GetDeviceSupportedFormats( + const DeviceFormatsCallback& callback) { + impl_->GetDeviceSupportedFormats(callback); +} + VideoCaptureImplManager::VideoCaptureImplManager() : filter_(new VideoCaptureMessageFilter()), weak_factory_(this) { diff --git a/content/renderer/media/video_capture_impl_manager.h b/content/renderer/media/video_capture_impl_manager.h index 24d3176..1932620 100644 --- a/content/renderer/media/video_capture_impl_manager.h +++ b/content/renderer/media/video_capture_impl_manager.h @@ -51,6 +51,8 @@ class CONTENT_EXPORT VideoCaptureHandle : media::VideoCapture { virtual void StopCapture(EventHandler* handler) OVERRIDE; virtual bool CaptureStarted() OVERRIDE; virtual int CaptureFrameRate() OVERRIDE; + virtual void GetDeviceSupportedFormats( + const DeviceFormatsCallback& callback) OVERRIDE; private: friend class VideoCaptureImplManager; diff --git a/content/renderer/media/video_capture_impl_unittest.cc b/content/renderer/media/video_capture_impl_unittest.cc index 2c9c75a..f2297fc 100644 --- a/content/renderer/media/video_capture_impl_unittest.cc +++ b/content/renderer/media/video_capture_impl_unittest.cc @@ -14,6 +14,8 @@ using ::testing::_; using ::testing::AtLeast; +using ::testing::InvokeWithoutArgs; +using ::testing::Return; using media::MockVideoCaptureEventHandler; namespace content { @@ -38,7 +40,8 @@ class VideoCaptureImplTest : public ::testing::Test { public: MockVideoCaptureImpl(const media::VideoCaptureSessionId id, VideoCaptureMessageFilter* filter) - : VideoCaptureImpl(id, filter) {} + : VideoCaptureImpl(id, filter) { + } virtual ~MockVideoCaptureImpl() {} // Override Send() to mimic device to send events. @@ -54,6 +57,8 @@ class VideoCaptureImplTest : public ::testing::Test { IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Stop, DeviceStopCapture) IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady, DeviceReceiveEmptyBuffer) + IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceSupportedFormats, + DeviceGetSupportedFormats) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() EXPECT_TRUE(handled); @@ -73,6 +78,14 @@ class VideoCaptureImplTest : public ::testing::Test { } void DeviceReceiveEmptyBuffer(int device_id, int buffer_id) {} + + void DeviceGetSupportedFormats(int device_id, + media::VideoCaptureSessionId session_id) { + // When the mock message filter receives a request for the device + // supported formats, replies immediately with an empty format list. + OnDeviceSupportedFormatsEnumerated( + media::VideoCaptureFormats()); + } }; VideoCaptureImplTest() { @@ -198,4 +211,49 @@ TEST_F(VideoCaptureImplTest, SmallAndLarge) { run_loop_.Run(); } +// Check that a request to GetDeviceSupportedFormats() ends up eventually in the +// provided callback. +TEST_F(VideoCaptureImplTest, GetDeviceFormats) { + scoped_ptr<MockVideoCaptureEventHandler> client( + new MockVideoCaptureEventHandler); + + EXPECT_CALL(*client, OnDeviceSupportedFormatsEnumerated(_)); + + const base::Callback<void(const media::VideoCaptureFormats&)> + callback = base::Bind( + &MockVideoCaptureEventHandler::OnDeviceSupportedFormatsEnumerated, + base::Unretained(client.get())); + video_capture_impl_->GetDeviceSupportedFormats(callback); + video_capture_impl_->DeInit( + media::BindToCurrentLoop(run_loop_.QuitClosure())); + run_loop_.Run(); +} + +// Check that two requests to GetDeviceSupportedFormats() end up eventually +// calling the provided callbacks. +TEST_F(VideoCaptureImplTest, TwoClientsGetDeviceFormats) { + scoped_ptr<MockVideoCaptureEventHandler> client1( + new MockVideoCaptureEventHandler); + scoped_ptr<MockVideoCaptureEventHandler> client2( + new MockVideoCaptureEventHandler); + + EXPECT_CALL(*client1, OnDeviceSupportedFormatsEnumerated(_)); + EXPECT_CALL(*client2, OnDeviceSupportedFormatsEnumerated(_)); + + const base::Callback<void(const media::VideoCaptureFormats&)> + callback1 = base::Bind( + &MockVideoCaptureEventHandler::OnDeviceSupportedFormatsEnumerated, + base::Unretained(client1.get())); + const base::Callback<void(const media::VideoCaptureFormats&)> + callback2 = base::Bind( + &MockVideoCaptureEventHandler::OnDeviceSupportedFormatsEnumerated, + base::Unretained(client2.get())); + + video_capture_impl_->GetDeviceSupportedFormats(callback1); + video_capture_impl_->GetDeviceSupportedFormats(callback2); + video_capture_impl_->DeInit( + media::BindToCurrentLoop(run_loop_.QuitClosure())); + run_loop_.Run(); +} + } // namespace content diff --git a/content/renderer/media/video_capture_message_filter.cc b/content/renderer/media/video_capture_message_filter.cc index 98b2e4e..94075ff 100644 --- a/content/renderer/media/video_capture_message_filter.cc +++ b/content/renderer/media/video_capture_message_filter.cc @@ -61,6 +61,8 @@ bool VideoCaptureMessageFilter::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(VideoCaptureMsg_StateChanged, OnDeviceStateChanged) IPC_MESSAGE_HANDLER(VideoCaptureMsg_NewBuffer, OnBufferCreated) IPC_MESSAGE_HANDLER(VideoCaptureMsg_FreeBuffer, OnBufferDestroyed) + IPC_MESSAGE_HANDLER(VideoCaptureMsg_DeviceSupportedFormatsEnumerated, + OnDeviceSupportedFormatsEnumerated) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -158,4 +160,15 @@ void VideoCaptureMessageFilter::OnDeviceStateChanged( delegate->OnStateChanged(state); } +void VideoCaptureMessageFilter::OnDeviceSupportedFormatsEnumerated( + int device_id, + const media::VideoCaptureFormats& supported_formats) { + Delegate* delegate = find_delegate(device_id); + if (!delegate) { + DLOG(WARNING) << "OnDeviceFormatsEnumerated: unknown device"; + return; + } + delegate->OnDeviceSupportedFormatsEnumerated(supported_formats); +} + } // namespace content diff --git a/content/renderer/media/video_capture_message_filter.h b/content/renderer/media/video_capture_message_filter.h index 2c71efa..ed03f8c 100644 --- a/content/renderer/media/video_capture_message_filter.h +++ b/content/renderer/media/video_capture_message_filter.h @@ -41,6 +41,10 @@ class CONTENT_EXPORT VideoCaptureMessageFilter // process. virtual void OnStateChanged(VideoCaptureState state) = 0; + // Called upon reception of device's supported formats back from browser. + virtual void OnDeviceSupportedFormatsEnumerated( + const media::VideoCaptureFormats& supported_formats) = 0; + // Called when the delegate has been added to filter's delegate list. // |device_id| is the device id for the delegate. virtual void OnDelegateAdded(int32 device_id) = 0; @@ -91,6 +95,11 @@ class CONTENT_EXPORT VideoCaptureMessageFilter // State of browser process' video capture device has changed. void OnDeviceStateChanged(int device_id, VideoCaptureState state); + // Receive a device's supported formats back from browser process. + void OnDeviceSupportedFormatsEnumerated( + int device_id, + const media::VideoCaptureFormats& supported_formats); + // Finds the delegate associated with |device_id|, NULL if not found. Delegate* find_delegate(int device_id) const; diff --git a/content/renderer/media/video_capture_message_filter_unittest.cc b/content/renderer/media/video_capture_message_filter_unittest.cc index 985aebe..22f22c3 100644 --- a/content/renderer/media/video_capture_message_filter_unittest.cc +++ b/content/renderer/media/video_capture_message_filter_unittest.cc @@ -34,6 +34,8 @@ class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate { base::TimeTicks timestamp, const media::VideoCaptureFormat& format)); MOCK_METHOD1(OnStateChanged, void(VideoCaptureState state)); + MOCK_METHOD1(OnDeviceSupportedFormatsEnumerated, + void(const media::VideoCaptureFormats& formats)); virtual void OnDelegateAdded(int32 device_id) OVERRIDE { ASSERT_TRUE(device_id != 0); @@ -141,4 +143,21 @@ TEST(VideoCaptureMessageFilterTest, Delegates) { VIDEO_CAPTURE_STATE_ENDED)); } +TEST(VideoCaptureMessageFilterTest, GetSomeDeviceCapabilities) { + scoped_refptr<VideoCaptureMessageFilter> filter( + new VideoCaptureMessageFilter()); + + IPC::TestSink channel; + filter->OnFilterAdded(&channel); + MockVideoCaptureDelegate delegate; + filter->AddDelegate(&delegate); + ASSERT_EQ(1, delegate.device_id()); + + // VideoCaptureMsg_OnDeviceCapabilitiesEnumerated + EXPECT_CALL(delegate, OnDeviceSupportedFormatsEnumerated(_)); + media::VideoCaptureFormats supported_formats; + filter->OnMessageReceived(VideoCaptureMsg_DeviceSupportedFormatsEnumerated( + delegate.device_id(), supported_formats)); +} + } // namespace content diff --git a/content/renderer/pepper/pepper_platform_video_capture.cc b/content/renderer/pepper/pepper_platform_video_capture.cc index 673fb72..fe12279 100644 --- a/content/renderer/pepper/pepper_platform_video_capture.cc +++ b/content/renderer/pepper/pepper_platform_video_capture.cc @@ -78,6 +78,11 @@ int PepperPlatformVideoCapture::CaptureFrameRate() { return handler_proxy_->state().frame_rate; } +void PepperPlatformVideoCapture::GetDeviceSupportedFormats( + const DeviceFormatsCallback& callback) { + NOTREACHED(); +} + void PepperPlatformVideoCapture::DetachEventHandler() { handler_ = NULL; StopCapture(NULL); diff --git a/content/renderer/pepper/pepper_platform_video_capture.h b/content/renderer/pepper/pepper_platform_video_capture.h index a0760ba..60d3059 100644 --- a/content/renderer/pepper/pepper_platform_video_capture.h +++ b/content/renderer/pepper/pepper_platform_video_capture.h @@ -47,6 +47,8 @@ class PepperPlatformVideoCapture virtual void StopCapture(media::VideoCapture::EventHandler* handler) OVERRIDE; virtual bool CaptureStarted() OVERRIDE; virtual int CaptureFrameRate() OVERRIDE; + virtual void GetDeviceSupportedFormats( + const DeviceFormatsCallback& callback) OVERRIDE; // media::VideoCapture::EventHandler implementation virtual void OnStarted(VideoCapture* capture) OVERRIDE; diff --git a/media/video/capture/mock_video_capture_event_handler.h b/media/video/capture/mock_video_capture_event_handler.h index ff5cb71..87c6c40 100644 --- a/media/video/capture/mock_video_capture_event_handler.h +++ b/media/video/capture/mock_video_capture_event_handler.h @@ -29,6 +29,8 @@ class MockVideoCaptureEventHandler : public VideoCapture::EventHandler { MOCK_METHOD2(OnDeviceInfoReceived, void(VideoCapture* capture, const VideoCaptureFormat& device_info)); + MOCK_METHOD1(OnDeviceSupportedFormatsEnumerated, + void(const media::VideoCaptureFormats& supported_formats)); }; } // namespace media diff --git a/media/video/capture/video_capture.h b/media/video/capture/video_capture.h index 9a0e943..0a03b9f 100644 --- a/media/video/capture/video_capture.h +++ b/media/video/capture/video_capture.h @@ -8,6 +8,7 @@ #ifndef MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_H_ #define MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_H_ +#include "base/callback.h" #include "base/memory/ref_counted.h" #include "base/time/time.h" #include "media/base/media_export.h" @@ -49,6 +50,9 @@ class MEDIA_EXPORT VideoCapture { virtual ~EventHandler() {} }; + typedef base::Callback<void(const media::VideoCaptureFormats&)> + DeviceFormatsCallback; + VideoCapture() {} // Request video capture to start capturing with |params|. @@ -64,6 +68,12 @@ class MEDIA_EXPORT VideoCapture { virtual bool CaptureStarted() = 0; virtual int CaptureFrameRate() = 0; + // Request the device capture supported formats. This method can be called + // before startCapture() and/or after stopCapture() so a |callback| is used + // instead of replying via EventHandler. + virtual void GetDeviceSupportedFormats( + const DeviceFormatsCallback& callback) = 0; + protected: virtual ~VideoCapture() {} |