Class: RTCP

Inherits:
Object
  • Object
show all
Defined in:
lib/rtcp.rb,
lib/rtcp/version.rb,
lib/rtcp/decode_error.rb

Direct Known Subclasses

APP, BYE, PSFB, RSI, SDES, SR, XR

Defined Under Namespace

Classes: APP, BYE, DecodeError, PSFB, RR, RSI, SDES, SR, XR

Constant Summary collapse

VERSION =
"0.1.0"
@@packet_classes =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



14
15
16
# File 'lib/rtcp.rb', line 14

def length
  @length
end

#type_idObject (readonly)

Returns the value of attribute type_id.



14
15
16
# File 'lib/rtcp.rb', line 14

def type_id
  @type_id
end

Class Method Details

.decode(data) ⇒ Object

Decodes the supplied RTCP packet and returns it

Raises:



25
26
27
28
29
30
31
32
33
# 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) ⇒ Object

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



36
37
38
39
40
41
42
43
44
# 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

Instance Method Details

#decode(packet_data) ⇒ Object



46
47
48
49
50
51
52
# 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_sObject

Returns the packet as RTCP data string



55
56
57
# File 'lib/rtcp.rb', line 55

def to_s
  @packet_data
end