RTCP_Channel.h

Go to the documentation of this file.
00001 // $Id: RTCP_Channel.h 71526 2006-03-14 06:14:35Z jtc $
00002 
00003 #ifndef RTCP_CHANNEL_INCLUDE
00004 #define RTCP_CHANNEL_INCLUDE
00005 
00006 #include /**/ "ace/pre.h"
00007 
00008 #include "orbsvcs/AV/RTP.h"
00009 #include "orbsvcs/AV/RTCP_Packet.h"
00010 
00011 #include "ace/Message_Block.h"
00012 #include "ace/SString.h"
00013 
00014 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00015 
00016 /**
00017  * @class RTCP_Channel_In
00018  * @brief The RTCP_Channel_In class represents a single incoming data channel,
00019  * or stream.  The class has several responsibilities.  When the class is
00020  * instantiated, the incoming RTP traffic must be declared a valid source based
00021  * on the RTP packets received.  Once declared valie, this class is responsible
00022  * for keeping up with reception statistics and other information.  When an SR
00023  * or RR is created (outside of this class), this class is used to get the
00024  * Receiver Report block for this particular stream.
00025  */
00026 
00027 class RTCP_Channel_In
00028 {
00029 public:
00030   /// Constructor for an incoming channel.  Requires the synchronization source
00031   /// id and address of the sender.
00032   RTCP_Channel_In(ACE_UINT32 ssrc,
00033                   const ACE_Addr *addr);
00034 
00035   /// Destructor
00036   ~RTCP_Channel_In(void);
00037 
00038   /// This operation takes the incoming ACE_Message_Block, converts it to an
00039   /// RTP_Packet and calls updateStatistics.  It also uses compares the peer_addr
00040   /// to the stored peer_address_ to check for loops.
00041   void recv_rtp_packet (ACE_Message_Block *mb,
00042                         const ACE_Addr *peer_addr);
00043 
00044   /// Takes statistics of incoming RTP traffic and creates a receiver report block.
00045   RR_Block *getRRBlock(void);
00046 
00047   /// Returns the delay since last sender report.
00048   ACE_UINT32 dlsr (void);
00049 
00050   /// Returns the last sender report timestamp.
00051   ACE_UINT32 lsr (void);
00052 
00053   /// Updates channel information with incoming sender report.
00054   int updateStatistics(RTCP_SR_Packet *sr);
00055 
00056   /// Updates channel information with incoming receiver report.
00057   int updateStatistics(RTCP_RR_Packet *rr);
00058 
00059   /// Returns 1 if data has been sent since the last report, 0 if not.
00060   int sender (void) { return this->data_since_last_report_; }
00061 
00062   /// Returns 1 if this is an active source, 0 if not.
00063   int active (void) { return this->active_; }
00064 
00065 private:
00066   /// Don't want default constructor.
00067   RTCP_Channel_In(void);
00068 
00069   /// Don't want copy constructor.
00070   RTCP_Channel_In(const RTCP_Channel_In &ch);
00071 
00072   /// The synchronization source id of the source this channel represents.
00073   ACE_UINT32 remote_ssrc_;
00074 
00075   /// The canonical name of the source this channel represents.
00076   ACE_CString cname_;
00077 
00078   // Used to declare a source valid
00079   /// The highest sequence number seen.
00080   ACE_UINT16 max_seq_;
00081 
00082   /// The shifted count of sequence number cycles (ie when sequence number wraps)
00083   ACE_UINT32 cycles_;
00084 
00085   /// The first sequence number received.
00086   ACE_UINT32 base_seq_;
00087 
00088   /// last 'bad' sequence number + 1
00089   ACE_UINT32 bad_seq_;
00090 
00091   /// The number of in sequence packets until a source is declared valid.
00092   ACE_UINT32 probation_;
00093 
00094   /// The number of packets received.
00095   ACE_UINT32 received_;
00096 
00097   /// The packet expected at last interval.
00098   ACE_UINT32 expected_prior_;
00099 
00100   /// The packet received at last interval.
00101   ACE_UINT32 received_prior_;
00102 
00103   /// The last transit time.
00104   ACE_UINT32 transit_;
00105 
00106   /// The inter-arrival jitter measured in timestamp units.
00107   double jitter_;
00108 
00109   // Used for jitter calculations
00110   /// Flag to indicate the first data packet received.
00111   char first_data_packet_;
00112 
00113   /// The first timestamp received.
00114   ACE_UINT32 init_time_stamp_;
00115 
00116   /// The local time that the initial packet was received.
00117   ACE_Time_Value init_local_time_;
00118 
00119   /// The address that the first RTP packet was received from.
00120   ACE_Addr *peer_address_;
00121 
00122   /// The most significant word of the last sender report NTP timestamp.
00123   ACE_UINT32 ntp_ts_msw_;
00124 
00125   /// The least significant word of the last sender report NTP timestamp.
00126   ACE_UINT32 ntp_ts_lsw_;
00127 
00128   /// The last sender report RTP timestamp.
00129   ACE_UINT32 rtp_ts_;
00130 
00131   /// The last time a sender report was received in 1/65536 seconds.
00132   /// Used to calculate DLSR.
00133   ACE_UINT32 last_sr_time_;
00134 
00135   /// Flag to indicate whether or not the source is active.
00136   int active_;
00137 
00138   /// This is a counter to indicate the number of reporting intervals that have
00139   /// passed since data has been received.  After 32, declare the source inactive.
00140   int no_data_counter_;
00141 
00142   /// This flag indicates that data has been received since the last report was
00143   /// sent.
00144   char data_since_last_report_;
00145 
00146   /// The RTP payload type.
00147   int payload_type_;
00148 
00149   /// This operation is used update statistics for the incoming RTP packet.
00150   void updateStatistics(RTP_Packet *pkt);
00151 
00152   /// This is called when the first RTP packet is received.
00153   void init_seq(ACE_UINT16 seq);
00154 
00155   /// This is called when each RTP packet is received.  It is used to declare
00156   /// a source as valid.
00157   int update_seq(ACE_UINT16 seq);
00158 };
00159 
00160 /**
00161  * @class RTCP_Channel_Out
00162  * @brief The RTCP_Channel_Out class represents a single outgoing data channel,
00163  * or stream.  It keeps track of statistics such as number of packets sent and
00164  * number of bytes sent.
00165  */
00166 
00167 class RTCP_Channel_Out
00168 {
00169 public:
00170   /// Constructor.
00171   RTCP_Channel_Out(void);
00172 
00173   /// Destructor.
00174   ~RTCP_Channel_Out(void);
00175 
00176   /// Update the channel statistics each time an RTP packet is sent.
00177   void updateStatistics (RTP_Packet *pkt);
00178 
00179   /// Returns the timestamp of the last RTP packet sent.
00180   ACE_UINT32 timestamp (void);
00181 
00182   /// Returns the number of packets sent.
00183   ACE_UINT32 packets_sent (void);
00184 
00185   /// Returns the number of octets sent.
00186   ACE_UINT32 octets_sent (void);
00187 
00188   /// Sets the canonical name of the source.
00189   void cname (const char *cname) { this->cname_ = cname; }
00190 
00191   /// Returns the canonical name of the source.
00192   const char *cname (void) { return this->cname_.c_str(); }
00193 
00194   /// Returns whether or not this source is active.
00195   char active (void);
00196 
00197 private:
00198   /// Holds the canonical name for this channel.
00199   ACE_CString cname_;
00200 
00201   /// Flag to indicate whether or not this channel is active.
00202   char active_;
00203 
00204   /// The sequence number of the last RTP packet sent.
00205   unsigned int seq_num_;
00206 
00207   /// The timestamp of the last RTP packet sent.
00208   unsigned int timestamp_;
00209 
00210   /// The initial offset of the timestamp.
00211   unsigned int timestamp_offset_;
00212 
00213   /// The total number of packets sent.
00214   unsigned int packets_sent_;
00215 
00216   /// The total numbef of octets sent.
00217   unsigned int octets_sent_;
00218 };
00219 
00220 TAO_END_VERSIONED_NAMESPACE_DECL
00221 
00222 #include /**/ "ace/post.h"
00223 #endif /* RTCP_CHANNEL_INCLUDE */

Generated on Tue Feb 2 17:47:49 2010 for TAO_AV by  doxygen 1.4.7