From 4e6f4a917b8976364e58461dab90517055d393a4 Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Mon, 19 Mar 2007 09:44:07 +0000 Subject: [PATCH] sessions can be set onHold with AmSession::setOnHold, if you want a reinvite with on Hold, call AmSession::Reinvite after setOnHold git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@277 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- core/AmMediaProcessor.cpp | 19 +++++++++++++++++++ core/AmMediaProcessor.h | 12 ++++++++---- core/AmRtpStream.cpp | 15 +++++++++++++++ core/AmRtpStream.h | 7 +++++++ core/AmSession.cpp | 15 +++++++++++++++ core/AmSession.h | 8 ++++++++ 6 files changed, 72 insertions(+), 4 deletions(-) diff --git a/core/AmMediaProcessor.cpp b/core/AmMediaProcessor.cpp index 11ff24b6..f41bda51 100644 --- a/core/AmMediaProcessor.cpp +++ b/core/AmMediaProcessor.cpp @@ -121,6 +121,15 @@ void AmMediaProcessor::removeSession(AmSession* s) { removeFromProcessor(s, RemoveSession); } +/* FIXME: implement Call Group ts offsets for soft changing of + call groups +*/ +void AmMediaProcessor::changeCallgroup(AmSession* s, + const string& new_callgroup) { + removeFromProcessor(s, SoftRemoveSession); + addSession(s, new_callgroup); +} + void AmMediaProcessor::removeFromProcessor(AmSession* s, unsigned int r_type) { DBG("AmMediaProcessor::removeSession\n"); @@ -329,6 +338,16 @@ void AmMediaProcessorThread::process(AmEvent* e) break; + case AmMediaProcessor::SoftRemoveSession:{ + AmSession* s = sr->s; + set::iterator s_it = sessions.find(s); + if(s_it != sessions.end()){ + sessions.erase(s_it); + DBG("Session removed softly from the scheduler\n"); + } + } + break; + default: ERROR("AmMediaProcessorThread::process: unknown event id."); break; diff --git a/core/AmMediaProcessor.h b/core/AmMediaProcessor.h index b8908e8e..63277902 100644 --- a/core/AmMediaProcessor.h +++ b/core/AmMediaProcessor.h @@ -101,11 +101,12 @@ class AmMediaProcessor void removeFromProcessor(AmSession* s, unsigned int r_type); public: /** - * InsertSession : inserts the session to the processor - * RemoveSession : remove the session from the processor - * ClearSession : remove the session from processor and clear audio + * InsertSession : inserts the session to the processor + * RemoveSession : remove the session from the processor + * SoftRemoveSession : remove the session from the processor but leave it attached + * ClearSession : remove the session from processor and clear audio */ - enum { InsertSession, RemoveSession, ClearSession }; + enum { InsertSession, RemoveSession, SoftRemoveSession, ClearSession }; static AmMediaProcessor* instance(); @@ -116,6 +117,9 @@ public: void removeSession(AmSession* s); /** Remove session s from processor and clear its audio */ void clearSession(AmSession* s); + /** Change the callgroup of a session (use with caution) */ + void changeCallgroup(AmSession* s, + const string& new_callgroup); }; diff --git a/core/AmRtpStream.cpp b/core/AmRtpStream.cpp index 8d879d15..041bf0bc 100644 --- a/core/AmRtpStream.cpp +++ b/core/AmRtpStream.cpp @@ -164,6 +164,9 @@ void AmRtpStream::setLocalPort() int AmRtpStream::send( unsigned int ts, unsigned char* buffer, unsigned int size ) { + if ((mute) || (hold)) + return 0; + if(!size) return -1; @@ -270,6 +273,7 @@ AmRtpStream::AmRtpStream(AmSession* _s) passive(false), telephone_event_pt(NULL), mute(false), + hold(false), receiving(true) { @@ -302,6 +306,9 @@ AmRtpStream::~AmRtpStream() int AmRtpStream::getLocalPort() { + if (hold) + return 0; + if(!l_port) setLocalPort(); @@ -377,6 +384,14 @@ void AmRtpStream::resume() runcond.set(true); } +void AmRtpStream::setOnHold(bool on_hold) { + mute = hold = on_hold; +} + +bool AmRtpStream::getOnHold() { + return hold; +} + void AmRtpStream::icmpError() { if(!passive){ diff --git a/core/AmRtpStream.h b/core/AmRtpStream.h index 703cb2dd..d1fe170d 100644 --- a/core/AmRtpStream.h +++ b/core/AmRtpStream.h @@ -141,6 +141,7 @@ public: /** Mute */ bool mute; + bool hold; bool begin_talk; /** should we receive packets? if not -> drop */ @@ -222,6 +223,12 @@ public: */ void resume(); + /** set the RTP stream on hold (mute && port = 0) */ + void setOnHold(bool on_hold); + + /** get the RTP stream on hold */ + bool getOnHold(); + /** * Report an ICMP error. */ diff --git a/core/AmSession.cpp b/core/AmSession.cpp index 59b2ea90..ce07f077 100644 --- a/core/AmSession.cpp +++ b/core/AmSession.cpp @@ -143,6 +143,11 @@ void AmSession::setCallgroup(const string& cg) { callgroup = cg; } +void AmSession::changeCallgroup(const string& cg) { + callgroup = cg; + AmMediaProcessor::instance()->changeCallgroup(this, cg); +} + void AmSession::addHandler(AmSessionEventHandler* sess_evh) { if (sess_evh != NULL) @@ -687,3 +692,13 @@ void AmSession::sendInvite() sdp.genRequest(AmConfig::LocalIP,rtp_str.getLocalPort(),sdp_body); dlg.invite("", "application/sdp", sdp_body); } + +void AmSession::setOnHold(bool hold) +{ + lockAudio(); + bool old_hold = rtp_str.getOnHold(); + rtp_str.setOnHold(hold); + if (hold != old_hold) + sendReinvite(); + unlockAudio(); +} diff --git a/core/AmSession.h b/core/AmSession.h index a442d2d3..90852713 100644 --- a/core/AmSession.h +++ b/core/AmSession.h @@ -182,6 +182,11 @@ public: void setCallgroup(const string& cg); string getCallgroup() { return callgroup; } + /** This function removes the session from + * the media processor and adds it again. + */ + void changeCallgroup(const string& cg); + /** * Accept the SDP proposal * thus setting up audio stream @@ -263,6 +268,9 @@ public: /** send an INVITE */ void sendInvite(); + /** set the session on/off hold */ + void setOnHold(bool hold); + /** * Destroy the session. * It causes the session to be erased from the active session list