From 9412c2d5d0d14de03c2e3974337b3e04ceb1db13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kita?= Date: Tue, 1 Oct 2024 18:38:05 +0200 Subject: [PATCH 1/3] Revoke is_keyframe/2 --- README.md | 2 +- lib/rtp_h264/utils.ex | 29 +++++++++++++++++++++++++++++ mix.exs | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 135180c..5362a8a 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.3"} + {:membrane_rtp_h264_plugin, "~> 0.19.4"} ] end ``` diff --git a/lib/rtp_h264/utils.ex b/lib/rtp_h264/utils.ex index b48aabc..a92effd 100644 --- a/lib/rtp_h264/utils.ex +++ b/lib/rtp_h264/utils.ex @@ -3,6 +3,35 @@ defmodule Membrane.RTP.H264.Utils do Utility functions for RTP packets containing H264 encoded frames. """ + @deprecated "Use #{inspect(__MODULE__)}.keyframe?/2 instead" + @doc """ + Checks whether RTP payload contains H264 keyframe. + + By default, with option `look_for` set to `:sps`, will in some cases check + whether the payload contains SPS (NALU payload type 7); + if `look_for` is set to `:idr`, will look exclusively for IDR frames + (NALU payload type 5). + """ + # This is rewritten from galene + # https://github.com/jech/galene/blob/6fbdf0eab2c9640e673d9f9ec0331da24cbf2c4c/codecs/codecs.go#L119 + # and based on https://datatracker.ietf.org/doc/html/rfc6184#section-5 + # + # it is also unclear why we sometimes check against nalu type == 7 + # and sometimes against nalu type == 5 but galene does it this way + # and it works + @spec is_keyframe(binary(), :sps | :idr) :: boolean() + # credo:disable-for-next-line Credo.Check.Readability.PredicateFunctionNames + def is_keyframe(rtp_payload, look_for \\ :sps) + + # credo:disable-for-next-line Credo.Check.Readability.PredicateFunctionNames + def is_keyframe(rtp_payload, _look_for) when byte_size(rtp_payload) < 1, do: false + + # credo:disable-for-next-line Credo.Check.Readability.PredicateFunctionNames + def is_keyframe(rtp_payload, look_for) do + <<_f::1, _nri::2, nalu_type::5, rest::binary>> = rtp_payload + do_is_keyframe(nalu_type, rest, look_for) + end + @doc """ Checks whether RTP payload contains H264 keyframe. diff --git a/mix.exs b/mix.exs index a302c5a..cbdd3cd 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Membrane.RTP.H264.MixProject do use Mix.Project - @version "0.19.3" + @version "0.19.4" @github_url "https://github.com/membraneframework/membrane_rtp_h264_plugin" def project do From 6e59f0122480cd955382e9915e43d804336dc6a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kita?= Date: Tue, 1 Oct 2024 18:39:28 +0200 Subject: [PATCH 2/3] Remove redundant comment --- lib/rtp_h264/utils.ex | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/rtp_h264/utils.ex b/lib/rtp_h264/utils.ex index a92effd..09fc4c7 100644 --- a/lib/rtp_h264/utils.ex +++ b/lib/rtp_h264/utils.ex @@ -12,13 +12,6 @@ defmodule Membrane.RTP.H264.Utils do if `look_for` is set to `:idr`, will look exclusively for IDR frames (NALU payload type 5). """ - # This is rewritten from galene - # https://github.com/jech/galene/blob/6fbdf0eab2c9640e673d9f9ec0331da24cbf2c4c/codecs/codecs.go#L119 - # and based on https://datatracker.ietf.org/doc/html/rfc6184#section-5 - # - # it is also unclear why we sometimes check against nalu type == 7 - # and sometimes against nalu type == 5 but galene does it this way - # and it works @spec is_keyframe(binary(), :sps | :idr) :: boolean() # credo:disable-for-next-line Credo.Check.Readability.PredicateFunctionNames def is_keyframe(rtp_payload, look_for \\ :sps) From 988ecbd728b670844960b7084357dc76271fc39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kita?= Date: Tue, 1 Oct 2024 18:42:03 +0200 Subject: [PATCH 3/3] Add information about deprecation in docs --- lib/rtp_h264/utils.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/rtp_h264/utils.ex b/lib/rtp_h264/utils.ex index 09fc4c7..6239c0e 100644 --- a/lib/rtp_h264/utils.ex +++ b/lib/rtp_h264/utils.ex @@ -3,8 +3,9 @@ defmodule Membrane.RTP.H264.Utils do Utility functions for RTP packets containing H264 encoded frames. """ - @deprecated "Use #{inspect(__MODULE__)}.keyframe?/2 instead" @doc """ + Deprecated since `v0.19.4`. Use `keyframe?/2` instead. + Checks whether RTP payload contains H264 keyframe. By default, with option `look_for` set to `:sps`, will in some cases check @@ -12,6 +13,7 @@ defmodule Membrane.RTP.H264.Utils do if `look_for` is set to `:idr`, will look exclusively for IDR frames (NALU payload type 5). """ + @deprecated "Use #{inspect(__MODULE__)}.keyframe?/2 instead" @spec is_keyframe(binary(), :sps | :idr) :: boolean() # credo:disable-for-next-line Credo.Check.Readability.PredicateFunctionNames def is_keyframe(rtp_payload, look_for \\ :sps)