Commit 86ca97fc authored by vandebo@chromium.org's avatar vandebo@chromium.org

Revert "Add VideoCaptureImpl and VideoCaptureImplManager"

This reverts commit r86758

Revert "fix clang"

This reverts commit r86761

BUG=NONE
TEST=NONE
TBR=wjia@google.com

Review URL: http://codereview.chromium.org/7071002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86770 0039d316-1c4b-4281-b951-d872f2087c98
parent f112b0f0
......@@ -1959,7 +1959,6 @@
'../content/renderer/active_notification_tracker_unittest.cc',
'../content/renderer/audio_message_filter_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/video_capture_message_filter_unittest.cc',
'../testing/gtest_mac_unittest.mm',
......
......@@ -70,10 +70,6 @@
'renderer/media/gles2_video_decode_context.h',
'renderer/media/ipc_video_decoder.cc',
'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.h',
'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);
}
VideoCaptureImplManager::Device::~Device() {}
// 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);
~Device();
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,13 +54,6 @@ void VideoCaptureMessageFilter::OnFilterAdded(IPC::Channel* channel) {
// Captures the message loop proxy for IPC.
message_loop_proxy_ = base::MessageLoopProxy::CreateForCurrentThread();
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() {
......@@ -121,18 +114,14 @@ void VideoCaptureMessageFilter::OnDeviceInfoReceived(
delegate->OnDeviceInfoReceived(params);
}
void VideoCaptureMessageFilter::AddDelegate(Delegate* delegate) {
int32 VideoCaptureMessageFilter::AddDelegate(Delegate* delegate) {
if (++last_device_id_ <= 0)
last_device_id_ = 1;
while (delegates_.find(last_device_id_) != delegates_.end())
last_device_id_++;
if (channel_) {
delegates_[last_device_id_] = delegate;
delegate->OnDelegateAdded(last_device_id_);
} else {
pending_delegates_[last_device_id_] = delegate;
}
delegates_[last_device_id_] = delegate;
return last_device_id_;
}
void VideoCaptureMessageFilter::RemoveDelegate(Delegate* delegate) {
......@@ -143,13 +132,6 @@ void VideoCaptureMessageFilter::RemoveDelegate(Delegate* delegate) {
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() {
......
......@@ -34,10 +34,6 @@ class VideoCaptureMessageFilter : public IPC::ChannelProxy::MessageFilter {
virtual void OnDeviceInfoReceived(
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:
virtual ~Delegate() {}
};
......@@ -45,14 +41,14 @@ class VideoCaptureMessageFilter : public IPC::ChannelProxy::MessageFilter {
explicit VideoCaptureMessageFilter(int32 route_id);
virtual ~VideoCaptureMessageFilter();
// Add a delegate to the map.
void AddDelegate(Delegate* delegate);
// Add a delegate to the map and return id of the entry.
int32 AddDelegate(Delegate* delegate);
// Remove a delegate from the map.
void RemoveDelegate(Delegate* delegate);
// Send a message asynchronously.
virtual bool Send(IPC::Message* message);
bool Send(IPC::Message* message);
void AddFilter();
......@@ -83,7 +79,6 @@ class VideoCaptureMessageFilter : public IPC::ChannelProxy::MessageFilter {
// A map of device ids to delegates.
Delegates delegates_;
Delegates pending_delegates_;
int32 last_device_id_;
int32 route_id_;
......
......@@ -13,8 +13,6 @@ class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate {
public:
MockVideoCaptureDelegate() {
Reset();
device_id_received_ = false;
device_id_ = 0;
}
virtual void OnBufferReceived(TransportDIB::Handle handle,
......@@ -36,11 +34,6 @@ class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate {
params_.frame_per_second = params.frame_per_second;
}
virtual void OnDelegateAdded(int32 device_id) {
device_id_received_ = true;
device_id_ = device_id;
}
void Reset() {
buffer_received_ = false;
handle_ = TransportDIB::DefaultHandleValue();
......@@ -65,9 +58,6 @@ class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate {
bool device_info_receive() { return device_info_received_; }
const media::VideoCaptureParams& received_device_info() { return params_; }
bool device_id_received() { return device_id_received_; }
int32 device_id() { return device_id_; }
private:
bool buffer_received_;
TransportDIB::Handle handle_;
......@@ -79,9 +69,6 @@ class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate {
bool device_info_received_;
media::VideoCaptureParams params_;
bool device_id_received_;
int32 device_id_;
DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureDelegate);
};
......@@ -93,15 +80,14 @@ TEST(VideoCaptureMessageFilterTest, Basic) {
const int kRouteId = 0;
scoped_refptr<VideoCaptureMessageFilter> filter(
new VideoCaptureMessageFilter(kRouteId));
filter->channel_ = reinterpret_cast<IPC::Channel*>(1);
MockVideoCaptureDelegate delegate;
filter->AddDelegate(&delegate);
int device_id = filter->AddDelegate(&delegate);
// VideoCaptureMsg_StateChanged
EXPECT_FALSE(delegate.state_changed_received());
filter->OnMessageReceived(
VideoCaptureMsg_StateChanged(kRouteId, delegate.device_id(),
VideoCaptureMsg_StateChanged(kRouteId, device_id,
media::VideoCapture::kStarted));
EXPECT_TRUE(delegate.state_changed_received());
EXPECT_TRUE(media::VideoCapture::kStarted == delegate.state());
......@@ -113,7 +99,7 @@ TEST(VideoCaptureMessageFilterTest, Basic) {
EXPECT_FALSE(delegate.buffer_received());
filter->OnMessageReceived(VideoCaptureMsg_BufferReady(
kRouteId, delegate.device_id(), handle, timestamp));
kRouteId, device_id, handle, timestamp));
EXPECT_TRUE(delegate.buffer_received());
#if defined(OS_MACOSX)
EXPECT_EQ(handle.fd, delegate.received_buffer_handle().fd);
......@@ -131,7 +117,7 @@ TEST(VideoCaptureMessageFilterTest, Basic) {
EXPECT_FALSE(delegate.device_info_receive());
filter->OnMessageReceived(VideoCaptureMsg_DeviceInfo(
kRouteId, delegate.device_id(), params));
kRouteId, device_id, params));
EXPECT_TRUE(delegate.device_info_receive());
EXPECT_EQ(params.width, delegate.received_device_info().width);
EXPECT_EQ(params.height, delegate.received_device_info().height);
......@@ -148,19 +134,18 @@ TEST(VideoCaptureMessageFilterTest, Delegates) {
const int kRouteId = 0;
scoped_refptr<VideoCaptureMessageFilter> filter(
new VideoCaptureMessageFilter(kRouteId));
filter->channel_ = reinterpret_cast<IPC::Channel*>(1);
MockVideoCaptureDelegate delegate1;
MockVideoCaptureDelegate delegate2;
filter->AddDelegate(&delegate1);
filter->AddDelegate(&delegate2);
int device_id1 = filter->AddDelegate(&delegate1);
int device_id2 = filter->AddDelegate(&delegate2);
// Send an IPC message. Make sure the correct delegate gets called.
EXPECT_FALSE(delegate1.state_changed_received());
EXPECT_FALSE(delegate2.state_changed_received());
filter->OnMessageReceived(
VideoCaptureMsg_StateChanged(kRouteId, delegate1.device_id(),
VideoCaptureMsg_StateChanged(kRouteId, device_id1,
media::VideoCapture::kStarted));
EXPECT_TRUE(delegate1.state_changed_received());
EXPECT_FALSE(delegate2.state_changed_received());
......@@ -169,7 +154,7 @@ TEST(VideoCaptureMessageFilterTest, Delegates) {
EXPECT_FALSE(delegate1.state_changed_received());
EXPECT_FALSE(delegate2.state_changed_received());
filter->OnMessageReceived(
VideoCaptureMsg_StateChanged(kRouteId, delegate2.device_id(),
VideoCaptureMsg_StateChanged(kRouteId, device_id2,
media::VideoCapture::kStarted));
EXPECT_FALSE(delegate1.state_changed_received());
EXPECT_TRUE(delegate2.state_changed_received());
......@@ -178,7 +163,7 @@ TEST(VideoCaptureMessageFilterTest, Delegates) {
// Send a message of a different route id, a message is not received.
EXPECT_FALSE(delegate1.state_changed_received());
filter->OnMessageReceived(
VideoCaptureMsg_StateChanged(kRouteId+1, delegate1.device_id(),
VideoCaptureMsg_StateChanged(kRouteId+1, device_id1,
media::VideoCapture::kStarted));
EXPECT_FALSE(delegate1.state_changed_received());
......@@ -186,14 +171,14 @@ TEST(VideoCaptureMessageFilterTest, Delegates) {
filter->RemoveDelegate(&delegate1);
EXPECT_FALSE(delegate1.state_changed_received());
filter->OnMessageReceived(
VideoCaptureMsg_StateChanged(kRouteId, delegate1.device_id(),
VideoCaptureMsg_StateChanged(kRouteId, device_id1,
media::VideoCapture::kStarted));
EXPECT_FALSE(delegate1.state_changed_received());
filter->RemoveDelegate(&delegate2);
EXPECT_FALSE(delegate2.state_changed_received());
filter->OnMessageReceived(
VideoCaptureMsg_StateChanged(kRouteId, delegate2.device_id(),
VideoCaptureMsg_StateChanged(kRouteId, device_id2,
media::VideoCapture::kStarted));
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