Class: Ariblib::TransportStreamFile

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

Overview

TSファイル

Constant Summary collapse

Default_payload =
{
  #0x0000 => ProgramAssociationTable.new,
  #0x0001 => ConditionalAccessTable.new,
  0x0012 => EventInformationTable.new,
  0x0011 => ServiceDescriptionTable.new,
  0x0010 => NetworkInformationTable.new,
  0x0014 => TimeOffsetTable.new,
  0x0029 => CommonDataTable.new,
}
ReadSize =
188*20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, payload_list = Default_payload) ⇒ TransportStreamFile

Returns a new instance of TransportStreamFile.



62
63
64
65
66
67
68
69
70
# File 'lib/ariblib/TransportStreamFile.rb', line 62

def initialize(filename,payload_list=Default_payload)
  @file=open(filename,'rb')
  @bs=BitStream.new(@file.read(ReadSize))
  @payload=payload_list
  @payload.default=TransportStreamPacket.new
  @payload.merge!(payload_list)
  @payload_ap=Hash.new(0)
  @packet_count=0
end

Instance Attribute Details

#adaptation_field_controlObject (readonly)

Returns the value of attribute adaptation_field_control.



42
43
44
# File 'lib/ariblib/TransportStreamFile.rb', line 42

def adaptation_field_control
  @adaptation_field_control
end

#bsObject (readonly)

Returns the value of attribute bs.



47
48
49
# File 'lib/ariblib/TransportStreamFile.rb', line 47

def bs
  @bs
end

#continuity_counterObject (readonly)

Returns the value of attribute continuity_counter.



48
49
50
# File 'lib/ariblib/TransportStreamFile.rb', line 48

def continuity_counter
  @continuity_counter
end

#packet_start_posObject (readonly)

Returns the value of attribute packet_start_pos.



43
44
45
# File 'lib/ariblib/TransportStreamFile.rb', line 43

def packet_start_pos
  @packet_start_pos
end

#payloadObject (readonly)

Returns the value of attribute payload.



46
47
48
# File 'lib/ariblib/TransportStreamFile.rb', line 46

def payload
  @payload
end

#payload_apObject (readonly)

Returns the value of attribute payload_ap.



40
41
42
# File 'lib/ariblib/TransportStreamFile.rb', line 40

def payload_ap
  @payload_ap
end

#payload_lengthObject (readonly)

Returns the value of attribute payload_length.



50
51
52
# File 'lib/ariblib/TransportStreamFile.rb', line 50

def payload_length
  @payload_length
end

#payload_unit_start_indicatorObject (readonly)

Returns the value of attribute payload_unit_start_indicator.



49
50
51
# File 'lib/ariblib/TransportStreamFile.rb', line 49

def payload_unit_start_indicator
  @payload_unit_start_indicator
end

#pidObject (readonly)

Returns the value of attribute pid.



41
42
43
# File 'lib/ariblib/TransportStreamFile.rb', line 41

def pid
  @pid
end

Instance Method Details

#closeObject



76
77
78
# File 'lib/ariblib/TransportStreamFile.rb', line 76

def close
  @file.close
end

#eof?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/ariblib/TransportStreamFile.rb', line 72

def eof?
  @file.eof? && (@bs.lest <= 0)
end

#syncObject



80
81
82
83
84
85
86
# File 'lib/ariblib/TransportStreamFile.rb', line 80

def sync
  while(@bs.lest>0 and (c=@bs.read(8))!=0x47) do
  end
  return false if @bs.lest<=0
  @bs.pos-=8
  true
end

#transport_packetObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/ariblib/TransportStreamFile.rb', line 88

def transport_packet
  if @bs.lest <= 0
    tmp=@file.read(ReadSize)
    return nil unless tmp
    @bs=BitStream.new(tmp)
  end
  packet_start_pos              = @bs.pos
  sync_byte                     = @bs.getc
  return :async unless sync_byte==0x47
  tmp                           = @bs.getc
  tmp=(tmp<<8)|                   @bs.getc
  #transport_error_indicator     = @bs.read  1 #bslbf
  #@payload_unit_start_indicator = @bs.read  1 #bslbf
  #transport_priority            = @bs.read  1 #bslbf
  #@pid                          = @bs.read  13 #uimsbf
  transport_error_indicator     = tmp & 0x8000 #1 bslbf
  @payload_unit_start_indicator = tmp & 0x4000 #1 bslbf
  transport_priority            = tmp & 0x2000 #1 bslbf
  @pid                          = tmp & 0x1fff #13 uimsbf
  tmp                           = @bs.getc
  #transport_scrambling_control  = @bs.read  2 #bslbf
  #@adaptation_field_control     = @bs.read  2 #bslbf
  #@continuity_counter           = @bs.read  4 #uimsbf
  transport_scrambling_control  = tmp & 0xc0 #2 bslbf
  adaptation_field_control1     = tmp & 0x20 #2 bslbf
  adaptation_field_control2     = tmp & 0x10 #2 bslbf
  @continuity_counter           = tmp & 0x0f #4 uimsbf
  if(adaptation_field_control1 !=0 )
    #adaptation_field()
    @adaptation_field_length    = @bs.getc
    @adaptation_field_length   += 1 #uimsbf
    @adaptation_pos=@bs.pos
    @bs.pos+=@adaptation_field_length
  end
  count = packet_start_pos+188*8
  @payload_length=((count)-@bs.pos)/8
  if(adaptation_field_control2 !=0 )
    @payload[@pid].set(self)
    @payload_ap[@pid]+=1
  end
  @bs.pos=count
  true
end