Class: MP4::Layout::Container
- Inherits:
-
Object
- Object
- MP4::Layout::Container
- Defined in:
- lib/mp4/layout/container.rb
Instance Attribute Summary collapse
-
#descendants ⇒ Object
include ::Layout::Base.
-
#name ⇒ Object
include ::Layout::Base.
-
#root ⇒ Object
include ::Layout::Base.
Instance Method Summary collapse
- #add_atom(atom) ⇒ Object
- #add_container(name, &block) ⇒ Object
- #add_mdat(mp4, source) ⇒ Object
- #binary_descendants ⇒ Object
- #generate ⇒ Object
-
#initialize(root: false, name: nil) ⇒ Container
constructor
A new instance of Container.
- #pack ⇒ Object
- #size ⇒ Object
Constructor Details
Instance Attribute Details
#descendants ⇒ Object
include ::Layout::Base
5 6 7 |
# File 'lib/mp4/layout/container.rb', line 5 def descendants @descendants end |
#name ⇒ Object
include ::Layout::Base
5 6 7 |
# File 'lib/mp4/layout/container.rb', line 5 def name @name end |
#root ⇒ Object
include ::Layout::Base
5 6 7 |
# File 'lib/mp4/layout/container.rb', line 5 def root @root end |
Instance Method Details
#add_atom(atom) ⇒ Object
41 42 43 44 |
# File 'lib/mp4/layout/container.rb', line 41 def add_atom(atom) @descendants << atom atom end |
#add_container(name, &block) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/mp4/layout/container.rb', line 31 def add_container(name, &block) container = self.class.new(name: name) block.call(container) @descendants << container.generate container end |
#add_mdat(mp4, source) ⇒ Object
46 47 48 |
# File 'lib/mp4/layout/container.rb', line 46 def add_mdat(mp4, source) @descendants << ::Layout::Mdat.new(mp4: mp4, source: source) end |
#binary_descendants ⇒ Object
23 24 25 |
# File 'lib/mp4/layout/container.rb', line 23 def binary_descendants descendants.join end |
#generate ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/mp4/layout/container.rb', line 13 def generate return binary_descendants if root [ BinData::Uint32be.new(size).to_binary_s, BinData::String.new(name).to_binary_s, binary_descendants, ].join end |
#pack ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/mp4/layout/container.rb', line 50 def pack return descendants.map(&:pack).join if root [ *header, descendants.map(&:pack), ].join end |
#size ⇒ Object
27 28 29 |
# File 'lib/mp4/layout/container.rb', line 27 def size ::MP4::Constants::GENERIC_HEADER_SIZE + binary_descendants.size end |