Public Member Functions | Private Member Functions | Private Attributes

RTCP_Channel_In Class Reference

The RTCP_Channel_In class represents a single incoming data channel, or stream. The class has several responsibilities. When the class is instantiated, the incoming RTP traffic must be declared a valid source based on the RTP packets received. Once declared valie, this class is responsible for keeping up with reception statistics and other information. When an SR or RR is created (outside of this class), this class is used to get the Receiver Report block for this particular stream. More...

#include <RTCP_Channel.h>

Collaboration diagram for RTCP_Channel_In:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 RTCP_Channel_In (ACE_UINT32 ssrc, const ACE_Addr *addr)
 ~RTCP_Channel_In (void)
 Destructor.
void recv_rtp_packet (ACE_Message_Block *mb, const ACE_Addr *peer_addr)
RR_BlockgetRRBlock (void)
 Takes statistics of incoming RTP traffic and creates a receiver report block.
ACE_UINT32 dlsr (void)
 Returns the delay since last sender report.
ACE_UINT32 lsr (void)
 Returns the last sender report timestamp.
int updateStatistics (RTCP_SR_Packet *sr)
 Updates channel information with incoming sender report.
int updateStatistics (RTCP_RR_Packet *rr)
 Updates channel information with incoming receiver report.
int sender (void)
 Returns 1 if data has been sent since the last report, 0 if not.
int active (void)
 Returns 1 if this is an active source, 0 if not.

Private Member Functions

 RTCP_Channel_In (void)
 Don't want default constructor.
 RTCP_Channel_In (const RTCP_Channel_In &ch)
 Don't want copy constructor.
void updateStatistics (RTP_Packet *pkt)
 This operation is used update statistics for the incoming RTP packet.
void init_seq (ACE_UINT16 seq)
 This is called when the first RTP packet is received.
int update_seq (ACE_UINT16 seq)

Private Attributes

ACE_UINT32 remote_ssrc_
 The synchronization source id of the source this channel represents.
ACE_CString cname_
 The canonical name of the source this channel represents.
ACE_UINT16 max_seq_
 The highest sequence number seen.
ACE_UINT32 cycles_
 The shifted count of sequence number cycles (ie when sequence number wraps).
ACE_UINT32 base_seq_
 The first sequence number received.
ACE_UINT32 bad_seq_
 last 'bad' sequence number + 1
ACE_UINT32 probation_
 The number of in sequence packets until a source is declared valid.
ACE_UINT32 received_
 The number of packets received.
ACE_UINT32 expected_prior_
 The packet expected at last interval.
ACE_UINT32 received_prior_
 The packet received at last interval.
ACE_UINT32 transit_
 The last transit time.
double jitter_
 The inter-arrival jitter measured in timestamp units.
char first_data_packet_
 Flag to indicate the first data packet received.
ACE_UINT32 init_time_stamp_
 The first timestamp received.
ACE_Time_Value init_local_time_
 The local time that the initial packet was received.
ACE_Addrpeer_address_
 The address that the first RTP packet was received from.
ACE_UINT32 ntp_ts_msw_
 The most significant word of the last sender report NTP timestamp.
ACE_UINT32 ntp_ts_lsw_
 The least significant word of the last sender report NTP timestamp.
ACE_UINT32 rtp_ts_
 The last sender report RTP timestamp.
ACE_UINT32 last_sr_time_
int active_
 Flag to indicate whether or not the source is active.
int no_data_counter_
char data_since_last_report_
int payload_type_
 The RTP payload type.

Detailed Description

The RTCP_Channel_In class represents a single incoming data channel, or stream. The class has several responsibilities. When the class is instantiated, the incoming RTP traffic must be declared a valid source based on the RTP packets received. Once declared valie, this class is responsible for keeping up with reception statistics and other information. When an SR or RR is created (outside of this class), this class is used to get the Receiver Report block for this particular stream.

Definition at line 27 of file RTCP_Channel.h.


Constructor & Destructor Documentation

RTCP_Channel_In::RTCP_Channel_In ( ACE_UINT32  ssrc,
const ACE_Addr addr 
)

Constructor for an incoming channel. Requires the synchronization source id and address of the sender.

Definition at line 9 of file RTCP_Channel.cpp.

 : remote_ssrc_ (ssrc),
   cname_ (""),
   transit_ (0),
   jitter_ (0.0),
   first_data_packet_ (1),
   ntp_ts_msw_ (0),
   ntp_ts_lsw_ (0),
   last_sr_time_ (0),
   active_ (0),
   no_data_counter_ (0),
   data_since_last_report_ (0)
{
  const ACE_INET_Addr *const_inet_addr = dynamic_cast<const ACE_INET_Addr*> (peer_addr);

  ACE_INET_Addr *inet_addr;
  ACE_NEW (inet_addr,
           ACE_INET_Addr (*const_inet_addr));

  this->peer_address_ = inet_addr;
}

RTCP_Channel_In::~RTCP_Channel_In ( void   ) 

Destructor.

Definition at line 32 of file RTCP_Channel.cpp.

{
  delete this->peer_address_;
}

RTCP_Channel_In::RTCP_Channel_In ( void   )  [private]

Don't want default constructor.

RTCP_Channel_In::RTCP_Channel_In ( const RTCP_Channel_In ch  )  [private]

Don't want copy constructor.


Member Function Documentation

int RTCP_Channel_In::active ( void   )  [inline]

Returns 1 if this is an active source, 0 if not.

Definition at line 63 of file RTCP_Channel.h.

{ return this->active_; }

ACE_UINT32 RTCP_Channel_In::dlsr ( void   ) 

Returns the delay since last sender report.

RR_Block * RTCP_Channel_In::getRRBlock ( void   ) 

Takes statistics of incoming RTP traffic and creates a receiver report block.

Definition at line 240 of file RTCP_Channel.cpp.

{
  // If no data has been received since the last report, don't create a block.
  if (!this->data_since_last_report_)
    {
      this->no_data_counter_++;

      // make the source inactive if significant time has passed since last report
      if (this->no_data_counter_ == 32)
        this->active_ = 0;

      return 0;
    }

  this->no_data_counter_ = 0;

  RR_Block *local_block_ptr = 0;

  ACE_NEW_RETURN (local_block_ptr,
                  RR_Block,
                  0);

  ACE_OS::memset(local_block_ptr, 0, sizeof(RR_Block));

  // Set the ssrc of the source this report is for.
  local_block_ptr->ssrc_ = this->remote_ssrc_;

  // Calculate packets expected/lost (from RFC 1889 Appendix A.3)
  ACE_UINT32 extended_max;
  ACE_UINT32 expected;
  ACE_UINT32 expected_interval;
  ACE_UINT32 received_interval;
  int lost_interval;

  extended_max = this->cycles_ + this->max_seq_;
  expected = extended_max - this->base_seq_ + 1;

  local_block_ptr->lost_ = expected - this->received_;
  expected_interval = expected - this->expected_prior_;
  this->expected_prior_ = expected;
  received_interval = this->received_ - this->received_prior_;
  this->received_prior_ = this->received_;
  lost_interval = expected_interval - received_interval;

  if ((expected_interval == 0) || (lost_interval <= 0))
    local_block_ptr->fraction_ = 0;
  else
    local_block_ptr->fraction_ = (lost_interval << 8) / expected_interval;


  local_block_ptr->last_seq_ = extended_max;

  // taken from RFC 1889 App A.8
  local_block_ptr->jitter_ = (ACE_UINT32)this->jitter_;

  // calculate the last SR timestamp (lsr)
  local_block_ptr->lsr_ = ((this->ntp_ts_msw_ & 0xFFFF) << 16) |
                          ((this->ntp_ts_lsw_ & 0xFFFF0000) >> 16);

  // calculate the delay since last SR (dlsr)
  ACE_Time_Value now = ACE_OS::gettimeofday ();
  ACE_UINT32 now32 = (ACE_UINT32)
                     (now.sec () * 65536 +
                      now.usec () * 0.065536);

  local_block_ptr->dlsr_ = now32 - this->last_sr_time_;

  // indicate that no data has been received since the last report
  this->data_since_last_report_ = 0;

  return local_block_ptr;
}

void RTCP_Channel_In::init_seq ( ACE_UINT16  seq  )  [private]

This is called when the first RTP packet is received.

Definition at line 135 of file RTCP_Channel.cpp.

{
  this->base_seq_ = seq - 1;
  this->max_seq_ = seq;
  this->bad_seq_ = RTP_SEQ_MOD + 1;
  this->cycles_ = 0;
  this->received_ = 0;
  this->received_prior_ = 0;
  this->expected_prior_ = 0;
}

ACE_UINT32 RTCP_Channel_In::lsr ( void   ) 

Returns the last sender report timestamp.

void RTCP_Channel_In::recv_rtp_packet ( ACE_Message_Block mb,
const ACE_Addr peer_addr 
)

This operation takes the incoming ACE_Message_Block, converts it to an RTP_Packet and calls updateStatistics. It also uses compares the peer_addr to the stored peer_address_ to check for loops.

Definition at line 221 of file RTCP_Channel.cpp.

{
  if (*peer_address != *this->peer_address_)
    ACE_DEBUG ((LM_DEBUG,
                "RTCP_Channel_In::recv_rtp_packet - possible loop/collision detected"));

  RTP_Packet data_packet(mb->rd_ptr (), static_cast<int> (mb->length ()));

  // make sure the packet is valid
  if (data_packet.is_valid ())
    this->updateStatistics(&data_packet);
  else
    ACE_DEBUG ((LM_DEBUG,
                "RTCP_Channel_In::recvDataPacket - invalid RTP packet\n"));
}

int RTCP_Channel_In::sender ( void   )  [inline]

Returns 1 if data has been sent since the last report, 0 if not.

Definition at line 60 of file RTCP_Channel.h.

{ return this->data_since_last_report_; }

int RTCP_Channel_In::update_seq ( ACE_UINT16  seq  )  [private]

This is called when each RTP packet is received. It is used to declare a source as valid.

Definition at line 147 of file RTCP_Channel.cpp.

{
  // The following is taken from RFC 1889 Appendix A.1
  ACE_UINT16 udelta = seq - this->max_seq_;
  const int MAX_DROPOUT = 3000;
  const int MAX_MISORDER = 100;
  const int MIN_SEQUENTIAL = 2;

  // Source is not valid until MIN_SEQUENTIAL packets with
  // sequential sequence numbers have been received.
  if (this->probation_)
    {
      // packet is in sequence
      if (seq == this->max_seq_ + (ACE_UINT16)1)
        {
          this->probation_ --;
          this->max_seq_ = seq;
          if (this->probation_ == 0)
            {
              this->init_seq(seq);
              this->received_++;
              return 1;
            }
        }
      else
        {
          this->probation_ = MIN_SEQUENTIAL - 1;
          this->max_seq_ = seq;
        }
      return 0;
    }
  else if (udelta < MAX_DROPOUT)
    {
      // in order, with permissible gap
      if (seq < this->max_seq_)
        {
          // seq number wrapped - count another 64k cycle
          this->cycles_+=RTP_SEQ_MOD;
        }
      this->max_seq_ = seq;
    }
  else if (udelta <= RTP_SEQ_MOD - MAX_MISORDER)
    {
      // the sequence number made a large jump
      ACE_UINT32 temp = seq; // Borland reports a warning on the next line
                             // without this line.
      if (temp == this->bad_seq_)
        {
          // two sequential packets, assume the other side restarted without
          // telling us so just re-sync
          // (i.e., pretend this was the first packet).
          this->init_seq (seq);

          if (TAO_debug_level > 0)
          ACE_DEBUG ((LM_DEBUG,
                      "RTCP_Channel_In: large jump in sequence number",
                      "; init seq\n"));
        }
      else
        {
          this->bad_seq_ = (seq+1)&(RTP_SEQ_MOD-1);
          return 0;
        }
    }
  else
    {
      // dup or reordered packet
    }
  this->received_++;

  return 1;
}

void RTCP_Channel_In::updateStatistics ( RTP_Packet pkt  )  [private]

This operation is used update statistics for the incoming RTP packet.

Definition at line 38 of file RTCP_Channel.cpp.

{
  ACE_Time_Value current_time;
  ACE_UINT32 arrival;
  int transit, d;

  this->active_ = 0;

  // determine if the source has been declared valid
  if (update_seq(dataPkt->sn ()) == 0)
    return;

  // Set initial values if this is the first data packet.
  if (this->first_data_packet_)
    {
      // store the initial timestamp
      this->init_time_stamp_ = dataPkt->ts ();
      this->init_local_time_ = ACE_OS::gettimeofday ();
      this->first_data_packet_ = 0;
    }

  // Get the current time.
  current_time = ACE_OS::gettimeofday ();

  unsigned int samples_per_sec;
  double samples_per_usec;


  switch (dataPkt->pt())
  {
    case RTP_PT_PCMU:
    case RTP_PT_CELP:
    case RTP_PT_G721:
    case RTP_PT_GSM:
    case RTP_PT_DVI:
    case RTP_PT_LPC:
    case RTP_PT_PCMA:
    case RTP_PT_G722:
      samples_per_sec = 8000;
      break;
    case RTP_PT_L16_STEREO:
    case RTP_PT_L16_MONO:
      samples_per_sec = 44100;
      break;
    default:
      samples_per_sec = 1000000;
  };

  samples_per_usec = samples_per_sec/1000000.0;

  // Calculate the current timestamp.
  arrival = (ACE_UINT32)((current_time.sec () -
                this->init_local_time_.sec ()) * samples_per_sec +
            ((double)(current_time.usec () -
                (double)this->init_local_time_.usec ()) * samples_per_usec)  +
            this->init_time_stamp_);


  // jitter calc from RFC 1889 app a.8
  transit = arrival - dataPkt->ts ();
  d = transit - this->transit_;
  this->transit_ = transit;
  if (d < 0)
    d = -d;

  // Calculate the inter-arrival jitter.
  this->jitter_ += (1./16.)*((double)d - this->jitter_);

  // Indicate that data has been received since the last report.
  this->data_since_last_report_ = 1;

  // Store the payload type.
  this->payload_type_ = dataPkt->pt ();
}

int RTCP_Channel_In::updateStatistics ( RTCP_RR_Packet rr  ) 

Updates channel information with incoming receiver report.

Definition at line 129 of file RTCP_Channel.cpp.

{
  return 0;
}

int RTCP_Channel_In::updateStatistics ( RTCP_SR_Packet sr  ) 

Updates channel information with incoming sender report.

Definition at line 114 of file RTCP_Channel.cpp.

{
  // calculate the last SR time in 1/65536 sec.
  ACE_Time_Value now = ACE_OS::gettimeofday ();
  this->last_sr_time_ = (ACE_UINT32)
                        (now.sec () * 65536 +
                         now.usec () * 0.065536);

  this->ntp_ts_msw_ = sr->ntp_ts_msw ();
  this->ntp_ts_lsw_ = sr->ntp_ts_lsw ();

  return 0;
}


Member Data Documentation

int RTCP_Channel_In::active_ [private]

Flag to indicate whether or not the source is active.

Definition at line 136 of file RTCP_Channel.h.

ACE_UINT32 RTCP_Channel_In::bad_seq_ [private]

last 'bad' sequence number + 1

Definition at line 89 of file RTCP_Channel.h.

ACE_UINT32 RTCP_Channel_In::base_seq_ [private]

The first sequence number received.

Definition at line 86 of file RTCP_Channel.h.

The canonical name of the source this channel represents.

Definition at line 76 of file RTCP_Channel.h.

ACE_UINT32 RTCP_Channel_In::cycles_ [private]

The shifted count of sequence number cycles (ie when sequence number wraps).

Definition at line 83 of file RTCP_Channel.h.

This flag indicates that data has been received since the last report was sent.

Definition at line 144 of file RTCP_Channel.h.

ACE_UINT32 RTCP_Channel_In::expected_prior_ [private]

The packet expected at last interval.

Definition at line 98 of file RTCP_Channel.h.

Flag to indicate the first data packet received.

Definition at line 111 of file RTCP_Channel.h.

The local time that the initial packet was received.

Definition at line 117 of file RTCP_Channel.h.

ACE_UINT32 RTCP_Channel_In::init_time_stamp_ [private]

The first timestamp received.

Definition at line 114 of file RTCP_Channel.h.

double RTCP_Channel_In::jitter_ [private]

The inter-arrival jitter measured in timestamp units.

Definition at line 107 of file RTCP_Channel.h.

ACE_UINT32 RTCP_Channel_In::last_sr_time_ [private]

The last time a sender report was received in 1/65536 seconds. Used to calculate DLSR.

Definition at line 133 of file RTCP_Channel.h.

ACE_UINT16 RTCP_Channel_In::max_seq_ [private]

The highest sequence number seen.

Definition at line 80 of file RTCP_Channel.h.

This is a counter to indicate the number of reporting intervals that have passed since data has been received. After 32, declare the source inactive.

Definition at line 140 of file RTCP_Channel.h.

ACE_UINT32 RTCP_Channel_In::ntp_ts_lsw_ [private]

The least significant word of the last sender report NTP timestamp.

Definition at line 126 of file RTCP_Channel.h.

ACE_UINT32 RTCP_Channel_In::ntp_ts_msw_ [private]

The most significant word of the last sender report NTP timestamp.

Definition at line 123 of file RTCP_Channel.h.

The RTP payload type.

Definition at line 147 of file RTCP_Channel.h.

The address that the first RTP packet was received from.

Definition at line 120 of file RTCP_Channel.h.

ACE_UINT32 RTCP_Channel_In::probation_ [private]

The number of in sequence packets until a source is declared valid.

Definition at line 92 of file RTCP_Channel.h.

ACE_UINT32 RTCP_Channel_In::received_ [private]

The number of packets received.

Definition at line 95 of file RTCP_Channel.h.

ACE_UINT32 RTCP_Channel_In::received_prior_ [private]

The packet received at last interval.

Definition at line 101 of file RTCP_Channel.h.

ACE_UINT32 RTCP_Channel_In::remote_ssrc_ [private]

The synchronization source id of the source this channel represents.

Definition at line 73 of file RTCP_Channel.h.

ACE_UINT32 RTCP_Channel_In::rtp_ts_ [private]

The last sender report RTP timestamp.

Definition at line 129 of file RTCP_Channel.h.

ACE_UINT32 RTCP_Channel_In::transit_ [private]

The last transit time.

Definition at line 104 of file RTCP_Channel.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines