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

Pts integrity warn #59

merged 4 commits into from
Jan 26, 2024

Conversation

bartkrak
Copy link
Contributor

No description provided.

@bartkrak bartkrak requested a review from FelonEkonom January 19, 2024 16:53
@bartkrak bartkrak requested a review from mat-hek as a code owner January 19, 2024 16:53
Comment on lines 220 to 231
defp validate_pts_integrity(true = _check_pts_integrity?, packets, input_pts) do
cond do
length(packets) >= 2 and Enum.at(packets, 1).pts > input_pts ->
Membrane.Logger.warning("PTS values are overlapping")

length(packets) >= 2 and Enum.at(packets, 1).pts < input_pts ->
Membrane.Logger.warning("PTS values are not continous")

true ->
:ok
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
defp validate_pts_integrity(true = _check_pts_integrity?, packets, input_pts) do
cond do
length(packets) >= 2 and Enum.at(packets, 1).pts > input_pts ->
Membrane.Logger.warning("PTS values are overlapping")
length(packets) >= 2 and Enum.at(packets, 1).pts < input_pts ->
Membrane.Logger.warning("PTS values are not continous")
true ->
:ok
end
end
defp 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
  1. I would avoid calling length(packets) two times, because this function has linear complexity
  2. Move it to Util module, to stop reapeating yourself and delete this function from Encoder
  3. IMO it would be prettier to remove flag from function args and wrap function call into an if statement, eg. if check_pts_integrity?, do: Util.validate..

@bartkrak bartkrak requested a review from FelonEkonom January 22, 2024 13:16
Copy link
Member

@FelonEkonom FelonEkonom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump version minor

@@ -66,4 +66,20 @@ defmodule Membrane.Opus.Util do
_otherwise -> :error
end
end

@spec validate_pts_integrity(list(), any()) :: :ok
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@spec validate_pts_integrity(list(), any()) :: :ok
@spec validate_pts_integrity([Membrane.Buffer.t()], integer()) :: :ok

It is better, to be more specific in typespecs, when it is possible

@bartkrak bartkrak requested a review from FelonEkonom January 23, 2024 22:54
@FelonEkonom FelonEkonom merged commit 91f7435 into master Jan 26, 2024
3 checks passed
@FelonEkonom FelonEkonom deleted the pts_integrity_warn branch January 26, 2024 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants