From 4be3ad281c8e53cd6b821a9dfe38e4bb6246afa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Chali=C5=84ski?= Date: Tue, 16 Apr 2024 00:41:09 +0200 Subject: [PATCH 1/4] crashing pts integrity check fix --- README.md | 2 +- lib/membrane_aac_fdk_plugin/encoder.ex | 3 ++- mix.exs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 98591f3..bd61c2e 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ The package can be installed by adding `membrane_aac_fdk_plugin` to your list of ```elixir def deps do [ - {:membrane_aac_fdk_plugin, "~> 0.18.7"} + {:membrane_aac_fdk_plugin, "~> 0.18.8"} ] end ``` diff --git a/lib/membrane_aac_fdk_plugin/encoder.ex b/lib/membrane_aac_fdk_plugin/encoder.ex index eb15346..bb9c8ae 100644 --- a/lib/membrane_aac_fdk_plugin/encoder.ex +++ b/lib/membrane_aac_fdk_plugin/encoder.ex @@ -277,7 +277,8 @@ defmodule Membrane.AAC.FDK.Encoder do end defp validate_pts_integrity(packets, input_pts) do - with [%Buffer{pts: first_pts}, %Buffer{pts: second_pts} | _tail] <- packets do + with [%Buffer{pts: first_pts}, %Buffer{pts: second_pts} | _tail] + when first_pts != nil and second_pts != nil <- packets do duration = second_pts - first_pts epsilon = duration / 10 diff --git a/mix.exs b/mix.exs index 5308a8b..45696cb 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Membrane.AAC.FDK.Plugin.MixProject do use Mix.Project - @version "0.18.7" + @version "0.18.8" @github_url "https://github.com/membraneframework/membrane_aac_fdk_plugin" def project do From 59913de9f7ddaeb6bd24a1a26cf3810d1c63ee78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Chali=C5=84ski?= Date: Wed, 17 Apr 2024 01:53:12 +0200 Subject: [PATCH 2/4] added pts tests --- test/membrane_element_fdk_aac/pts_test.exs | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 test/membrane_element_fdk_aac/pts_test.exs diff --git a/test/membrane_element_fdk_aac/pts_test.exs b/test/membrane_element_fdk_aac/pts_test.exs new file mode 100644 index 0000000..02fa6bc --- /dev/null +++ b/test/membrane_element_fdk_aac/pts_test.exs @@ -0,0 +1,77 @@ +defmodule Membrane.FLAC.Parser.IntegrationTest do + use ExUnit.Case + import Membrane.Testing.Assertions + alias Membrane.{Pipeline, Time} + + test "encode with timestamps" do + pipeline = prepare_pts_test_pipeline(true) + + Enum.each(0..294, fn index -> + assert_sink_buffer(pipeline, :sink, %Membrane.Buffer{pts: out_pts}) + + # every other buffer gets queued and concated with next one to be big enough, because of that we expect different pts than on input + assert out_pts == (index * 2 * 1000) |> Time.nanoseconds() + end) + + Pipeline.terminate(pipeline) + end + + test "encode without timestamps" do + pipeline = prepare_pts_test_pipeline(false) + + Enum.each(0..294, fn index -> + assert_sink_buffer(pipeline, :sink, %Membrane.Buffer{pts: out_pts}) + assert out_pts == nil + end) + + Pipeline.terminate(pipeline) + end + + defp prepare_pts_test_pipeline(with_pts?) do + import Membrane.ChildrenSpec + + spec = + child(:source, %Membrane.Testing.Source{ + output: buffers_from_file(with_pts?), + stream_format: %Membrane.RawAudio{ + sample_format: :s16le, + sample_rate: 16_000, + channels: 1 + } + }) + |> child(:aac_encoder, Membrane.AAC.FDK.Encoder) + |> child(:sink, Membrane.Testing.Sink) + + Membrane.Testing.Pipeline.start_link_supervised!(spec: spec) + end + + defp buffers_from_file(with_pts?) do + # 589 buffers is generated from this binary + binary = "../fixtures/input-encoder.raw" |> Path.expand(__DIR__) |> File.read!() + + split_binary(binary) + |> Enum.with_index() + |> Enum.map(fn {payload, index} -> + %Membrane.Buffer{ + payload: payload, + pts: + if with_pts? do + (index * 1000) |> Time.nanoseconds() + else + nil + end + } + end) + end + + @spec split_binary(binary(), list(binary())) :: list(binary()) + def split_binary(binary, acc \\ []) + + def split_binary(<>, acc) do + split_binary(rest, [binary] ++ acc) + end + + def split_binary(rest, acc) when byte_size(rest) <= 1024 do + Enum.reverse(acc) ++ [rest] + end +end From 248c309e4c9cf75df86dd0698afba1de2b6ac37d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Chali=C5=84ski?= Date: Wed, 17 Apr 2024 01:55:22 +0200 Subject: [PATCH 3/4] warning fix --- test/membrane_element_fdk_aac/pts_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/membrane_element_fdk_aac/pts_test.exs b/test/membrane_element_fdk_aac/pts_test.exs index 02fa6bc..cdd37d4 100644 --- a/test/membrane_element_fdk_aac/pts_test.exs +++ b/test/membrane_element_fdk_aac/pts_test.exs @@ -19,7 +19,7 @@ defmodule Membrane.FLAC.Parser.IntegrationTest do test "encode without timestamps" do pipeline = prepare_pts_test_pipeline(false) - Enum.each(0..294, fn index -> + Enum.each(0..294, fn _index -> assert_sink_buffer(pipeline, :sink, %Membrane.Buffer{pts: out_pts}) assert out_pts == nil end) From 6ac6180d3ba29f0c1964b89ded814cf5767b0b3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Chali=C5=84ski?= Date: Wed, 17 Apr 2024 15:25:03 +0200 Subject: [PATCH 4/4] Update test/membrane_element_fdk_aac/pts_test.exs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ɓukasz Kita --- test/membrane_element_fdk_aac/pts_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/membrane_element_fdk_aac/pts_test.exs b/test/membrane_element_fdk_aac/pts_test.exs index cdd37d4..30664b0 100644 --- a/test/membrane_element_fdk_aac/pts_test.exs +++ b/test/membrane_element_fdk_aac/pts_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.FLAC.Parser.IntegrationTest do - use ExUnit.Case + use ExUnit.Case, async: true import Membrane.Testing.Assertions alias Membrane.{Pipeline, Time}