[asterisk-scf-commits] asterisk-scf/integration/media_rtp_pjmedia.git branch "nat-support" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Tue Jul 12 07:38:07 CDT 2011
branch "nat-support" has been updated
via 5ebbcf58c3f25ecb983a1f865b346e8027bdfc09 (commit)
from 67595d56b549232aeb6e18cf88203b68ce794031 (commit)
Summary of changes:
src/ICETransport.cpp | 88 ++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 68 insertions(+), 20 deletions(-)
- Log -----------------------------------------------------------------
commit 5ebbcf58c3f25ecb983a1f865b346e8027bdfc09
Author: Brent Eagles <beagles at digium.com>
Date: Tue Jul 12 10:03:31 2011 -0230
Async negotiation.
diff --git a/src/ICETransport.cpp b/src/ICETransport.cpp
index 6cbfc00..b1ef798 100644
--- a/src/ICETransport.cpp
+++ b/src/ICETransport.cpp
@@ -81,9 +81,23 @@ public:
return mRole;
}
- CandidatePtr negotiate(const string& hostname, Ice::Int port, const CandidateSeq& candidates,
+ void negotiate_async(const AMD_InteractiveConnectionAgent_negotiatePtr& callback,
+ const string& hostname, Ice::Int port, const CandidateSeq& candidates,
const Ice::Current&)
{
+
+ boost::unique_lock<boost::shared_mutex> lock(mLock);
+ stateCheck();
+ if (mCurrentNegotiation)
+ {
+ pjmedia_transport_media_stop(mTransport);
+ mCurrentNegotiation->ice_exception(NegotiationInterrupted("New negotiate() request"));
+ //
+ // TODO: are we going to support cancellable negotiations.
+ //
+ }
+ mCurrentNegotiation = callback;
+
//
// So how this works is we create a remote SDP and call pjmedia_transport_start() easy peasy. (Same deal
//
@@ -218,12 +232,10 @@ public:
{
if (fail(status))
{
- //
- // TODO!
- //
- return;
+ ostringstream err;
+ err << "Setup/negotiation failed with pj_status_t value of " << status;
+ throw NegotiationError(err.str());
}
- mTransport = transport;
pjmedia_transport_info info;
pjmedia_transport_info_init(&info);
@@ -247,6 +259,7 @@ public:
if (iceInfo)
{
boost::unique_lock<boost::shared_mutex> lock(mLock);
+ mTransport = transport;
if (iceInfo->role == PJ_ICE_SESS_ROLE_CONTROLLING)
{
setRole(Controlling);
@@ -267,6 +280,7 @@ public:
{
const string candidateName("candidate");
pjmedia_sdp_media* media = sdpSession.media[i];
+ ostringstream errorMessage;
for (size_t j = 0; j < media->attr_count; ++j)
{
pjmedia_sdp_attr* attr = media->attr[j];
@@ -280,14 +294,14 @@ public:
string foundation;
if (!(is >> foundation))
{
- logger(Error) << "Unable to parse ICE candidate value (foundation) : " << value;
+ errorMessage << "Unable to parse ICE candidate value (foundation) : " << value;
break;
}
int componentId;
if (!(is >> componentId))
{
- logger(Error) << "Unable to parse ICE candidate value (component id) : " << value;
+ errorMessage << "Unable to parse ICE candidate value (component id) : " << value;
break;
}
@@ -297,45 +311,46 @@ public:
string transportDummy;
if (!(is >> transportDummy))
{
- logger(Error) << "Unable to parse ICE candidate value (transport) : " << value;
+ errorMessage << "Unable to parse ICE candidate value (transport) : " << value;
break;
}
int priority;
if (!(is >> priority))
{
- logger(Error) << "Unable to parse ICE candidate value (priority) : " << value;
+ errorMessage << "Unable to parse ICE candidate value (priority) : " << value;
break;
}
string connectionAddress;
if (!(is >> connectionAddress))
{
- logger(Error) << "Unable to parse ICE candidate value (connection address) : " << value;
+ errorMessage << "Unable to parse ICE candidate value (connection address) : " << value;
break;
}
unsigned port;
if (!(is >> port))
{
- logger(Error) << "Unable to parse ICE candidate value (connection port) : " << value;
+ errorMessage << "Unable to parse ICE candidate value (connection port) : " << value;
break;
}
string candidateTypePrefix;
if (!(is >> candidateTypePrefix))
{
- logger(Error) << "Unable to parse ICE candidate constant (typ) : " << value;
+ errorMessage << "Unable to parse ICE candidate constant (typ) : " << value;
break;
}
string candidateType;
if (!(is >> candidateType))
{
- logger(Error) << "Unable to parse ICE candidate value (candidate type) : " << value;
+ errorMessage << "Unable to parse ICE candidate value (candidate type) : " << value;
break;
}
+
CandidatePtr candidateObj = new Candidate;
candidateObj->sessionId = IceUtil::generateUUID(); // this should be the object id.
candidateObj->componentId = 1; // At least until we implement RTCP.
@@ -362,7 +377,7 @@ public:
}
else
{
- logger(Error) << "Unable to determine the candidate type, skipping : " << value;
+ errorMessage << "Unable to determine the candidate type, skipping : " << value;
}
if (candidateType != "host")
@@ -370,27 +385,27 @@ public:
string dummy;
if (!(is >> dummy))
{
- logger(Error) << "Unable to parse ICE candidate constant (raddr) : " << value;
+ errorMessage << "Unable to parse ICE candidate constant (raddr) : " << value;
break;
}
string baseAddress;
if (!(is >> baseAddress))
{
- logger(Error) << "Unable to parse ICE candidate value (rel-addr) : " << value;
+ errorMessage << "Unable to parse ICE candidate value (rel-addr) : " << value;
break;
}
if (!(is >> dummy))
{
- logger(Error) << "Unable to parse ICE candidate constant (rport) : " << value;
+ errorMessage << "Unable to parse ICE candidate constant (rport) : " << value;
break;
}
unsigned basePort;
if (!(is >> basePort))
{
- logger(Error) << "Unable to parse ICE candidate value (rel-port) : " << value;
+ errorMessage << "Unable to parse ICE candidate value (rel-port) : " << value;
break;
}
candidateObj->baseAddress = baseAddress;
@@ -406,6 +421,26 @@ public:
//
mCandidates.push_back(candidateObj);
}
+ string err(errorMessage.str());
+ if (!err.empty())
+ {
+ throw invalid_argument(err);
+ }
+ }
+ }
+ if (mCurrentNegotiation)
+ {
+ if (mCandidates.size() == 0)
+ {
+ logger(Error) << "No candidates after negotiation, looks like fail";
+ mCurrentNegotiation->ice_exception(NoValidCandidates());
+ throw invalid_argument("no valid candidates, did negotiation fail?");
+ }
+ mCurrentNegotiation->ice_response(mCandidates[0]);
+ mCurrentNegotiation = 0;
+ if (mCandidates.size() > 1)
+ {
+ logger(Warning) << "More than one candidate after negotiation!";
}
}
}
@@ -420,6 +455,11 @@ public:
return;
}
mShuttingDown = true;
+ if (mCurrentNegotiation)
+ {
+ pjmedia_transport_media_stop(mTransport);
+ mCurrentNegotiation->ice_exception(NegotiationInterrupted("Shutting down."));
+ }
}
mAdapter->removeFacet(mId, "ICEAgent");
}
@@ -447,6 +487,7 @@ private:
PJMediaEnvironmentPtr mEnv;
PJMediaEndpointPtr mEndpoint;
pjmedia_transport* mTransport;
+ AMD_InteractiveConnectionAgent_negotiatePtr mCurrentNegotiation;
void stateCheck()
{
@@ -521,7 +562,14 @@ void ICECallbackAdapter::addAgent(pjmedia_transport* transport, const ICEAgentIm
i->second.agent = agent;
if (i->second.connected)
{
- agent->onSetupComplete(transport, PJ_SUCCESS);
+ try
+ {
+ agent->onSetupComplete(transport, PJ_SUCCESS);
+ }
+ catch(const invalid_argument& ex)
+ {
+ logger(Error) << "Agent added to map but the setup seems incorrect: " << ex.what();
+ }
}
}
//
-----------------------------------------------------------------------
--
asterisk-scf/integration/media_rtp_pjmedia.git
More information about the asterisk-scf-commits
mailing list