Class: WahWah::Ogg::Packets

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/wahwah/ogg/packets.rb

Overview

From Ogg’s perspective, packets can be of any arbitrary size. A specific media mapping will define how to group or break up packets from a specific media encoder. As Ogg pages have a maximum size of about 64 kBytes, sometimes a packet has to be distributed over several pages. To simplify that process, Ogg divides each packet into 255 byte long chunks plus a final shorter chunk. These chunks are called “Ogg Segments”. They are only a logical construct and do not have a header for themselves.

Instance Method Summary collapse

Constructor Details

#initialize(file_io) ⇒ Packets

Returns a new instance of Packets.



16
17
18
# File 'lib/wahwah/ogg/packets.rb', line 16

def initialize(file_io)
  @file_io = file_io
end

Instance Method Details

#eachObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/wahwah/ogg/packets.rb', line 20

def each
  @file_io.rewind

  packet = +""
  pages = Ogg::Pages.new(@file_io)

  pages.each do |page|
    page.segments.each do |segment|
      packet << segment

      # Ogg divides each packet into 255 byte long segments plus a final shorter segment.
      # So when segment length is less than 255 byte, it's the final segment.
      if segment.length < 255
        yield packet
        packet = +""
      end
    end
  end
end