From 69f33611049e364d09aaee49af8df472f9a1ce70 Mon Sep 17 00:00:00 2001 From: Mateusz Front Date: Fri, 19 Apr 2024 16:54:45 +0200 Subject: [PATCH] Fix fu-a and stap-a packetization (#48) * fix fu-a ending * fix stap-a nri * properly set f bit in stap-a * bump version * update circle config * fix CI --- .circleci/config.yml | 59 +++++++++++++----------------- README.md | 2 +- lib/rtp_h264/nal_formats/fu.ex | 5 +-- lib/rtp_h264/nal_formats/stap_a.ex | 4 +- lib/rtp_h264/nal_header.ex | 4 +- lib/rtp_h264/payloader.ex | 10 ++--- mix.exs | 2 +- mix.lock | 1 - 8 files changed, 37 insertions(+), 50 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 350aa5a..c077fb4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 \ No newline at end of file + - 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.*/ diff --git a/README.md b/README.md index b93140e..40a49c8 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/lib/rtp_h264/nal_formats/fu.ex b/lib/rtp_h264/nal_formats/fu.ex index e2a3d93..3c0a01f 100644 --- a/lib/rtp_h264/nal_formats/fu.ex +++ b/lib/rtp_h264/nal_formats/fu.ex @@ -56,7 +56,7 @@ defmodule Membrane.RTP.H264.FU do defp do_serialize(data, r, nri, type, preferred_size) do case data do - <> -> + <> when byte_size(rest) > 0 -> payload = head |> FU.Header.add_header(0, 0, type) @@ -64,9 +64,6 @@ defmodule Membrane.RTP.H264.FU do [payload] ++ do_serialize(rest, r, nri, type, preferred_size) - <<>> -> - [] - rest -> [ rest diff --git a/lib/rtp_h264/nal_formats/stap_a.ex b/lib/rtp_h264/nal_formats/stap_a.ex index 4c93ff4..a5868e1 100644 --- a/lib/rtp_h264/nal_formats/stap_a.ex +++ b/lib/rtp_h264/nal_formats/stap_a.ex @@ -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(&<>) |> 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 diff --git a/lib/rtp_h264/nal_header.ex b/lib/rtp_h264/nal_header.ex index 84b30f5..676c93e 100644 --- a/lib/rtp_h264/nal_header.ex +++ b/lib/rtp_h264/nal_header.ex @@ -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: <> <> payload + def add_header(payload, f, nri, type), + do: <> <> payload @doc """ Parses type stored in NAL Header diff --git a/lib/rtp_h264/payloader.ex b/lib/rtp_h264/payloader.ex index fdff232..56d0d8c 100644 --- a/lib/rtp_h264/payloader.ex +++ b/lib/rtp_h264/payloader.ex @@ -54,7 +54,7 @@ defmodule Membrane.RTP.H264.Payloader do dts: 0, metadata: nil, nri: 0, - reserved: 0 + f: 0 } ] end @@ -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 - <> = buffer.payload + <> = buffer.payload stap_acc = %{ stap_acc @@ -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}} @@ -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{ diff --git a/mix.exs b/mix.exs index 2ccded4..f0dd660 100644 --- a/mix.exs +++ b/mix.exs @@ -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 diff --git a/mix.lock b/mix.lock index 0d5591c..7f157eb 100644 --- a/mix.lock +++ b/mix.lock @@ -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"},