From 63bd0dce9b3aaf084ffac6f310fb862173c22598 Mon Sep 17 00:00:00 2001 From: Mateusz Front Date: Mon, 13 May 2024 11:52:15 +0200 Subject: [PATCH 1/4] skip persumed AUs that don't have any VCL NALus --- lib/membrane_h264_plugin/h26x_parser.ex | 57 +++++++++++++------------ 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/lib/membrane_h264_plugin/h26x_parser.ex b/lib/membrane_h264_plugin/h26x_parser.ex index 40a492f..073921a 100644 --- a/lib/membrane_h264_plugin/h26x_parser.ex +++ b/lib/membrane_h264_plugin/h26x_parser.ex @@ -354,18 +354,15 @@ defmodule Membrane.H26x.Parser do @spec prepare_actions_for_au(AUSplitter.access_unit(), boolean(), state()) :: callback_return() def prepare_actions_for_au(au, keyframe?, state) do - {{pts, dts}, state} = prepare_timestamps(au, state) - {should_skip_au, state} = skip_au?(au, keyframe?, state) + {should_forward_au, state} = forward_au?(au, keyframe?, state) - buffers_actions = - if should_skip_au do - [] - else - buffers = wrap_into_buffer(au, pts, dts, keyframe?, state) - [buffer: {:output, buffers}] - end - - {buffers_actions, state} + if should_forward_au do + {{pts, dts}, state} = prepare_timestamps(au, state) + buffers = wrap_into_buffer(au, pts, dts, keyframe?, state) + {[buffer: {:output, buffers}], state} + else + {[], state} + end end @spec flatten_parameter_sets(parameter_sets()) :: list() @@ -407,28 +404,32 @@ defmodule Membrane.H26x.Parser do {timestamps, %{state | au_timestamp_generator: timestamp_generator}} else - case state.nalu_parser_mod do - Membrane.H264.NALuParser -> - require Membrane.H264.NALuTypes, as: NALuTypes - {Enum.find(au, &NALuTypes.is_vcl_nalu_type(&1.type)).timestamps, state} - - Membrane.H265.NALuParser -> - require Membrane.H265.NALuTypes, as: NALuTypes - {Enum.find(au, &NALuTypes.is_vcl_nalu_type(&1.type)).timestamps, state} - end + {first_vcl_nalu(au, state).timestamps, state} end end - @spec skip_au?(AUSplitter.access_unit(), boolean(), state()) :: {boolean(), state()} - defp skip_au?(au, keyframe?, state) do - has_seen_keyframe? = keyframe? and Enum.all?(au, &(&1.status == :valid)) + @spec forward_au?(AUSplitter.access_unit(), boolean(), state()) :: {boolean(), state()} + defp forward_au?(au, keyframe?, state) do + with true <- Enum.all?(au, &(&1.status == :valid)), + true <- first_vcl_nalu(au, state) != nil do + skip_until_keyframe? = state.skip_until_keyframe and not keyframe? + state = %{state | skip_until_keyframe: skip_until_keyframe?} + {not skip_until_keyframe?, state} + else + false -> {false, state} + end + end - state = %{ - state - | skip_until_keyframe: state.skip_until_keyframe and not has_seen_keyframe? - } + defp first_vcl_nalu(au, state) do + case state.nalu_parser_mod do + Membrane.H264.NALuParser -> + require Membrane.H264.NALuTypes, as: NALuTypes + Enum.find(au, &NALuTypes.is_vcl_nalu_type(&1.type)) - {Enum.any?(au, &(&1.status == :error)) or state.skip_until_keyframe, state} + Membrane.H265.NALuParser -> + require Membrane.H265.NALuTypes, as: NALuTypes + Enum.find(au, &NALuTypes.is_vcl_nalu_type(&1.type)) + end end @spec wrap_into_buffer( From 7f9b2cdcb3d2ac452a0114c106ad49c73611013f Mon Sep 17 00:00:00 2001 From: Mateusz Front Date: Tue, 14 May 2024 10:52:03 +0200 Subject: [PATCH 2/4] add typespec --- lib/membrane_h264_plugin/h26x_parser.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/membrane_h264_plugin/h26x_parser.ex b/lib/membrane_h264_plugin/h26x_parser.ex index 073921a..294d486 100644 --- a/lib/membrane_h264_plugin/h26x_parser.ex +++ b/lib/membrane_h264_plugin/h26x_parser.ex @@ -420,6 +420,7 @@ defmodule Membrane.H26x.Parser do end end + @spec first_vcl_nalu(AUSplitter.access_unit(), state()) :: Membrane.H26x.NALu.t() defp first_vcl_nalu(au, state) do case state.nalu_parser_mod do Membrane.H264.NALuParser -> From 1d2fbfe7853450f1227d4fbe62bff3c43294d1cb Mon Sep 17 00:00:00 2001 From: Mateusz Front Date: Tue, 14 May 2024 11:11:59 +0200 Subject: [PATCH 3/4] forward_au? -> should_forward_au --- lib/membrane_h264_plugin/h26x_parser.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/membrane_h264_plugin/h26x_parser.ex b/lib/membrane_h264_plugin/h26x_parser.ex index 294d486..4a83551 100644 --- a/lib/membrane_h264_plugin/h26x_parser.ex +++ b/lib/membrane_h264_plugin/h26x_parser.ex @@ -354,7 +354,7 @@ defmodule Membrane.H26x.Parser do @spec prepare_actions_for_au(AUSplitter.access_unit(), boolean(), state()) :: callback_return() def prepare_actions_for_au(au, keyframe?, state) do - {should_forward_au, state} = forward_au?(au, keyframe?, state) + {should_forward_au, state} = should_forward_au(au, keyframe?, state) if should_forward_au do {{pts, dts}, state} = prepare_timestamps(au, state) @@ -408,8 +408,8 @@ defmodule Membrane.H26x.Parser do end end - @spec forward_au?(AUSplitter.access_unit(), boolean(), state()) :: {boolean(), state()} - defp forward_au?(au, keyframe?, state) do + @spec should_forward_au(AUSplitter.access_unit(), boolean(), state()) :: {boolean(), state()} + defp should_forward_au(au, keyframe?, state) do with true <- Enum.all?(au, &(&1.status == :valid)), true <- first_vcl_nalu(au, state) != nil do skip_until_keyframe? = state.skip_until_keyframe and not keyframe? From d21d8e43bc3e6b7ee27901bc16939591e55bd8cb Mon Sep 17 00:00:00 2001 From: Mateusz Front Date: Tue, 14 May 2024 11:20:09 +0200 Subject: [PATCH 4/4] bump version --- README.md | 2 +- mix.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c71e47a..12f45a2 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ The package can be installed by adding `membrane_h26x_plugin` to your list of de ```elixir def deps do [ - {:membrane_h26x_plugin, "~> 0.10.1"} + {:membrane_h26x_plugin, "~> 0.10.2"} ] end ``` diff --git a/mix.exs b/mix.exs index 50da8b3..dc261b1 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Membrane.H26x.Plugin.Mixfile do use Mix.Project - @version "0.10.1" + @version "0.10.2" @github_url "https://github.com/membraneframework/membrane_h26x_plugin" def project do