class RTCP

Constants

VERSION

Attributes

length[R]
type_id[R]

Public Class Methods

decode(data) click to toggle source

Decodes the supplied RTCP packet and returns it

# File lib/rtcp.rb, line 25
def self.decode(data)
  raise(RTCP::DecodeError, "Truncated Packet") if (data.length < 4)

  packet_type, length = data.unpack('xCn')
  length = 4 * (length + 1)
  raise(RTCP::DecodeError, "Truncated Packet") if (data.length < length)

  self.packet_class(packet_type).new.decode(data.slice(0..(length - 1)))
end
decode_all(data) click to toggle source

Decodes all RTCP packets in the supplied string returns them in an array

# File lib/rtcp.rb, line 36
def self.decode_all(data)
  packets = []
  while data && data.length > 0
    packet = self.decode(data)
    packets.push(packet)
    data = data.slice(packet.length..-1)
  end
  packets
end

Private Class Methods

packet_class(packet_type) click to toggle source

Returns the Class to use for handling RTCP packets of the given packet type.

# File lib/rtcp.rb, line 95
def self.packet_class(packet_type)
  @@packet_classes[packet_type] || self
end

Public Instance Methods

decode(packet_data) click to toggle source
# File lib/rtcp.rb, line 46
def decode(packet_data)
  @type_id, length = packet_data.unpack('xCn')
  @length      = 4 * (length + 1)

  @packet_data = packet_data
  self
end
to_s() click to toggle source

Returns the packet as RTCP data string

# File lib/rtcp.rb, line 55
def to_s
  @packet_data
end

Protected Instance Methods

ensure_packet_type(packet_type) click to toggle source

Ensures that the current RTCP Packet object is able to decode the RTCP packet with the given Packet Type ID.

Raises an RTCP::DecodeError exception when this is not the case.

# File lib/rtcp.rb, line 65
def ensure_packet_type(packet_type)
  if packet_type != self.class::PT_ID
    raise(RTCP::DecodeError, "Wrong Packet Type. packet_type=#{packet_type}")
  end
end
payload_data(packet_data, packet_length, header_length) click to toggle source

Extracts and returns the payload data from the given packet_data using the supplied packet length and header_length values.

It also sets the @packet_data instance variable, which is currently used by the to_s method for returning the packet data.

Raises an RTCP::DecodeError exception when the packet_data is shorter than packet_length.

# File lib/rtcp.rb, line 79
def payload_data(packet_data, packet_length, header_length)
  if packet_data.length > packet_length
    @packet_data = packet_data[0..packet_length]
  elsif packet_data.length == packet_length
    @packet_data = packet_data
  else
    raise RTCP::DecodeError, "Truncated Packet"
  end

  @packet_data[header_length..-1]
end