diff --git a/apps/ann_b2b/AnnounceB2B.cpp b/apps/ann_b2b/AnnounceB2B.cpp index d9a820a9..0d6d58d9 100644 --- a/apps/ann_b2b/AnnounceB2B.cpp +++ b/apps/ann_b2b/AnnounceB2B.cpp @@ -105,7 +105,9 @@ AnnounceCallerDialog::AnnounceCallerDialog(const string& filename) void AnnounceCallerDialog::onSessionStart(const AmSipRequest& req) { - setDtmfDetectionEnabled(false); + // we can drop all received packets + // this disables DTMF detection as well + setReceiving(false); callee_addr = req.to; callee_uri = req.r_uri; diff --git a/apps/announce_transfer/AnnounceTransfer.cpp b/apps/announce_transfer/AnnounceTransfer.cpp index cab059d2..f1a2ef6e 100644 --- a/apps/announce_transfer/AnnounceTransfer.cpp +++ b/apps/announce_transfer/AnnounceTransfer.cpp @@ -103,8 +103,9 @@ AnnounceTransferDialog::~AnnounceTransferDialog() void AnnounceTransferDialog::onSessionStart(const AmSipRequest& req) { - // disable DTMF detection - don't use DTMF here - setDtmfDetectionEnabled(false); + // we can drop all received packets + // this disables DTMF detection as well + setReceiving(false); DBG("AnnounceTransferDialog::onSessionStart\n"); if (status == Disconnected) { diff --git a/apps/announcement/Announcement.cpp b/apps/announcement/Announcement.cpp index c3dfe16d..fcffc307 100644 --- a/apps/announcement/Announcement.cpp +++ b/apps/announcement/Announcement.cpp @@ -113,7 +113,9 @@ void AnnouncementDialog::onSessionStart(const AmSipReply& rep) } void AnnouncementDialog::startSession(){ - setDtmfDetectionEnabled(false); + // we can drop all received packets + // this disables DTMF detection as well + setReceiving(false); if(wav_file.open(filename,AmAudioFile::Read)) throw string("AnnouncementDialog::onSessionStart: Cannot open file\n"); diff --git a/apps/early_announce/EarlyAnnounce.cpp b/apps/early_announce/EarlyAnnounce.cpp index 7494a27f..9ab37f58 100644 --- a/apps/early_announce/EarlyAnnounce.cpp +++ b/apps/early_announce/EarlyAnnounce.cpp @@ -129,8 +129,9 @@ EarlyAnnounceDialog::~EarlyAnnounceDialog() void EarlyAnnounceDialog::onSessionStart(const AmSipRequest& req) { - // disable DTMF detection - don't use DTMF here - setDtmfDetectionEnabled(false); + // we can drop all received packets + // this disables DTMF detection as well + setReceiving(false); DBG("EarlyAnnounceDialog::onSessionStart\n"); if(wav_file.open(filename,AmAudioFile::Read)) diff --git a/core/AmMediaProcessor.cpp b/core/AmMediaProcessor.cpp index 7d7b1202..6cd07e98 100644 --- a/core/AmMediaProcessor.cpp +++ b/core/AmMediaProcessor.cpp @@ -217,57 +217,57 @@ void AmMediaProcessorThread::processDtmfEvents() void AmMediaProcessorThread::processAudio(unsigned int ts) { + // receiving for(set::iterator it = sessions.begin(); it != sessions.end(); it++){ - AmSession* s = (*it); - s->lockAudio(); - AmAudio* input = s->getInput(); - - if(s->rtp_str.checkInterval(ts)){ - - //DBG("ts = %u\n",ts); - int ret = s->rtp_str.receive(ts); - if(ret < 0){ - switch(ret){ - - case RTP_DTMF: - case RTP_UNKNOWN_PL: - case RTP_PARSE_ERROR: - break; - - case RTP_TIMEOUT: - postRequest(new SchedRequest(AmMediaProcessor::RemoveSession,s)); - s->postEvent(new AmRtpTimeoutEvent()); - break; - - case RTP_BUFFER_SIZE: - default: - ERROR("AmRtpAudio::receive() returned %i\n",ret); - postRequest(new SchedRequest(AmMediaProcessor::ClearSession,s)); - break; - } - } - else { - unsigned int f_size = s->rtp_str.getFrameSize(); - int size = s->rtp_str.get(ts,buffer,f_size); - if (input) { - - int ret = input->put(ts,buffer,size); - if(ret < 0){ - DBG("input->put() returned: %i\n",ret); - postRequest(new SchedRequest(AmMediaProcessor::ClearSession,s)); - } + AmSession* s = (*it); + if (s->rtp_str.checkInterval(ts) && + (s->rtp_str.receiving || s->rtp_str.getPassiveMode())) { + s->lockAudio(); + AmAudio* input = s->getInput(); + int ret = s->rtp_str.receive(ts); + if(ret < 0){ + switch(ret){ + + case RTP_DTMF: + case RTP_UNKNOWN_PL: + case RTP_PARSE_ERROR: + break; + + case RTP_TIMEOUT: + postRequest(new SchedRequest(AmMediaProcessor::RemoveSession,s)); + s->postEvent(new AmRtpTimeoutEvent()); + break; + + case RTP_BUFFER_SIZE: + default: + ERROR("AmRtpAudio::receive() returned %i\n",ret); + postRequest(new SchedRequest(AmMediaProcessor::ClearSession,s)); + break; + } + } + else { + unsigned int f_size = s->rtp_str.getFrameSize(); + int size = s->rtp_str.get(ts,buffer,f_size); + + if (input) { + int ret = input->put(ts,buffer,size); + if(ret < 0){ + DBG("input->put() returned: %i\n",ret); + postRequest(new SchedRequest(AmMediaProcessor::ClearSession,s)); + } + } + if (s->isDtmfDetectionEnabled()) + s->putDtmfAudio(buffer, size, ts); + } + s->unlockAudio(); } - if (s->isDtmfDetectionEnabled()) - s->putDtmfAudio(buffer, size, ts); - } - } - s->unlockAudio(); } + // sending for(set::iterator it = sessions.begin(); - it != sessions.end(); it++){ + it != sessions.end(); it++){ AmSession* s = (*it); s->lockAudio(); @@ -278,13 +278,12 @@ void AmMediaProcessorThread::processAudio(unsigned int ts) int size = output->get(ts,buffer,s->rtp_str.getFrameSize()); if(size <= 0){ DBG("output->get() returned: %i\n",size); - postRequest(new SchedRequest(AmMediaProcessor::ClearSession,s)); //removeSession(s); + postRequest(new SchedRequest(AmMediaProcessor::ClearSession,s)); } else if(!s->rtp_str.mute){ if(s->rtp_str.put(ts,buffer,size)<0) postRequest(new SchedRequest(AmMediaProcessor::ClearSession,s)); - // removeSession(s); } } s->unlockAudio(); diff --git a/core/AmRtpStream.cpp b/core/AmRtpStream.cpp index 593382d5..67c859a5 100644 --- a/core/AmRtpStream.cpp +++ b/core/AmRtpStream.cpp @@ -203,26 +203,28 @@ int AmRtpStream::receive( unsigned char* buffer, unsigned int size, if(err <= 0) return err; -#ifdef SUPPORT_IPV6 - struct sockaddr_storage recv_addr; -#else - struct sockaddr_in recv_addr; -#endif - rp.getAddr(&recv_addr); - #ifndef SUPPORT_IPV6 - // symmetric RTP - if( passive && ((recv_addr.sin_port != r_saddr.sin_port) + if(passive) { +// #ifdef SUPPORT_IPV6 +// struct sockaddr_storage recv_addr; +// #else + struct sockaddr_in recv_addr; + rp.getAddr(&recv_addr); + + // symmetric RTP + if ((recv_addr.sin_port != r_saddr.sin_port) || (recv_addr.sin_addr.s_addr - != r_saddr.sin_addr.s_addr)) ) { - - string addr_str = get_addr_str(recv_addr.sin_addr); - int port = ntohs(recv_addr.sin_port); - setRAddr(addr_str,port); - DBG("Symmetric RTP: setting new remote address: %s:%i\n",addr_str.c_str(),port); - // avoid comparing each time sender address - passive = false; - } + != r_saddr.sin_addr.s_addr)) { + + string addr_str = get_addr_str(recv_addr.sin_addr); + int port = ntohs(recv_addr.sin_port); + setRAddr(addr_str,port); + DBG("Symmetric RTP: setting new remote address: %s:%i\n", + addr_str.c_str(),port); + // avoid comparing each time sender address + passive = false; + } + } #endif if(rp.parse() == -1){ @@ -358,9 +360,9 @@ AmRtpStream::AmRtpStream(AmSession* _s) r_ssrc_i(false), session(_s), passive(false), - first_recved(false), telephone_event_pt(NULL), - mute(false) + mute(false), + receiving(true) #ifdef USE_ADAPTIVE_JB , m_main_jb(new AmJitterBuffer(this)), @@ -478,7 +480,7 @@ void AmRtpStream::resume() void AmRtpStream::icmpError() { - if(!passive || first_recved.get()){ + if(!passive){ AmIcmpWatcher::instance()->removeStream(l_port); if(session) session->stop(); @@ -488,6 +490,9 @@ void AmRtpStream::icmpError() #ifndef USE_ADAPTIVE_JB void AmRtpStream::bufferPacket(const AmRtpPacket* p) { + if (!receiving && !passive) + return; + jitter_mut.lock(); gettimeofday(&last_recv_time,NULL); jitter_buf[p->timestamp].copy(p); @@ -496,6 +501,9 @@ void AmRtpStream::bufferPacket(const AmRtpPacket* p) int AmRtpStream::nextPacket(AmRtpPacket& p) { + if (!receiving && !passive) + return RTP_EMPTY; + struct timeval now; struct timeval diff; gettimeofday(&now,NULL); @@ -524,6 +532,9 @@ int AmRtpStream::nextPacket(AmRtpPacket& p) #else void AmRtpStream::bufferPacket(const AmRtpPacket* p) { + if (!receiving && !passive) + return; + gettimeofday(&last_recv_time,NULL); if (p->payload == payload && m_main_jb) m_main_jb->put(p); @@ -533,6 +544,9 @@ void AmRtpStream::bufferPacket(const AmRtpPacket* p) int AmRtpStream::nextAudioPacket(AmRtpPacket& p, unsigned int ts, unsigned int ms) { + if (!receiving && !passive) + return RTP_EMPTY; + if (m_main_jb && m_main_jb->get(p, ts, ms)) return 1; diff --git a/core/AmRtpStream.h b/core/AmRtpStream.h index 2a9b23be..367a75b2 100644 --- a/core/AmRtpStream.h +++ b/core/AmRtpStream.h @@ -129,7 +129,6 @@ protected: /** symmetric RTP */ bool passive; // passive mode ? - AmSharedVar first_recved; // first packet received ? /** Payload type for telephone event */ auto_ptr telephone_event_pt; @@ -161,6 +160,9 @@ public: bool mute; bool begin_talk; + /** should we receive packets? if not -> drop */ + bool receiving; + int send( unsigned int ts, unsigned char* buffer, unsigned int size ); @@ -211,6 +213,7 @@ public: /** Symmetric RTP: passive mode ? */ void setPassiveMode(bool p) { passive = p; } + bool getPassiveMode() { return passive; } /** * Set remote telephone event diff --git a/core/AmSession.h b/core/AmSession.h index 82ff5b48..4152cac9 100644 --- a/core/AmSession.h +++ b/core/AmSession.h @@ -216,6 +216,9 @@ public: /** setter for rtp_str->mute */ void setMute(bool mute) { rtp_str.mute = mute; } + /** setter for rtp_str->receiving */ + void setReceiving(bool receive) { rtp_str.receiving = receive; } + /** Gets the Session's call ID */ const string& getCallID() const;