diff --git a/core/AmPlayoutBuffer.cpp b/core/AmPlayoutBuffer.cpp index d928df9c..d07d66a6 100644 --- a/core/AmPlayoutBuffer.cpp +++ b/core/AmPlayoutBuffer.cpp @@ -18,7 +18,6 @@ #define MAX_DELAY 8000 /* 1 second */ - AmPlayoutBuffer::AmPlayoutBuffer(AmRtpAudio *owner) : r_ts(0),w_ts(0), last_ts_i(false), m_owner(owner) { @@ -31,7 +30,7 @@ void AmPlayoutBuffer::direct_write_buffer(unsigned int ts, ShortSample* buf, uns void AmPlayoutBuffer::write(u_int32_t ref_ts, u_int32_t rtp_ts, int16_t* buf, u_int32_t len, bool begin_talk) -{ +{ unsigned int mapped_ts; if(!recv_offset_i) { diff --git a/core/AmRtpAudio.cpp b/core/AmRtpAudio.cpp index 9a31c497..f1f6892c 100644 --- a/core/AmRtpAudio.cpp +++ b/core/AmRtpAudio.cpp @@ -103,18 +103,18 @@ int AmRtpAudio::receive(unsigned int audio_buffer_ts) return size; } -int AmRtpAudio::get(unsigned int user_ts, unsigned char* buffer, unsigned int nb_samples) +int AmRtpAudio::get(unsigned int ref_ts, unsigned char* buffer, unsigned int nb_samples) { - int size = read(user_ts,PCM16_S2B(nb_samples)); + int size = read(ref_ts,PCM16_S2B(nb_samples)); memcpy(buffer,(unsigned char*)samples,size); return size; } -int AmRtpAudio::read(unsigned int user_ts, unsigned int size) +int AmRtpAudio::read(unsigned int ref_ts, unsigned int size) { u_int32_t rlen = playout_buffer - ->read(user_ts, + ->read(ref_ts, (ShortSample*)((unsigned char*)samples), PCM16_B2S(size)); diff --git a/core/AmRtpReceiver.cpp b/core/AmRtpReceiver.cpp index 31947796..f7cb1f3d 100644 --- a/core/AmRtpReceiver.cpp +++ b/core/AmRtpReceiver.cpp @@ -91,12 +91,19 @@ void AmRtpReceiver::run() if(p.recv(tmp_fds[i].fd) > 0){ + int parse_res = p.parse(); gettimeofday(&p.recv_time,NULL); streams_mut.lock(); Streams::iterator it = streams.find(tmp_fds[i].fd); - if(it != streams.end()) - it->second->bufferPacket(&p); + if(it != streams.end()) { + if (parse_res == -1) { + DBG("error while parsing RTP packet.\n"); + it->second->clearRTPTimeout(&p.recv_time); + } else { + it->second->bufferPacket(&p); + } + } streams_mut.unlock(); } } diff --git a/core/AmRtpStream.cpp b/core/AmRtpStream.cpp index 31445ae4..96c42d26 100644 --- a/core/AmRtpStream.cpp +++ b/core/AmRtpStream.cpp @@ -403,15 +403,20 @@ void AmRtpStream::icmpError() void AmRtpStream::bufferPacket(const AmRtpPacket* p) { + memcpy(&last_recv_time, &p->recv_time, sizeof(struct timeval)); + if (!receiving && !passive) return; jitter_mut.lock(); - gettimeofday(&last_recv_time,NULL); jitter_buf[p->timestamp].copy(p); jitter_mut.unlock(); } +void AmRtpStream::clearRTPTimeout(struct timeval* recv_time) { + memcpy(&last_recv_time, recv_time, sizeof(struct timeval)); +} + int AmRtpStream::nextPacket(AmRtpPacket& p) { if (!receiving && !passive) diff --git a/core/AmRtpStream.h b/core/AmRtpStream.h index 472b63be..120770c5 100644 --- a/core/AmRtpStream.h +++ b/core/AmRtpStream.h @@ -126,7 +126,7 @@ protected: /* get next packet in buffer */ int nextPacket(AmRtpPacket& p); - + AmSession* session; /** Initializes a new random local port, and sets own attributes properly. */ @@ -236,6 +236,11 @@ public: */ void bufferPacket(const AmRtpPacket* p); + /* + * clear RTP timeout at time recv_time + */ + void clearRTPTimeout(struct timeval* recv_time); + virtual unsigned int bytes2samples(unsigned int) const = 0; }; /** \brief represents info about an \ref AmRtpStream */