drops received packets if not using input

set this with AmSession::setReceiving



git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@243 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Stefan Sayer 20 years ago
parent a9d3e589cc
commit 866b8703ac

@ -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;

@ -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) {

@ -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");

@ -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))

@ -217,57 +217,57 @@ void AmMediaProcessorThread::processDtmfEvents()
void AmMediaProcessorThread::processAudio(unsigned int ts)
{
// receiving
for(set<AmSession*>::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<AmSession*>::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();

@ -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;

@ -129,7 +129,6 @@ protected:
/** symmetric RTP */
bool passive; // passive mode ?
AmSharedVar<bool> first_recved; // first packet received ?
/** Payload type for telephone event */
auto_ptr<const SdpPayload> 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

@ -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;

Loading…
Cancel
Save