diff --git a/README.md b/README.md index af4780e..64e30f1 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ The package can be installed by adding `membrane_opus_plugin` to your list of de ```elixir def deps do [ - {:membrane_opus_plugin, "~> 0.19.2"} + {:membrane_opus_plugin, "~> 0.20.0"} ] end ``` diff --git a/lib/membrane_opus/encoder.ex b/lib/membrane_opus/encoder.ex index 88079aa..1f03bfb 100644 --- a/lib/membrane_opus/encoder.ex +++ b/lib/membrane_opus/encoder.ex @@ -10,6 +10,7 @@ defmodule Membrane.Opus.Encoder do alias __MODULE__.Native alias Membrane.Buffer alias Membrane.Opus + alias Membrane.Opus.Util alias Membrane.RawAudio @allowed_channels [1, 2] @@ -147,9 +148,8 @@ defmodule Membrane.Opus.Encoder do {:ok, encoded_buffers, state} -> # something was encoded - if check_pts_integrity? and length(encoded_buffers) >= 2 and - Enum.at(encoded_buffers, 1).pts > input_pts do - Membrane.Logger.warning("PTS values are overlapping") + if check_pts_integrity? do + Util.validate_pts_integrity(encoded_buffers, input_pts) end {[buffer: {:output, encoded_buffers}], state} diff --git a/lib/membrane_opus/parser.ex b/lib/membrane_opus/parser.ex index 0f07c94..5dd1842 100644 --- a/lib/membrane_opus/parser.ex +++ b/lib/membrane_opus/parser.ex @@ -9,7 +9,7 @@ defmodule Membrane.Opus.Parser do """ use Membrane.Filter - require Membrane.Logger + alias __MODULE__.{Delimitation, FrameLengths} alias Membrane.{Buffer, Opus, RemoteStream} alias Membrane.Opus.Util @@ -105,9 +105,8 @@ defmodule Membrane.Opus.Parser do set_current_pts(state, input_pts) ) - if check_pts_integrity? and length(packets) >= 2 and - Enum.at(packets, 1).pts > input_pts do - Membrane.Logger.warning("PTS values are overlapping") + if check_pts_integrity? do + Util.validate_pts_integrity(packets, input_pts) end stream_format = %Opus{ diff --git a/lib/membrane_opus/util.ex b/lib/membrane_opus/util.ex index b17cea2..27c1c95 100644 --- a/lib/membrane_opus/util.ex +++ b/lib/membrane_opus/util.ex @@ -1,8 +1,8 @@ defmodule Membrane.Opus.Util do @moduledoc false # Miscellaneous utility functions - import Membrane.Time + require Membrane.Logger @spec parse_toc_byte(data :: binary) :: {:ok, config_number :: 0..31, stereo_flag :: 0..1, frame_packing :: 0..3} | :error @@ -66,4 +66,20 @@ defmodule Membrane.Opus.Util do _otherwise -> :error end end + + @spec validate_pts_integrity([Membrane.Buffer.t()], integer()) :: :ok + def validate_pts_integrity(packets, input_pts) do + cond do + length(packets) < 2 or Enum.at(packets, 1).pts == input_pts -> + :ok + + Enum.at(packets, 1).pts > input_pts -> + Membrane.Logger.warning("PTS values are overlapping") + :ok + + Enum.at(packets, 1).pts < input_pts -> + Membrane.Logger.warning("PTS values are not continous") + :ok + end + end end diff --git a/mix.exs b/mix.exs index a1a80c5..68428ce 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Membrane.Opus.Plugin.Mixfile do use Mix.Project - @version "0.19.2" + @version "0.20.0" @github_url "https://github.com/membraneframework/membrane_opus_plugin" def project do