Commit d149220b authored by Guillaume Roguez's avatar Guillaume Roguez

sdp: alloc dedicated memory pool per Sdp instance

Refs #62797

Change-Id: I5432f31efa25c228146db3c2800c746105afcf1a
parent 46a8800d
This diff is collapsed.
......@@ -70,17 +70,10 @@ class Sdp {
*
* @param memory pool
*/
Sdp(pj_pool_t *pool);
Sdp(const std::string& id);
~Sdp();
/**
* Accessor for the internal memory pool
*/
pj_pool_t *getMemoryPool() const {
return memPool_;
}
/**
* Read accessor. Get the local passive sdp session information before negotiation
*
......@@ -304,10 +297,9 @@ class Sdp {
void updateRemoteIP(unsigned index);
/**
* The pool to allocate memory, ownership to SipCall
* SDP should not release the pool itself
* The pool to allocate memory
*/
pj_pool_t *memPool_;
std::unique_ptr<pj_pool_t, decltype(pj_pool_release)&> memPool_;
/** negotiator */
pjmedia_sdp_neg *negotiator_;
......
......@@ -136,8 +136,9 @@ SIPCall::SIPCall(SIPAccountBase& account, const std::string& id, Call::CallType
#endif
, pool_(pj_pool_create(&getSIPVoIPLink()->getCachingPool()->factory,
id.c_str(), INITIAL_SIZE, INCREMENT_SIZE, NULL))
, sdp_(new Sdp(pool_))
{}
, sdp_(new Sdp(id))
{
}
SIPCall::~SIPCall()
{
......@@ -150,8 +151,6 @@ SIPCall::~SIPCall()
inv->mod_data[mod_ua_id] = nullptr;
}
// local sdp must be destroyed before pool
sdp_.reset();
pj_pool_release(pool_);
}
......
......@@ -101,23 +101,18 @@ static const char *const LOCALHOST = "127.0.0.1";
void SDPTest::setUp()
{
pj_caching_pool_init(&poolCache_, &pj_pool_factory_default_policy, 0);
testPool_ = pj_pool_create(&poolCache_.factory, "sdptest", 4000, 4000, NULL);
session_ = new Sdp(testPool_);
session_.reset(new Sdp("123456789"));
}
void SDPTest::tearDown()
{
delete session_;
session_ = NULL;
pj_pool_release(testPool_);
session_.reset();
}
void SDPTest::receiveAnswerAfterInitialOffer(const pjmedia_sdp_session* remote)
{
CPPUNIT_ASSERT(pjmedia_sdp_neg_get_state(session_->negotiator_) == PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER);
CPPUNIT_ASSERT(pjmedia_sdp_neg_set_remote_answer(session_->memPool_, session_->negotiator_, remote) == PJ_SUCCESS);
CPPUNIT_ASSERT(pjmedia_sdp_neg_set_remote_answer(session_->memPool_.get(), session_->negotiator_, remote) == PJ_SUCCESS);
CPPUNIT_ASSERT(pjmedia_sdp_neg_get_state(session_->negotiator_) == PJMEDIA_SDP_NEG_STATE_WAIT_NEGO);
}
......@@ -158,7 +153,7 @@ void SDPTest::testInitialOfferFirstCodec()
session_->createOffer(codecSelection, videoCodecs);
pjmedia_sdp_session *remoteAnswer;
pjmedia_sdp_parse(testPool_, (char*) sdp_answer1, strlen(sdp_answer1), &remoteAnswer);
pjmedia_sdp_parse(session_->memPool_.get(), (char*) sdp_answer1, strlen(sdp_answer1), &remoteAnswer);
receiveAnswerAfterInitialOffer(remoteAnswer);
session_->startNegotiation();
......@@ -183,7 +178,7 @@ void SDPTest::testInitialAnswerFirstCodec()
codecSelection.push_back(PAYLOAD_CODEC_ALAW);
codecSelection.push_back(PAYLOAD_CODEC_G722);
pjmedia_sdp_parse(testPool_, (char*) sdp_offer1, strlen(sdp_offer1), &remoteOffer);
pjmedia_sdp_parse(session_->memPool_.get(), (char*) sdp_offer1, strlen(sdp_offer1), &remoteOffer);
session_->setPublishedIP(LOCALHOST);
session_->setLocalPublishedAudioPort(49567);
......@@ -217,7 +212,7 @@ void SDPTest::testInitialOfferLastCodec()
session_->createOffer(codecSelection, createVideoCodecs());
pjmedia_sdp_session *remoteAnswer;
pjmedia_sdp_parse(testPool_, (char*) sdp_answer2, strlen(sdp_answer2), &remoteAnswer);
pjmedia_sdp_parse(session_->memPool_.get(), (char*) sdp_answer2, strlen(sdp_answer2), &remoteAnswer);
receiveAnswerAfterInitialOffer(remoteAnswer);
session_->startNegotiation();
......@@ -242,7 +237,7 @@ void SDPTest::testInitialAnswerLastCodec()
codecSelection.push_back(PAYLOAD_CODEC_ALAW);
codecSelection.push_back(PAYLOAD_CODEC_G722);
pjmedia_sdp_parse(testPool_, (char*)sdp_offer2, strlen(sdp_offer2), &remoteOffer);
pjmedia_sdp_parse(session_->memPool_.get(), (char*)sdp_offer2, strlen(sdp_offer2), &remoteOffer);
session_->setPublishedIP(LOCALHOST);
session_->setLocalPublishedAudioPort(49567);
......@@ -277,8 +272,8 @@ void SDPTest::testReinvite()
session_->createOffer(codecSelection, videoCodecs);
pjmedia_sdp_session *remoteAnswer;
// pjmedia_sdp_parse(testPool_, test[0].offer_answer[0].sdp2, strlen(test[0].offer_answer[0].sdp2), &remoteAnswer);
pjmedia_sdp_parse(testPool_, (char*) sdp_answer1, strlen(sdp_answer1), &remoteAnswer);
// pjmedia_sdp_parse(session_->memPool_.get(), test[0].offer_answer[0].sdp2, strlen(test[0].offer_answer[0].sdp2), &remoteAnswer);
pjmedia_sdp_parse(session_->memPool_.get(), (char*) sdp_answer1, strlen(sdp_answer1), &remoteAnswer);
receiveAnswerAfterInitialOffer(remoteAnswer);
session_->startNegotiation();
......@@ -292,7 +287,7 @@ void SDPTest::testReinvite()
CPPUNIT_ASSERT(codec and codec->getMimeSubtype() == "PCMU");
pjmedia_sdp_session *reinviteOffer;
pjmedia_sdp_parse(testPool_, (char*) sdp_reinvite, strlen(sdp_reinvite), &reinviteOffer);
pjmedia_sdp_parse(session_->memPool_.get(), (char*) sdp_reinvite, strlen(sdp_reinvite), &reinviteOffer);
session_->receiveOffer(reinviteOffer, codecSelection, videoCodecs);
session_->startNegotiation();
......
......@@ -46,6 +46,7 @@
#include <exception>
#include <string>
#include <memory>
#include <pj/pool.h>
#include <pjmedia/sdp.h>
......@@ -88,8 +89,7 @@ class SDPTest : public CppUnit::TestCase {
CPPUNIT_TEST_SUITE_END();
public:
SDPTest() : CppUnit::TestCase("SDP module Tests"), session_(0),
testPool_(0), poolCache_() {}
SDPTest() : CppUnit::TestCase("SDP module Tests") {}
/**
* Code factoring - Common resources can be initialized here.
......@@ -117,9 +117,7 @@ class SDPTest : public CppUnit::TestCase {
NON_COPYABLE(SDPTest);
void receiveAnswerAfterInitialOffer(const pjmedia_sdp_session* remote);
Sdp *session_;
pj_pool_t *testPool_;
pj_caching_pool poolCache_;
std::unique_ptr<Sdp> session_;
};
/* Register our test module */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment