Skip to content

Commit

Permalink
fix stap-a nri
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-hek committed Apr 17, 2024
1 parent 954b988 commit cd36c98
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/rtp_h264/nal_formats/stap_a.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ defmodule Membrane.RTP.H264.StapA do
def aggregation_unit_size(nalu), do: byte_size(nalu) + 2

@spec serialize([binary], 0..1, 0..3) :: binary
def serialize(payloads, reserved, nri) do
def serialize(payloads, f, nri) do
payloads
|> Enum.reverse()
|> Enum.map(&<<byte_size(&1)::16, &1::binary>>)
|> IO.iodata_to_binary()
|> NAL.Header.add_header(reserved, nri, NAL.Header.encode_type(:stap_a))
|> NAL.Header.add_header(f, nri, NAL.Header.encode_type(:stap_a))
end
end
4 changes: 2 additions & 2 deletions lib/rtp_h264/nal_header.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ defmodule Membrane.RTP.H264.NAL.Header do
Adds NAL header to payload
"""
@spec add_header(binary(), 0 | 1, nri(), type()) :: binary()
def add_header(payload, reserved, nri, type),
do: <<reserved::1, nri::2, type::5>> <> payload
def add_header(payload, f, nri, type),
do: <<f::1, nri::2, type::5>> <> payload

@doc """
Parses type stored in NAL Header
Expand Down
11 changes: 5 additions & 6 deletions lib/rtp_h264/payloader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ defmodule Membrane.RTP.H264.Payloader do
pts: 0,
dts: 0,
metadata: nil,
nri: 0,
reserved: 0
nri: 0
}
]
end
Expand Down Expand Up @@ -115,7 +114,7 @@ defmodule Membrane.RTP.H264.Payloader do
metadata_match? = !stap_acc.metadata || stap_acc.pts == buffer.pts

if metadata_match? and size <= state.max_payload_size do
<<r::1, nri::2, _type::5, _rest::binary>> = buffer.payload
<<_r::1, nri::2, _type::5, _rest::binary>> = buffer.payload

stap_acc = %{
stap_acc
Expand All @@ -124,8 +123,7 @@ defmodule Membrane.RTP.H264.Payloader do
metadata: stap_acc.metadata || buffer.metadata,
pts: buffer.pts,
dts: buffer.dts,
reserved: stap_acc.reserved * r,
nri: min(stap_acc.nri, nri)
nri: max(stap_acc.nri, nri)
}

{:accept, [], %{state | stap_acc: stap_acc}}
Expand All @@ -143,6 +141,7 @@ defmodule Membrane.RTP.H264.Payloader do

[payload] ->
# use single nalu

[
%Buffer{
payload: payload,
Expand All @@ -154,7 +153,7 @@ defmodule Membrane.RTP.H264.Payloader do
]

payloads ->
payload = StapA.serialize(payloads, stap_acc.reserved, stap_acc.nri)
payload = StapA.serialize(payloads, 0, stap_acc.nri)

[
%Buffer{
Expand Down

0 comments on commit cd36c98

Please sign in to comment.