summaryrefslogtreecommitdiffstats
path: root/content/renderer/media
diff options
context:
space:
mode:
authorwjia@chromium.org <wjia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-01 17:40:06 +0000
committerwjia@chromium.org <wjia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-01 17:40:06 +0000
commit6a33b920912e2b2a01a2f04527041aea8a6a94f2 (patch)
tree0af392e21f760e5f0845ea16baebb18f27978194 /content/renderer/media
parenta672c47b362dba0781eb1fbb396ac702c35f39c9 (diff)
downloadchromium_src-6a33b920912e2b2a01a2f04527041aea8a6a94f2.zip
chromium_src-6a33b920912e2b2a01a2f04527041aea8a6a94f2.tar.gz
chromium_src-6a33b920912e2b2a01a2f04527041aea8a6a94f2.tar.bz2
refactor video capture in renderer process
This patch is a split of http://codereview.chromium.org/8304017/ . 1. Since all clients of VideoCaptureImpl accept pixel frames with different dimension than requested, there is no need to distinguish them. Remove "resolution_fixed" in media::VideoCapture::VideoCaptureCapability. 2. VideoCaptureImpl is now taking the largested dimension from client requests and send it to browser process. 3. remove some unnecessary code in VideoCaptureModuleImpl since webrtc ViE can handle different frame size. BUG=none TEST=trybots Review URL: http://codereview.chromium.org/8400084 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108126 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer/media')
-rw-r--r--content/renderer/media/capture_video_decoder_unittest.cc1
-rw-r--r--content/renderer/media/media_stream_impl.cc1
-rw-r--r--content/renderer/media/video_capture_impl.cc251
-rw-r--r--content/renderer/media/video_capture_impl.h30
-rw-r--r--content/renderer/media/video_capture_impl_unittest.cc135
-rw-r--r--content/renderer/media/video_capture_module_impl.cc8
-rw-r--r--content/renderer/media/video_capture_module_impl.h1
7 files changed, 177 insertions, 250 deletions
diff --git a/content/renderer/media/capture_video_decoder_unittest.cc b/content/renderer/media/capture_video_decoder_unittest.cc
index 780d803..65c7893 100644
--- a/content/renderer/media/capture_video_decoder_unittest.cc
+++ b/content/renderer/media/capture_video_decoder_unittest.cc
@@ -95,7 +95,6 @@ class CaptureVideoDecoderTest : public ::testing::Test {
capability.expected_capture_delay = 0;
capability.raw_type = media::VideoFrame::I420;
capability.interlaced = false;
- capability.resolution_fixed = false;
decoder_ = new CaptureVideoDecoder(message_loop_proxy_,
kVideoStreamId, vc_manager_, capability);
diff --git a/content/renderer/media/media_stream_impl.cc b/content/renderer/media/media_stream_impl.cc
index 52e9ec2..7573e78 100644
--- a/content/renderer/media/media_stream_impl.cc
+++ b/content/renderer/media/media_stream_impl.cc
@@ -42,7 +42,6 @@ scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder(
capability.expected_capture_delay = 0;
capability.raw_type = media::VideoFrame::I420;
capability.interlaced = false;
- capability.resolution_fixed = false;
decoder = new CaptureVideoDecoder(
message_loop_factory->GetMessageLoopProxy("CaptureVideoDecoder").get(),
diff --git a/content/renderer/media/video_capture_impl.cc b/content/renderer/media/video_capture_impl.cc
index 6941162..addc6a9 100644
--- a/content/renderer/media/video_capture_impl.cc
+++ b/content/renderer/media/video_capture_impl.cc
@@ -9,14 +9,23 @@
#include "content/common/child_process.h"
#include "content/common/media/video_capture_messages.h"
-VideoCaptureImpl::DIBBuffer::DIBBuffer(
- base::SharedMemory* d, media::VideoCapture::VideoFrameBuffer* ptr)
- : dib(d),
- mapped_memory(ptr) {}
+struct VideoCaptureImpl::DIBBuffer {
+ public:
+ DIBBuffer(
+ base::SharedMemory* d,
+ media::VideoCapture::VideoFrameBuffer* ptr)
+ : dib(d),
+ mapped_memory(ptr),
+ references(0) {
+ }
+ ~DIBBuffer() {}
-VideoCaptureImpl::DIBBuffer::~DIBBuffer() {
- delete dib;
-}
+ scoped_ptr<base::SharedMemory> dib;
+ scoped_refptr<media::VideoCapture::VideoFrameBuffer> mapped_memory;
+
+ // Number of clients which hold this DIB.
+ int references;
+};
bool VideoCaptureImpl::CaptureStarted() {
return state_ == kStarted;
@@ -47,8 +56,7 @@ VideoCaptureImpl::VideoCaptureImpl(
state_(kStopped) {
DCHECK(filter);
memset(&current_params_, 0, sizeof(current_params_));
- memset(&new_params_, 0, sizeof(new_params_));
- current_params_.session_id = new_params_.session_id = id;
+ current_params_.session_id = id;
}
VideoCaptureImpl::~VideoCaptureImpl() {
@@ -147,81 +155,62 @@ void VideoCaptureImpl::DoStartCapture(
const VideoCaptureCapability& capability) {
DCHECK(ml_proxy_->BelongsToCurrentThread());
- if (pending_clients_.find(handler) != pending_clients_.end() ||
+ if (state_ == kError) {
+ handler->OnError(this, 1);
+ handler->OnRemoved(this);
+ return;
+ }
+
+ ClientInfo::iterator it1 = clients_pending_on_filter_.find(handler);
+ ClientInfo::iterator it2 = clients_pending_on_restart_.find(handler);
+ if (it1 != clients_pending_on_filter_.end() ||
+ it2 != clients_pending_on_restart_.end() ||
clients_.find(handler) != clients_.end() ) {
// This client has started.
return;
}
if (!device_id_) {
- pending_clients_[handler] = capability;
+ clients_pending_on_filter_[handler] = capability;
return;
}
- if (capability.resolution_fixed && master_clients_.size()) {
- bool matches_current_params =
- CapabilityMatchesParameters(capability, current_params_);
- bool matches_new_params =
- CapabilityMatchesParameters(capability, new_params_);
- if ((state_ == kStarted && !matches_current_params) ||
- (state_ == kStopping && !matches_new_params)) {
- // Can't have 2 master clients with different resolutions.
- handler->OnError(this, 1);
- handler->OnRemoved(this);
- return;
- }
- }
-
handler->OnStarted(this);
- clients_[handler] = capability;
- if (capability.resolution_fixed) {
- master_clients_.push_back(handler);
- if (master_clients_.size() > 1) {
- if (device_info_available_)
- handler->OnDeviceInfoReceived(this, device_info_);
+ if (state_ == kStarted) {
+ if (capability.width > current_params_.width ||
+ capability.height > current_params_.height) {
+ StopDevice();
+ DVLOG(1) << "StartCapture: Got client with higher resolution ("
+ << capability.width << ", " << capability.height << ") "
+ << "after started, try to restart.";
+ clients_pending_on_restart_[handler] = capability;
return;
}
- }
- if (state_ == kStarted) {
- // Take the resolution of master client.
- if (capability.resolution_fixed &&
- !CapabilityMatchesParameters(capability, current_params_)) {
- new_params_.width = capability.width;
- new_params_.height = capability.height;
- new_params_.frame_per_second = capability.max_fps;
- DLOG(INFO) << "StartCapture: Got master client with new resolution ("
- << new_params_.width << ", " << new_params_.height << ") "
- << "during started, try to restart.";
- StopDevice();
- } else if (device_info_available_) {
+ if (device_info_available_) {
handler->OnDeviceInfoReceived(this, device_info_);
}
+
+ clients_[handler] = capability;
return;
}
if (state_ == kStopping) {
- if (capability.resolution_fixed || !pending_start()) {
- new_params_.width = capability.width;
- new_params_.height = capability.height;
- new_params_.frame_per_second = capability.max_fps;
- DLOG(INFO) << "StartCapture: Got new resolution ("
- << new_params_.width << ", " << new_params_.height << ") "
- << ", already in stopping.";
- }
+ clients_pending_on_restart_[handler] = capability;
+ DVLOG(1) << "StartCapture: Got new resolution ("
+ << capability.width << ", " << capability.height << ") "
+ << ", during stopping.";
return;
}
+ clients_[handler] = capability;
DCHECK_EQ(clients_.size(), 1ul);
video_type_ = capability.raw_type;
- new_params_.width = 0;
- new_params_.height = 0;
- new_params_.frame_per_second = 0;
current_params_.width = capability.width;
current_params_.height = capability.height;
current_params_.frame_per_second = capability.max_fps;
- DLOG(INFO) << "StartCapture: resolution ("
- << current_params_.width << ", " << current_params_.height << ")";
+ DVLOG(1) << "StartCapture: starting with first resolution ("
+ << current_params_.width << ", " << current_params_.height << ")";
StartCaptureInternal();
}
@@ -230,11 +219,18 @@ void VideoCaptureImpl::DoStopCapture(
media::VideoCapture::EventHandler* handler) {
DCHECK(ml_proxy_->BelongsToCurrentThread());
- ClientInfo::iterator it = pending_clients_.find(handler);
- if (it != pending_clients_.end()) {
+ ClientInfo::iterator it = clients_pending_on_filter_.find(handler);
+ if (it != clients_pending_on_filter_.end()) {
handler->OnStopped(this);
handler->OnRemoved(this);
- pending_clients_.erase(it);
+ clients_pending_on_filter_.erase(it);
+ return;
+ }
+ it = clients_pending_on_restart_.find(handler);
+ if (it != clients_pending_on_restart_.end()) {
+ handler->OnStopped(this);
+ handler->OnRemoved(this);
+ clients_pending_on_filter_.erase(it);
return;
}
@@ -244,64 +240,15 @@ void VideoCaptureImpl::DoStopCapture(
handler->OnStopped(this);
handler->OnRemoved(this);
clients_.erase(handler);
- master_clients_.remove(handler);
-
- // Still have at least one master client.
- if (master_clients_.size() > 0)
- return;
-
- // TODO(wjia): Is it really needed to handle resolution change for non-master
- // clients, except no client case?
- if (clients_.size() > 0) {
- DLOG(INFO) << "StopCapture: No master client.";
- int max_width = 0;
- int max_height = 0;
- int frame_rate = 0;
- for (ClientInfo::iterator it = clients_.begin();
- it != clients_.end(); it++) {
- if (it->second.width > max_width && it->second.height > max_height) {
- max_width = it->second.width;
- max_height = it->second.height;
- frame_rate = it->second.max_fps;
- }
- }
- if (state_ == kStarted) {
- // Only handle resolution reduction.
- if (max_width < current_params_.width &&
- max_height < current_params_.height) {
- new_params_.width = max_width;
- new_params_.height = max_height;
- new_params_.frame_per_second = frame_rate;
- DLOG(INFO) << "StopCapture: New smaller resolution ("
- << new_params_.width << ", " << new_params_.height << ") "
- << "), stopping ...";
- StopDevice();
- }
- return;
- }
-
- if (state_ == kStopping) {
- new_params_.width = max_width;
- new_params_.height = max_height;
- new_params_.frame_per_second = frame_rate;
- DLOG(INFO) << "StopCapture: New resolution ("
- << new_params_.width << ", " << new_params_.height << ") "
- << "), during stopping.";
- return;
- }
- } else {
- new_params_.width = current_params_.width = 0;
- new_params_.height = current_params_.height = 0;
- new_params_.frame_per_second = current_params_.frame_per_second = 0;
- DLOG(INFO) << "StopCapture: No more client, stopping ...";
+ if (clients_.empty()) {
+ DVLOG(1) << "StopCapture: No more client, stopping ...";
StopDevice();
}
}
void VideoCaptureImpl::DoFeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) {
DCHECK(ml_proxy_->BelongsToCurrentThread());
- DCHECK(client_side_dibs_.find(buffer) != client_side_dibs_.end());
CachedDIB::iterator it;
for (it = cached_dibs_.begin(); it != cached_dibs_.end(); it++) {
@@ -310,11 +257,10 @@ void VideoCaptureImpl::DoFeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) {
}
DCHECK(it != cached_dibs_.end());
- if (client_side_dibs_[buffer] <= 1) {
- client_side_dibs_.erase(buffer);
+ DCHECK_GT(it->second->references, 0);
+ it->second->references--;
+ if (it->second->references == 0) {
Send(new VideoCaptureHostMsg_BufferReady(device_id_, it->first));
- } else {
- client_side_dibs_[buffer]--;
}
}
@@ -322,6 +268,7 @@ void VideoCaptureImpl::DoBufferCreated(
base::SharedMemoryHandle handle,
int length, int buffer_id) {
DCHECK(ml_proxy_->BelongsToCurrentThread());
+ DCHECK(device_info_available_);
media::VideoCapture::VideoFrameBuffer* buffer;
DCHECK(cached_dibs_.find(buffer_id) == cached_dibs_.end());
@@ -331,8 +278,9 @@ void VideoCaptureImpl::DoBufferCreated(
buffer = new VideoFrameBuffer();
buffer->memory_pointer = static_cast<uint8*>(dib->memory());
buffer->buffer_size = length;
- buffer->width = current_params_.width;
- buffer->height = current_params_.height;
+ buffer->width = device_info_.width;
+ buffer->height = device_info_.height;
+ buffer->stride = device_info_.width;
DIBBuffer* dib_buffer = new DIBBuffer(dib, buffer);
cached_dibs_[buffer_id] = dib_buffer;
@@ -353,7 +301,7 @@ void VideoCaptureImpl::DoBufferReceived(int buffer_id, base::Time timestamp) {
for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); it++) {
it->first->OnBufferReady(this, buffer);
}
- client_side_dibs_[buffer] = clients_.size();
+ cached_dibs_[buffer_id]->references = clients_.size();
}
void VideoCaptureImpl::DoStateChanged(const media::VideoCapture::State& state) {
@@ -364,9 +312,9 @@ void VideoCaptureImpl::DoStateChanged(const media::VideoCapture::State& state) {
break;
case media::VideoCapture::kStopped:
state_ = kStopped;
- DLOG(INFO) << "OnStateChanged: stopped!, device_id = " << device_id_;
+ DVLOG(1) << "OnStateChanged: stopped!, device_id = " << device_id_;
STLDeleteValues(&cached_dibs_);
- if (pending_start())
+ if (!clients_.empty() || !clients_pending_on_restart_.empty())
RestartCapture();
break;
case media::VideoCapture::kPaused:
@@ -376,6 +324,7 @@ void VideoCaptureImpl::DoStateChanged(const media::VideoCapture::State& state) {
}
break;
case media::VideoCapture::kError:
+ DVLOG(1) << "OnStateChanged: error!, device_id = " << device_id_;
for (ClientInfo::iterator it = clients_.begin();
it != clients_.end(); it++) {
// TODO(wjia): browser process would send error code.
@@ -383,9 +332,7 @@ void VideoCaptureImpl::DoStateChanged(const media::VideoCapture::State& state) {
it->first->OnRemoved(this);
}
clients_.clear();
- master_clients_.clear();
- state_ = kStopped;
- current_params_.width = current_params_.height = 0;
+ state_ = kError;
break;
default:
break;
@@ -395,8 +342,9 @@ void VideoCaptureImpl::DoStateChanged(const media::VideoCapture::State& state) {
void VideoCaptureImpl::DoDeviceInfoReceived(
const media::VideoCaptureParams& device_info) {
DCHECK(ml_proxy_->BelongsToCurrentThread());
- if (state_ != kStarted)
- return;
+ DCHECK(!ClientHasDIB());
+
+ STLDeleteValues(&cached_dibs_);
device_info_ = device_info;
device_info_available_ = true;
@@ -406,15 +354,15 @@ void VideoCaptureImpl::DoDeviceInfoReceived(
}
void VideoCaptureImpl::DoDelegateAdded(int32 device_id) {
- DLOG(INFO) << "DoDelegateAdded: device_id " << device_id;
+ DVLOG(1) << "DoDelegateAdded: device_id " << device_id;
DCHECK(ml_proxy_->BelongsToCurrentThread());
device_id_ = device_id;
- for (ClientInfo::iterator it = pending_clients_.begin();
- it != pending_clients_.end(); ) {
+ for (ClientInfo::iterator it = clients_pending_on_filter_.begin();
+ it != clients_pending_on_filter_.end(); ) {
media::VideoCapture::EventHandler* handler = it->first;
const VideoCaptureCapability capability = it->second;
- pending_clients_.erase(it++);
+ clients_pending_on_filter_.erase(it++);
StartCapture(handler, capability);
}
}
@@ -434,16 +382,28 @@ void VideoCaptureImpl::RestartCapture() {
DCHECK(ml_proxy_->BelongsToCurrentThread());
DCHECK_EQ(state_, kStopped);
- current_params_.width = new_params_.width;
- current_params_.height = new_params_.height;
- current_params_.frame_per_second = new_params_.frame_per_second;
-
- new_params_.width = 0;
- new_params_.height = 0;
- new_params_.frame_per_second = 0;
-
- DLOG(INFO) << "RestartCapture, " << current_params_.width << ", "
- << current_params_.height;
+ int width = 0;
+ int height = 0;
+ for (ClientInfo::iterator it = clients_.begin();
+ it != clients_.end(); it++) {
+ if (it->second.width > width)
+ width = it->second.width;
+ if (it->second.height > height)
+ height = it->second.height;
+ }
+ for (ClientInfo::iterator it = clients_pending_on_restart_.begin();
+ it != clients_pending_on_restart_.end(); ) {
+ if (it->second.width > width)
+ width = it->second.width;
+ if (it->second.height > height)
+ height = it->second.height;
+ clients_[it->first] = it->second;
+ clients_pending_on_restart_.erase(it++);
+ }
+ current_params_.width = width;
+ current_params_.height = height;
+ DVLOG(1) << "RestartCapture, " << current_params_.width << ", "
+ << current_params_.height;
StartCaptureInternal();
}
@@ -473,10 +433,11 @@ void VideoCaptureImpl::Send(IPC::Message* message) {
message_filter_.get(), message)));
}
-bool VideoCaptureImpl::CapabilityMatchesParameters(
- const VideoCaptureCapability& capability,
- const media::VideoCaptureParams& params) {
- return (capability.width == params.width &&
- capability.height == params.height &&
- capability.max_fps == params.frame_per_second);
+bool VideoCaptureImpl::ClientHasDIB() {
+ CachedDIB::iterator it;
+ for (it = cached_dibs_.begin(); it != cached_dibs_.end(); it++) {
+ if (it->second->references > 0)
+ return true;
+ }
+ return false;
}
diff --git a/content/renderer/media/video_capture_impl.h b/content/renderer/media/video_capture_impl.h
index e2a224b..b0f84f5 100644
--- a/content/renderer/media/video_capture_impl.h
+++ b/content/renderer/media/video_capture_impl.h
@@ -42,24 +42,12 @@ class CONTENT_EXPORT VideoCaptureImpl
const media::VideoCaptureParams& device_info);
virtual void OnDelegateAdded(int32 device_id);
- bool pending_start() {
- return (new_params_.width > 0 && new_params_.height > 0);
- }
-
private:
friend class VideoCaptureImplManager;
friend class VideoCaptureImplTest;
friend class MockVideoCaptureImpl;
- struct DIBBuffer {
- public:
- DIBBuffer(base::SharedMemory* d,
- media::VideoCapture::VideoFrameBuffer* ptr);
- ~DIBBuffer();
-
- base::SharedMemory* dib;
- scoped_refptr<media::VideoCapture::VideoFrameBuffer> mapped_memory;
- };
+ struct DIBBuffer;
VideoCaptureImpl(media::VideoCaptureSessionId id,
scoped_refptr<base::MessageLoopProxy> ml_proxy,
@@ -88,28 +76,22 @@ class CONTENT_EXPORT VideoCaptureImpl
virtual void Send(IPC::Message* message);
// Helpers.
- bool CapabilityMatchesParameters(const VideoCaptureCapability& capability,
- const media::VideoCaptureParams& params);
+ bool ClientHasDIB();
scoped_refptr<VideoCaptureMessageFilter> message_filter_;
scoped_refptr<base::MessageLoopProxy> ml_proxy_;
int device_id_;
// Pool of DIBs.
- typedef std::map<int, DIBBuffer*> CachedDIB;
+ typedef std::map<int /* buffer_id */, DIBBuffer*> CachedDIB;
CachedDIB cached_dibs_;
- // DIBs at client side. The mapped value |int| means number of clients which
- // hold this dib.
- typedef std::map<media::VideoCapture::VideoFrameBuffer*, int> ClientSideDIB;
- ClientSideDIB client_side_dibs_;
-
typedef std::map<media::VideoCapture::EventHandler*, VideoCaptureCapability>
ClientInfo;
ClientInfo clients_;
- std::list<media::VideoCapture::EventHandler*> master_clients_;
- ClientInfo pending_clients_;
+ ClientInfo clients_pending_on_filter_;
+ ClientInfo clients_pending_on_restart_;
media::VideoFrame::Format video_type_;
@@ -121,8 +103,6 @@ class CONTENT_EXPORT VideoCaptureImpl
media::VideoCaptureParams device_info_;
bool device_info_available_;
- // The parameter will be used in next capture session.
- media::VideoCaptureParams new_params_;
State state_;
DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl);
diff --git a/content/renderer/media/video_capture_impl_unittest.cc b/content/renderer/media/video_capture_impl_unittest.cc
index 43c7aa8..d7d08705c 100644
--- a/content/renderer/media/video_capture_impl_unittest.cc
+++ b/content/renderer/media/video_capture_impl_unittest.cc
@@ -12,10 +12,10 @@ using ::testing::_;
using ::testing::AtLeast;
using ::testing::Return;
-#define DEFAULT_CAPABILITY_REGULAR {176, 144, 30, 0, media::VideoFrame::I420, \
- false, false }
-#define DEFAULT_CAPABILITY_MASTER {320, 240, 20, 0, media::VideoFrame::I420, \
- false, true }
+#define CAPABILITY_SMALL {176, 144, 30, 0, media::VideoFrame::I420, \
+ false }
+#define CAPABILITY_LARGE {320, 240, 30, 0, media::VideoFrame::I420, \
+ false }
class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter {
public:
@@ -133,7 +133,7 @@ TEST_F(VideoCaptureImplTest, Simple) {
// Execute SetCapture() and StopCapture() for one client.
scoped_ptr<MockVideoCaptureClient> client(new MockVideoCaptureClient);
media::VideoCapture::VideoCaptureCapability capability =
- DEFAULT_CAPABILITY_REGULAR;
+ CAPABILITY_SMALL;
EXPECT_CALL(*client, OnStarted(_))
.WillOnce(Return());
@@ -156,7 +156,7 @@ TEST_F(VideoCaptureImplTest, TwoClientsInSequence) {
// Execute SetCapture() and StopCapture() for 2 clients in sequence.
scoped_ptr<MockVideoCaptureClient> client(new MockVideoCaptureClient);
media::VideoCapture::VideoCaptureCapability capability =
- DEFAULT_CAPABILITY_REGULAR;
+ CAPABILITY_SMALL;
EXPECT_CALL(*client, OnStarted(_))
.WillOnce(Return());
@@ -191,114 +191,111 @@ TEST_F(VideoCaptureImplTest, TwoClientsInSequence) {
message_loop_->RunAllPending();
}
-TEST_F(VideoCaptureImplTest, MasterAndRegular) {
+TEST_F(VideoCaptureImplTest, LargeAndSmall) {
// Execute SetCapture() and StopCapture() for 2 clients simultaneously.
- // The master client starts first and stops first.
- scoped_ptr<MockVideoCaptureClient> client_regular(new MockVideoCaptureClient);
- scoped_ptr<MockVideoCaptureClient> client_master(new MockVideoCaptureClient);
- media::VideoCapture::VideoCaptureCapability capability_regular =
- DEFAULT_CAPABILITY_REGULAR;
- media::VideoCapture::VideoCaptureCapability capability_master =
- DEFAULT_CAPABILITY_MASTER;
+ // The large client starts first and stops first.
+ scoped_ptr<MockVideoCaptureClient> client_small(new MockVideoCaptureClient);
+ scoped_ptr<MockVideoCaptureClient> client_large(new MockVideoCaptureClient);
+ media::VideoCapture::VideoCaptureCapability capability_small =
+ CAPABILITY_SMALL;
+ media::VideoCapture::VideoCaptureCapability capability_large =
+ CAPABILITY_LARGE;
- EXPECT_CALL(*client_master, OnStarted(_))
+ EXPECT_CALL(*client_large, OnStarted(_))
.WillOnce(Return());
- EXPECT_CALL(*client_master, OnDeviceInfoReceived(_,_))
+ EXPECT_CALL(*client_large, OnDeviceInfoReceived(_,_))
.WillOnce(Return());
- EXPECT_CALL(*client_regular, OnStarted(_))
+ EXPECT_CALL(*client_small, OnStarted(_))
.WillOnce(Return());
- EXPECT_CALL(*client_regular, OnDeviceInfoReceived(_,_))
+ EXPECT_CALL(*client_small, OnDeviceInfoReceived(_,_))
.WillOnce(Return());
- video_capture_impl_->StartCapture(client_master.get(), capability_master);
- video_capture_impl_->StartCapture(client_regular.get(), capability_regular);
+ video_capture_impl_->StartCapture(client_large.get(), capability_large);
+ video_capture_impl_->StartCapture(client_small.get(), capability_small);
message_loop_->RunAllPending();
- EXPECT_CALL(*client_master, OnStopped(_))
+ EXPECT_CALL(*client_large, OnStopped(_))
.WillOnce(Return());
- EXPECT_CALL(*client_master, OnRemoved(_))
+ EXPECT_CALL(*client_large, OnRemoved(_))
.WillOnce(Return());
- EXPECT_CALL(*client_regular, OnStopped(_))
+ EXPECT_CALL(*client_small, OnStopped(_))
.WillOnce(Return());
- EXPECT_CALL(*client_regular, OnRemoved(_))
+ EXPECT_CALL(*client_small, OnRemoved(_))
.WillOnce(Return());
- video_capture_impl_->StopCapture(client_master.get());
- video_capture_impl_->StopCapture(client_regular.get());
+ video_capture_impl_->StopCapture(client_large.get());
+ video_capture_impl_->StopCapture(client_small.get());
message_loop_->RunAllPending();
}
-TEST_F(VideoCaptureImplTest, RegularAndMaster) {
+TEST_F(VideoCaptureImplTest, SmallAndLarge) {
// Execute SetCapture() and StopCapture() for 2 clients simultaneously.
- // The regular client starts first and stops first.
- scoped_ptr<MockVideoCaptureClient> client_regular(new MockVideoCaptureClient);
- scoped_ptr<MockVideoCaptureClient> client_master(new MockVideoCaptureClient);
- media::VideoCapture::VideoCaptureCapability capability_regular =
- DEFAULT_CAPABILITY_REGULAR;
- media::VideoCapture::VideoCaptureCapability capability_master =
- DEFAULT_CAPABILITY_MASTER;
+ // The small client starts first and stops first.
+ scoped_ptr<MockVideoCaptureClient> client_small(new MockVideoCaptureClient);
+ scoped_ptr<MockVideoCaptureClient> client_large(new MockVideoCaptureClient);
+ media::VideoCapture::VideoCaptureCapability capability_small =
+ CAPABILITY_SMALL;
+ media::VideoCapture::VideoCaptureCapability capability_large =
+ CAPABILITY_LARGE;
- EXPECT_CALL(*client_master, OnStarted(_))
+ EXPECT_CALL(*client_large, OnStarted(_))
.WillOnce(Return());
- EXPECT_CALL(*client_master, OnDeviceInfoReceived(_,_))
+ EXPECT_CALL(*client_large, OnDeviceInfoReceived(_,_))
.WillOnce(Return());
- EXPECT_CALL(*client_regular, OnStarted(_))
+ EXPECT_CALL(*client_small, OnStarted(_))
.WillOnce(Return());
- EXPECT_CALL(*client_regular, OnDeviceInfoReceived(_,_))
+ EXPECT_CALL(*client_small, OnDeviceInfoReceived(_,_))
.Times(AtLeast(1))
.WillRepeatedly(Return());
- video_capture_impl_->StartCapture(client_regular.get(), capability_regular);
- video_capture_impl_->StartCapture(client_master.get(), capability_master);
+ video_capture_impl_->StartCapture(client_small.get(), capability_small);
+ video_capture_impl_->StartCapture(client_large.get(), capability_large);
message_loop_->RunAllPending();
- EXPECT_CALL(*client_master, OnStopped(_))
+ EXPECT_CALL(*client_large, OnStopped(_))
.WillOnce(Return());
- EXPECT_CALL(*client_master, OnRemoved(_))
+ EXPECT_CALL(*client_large, OnRemoved(_))
.WillOnce(Return());
- EXPECT_CALL(*client_regular, OnStopped(_))
+ EXPECT_CALL(*client_small, OnStopped(_))
.WillOnce(Return());
- EXPECT_CALL(*client_regular, OnRemoved(_))
+ EXPECT_CALL(*client_small, OnRemoved(_))
.WillOnce(Return());
- video_capture_impl_->StopCapture(client_regular.get());
- video_capture_impl_->StopCapture(client_master.get());
+ video_capture_impl_->StopCapture(client_small.get());
+ video_capture_impl_->StopCapture(client_large.get());
message_loop_->RunAllPending();
}
-TEST_F(VideoCaptureImplTest, Master1AndMaster2) {
- // Execute SetCapture() and StopCapture() for 2 master clients simultaneously.
- // The two clients have different resolution. The second client is expected to
- // recevie an error.
- scoped_ptr<MockVideoCaptureClient> client_master1(new MockVideoCaptureClient);
- scoped_ptr<MockVideoCaptureClient> client_master2(new MockVideoCaptureClient);
- media::VideoCapture::VideoCaptureCapability capability1 =
- DEFAULT_CAPABILITY_MASTER;
- media::VideoCapture::VideoCaptureCapability capability2 =
- DEFAULT_CAPABILITY_MASTER;
- capability2.width++;
+TEST_F(VideoCaptureImplTest, TwoClientsWithSameSize) {
+ // Execute SetCapture() and StopCapture() for 2 clients simultaneously.
+ // The client1 starts first and stops first.
+ scoped_ptr<MockVideoCaptureClient> client1(new MockVideoCaptureClient);
+ scoped_ptr<MockVideoCaptureClient> client2(new MockVideoCaptureClient);
+ media::VideoCapture::VideoCaptureCapability capability = CAPABILITY_SMALL;
- EXPECT_CALL(*client_master1, OnStarted(_))
+ EXPECT_CALL(*client1, OnStarted(_))
.WillOnce(Return());
- EXPECT_CALL(*client_master1, OnDeviceInfoReceived(_,_))
+ EXPECT_CALL(*client1, OnDeviceInfoReceived(_,_))
.WillOnce(Return());
- EXPECT_CALL(*client_master2, OnError(_,_))
+ EXPECT_CALL(*client2, OnStarted(_))
.WillOnce(Return());
- EXPECT_CALL(*client_master2, OnRemoved(_))
+ EXPECT_CALL(*client2, OnDeviceInfoReceived(_,_))
.WillOnce(Return());
- video_capture_impl_->StartCapture(client_master1.get(), capability1);
- video_capture_impl_->StartCapture(client_master2.get(), capability2);
+ video_capture_impl_->StartCapture(client1.get(), capability);
+ video_capture_impl_->StartCapture(client2.get(), capability);
message_loop_->RunAllPending();
- EXPECT_CALL(*client_master1, OnStopped(_))
+ EXPECT_CALL(*client1, OnStopped(_))
+ .WillOnce(Return());
+ EXPECT_CALL(*client1, OnRemoved(_))
+ .WillOnce(Return());
+ EXPECT_CALL(*client2, OnStopped(_))
.WillOnce(Return());
- EXPECT_CALL(*client_master1, OnRemoved(_))
+ EXPECT_CALL(*client2, OnRemoved(_))
.WillOnce(Return());
- EXPECT_CALL(*client_master2, OnStopped(_))
- .Times(0);
- video_capture_impl_->StopCapture(client_master1.get());
- video_capture_impl_->StopCapture(client_master2.get());
+ video_capture_impl_->StopCapture(client1.get());
+ video_capture_impl_->StopCapture(client2.get());
message_loop_->RunAllPending();
}
diff --git a/content/renderer/media/video_capture_module_impl.cc b/content/renderer/media/video_capture_module_impl.cc
index b691234..e50e561 100644
--- a/content/renderer/media/video_capture_module_impl.cc
+++ b/content/renderer/media/video_capture_module_impl.cc
@@ -16,7 +16,6 @@ VideoCaptureModuleImpl::VideoCaptureModuleImpl(
thread_("VideoCaptureModuleImpl"),
vc_manager_(vc_manager),
state_(media::VideoCapture::kStopped),
- got_first_frame_(false),
width_(-1),
height_(-1),
frame_rate_(-1),
@@ -160,7 +159,6 @@ void VideoCaptureModuleImpl::StartCaptureInternal(
cap.height = capability.height;
cap.max_fps = capability.maxFPS;
cap.raw_type = media::VideoFrame::I420;
- cap.resolution_fixed = true;
capture_engine_->StartCapture(this, cap);
}
@@ -191,7 +189,6 @@ void VideoCaptureModuleImpl::OnStoppedOnCaptureThread(
VLOG(1) << "Capture Stopped!!! ";
state_ = media::VideoCapture::kStopped;
- got_first_frame_ = false;
width_ = -1;
height_ = -1;
frame_rate_ = -1;
@@ -211,11 +208,6 @@ void VideoCaptureModuleImpl::OnBufferReadyOnCaptureThread(
if (state_ != media::VideoCapture::kStarted)
return;
- if (!got_first_frame_) {
- got_first_frame_ = true;
- start_time_ = buf->timestamp;
- }
-
frameInfo_.width = buf->width;
frameInfo_.height = buf->height;
frameInfo_.rawType = video_type_;
diff --git a/content/renderer/media/video_capture_module_impl.h b/content/renderer/media/video_capture_module_impl.h
index 3f6385a..fb3fb64 100644
--- a/content/renderer/media/video_capture_module_impl.h
+++ b/content/renderer/media/video_capture_module_impl.h
@@ -70,7 +70,6 @@ class VideoCaptureModuleImpl
// The video capture manager handles open/close of video capture devices.
scoped_refptr<VideoCaptureImplManager> vc_manager_;
media::VideoCapture::State state_;
- bool got_first_frame_;
WebRtc_UWord32 width_;
WebRtc_UWord32 height_;
WebRtc_Word32 frame_rate_;