Module: sems Branch: master Commit: a40230a727ac5c7e042ada3f32a058da430d02da URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=a40230a727ac5c7e042ada3f32a058da430d02da
Author: Raphael Coeffic <[email protected]> Committer: Raphael Coeffic <[email protected]> Date: Wed Dec 14 18:42:25 2011 +0100 some clean up in AmRtpStream - moved packet receiving logic to the receiver to the stream. - removed unnecessary attributes from the public interface. --- core/AmRtpReceiver.cpp | 24 +----------------------- core/AmRtpStream.cpp | 43 +++++++++++++++++++++++++++---------------- core/AmRtpStream.h | 48 +++++++++++++++++++++--------------------------- 3 files changed, 49 insertions(+), 66 deletions(-) diff --git a/core/AmRtpReceiver.cpp b/core/AmRtpReceiver.cpp index f9bd044..e2d2493 100644 --- a/core/AmRtpReceiver.cpp +++ b/core/AmRtpReceiver.cpp @@ -122,29 +122,7 @@ void AmRtpReceiver::run() streams_mut.lock(); Streams::iterator it = streams.find(tmp_fds[i].fd); if(it != streams.end()) { - AmRtpPacket* p = it->second->newPacket(); - if (!p) { - // drop received data - AmRtpPacket dummy; - dummy.recv(tmp_fds[i].fd); - streams_mut.unlock(); - continue; - } - - if(p->recv(tmp_fds[i].fd) > 0){ - int parse_res = p->parse(); - gettimeofday(&p->recv_time,NULL); - - if (parse_res == -1) { - DBG("error while parsing RTP packet.\n"); - it->second->clearRTPTimeout(&p->recv_time); - it->second->freePacket(p); - } else { - it->second->bufferPacket(p); - } - } else { - it->second->freePacket(p); - } + it->second->recvPacket(); } streams_mut.unlock(); } diff --git a/core/AmRtpStream.cpp b/core/AmRtpStream.cpp index 777bbac..57521c5 100644 --- a/core/AmRtpStream.cpp +++ b/core/AmRtpStream.cpp @@ -574,8 +574,6 @@ int AmRtpStream::init(const AmSdp& local, ++sdp_it; } - //TODO: support mute, on_hold & sendrecv/sendonly/recvonly/inactive - setLocalIP(local.conn.address); setPassiveMode(remote_media.dir == SdpMedia::DirActive); setRAddr(remote.conn.address, remote_media.port); @@ -650,14 +648,6 @@ bool AmRtpStream::getOnHold() { return hold; } -AmRtpPacket* AmRtpStream::newPacket() { - return mem.newPacket(); -} - -void AmRtpStream::freePacket(AmRtpPacket* p) { - return mem.freePacket(p); -} - void AmRtpStream::bufferPacket(AmRtpPacket* p) { memcpy(&last_recv_time, &p->recv_time, sizeof(struct timeval)); @@ -746,18 +736,13 @@ void AmRtpStream::bufferPacket(AmRtpPacket* p) } void AmRtpStream::clearRTPTimeout(struct timeval* recv_time) { - memcpy(&last_recv_time, recv_time, sizeof(struct timeval)); + memcpy(&last_recv_time, recv_time, sizeof(struct timeval)); } void AmRtpStream::clearRTPTimeout() { gettimeofday(&last_recv_time,NULL); } -unsigned int AmRtpStream::bytes2samples(unsigned int) const { - ERROR("bytes2samples called on AmRtpStream\n"); - return 0; -} - int AmRtpStream::nextPacket(AmRtpPacket*& p) { if (!receiving && !passive) @@ -799,6 +784,32 @@ int AmRtpStream::nextPacket(AmRtpPacket*& p) return 1; } +void AmRtpStream::recvPacket() +{ + AmRtpPacket* p = mem.newPacket(); + if (!p) { + // drop received data + AmRtpPacket dummy; + dummy.recv(l_sd); + return; + } + + if(p->recv(l_sd) > 0){ + int parse_res = p->parse(); + gettimeofday(&p->recv_time,NULL); + + if (parse_res == -1) { + DBG("error while parsing RTP packet.\n"); + clearRTPTimeout(&p->recv_time); + mem.freePacket(p); + } else { + bufferPacket(p); + } + } else { + mem.freePacket(p); + } +} + #include "rtp/rtp.h" void AmRtpStream::relay(AmRtpPacket* p) { diff --git a/core/AmRtpStream.h b/core/AmRtpStream.h index 22da0a3..4c7950d 100644 --- a/core/AmRtpStream.h +++ b/core/AmRtpStream.h @@ -182,6 +182,15 @@ protected: /** symmetric RTP */ bool passive; // passive mode ? + /** mute && port == 0 */ + bool hold; + + /** marker flag */ + bool begin_talk; + + /** do check rtp timeout */ + bool monitor_rtp_timeout; + /** Payload type for telephone event */ auto_ptr<const SdpPayload> remote_telephone_event_pt; auto_ptr<const SdpPayload> local_telephone_event_pt; @@ -210,7 +219,12 @@ protected: /** Payload provider */ AmPayloadProvider* payload_provider; - /* get next packet in buffer */ + // get the next available port within configured range + static int getNextPort(); + + /** Insert an RTP packet to the buffer queue */ + void bufferPacket(AmRtpPacket* p); + /* Get next packet from the buffer queue */ int nextPacket(AmRtpPacket*& p); /** handle symmetric RTP - if in passive mode, update raddr from rp */ @@ -221,28 +235,20 @@ protected: /** Sets generic parameters on SDP media */ void getSdp(SdpMedia& m); - // get the next available port within configured range - static int getNextPort(); + /** Clear RTP timeout at time recv_time */ + void clearRTPTimeout(struct timeval* recv_time); public: - AmRtpPacket* newPacket(); - void freePacket(AmRtpPacket* p); - /** Mute */ bool mute; - /** mute && port == 0 */ - bool hold; - /** marker flag */ - bool begin_talk; - /** do check rtp timeout */ - bool monitor_rtp_timeout; /** should we receive packets? if not -> drop */ bool receiving; /** Allocates resources for future use of RTP. */ AmRtpStream(AmSession* _s, int _if); + /** Stops the stream and frees all resources. */ virtual ~AmRtpStream(); @@ -259,6 +265,8 @@ public: int receive( unsigned char* buffer, unsigned int size, unsigned int& ts, int& payload ); + void recvPacket(); + /** ping the remote side, to open NATs and enable symmetric RTP */ int ping(); @@ -343,8 +351,7 @@ public: * @warning It is necessary to call getSdpOffer/getSdpAnswer prior to init(...) * @warning so that the internal SDP media line index is set properly. */ - virtual int init(const AmSdp& local, - const AmSdp& remote); + virtual int init(const AmSdp& local, const AmSdp& remote); /** * Stops RTP stream. @@ -367,24 +374,11 @@ public: /** getter for monitor_rtp_timeout */ bool getMonitorRTPTimeout() { return monitor_rtp_timeout; } - /** - * Insert an RTP packet to the buffer. - * Note: memory is owned by this instance. - */ - void bufferPacket(AmRtpPacket* p); - - /* - * clear RTP timeout at time recv_time - */ - void clearRTPTimeout(struct timeval* recv_time); - /* * clear RTP timeout to current time */ void clearRTPTimeout(); - virtual unsigned int bytes2samples(unsigned int) const; - /** set relay stream for RTP relaying */ void setRelayStream(AmRtpStream* stream); _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
