Class: Discorb::Voice::OggStream::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/discorb/voice/ogg.rb

Overview

Represents a page of the Ogg stream.

Defined Under Namespace

Classes: Packet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Page

Note:

This method will seek the io.

Creates a new page.

Parameters:

  • io (IO)

    The audio ogg stream.



84
85
86
87
88
89
90
# File 'lib/discorb/voice/ogg.rb', line 84

def initialize(io)
  @version, @header_type, @granule_position, @bitstream_serial_number, @page_sequence_number, @crc_checksum, @page_segments =
    io.read(23).unpack("CCQ<L<L<L<C")
  @segtable = io.read(@page_segments)
  len = @segtable.unpack("C*").sum
  @body = io.read(len)
end

Instance Attribute Details

#bitstream_serial_numberInteger (readonly)

Returns The bitstream serial number of the page.

Returns:

  • (Integer)

    The bitstream serial number of the page.



68
69
70
# File 'lib/discorb/voice/ogg.rb', line 68

def bitstream_serial_number
  @bitstream_serial_number
end

#bodyString (readonly)

Returns The body of the page.

Returns:

  • (String)

    The body of the page.



76
77
78
# File 'lib/discorb/voice/ogg.rb', line 76

def body
  @body
end

#crc_checksumInteger (readonly)

Returns The CRC checksum of the page.

Returns:

  • (Integer)

    The CRC checksum of the page.



72
73
74
# File 'lib/discorb/voice/ogg.rb', line 72

def crc_checksum
  @crc_checksum
end

#granule_positionInteger (readonly)

Returns The granule position of the page.

Returns:

  • (Integer)

    The granule position of the page.



66
67
68
# File 'lib/discorb/voice/ogg.rb', line 66

def granule_position
  @granule_position
end

#header_typeInteger (readonly)

Returns The header type of the page.

Returns:

  • (Integer)

    The header type of the page.



64
65
66
# File 'lib/discorb/voice/ogg.rb', line 64

def header_type
  @header_type
end

#page_segmentsInteger (readonly)

Returns The length of the page segment table.

Returns:

  • (Integer)

    The length of the page segment table.



74
75
76
# File 'lib/discorb/voice/ogg.rb', line 74

def page_segments
  @page_segments
end

#page_sequence_numberInteger (readonly)

Returns The page sequence number of the page.

Returns:

  • (Integer)

    The page sequence number of the page.



70
71
72
# File 'lib/discorb/voice/ogg.rb', line 70

def page_sequence_number
  @page_sequence_number
end

#versionInteger (readonly)

Returns The version of the page.

Returns:

  • (Integer)

    The version of the page.



62
63
64
# File 'lib/discorb/voice/ogg.rb', line 62

def version
  @version
end

Instance Method Details

#packetsEnumerator<Discorb::Voice::OggStream::Page::Packet>

Enumerates the packets of the page.

Returns:



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/discorb/voice/ogg.rb', line 97

def packets
  Enumerator.new do |enum|
    offset = 0
    length = 0
    partial = true
    @segtable.bytes.each do |seg|
      if seg == 255
        length += 255
        partial = true
      else
        length += seg
        partial = false
        enum << Packet.new(@body[offset, length], partial, self)
        offset += length
        length = 0
      end
    end

    enum << Packet.new(@body[offset, length], partial, self) if partial
  end
end