Class: FileData::Box

Inherits:
Object
  • Object
show all
Defined in:
lib/file_data/formats/mpeg4/box.rb

Overview

Mpeg4 box

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, content_stream) ⇒ Box

Returns a new instance of Box.



8
9
10
11
12
# File 'lib/file_data/formats/mpeg4/box.rb', line 8

def initialize(type, content_stream)
  @type = type
  @content_stream = content_stream
  @end_pos = @content_stream.end_pos
end

Instance Attribute Details

#content_streamObject (readonly)

Returns the value of attribute content_stream.



6
7
8
# File 'lib/file_data/formats/mpeg4/box.rb', line 6

def content_stream
  @content_stream
end

#end_posObject (readonly)

Returns the value of attribute end_pos.



6
7
8
# File 'lib/file_data/formats/mpeg4/box.rb', line 6

def end_pos
  @end_pos
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/file_data/formats/mpeg4/box.rb', line 6

def type
  @type
end

Class Method Details

.parse(view) ⇒ Object



14
15
16
17
# File 'lib/file_data/formats/mpeg4/box.rb', line 14

def self.parse(view)
  type, pos, size = parse_header(view)
  new(type, Helpers::SubStreamView.new(view.stream, pos, size))
end

.parse_header(view) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/file_data/formats/mpeg4/box.rb', line 19

def self.parse_header(view)
  start_pos = view.pos
  first_field = view.read_value(4)
  type = view.read_ascii(4)

  total_size =
    if first_field == 1
      view.read_value(8)
    else
      first_field
    end

  content_pos = view.pos
  header_size = content_pos - start_pos
  content_size = total_size - header_size

  [type, content_pos, content_size]
end