Commit ae70b1aa authored by wjia@google.com's avatar wjia@google.com

Add VideoCaptureImpl and VideoCaptureImplManager

BUG=none
TEST=try bots
Review URL: http://codereview.chromium.org/6902166

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86758 0039d316-1c4b-4281-b951-d872f2087c98
parent 38eacdfe
...@@ -1959,6 +1959,7 @@ ...@@ -1959,6 +1959,7 @@
'../content/renderer/active_notification_tracker_unittest.cc', '../content/renderer/active_notification_tracker_unittest.cc',
'../content/renderer/audio_message_filter_unittest.cc', '../content/renderer/audio_message_filter_unittest.cc',
'../content/renderer/media/audio_renderer_impl_unittest.cc', '../content/renderer/media/audio_renderer_impl_unittest.cc',
'../content/renderer/media/video_capture_impl_unittest.cc',
'../content/renderer/paint_aggregator_unittest.cc', '../content/renderer/paint_aggregator_unittest.cc',
'../content/renderer/video_capture_message_filter_unittest.cc', '../content/renderer/video_capture_message_filter_unittest.cc',
'../testing/gtest_mac_unittest.mm', '../testing/gtest_mac_unittest.mm',
......
...@@ -70,6 +70,10 @@ ...@@ -70,6 +70,10 @@
'renderer/media/gles2_video_decode_context.h', 'renderer/media/gles2_video_decode_context.h',
'renderer/media/ipc_video_decoder.cc', 'renderer/media/ipc_video_decoder.cc',
'renderer/media/ipc_video_decoder.h', 'renderer/media/ipc_video_decoder.h',
'renderer/media/video_capture_impl.cc',
'renderer/media/video_capture_impl.h',
'renderer/media/video_capture_impl_manager.cc',
'renderer/media/video_capture_impl_manager.h',
'renderer/navigation_state.cc', 'renderer/navigation_state.cc',
'renderer/navigation_state.h', 'renderer/navigation_state.h',
'renderer/notification_provider.cc', 'renderer/notification_provider.cc',
......
This diff is collapsed.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// VideoCaptureImpl represents a capture device in renderer process. It provides
// interfaces for clients to Start/Stop capture. It also communicates to clients
// when buffer is ready, state of capture device is changed.
#ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_
#define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_
#include <list>
#include <map>
#include "content/renderer/video_capture_message_filter.h"
#include "media/base/callback.h"
#include "media/video/capture/video_capture.h"
#include "ui/gfx/surface/transport_dib.h"
namespace base {
class MessageLoopProxy;
}
class VideoCaptureImpl
: public media::VideoCapture,
public VideoCaptureMessageFilter::Delegate {
public:
// media::VideoCapture interface.
virtual void StartCapture(media::VideoCapture::EventHandler* handler,
const VideoCaptureCapability& capability);
virtual void StopCapture(media::VideoCapture::EventHandler* handler);
virtual bool CaptureStarted();
virtual int CaptureWidth();
virtual int CaptureHeight();
virtual int CaptureFrameRate();
// VideoCaptureMessageFilter::Delegate interface.
virtual void OnBufferReceived(TransportDIB::Handle handle,
base::Time timestamp);
virtual void OnStateChanged(const media::VideoCapture::State& state);
virtual void OnDeviceInfoReceived(
const media::VideoCaptureParams& device_info);
virtual void OnDelegateAdded(int32 device_id);
bool pending_start() {
return (new_width_ > 0 && new_height_ > 0);
}
private:
friend class VideoCaptureImplManager;
friend class VideoCaptureImplTest;
enum State {
kStarted,
kStopping,
kStopped
};
struct DIBBuffer {
public:
DIBBuffer(TransportDIB* d, media::VideoCapture::VideoFrameBuffer* ptr);
~DIBBuffer();
TransportDIB* dib;
scoped_refptr<media::VideoCapture::VideoFrameBuffer> mapped_memory;
};
VideoCaptureImpl(media::VideoCaptureSessionId id,
scoped_refptr<base::MessageLoopProxy> ml_proxy,
VideoCaptureMessageFilter* filter);
virtual ~VideoCaptureImpl();
void Init();
void DeInit(Task* task);
void StopDevice();
void RestartCapture();
void StartCaptureInternal();
void AddDelegateOnIOThread();
void RemoveDelegateOnIOThread(Task* task);
scoped_refptr<VideoCaptureMessageFilter> message_filter_;
media::VideoCaptureSessionId session_id_;
scoped_refptr<base::MessageLoopProxy> ml_proxy_;
int device_id_;
// Pool of DIBs.
typedef std::list<DIBBuffer*> CachedDIB;
CachedDIB cached_dibs_;
typedef std::map<media::VideoCapture::EventHandler*, VideoCaptureCapability>
ClientInfo;
ClientInfo clients_;
std::list<media::VideoCapture::EventHandler*> master_clients_;
ClientInfo pending_clients_;
int width_;
int height_;
int frame_rate_;
media::VideoFrame::Format video_type_;
int new_width_;
int new_height_;
State state_;
DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl);
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(VideoCaptureImpl);
#endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/media/video_capture_impl_manager.h"
#include "base/memory/singleton.h"
#include "content/common/child_process.h"
#include "content/common/child_thread.h"
#include "content/common/video_capture_messages.h"
#include "content/common/view_messages.h"
#include "media/base/message_loop_factory_impl.h"
namespace {
// VideoCaptureMessageFilterCreator is to be used as a singleton so we can get
// access to a shared VideoCaptureMessageFilter.
// Example usage:
// VideoCaptureMessageFilter* filter =
// VideoCaptureMessageFilterCreator::SharedFilter();
class VideoCaptureMessageFilterCreator {
public:
VideoCaptureMessageFilterCreator() {
int routing_id;
ChildThread::current()->Send(
new ViewHostMsg_GenerateRoutingID(&routing_id));
filter_ = new VideoCaptureMessageFilter(routing_id);
filter_->AddFilter();
}
static VideoCaptureMessageFilter* SharedFilter() {
return GetInstance()->filter_.get();
}
static VideoCaptureMessageFilterCreator* GetInstance() {
return Singleton<VideoCaptureMessageFilterCreator>::get();
}
private:
scoped_refptr<VideoCaptureMessageFilter> filter_;
};
} // namespace
VideoCaptureImplManager::VideoCaptureImplManager() {
ml_factory_.reset(new media::MessageLoopFactoryImpl());
ml_proxy_ = ml_factory_->GetMessageLoopProxy("VC manager");
}
VideoCaptureImplManager::~VideoCaptureImplManager() {}
// static
media::VideoCapture* VideoCaptureImplManager::AddDevice(
media::VideoCaptureSessionId id,
media::VideoCapture::EventHandler* handler) {
DCHECK(handler);
VideoCaptureImplManager* manager = GetInstance();
base::AutoLock auto_lock(manager->lock_);
Devices::iterator it = manager->devices_.find(id);
if (it == manager->devices_.end()) {
VideoCaptureImpl* vc =
new VideoCaptureImpl(id, manager->ml_proxy_,
VideoCaptureMessageFilterCreator::SharedFilter());
manager->devices_[id] = Device(vc, handler);
vc->Init();
return vc;
}
manager->devices_[id].clients.push_front(handler);
return it->second.vc;
}
// static
void VideoCaptureImplManager::RemoveDevice(
media::VideoCaptureSessionId id,
media::VideoCapture::EventHandler* handler) {
DCHECK(handler);
VideoCaptureImplManager* manager = GetInstance();
base::AutoLock auto_lock(manager->lock_);
Devices::iterator it = manager->devices_.find(id);
if (it == manager->devices_.end())
return;
size_t size = it->second.clients.size();
it->second.clients.remove(handler);
if (size == it->second.clients.size() || size > 1)
return;
manager->devices_[id].vc->DeInit(NewRunnableMethod(manager,
&VideoCaptureImplManager::FreeDevice, manager->devices_[id].vc));
manager->devices_.erase(id);
return;
}
// static
VideoCaptureImplManager* VideoCaptureImplManager::GetInstance() {
return Singleton<VideoCaptureImplManager>::get();
}
void VideoCaptureImplManager::FreeDevice(VideoCaptureImpl* vc) {
delete vc;
}
VideoCaptureImplManager::Device::Device() : vc(NULL) {}
VideoCaptureImplManager::Device::Device(
VideoCaptureImpl* device,
media::VideoCapture::EventHandler* handler)
: vc(device) {
clients.push_front(handler);
}
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// VideoCaptureImplManager manages video capture devices in renderer process.
// The video capture clients use AddDevice() to get a pointer to
// video capture device. VideoCaputreImplManager supports multiple clients
// accessing same device.
#ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_
#define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_
#include <list>
#include <map>
#include "base/message_loop_proxy.h"
#include "base/synchronization/lock.h"
#include "content/renderer/media/video_capture_impl.h"
#include "content/renderer/video_capture_message_filter.h"
#include "media/base/callback.h"
#include "media/base/message_loop_factory.h"
#include "media/video/capture/video_capture.h"
class VideoCaptureImplManager {
public:
VideoCaptureImplManager();
~VideoCaptureImplManager();
// Called by video capture client |handler| to add device referenced
// by |id| to VideoCaptureImplManager's list of opened device list.
// A pointer to VideoCapture is returned to client so that client can
// operate on that pointer, such as StartCaptrue, StopCapture.
static media::VideoCapture* AddDevice(
media::VideoCaptureSessionId id,
media::VideoCapture::EventHandler* handler);
// Called by video capture client |handler| to remove device referenced
// by |id| from VideoCaptureImplManager's list of opened device list.
static void RemoveDevice(media::VideoCaptureSessionId id,
media::VideoCapture::EventHandler* handler);
static VideoCaptureImplManager* GetInstance();
private:
struct Device {
Device();
Device(VideoCaptureImpl* device,
media::VideoCapture::EventHandler* handler);
VideoCaptureImpl* vc;
std::list<media::VideoCapture::EventHandler*> clients;
};
void FreeDevice(VideoCaptureImpl* vc);
typedef std::map<media::VideoCaptureSessionId, Device> Devices;
Devices devices_;
base::Lock lock_;
scoped_refptr<base::MessageLoopProxy> ml_proxy_;
scoped_ptr<media::MessageLoopFactory> ml_factory_;
DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager);
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(VideoCaptureImplManager);
#endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/message_loop.h"
#include "content/renderer/media/video_capture_impl.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::_;
using ::testing::Return;
#define DEFAULT_CAPABILITY {176, 144, 30, 0, media::VideoFrame::I420, \
false, false }
ACTION_P(DeleteMessage, return_value) {
delete arg0;
return return_value;
}
class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter {
public:
MockVideoCaptureMessageFilter() : VideoCaptureMessageFilter(1) {}
virtual ~MockVideoCaptureMessageFilter() {}
// Filter implementation.
MOCK_METHOD1(Send, bool(IPC::Message* message));
MOCK_METHOD0(ReadyToSend, bool());
private:
DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureMessageFilter);
};
class MockVideoCaptureClient : public media::VideoCapture::EventHandler {
public:
MockVideoCaptureClient() {}
virtual ~MockVideoCaptureClient() {}
// Filter implementation.
MOCK_METHOD1(OnStarted, void(media::VideoCapture* capture));
MOCK_METHOD1(OnStopped, void(media::VideoCapture* capture));
MOCK_METHOD1(OnPaused, void(media::VideoCapture* capture));
MOCK_METHOD2(OnError, void(media::VideoCapture* capture, int error_code));
MOCK_METHOD2(OnBufferReady,
void(media::VideoCapture* capture,
scoped_refptr<media::VideoCapture::VideoFrameBuffer> buf));
MOCK_METHOD2(OnDeviceInfoReceived,
void(media::VideoCapture* capture,
const media::VideoCaptureParams& device_info));
private:
DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureClient);
};
class VideoCaptureImplTest : public ::testing::Test {
public:
VideoCaptureImplTest() {
message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO));
message_loop_proxy_ =
base::MessageLoopProxy::CreateForCurrentThread().get();
message_filter_ = new MockVideoCaptureMessageFilter;
session_id_ = 1;
video_capture_impl_ = new VideoCaptureImpl(session_id_, message_loop_proxy_,
message_filter_);
video_capture_impl_->device_id_ = 2;
}
virtual ~VideoCaptureImplTest() {
delete video_capture_impl_;
}
protected:
scoped_ptr<MessageLoop> message_loop_;
scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
scoped_refptr<MockVideoCaptureMessageFilter> message_filter_;
media::VideoCaptureSessionId session_id_;
VideoCaptureImpl* video_capture_impl_;
private:
DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplTest);
};
TEST_F(VideoCaptureImplTest, Simple) {
// Execute SetCapture() and StopCapture().
scoped_ptr<MockVideoCaptureClient> client(new MockVideoCaptureClient);
media::VideoCapture::VideoCaptureCapability capability = DEFAULT_CAPABILITY;
EXPECT_CALL(*message_filter_, Send(_))
.WillRepeatedly(DeleteMessage(true));
EXPECT_CALL(*message_filter_, ReadyToSend())
.WillRepeatedly(Return(true));
EXPECT_CALL(*client, OnStarted(_))
.WillOnce(Return());
video_capture_impl_->StartCapture(client.get(), capability);
EXPECT_CALL(*client, OnStopped(_))
.WillOnce(Return());
video_capture_impl_->StopCapture(client.get());
}
...@@ -54,6 +54,13 @@ void VideoCaptureMessageFilter::OnFilterAdded(IPC::Channel* channel) { ...@@ -54,6 +54,13 @@ void VideoCaptureMessageFilter::OnFilterAdded(IPC::Channel* channel) {
// Captures the message loop proxy for IPC. // Captures the message loop proxy for IPC.
message_loop_proxy_ = base::MessageLoopProxy::CreateForCurrentThread(); message_loop_proxy_ = base::MessageLoopProxy::CreateForCurrentThread();
channel_ = channel; channel_ = channel;
for (Delegates::iterator it = pending_delegates_.begin();
it != pending_delegates_.end(); it++) {
it->second->OnDelegateAdded(it->first);
delegates_[it->first] = it->second;
}
pending_delegates_.clear();
} }
void VideoCaptureMessageFilter::OnFilterRemoved() { void VideoCaptureMessageFilter::OnFilterRemoved() {
...@@ -114,14 +121,18 @@ void VideoCaptureMessageFilter::OnDeviceInfoReceived( ...@@ -114,14 +121,18 @@ void VideoCaptureMessageFilter::OnDeviceInfoReceived(
delegate->OnDeviceInfoReceived(params); delegate->OnDeviceInfoReceived(params);
} }
int32 VideoCaptureMessageFilter::AddDelegate(Delegate* delegate) { void VideoCaptureMessageFilter::AddDelegate(Delegate* delegate) {
if (++last_device_id_ <= 0) if (++last_device_id_ <= 0)
last_device_id_ = 1; last_device_id_ = 1;
while (delegates_.find(last_device_id_) != delegates_.end()) while (delegates_.find(last_device_id_) != delegates_.end())
last_device_id_++; last_device_id_++;
if (channel_) {
delegates_[last_device_id_] = delegate; delegates_[last_device_id_] = delegate;
return last_device_id_; delegate->OnDelegateAdded(last_device_id_);
} else {
pending_delegates_[last_device_id_] = delegate;
}
} }
void VideoCaptureMessageFilter::RemoveDelegate(Delegate* delegate) { void VideoCaptureMessageFilter::RemoveDelegate(Delegate* delegate) {
...@@ -132,6 +143,13 @@ void VideoCaptureMessageFilter::RemoveDelegate(Delegate* delegate) { ...@@ -132,6 +143,13 @@ void VideoCaptureMessageFilter::RemoveDelegate(Delegate* delegate) {
break; break;
} }
} }
for (Delegates::iterator it = pending_delegates_.begin();
it != pending_delegates_.end(); it++) {
if (it->second == delegate) {
pending_delegates_.erase(it);
break;
}
}
} }
void VideoCaptureMessageFilter::AddFilter() { void VideoCaptureMessageFilter::AddFilter() {
......
...@@ -34,6 +34,10 @@ class VideoCaptureMessageFilter : public IPC::ChannelProxy::MessageFilter { ...@@ -34,6 +34,10 @@ class VideoCaptureMessageFilter : public IPC::ChannelProxy::MessageFilter {
virtual void OnDeviceInfoReceived( virtual void OnDeviceInfoReceived(
const media::VideoCaptureParams& device_info) = 0; const media::VideoCaptureParams& device_info) = 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;
protected: protected:
virtual ~Delegate() {} virtual ~Delegate() {}
}; };
...@@ -41,14 +45,14 @@ class VideoCaptureMessageFilter : public IPC::ChannelProxy::MessageFilter { ...@@ -41,14 +45,14 @@ class VideoCaptureMessageFilter : public IPC::ChannelProxy::MessageFilter {
explicit VideoCaptureMessageFilter(int32 route_id); explicit VideoCaptureMessageFilter(int32 route_id);
virtual ~VideoCaptureMessageFilter(); virtual ~VideoCaptureMessageFilter();
// Add a delegate to the map and return id of the entry. // Add a delegate to the map.
int32 AddDelegate(Delegate* delegate); void AddDelegate(Delegate* delegate);
// Remove a delegate from the map. // Remove a delegate from the map.
void RemoveDelegate(Delegate* delegate); void RemoveDelegate(Delegate* delegate);
// Send a message asynchronously. // Send a message asynchronously.
bool Send(IPC::Message* message); virtual bool Send(IPC::Message* message);
void AddFilter(); void AddFilter();
...@@ -79,6 +83,7 @@ class VideoCaptureMessageFilter : public IPC::ChannelProxy::MessageFilter { ...@@ -79,6 +83,7 @@ class VideoCaptureMessageFilter : public IPC::ChannelProxy::MessageFilter {
// A map of device ids to delegates. // A map of device ids to delegates.
Delegates delegates_; Delegates delegates_;
Delegates pending_delegates_;
int32 last_device_id_; int32 last_device_id_;
int32 route_id_; int32 route_id_;
......
...@@ -13,6 +13,8 @@ class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate { ...@@ -13,6 +13,8 @@ class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate {
public: public:
MockVideoCaptureDelegate() { MockVideoCaptureDelegate() {
Reset(); Reset();
device_id_received_ = false;
device_id_ = 0;
} }
virtual void OnBufferReceived(TransportDIB::Handle handle, virtual void OnBufferReceived(TransportDIB::Handle handle,
...@@ -34,6 +36,11 @@ class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate { ...@@ -34,6 +36,11 @@ class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate {
params_.frame_per_second = params.frame_per_second; params_.frame_per_second = params.frame_per_second;
} }
virtual void OnDelegateAdded(int32 device_id) {
device_id_received_ = true;
device_id_ = device_id;
}
void Reset() { void Reset() {
buffer_received_ = false; buffer_received_ = false;
handle_ = TransportDIB::DefaultHandleValue(); handle_ = TransportDIB::DefaultHandleValue();
...@@ -58,6 +65,9 @@ class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate { ...@@ -58,6 +65,9 @@ class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate {
bool device_info_receive() { return device_info_received_; } bool device_info_receive() { return device_info_received_; }
const media::VideoCaptureParams& received_device_info() { return params_; } const media::VideoCaptureParams& received_device_info() { return params_; }
bool device_id_received() { return device_id_received_; }
int32 device_id() { return device_id_; }
private: private:
bool buffer_received_; bool buffer_received_;
TransportDIB::Handle handle_; TransportDIB::Handle handle_;
...@@ -69,6 +79,9 @@ class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate { ...@@ -69,6 +79,9 @@ class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate {
bool device_info_received_; bool device_info_received_;
media::VideoCaptureParams params_; media::VideoCaptureParams params_;
bool device_id_received_;
int32 device_id_;
DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureDelegate); DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureDelegate);
}; };
...@@ -80,14 +93,15 @@ TEST(VideoCaptureMessageFilterTest, Basic) { ...@@ -80,14 +93,15 @@ TEST(VideoCaptureMessageFilterTest, Basic) {
const int kRouteId = 0; const int kRouteId = 0;
scoped_refptr<VideoCaptureMessageFilter> filter( scoped_refptr<VideoCaptureMessageFilter> filter(
new VideoCaptureMessageFilter(kRouteId)); new VideoCaptureMessageFilter(kRouteId));
filter->channel_ = reinterpret_cast<IPC::Channel*>(1);
MockVideoCaptureDelegate delegate; MockVideoCaptureDelegate delegate;
int device_id = filter->AddDelegate(&delegate); filter->AddDelegate(&delegate);
// VideoCaptureMsg_StateChanged // VideoCaptureMsg_StateChanged
EXPECT_FALSE(delegate.state_changed_received()); EXPECT_FALSE(delegate.state_changed_received());
filter->OnMessageReceived( filter->OnMessageReceived(
VideoCaptureMsg_StateChanged(kRouteId, device_id, VideoCaptureMsg_StateChanged(kRouteId, delegate.device_id(),
media::VideoCapture::kStarted)); media::VideoCapture::kStarted));
EXPECT_TRUE(delegate.state_changed_received()); EXPECT_TRUE(delegate.state_changed_received());
EXPECT_TRUE(media::VideoCapture::kStarted == delegate.state()); EXPECT_TRUE(media::VideoCapture::kStarted == delegate.state());
...@@ -99,7 +113,7 @@ TEST(VideoCaptureMessageFilterTest, Basic) { ...@@ -99,7 +113,7 @@ TEST(VideoCaptureMessageFilterTest, Basic) {
EXPECT_FALSE(delegate.buffer_received()); EXPECT_FALSE(delegate.buffer_received());
filter->OnMessageReceived(VideoCaptureMsg_BufferReady( filter->OnMessageReceived(VideoCaptureMsg_BufferReady(
kRouteId, device_id, handle, timestamp)); kRouteId, delegate.device_id(), handle, timestamp));
EXPECT_TRUE(delegate.buffer_received()); EXPECT_TRUE(delegate.buffer_received());
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
EXPECT_EQ(handle.fd, delegate.received_buffer_handle().fd); EXPECT_EQ(handle.fd, delegate.received_buffer_handle().fd);
...@@ -117,7 +131,7 @@ TEST(VideoCaptureMessageFilterTest, Basic) { ...@@ -117,7 +131,7 @@ TEST(VideoCaptureMessageFilterTest, Basic) {
EXPECT_FALSE(delegate.device_info_receive()); EXPECT_FALSE(delegate.device_info_receive());
filter->OnMessageReceived(VideoCaptureMsg_DeviceInfo( filter->OnMessageReceived(VideoCaptureMsg_DeviceInfo(
kRouteId, device_id, params)); kRouteId, delegate.device_id(), params));
EXPECT_TRUE(delegate.device_info_receive()); EXPECT_TRUE(delegate.device_info_receive());
EXPECT_EQ(params.width, delegate.received_device_info().width); EXPECT_EQ(params.width, delegate.received_device_info().width);
EXPECT_EQ(params.height, delegate.received_device_info().height); EXPECT_EQ(params.height, delegate.received_device_info().height);
...@@ -134,18 +148,19 @@ TEST(VideoCaptureMessageFilterTest, Delegates) { ...@@ -134,18 +148,19 @@ TEST(VideoCaptureMessageFilterTest, Delegates) {
const int kRouteId = 0; const int kRouteId = 0;
scoped_refptr<VideoCaptureMessageFilter> filter( scoped_refptr<VideoCaptureMessageFilter> filter(
new VideoCaptureMessageFilter(kRouteId)); new VideoCaptureMessageFilter(kRouteId));
filter->channel_ = reinterpret_cast<IPC::Channel*>(1);
MockVideoCaptureDelegate delegate1; MockVideoCaptureDelegate delegate1;
MockVideoCaptureDelegate delegate2; MockVideoCaptureDelegate delegate2;
int device_id1 = filter->AddDelegate(&delegate1); filter->AddDelegate(&delegate1);
int device_id2 = filter->AddDelegate(&delegate2); filter->AddDelegate(&delegate2);
// Send an IPC message. Make sure the correct delegate gets called. // Send an IPC message. Make sure the correct delegate gets called.
EXPECT_FALSE(delegate1.state_changed_received()); EXPECT_FALSE(delegate1.state_changed_received());
EXPECT_FALSE(delegate2.state_changed_received()); EXPECT_FALSE(delegate2.state_changed_received());
filter->OnMessageReceived( filter->OnMessageReceived(
VideoCaptureMsg_StateChanged(kRouteId, device_id1, VideoCaptureMsg_StateChanged(kRouteId, delegate1.device_id(),
media::VideoCapture::kStarted)); media::VideoCapture::kStarted));
EXPECT_TRUE(delegate1.state_changed_received()); EXPECT_TRUE(delegate1.state_changed_received());
EXPECT_FALSE(delegate2.state_changed_received()); EXPECT_FALSE(delegate2.state_changed_received());
...@@ -154,7 +169,7 @@ TEST(VideoCaptureMessageFilterTest, Delegates) { ...@@ -154,7 +169,7 @@ TEST(VideoCaptureMessageFilterTest, Delegates) {
EXPECT_FALSE(delegate1.state_changed_received()); EXPECT_FALSE(delegate1.state_changed_received());
EXPECT_FALSE(delegate2.state_changed_received()); EXPECT_FALSE(delegate2.state_changed_received());
filter->OnMessageReceived( filter->OnMessageReceived(
VideoCaptureMsg_StateChanged(kRouteId, device_id2, VideoCaptureMsg_StateChanged(kRouteId, delegate2.device_id(),
media::VideoCapture::kStarted)); media::VideoCapture::kStarted));
EXPECT_FALSE(delegate1.state_changed_received()); EXPECT_FALSE(delegate1.state_changed_received());
EXPECT_TRUE(delegate2.state_changed_received()); EXPECT_TRUE(delegate2.state_changed_received());
...@@ -163,7 +178,7 @@ TEST(VideoCaptureMessageFilterTest, Delegates) { ...@@ -163,7 +178,7 @@ TEST(VideoCaptureMessageFilterTest, Delegates) {
// Send a message of a different route id, a message is not received. // Send a message of a different route id, a message is not received.
EXPECT_FALSE(delegate1.state_changed_received()); EXPECT_FALSE(delegate1.state_changed_received());
filter->OnMessageReceived( filter->OnMessageReceived(
VideoCaptureMsg_StateChanged(kRouteId+1, device_id1, VideoCaptureMsg_StateChanged(kRouteId+1, delegate1.device_id(),
media::VideoCapture::kStarted)); media::VideoCapture::kStarted));
EXPECT_FALSE(delegate1.state_changed_received()); EXPECT_FALSE(delegate1.state_changed_received());
...@@ -171,14 +186,14 @@ TEST(VideoCaptureMessageFilterTest, Delegates) { ...@@ -171,14 +186,14 @@ TEST(VideoCaptureMessageFilterTest, Delegates) {
filter->RemoveDelegate(&delegate1); filter->RemoveDelegate(&delegate1);
EXPECT_FALSE(delegate1.state_changed_received()); EXPECT_FALSE(delegate1.state_changed_received());
filter->OnMessageReceived( filter->OnMessageReceived(
VideoCaptureMsg_StateChanged(kRouteId, device_id1, VideoCaptureMsg_StateChanged(kRouteId, delegate1.device_id(),
media::VideoCapture::kStarted)); media::VideoCapture::kStarted));
EXPECT_FALSE(delegate1.state_changed_received()); EXPECT_FALSE(delegate1.state_changed_received());
filter->RemoveDelegate(&delegate2); filter->RemoveDelegate(&delegate2);
EXPECT_FALSE(delegate2.state_changed_received()); EXPECT_FALSE(delegate2.state_changed_received());
filter->OnMessageReceived( filter->OnMessageReceived(
VideoCaptureMsg_StateChanged(kRouteId, device_id2, VideoCaptureMsg_StateChanged(kRouteId, delegate2.device_id(),
media::VideoCapture::kStarted)); media::VideoCapture::kStarted));
EXPECT_FALSE(delegate2.state_changed_received()); EXPECT_FALSE(delegate2.state_changed_received());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment