Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pts integrity warn #59

Merged
merged 4 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
6 changes: 3 additions & 3 deletions lib/membrane_opus/encoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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}
Expand Down
7 changes: 3 additions & 4 deletions lib/membrane_opus/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down
18 changes: 17 additions & 1 deletion lib/membrane_opus/util.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -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
Expand Down