Signal when shutting down DirectTransport.
Avoids starting the network thread when there are no packets to be read.
This allows the transport to shut down directly, which makes tests using
it able to quit faster, and not have to wait up to 10ms.
BUG=
R=stefan@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/2010004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@4524 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/video_engine/test/common/direct_transport.cc b/webrtc/video_engine/test/common/direct_transport.cc
index f28c208..b6a444e 100644
--- a/webrtc/video_engine/test/common/direct_transport.cc
+++ b/webrtc/video_engine/test/common/direct_transport.cc
@@ -19,6 +19,7 @@
: lock_(CriticalSectionWrapper::CreateCriticalSection()),
packet_event_(EventWrapper::Create()),
thread_(ThreadWrapper::CreateThread(NetworkProcess, this)),
+ shutting_down_(false),
receiver_(NULL) {
unsigned int thread_id;
EXPECT_TRUE(thread_->Start(thread_id));
@@ -26,7 +27,15 @@
DirectTransport::~DirectTransport() { StopSending(); }
-void DirectTransport::StopSending() { EXPECT_TRUE(thread_->Stop()); }
+void DirectTransport::StopSending() {
+ {
+ CriticalSectionScoped crit_(lock_.get());
+ shutting_down_ = true;
+ }
+
+ packet_event_->Set();
+ EXPECT_TRUE(thread_->Stop());
+}
void DirectTransport::SetReceiver(newapi::PacketReceiver* receiver) {
receiver_ = receiver;
@@ -65,7 +74,7 @@
while (true) {
Packet p;
{
- webrtc::CriticalSectionScoped crit(lock_.get());
+ CriticalSectionScoped crit(lock_.get());
if (packet_queue_.empty())
break;
p = packet_queue_.front();
@@ -74,7 +83,7 @@
receiver_->DeliverPacket(p.data, p.length);
}
- switch (packet_event_->Wait(10)) {
+ switch (packet_event_->Wait(WEBRTC_EVENT_INFINITE)) {
case kEventSignaled:
packet_event_->Reset();
break;
@@ -85,7 +94,8 @@
return true;
}
- return true;
+ CriticalSectionScoped crit(lock_.get());
+ return shutting_down_ ? false : true;
}
} // namespace test
} // namespace webrtc
diff --git a/webrtc/video_engine/test/common/direct_transport.h b/webrtc/video_engine/test/common/direct_transport.h
index 888ed46..642a306 100644
--- a/webrtc/video_engine/test/common/direct_transport.h
+++ b/webrtc/video_engine/test/common/direct_transport.h
@@ -57,6 +57,8 @@
scoped_ptr<EventWrapper> packet_event_;
scoped_ptr<ThreadWrapper> thread_;
+ bool shutting_down_;
+
std::deque<Packet> packet_queue_;
newapi::PacketReceiver* receiver_;
};