[asterisk-scf-commits] asterisk-scf/integration/media_rtp_pjmedia.git branch "nat-traversal" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Mon Apr 25 10:54:12 CDT 2011
branch "nat-traversal" has been created
at d173b7aa471e7ae3deb40dee93868170b8d6dda4 (commit)
- Log -----------------------------------------------------------------
commit d173b7aa471e7ae3deb40dee93868170b8d6dda4
Author: Brent Eagles <beagles at digium.com>
Date: Mon Apr 25 13:23:18 2011 -0230
Some in-progress NAT traversal changes.
diff --git a/local-slice/RtpStateReplicationIf.ice b/local-slice/RtpStateReplicationIf.ice
index 46a5014..254b50e 100644
--- a/local-slice/RtpStateReplicationIf.ice
+++ b/local-slice/RtpStateReplicationIf.ice
@@ -38,7 +38,7 @@ module V1
const string StateReplicatorComponentCategory = "RtpStateReplicatorComponent";
const string StateReplicatorDiscoveryCategory = "RtpStateReplicator";
- class RtpStateReplicatorParams extends AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams
+ unsliceable class RtpStateReplicatorParams extends AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams
{
string mName;
};
diff --git a/src/RTPICESession.cpp b/src/RTPICESession.cpp
new file mode 100644
index 0000000..1d75ede
--- /dev/null
+++ b/src/RTPICESession.cpp
@@ -0,0 +1,540 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#include <pjlib.h>
+#include <Ice/Ice.h>
+#include <IceUtil/UUID.h>
+
+#include <pjmedia.h>
+#include <pjnath.h>
+
+#include <AsteriskSCF/Media/MediaIf.h>
+#include <AsteriskSCF/Media/RTP/MediaRTPIf.h>
+#include <AsteriskSCF/System/Component/ReplicaIf.h>
+#include <AsteriskSCF/System/ExceptionsIf.h>
+#include <AsteriskSCF/SmartProxy.h>
+
+#include "RtpStateReplicationIf.h"
+
+#include "RTPSource.h"
+#include "RTPSink.h"
+
+#include "ServiceConfig.h"
+
+#include <boost/bind.hpp>
+
+using namespace std;
+using namespace AsteriskSCF::Media::V1;
+using namespace AsteriskSCF::Media::RTP::V1;
+
+namespace ICEMediaSession
+{
+static bool success(pj_status_t r)
+{
+ return r == PJ_SUCCESS;
+}
+
+static bool fail(pj_status_t r)
+{
+ return !success(r);
+}
+
+typedef AsteriskSCF::SmartProxy::SmartProxy<RtpStateReplicatorPrx> StateReplicatorPrx;
+
+class NATModule : public IceUtil::Shared
+{
+public:
+ NATModule(const PjlibEnvironmentPtr& environ, const Ice::PropertiesPtr& props, const Logger& logger)
+ {
+ std::string stunServerProperty = props->getProperty("Media.STUN.Server");
+ //
+ // XXX:
+ // This actually isn't necessarily an error, the STUN server can be determined from
+ // DNS records. Let's leave it for now.
+ //
+ //
+ if (stunServerProperty.empty())
+ {
+ throw InternalInitializationException("No STUN server configured");
+ }
+ Ice::Int portProperty = props->getPropertyAsIntWithDefault("Media.STUN.Port", PJ_STUN_PORT);
+ if (portProperty > UINT_MAX)
+ {
+ logger(Warning) << "Property `Media.STUN.Port' is out of range for IP port numbers, defaulting to "
+ << PJ_STUN_PORT;
+ portProperty = PJ_STUN_PORT;
+ }
+ pj_ice_strans_cfg_default(&mICECfg);
+ pj_stun_config_init(&mICECfg.stun_cfg, environ->getPoolFactory(), 0
+ pjmedia_endpoint_get_ioqueue(environ->getMediaEndpoint()), 0);
+ pj_status_t result = pj_timer_heap_create(environ->getPool(),
+ props->getPropertyAsIntWithDefault("Media.PJMedia.TimerHeap.Size", 1000), &mICECfg.stun_cfg.timer_heap);
+ if (fail(result))
+ {
+ throw InternalInitializationException("Unable to initialize timer heap.");
+ }
+ pj_strdup2(environ->getPool(), mICECfg.stun.server, stunServerProperty.c_str());
+ mICECfg.stun.port = portProperty;
+
+ mICECfg.stun.max_host_cands = props->getPropertyAsIntWithDefault("Media.ICE.MaxCandidates", 2);
+ if (props->getPropertyAsIntWithDefault("Media.TURN.Enable", 0) > 0)
+ {
+ string turnServer = props->getProperty("Media.TURN.Server.Hostname");
+ //
+ // XXX: verify default TURN server port number.
+ //
+ Ice::Int turnPort = props->getPropertyAsIntWithDefault("Media.TURN.Server.Port", 3479);
+ pj_strdup2(environ->getPool(), mICE.turn.server, turnServer.c_str());
+ mICE.turn.server.port = turnPort;
+
+ //
+ // TODO: TURN QoS settings.
+ //
+ }
+ //
+ // TODO: QoS.
+ //
+ }
+
+ void start()
+ {
+ //
+ // commence resolving STUN server, etc.
+ //
+ }
+
+protected:
+ ~NATModule()
+ {
+ pj_time_heap_destroy(&mICECfg.timer_heap);
+ }
+
+private:
+ pj_ice_strans_cfg mICECfg;
+
+};
+
+typedef IceUtil::Handle<NATModule> NATModulePtr;
+
+class PjLibEnvironment : public IceUtil::Shared
+{
+public:
+ PjLibEnvironment(pj_pool_factory* poolFactory, const Ice::PropertiesPtr& props, const Logger& logger) :
+ mPoolFactory(poolFactory),
+ mProperties(props),
+ mMediaEndpoint(0),
+ mPool(0),
+ mLogger(logger)
+ {
+ pj_status_t result = pjmedia_endpt_create(mPjLib->getPoolFactory(), 0, 1, &mEndpoint);
+ if (fail(result))
+ {
+ throw InternalInitializationException("Unable to create PJMEDIA endpoint.");
+ }
+ }
+
+ pj_pool_factory* getPoolFactory() const
+ {
+ boost::shared_lock<boost::shared_mutex> lock(mLock);
+ return mPoolFactory;
+ }
+
+ pjmedia_endpoint* getMediaEndpoint() const
+ {
+ boost::shared_lock<boost::shared_mutex> lock(mLock);
+ return mMediaEndpoint;
+ }
+
+ pj_pool_t* getPool() const
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mLock);
+ if (!mPool)
+ {
+ pj_status_t result = pjmedia_endpt_create_pool(mMediaEndpoint, "SESSPOOL", 1024, 512);
+ if (fail(result))
+ {
+ throw InternalInitializationException("Unable to initialize pool.");
+ }
+ }
+ return mPool;
+ }
+
+ NATModulePtr getNATModule()
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mLock);
+ if (!mNATModule)
+ {
+ mNATModule = new NATModule(this, mProperties, mLogger);
+ }
+ }
+
+ void destroy()
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mLock);
+ mNATModule = 0;
+ }
+
+private:
+ mutable boost::shared_mutex mLock;
+ pj_pool_factory* mPoolFactory;
+ Ice::PropertiesPtr mProperties;
+ pjmedia_endpoint* mMediaEndpoint;
+ NATModulePtr mNATModule;
+ pj_pool_t* mPool;
+ Logger mLogger;
+};
+typedef IceUtil::Handle<PjLibEnvironment> PjLibEnvironmentPtr;
+
+class RTPSessionImpl : public RTPSession
+{
+public:
+
+ //
+ // RTPSessionImpl uses a two-stage initialization to reduce duplication
+ // amongst constructor versions and avoid exception prone calls in
+ // the constructor itself.
+ //
+ RTPSessionImpl(const FormatSeq& formats, const PjLibEnvironmentPtr& pjLib,
+ const ReplicatorPtr& replicaService, const StateReplicatorPrx& replicator);
+
+ void initialize();
+
+ //
+ // Slice to C++ mapping.
+ //
+
+ //
+ // Session
+ //
+ StreamSourceSeq getSources(const Ice::Current& current);
+ StreamSinkSeq getSinks(const Ice::Current& current);
+ std::string getId(const Ice::Current& current);
+
+ //
+ // RTPSession.
+ //
+ void associatePayLoads(const PayLoadMap& mappings, const Ice::Current& current);
+ void useRTCP(bool enable, const Ice::Current& current);
+ RTCPSessionPrx getRTCPSession(const Ice::Current& current);
+ void release(const Ice::Current& current);
+
+ //
+ // Internal methods.
+ //
+private:
+ FormatSeq mFormats;
+ PjLibEnvironmentPtr mPjLib;
+ ReplicatorPtr mReplicaControl;
+ StateReplicatorPrx mReplicator;
+
+ //
+ // TODO: Should the endpoint belong to a different object. Could a single endpoint
+ // have multiple transports?
+ //
+ pjmedia_endpt* mEndpoint;
+ pjmedia_transport* mTransport;
+
+};
+
+typedef IceUtil::Handle<RTPSessionImpl> RTPSessionImplPtr;
+
+class SinkImpl : public StreamSinkRTP
+{
+public:
+
+ SinkImpl();
+
+ //
+ // Slice to C++ mapping.
+ //
+
+ //
+ // StreamSink
+ //
+ void write(const FrameSeq& frames, const Ice::Current& current);
+ void setSource(const StreamSourcePrx& source, const Ice::Current& current);
+ StreamSourcePrx getSource(const Ice::Current& current);
+ FormatSeq getFormats(const Ice::Current& current);
+ std::string getId(const Ice::Current& current);
+
+ //
+ // StreamSinkRTP
+ //
+ void setRemoteDetails(const std::string& address, int port, const Ice::Current& current);
+ std::string getRemoteAddress(const Ice::Current& current);
+ int getRemotePort(const Ice::Current& current);
+
+ //
+ // Internal methods.
+ //
+ void destroy();
+};
+
+class SourceImpl : public StreamSourceRTP
+{
+public:
+ SourceImpl();
+
+ //
+ // Slice to C++ mapping.
+ //
+
+ //
+ // StreamSource
+ //
+ void setSink(const StreamSinkPrx& destination, const Ice::Current& current);
+ StreamSinkPrx getSink(const Ice::Current& current);
+ FormatSeq getFormats(const Ice::Current& current);
+ std::string getId( const Ice::Current& current);
+ void requestFormat(const FormatPtr& newFormat, const Ice::Current& current);
+
+ //
+ // Internal methods.
+ //
+ void destroy();
+};
+
+/**
+ *
+ * Base class to allow some polymorphic behavior on different pjmedia based transports.
+ *
+ **/
+class PJMediaTransport : public IceUtil::Shared
+{
+public:
+
+ pjmedia_transport* getTransport()
+ {
+ boost::shared_lock<boost::shared_mutex> lock(mLock);
+ return mTransport;
+ }
+
+ Ice::Int getPort()
+ {
+ boost::shared_lock<boost::shared_mutex> lock(mLock);
+ return mPort;
+
+ void destroy()
+ {
+ boost::unique_locK<boost::shared_mutex> lock(mLock);
+ pjmedia_transport_close(mTransport);
+ mPort = 0;
+ mTransport = 0;
+ }
+
+protected:
+ boost::shared_mutex mLock;
+ pjmedia_transport* mTransport;
+ Ice::Int mPort;
+
+ PJMediaTransport(pjmedia_transport* t, const Ice::Int p) :
+ mTransport(t),
+ mPort(p)
+ {
+ }
+};
+
+class ICETransport : public PJMediaTransport
+{
+ //
+ // Hidden and unimplemented.
+ //
+ ICETransport(const ICETransport&);
+ void operator=(const ICETransport&);
+
+public:
+ static IceUtil::Handle<ICETransport> create(const PjLibEnvironmentPtr& pjlib)
+ {
+ pjmedia_ice_create(mPjLib->getMediaEndpoint(), "ASCF_ICE_MEDIA", 10, 0, &ICECallbackAdapter::onIceComplete,
+ &mTransport);
+ }
+};
+typedef IceUtil::Handle<ICETransport> ICETransportPtr;
+
+class UDPTransport : public PJMediaTransport
+{
+ //
+ // Hidden and unimplemented.
+ //
+ UDPTransport(const UDPTransport&);
+ void operator=(const UDPTransport&);
+
+public:
+ //
+ // Replicant version.
+ //
+ static IceUtil::Handle<UDPTransport> create(const PjLibEnvironmentPtr& pjlib, Ice::Int port)
+ {
+ pjmedia_transport* transport;
+ pj_status_t result = pjmedia_transport_udp_create2(pjlib->getMediaEndpoint(), "RTP", 0, port, transport);
+ if (fail(result))
+ {
+ throw InternalInitializationException("Unable to initialize UDP media transport on "
+ "replicant, port conflict!");
+ }
+ return new UDPTransport(transport, port);
+ }
+
+ //
+ // Primary version.
+ //
+ static IceUtil::Handle<UDPTransport> create(const PjLibEnvironmentPtr& pjlib, Ice::Int port)
+ {
+ const Ice::Int minPort =
+ properties->getPropertyAsIntWithDefault("AsteriskSCF.Media.Transport.UDPTransport.MinPort",
+ DefaultRTPPortMinimum);
+ const Ice::Int maxPort =
+ properties->getPropertyAsIntWithDefault("AsteriskSCF.Media.Transport.UDPTransport.MaxPort",
+ DefaultRTPPortMaximum);
+
+ //
+ // Now create some transport we can use to actually send or receive the media. The candidate ports increment by
+ // two to allow "room" for both a control and a data port.
+ //
+ for (Ice::Int port = minPort; port < maxPort && port <= USHRT_MAX ; port +=2)
+ {
+ pjmedia_transport* transport;
+ pj_result_t result = pjmedia_transport_udp_create2(pjlib->getMediaEndpoint(), "RTP", 0, port, 0, &transport);
+ if (success(result))
+ {
+ return new UDPTransport(transport, port);
+ }
+ }
+ throw InternalInitializationException("Unable to initialize UDP media transport");
+ }
+
+private:
+ UDPTransport(pjmedia_transport* t, const Ice::Int port) :
+ PJMediaTransport(t, port)
+ {
+ }
+};
+typedef IceUtil::Handle<UDPTransport> UDPTransportPtr;
+
+pjmedia_transport* PJMediaTransport::getTransport()
+{
+ boost::shared_lock<boost::shared_mutex> lock(mLock);
+ return mTransport;
+}
+
+class ICECallbackAdapter
+{
+public:
+ typedef std::map<pjmedia_transport*, RTPSessionImplPtr> TransportMap;
+
+ static void addEntry(pjmedia_transport* transport, const RTPSessionImplPtr& callback)
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mLock);
+ TransportMap::iterator i = mTransportMap.find(transport);
+ if (i != mTransportMap.end())
+ {
+ mTransportMap.insert(make_pair(transport, callback));
+ }
+ }
+
+ static void onICEComplete(pjmedia_transport* transport, pj_ice_strans_op operation, pj_status_t status)
+ {
+ switch (operation)
+ {
+ //
+ // TODO: Fill out.
+ //
+ case PJ_ICE_STRANS_OP_INIT:
+ //
+ // Initialization is complete. FWICT, this should not get here.
+ //
+ break;
+ case PJ_ICE_STRANS_OP_NEGOTIATION:
+ //
+ // Negotiation is complete.
+ //
+ {
+ boost::shared_lock<boost::shared_mutex> lock(mLock);
+ TransportMap::iterator i = mTransportMap.find(transport);
+ if (i == mTransportMap.end())
+ {
+ //
+ // XXX This is a "possibly" an exceptional condition. We'll skip the assert/thing for now, but this
+ // should really log or something.
+ //
+ }
+ i->second->onComplete(operation, status);
+ }
+ break;
+ case PJ_ICE_STRANS_OP_KEEP_ALIVE:
+ //
+ // Keep alive has successfully completed. FWICT this should not get here.
+ //
+ break;
+ default:
+ };
+ }
+
+private:
+
+ static TransportMap mTransportMap;
+ static boost::shared_mutex mLock;
+};
+
+//
+// Static member initializations.
+//
+IceCallbackAdapter::TransportMap IceCallbackAdapter::mTransportMap;
+boost::shared_mutex IceCallbackAdapter::mLock;
+
+}
+using namespace ICEMediaSession;
+
+RTPSessionImpl::RTPSessionImpl(const FormatSeq& formats, const PjLibEnvironmentPtr& pjLib,
+ const ReplicatorPtr& replicaService, const StateReplicatorPrx& replicator) :
+ mFormats(formats),
+ mPjLib(pjLib),
+ mReplicaControl(replicaService),
+ mReplicator(replicator),
+ mBasePort(0)
+{
+}
+
+void RTPSessionImpl::initialize(const Ice::PropertiesPtr& properties)
+{
+#if 0
+ //
+ // XXX binding local ports with an ICE transport?
+ //
+ const int minPort = properties->getPropertyAsIntWithDefault("AsteriskSCF.Media.Transport.ICETransport.MinPort",
+ DefaultRTPPortMinimum);
+ const int maxPort = properties->getPropertyAsIntWithDefault("AsteriskSCF.Media.Transport.ICETransport.MaxPort",
+ DefaultRTPPortMaximum);
+
+ for (int candidatePort = minPort; port < maxPort; candidatePort +=2)
+ {
+
+ }
+#endif
+ pjmedia_ice_create(mPjLib->getMediaEndpoint(), "ASCF_ICE_MEDIA", 10, 0, &ICECallbackAdapter::onIceComplete,
+ &mTransport);
+}
+
+RTPSessionPrx RTPICESession::create(const Ice::ObjectAdapterPtr& adapter, const Ice::Identity& id,
+ const FormatSeq& formats, pj_pool_factory* factory, const ReplicatPtr& replicaService,
+ const AsteriskSCF::SmartProxy::SmartProxy<RtpStateReplicatorPrx>& stateReplicator)
+{
+ RTPSessionImplPtr servant(new RTPSessionImpl(formats, new PjLibEnvironment(factory), replicaService,
+ stateReplicator));
+ assert(adapter);
+ servant->initialize(adapter->getCommunicator()->getProperties());
+ return RTPSessionPrx::uncheckedCast(adapter->add(servant, id));
+}
diff --git a/src/RTPICESession.h b/src/RTPICESession.h
new file mode 100644
index 0000000..a886a0c
--- /dev/null
+++ b/src/RTPICESession.h
@@ -0,0 +1,17 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#pragma once
diff --git a/src/ServiceConfig.h b/src/ServiceConfig.h
new file mode 100644
index 0000000..ff1cf59
--- /dev/null
+++ b/src/ServiceConfig.h
@@ -0,0 +1,35 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#pragma once
+
+namespace AsteriskSCF
+{
+namespace PJMediaRTP
+{
+
+/**
+ * Default value for where we should start allocating RTP and RTCP ports from.
+ */
+const int DefaultRTPPortMinimum = 10000;
+
+/**
+ * Default value for where we should stop allocating RTP and RTCP ports.
+ */
+const int DefaultRTPPortMaximum = 20000;
+
+}; /* End of namespace PJMediaRTP */
+}; /* End of namespace AsteriskSCF */
commit 18201f08187367d3c2cefe726614cd495b06dd0d
Author: Brent Eagles <beagles at digium.com>
Date: Tue Apr 19 13:21:42 2011 -0230
Changes in progress
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1f2b232..cf9d79d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -20,6 +20,8 @@ asterisk_scf_component_add_file(media_rtp_pjmedia RTPSink.cpp)
asterisk_scf_component_add_file(media_rtp_pjmedia RTPSession.h)
asterisk_scf_component_add_file(media_rtp_pjmedia RTPSource.h)
asterisk_scf_component_add_file(media_rtp_pjmedia RTPSink.h)
+asterisk_scf_component_add_file(media_rtp_pjmedia RTPICESession.cpp)
+asterisk_scf_component_add_file(media_rtp_pjmedia RTPICESession.h)
asterisk_scf_component_add_file(media_rtp_pjmedia RtpStateReplicatorListener.cpp)
asterisk_scf_component_add_file(media_rtp_pjmedia RtpStateReplicator.h)
asterisk_scf_component_add_slice(media_rtp_pjmedia ../local-slice/RtpStateReplicationIf.ice)
diff --git a/src/MediaRTPpjmedia.cpp b/src/MediaRTPpjmedia.cpp
index f041e4f..b3233b4 100644
--- a/src/MediaRTPpjmedia.cpp
+++ b/src/MediaRTPpjmedia.cpp
@@ -14,11 +14,11 @@
* at the top of the source tree.
*/
+#include <pjlib.h>
#include <Ice/Ice.h>
#include <IceBox/IceBox.h>
#include <IceUtil/UUID.h>
-#include <pjlib.h>
#include <pjmedia.h>
#include <boost/shared_ptr.hpp>
@@ -335,7 +335,7 @@ RTPMediaServiceImpl::RTPMediaServiceImpl(const Ice::ObjectAdapterPtr& adapter, c
pj_caching_pool_init(&mCachingPool, &pj_pool_factory_default_policy, 0);
/* Initialize the memory pool that pjmedia will draw from. */
- mMemoryPool = pj_pool_create(&mCachingPool.factory, "media_rtp_pjmedia", 1000, 1000, NULL);
+ mMemoryPool = pj_pool_create(&mCachingPool.factory, "media_rtp_pjmedia", 1024, 1024, 0);
}
/**
diff --git a/src/RTPSession.cpp b/src/RTPSession.cpp
index 5a8c334..7aedcf9 100644
--- a/src/RTPSession.cpp
+++ b/src/RTPSession.cpp
@@ -14,10 +14,10 @@
* at the top of the source tree.
*/
+#include <pjlib.h>
#include <Ice/Ice.h>
#include <IceUtil/UUID.h>
-#include <pjlib.h>
#include <pjmedia.h>
#include <AsteriskSCF/Media/MediaIf.h>
@@ -31,6 +31,7 @@
#include "RTPSession.h"
#include "RTPSource.h"
#include "RTPSink.h"
+#include "ServiceConfig.h"
using namespace std;
using namespace AsteriskSCF::Core::Discovery::V1;
@@ -41,16 +42,6 @@ using namespace AsteriskSCF::System::V1;
using namespace AsteriskSCF::SmartProxy;
/**
- * Default value for where we should start allocating RTP and RTCP ports from.
- */
-#define DEFAULT_RTP_PORT_MINIMUM 10000
-
-/**
- * Default value for where we should stop allocating RTP and RTCP ports.
- */
-#define DEFAULT_RTP_PORT_MAXIMUM 20000
-
-/**
* Private implementation details for the RTPSessionImpl class.
*/
class RTPSessionImplPriv
@@ -130,6 +121,12 @@ public:
AsteriskSCF::SmartProxy::SmartProxy<RtpStateReplicatorPrx> mStateReplicator;
};
+
+//
+// TODO: Construction of an object should not add/remove elements to an object adapter IF the lifecycle
+// of the objects (actual and logical) depend on the successful construction of the object being created
+//
+
/**
* Constructor for the RTPSessionImpl class (used by Ice).
*/
@@ -155,7 +152,11 @@ RTPSessionImpl::RTPSessionImpl(const Ice::ObjectAdapterPtr& adapter, const Forma
}
/* Now create some transport we can use to actually send or receive the media. */
- for (int port = DEFAULT_RTP_PORT_MINIMUM; port < DEFAULT_RTP_PORT_MAXIMUM; port += 2)
+
+ //
+ // The candidate ports increment by two to allow "room" for both a control and a data port.
+ //
+ for (int port = DefaultRTPPortMinimum; port < DefaultRTPPortMaximum; port += 2)
{
if ((status = pjmedia_transport_udp_create2(mImpl->mEndpoint, "RTP", NULL, port, 0, &mImpl->mTransport)) ==
PJ_SUCCESS)
diff --git a/src/RTPSink.cpp b/src/RTPSink.cpp
index 2324799..caea14d 100644
--- a/src/RTPSink.cpp
+++ b/src/RTPSink.cpp
@@ -14,10 +14,10 @@
* at the top of the source tree.
*/
+#include <pjlib.h>
#include <Ice/Ice.h>
#include <IceUtil/UUID.h>
-#include <pjlib.h>
#include <pjmedia.h>
#include <AsteriskSCF/Media/MediaIf.h>
diff --git a/src/RtpStateReplicatorApp.cpp b/src/RtpStateReplicatorApp.cpp
index 91c0e37..2269eed 100644
--- a/src/RtpStateReplicatorApp.cpp
+++ b/src/RtpStateReplicatorApp.cpp
@@ -14,13 +14,13 @@
* at the top of the source tree.
*/
+#include <pjlib.h>
+
#include <Ice/Ice.h>
#include <IceUtil/UUID.h>
#include <IceStorm/IceStorm.h>
#include <IceBox/IceBox.h>
-#include <pjlib.h>
-
#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
#include <AsteriskSCF/System/Component/ComponentServiceIf.h>
#include <AsteriskSCF/Logger/IceLogger.h>
diff --git a/src/RtpStateReplicatorListener.cpp b/src/RtpStateReplicatorListener.cpp
index b47f408..1dfff9a 100644
--- a/src/RtpStateReplicatorListener.cpp
+++ b/src/RtpStateReplicatorListener.cpp
@@ -13,13 +13,12 @@
* the GNU General Public License Version 2. See the LICENSE.txt file
* at the top of the source tree.
*/
-
+#include <pjlib.h>
#include <IceUtil/UUID.h>
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
-#include <pjlib.h>
#include <pjmedia.h>
#include <AsteriskSCF/System/Component/ReplicaIf.h>
commit 0bde39196d3a9592097914cd3a544a0cd106fa9a
Author: Brent Eagles <beagles at digium.com>
Date: Fri Apr 1 13:16:55 2011 -0230
Capture changes in progress
diff --git a/src/RTPSession.cpp b/src/RTPSession.cpp
index d4e0381..5a8c334 100644
--- a/src/RTPSession.cpp
+++ b/src/RTPSession.cpp
@@ -23,6 +23,7 @@
#include <AsteriskSCF/Media/MediaIf.h>
#include <AsteriskSCF/Media/RTP/MediaRTPIf.h>
#include <AsteriskSCF/System/Component/ReplicaIf.h>
+#include <AsteriskSCF/System/ExceptionsIf.h>
#include <AsteriskSCF/SmartProxy.h>
#include "RtpStateReplicationIf.h"
@@ -36,6 +37,7 @@ using namespace AsteriskSCF::Core::Discovery::V1;
using namespace AsteriskSCF::Media::V1;
using namespace AsteriskSCF::Media::RTP::V1;
using namespace AsteriskSCF::System::Component::V1;
+using namespace AsteriskSCF::System::V1;
using namespace AsteriskSCF::SmartProxy;
/**
@@ -137,6 +139,10 @@ RTPSessionImpl::RTPSessionImpl(const Ice::ObjectAdapterPtr& adapter, const Forma
mImpl(new RTPSessionImplPriv(adapter, formats, replicaService, stateReplicator))
{
/* Add ourselves to the ICE ASM so we can be used. */
+
+ //
+ // XXX: It's sketchy to add a servant to an object adapter in it's constructor.
+ //
mImpl->mProxy = RTPSessionPrx::uncheckedCast(adapter->addWithUUID(this));
/* Create an endpoint in pjmedia for our media. */
@@ -145,6 +151,7 @@ RTPSessionImpl::RTPSessionImpl(const Ice::ObjectAdapterPtr& adapter, const Forma
if (status != PJ_SUCCESS)
{
/* TODO: This is bad... we can't go on! */
+ throw InternalInitializationException("Unable to created PJMEDIA endpoint!");
}
/* Now create some transport we can use to actually send or receive the media. */
commit 5a8aa0e39283ebc8eed7883d0b6cbb1867e3863b
Author: Brent Eagles <beagles at digium.com>
Date: Mon Mar 21 11:19:59 2011 -0230
* Update method signatures to pass smart pointers, references and proxies
by const ref.
* Split some long lines
diff --git a/src/MediaRTPpjmedia.cpp b/src/MediaRTPpjmedia.cpp
index 4a1d0ee..f041e4f 100644
--- a/src/MediaRTPpjmedia.cpp
+++ b/src/MediaRTPpjmedia.cpp
@@ -59,7 +59,8 @@ static const string MediaServiceId("RTPMediaService");
class RTPMediaServiceImpl : public RTPMediaService
{
public:
- RTPMediaServiceImpl(Ice::ObjectAdapterPtr, ReplicaPtr, AsteriskSCF::SmartProxy::SmartProxy<RtpStateReplicatorPrx>);
+ RTPMediaServiceImpl(const Ice::ObjectAdapterPtr&, const ReplicaPtr&,
+ const AsteriskSCF::SmartProxy::SmartProxy<RtpStateReplicatorPrx>&);
RTPSessionPrx allocate(const FormatSeq&, const Ice::Current&);
pj_pool_factory *getPoolFactory() { return &mCachingPool.factory; };
private:
@@ -100,7 +101,7 @@ typedef IceUtil::Handle<RTPMediaServiceImpl> RTPMediaServiceImplPtr;
class ReplicaImpl : public Replica
{
public:
- ReplicaImpl(Ice::ObjectAdapterPtr adapter) : mAdapter(adapter), mPaused(false), mActive(true) { }
+ ReplicaImpl(const Ice::ObjectAdapterPtr& adapter) : mAdapter(adapter), mPaused(false), mActive(true) { }
bool isActive(const Ice::Current&)
{
@@ -111,9 +112,11 @@ public:
{
mActive = true;
- for (vector<AsteriskSCF::System::Component::V1::ReplicaListenerPrx>::const_iterator listener = mListeners.begin(); listener != mListeners.end(); ++listener)
+ for (vector<AsteriskSCF::System::Component::V1::ReplicaListenerPrx>::const_iterator listener =
+ mListeners.begin(); listener != mListeners.end(); ++listener)
{
- (*listener)->activated(ReplicaPrx::uncheckedCast(mAdapter->createDirectProxy(mAdapter->getCommunicator()->stringToIdentity(ReplicaServiceId))));
+ (*listener)->activated(ReplicaPrx::uncheckedCast(
+ mAdapter->createDirectProxy(mAdapter->getCommunicator()->stringToIdentity(ReplicaServiceId))));
}
return true;
@@ -123,9 +126,11 @@ public:
{
mActive = false;
- for (vector<AsteriskSCF::System::Component::V1::ReplicaListenerPrx>::const_iterator listener = mListeners.begin(); listener != mListeners.end(); ++listener)
+ for (vector<AsteriskSCF::System::Component::V1::ReplicaListenerPrx>::const_iterator listener =
+ mListeners.begin(); listener != mListeners.end(); ++listener)
{
- (*listener)->onStandby(ReplicaPrx::uncheckedCast(mAdapter->createDirectProxy(mAdapter->getCommunicator()->stringToIdentity(ReplicaServiceId))));
+ (*listener)->onStandby(ReplicaPrx::uncheckedCast(
+ mAdapter->createDirectProxy(mAdapter->getCommunicator()->stringToIdentity(ReplicaServiceId))));
}
}
@@ -226,7 +231,8 @@ public:
/**
* A constructor for this implementation which just sets a few variables, nothing extreme.
*/
- ComponentServicepjmediaImpl(MediaRTPpjmediaApp& app, RtpGeneralStateItemPtr generalState) : mApplication(app), mGeneralState(generalState) { };
+ ComponentServicepjmediaImpl(MediaRTPpjmediaApp& app, const RtpGeneralStateItemPtr& generalState) :
+ mApplication(app), mGeneralState(generalState) { };
/**
* An implementation of the suspend method which actually suspends ourselves
@@ -321,7 +327,8 @@ private:
/**
* Constructor for the RTPMediaServiceImpl class.
*/
-RTPMediaServiceImpl::RTPMediaServiceImpl(Ice::ObjectAdapterPtr adapter, ReplicaPtr replicaService, AsteriskSCF::SmartProxy::SmartProxy<RtpStateReplicatorPrx> stateReplicator) :
+RTPMediaServiceImpl::RTPMediaServiceImpl(const Ice::ObjectAdapterPtr& adapter, const ReplicaPtr& replicaService,
+ const AsteriskSCF::SmartProxy::SmartProxy<RtpStateReplicatorPrx>& stateReplicator) :
mAdapter(adapter), mReplicaService(replicaService), mStateReplicator(stateReplicator)
{
/* Initialize the memory caching pool using default policy as specified by pjlib. */
@@ -336,19 +343,20 @@ RTPMediaServiceImpl::RTPMediaServiceImpl(Ice::ObjectAdapterPtr adapter, ReplicaP
*/
RTPSessionPrx RTPMediaServiceImpl::allocate(const FormatSeq& formats, const Ice::Current&)
{
- RTPSessionImplPtr session = new RTPSessionImpl(mAdapter, formats, &mCachingPool.factory, mReplicaService, mStateReplicator);
+ RTPSessionImplPtr session =
+ new RTPSessionImpl(mAdapter, formats, &mCachingPool.factory, mReplicaService, mStateReplicator);
return session->getProxy();
}
/**
* Implementation of the IceBox::Service::start method.
*/
-void MediaRTPpjmediaApp::start(const std::string& name, const Ice::CommunicatorPtr& communicator, const Ice::StringSeq& args)
+void MediaRTPpjmediaApp::start(const std::string& name, const Ice::CommunicatorPtr& communicator,
+ const Ice::StringSeq& args)
{
// we need a logger before we're ready to build the real communicator.
// use the one we're provided to create the IceLogger.
- mLoggerAdapter = communicator->createObjectAdapter(
- "MediaRTPpjmediaAdapterLogger");
+ mLoggerAdapter = communicator->createObjectAdapter("MediaRTPpjmediaAdapterLogger");
ConfiguredIceLoggerPtr iceLogger = createIceLogger(mLoggerAdapter);
getLoggerFactory().setLogOutput(iceLogger->getLogger());
mLoggerAdapter->activate();
@@ -388,7 +396,8 @@ void MediaRTPpjmediaApp::start(const std::string& name, const Ice::CommunicatorP
lg(Info) << "Activated pjmedia rtp component media service." << endl;
- ServiceLocatorManagementPrx management = ServiceLocatorManagementPrx::checkedCast(mCommunicator->propertyToProxy("ServiceLocatorManagementProxy"));
+ ServiceLocatorManagementPrx management =
+ ServiceLocatorManagementPrx::checkedCast(mCommunicator->propertyToProxy("ServiceLocatorManagementProxy"));
// The service locator is required for state replicator operation, so go ahead and find it
ServiceLocatorPrx locator = ServiceLocatorPrx::checkedCast(mCommunicator->propertyToProxy("LocatorService.Proxy"));
@@ -396,7 +405,8 @@ void MediaRTPpjmediaApp::start(const std::string& name, const Ice::CommunicatorP
// Look for the configured state replicator or default one
RtpStateReplicatorParamsPtr replicatorParams = new RtpStateReplicatorParams();
replicatorParams->category = StateReplicatorDiscoveryCategory;
- replicatorParams->mName = mCommunicator->getProperties()->getPropertyWithDefault("Sip.StateReplicatorName", "default");
+ replicatorParams->mName =
+ mCommunicator->getProperties()->getPropertyWithDefault("Sip.StateReplicatorName", "default");
try
{
@@ -408,12 +418,15 @@ void MediaRTPpjmediaApp::start(const std::string& name, const Ice::CommunicatorP
lg(Error) << "State replicator could not be found, operating without.";
}
- RTPMediaServiceImplPtr rtpmediaservice = new RTPMediaServiceImpl(mGlobalAdapter, mReplicaService, mStateReplicator);
+ RTPMediaServiceImplPtr rtpmediaservice =
+ new RTPMediaServiceImpl(mGlobalAdapter, mReplicaService, mStateReplicator);
if (mStateReplicator)
{
- mReplicatorListener = new RtpStateReplicatorListenerI(mGlobalAdapter, rtpmediaservice->getPoolFactory(), mGeneralState);
- mReplicatorListenerProxy = RtpStateReplicatorListenerPrx::uncheckedCast(mLocalAdapter->addWithUUID(mReplicatorListener));
+ mReplicatorListener =
+ new RtpStateReplicatorListenerI(mGlobalAdapter, rtpmediaservice->getPoolFactory(), mGeneralState);
+ mReplicatorListenerProxy =
+ RtpStateReplicatorListenerPrx::uncheckedCast(mLocalAdapter->addWithUUID(mReplicatorListener));
if (mCommunicator->getProperties()->getPropertyWithDefault("Rtp.StateReplicatorListener", "no") == "yes")
{
@@ -434,7 +447,8 @@ void MediaRTPpjmediaApp::start(const std::string& name, const Ice::CommunicatorP
if (mReplicaService->isActive() == true)
{
- mGeneralState->mServiceManagement = ServiceManagementPrx::uncheckedCast(management->addService(RTPMediaServiceProxy, "media_rtp_pjmedia"));
+ mGeneralState->mServiceManagement = ServiceManagementPrx::uncheckedCast(
+ management->addService(RTPMediaServiceProxy, "media_rtp_pjmedia"));
/* Now we can add some parameters to help find us. */
genericparams->category = "rtp";
mGeneralState->mServiceManagement->addLocatorParams(genericparams, "");
@@ -442,10 +456,12 @@ void MediaRTPpjmediaApp::start(const std::string& name, const Ice::CommunicatorP
/* One must provide a component service to manage us, if someone wants to */
ComponentServicePtr ComponentService = new ComponentServicepjmediaImpl(*this, mGeneralState);
- ComponentServicePrx ComponentServiceProxy = ComponentServicePrx::uncheckedCast(mLocalAdapter->addWithUUID(ComponentService));
+ ComponentServicePrx ComponentServiceProxy =
+ ComponentServicePrx::uncheckedCast(mLocalAdapter->addWithUUID(ComponentService));
/* Let's add the component service to the service locator first */
- mComponentServiceManagement = ServiceManagementPrx::uncheckedCast(management->addService(ComponentServiceProxy, "media_rtp_pjmedia"));
+ mComponentServiceManagement =
+ ServiceManagementPrx::uncheckedCast(management->addService(ComponentServiceProxy, "media_rtp_pjmedia"));
genericparams->category = "Component/media_rtp_pjmedia";
mComponentServiceManagement->addLocatorParams(genericparams, "");
diff --git a/src/RTPSession.cpp b/src/RTPSession.cpp
index 5e7f33e..d4e0381 100644
--- a/src/RTPSession.cpp
+++ b/src/RTPSession.cpp
@@ -54,8 +54,12 @@ using namespace AsteriskSCF::SmartProxy;
class RTPSessionImplPriv
{
public:
- RTPSessionImplPriv(Ice::ObjectAdapterPtr adapter, const FormatSeq& formats, ReplicaPtr replicaService, AsteriskSCF::SmartProxy::SmartProxy<RtpStateReplicatorPrx> stateReplicator) :
- mAdapter(adapter), mFormats(formats), mSessionStateItem(new RtpSessionStateItem()), mReplicaService(replicaService), mStateReplicator(stateReplicator) { };
+ RTPSessionImplPriv(const Ice::ObjectAdapterPtr& adapter, const FormatSeq& formats,
+ const ReplicaPtr& replicaService,
+ const AsteriskSCF::SmartProxy::SmartProxy<RtpStateReplicatorPrx>& stateReplicator) :
+ mAdapter(adapter), mFormats(formats),
+ mSessionStateItem(new RtpSessionStateItem()),
+ mReplicaService(replicaService), mStateReplicator(stateReplicator) { };
~RTPSessionImplPriv();
/**
@@ -127,7 +131,9 @@ public:
/**
* Constructor for the RTPSessionImpl class (used by Ice).
*/
-RTPSessionImpl::RTPSessionImpl(Ice::ObjectAdapterPtr adapter, const FormatSeq& formats, pj_pool_factory* factory, ReplicaPtr replicaService, AsteriskSCF::SmartProxy::SmartProxy<RtpStateReplicatorPrx> stateReplicator) :
+RTPSessionImpl::RTPSessionImpl(const Ice::ObjectAdapterPtr& adapter, const FormatSeq& formats,
+ pj_pool_factory* factory, const ReplicaPtr& replicaService,
+ const AsteriskSCF::SmartProxy::SmartProxy<RtpStateReplicatorPrx>& stateReplicator) :
mImpl(new RTPSessionImplPriv(adapter, formats, replicaService, stateReplicator))
{
/* Add ourselves to the ICE ASM so we can be used. */
@@ -144,7 +150,8 @@ RTPSessionImpl::RTPSessionImpl(Ice::ObjectAdapterPtr adapter, const FormatSeq& f
/* Now create some transport we can use to actually send or receive the media. */
for (int port = DEFAULT_RTP_PORT_MINIMUM; port < DEFAULT_RTP_PORT_MAXIMUM; port += 2)
{
- if ((status = pjmedia_transport_udp_create2(mImpl->mEndpoint, "RTP", NULL, port, 0, &mImpl->mTransport)) == PJ_SUCCESS)
+ if ((status = pjmedia_transport_udp_create2(mImpl->mEndpoint, "RTP", NULL, port, 0, &mImpl->mTransport)) ==
+ PJ_SUCCESS)
{
mImpl->mSessionStateItem->mPort = port;
break;
@@ -173,8 +180,10 @@ RTPSessionImpl::RTPSessionImpl(Ice::ObjectAdapterPtr adapter, const FormatSeq& f
/**
* Constructor for the RTPSessionImpl class (used by state replicator).
*/
-RTPSessionImpl::RTPSessionImpl(Ice::ObjectAdapterPtr adapter, pj_pool_factory* factory, Ice::Identity sessionIdentity, Ice::Identity sinkIdentity,
- Ice::Identity sourceIdentity, Ice::Int port, const FormatSeq& formats) : mImpl(new RTPSessionImplPriv(adapter, formats, 0, *(new AsteriskSCF::SmartProxy::SmartProxy<RtpStateReplicatorPrx>)))
+RTPSessionImpl::RTPSessionImpl(const Ice::ObjectAdapterPtr& adapter, pj_pool_factory* factory,
+ const Ice::Identity& sessionIdentity, const Ice::Identity& sinkIdentity, const Ice::Identity& sourceIdentity,
+ Ice::Int port, const FormatSeq& formats) :
+ mImpl(new RTPSessionImplPriv(adapter, formats, 0, *(new AsteriskSCF::SmartProxy::SmartProxy<RtpStateReplicatorPrx>)))
{
mImpl->mProxy = RTPSessionPrx::uncheckedCast(adapter->add(this, sessionIdentity));
@@ -185,13 +194,15 @@ RTPSessionImpl::RTPSessionImpl(Ice::ObjectAdapterPtr adapter, pj_pool_factory* f
/* TODO: This is bad... we can't go on! */
}
- if ((status = pjmedia_transport_udp_create2(mImpl->mEndpoint, "RTP", NULL, port, 0, &mImpl->mTransport)) != PJ_SUCCESS)
+ if ((status = pjmedia_transport_udp_create2(mImpl->mEndpoint, "RTP", NULL, port, 0, &mImpl->mTransport))
+ != PJ_SUCCESS)
{
// TODO: This is also bad, something is using the port */
}
mImpl->mStreamSource = new StreamSourceRTPImpl(this, "");
- mImpl->mStreamSourceProxy = StreamSourceRTPPrx::uncheckedCast(mImpl->mAdapter->add(mImpl->mStreamSource, sourceIdentity));
+ mImpl->mStreamSourceProxy =
+ StreamSourceRTPPrx::uncheckedCast(mImpl->mAdapter->add(mImpl->mStreamSource, sourceIdentity));
mImpl->mStreamSink = new StreamSinkRTPImpl(this, "");
mImpl->mStreamSinkProxy = StreamSinkRTPPrx::uncheckedCast(mImpl->mAdapter->add(mImpl->mStreamSink, sinkIdentity));
@@ -331,7 +342,7 @@ FormatSeq RTPSessionImpl::getFormats()
/**
* API call which calls into RTPSourceImpl in order to setup transport.
*/
-void RTPSessionImpl::setRemoteDetails(std::string address, int port)
+void RTPSessionImpl::setRemoteDetails(const string& address, int port)
{
mImpl->mStreamSource->setRemoteDetails(address, port);
}
@@ -389,7 +400,8 @@ StreamSinkRTPPtr RTPSessionImpl::getSink()
/**
* API call which replicates state items.
*/
-void RTPSessionImpl::replicateState(RtpSessionStateItemPtr session, RtpStreamSinkStateItemPtr sink, RtpStreamSourceStateItemPtr source)
+void RTPSessionImpl::replicateState(const RtpSessionStateItemPtr& session, const RtpStreamSinkStateItemPtr& sink,
+ const RtpStreamSourceStateItemPtr& source)
{
// If state replication has been disabled do nothing
if (!mImpl->mStateReplicator || mImpl->mReplicaService->isActive() == false)
@@ -432,7 +444,8 @@ void RTPSessionImpl::replicateState(RtpSessionStateItemPtr session, RtpStreamSin
/**
* API call which removes state items from the replicator.
*/
-void RTPSessionImpl::removeState(RtpSessionStateItemPtr session, RtpStreamSinkStateItemPtr sink, RtpStreamSourceStateItemPtr source)
+void RTPSessionImpl::removeState(const RtpSessionStateItemPtr& session, const RtpStreamSinkStateItemPtr& sink,
+ const RtpStreamSourceStateItemPtr& source)
{
// If state replication has been disabled do nothing
if (!mImpl->mStateReplicator || mImpl->mReplicaService->isActive() == false)
diff --git a/src/RTPSession.h b/src/RTPSession.h
index a76b610..4929906 100644
--- a/src/RTPSession.h
+++ b/src/RTPSession.h
@@ -41,9 +41,11 @@ typedef IceUtil::Handle<StreamSourceRTPImpl> StreamSourceRTPImplPtr;
class RTPSessionImpl : public AsteriskSCF::Media::RTP::V1::RTPSession
{
public:
- RTPSessionImpl(Ice::ObjectAdapterPtr, const AsteriskSCF::Media::V1::FormatSeq&, pj_pool_factory*, AsteriskSCF::System::Component::V1::ReplicaPtr,
- AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::Media::RTP::V1::RtpStateReplicatorPrx>);
- RTPSessionImpl(Ice::ObjectAdapterPtr, pj_pool_factory*, Ice::Identity, Ice::Identity, Ice::Identity, Ice::Int, const AsteriskSCF::Media::V1::FormatSeq&);
+ RTPSessionImpl(const Ice::ObjectAdapterPtr&, const AsteriskSCF::Media::V1::FormatSeq&,
+ pj_pool_factory*, const AsteriskSCF::System::Component::V1::ReplicaPtr&,
+ const AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::Media::RTP::V1::RtpStateReplicatorPrx>&);
+ RTPSessionImpl(const Ice::ObjectAdapterPtr&, pj_pool_factory*, const Ice::Identity&, const Ice::Identity&,
+ const Ice::Identity&, Ice::Int, const AsteriskSCF::Media::V1::FormatSeq&);
AsteriskSCF::Media::V1::StreamSourceSeq getSources(const Ice::Current&);
AsteriskSCF::Media::V1::StreamSinkSeq getSinks(const Ice::Current&);
std::string getId(const Ice::Current&);
@@ -54,13 +56,17 @@ public:
pjmedia_transport* getTransport();
AsteriskSCF::Media::V1::FormatSeq getFormats();
void associatePayloads(const AsteriskSCF::Media::RTP::V1::PayloadMap&, const Ice::Current&);
- void setRemoteDetails(std::string address, int port);
+ void setRemoteDetails(const std::string& address, int port);
AsteriskSCF::Media::V1::FormatPtr getFormat(int payload);
int getPayload(const AsteriskSCF::Media::V1::FormatPtr& mediaformat);
StreamSourceRTPImplPtr getSource();
AsteriskSCF::Media::RTP::V1::StreamSinkRTPPtr getSink();
- void replicateState(AsteriskSCF::Media::RTP::V1::RtpSessionStateItemPtr, AsteriskSCF::Media::RTP::V1::RtpStreamSinkStateItemPtr, AsteriskSCF::Media::RTP::V1::RtpStreamSourceStateItemPtr);
- void removeState(AsteriskSCF::Media::RTP::V1::RtpSessionStateItemPtr, AsteriskSCF::Media::RTP::V1::RtpStreamSinkStateItemPtr, AsteriskSCF::Media::RTP::V1::RtpStreamSourceStateItemPtr);
+ void replicateState(const AsteriskSCF::Media::RTP::V1::RtpSessionStateItemPtr&,
+ const AsteriskSCF::Media::RTP::V1::RtpStreamSinkStateItemPtr&,
+ const AsteriskSCF::Media::RTP::V1::RtpStreamSourceStateItemPtr&);
+ void removeState(const AsteriskSCF::Media::RTP::V1::RtpSessionStateItemPtr&,
+ const AsteriskSCF::Media::RTP::V1::RtpStreamSinkStateItemPtr&,
+ const AsteriskSCF::Media::RTP::V1::RtpStreamSourceStateItemPtr&);
private:
/**
* Private implementation data for RTPSessionImpl.
diff --git a/src/RTPSink.cpp b/src/RTPSink.cpp
index e20f86d..2324799 100644
--- a/src/RTPSink.cpp
+++ b/src/RTPSink.cpp
@@ -44,7 +44,7 @@ public:
/**
* Constructor for our StreamSinkRTPImplPriv class.
*/
- StreamSinkRTPImplPriv(RTPSessionImplPtr, std::string);
+ StreamSinkRTPImplPriv(const RTPSessionImplPtr&, const std::string&);
/**
* A structure containing outgoing pjmedia session data.
@@ -65,7 +65,8 @@ public:
/**
* Constructor for the StreamSinkRTPImplPriv class.
*/
-StreamSinkRTPImplPriv::StreamSinkRTPImplPriv(RTPSessionImplPtr session, std::string sessionId) : mSession(session), mSinkStateItem(new RtpStreamSinkStateItem())
+StreamSinkRTPImplPriv::StreamSinkRTPImplPriv(const RTPSessionImplPtr& session, const string& sessionId) :
+ mSession(session), mSinkStateItem(new RtpStreamSinkStateItem)
{
pjmedia_rtp_session_init(&mOutgoingSession, 0, pj_rand());
mSinkStateItem->mSessionId = sessionId;
@@ -76,7 +77,8 @@ StreamSinkRTPImplPriv::StreamSinkRTPImplPriv(RTPSessionImplPtr session, std::str
/**
* Constructor for the StreamSinkRTPImpl class.
*/
-StreamSinkRTPImpl::StreamSinkRTPImpl(RTPSessionImplPtr session, std::string sessionId) : mImpl(new StreamSinkRTPImplPriv(session, sessionId))
+StreamSinkRTPImpl::StreamSinkRTPImpl(const RTPSessionImplPtr& session, const string& sessionId) :
+ mImpl(new StreamSinkRTPImplPriv(session, sessionId))
{
}
@@ -112,7 +114,8 @@ void StreamSinkRTPImpl::write(const AsteriskSCF::Media::V1::FrameSeq& frames, co
}
/* Using the available information construct an RTP header that we can place at the front of our packet */
- pj_status_t status = pjmedia_rtp_encode_rtp(&mImpl->mOutgoingSession, mImpl->mSession->getPayload((*frame)->mediaformat), 0, (*frame)->payload.size(),
+ pj_status_t status = pjmedia_rtp_encode_rtp(&mImpl->mOutgoingSession,
+ mImpl->mSession->getPayload((*frame)->mediaformat), 0, (*frame)->payload.size(),
(*frame)->payload.size(), &header, &header_len);
if (status != PJ_SUCCESS)
@@ -131,7 +134,8 @@ void StreamSinkRTPImpl::write(const AsteriskSCF::Media::V1::FrameSeq& frames, co
pj_memcpy(packet + header_len, &(*frame)->payload[0], (*frame)->payload.size());
/* All done, transmission can now occur */
- status = pjmedia_transport_send_rtp(mImpl->mSession->getTransport(), packet, (*frame)->payload.size() + header_len);
+ status = pjmedia_transport_send_rtp(mImpl->mSession->getTransport(), packet,
+ (*frame)->payload.size() + header_len);
if (status != PJ_SUCCESS)
{
@@ -179,7 +183,7 @@ std::string StreamSinkRTPImpl::getId(const Ice::Current& current)
/**
* Implementation of the setRemoteDetails method as defined in MediaRTPIf.ice
*/
-void StreamSinkRTPImpl::setRemoteDetails(const std::string& address, Ice::Int port, const Ice::Current&)
+void StreamSinkRTPImpl::setRemoteDetails(const string& address, Ice::Int port, const Ice::Current&)
{
/* This method is essentially a passthru to the RTPSourceImpl. It takes care of
* actually attaching the transport.
diff --git a/src/RTPSink.h b/src/RTPSink.h
index a350d18..6254d5a 100644
--- a/src/RTPSink.h
+++ b/src/RTPSink.h
@@ -21,7 +21,7 @@ class StreamSinkRTPImplPriv;
class StreamSinkRTPImpl : public AsteriskSCF::Media::RTP::V1::StreamSinkRTP
{
public:
- StreamSinkRTPImpl(RTPSessionImplPtr, std::string);
+ StreamSinkRTPImpl(const RTPSessionImplPtr&, const std::string&);
void write(const AsteriskSCF::Media::V1::FrameSeq&, const Ice::Current&);
void setSource(const AsteriskSCF::Media::V1::StreamSourcePrx&, const Ice::Current&);
AsteriskSCF::Media::V1::StreamSourcePrx getSource(const Ice::Current&);
diff --git a/src/RTPSource.cpp b/src/RTPSource.cpp
index 39c52e2..7e0450b 100644
--- a/src/RTPSource.cpp
+++ b/src/RTPSource.cpp
@@ -51,7 +51,7 @@ public:
/**
* Constructor for our StreamSourceRTPImplPriv class.
*/
- StreamSourceRTPImplPriv(RTPSessionImplPtr, std::string);
+ StreamSourceRTPImplPriv(const RTPSessionImplPtr&, const string&);
/**
* A structure containing incoming pjmedia session data.
@@ -72,7 +72,8 @@ public:
/**
* Constructor for the StreamSourceRTPImplPriv class.
*/
-StreamSourceRTPImplPriv::StreamSourceRTPImplPriv(RTPSessionImplPtr session, std::string sessionId) : mSession(session), mSourceStateItem(new RtpStreamSourceStateItem())
+StreamSourceRTPImplPriv::StreamSourceRTPImplPriv(const RTPSessionImplPtr& session, const string& sessionId) :
+ mSession(session), mSourceStateItem(new RtpStreamSourceStateItem)
{
pjmedia_rtp_session_init(&mIncomingSession, 0, 0);
mSourceStateItem->mSessionId = sessionId;
@@ -82,7 +83,8 @@ StreamSourceRTPImplPriv::StreamSourceRTPImplPriv(RTPSessionImplPtr session, std:
/**
* Constructor for the StreamSourceRTPImpl class.
*/
-StreamSourceRTPImpl::StreamSourceRTPImpl(RTPSessionImplPtr session, std::string sessionId) : mImpl(new StreamSourceRTPImplPriv(session, sessionId))
+StreamSourceRTPImpl::StreamSourceRTPImpl(const RTPSessionImplPtr& session, const string& sessionId) :
+ mImpl(new StreamSourceRTPImplPriv(session, sessionId))
{
}
@@ -174,7 +176,8 @@ static void receiveRTP(void *userdata, void *packet, pj_ssize_t size)
Ice::Byte* payload;
unsigned int payload_size;
- pj_status_t status = pjmedia_rtp_decode_rtp(&source->mImpl->mIncomingSession, packet, size, &header, (const void**)&payload, &payload_size);
+ pj_status_t status = pjmedia_rtp_decode_rtp(&source->mImpl->mIncomingSession, packet, size, &header,
+ (const void**)&payload, &payload_size);
if (status != PJ_SUCCESS)
{
@@ -219,7 +222,7 @@ static void receiveRTP(void *userdata, void *packet, pj_ssize_t size)
/**
* API call which sets up our pjmedia transport and allows media to be sent and received.
*/
-void StreamSourceRTPImpl::setRemoteDetails(std::string address, int port)
+void StreamSourceRTPImpl::setRemoteDetails(const string& address, int port)
{
pj_sockaddr_in sin;
diff --git a/src/RTPSource.h b/src/RTPSource.h
index c6d9d4a..d7373e7 100644
--- a/src/RTPSource.h
+++ b/src/RTPSource.h
@@ -21,7 +21,7 @@ class StreamSourceRTPImplPriv;
class StreamSourceRTPImpl : public AsteriskSCF::Media::RTP::V1::StreamSourceRTP
{
public:
- StreamSourceRTPImpl(RTPSessionImplPtr, std::string);
+ StreamSourceRTPImpl(const RTPSessionImplPtr&, const std::string&);
void setSink(const AsteriskSCF::Media::V1::StreamSinkPrx&, const Ice::Current&);
AsteriskSCF::Media::V1::StreamSinkPrx getSink(const Ice::Current&);
AsteriskSCF::Media::V1::FormatSeq getFormats(const Ice::Current&);
@@ -29,7 +29,7 @@ public:
void requestFormat(const AsteriskSCF::Media::V1::FormatPtr&, const Ice::Current&);
std::string getLocalAddress(const Ice::Current&);
Ice::Int getLocalPort(const Ice::Current&);
- void setRemoteDetails(std::string address, int port);
+ void setRemoteDetails(const std::string& address, int port);
AsteriskSCF::Media::RTP::V1::RtpStreamSourceStateItemPtr getStateItem();
/**
diff --git a/src/RtpStateReplicator.h b/src/RtpStateReplicator.h
index 34dc017..b2db101 100644
--- a/src/RtpStateReplicator.h
+++ b/src/RtpStateReplicator.h
@@ -24,17 +24,18 @@
using namespace AsteriskSCF::Media::RTP::V1;
-typedef AsteriskSCF::StateReplication::StateReplicator<RtpStateReplicator, RtpStateItemPtr, std::string, RtpStateReplicatorListenerPrx> RtpStateReplicatorI;
+typedef AsteriskSCF::StateReplication::StateReplicator<RtpStateReplicator, RtpStateItemPtr, std::string,
+ RtpStateReplicatorListenerPrx> RtpStateReplicatorI;
typedef IceUtil::Handle<RtpStateReplicatorI> RtpStateReplicatorIPtr;
class RtpStateReplicatorListenerI : public RtpStateReplicatorListener
{
public:
- RtpStateReplicatorListenerI(Ice::ObjectAdapterPtr, pj_pool_factory*, RtpGeneralStateItemPtr);
+ RtpStateReplicatorListenerI(const Ice::ObjectAdapterPtr&, pj_pool_factory*, const RtpGeneralStateItemPtr&);
~RtpStateReplicatorListenerI();
void stateRemoved(const Ice::StringSeq&, const Ice::Current&);
void stateSet(const RtpStateItemSeq&, const Ice::Current&);
- bool operator==(RtpStateReplicatorListenerI &rhs);
+ bool operator==(const RtpStateReplicatorListenerI &rhs);
private:
struct RtpStateReplicatorListenerImpl *mImpl;
};
diff --git a/src/RtpStateReplicatorApp.cpp b/src/RtpStateReplicatorApp.cpp
index 6fa76d9..91c0e37 100644
--- a/src/RtpStateReplicatorApp.cpp
+++ b/src/RtpStateReplicatorApp.cpp
@@ -53,7 +53,7 @@ public:
virtual void start(const string &name, const Ice::CommunicatorPtr& ic, const Ice::StringSeq& args);
virtual void stop();
private:
- void initialize(std::string appName, const Ice::CommunicatorPtr& ic);
+ void initialize(const string& appName, const Ice::CommunicatorPtr& ic);
void registerWithServiceLocator(const Ice::CommunicatorPtr& ic);
void deregisterFromServiceLocator();
std::string mAppName;
@@ -101,7 +101,7 @@ private:
class RtpStateReplicatorCompare : public ServiceLocatorParamsCompare
{
public:
- RtpStateReplicatorCompare(string name) : mName(name) {}
+ RtpStateReplicatorCompare(const string& name) : mName(name) {}
bool isSupported(const ServiceLocatorParamsPtr ¶ms, const Ice::Current &)
{
RtpStateReplicatorParamsPtr sipParams = RtpStateReplicatorParamsPtr::dynamicCast(params);
@@ -126,11 +126,13 @@ void RtpStateReplicatorService::registerWithServiceLocator(const Ice::Communicat
try
{
// Get a proxy to the management interface for the Service Locator, so we can add ourselves into the system discovery mechanisms.
- mServiceLocatorManagement = ServiceLocatorManagementPrx::checkedCast(ic->propertyToProxy("LocatorServiceManagement.Proxy"));
+ mServiceLocatorManagement =
+ ServiceLocatorManagementPrx::checkedCast(ic->propertyToProxy("LocatorServiceManagement.Proxy"));
if (mServiceLocatorManagement == 0)
{
- lg(Error) << "Unable to obtain proxy to ServiceLocatorManagement interface. Check config file. This component can't be found until this is corrected." << endl;
+ lg(Error) << "Unable to obtain proxy to ServiceLocatorManagement interface. Check config file. "
+ "This component can't be found until this is corrected.";
return;
}
@@ -140,7 +142,8 @@ void RtpStateReplicatorService::registerWithServiceLocator(const Ice::Communicat
// The GUID passed in to add service needs to be unique for reporting.
string componentServiceGuid(AsteriskSCF::Media::RTP::V1::StateReplicatorComponentCategory);
- mComponentServiceManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(componentServicePrx, componentServiceGuid));
+ mComponentServiceManagement = ServiceManagementPrx::uncheckedCast(
+ mServiceLocatorManagement->addService(componentServicePrx, componentServiceGuid));
// Add category as a parameter to enable other components look this component up.
ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
@@ -152,14 +155,16 @@ void RtpStateReplicatorService::registerWithServiceLocator(const Ice::Communicat
RtpStateReplicatorPrx stateReplicatorPrx = RtpStateReplicatorPrx::checkedCast(stateReplicatorObjectPrx);
string stateReplicationGuid(AsteriskSCF::Media::RTP::V1::StateReplicatorDiscoveryCategory);
- mStateReplicationManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(stateReplicatorPrx, stateReplicationGuid));
+ mStateReplicationManagement = ServiceManagementPrx::uncheckedCast(
+ mServiceLocatorManagement->addService(stateReplicatorPrx, stateReplicationGuid));
- ServiceLocatorParamsPtr discoveryParams = new ServiceLocatorParams();
+ ServiceLocatorParamsPtr discoveryParams = new ServiceLocatorParams;
discoveryParams->category = AsteriskSCF::Media::RTP::V1::StateReplicatorDiscoveryCategory;
string replicatorName = ic->getProperties()->getPropertyWithDefault("RtpStateReplicator.Name", "default");
RtpStateReplicatorCompare* nameCompare = new RtpStateReplicatorCompare(replicatorName);
- ServiceLocatorParamsComparePrx compareProxy = ServiceLocatorParamsComparePrx::uncheckedCast(mAdapter->addWithUUID(nameCompare));
+ ServiceLocatorParamsComparePrx compareProxy = ServiceLocatorParamsComparePrx::uncheckedCast(
+ mAdapter->addWithUUID(nameCompare));
string compareGuid = IceUtil::generateUUID();
mServiceLocatorManagement->addCompare(compareGuid, compareProxy);
@@ -169,7 +174,7 @@ void RtpStateReplicatorService::registerWithServiceLocator(const Ice::Communicat
}
catch(...)
{
- lg(Error) << "Exception in " << mAppName << " registerWithServiceLocator()" << endl;
+ lg(Error) << "Exception in " << mAppName << " registerWithServiceLocator()";
}
}
@@ -186,11 +191,11 @@ void RtpStateReplicatorService::deregisterFromServiceLocator()
}
catch(...)
{
- lg(Error) << "Had trouble in deregisterFromServiceLocator()." << endl;
+ lg(Error) << "Had trouble in deregisterFromServiceLocator().";
}
}
-void RtpStateReplicatorService::initialize(const std::string appName, const Ice::CommunicatorPtr& ic)
+void RtpStateReplicatorService::initialize(const string& appName, const Ice::CommunicatorPtr& ic)
{
mAdapter = ic->createObjectAdapter("RtpStateReplicator");
diff --git a/src/RtpStateReplicatorListener.cpp b/src/RtpStateReplicatorListener.cpp
index cc00a2a..b47f408 100644
--- a/src/RtpStateReplicatorListener.cpp
+++ b/src/RtpStateReplicatorListener.cpp
@@ -56,8 +56,10 @@ private:
struct RtpStateReplicatorListenerImpl
{
public:
- RtpStateReplicatorListenerImpl(Ice::ObjectAdapterPtr adapter, pj_pool_factory *poolFactory, RtpGeneralStateItemPtr generalState)
+ RtpStateReplicatorListenerImpl(const Ice::ObjectAdapterPtr& adapter, pj_pool_factory *poolFactory,
+ const RtpGeneralStateItemPtr& generalState)
: mId(IceUtil::generateUUID()), mAdapter(adapter), mPoolFactory(poolFactory), mGeneralState(generalState) {}
+
void removeStateNoticeImpl(const Ice::StringSeq& itemKeys)
{
for (Ice::StringSeq::const_iterator key = itemKeys.begin(); key != itemKeys.end(); ++key)
@@ -71,7 +73,7 @@ public:
class visitor : public AsteriskSCF::Media::RTP::V1::RtpStateItemVisitor
{
public:
- visitor(RtpStateReplicatorListenerImpl *impl) : impl(impl)
+ visitor(RtpStateReplicatorListenerImpl *impl) : impl(impl)
{
}
@@ -94,8 +96,9 @@ public:
localitem = newitem;
impl->mStateItems.insert(make_pair(item->mSessionId, newitem));
- RTPSessionImplPtr localSession = new RTPSessionImpl(impl->mAdapter, impl->mPoolFactory, item->mSessionIdentity, item->mSinkIdentity,
- item->mSourceIdentity, item->mPort, item->mFormats);
+ RTPSessionImplPtr localSession =
+ new RTPSessionImpl(impl->mAdapter, impl->mPoolFactory, item->mSessionIdentity,
+ item->mSinkIdentity, item->mSourceIdentity, item->mPort, item->mFormats);
localitem->setSession(localSession);
}
else
@@ -108,17 +111,20 @@ public:
void visitStreamSink(const RtpStreamSinkStateItemPtr &item, const Ice::Current &)
{
- map<string, boost::shared_ptr<RtpStateReplicatorItem> >::iterator i = impl->mStateItems.find(item->mSessionId);
+ map<string, boost::shared_ptr<RtpStateReplicatorItem> >::iterator i =
+ impl->mStateItems.find(item->mSessionId);
if (i != impl->mStateItems.end())
{
i->second->getSession()->getSink()->setSource(item->mSource, Ice::Current());
- i->second->getSession()->getSink()->setRemoteDetails(item->mRemoteAddress, item->mRemotePort, Ice::Current());
+ i->second->getSession()->getSink()->setRemoteDetails(item->mRemoteAddress, item->mRemotePort,
+ Ice::Current());
}
}
void visitStreamSource(const RtpStreamSourceStateItemPtr &item, const Ice::Current &)
{
- map<string, boost::shared_ptr<RtpStateReplicatorItem> >::iterator i = impl->mStateItems.find(item->mSessionId);
+ map<string, boost::shared_ptr<RtpStateReplicatorItem> >::iterator i =
+ impl->mStateItems.find(item->mSessionId);
if (i != impl->mStateItems.end())
{
i->second->getSession()->getSource()->setSink(item->mSink, Ice::Current());
@@ -141,7 +147,8 @@ public:
RtpGeneralStateItemPtr mGeneralState;
};
-RtpStateReplicatorListenerI::RtpStateReplicatorListenerI(Ice::ObjectAdapterPtr adapter, pj_pool_factory *poolFactory, RtpGeneralStateItemPtr generalState)
+RtpStateReplicatorListenerI::RtpStateReplicatorListenerI(const Ice::ObjectAdapterPtr& adapter,
+ pj_pool_factory *poolFactory, const RtpGeneralStateItemPtr& generalState)
: mImpl(new RtpStateReplicatorListenerImpl(adapter, poolFactory, generalState)) {}
RtpStateReplicatorListenerI::~RtpStateReplicatorListenerI()
@@ -159,7 +166,7 @@ void RtpStateReplicatorListenerI::stateSet(const RtpStateItemSeq& items, const I
mImpl->setStateNoticeImpl(items);
}
-bool RtpStateReplicatorListenerI::operator==(RtpStateReplicatorListenerI &rhs)
+bool RtpStateReplicatorListenerI::operator==(const RtpStateReplicatorListenerI &rhs)
{
return mImpl->mId == rhs.mImpl->mId;
}
commit b87be842f83fc697fdc7e7c7d2775f2607af7ce6
Author: Joshua Colp <jcolp at digium.com>
Date: Wed Mar 2 15:56:46 2011 -0400
Visitors must be allocated on the heap and not the stack to ensure Ice object reference counting works properly.
diff --git a/src/RtpStateReplicatorListener.cpp b/src/RtpStateReplicatorListener.cpp
index fb0061e..cc00a2a 100644
--- a/src/RtpStateReplicatorListener.cpp
+++ b/src/RtpStateReplicatorListener.cpp
@@ -124,11 +124,13 @@ public:
i->second->getSession()->getSource()->setSink(item->mSink, Ice::Current());
}
}
- } v(this);
+ };
+
+ AsteriskSCF::Media::RTP::V1::RtpStateItemVisitorPtr v = new visitor(this);
for (RtpStateItemSeq::const_iterator item = items.begin(); item != items.end(); ++item)
{
- (*item)->visit(&v);
+ (*item)->visit(v);
}
}
diff --git a/test/TestRTPpjmedia.cpp b/test/TestRTPpjmedia.cpp
index 3b7cb2a..f03cb72 100644
--- a/test/TestRTPpjmedia.cpp
+++ b/test/TestRTPpjmedia.cpp
@@ -178,11 +178,13 @@ void TestRtpReplicatorListener::stateSet(const RtpStateItemSeq& items, const Ice
boost::mutex::scoped_lock lock(Testbed.mLock);
Testbed.mCondition.notify_one();
}
- } v(this);
+ };
+
+ AsteriskSCF::Media::RTP::V1::RtpStateItemVisitorPtr v = new visitor(this);
for (RtpStateItemSeq::const_iterator item = items.begin(); item != items.end(); ++item)
{
- (*item)->visit(&v);
+ (*item)->visit(v);
}
}
commit 13bea3f9271b2ecbe159b74cc0d8295819a6fd0b
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Fri Feb 18 16:32:05 2011 -0600
Use a relative class name for the class that visits RtpStateItem objects.
diff --git a/local-slice/RtpStateReplicationIf.ice b/local-slice/RtpStateReplicationIf.ice
index 7bc5531..46a5014 100644
--- a/local-slice/RtpStateReplicationIf.ice
+++ b/local-slice/RtpStateReplicationIf.ice
@@ -47,7 +47,7 @@ module V1
{
};
- ["visitor:::AsteriskSCF::Media::RTP::V1::RtpStateItemVisitor"] class RtpStateItem
+ ["visitor:RtpStateItemVisitor"] class RtpStateItem
{
string key;
string mSessionId;
commit f604c99c60525eae4bf71f1a7f722bb8d2e51ac6
Author: Joshua Colp <jcolp at digium.com>
Date: Fri Feb 4 08:18:14 2011 -0400
Fix build regression on some platforms.
diff --git a/src/RtpStateReplicatorListener.cpp b/src/RtpStateReplicatorListener.cpp
index 35f490d..fb0061e 100644
--- a/src/RtpStateReplicatorListener.cpp
+++ b/src/RtpStateReplicatorListener.cpp
@@ -92,7 +92,7 @@ public:
{
boost::shared_ptr<RtpStateReplicatorItem> newitem(new RtpStateReplicatorItem());
localitem = newitem;
- impl->mStateItems.insert(make_pair<string, boost::shared_ptr<RtpStateReplicatorItem> >(item->mSessionId, newitem));
+ impl->mStateItems.insert(make_pair(item->mSessionId, newitem));
RTPSessionImplPtr localSession = new RTPSessionImpl(impl->mAdapter, impl->mPoolFactory, item->mSessionIdentity, item->mSinkIdentity,
item->mSourceIdentity, item->mPort, item->mFormats);
commit 5a66fe64bbaf6449dad3c5966275c4e3b58c2c1c
Author: Joshua Colp <jcolp at digium.com>
Date: Fri Feb 4 07:52:56 2011 -0400
Add missing visitor code in the listener.
diff --git a/src/RtpStateReplicatorListener.cpp b/src/RtpStateReplicatorListener.cpp
index d7b0f8d..35f490d 100644
--- a/src/RtpStateReplicatorListener.cpp
+++ b/src/RtpStateReplicatorListener.cpp
@@ -30,6 +30,7 @@
#include "RTPSink.h"
#include "RTPSource.h"
+using namespace std;
using namespace AsteriskSCF::Media::RTP::V1;
class RtpStateReplicatorItem
@@ -67,29 +68,34 @@ public:
}
void setStateNoticeImpl(const RtpStateItemSeq& items)
{
- for (RtpStateItemSeq::const_iterator item = items.begin(); item != items.end(); ++item)
- {
- std::map<std::string, boost::shared_ptr<RtpStateReplicatorItem> >::iterator i = mStateItems.find((*item)->mSessionId);
- RtpGeneralStateItemPtr general;
- RtpSessionStateItemPtr session;
- RtpStreamSinkStateItemPtr sink;
- RtpStreamSourceStateItemPtr source;
- boost::shared_ptr<RtpStateReplicatorItem> localitem;
-
- if ((general = RtpGeneralStateItemPtr::dynamicCast((*item))))
+ class visitor : public AsteriskSCF::Media::RTP::V1::RtpStateItemVisitor
+ {
+ public:
+ visitor(RtpStateReplicatorListenerImpl *impl) : impl(impl)
{
- mGeneralState->mServiceManagement = general->mServiceManagement;
}
- else if ((session = RtpSessionStateItemPtr::dynamicCast((*item))))
+
+ private:
+ RtpStateReplicatorListenerImpl *impl;
+
+ void visitGeneral(const RtpGeneralStateItemPtr &item, const Ice::Current &)
{
- if (i == mStateItems.end())
+ impl->mGeneralState->mServiceManagement = item->mServiceManagement;
+ }
+
+ void visitSession(const RtpSessionStateItemPtr &item, const Ice::Current &)
+ {
+ map<string, boost::shared_ptr<RtpStateReplicatorItem> >::iterator i = impl->mStateItems.find(item->mSessionId);
+ boost::shared_ptr<RtpStateReplicatorItem> localitem;
+
+ if (i == impl->mStateItems.end())
{
boost::shared_ptr<RtpStateReplicatorItem> newitem(new RtpStateReplicatorItem());
localitem = newitem;
- mStateItems.insert(std::make_pair((*item)->mSessionId, newitem));
+ impl->mStateItems.insert(make_pair<string, boost::shared_ptr<RtpStateReplicatorItem> >(item->mSessionId, newitem));
- RTPSessionImplPtr localSession = new RTPSessionImpl(mAdapter, mPoolFactory, session->mSessionIdentity, session->mSinkIdentity,
- session->mSourceIdentity, session->mPort, session->mFormats);
+ RTPSessionImplPtr localSession = new RTPSessionImpl(impl->mAdapter, impl->mPoolFactory, item->mSessionIdentity, item->mSinkIdentity,
+ item->mSourceIdentity, item->mPort, item->mFormats);
localitem->setSession(localSession);
}
else
@@ -97,31 +103,37 @@ public:
localitem = i->second;
}
- localitem->getSession()->associatePayloads(session->mPayloadstoFormats, Ice::Current());
+ localitem->getSession()->associatePayloads(item->mPayloadstoFormats, Ice::Current());
}
- else if ((sink = RtpStreamSinkStateItemPtr::dynamicCast((*item))))
+
+ void visitStreamSink(const RtpStreamSinkStateItemPtr &item, const Ice::Current &)
{
- if (i == mStateItems.end())
+ map<string, boost::shared_ptr<RtpStateReplicatorItem> >::iterator i = impl->mStateItems.find(item->mSessionId);
+ if (i != impl->mStateItems.end())
{
- continue;
+ i->second->getSession()->getSink()->setSource(item->mSource, Ice::Current());
+ i->second->getSession()->getSink()->setRemoteDetails(item->mRemoteAddress, item->mRemotePort, Ice::Current());
}
-
- i->second->getSession()->getSink()->setSource(sink->mSource, Ice::Current());
- i->second->getSession()->getSink()->setRemoteDetails(sink->mRemoteAddress, sink->mRemotePort, Ice::Current());
}
- else if ((source = RtpStreamSourceStateItemPtr::dynamicCast((*item))))
+
+ void visitStreamSource(const RtpStreamSourceStateItemPtr &item, const Ice::Current &)
{
- if (i == mStateItems.end())
+ map<string, boost::shared_ptr<RtpStateReplicatorItem> >::iterator i = impl->mStateItems.find(item->mSessionId);
+ if (i != impl->mStateItems.end())
{
- continue;
+ i->second->getSession()->getSource()->setSink(item->mSink, Ice::Current());
}
-
- i->second->getSession()->getSource()->setSink(source->mSink, Ice::Current());
}
+ } v(this);
+
+ for (RtpStateItemSeq::const_iterator item = items.begin(); item != items.end(); ++item)
+ {
+ (*item)->visit(&v);
}
}
- std::string mId;
- std::map<std::string, boost::shared_ptr<RtpStateReplicatorItem> > mStateItems;
+
+ string mId;
+ map<string, boost::shared_ptr<RtpStateReplicatorItem> > mStateItems;
Ice::ObjectAdapterPtr mAdapter;
pj_pool_factory *mPoolFactory;
RtpGeneralStateItemPtr mGeneralState;
commit 3ab1fdbe6e035a7fb16b4b53815b50d2a1f7238c
Merge: 6044159 5668dac
Author: Joshua Colp <jcolp at digium.com>
Date: Wed Jan 26 13:16:48 2011 -0400
Merge branch 'master' of git.asterisk.org:asterisk-scf/release/media_rtp_pjmedia
commit 60441594fa6e12cab55876bc4a654d70441867df
Author: Joshua Colp <jcolp at digium.com>
Date: Wed Jan 26 13:16:08 2011 -0400
Don't specify the template parameters.
diff --git a/src/RtpStateReplicatorListener.cpp b/src/RtpStateReplicatorListener.cpp
index 58da256..d7b0f8d 100644
--- a/src/RtpStateReplicatorListener.cpp
+++ b/src/RtpStateReplicatorListener.cpp
@@ -86,7 +86,7 @@ public:
{
boost::shared_ptr<RtpStateReplicatorItem> newitem(new RtpStateReplicatorItem());
localitem = newitem;
- mStateItems.insert(std::make_pair<std::string, boost::shared_ptr<RtpStateReplicatorItem> >((*item)->mSessionId, newitem));
+ mStateItems.insert(std::make_pair((*item)->mSessionId, newitem));
RTPSessionImplPtr localSession = new RTPSessionImpl(mAdapter, mPoolFactory, session->mSessionIdentity, session->mSinkIdentity,
session->mSourceIdentity, session->mPort, session->mFormats);
commit 5668dacfae47078f246f58cbf48534459e0cc222
Author: David M. Lee <dlee at digium.com>
Date: Tue Jan 25 22:31:34 2011 -0600
Adding missing dependencies for RtpStateReplicator.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ccabce8..1f2b232 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -60,5 +60,7 @@ asterisk_scf_component_add_ice_libraries(RtpStateReplicator IceStorm)
asterisk_scf_component_add_boost_libraries(RtpStateReplicator thread date_time)
asterisk_scf_component_build_icebox(RtpStateReplicator)
+target_link_libraries(RtpStateReplicator asterisk-scf-api)
+target_link_libraries(RtpStateReplicator logging-client)
-asterisk_scf_component_install(RtpStateReplicator)
\ No newline at end of file
+asterisk_scf_component_install(RtpStateReplicator)
commit 10846d9c15bc3a12ee211d00616d9c55e2a09a38
Merge: 7a004be dcf83d9
Author: Joshua Colp <jcolp at digium.com>
Date: Mon Jan 24 20:18:34 2011 -0400
Add support for RTP component replication.
diff --cc src/CMakeLists.txt
index c0244c5,fa8662e..ccabce8
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@@ -29,5 -38,25 +38,27 @@@ pjproject_link(media_rtp_pjmedia pjlib
pjproject_link(media_rtp_pjmedia pjlib-util)
pjproject_link(media_rtp_pjmedia pjmedia)
pjproject_link(media_rtp_pjmedia pjnath)
-#asterisk_scf_component_install(media_rtp_pjmedia RUNTIME bin "pjmedia RTP Media." Media)
+
+asterisk_scf_component_install(media_rtp_pjmedia)
+
+ asterisk_scf_component_init(RtpStateReplicator CXX)
+
+ #This line allows us to use the templated state replicator
+ #code. This statement is not the most permanent of changes
+ #and assumes the directories are structured in the way that
+ #gitall structures them.
+ include_directories(${utils_dir}/StateReplicator/include)
+ include_directories(${utils_dir}/SmartProxy/include)
+ include_directories(${API_INCLUDE_DIR})
+
+ asterisk_scf_component_add_file(RtpStateReplicator RtpStateReplicatorApp.cpp)
+ asterisk_scf_component_add_file(RtpStateReplicator RtpStateReplicator.h)
+ asterisk_scf_component_add_slice(RtpStateReplicator ../local-slice/RtpStateReplicationIf.ice)
+
+ asterisk_scf_component_add_ice_libraries(RtpStateReplicator IceStorm)
+
+ asterisk_scf_component_add_boost_libraries(RtpStateReplicator thread date_time)
+
+ asterisk_scf_component_build_icebox(RtpStateReplicator)
-target_link_libraries(RtpStateReplicator logging-client)
++
++asterisk_scf_component_install(RtpStateReplicator)
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;
commit 7a004be53942d4c1880a49076eb03db0a0b24a90
Author: David M. Lee <dlee at digium.com>
Date: Thu Jan 20 12:33:27 2011 -0600
... 15467 lines suppressed ...
--
asterisk-scf/integration/media_rtp_pjmedia.git
More information about the asterisk-scf-commits
mailing list