class TSparser::PSISectionReader

Public Class Methods

new(pid, ts) click to toggle source
# File lib/psi_section_reader.rb, line 4
def initialize(pid, ts)
  @ts = ts.filter(pid)
end

Public Instance Methods

read() click to toggle source
# File lib/psi_section_reader.rb, line 8
def read
  cont_packets = []
  while packet = @ts.read
    if packet.payload_unit_start_indicator == 1
      if @start_packet && continuity_check(@start_packet, *cont_packets, packet)
        binary = @start_packet.payload.from(@start_packet.payload.b(0) + 1)
        binary = binary.join(*cont_packets.map{|packet| packet.payload})
        @start_packet = packet
        return binary
      else
        @start_packet = packet
        cont_packets = []
        next
      end
    end
    cont_packets << packet
  end
  return nil
end

Private Instance Methods

continuity_check(first_packet, *packets) click to toggle source
# File lib/psi_section_reader.rb, line 30
def continuity_check(first_packet, *packets)
  counter = first_packet.continuity_counter
  return packets.all? do |packet|
    counter += 1
    packet.continuity_counter == counter % 16
  end
end