Class: Discorb::Voice::OggStream

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

Overview

Represents a Ogg stream.

Defined Under Namespace

Classes: Page

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ OggStream

Creates a new Ogg stream.

Parameters:

  • io (IO)

    The audio ogg stream.



13
14
15
# File 'lib/discorb/voice/ogg.rb', line 13

def initialize(io)
  @io = io
end

Instance Method Details

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

Enumerates the packets of the Ogg stream.

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/discorb/voice/ogg.rb', line 22

def packets
  Enumerator.new do |enum|
    part = +""
    raw_packets.each do |packet|
      part << packet.data
      unless packet.partial
        enum << part
        part = +""
      end
    end
  end
end

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

Enumerates the raw packets of the Ogg stream. This may include partial packets.

Returns:



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/discorb/voice/ogg.rb', line 41

def raw_packets
  Enumerator.new do |enum|
    loop do
      # p c += 1
      break if @io.read(4) != "OggS"
      pg = Page.new(@io)
      pg.packets.each do |packet|
        enum << packet
      end
      # enum << pg.packets.next
    end
  end
end