Class: TSparser::TS

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

Instance Method Summary collapse

Constructor Details

#initialize(io, filtering_procs = []) ⇒ TS

Returns a new instance of TS.



5
6
7
8
# File 'lib/ts.rb', line 5

def initialize(io, filtering_procs=[])
  @io = io
  @filtering_procs = filtering_procs
end

Instance Method Details

#closeObject



37
38
39
# File 'lib/ts.rb', line 37

def close
  @io.close
end

#eof?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/ts.rb', line 33

def eof?
  return @io.eof?
end

#filter(*pids, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/ts.rb', line 10

def filter(*pids, &block)
  new_filtering_procs = @filtering_procs
  if pids.length > 0
    new_filtering_procs = [Proc.new{|packet| pids.include?(packet.pid)}] + new_filtering_procs
  end
  if block
    new_filtering_procs = new_filtering_procs + [block]
  end
  return TS.new(@io, new_filtering_procs)
end

#readObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ts.rb', line 21

def read
  loop do
    return nil if eof?
    packet_binary = Binary.new(@io.read(188))
    if packet_binary.length != 188
      raise "Bytes less than 188byte (#{packet_bytes.length}byte) were read from TS file."
    end
    packet = TransportPacket.new(packet_binary)
    return packet if @filtering_procs.all?{|filter| filter.call(packet)}
  end
end