create RTP stream (AmSession::rtp_str) only if really needed

replace AmSession::rtp_str with AmSession::RTPStream() in your app.

for example for pure signaling B2B calls, no RTP stream instance is
created, which saves a lot of memory (especially because of        
the RTP receive buffer)     


ref r30371 r30372


git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1784 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Stefan Sayer 17 years ago
parent b339b41bc7
commit c6d9ae3bbf

@ -109,8 +109,8 @@ void AuthB2BDialog::onInvite(const AmSipRequest& req)
// -> only in SessionFactory::onInvite they do. todo: move the logic to
// session factory
setReceiving(false);
AmMediaProcessor::instance()->removeSession(this);
// this will prevent us from being added to media processor
setInOut(NULL,NULL);
if (AuthB2BFactory::user.empty()) {
string app_param = getHeader(req.hdrs, PARAM_HDR);
@ -131,10 +131,10 @@ void AuthB2BDialog::onInvite(const AmSipRequest& req)
from = "sip:"+user+"@"+domain;
to = "sip:"+req.user+"@"+domain;
// DBG("-----------------------------------------------------------------\n");
// DBG("domain = %s, user = %s, pwd = %s, from = %s, to = %s;",
// domain.c_str(), user.c_str(), password.c_str(), from.c_str(), to.c_str());
// DBG("-----------------------------------------------------------------\n");
// DBG("-----------------------------------------------------------------\n");
// DBG("domain = %s, user = %s, pwd = %s, from = %s, to = %s;",
// domain.c_str(), user.c_str(), password.c_str(), from.c_str(), to.c_str());
// DBG("-----------------------------------------------------------------\n");
m_state = BB_Dialing;

@ -137,8 +137,8 @@ void CallTimerDialog::onInvite(const AmSipRequest& req)
return;
}
setReceiving(false);
AmMediaProcessor::instance()->removeSession(this);
// this will prevent us from being added to media processor
setInOut(NULL,NULL);
m_state = BB_Dialing;

@ -228,7 +228,7 @@ CallBackDialog::CallBackDialog(AmPromptCollection& prompts,
state(CBNone)
{
// set configured playout type
rtp_str.setPlayoutType(CallBackFactory::m_PlayoutType);
RTPStream()->setPlayoutType(CallBackFactory::m_PlayoutType);
}
CallBackDialog::~CallBackDialog()
@ -321,7 +321,7 @@ CallBackCalleeDialog::CallBackCalleeDialog(const string& other_tag,
: AmB2ABCalleeSession(other_tag, connector), cred(cred)
{
// set configured playout type
rtp_str.setPlayoutType(CallBackFactory::m_PlayoutType);
RTPStream()->setPlayoutType(CallBackFactory::m_PlayoutType);
setDtmfDetectionEnabled(false);
}

@ -349,7 +349,7 @@ ConferenceDialog::ConferenceDialog(const string& conf_id,
allow_dialout(false)
{
dialedout = this->dialout_channel.get() != 0;
rtp_str.setPlayoutType(ConferenceFactory::m_PlayoutType);
RTPStream()->setPlayoutType(ConferenceFactory::m_PlayoutType);
#ifdef WITH_SAS_TTS
tts_voice = register_cmu_us_kal();
#endif
@ -763,7 +763,7 @@ void ConferenceDialog::createDialoutParticipant(const string& uri_user)
dialout_dlg.remote_uri = uri;
string body;
int local_port = dialout_session->rtp_str.getLocalPort();
int local_port = dialout_session->RTPStream()->getLocalPort();
dialout_session->sdp.genRequest(AmConfig::LocalIP,local_port,body);
if (extra_headers.length() == 0) {
@ -855,7 +855,7 @@ void ConferenceDialog::onSipRequest(const AmSipRequest& req)
DBG("ConferenceDialog::onSipRequest: remote_tag = %s\n",dlg.remote_tag.c_str());
string body;
int local_port = rtp_str.getLocalPort();
int local_port = RTPStream()->getLocalPort();
sdp.genRequest(AmConfig::LocalIP,local_port,body);
dlg.sendRequest("INVITE","application/sdp",body,"");

@ -195,9 +195,9 @@ EXEC_ACTION_START(ConfRejoinAction) {
EXEC_ACTION_START(ConfSetPlayoutTypeAction) {
string playout_type = resolveVars(arg, sess, sc_sess, event_params);
if (playout_type == "adaptive")
sess->rtp_str.setPlayoutType(ADAPTIVE_PLAYOUT);
sess->RTPStream()->setPlayoutType(ADAPTIVE_PLAYOUT);
else if (playout_type == "jb")
sess->rtp_str.setPlayoutType(JB_PLAYOUT);
sess->RTPStream()->setPlayoutType(JB_PLAYOUT);
else
sess->rtp_str.setPlayoutType(SIMPLE_PLAYOUT);
sess->RTPStream()->setPlayoutType(SIMPLE_PLAYOUT);
} EXEC_ACTION_END;

@ -93,7 +93,7 @@ b2b_connectDialog::b2b_connectDialog() // AmDynInvoke* user_timer)
AmB2ABCallerSession()
{
rtp_str.setPlayoutType(ADAPTIVE_PLAYOUT);
RTPStream()->setPlayoutType(ADAPTIVE_PLAYOUT);
}
b2b_connectDialog::~b2b_connectDialog()
@ -274,7 +274,7 @@ b2b_connectCalleeSession::b2b_connectCalleeSession(const string& other_tag,
: credentials("", user, pwd), // domain (realm) is unused in credentials
AmB2ABCalleeSession(other_tag, connector)
{
rtp_str.setPlayoutType(ADAPTIVE_PLAYOUT);
RTPStream()->setPlayoutType(ADAPTIVE_PLAYOUT);
setDtmfDetectionEnabled(false);
}

@ -101,7 +101,7 @@ PinAuthConferenceDialog::PinAuthConferenceDialog(AmPromptCollection& prompts)
: play_list(this), separator(this, 0), prompts(prompts), state(None)
{
// set configured playout type
rtp_str.setPlayoutType(PinAuthConferenceFactory::m_PlayoutType);
RTPStream()->setPlayoutType(PinAuthConferenceFactory::m_PlayoutType);
}
PinAuthConferenceDialog::~PinAuthConferenceDialog()

@ -204,7 +204,7 @@ ServiceLineCalleeDialog::ServiceLineCalleeDialog(const string& other_tag,
ServiceLineFactory::GWAuthuser,
ServiceLineFactory::GWAuthpwd)
{
rtp_str.setPlayoutType(ADAPTIVE_PLAYOUT);
RTPStream()->setPlayoutType(ADAPTIVE_PLAYOUT);
setDtmfDetectionEnabled(false);
}

@ -60,7 +60,7 @@ SimpleConferenceDialog::SimpleConferenceDialog()
: play_list(this)
{
// use adaptive playout - its the best method around
rtp_str.setPlayoutType(ADAPTIVE_PLAYOUT);
RTPStream()->setPlayoutType(ADAPTIVE_PLAYOUT);
}
SimpleConferenceDialog::~SimpleConferenceDialog()

@ -26,7 +26,7 @@ void GWSession::setOtherLeg(AmAudio *otherleg) {
}
void GWSession::onInvite(const AmSipRequest& req) {
DBG("GWSession::onInvite\n");
// rtp_str.setMonitorRTPTimeout(false);
// RTPStream()->setMonitorRTPTimeout(false);
invite_req=req;
return;
}

@ -118,8 +118,8 @@ void SWPrepaidSIPDialog::onInvite(const AmSipRequest& req)
// TODO: errors thrown as exception don't seem to trigger a reply?
setReceiving(false);
AmMediaProcessor::instance()->removeSession(this);
// this will prevent us from being added to media processor
setInOut(NULL,NULL);
m_uuid = getHeader(req.hdrs,"P-Caller-Uuid");
if(!m_uuid.length()) {

@ -40,7 +40,7 @@ WebConferenceDialog::WebConferenceDialog(AmPromptCollection& prompts,
is_dialout = (cred != NULL);
accept_early_session = is_dialout;
// set configured playout type
rtp_str.setPlayoutType(WebConferenceFactory::m_PlayoutType);
RTPStream()->setPlayoutType(WebConferenceFactory::m_PlayoutType);
}
WebConferenceDialog::WebConferenceDialog(AmPromptCollection& prompts,
@ -54,7 +54,7 @@ WebConferenceDialog::WebConferenceDialog(AmPromptCollection& prompts,
DBG("set conf_id to %s\n", conf_id.c_str());
is_dialout = false;
// set configured playout type
rtp_str.setPlayoutType(WebConferenceFactory::m_PlayoutType);
RTPStream()->setPlayoutType(WebConferenceFactory::m_PlayoutType);
}
WebConferenceDialog::~WebConferenceDialog()

@ -284,10 +284,10 @@ void AmMediaProcessorThread::processAudio(unsigned int ts)
AmSession* s = (*it);
// todo: get frame size/checkInterval from local audio if local in+out (?)
unsigned int f_size = s->rtp_str.getFrameSize();
unsigned int f_size = s->RTPStream()->getFrameSize();
// complete frame time reached?
if (s->rtp_str.checkInterval(ts, f_size)) {
if (s->RTPStream()->checkInterval(ts, f_size)) {
s->lockAudio();
int got_audio = -1;
@ -295,8 +295,8 @@ void AmMediaProcessorThread::processAudio(unsigned int ts)
// get/receive audio
if (!s->getAudioLocal(AM_AUDIO_IN)) {
// input is not local - receive from rtp stream
if (s->rtp_str.receiving || s->rtp_str.getPassiveMode()) {
int ret = s->rtp_str.receive(ts);
if (s->RTPStream()->receiving || s->RTPStream()->getPassiveMode()) {
int ret = s->RTPStream()->receive(ts);
if(ret < 0){
switch(ret){
@ -317,7 +317,7 @@ void AmMediaProcessorThread::processAudio(unsigned int ts)
break;
}
} else {
got_audio = s->rtp_str.get(ts,buffer,f_size);
got_audio = s->RTPStream()->get(ts,buffer,f_size);
if (s->isDtmfDetectionEnabled() && got_audio > 0)
s->putDtmfAudio(buffer, got_audio, ts);
@ -355,9 +355,9 @@ void AmMediaProcessorThread::processAudio(unsigned int ts)
s->lockAudio();
AmAudio* output = s->getOutput();
if(output && s->rtp_str.sendIntReached()){
if(output && s->RTPStream()->sendIntReached()){
int size = output->get(ts,buffer,s->rtp_str.getFrameSize());
int size = output->get(ts,buffer,s->RTPStream()->getFrameSize());
if(size <= 0){
DBG("output->get() returned: %i\n",size);
postRequest(new SchedRequest(AmMediaProcessor::ClearSession,s));
@ -365,8 +365,8 @@ void AmMediaProcessorThread::processAudio(unsigned int ts)
else {
if (!s->getAudioLocal(AM_AUDIO_OUT)) {
// audio should go to RTP
if(!s->rtp_str.mute){
if(s->rtp_str.put(ts,buffer,size)<0)
if(!s->RTPStream()->mute){
if(s->RTPStream()->put(ts,buffer,size)<0)
postRequest(new SchedRequest(AmMediaProcessor::ClearSession,s));
}
} else {

@ -61,7 +61,7 @@ AmSession::AmSession()
: AmEventQueue(this),
dlg(this),
detached(true),
sess_stopped(false),rtp_str(this),negotiate_onreply(false),
sess_stopped(false),negotiate_onreply(false),
input(0), output(0), local_input(0), local_output(0),
m_dtmfDetector(this), m_dtmfEventQueue(&m_dtmfDetector),
m_dtmfDetectionEnabled(true),
@ -216,7 +216,7 @@ const vector<SdpPayload*>& AmSession::getPayloads()
int AmSession::getRPort()
{
return rtp_str.getRPort();
return RTPStream()->getRPort();
}
AmPayloadProviderInterface* AmSession::getPayloadProvider() {
@ -270,7 +270,7 @@ void AmSession::negotiate(const string& sdp_body,
telephone_event_payload->payload_type);
lockAudio();
rtp_str.setTelephoneEventPT(telephone_event_payload);
RTPStream()->setTelephoneEventPT(telephone_event_payload);
unlockAudio();
}
else {
@ -288,9 +288,9 @@ void AmSession::negotiate(const string& sdp_body,
lockAudio();
try {
rtp_str.setLocalIP(AmConfig::LocalIP);
rtp_str.setPassiveMode(passive_mode);
rtp_str.setRAddr(r_host, r_port);
RTPStream()->setLocalIP(AmConfig::LocalIP);
RTPStream()->setPassiveMode(passive_mode);
RTPStream()->setRAddr(r_host, r_port);
} catch (const string& err_str) {
unlockAudio();
throw AmSession::Exception(400, err_str);
@ -301,7 +301,9 @@ void AmSession::negotiate(const string& sdp_body,
unlockAudio();
if(sdp_reply)
sdp.genResponse(advertisedIP(), rtp_str.getLocalPort(), *sdp_reply, AmConfig::SingleCodecInOK);
sdp.genResponse(advertisedIP(),
RTPStream()->getLocalPort(),
*sdp_reply, AmConfig::SingleCodecInOK);
}
#ifdef SESSION_THREADPOOL
@ -359,7 +361,7 @@ bool AmSession::startup() {
return false;
}
zrtp_audio = zrtp_attach_stream(zrtp_session, rtp_str.get_ssrc());
zrtp_audio = zrtp_attach_stream(zrtp_session, RTPStream()->get_ssrc());
zrtp_audio->stream_usr_data = this;
if (NULL == zrtp_audio) {
@ -764,7 +766,7 @@ void AmSession::onSipReply(const AmSipReply& reply)
case AmSipDialog::Connected:
try {
rtp_str.setMonitorRTPTimeout(true);
RTPStream()->setMonitorRTPTimeout(true);
acceptAudio(reply.body,reply.hdrs);
@ -797,7 +799,7 @@ void AmSession::onSipReply(const AmSipReply& reply)
onRinging(reply);
rtp_str.setMonitorRTPTimeout(false);
RTPStream()->setMonitorRTPTimeout(false);
if(input || output || local_input || local_output)
AmMediaProcessor::instance()->addSession(this,
@ -813,10 +815,10 @@ void AmSession::onSipReply(const AmSipReply& reply)
onEarlySessionStart(reply);
rtp_str.setMonitorRTPTimeout(false);
RTPStream()->setMonitorRTPTimeout(false);
// ping the other side to open fw/NAT/symmetric RTP
rtp_str.ping();
RTPStream()->ping();
if(input || output || local_input || local_output)
AmMediaProcessor::instance()->addSession(this,
@ -876,11 +878,11 @@ int AmSession::acceptAudio(const string& body,
// enable RTP stream
lockAudio();
rtp_str.init(m_payloads);
RTPStream()->init(m_payloads);
unlockAudio();
DBG("Sending Rtp data to %s/%i\n",
rtp_str.getRHost().c_str(),rtp_str.getRPort());
RTPStream()->getRHost().c_str(),RTPStream()->getRPort());
return 0;
}
@ -935,9 +937,9 @@ void AmSession::sendUpdate()
void AmSession::sendReinvite(bool updateSDP, const string& headers)
{
if (updateSDP) {
rtp_str.setLocalIP(AmConfig::LocalIP);
RTPStream()->setLocalIP(AmConfig::LocalIP);
string sdp_body;
sdp.genResponse(advertisedIP(), rtp_str.getLocalPort(), sdp_body);
sdp.genResponse(advertisedIP(), RTPStream()->getLocalPort(), sdp_body);
dlg.reinvite(headers, "application/sdp", sdp_body);
} else {
dlg.reinvite(headers, "", "");
@ -950,19 +952,19 @@ int AmSession::sendInvite(const string& headers)
// Set local IP first, so that IP is set when
// getLocalPort/setLocalPort may bind.
rtp_str.setLocalIP(AmConfig::LocalIP);
RTPStream()->setLocalIP(AmConfig::LocalIP);
// Generate SDP.
string sdp_body;
sdp.genRequest(advertisedIP(), rtp_str.getLocalPort(), sdp_body);
sdp.genRequest(advertisedIP(), RTPStream()->getLocalPort(), sdp_body);
return dlg.invite(headers, "application/sdp", sdp_body);
}
void AmSession::setOnHold(bool hold)
{
lockAudio();
bool old_hold = rtp_str.getOnHold();
rtp_str.setOnHold(hold);
bool old_hold = RTPStream()->getOnHold();
RTPStream()->setOnHold(hold);
if (hold != old_hold)
sendReinvite();
unlockAudio();

@ -144,7 +144,9 @@ private:
friend class AmSessionContainer;
friend class AmSessionFactory;
friend class AmSessionProcessorThread;
auto_ptr<AmRtpAudio> _rtp_str;
protected:
AmSdp sdp;
@ -159,7 +161,7 @@ protected:
public:
AmRtpAudio rtp_str;
AmRtpAudio* RTPStream();
#ifdef WITH_ZRTP
zrtp_conn_ctx_t* zrtp_session; // ZRTP session
@ -286,10 +288,10 @@ public:
void clearAudio();
/** setter for rtp_str->mute */
void setMute(bool mute) { rtp_str.mute = mute; }
void setMute(bool mute) { RTPStream()->mute = mute; }
/** setter for rtp_str->receiving */
void setReceiving(bool receive) { rtp_str.receiving = receive; }
void setReceiving(bool receive) { RTPStream()->receiving = receive; }
/** Gets the Session's call ID */
const string& getCallID() const;
@ -510,6 +512,15 @@ public:
string advertisedIP();
};
inline AmRtpAudio* AmSession::RTPStream() {
if (NULL == _rtp_str.get()) {
DBG("creating RTP stream instance for session [%p]\n",
this);
_rtp_str.reset(new AmRtpAudio(this));
}
return _rtp_str.get();
}
#endif
// Local Variables:

@ -104,13 +104,13 @@ EchoDialog::~EchoDialog()
void EchoDialog::onSessionStart(const AmSipRequest& req)
{
rtp_str.setPlayoutType(playout_type);
RTPStream()->setPlayoutType(playout_type);
setInOut(&echo,&echo);
}
void EchoDialog::onSessionStart(const AmSipReply& req)
{
rtp_str.setPlayoutType(playout_type);
RTPStream()->setPlayoutType(playout_type);
setInOut(&echo,&echo);
}
@ -134,7 +134,7 @@ void EchoDialog::onDtmf(int event, int duration)
playout_type = SIMPLE_PLAYOUT;
DBG("received *. set playout technique to %s.\n", pt);
rtp_str.setPlayoutType(playout_type);
RTPStream()->setPlayoutType(playout_type);
}
#endif
}

Loading…
Cancel
Save