Class: Ogg::Reader

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

Overview

Reads pages and packets from an ogg stream

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Reader

Returns a new instance of Reader.



6
7
8
# File 'lib/ogg/reader.rb', line 6

def initialize(input)
  @input = input
end

Instance Attribute Details

#input ⇒ Object (readonly)

Returns the value of attribute input.



4
5
6
# File 'lib/ogg/reader.rb', line 4

def input
  @input
end

Instance Method Details

#each_pages(options = {}) ⇒ Object



10
11
12
13
14
# File 'lib/ogg/reader.rb', line 10

def each_pages(options = {})
  until @input.eof?
    yield Page.read(@input, options)
  end
end

#read_packets(max_packets) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ogg/reader.rb', line 16

def read_packets(max_packets)
  result = []
  partial_packet = ""
  each_pages do |page|
    partial_packet = page.segments.inject(partial_packet) do |packet,segment|
      packet << segment
      if segment.length < 255
        #end of packet
        result << packet
        return result if result.length == max_packets
        ""
      else
        packet
      end
    end
  end
  # We expect packets to reach page boundaries, consider raising exception if partial_packet here.
  result
end