Membrane.MP4.Container.Schema (Membrane MP4 plugin v0.36.9)

View Source

Types and struct for the compiled MP4 container schema.

A schema describes the valid box hierarchy of an MP4 file — which boxes exist, what fields they contain, and how they nest. Use Membrane.MP4.Container.Schema.Parser to compile a schema_def_t/0 into a t/0, or obtain the built-in default via Membrane.MP4.Container.Schema.Default.schema/0.

Summary

Types

A box field type.

For fields, the following primitive types are supported

The schema of MP4 structure.

Type describing the schema definition, that is hardcoded in this module.

t()

Types

field_t()

@type field_t() ::
  {:reserved, bitstring()}
  | {field_name :: atom(), primitive_t() | {:list, any()} | [field_t()]}

A box field type.

It may contain a primitive, a list or nested fields. Lists last till the end of a box.

primitive_t()

@type primitive_t() ::
  {:int, bit_size :: non_neg_integer()}
  | {:uint, bit_size :: non_neg_integer()}
  | :bin
  | {:bin, bit_size :: non_neg_integer()}
  | :str
  | {:str, bit_size :: non_neg_integer()}
  | {:fp, int_bit_size :: non_neg_integer(), frac_bit_size :: non_neg_integer()}

For fields, the following primitive types are supported:

  • {:int, bit_size} - a signed integer
  • {:uint, bit_size} - an unsigned integer
  • :bin - a binary lasting till the end of a box
  • {:bin, bit_size} - a binary of given size
  • :str - a string terminated with a null byte
  • {:str, bit_size} - a string of given size
  • {:fp, integer_part_bit_size, fractional_part_bit_size} - a fixed point number

schema_def_box_t()

@type schema_def_box_t() ::
  {box_name :: atom(),
   [{:black_box?, true}]
   | [
       {:version, non_neg_integer()}
       | {:fields, [schema_def_field_t()]}
       | schema_def_box_t()
     ]}

schema_def_field_t()

@type schema_def_field_t() ::
  {:reserved, bitstring()}
  | {field_name :: atom(),
     schema_def_primitive_t()
     | {:list, schema_def_primitive_t() | [schema_def_field_t()]}
     | [schema_def_field_t()]}

schema_def_primitive_t()

@type schema_def_primitive_t() :: atom()

The schema of MP4 structure.

An MP4 file consists of boxes, that all have the same header and different internal structures. Boxes can be nested with one another.

Each box has at most 4-letter name and may have the following parameters:

  • black_box? - if true, the box content is unspecified and is treated as an opaque binary. Defaults to false.
  • version - the box version. Versions usually differ by the sizes of particular fields.
  • fields - a list of key-value parameters
  • children - the nested boxes

schema_def_t()

@type schema_def_t() :: [schema_def_box_t()]

Type describing the schema definition, that is hardcoded in this module.

It may be useful for improving the schema definition. The actual schema that should be operated on, or, in other words, the parsed schema definition is specified by Membrane.MP4.Container.Schema.t/0.

The schema definition differs from the final schema in the following ways:

  • primitives along with their parameters are specified as atoms, for example :int32 instead of {:int, 32}
  • child boxes are nested within their parents directly, instead of residing under :children key.

t()

@type t() :: %Membrane.MP4.Container.Schema{
  boxes_layout: %{
    required(box_name :: atom()) =>
      %{black_box?: true}
      | %{
          black_box?: false,
          version: non_neg_integer(),
          fields: [field_t()],
          children: map()
        }
  },
  known_box_names: MapSet.t(String.t())
}

Functions

parse(schema_def)

@spec parse(schema_def_t()) :: t()