[asterisk-scf-commits] asterisk-scf/integration/media_rtp_pjmedia.git branch "replication" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Sun Jan 23 16:00:37 CST 2011
branch "replication" has been updated
via dcf83d9551f609836ba0cce86bd5dbb07e371541 (commit)
from a36a1c558a7d563e4ac69db343103cf2ebb29cda (commit)
Summary of changes:
test/TestRTPpjmedia.cpp | 124 ++++++++++++++++++++++++++++------------------
1 files changed, 75 insertions(+), 49 deletions(-)
- Log -----------------------------------------------------------------
commit dcf83d9551f609836ba0cce86bd5dbb07e371541
Author: Joshua Colp <jcolp at digium.com>
Date: Sun Jan 23 18:00:01 2011 -0400
Instead of using a sleep use a boost mutex lock and condition for signaling.
diff --git a/test/TestRTPpjmedia.cpp b/test/TestRTPpjmedia.cpp
index 2d87f8c..3b7cb2a 100644
--- a/test/TestRTPpjmedia.cpp
+++ b/test/TestRTPpjmedia.cpp
@@ -19,6 +19,8 @@
#include <boost/test/unit_test.hpp>
#include <boost/test/debug.hpp>
#include <boost/thread/thread.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/condition.hpp>
#include <Ice/Ice.h>
#include <IceBox/IceBox.h>
@@ -69,49 +71,6 @@ public:
typedef IceUtil::Handle<TestRtpReplicatorListener> TestRtpReplicatorListenerPtr;
-void TestRtpReplicatorListener::stateRemoved(const Ice::StringSeq& items, const Ice::Current&)
-{
-}
-
-void TestRtpReplicatorListener::stateSet(const RtpStateItemSeq& items, const Ice::Current&)
-{
- class visitor : public AsteriskSCF::Media::RTP::V1::RtpStateItemVisitor
- {
- public:
- visitor(TestRtpReplicatorListener *listener) : listener(listener)
- {
- }
-
- private:
- TestRtpReplicatorListener *listener;
-
- void visitGeneral(const RtpGeneralStateItemPtr &item, const Ice::Current &)
- {
- listener->mGeneral = item;
- }
-
- void visitSession(const RtpSessionStateItemPtr &item, const Ice::Current &)
- {
- listener->mSession = item;
- }
-
- void visitStreamSink(const RtpStreamSinkStateItemPtr &item, const Ice::Current &)
- {
- listener->mSink = item;
- }
-
- void visitStreamSource(const RtpStreamSourceStateItemPtr &item, const Ice::Current &)
- {
- listener->mSource = item;
- }
- } v(this);
-
- for (RtpStateItemSeq::const_iterator item = items.begin(); item != items.end(); ++item)
- {
- (*item)->visit(&v);
- }
-}
-
/**
* It seems odd that boost doesn't provide an easy way to access the GLOBAL_FIXTURE members.
* But it doesn't seem to, so I'm sharing global setup stuff here.
@@ -163,9 +122,71 @@ public:
* A sequence containing frames received via RTP.
*/
FrameSeq frames;
+
+ /**
+ * Lock to be used with the below condition, for when we get state information.
+ */
+ boost::mutex mLock;
+
+ /**
+ * Condition used to signal test thread that state was set.
+ */
+ boost::condition mCondition;
};
static SharedTestData Testbed;
+void TestRtpReplicatorListener::stateRemoved(const Ice::StringSeq& items, const Ice::Current&)
+{
+}
+
+void TestRtpReplicatorListener::stateSet(const RtpStateItemSeq& items, const Ice::Current&)
+{
+ class visitor : public AsteriskSCF::Media::RTP::V1::RtpStateItemVisitor
+ {
+ public:
+ visitor(TestRtpReplicatorListener *listener) : listener(listener)
+ {
+ }
+
+ private:
+ TestRtpReplicatorListener *listener;
+
+ void visitGeneral(const RtpGeneralStateItemPtr &item, const Ice::Current &)
+ {
+ listener->mGeneral = item;
+ boost::mutex::scoped_lock lock(Testbed.mLock);
+ Testbed.mCondition.notify_one();
+ }
+
+ void visitSession(const RtpSessionStateItemPtr &item, const Ice::Current &)
+ {
+ listener->mSession = item;
+ boost::mutex::scoped_lock lock(Testbed.mLock);
+ Testbed.mCondition.notify_one();
+ }
+
+ void visitStreamSink(const RtpStreamSinkStateItemPtr &item, const Ice::Current &)
+ {
+ listener->mSink = item;
+ boost::mutex::scoped_lock lock(Testbed.mLock);
+ Testbed.mCondition.notify_one();
+ }
+
+ void visitStreamSource(const RtpStreamSourceStateItemPtr &item, const Ice::Current &)
+ {
+ listener->mSource = item;
+ boost::mutex::scoped_lock lock(Testbed.mLock);
+ Testbed.mCondition.notify_one();
+ }
+ } v(this);
+
+ for (RtpStateItemSeq::const_iterator item = items.begin(); item != items.end(); ++item)
+ {
+ (*item)->visit(&v);
+ }
+}
+
+
class TestStreamSink : public StreamSink
{
public:
@@ -175,6 +196,8 @@ public:
void write(const AsteriskSCF::Media::V1::FrameSeq& frames, const Ice::Current&)
{
Testbed.frames = frames;
+ boost::mutex::scoped_lock lock(Testbed.mLock);
+ Testbed.mCondition.notify_one();
}
/**
@@ -363,7 +386,8 @@ BOOST_AUTO_TEST_CASE(AddListenertoStateReplicator)
BOOST_AUTO_TEST_CASE(CheckReplicatedGeneralStateItem)
{
// Since the RTP component is using a oneway invocation we wait here to ensure that the packet has been sent and processed
- boost::this_thread::sleep(boost::posix_time::seconds(1));
+ boost::mutex::scoped_lock lock(Testbed.mLock);
+ Testbed.mCondition.wait(lock);
BOOST_CHECK(Testbed.mListener->mGeneral);
}
@@ -392,7 +416,8 @@ BOOST_AUTO_TEST_CASE(AllocateRTPSession)
Testbed.session = service->allocate(formats);
// Give the RTP component time to replicate this session
- boost::this_thread::sleep(boost::posix_time::seconds(1));
+ boost::mutex::scoped_lock lock(Testbed.mLock);
+ Testbed.mCondition.wait(lock);
allocated = true;
}
@@ -753,7 +778,8 @@ BOOST_AUTO_TEST_CASE(SetupLoopback)
looped = true;
- boost::this_thread::sleep(boost::posix_time::seconds(1));
+ boost::mutex::scoped_lock lock(Testbed.mLock);
+ Testbed.mCondition.wait(lock);
}
catch (const Ice::Exception &e)
{
@@ -823,10 +849,10 @@ BOOST_AUTO_TEST_CASE(TransmitandReceiveFrame)
StreamSinkRTPPrx sink = StreamSinkRTPPrx::uncheckedCast(sinks.front());
sink->write(frames);
- /* In order to have the packet get sent and received we need to introduce a delay here, thus
- * why it exists.
+ /* It takes time for the packet to get sent and received so we wait until we get it here.
*/
- boost::this_thread::sleep(boost::posix_time::seconds(1));
+ boost::mutex::scoped_lock lock(Testbed.mLock);
+ Testbed.mCondition.wait(lock);
/* We only sent a single frame, so we should only get a single frame. */
AudioFramePtr received_frame;
-----------------------------------------------------------------------
--
asterisk-scf/integration/media_rtp_pjmedia.git
More information about the asterisk-scf-commits
mailing list