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

Skip empty packets #170

Merged
merged 3 commits into from
Oct 30, 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_rtp_plugin` to your list of dep
```elixir
def deps do
[
{:membrane_rtp_plugin, "~> 0.29.0"},
{:membrane_rtp_plugin, "~> 0.29.1"},
{:ex_libsrtp, ">= 0.0.0"} # required only if SRTP/SRTCP support is needed
]
end
Expand Down
17 changes: 10 additions & 7 deletions lib/membrane/rtp/jitter_buffer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ defmodule Membrane.RTP.JitterBuffer do
{actions, state} =
store
|> BufferStore.dump()
|> Enum.map_reduce(state, &record_to_action/2)
|> Enum.flat_map_reduce(state, &record_to_actions/2)

{actions ++ [end_of_stream: :output], %State{state | store: %BufferStore{}}}
end
Expand Down Expand Up @@ -131,7 +131,8 @@ defmodule Membrane.RTP.JitterBuffer do
# Additionally, flush buffers as long as there are no gaps
{buffers, store} = BufferStore.flush_ordered(store)

{actions, state} = (too_old_records ++ buffers) |> Enum.map_reduce(state, &record_to_action/2)
{actions, state} =
(too_old_records ++ buffers) |> Enum.flat_map_reduce(state, &record_to_actions/2)

state = %{state | store: store} |> set_timer()

Expand All @@ -156,12 +157,12 @@ defmodule Membrane.RTP.JitterBuffer do

defp set_timer(%State{max_latency_timer: timer} = state) when timer != nil, do: state

defp record_to_action(nil, state) do
action = {:event, {:output, %Membrane.Event.Discontinuity{}}}
defp record_to_actions(nil, state) do
action = [event: {:output, %Membrane.Event.Discontinuity{}}]
{action, state}
end

defp record_to_action(%Record{buffer: buffer}, state) do
defp record_to_actions(%Record{buffer: buffer}, state) do
%{timestamp: rtp_timestamp} = buffer.metadata.rtp
timestamp_base = state.timestamp_base || rtp_timestamp
previous_timestamp = state.previous_timestamp || rtp_timestamp
Expand All @@ -179,8 +180,10 @@ defmodule Membrane.RTP.JitterBuffer do
end

timestamp = div((rtp_timestamp - timestamp_base) * Time.second(), state.clock_rate)
action = {:buffer, {:output, %{buffer | pts: timestamp}}}
buffer = %Membrane.Buffer{buffer | pts: timestamp}
# An empty buffer is usually a WebRTC probing packet that should be skipped.
actions = if buffer.payload == <<>>, do: [], else: [buffer: {:output, buffer}]
state = %{state | timestamp_base: timestamp_base, previous_timestamp: rtp_timestamp}
{action, state}
{actions, state}
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.RTP.Plugin.MixProject do
use Mix.Project

@version "0.29.0"
@version "0.29.1"
@github_url "https://github.com/membraneframework/membrane_rtp_plugin"

def project do
Expand Down
Loading