class WahWah::Ogg::Packets

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.

Public Class Methods

new(file_io) click to toggle source
# File lib/wahwah/ogg/packets.rb, line 16
def initialize(file_io)
  @file_io = file_io
end

Public Instance Methods

each() { |packet| ... } click to toggle source
# 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