Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix h264 payloader stream format generation #76

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions lib/membrane_mp4/payloader/h264.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ defmodule Membrane.MP4.Payloader.H264 do
ctx.pads.input.stream_format,
pps,
sps,
state.parameters_in_band?
state
)}
], %{state | pps: pps, sps: sps}}
else
Expand Down Expand Up @@ -101,7 +101,7 @@ defmodule Membrane.MP4.Payloader.H264 do
|> pop_in([:h264, :nalus])
end

defp generate_stream_format(input_stream_format, pps, sps, inband_parameters?) do
defp generate_stream_format(input_stream_format, pps, sps, state) do
timescale =
case input_stream_format.framerate do
{0, _denominator} -> 30 * 1024
Expand All @@ -113,11 +113,17 @@ defmodule Membrane.MP4.Payloader.H264 do
timescale: timescale,
width: input_stream_format.width,
height: input_stream_format.height,
content: %AVC1{avcc: generate_avcc(pps, sps), inband_parameters?: inband_parameters?}
content: %AVC1{
avcc: generate_avcc(pps, sps, state),
inband_parameters?: state.parameters_in_band?
}
}
end

defp generate_avcc(pps, sps) do
defp generate_avcc(pps, sps, state) do
pps = fetch_parameters_set(pps, state.pps)
sps = fetch_parameters_set(sps, state.sps)

<<_idc_and_type, profile, compatibility, level, _rest::binary>> = hd(sps)

<<1, profile, compatibility, level, 0b111111::6, @nalu_length_size - 1::2-integer, 0b111::3,
Expand All @@ -128,4 +134,7 @@ defmodule Membrane.MP4.Payloader.H264 do
defp encode_parameter_sets(pss) do
Enum.map_join(pss, &<<byte_size(&1)::16-integer, &1::binary>>)
end

defp fetch_parameters_set([] = _new_ps, ps), do: ps
defp fetch_parameters_set(ps, _old_ps), do: ps
Comment on lines +138 to +139
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
defp fetch_parameters_set([] = _new_ps, ps), do: ps
defp fetch_parameters_set(ps, _old_ps), do: ps
defp fetch_parameters_sets([] = _new_ps, ps), do: ps
defp fetch_parameters_sets(ps, _old_ps), do: ps

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is actually a single parameter set 😛 (either sps or pps).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it doesn't have to be, we retrieve a list here, also there can be multiple sps and multiple pps in AVCC, also there's encode_parameter_sets

end