Skip to content

Commit

Permalink
Fix fu-a and stap-a packetization (#48)
Browse files Browse the repository at this point in the history
* fix fu-a ending

* fix stap-a nri

* properly set f bit in stap-a

* bump version

* update circle config

* fix CI
  • Loading branch information
mat-hek committed Apr 19, 2024
1 parent 2488def commit 69f3361
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 50 deletions.
59 changes: 25 additions & 34 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@

version: 2.0
jobs:
test:
docker:
- image: membraneframeworklabs/docker_membrane:latest
environment:
MIX_ENV: test

working_directory: ~/app

steps:
- checkout
- run: mix deps.get
- run: mix compile --force --warnings-as-errors
- run: mix test

lint:
docker:
- image: membraneframeworklabs/docker_membrane:latest
environment:
MIX_ENV: dev

working_directory: ~/app

steps:
- checkout
- run: mix deps.get
- run: mix format --check-formatted
- run: mix compile
- run: mix credo
- run: mix docs && mix docs 2>&1 | (! grep -q "warning:")
version: 2.1
orbs:
elixir: membraneframework/elixir@1

workflows:
version: 2
build:
jobs:
- test
- lint
- elixir/build_test:
filters: &filters
tags:
only: /v.*/
- elixir/test:
filters:
<<: *filters
- elixir/lint:
filters:
<<: *filters
- elixir/hex_publish:
requires:
- elixir/build_test
- elixir/test
- elixir/lint
context:
- Deployment
filters:
branches:
ignore: /.*/
tags:
only: /v.*/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The package can be installed by adding `membrane_rtp_h264_plugin` to your list o
```elixir
def deps do
[
{:membrane_rtp_h264_plugin, "~> 0.19.0"}
{:membrane_rtp_h264_plugin, "~> 0.19.1"}
]
end
```
Expand Down
5 changes: 1 addition & 4 deletions lib/rtp_h264/nal_formats/fu.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,14 @@ defmodule Membrane.RTP.H264.FU do

defp do_serialize(data, r, nri, type, preferred_size) do
case data do
<<head::binary-size(preferred_size), rest::binary>> ->
<<head::binary-size(preferred_size), rest::binary>> when byte_size(rest) > 0 ->
payload =
head
|> FU.Header.add_header(0, 0, type)
|> NAL.Header.add_header(r, nri, NAL.Header.encode_type(:fu_a))

[payload] ++ do_serialize(rest, r, nri, type, preferred_size)

<<>> ->
[]

rest ->
[
rest
Expand Down
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
10 changes: 5 additions & 5 deletions lib/rtp_h264/payloader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule Membrane.RTP.H264.Payloader do
dts: 0,
metadata: nil,
nri: 0,
reserved: 0
f: 0
}
]
end
Expand Down Expand Up @@ -115,7 +115,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
<<f::1, nri::2, _type::5, _rest::binary>> = buffer.payload

stap_acc = %{
stap_acc
Expand All @@ -124,8 +124,8 @@ 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),
f: max(stap_acc.f, f)
}

{:accept, [], %{state | stap_acc: stap_acc}}
Expand Down Expand Up @@ -154,7 +154,7 @@ defmodule Membrane.RTP.H264.Payloader do
]

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

[
%Buffer{
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Membrane.RTP.H264.MixProject do
use Mix.Project

@version "0.19.0"
@version "0.19.1"
@github_url "https://github.com/membraneframework/membrane_rtp_h264_plugin"

def project do
Expand Down
1 change: 0 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.2", "ad87296a092a46e03b7e9b0be7631ddcf64c790fa68a9ef5323b6cbb36affc72", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f3f5a1ca93ce6e092d92b6d9c049bcda58a3b617a8d888f8e7231c85630e8108"},
"membrane_caps_video_h264": {:hex, :membrane_caps_video_h264, "0.2.1", "8545074299dc48d8afe106b0be1ecf3097e997f0e9f32557f435c123135050fe", [:mix], [], "hexpm", "a14a8dcd0d2c205ca2cdbe5c7df24ec3e34a027e1caf511a71ca4c72b371b200"},
"membrane_core": {:hex, :membrane_core, "1.0.0", "1b543aefd952283be1f2a215a1db213aa4d91222722ba03cd35280622f1905ee", [:mix], [{:bunch, "~> 1.6", [hex: :bunch, repo: "hexpm", optional: false]}, {:qex, "~> 0.3", [hex: :qex, repo: "hexpm", optional: false]}, {:ratio, "~> 3.0", [hex: :ratio, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "352c90fd0a29942143c4bf7a727cc05c632e323f50a1a4e99321b1e8982f1533"},
"membrane_h264_format": {:hex, :membrane_h264_format, "0.6.1", "44836cd9de0abe989b146df1e114507787efc0cf0da2368f17a10c47b4e0738c", [:mix], [], "hexpm", "4b79be56465a876d2eac2c3af99e115374bbdc03eb1dea4f696ee9a8033cd4b0"},
"membrane_rtp_format": {:hex, :membrane_rtp_format, "0.8.0", "828924bbd27efcf85b2015ae781e824c4a9928f0a7dc132abc66817b2c6edfc4", [:mix], [{:membrane_core, "~> 1.0", [hex: :membrane_core, repo: "hexpm", optional: false]}], "hexpm", "bc75d2a649dfaef6df563212fbb9f9f62eebc871393692f9dae8d289bd4f94bb"},
Expand Down

0 comments on commit 69f3361

Please sign in to comment.