[asterisk-scf-commits] asterisk-scf/integration/media_rtp_pjmedia.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Oct 18 13:26:32 CDT 2010


branch "master" has been updated
       via  449baec16f07206459917279ce95a2aa577006eb (commit)
       via  1373c9359ca620c4feb00f1028cbe5ebf96972c5 (commit)
       via  2de61a5ed577c72af02ed266f44649cbca3862dc (commit)
      from  7109e4266e63fc36049d8b8e1ed5b15fcbb1e616 (commit)

Summary of changes:
 src/RTPSession.cpp      |    8 ++++++-
 src/RTPSink.cpp         |    7 ++++++
 test/TestRTPpjmedia.cpp |   50 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 1 deletions(-)


- Log -----------------------------------------------------------------
commit 449baec16f07206459917279ce95a2aa577006eb
Author: Joshua Colp <jcolp at digium.com>
Date:   Mon Oct 18 11:24:42 2010 -0700

    Throw the right exception if someone attempts to write out a frame that uses a media format that is not mapped to a payload.

diff --git a/src/RTPSession.cpp b/src/RTPSession.cpp
index 800fc14..19c81f4 100644
--- a/src/RTPSession.cpp
+++ b/src/RTPSession.cpp
@@ -285,10 +285,16 @@ FormatPtr RTPSessionImpl::getFormat(int payload)
 /**
  * API call which returns a payload based on media format.
  *
- * @return The payload number.
+ * @return The payload number or -1 if not found.
  */
 int RTPSessionImpl::getPayload(const FormatPtr& mediaformat)
 {
 	map<string, int>::iterator it = mImpl->mFormatstoPayloads.find(mediaformat->name);
+
+	if (it == mImpl->mFormatstoPayloads.end())
+	{
+	   return -1;
+	}
+
 	return (*it).second;
 }
diff --git a/src/RTPSink.cpp b/src/RTPSink.cpp
index e51b776..76d5519 100644
--- a/src/RTPSink.cpp
+++ b/src/RTPSink.cpp
@@ -89,6 +89,13 @@ void StreamSinkRTPImpl::write(const AsteriskSCF::Media::V1::FrameSeq& frames, co
 
 		const void *header;
 		int header_len;
+		int payload;
+
+		// Only allow media formats through that we support
+		if ((payload = mImpl->mSession->getPayload((*frame)->mediaformat)) < 0)
+		{
+		   throw UnsupportedMediaFormatException();
+		}
 
 		/* 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(),

commit 1373c9359ca620c4feb00f1028cbe5ebf96972c5
Author: Joshua Colp <jcolp at digium.com>
Date:   Mon Oct 18 11:24:32 2010 -0700

    Tweak the test a bit more.

diff --git a/test/TestRTPpjmedia.cpp b/test/TestRTPpjmedia.cpp
index d76834c..e9601d2 100644
--- a/test/TestRTPpjmedia.cpp
+++ b/test/TestRTPpjmedia.cpp
@@ -646,7 +646,7 @@ BOOST_AUTO_TEST_CASE(TransmitandReceiveFrame)
 /**
  * Confirm that trying to write a frame of unknown media format does not cause a crash and throws the correct exception
  */
-BOOST_AUTO_TEST_CASE(TransmitFrameWithUnknownMediaFormat)
+BOOST_AUTO_TEST_CASE(TransmitFrameWithUnsupportedMediaFormat)
 {
 	bool transmitted = true;
 
@@ -677,7 +677,7 @@ BOOST_AUTO_TEST_CASE(TransmitFrameWithUnknownMediaFormat)
 	   StreamSinkRTPPrx sink = StreamSinkRTPPrx::uncheckedCast(sinks.front());
 	   sink->write(frames);
 	}
-	catch (UnsupportedMediaFormatException &umfe)
+	catch (const UnsupportedMediaFormatException&)
 	{
 	   transmitted = false;
 	}

commit 2de61a5ed577c72af02ed266f44649cbca3862dc
Author: Joshua Colp <jcolp at digium.com>
Date:   Mon Oct 18 11:12:48 2010 -0700

    Add a test for confirming that trying to write a frame using an unsupported media format throws the proper exception.

diff --git a/test/TestRTPpjmedia.cpp b/test/TestRTPpjmedia.cpp
index 61a1d1e..d76834c 100644
--- a/test/TestRTPpjmedia.cpp
+++ b/test/TestRTPpjmedia.cpp
@@ -644,6 +644,56 @@ BOOST_AUTO_TEST_CASE(TransmitandReceiveFrame)
 }
 
 /**
+ * Confirm that trying to write a frame of unknown media format does not cause a crash and throws the correct exception
+ */
+BOOST_AUTO_TEST_CASE(TransmitFrameWithUnknownMediaFormat)
+{
+	bool transmitted = true;
+
+	try
+	{
+	   AudioFormatPtr format = new AudioFormat();
+	   format->name = "tacos";
+	   format->frameSize = 20;
+
+	   AudioFramePtr frame = new AudioFrame();
+	   frame->mediaformat = format;
+
+	   frame->payload.push_back('a');
+	   frame->payload.push_back('b');
+	   frame->payload.push_back('c');
+	   frame->payload.push_back('d');
+	   frame->payload.push_back('e');
+	   frame->payload.push_back('f');
+	   frame->payload.push_back('g');
+	   frame->payload.push_back('h');
+	   frame->payload.push_back('i');
+	   frame->payload.push_back('j');
+
+	   FrameSeq frames;
+	   frames.push_back(frame);
+
+	   StreamSinkSeq sinks = Testbed.session->getSinks();
+	   StreamSinkRTPPrx sink = StreamSinkRTPPrx::uncheckedCast(sinks.front());
+	   sink->write(frames);
+	}
+	catch (UnsupportedMediaFormatException &umfe)
+	{
+	   transmitted = false;
+	}
+	catch (const Ice::Exception &e)
+	{
+	   BOOST_TEST_MESSAGE(e.ice_name());
+	   BOOST_TEST_MESSAGE(e.what());
+	}
+	catch (...)
+	{
+	}
+
+	BOOST_CHECK(!transmitted);
+}
+
+/**
  * Confirm receiving an RTP packet that is not payload mapped to a media format does not cause a crash
  */
 BOOST_AUTO_TEST_CASE(ReceiveUnknownRTPPacket)

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/media_rtp_pjmedia.git



More information about the asterisk-scf-commits mailing list