Skip to content

Commit

Permalink
Format files
Browse files Browse the repository at this point in the history
  • Loading branch information
varsill committed Jan 7, 2025
1 parent 9cb7ad8 commit 52f7610
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions lib/membrane_mp4/demuxer/cmaf.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ defmodule Membrane.MP4.Demuxer.CMAF do
last_timescales: %{},
how_many_segment_bytes_read: 0,
tracks_info: nil,
tracks_notification_sent?: false
tracks_notification_sent?: false,
incomplete_mdat_header: nil
}

{[], state}
Expand All @@ -76,13 +77,28 @@ defmodule Membrane.MP4.Demuxer.CMAF do

@impl true
def handle_buffer(:input, buffer, ctx, state) do
{new_boxes, rest} = Container.parse!(state.unprocessed_binary <> buffer.payload)
{new_boxes, rest} =
if state.incomplete_mdat_header? do
else
Container.parse!(state.unprocessed_binary <> buffer.payload)
end

state = %{
state
| unprocessed_boxes: state.unprocessed_boxes ++ new_boxes,
unprocessed_binary: rest
}
maybe_header = parse_header(rest)

if maybe_header and maybe_header.name == :mdat do
%{
state
| unprocessed_boxes: state.unprocessed_boxes ++ new_boxes ++ [],
unprocessed_binary: <<>>,
incomplete_mdat_header: maybe_header
}
else
%{
state
| unprocessed_boxes: state.unprocessed_boxes ++ new_boxes,
unprocessed_binary: rest
}
end

handle_boxes(ctx, state)
end
Expand Down Expand Up @@ -174,7 +190,10 @@ defmodule Membrane.MP4.Demuxer.CMAF do
:mdat ->
state = Map.update!(state, :how_many_segment_bytes_read, &(&1 + box.header_size))
{actions, state} = read_mdat(box, state)
new_fsm_state = if state.samples_info == [], do: :reading_fragment_header, else: :reading_fragment_data

new_fsm_state =
if state.samples_info == [], do: :reading_fragment_header, else: :reading_fragment_data

{actions, %{state | fsm_state: new_fsm_state}}

_other ->
Expand Down Expand Up @@ -220,12 +239,12 @@ defmodule Membrane.MP4.Demuxer.CMAF do
end
end

# defp parse_header(data) do
# case Container.Header.parse(data) do
# {:ok, header, _rest} -> header
# {:error, :not_enough_data} -> nil
# end
# end
defp parse_header(data) do
case Container.Header.parse(data) do
{:ok, header, _rest} -> header
{:error, :not_enough_data} -> nil
end
end

defp match_tracks_with_pads(ctx, tracks_info) do
output_pads_data =
Expand Down

0 comments on commit 52f7610

Please sign in to comment.