Class: SippyCup::Media::RTPHeader
- Inherits:
-
Struct
- Object
- Struct
- SippyCup::Media::RTPHeader
- Includes:
- StructFu
- Defined in:
- lib/sippy_cup/media/rtp_header.rb
Constant Summary collapse
- VERSION =
2
Instance Attribute Summary collapse
-
#csrc_ids ⇒ Object
Returns the value of attribute csrc_ids.
-
#extension ⇒ Object
Returns the value of attribute extension.
-
#marker ⇒ Object
Returns the value of attribute marker.
-
#padding ⇒ Object
Returns the value of attribute padding.
-
#payload_id ⇒ Object
Returns the value of attribute payload_id.
-
#sequence_num ⇒ Object
Returns the value of attribute sequence_num.
-
#ssrc_id ⇒ Object
Returns the value of attribute ssrc_id.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #csrc_count ⇒ Object
- #csrc_ids_readable ⇒ Object
-
#initialize(args = {}) ⇒ RTPHeader
constructor
A new instance of RTPHeader.
- #read(str) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ RTPHeader
Returns a new instance of RTPHeader.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sippy_cup/media/rtp_header.rb', line 11 def initialize(args = {}) # TODO: Support Extension Header super( (args[:version] ? args[:version] : VERSION), (args[:padding] ? args[:padding] : 0), (args[:extension] ? args[:extension] : 0), (args[:marker] ? args[:marker] : 0), (args[:payload_id] ? args[:payload_id] : 0), Int16.new(args[:sequence_num] ? args[:sequence_num] : 0), Int32.new(args[:timestamp] ? args[:timestamp] : 0), Int32.new(args[:ssrc_id] ? args[:ssrc_id] : 0), (args[:csrc_ids] ? Array(args[:csrc_ids]) : []), ) end |
Instance Attribute Details
#csrc_ids ⇒ Object
Returns the value of attribute csrc_ids
6 7 8 |
# File 'lib/sippy_cup/media/rtp_header.rb', line 6 def csrc_ids @csrc_ids end |
#extension ⇒ Object
Returns the value of attribute extension
6 7 8 |
# File 'lib/sippy_cup/media/rtp_header.rb', line 6 def extension @extension end |
#marker ⇒ Object
Returns the value of attribute marker
6 7 8 |
# File 'lib/sippy_cup/media/rtp_header.rb', line 6 def marker @marker end |
#padding ⇒ Object
Returns the value of attribute padding
6 7 8 |
# File 'lib/sippy_cup/media/rtp_header.rb', line 6 def padding @padding end |
#payload_id ⇒ Object
Returns the value of attribute payload_id
6 7 8 |
# File 'lib/sippy_cup/media/rtp_header.rb', line 6 def payload_id @payload_id end |
#sequence_num ⇒ Object
Returns the value of attribute sequence_num
6 7 8 |
# File 'lib/sippy_cup/media/rtp_header.rb', line 6 def sequence_num @sequence_num end |
#ssrc_id ⇒ Object
Returns the value of attribute ssrc_id
6 7 8 |
# File 'lib/sippy_cup/media/rtp_header.rb', line 6 def ssrc_id @ssrc_id end |
#timestamp ⇒ Object
Returns the value of attribute timestamp
6 7 8 |
# File 'lib/sippy_cup/media/rtp_header.rb', line 6 def @timestamp end |
#version ⇒ Object
Returns the value of attribute version
6 7 8 |
# File 'lib/sippy_cup/media/rtp_header.rb', line 6 def version @version end |
Instance Method Details
#csrc_count ⇒ Object
43 44 45 |
# File 'lib/sippy_cup/media/rtp_header.rb', line 43 def csrc_count csrc_ids.count end |
#csrc_ids_readable ⇒ Object
47 48 49 |
# File 'lib/sippy_cup/media/rtp_header.rb', line 47 def csrc_ids_readable csrc_ids.to_s end |
#read(str) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sippy_cup/media/rtp_header.rb', line 26 def read(str) self[:version] = str[0].ord >> 6 self[:padding] = (str[0].ord >> 5) & 1 self[:extension] = (str[0].ord >> 4) & 1 num_csrcs = str[0].ord & 0xf self[:marker] = str[1] >> 7 self[:payload_id] = str[1] & 0x7f self[:sequence_num].read str[2,2] self[:timestamp].read str[4,4] self[:ssrc_id].read str[8,4] i = 8 num_csrcs.times do self[:csrc_ids] << Int32.new(str[i += 4, 4]) end self[:body] = str[i, str.length - i] end |
#to_s ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sippy_cup/media/rtp_header.rb', line 51 def to_s bytes = [ (version << 6) + (padding << 5) + (extension << 4) + (csrc_count), (marker << 7) + (payload_id), sequence_num, , ssrc_id ].pack 'CCnNN' csrc_ids.each do |csrc_id| bytes << [csrc_id].pack('N') end bytes end |