Skip to content

Commit

Permalink
CMAF demuxer (#118)
Browse files Browse the repository at this point in the history
* Add CMAF demuxer 

---------

Co-authored-by: Mateusz Front <mateusz.front@swmansion.com>
  • Loading branch information
varsill and mat-hek authored Jan 20, 2025
1 parent 9d49f1d commit 66e163f
Show file tree
Hide file tree
Showing 9 changed files with 835 additions and 43 deletions.
14 changes: 10 additions & 4 deletions lib/membrane_mp4/container/parse_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,21 @@ defmodule Membrane.MP4.Container.ParseHelper do

defp parse_field(data, {name, {:int, size}}, context) do
case data do
<<int::signed-integer-size(size), rest::bitstring>> -> {:ok, {int, rest}, context}
_unknown_format -> parse_field_error(data, name)
<<int::signed-integer-size(size), rest::bitstring>> ->
{:ok, {int, rest}, context}

_unknown_format ->
parse_field_error(data, name)
end
end

defp parse_field(data, {name, {:uint, size}}, context) do
case data do
<<uint::integer-size(size), rest::bitstring>> -> {:ok, {uint, rest}, context}
_unknown_format -> parse_field_error(data, name)
<<uint::integer-size(size), rest::bitstring>> ->
{:ok, {uint, rest}, context}

_unknown_format ->
parse_field_error(data, name)
end
end

Expand Down
77 changes: 46 additions & 31 deletions lib/membrane_mp4/container/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -377,35 +377,28 @@ defmodule Membrane.MP4.Container.Schema do
]
],
sidx: [
version: 1,
version: 0,
fields:
@full_box ++
[
reference_id: :uint32,
timescale: :uint32,
earliest_presentation_time: :uint64,
first_offset: :uint64,
earliest_presentation_time: {:uint32, when: {:version, value: 0}},
earliest_presentation_time: {:uint64, when: {:version, value: 1}},
first_offset: {:uint32, when: {:version, value: 0}},
first_offset: {:uint64, when: {:version, value: 1}},
reserved: <<0::16-integer>>,
reference_count: :uint16,
# TODO: make a list once list length is supported
# reference_list: [
# [
# reference_type: :bin1,
# referenced_size: :uint31,
# subsegment_duration: :uint32,
# starts_with_sap: :bin1,
# sap_type: :uint3,
# sap_delta_time: :uint28
# ],
# length: :reference_count
# ]
reference_type: :bin1,
# from the beginning of moof to the end
referenced_size: :uint31,
subsegment_duration: :uint32,
starts_with_sap: :bin1,
sap_type: :uint3,
sap_delta_time: :uint28
reference_list:
{:list,
[
reference_type: :bin1,
referenced_size: :uint31,
subsegment_duration: :uint32,
starts_with_sap: :bin1,
sap_type: :uint3,
sap_delta_time: :uint28
]}
]
],
moof: [
Expand All @@ -424,17 +417,19 @@ defmodule Membrane.MP4.Container.Schema do
@full_box ++
[
track_id: :uint32,
default_sample_duration: :uint32,
default_sample_size: :uint32,
default_sample_flags: :uint32
base_data_offset: {:uint64, when: {:fo_flags, mask: 0x00001}},
default_sample_duration: {:uint32, when: {:fo_flags, mask: 0x000008}},
default_sample_size: {:uint32, when: {:fo_flags, mask: 0x000010}},
default_sample_flags: {:uint32, when: {:fo_flags, mask: 0x000020}}
]
],
tfdt: [
version: 1,
fields:
@full_box ++
[
base_media_decode_time: :uint64
base_media_decode_time: {:uint32, when: {:version, value: 0}},
base_media_decode_time: {:uint64, when: {:version, value: 1}}
]
],
trun: [
Expand All @@ -443,15 +438,35 @@ defmodule Membrane.MP4.Container.Schema do
@full_box ++
[
sample_count: :uint32,
data_offset: :int32,
data_offset: {:int32, when: {:fo_flags, mask: 0x000001}},
first_sample_flags: {:bin32, when: {:fo_flags, mask: 0x000004}},
samples:
{:list,
[
sample_duration: {:uint32, when: {:fo_flags, mask: 0x000100}},
sample_size: {:uint32, when: {:fo_flags, mask: 0x000200}},
sample_flags: {:bin32, when: {:fo_flags, mask: 0x000400}},
sample_composition_offset:
{:uint32, when: {:fo_flags, mask: 0x000800}}
]}
]
],
trun: [
version: 1,
fields:
@full_box ++
[
sample_count: :uint32,
data_offset: {:int32, when: {:fo_flags, mask: 0x000001}},
first_sample_flags: {:bin32, when: {:fo_flags, mask: 0x000004}},
samples:
{:list,
[
sample_duration: :uint32,
sample_size: :uint32,
sample_flags: :bin32,
sample_duration: {:uint32, when: {:fo_flags, mask: 0x000100}},
sample_size: {:uint32, when: {:fo_flags, mask: 0x000200}},
sample_flags: {:bin32, when: {:fo_flags, mask: 0x000400}},
sample_composition_offset:
{:uint32, when: {:fo_flags, mask: 0x800}}
{:int32, when: {:fo_flags, mask: 0x000800}}
]}
]
]
Expand Down
Loading

0 comments on commit 66e163f

Please sign in to comment.