Class: MP4::Parser::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/mp4/parser/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:) ⇒ Service

Returns a new instance of Service.



5
6
7
# File 'lib/mp4/parser/service.rb', line 5

def initialize(source:)
  @source = source
end

Instance Attribute Details

#ftypObject (readonly)

Returns the value of attribute ftyp.



3
4
5
# File 'lib/mp4/parser/service.rb', line 3

def ftyp
  @ftyp
end

#mdatObject (readonly)

Returns the value of attribute mdat.



3
4
5
# File 'lib/mp4/parser/service.rb', line 3

def mdat
  @mdat
end

#moovObject (readonly)

Returns the value of attribute moov.



3
4
5
# File 'lib/mp4/parser/service.rb', line 3

def moov
  @moov
end

#sourceObject (readonly)

Returns the value of attribute source.



3
4
5
# File 'lib/mp4/parser/service.rb', line 3

def source
  @source
end

Instance Method Details

#callObject



9
10
11
# File 'lib/mp4/parser/service.rb', line 9

def call
  parse
end

#parseObject



13
14
15
16
17
18
19
20
# File 'lib/mp4/parser/service.rb', line 13

def parse
  main_boxes = MainBoxes.parse(source)
  parse_ftyp(*main_boxes.fetch(:ftyp))
  parse_moov(*main_boxes.fetch(:moov))
  parse_mdat(*main_boxes.fetch(:mdat))

  self
end

#parse_ftyp(offset, box_size) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/mp4/parser/service.rb', line 22

def parse_ftyp(offset, box_size)
  source.set_seek(offset + MP4::Constants::GENERIC_HEADER_SIZE)

  @ftyp = MP4::Binary::Ftyp.read(
    StringIO.new(source.read(box_size - MP4::Constants::GENERIC_HEADER_SIZE)),
  ).snapshot
end

#parse_mdat(offset, _box_size) ⇒ Object



38
39
40
# File 'lib/mp4/parser/service.rb', line 38

def parse_mdat(offset, _box_size)
  @mdat = { offset: offset }
end

#parse_moov(offset, box_size) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/mp4/parser/service.rb', line 30

def parse_moov(offset, box_size)
  source.set_seek(offset)

  @moov = Moov.parse(
    StringIO.new(source.read(box_size)),
  )
end