From aed8fc5a9d0e109867468480bd205f4df46d8d9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=9Aled=C5=BA?= Date: Wed, 4 May 2022 14:27:08 +0200 Subject: [PATCH] Change warn logs to debug. Replace `Handshake.Event` with `SRTP.KeyingMaterialEvent` (#99) --- lib/membrane/rtcp/packet.ex | 2 +- lib/membrane/rtcp/parser.ex | 4 ++-- .../rtcp/transport_feedback_packet/twcc.ex | 6 +++--- lib/membrane/rtp/jitter_buffer.ex | 4 ++-- lib/membrane/rtp/parser.ex | 2 +- lib/membrane/rtp/session/sender_report.ex | 2 +- lib/membrane/rtp/ssrc_router.ex | 14 +++++++------- lib/membrane/srtcp/decryptor.ex | 19 ++++++++++++++----- lib/membrane/srtp/decryptor.ex | 19 +++++++++++++------ lib/membrane/srtp/encryptor.ex | 19 +++++++++++-------- mix.exs | 2 +- mix.lock | 2 +- 12 files changed, 57 insertions(+), 38 deletions(-) diff --git a/lib/membrane/rtcp/packet.ex b/lib/membrane/rtcp/packet.ex index e182d70e..52666573 100644 --- a/lib/membrane/rtcp/packet.ex +++ b/lib/membrane/rtcp/packet.ex @@ -83,7 +83,7 @@ defmodule Membrane.RTCP.Packet do do_parse(rest, [packet | acc]) {:error, :unknown_packet_type} -> - Membrane.Logger.warn(""" + Membrane.Logger.debug(""" Ignoring rtcp packet with packet type #{header.packet_type}: #{inspect(raw_header <> body_and_rest, limit: :infinity)} Reason: :unknown_packet_type diff --git a/lib/membrane/rtcp/parser.ex b/lib/membrane/rtcp/parser.ex index d55c7c68..16e857df 100644 --- a/lib/membrane/rtcp/parser.ex +++ b/lib/membrane/rtcp/parser.ex @@ -37,7 +37,7 @@ defmodule Membrane.RTCP.Parser do {{:ok, actions}, state} {:error, reason} -> - Membrane.Logger.warn(""" + Membrane.Logger.debug(""" Couldn't parse rtcp packet: #{inspect(payload, limit: :infinity)} Reason: #{inspect(reason)}. Ignoring packet. @@ -61,7 +61,7 @@ defmodule Membrane.RTCP.Parser do end defp process_rtcp(%RTCP.FeedbackPacket{payload: %RTCP.FeedbackPacket.PLI{}}, _metadata) do - Membrane.Logger.warn("Received packet loss indicator RTCP packet") + Membrane.Logger.debug("Received packet loss indicator RTCP packet") [] end diff --git a/lib/membrane/rtcp/transport_feedback_packet/twcc.ex b/lib/membrane/rtcp/transport_feedback_packet/twcc.ex index 1e2e8707..8124a028 100644 --- a/lib/membrane/rtcp/transport_feedback_packet/twcc.ex +++ b/lib/membrane/rtcp/transport_feedback_packet/twcc.ex @@ -75,7 +75,7 @@ defmodule Membrane.RTCP.TransportFeedbackPacket.TWCC do }} {:error, reason} -> - Membrane.Logger.warn(""" + Membrane.Logger.debug(""" An error occured while parsing TWCC feedback packet. Reason: #{reason} Packet: #{inspect(packet, limit: :infinity)} @@ -236,14 +236,14 @@ defmodule Membrane.RTCP.TransportFeedbackPacket.TWCC do <> :large_or_negative_delta -> - Membrane.Logger.warn( + Membrane.Logger.debug( "Reporting a packet with large or negative delta: (#{inspect(scaled_delta / 4)}ms)" ) <> :not_received -> - Membrane.Logger.warn("Reporting a non-received packet") + Membrane.Logger.debug("Reporting a non-received packet") <<>> end end diff --git a/lib/membrane/rtp/jitter_buffer.ex b/lib/membrane/rtp/jitter_buffer.ex index 96bc34da..df7be31a 100644 --- a/lib/membrane/rtp/jitter_buffer.ex +++ b/lib/membrane/rtp/jitter_buffer.ex @@ -90,7 +90,7 @@ defmodule Membrane.RTP.JitterBuffer do %State{state | store: result} {:error, :late_packet} -> - Membrane.Logger.warn("Late packet has arrived") + Membrane.Logger.debug("Late packet has arrived") state end @@ -105,7 +105,7 @@ defmodule Membrane.RTP.JitterBuffer do send_buffers(state) {:error, :late_packet} -> - Membrane.Logger.warn("Late packet has arrived") + Membrane.Logger.debug("Late packet has arrived") {:ok, state} end end diff --git a/lib/membrane/rtp/parser.ex b/lib/membrane/rtp/parser.ex index e5e6d6e4..326ab0e6 100644 --- a/lib/membrane/rtp/parser.ex +++ b/lib/membrane/rtp/parser.ex @@ -88,7 +88,7 @@ defmodule Membrane.RTP.Parser do end {:error, reason} -> - Membrane.Logger.warn(""" + Membrane.Logger.debug(""" Couldn't parse rtp packet: #{inspect(payload, limit: :infinity)} Reason: #{inspect(reason)}. Ignoring packet. diff --git a/lib/membrane/rtp/session/sender_report.ex b/lib/membrane/rtp/session/sender_report.ex index 13849a7b..563a851e 100644 --- a/lib/membrane/rtp/session/sender_report.ex +++ b/lib/membrane/rtp/session/sender_report.ex @@ -56,7 +56,7 @@ defmodule Membrane.RTP.Session.SenderReport do if Enum.empty?(report_data.senders_ssrcs) do {:no_report, report_data} else - Membrane.Logger.warn( + Membrane.Logger.debug( "Not received sender stats from ssrcs: #{Enum.join(report_data.senders_ssrcs, ", ")}" ) diff --git a/lib/membrane/rtp/ssrc_router.ex b/lib/membrane/rtp/ssrc_router.ex index 5f613764..b5f10860 100644 --- a/lib/membrane/rtp/ssrc_router.ex +++ b/lib/membrane/rtp/ssrc_router.ex @@ -13,7 +13,7 @@ defmodule Membrane.RTP.SSRCRouter do use Membrane.Filter - alias Membrane.{RTP, RTCPEvent} + alias Membrane.{RTP, RTCPEvent, SRTP} def_input_pad :input, caps: RTP, availability: :on_request, demand_mode: :auto @@ -31,13 +31,13 @@ defmodule Membrane.RTP.SSRCRouter do input_pads: %{RTP.ssrc_t() => [input_pad :: Pad.ref_t()]}, output_pad_ids: MapSet.t(), linking_buffers: %{RTP.ssrc_t() => [Membrane.Buffer.t()]}, - handshake_event: struct() | nil + srtp_keying_material_event: struct() | nil } defstruct input_pads: %{}, output_pad_ids: MapSet.new(), linking_buffers: %{}, - handshake_event: nil + srtp_keying_material_event: nil end @typedoc """ @@ -56,8 +56,8 @@ defmodule Membrane.RTP.SSRCRouter do {buffered_actions, state} = pop_in(state, [:linking_buffers, ssrc]) events = - if state.handshake_event do - [{:event, {pad, state.handshake_event}}] + if state.srtp_keying_material_event do + [{:event, {pad, state.srtp_keying_material_event}}] else [] end @@ -110,13 +110,13 @@ defmodule Membrane.RTP.SSRCRouter do end @impl true - def handle_event(_pad, %{handshake_data: _data} = event, _ctx, state) do + def handle_event(_pad, %SRTP.KeyingMaterialEvent{} = event, _ctx, state) do {actions, state} = Enum.flat_map_reduce(state.input_pads, state, fn {ssrc, _input}, state -> maybe_add_to_linking_buffer(:event, event, ssrc, state) end) - {{:ok, actions}, %{state | handshake_event: event}} + {{:ok, actions}, %{state | srtp_keying_material_event: event}} end @impl true diff --git a/lib/membrane/srtcp/decryptor.ex b/lib/membrane/srtcp/decryptor.ex index 0a1692f6..c2ef3f18 100644 --- a/lib/membrane/srtcp/decryptor.ex +++ b/lib/membrane/srtcp/decryptor.ex @@ -8,6 +8,9 @@ if Code.ensure_loaded?(ExLibSRTP) do use Membrane.Filter alias Membrane.Buffer + alias Membrane.SRTP + + require Membrane.Logger def_input_pad :input, caps: :any, demand_mode: :auto def_output_pad :output, caps: :any, demand_mode: :auto @@ -48,15 +51,15 @@ if Code.ensure_loaded?(ExLibSRTP) do end @impl true - def handle_event(_pad, %{handshake_data: handshake_data}, _ctx, %{policies: []} = state) do - {_local_keying_material, remote_keying_material, protection_profile} = handshake_data - + def handle_event(_pad, %SRTP.KeyingMaterialEvent{} = event, _ctx, %{policies: []} = state) do {:ok, crypto_profile} = - ExLibSRTP.Policy.crypto_profile_from_dtls_srtp_protection_profile(protection_profile) + ExLibSRTP.Policy.crypto_profile_from_dtls_srtp_protection_profile( + event.protection_profile + ) policy = %ExLibSRTP.Policy{ ssrc: :any_inbound, - key: remote_keying_material, + key: event.remote_keying_material, rtp: crypto_profile, rtcp: crypto_profile } @@ -65,6 +68,12 @@ if Code.ensure_loaded?(ExLibSRTP) do {:ok, %{state | policies: [policy]}} end + @impl true + def handle_event(_pad, %SRTP.KeyingMaterialEvent{}, _ctx, state) do + Membrane.Logger.warn("Got unexpected SRTP.KeyingMaterialEvent. Ignoring.") + {:ok, state} + end + @impl true def handle_event(pad, event, ctx, state), do: super(pad, event, ctx, state) end diff --git a/lib/membrane/srtp/decryptor.ex b/lib/membrane/srtp/decryptor.ex index 1f7e59cf..cc8c3882 100644 --- a/lib/membrane/srtp/decryptor.ex +++ b/lib/membrane/srtp/decryptor.ex @@ -17,6 +17,7 @@ if Code.ensure_loaded?(ExLibSRTP) do alias Membrane.Buffer alias Membrane.RTP.Utils + alias Membrane.SRTP require Membrane.Logger @@ -58,15 +59,15 @@ if Code.ensure_loaded?(ExLibSRTP) do end @impl true - def handle_event(_pad, %{handshake_data: handshake_data}, _ctx, %{policies: []} = state) do - {_local_keying_material, remote_keying_material, protection_profile} = handshake_data - + def handle_event(_pad, %SRTP.KeyingMaterialEvent{} = event, _ctx, %{policies: []} = state) do {:ok, crypto_profile} = - ExLibSRTP.Policy.crypto_profile_from_dtls_srtp_protection_profile(protection_profile) + ExLibSRTP.Policy.crypto_profile_from_dtls_srtp_protection_profile( + event.protection_profile + ) policy = %ExLibSRTP.Policy{ ssrc: :any_inbound, - key: remote_keying_material, + key: event.remote_keying_material, rtp: crypto_profile, rtcp: crypto_profile } @@ -75,6 +76,12 @@ if Code.ensure_loaded?(ExLibSRTP) do {:ok, Map.put(state, :policies, [policy])} end + @impl true + def handle_event(_pad, %SRTP.KeyingMaterialEvent{}, _ctx, state) do + Membrane.Logger.warn("Got unexpected SRTP.KeyingMaterialEvent. Ignoring.") + {:ok, state} + end + @impl true def handle_event(pad, other, ctx, state), do: super(pad, other, ctx, state) @@ -102,7 +109,7 @@ if Code.ensure_loaded?(ExLibSRTP) do {{:ok, buffer: {:output, %Buffer{buffer | payload: payload}}}, state} {:error, reason} -> - Membrane.Logger.warn(""" + Membrane.Logger.debug(""" Couldn't unprotect srtp packet: #{inspect(payload, limit: :infinity)} Reason: #{inspect(reason)}. Ignoring packet. diff --git a/lib/membrane/srtp/encryptor.ex b/lib/membrane/srtp/encryptor.ex index 52afabdd..ef06571d 100644 --- a/lib/membrane/srtp/encryptor.ex +++ b/lib/membrane/srtp/encryptor.ex @@ -7,7 +7,7 @@ if Code.ensure_loaded?(ExLibSRTP) do """ use Membrane.Filter - alias Membrane.{Buffer, RTP} + alias Membrane.{Buffer, RTP, SRTP} require Membrane.Logger @@ -70,15 +70,15 @@ if Code.ensure_loaded?(ExLibSRTP) do end @impl true - def handle_event(_pad, %{handshake_data: handshake_data}, _ctx, %{policies: []} = state) do - {local_keying_material, _remote_keying_material, protection_profile} = handshake_data - + def handle_event(_pad, %SRTP.KeyingMaterialEvent{} = event, _ctx, %{policies: []} = state) do {:ok, crypto_profile} = - ExLibSRTP.Policy.crypto_profile_from_dtls_srtp_protection_profile(protection_profile) + ExLibSRTP.Policy.crypto_profile_from_dtls_srtp_protection_profile( + event.protection_profile + ) policy = %ExLibSRTP.Policy{ ssrc: :any_outbound, - key: local_keying_material, + key: event.local_keying_material, rtp: crypto_profile, rtcp: crypto_profile } @@ -89,11 +89,14 @@ if Code.ensure_loaded?(ExLibSRTP) do end @impl true - def handle_event(_pad, other, _ctx, state) do - Membrane.Logger.warn("Got unexpected event: #{inspect(other)}. Ignoring.") + def handle_event(_pad, %SRTP.KeyingMaterialEvent{}, _ctx, state) do + Membrane.Logger.warn("Got unexpected SRTP.KeyingMaterialEvent. Ignoring.") {:ok, state} end + @impl true + def handle_event(pad, other, ctx, state), do: super(pad, other, ctx, state) + @impl true def handle_process(:input, buffer, _ctx, %{policies: []} = state) do {:ok, Map.update!(state, :queue, &[buffer | &1])} diff --git a/mix.exs b/mix.exs index 64520879..e10194ec 100644 --- a/mix.exs +++ b/mix.exs @@ -68,7 +68,7 @@ defmodule Membrane.RTP.Plugin.MixProject do defp deps do [ {:membrane_core, "~> 0.9.0"}, - {:membrane_rtp_format, "~> 0.3.1"}, + {:membrane_rtp_format, github: "membraneframework/membrane_rtp_format", override: true}, {:ex_libsrtp, "~> 0.3.0", optional: true}, {:qex, "~> 0.5.1"}, {:bunch, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index bf418303..b39487ab 100644 --- a/mix.lock +++ b/mix.lock @@ -29,7 +29,7 @@ "membrane_hackney_plugin": {:hex, :membrane_hackney_plugin, "0.7.0", "fbeb449addf3e9df1d7eb44db0f0509ca81d0fa13ea563afb5441a0b4fa472d0", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:membrane_core, "~> 0.9.0", [hex: :membrane_core, repo: "hexpm", optional: false]}, {:mockery, "~> 2.3", [hex: :mockery, repo: "hexpm", optional: false]}], "hexpm", "2c973b46895b50f0136adeb60f31b4da01357dd67798ff66eead488f9fe81390"}, "membrane_pcap_plugin": {:git, "https://github.com/membraneframework/membrane_pcap_plugin.git", "5be29fe0a609914eb8190c4dffff48e5c6e35437", [tag: "v0.5.0"]}, "membrane_raw_video_format": {:hex, :membrane_raw_video_format, "0.2.0", "cda8eb207cf65c93690a19001aba3edbb2ba5d22abc8068a1f6a785ba871e8cf", [:mix], [], "hexpm", "6b716fc24f60834323637c95aaaa0f99be23fcc6a84a21af70195ef50185b634"}, - "membrane_rtp_format": {:hex, :membrane_rtp_format, "0.3.1", "c6920fdb58660d90e264fcf3587dbb5994fb2f3643d234e59608c82598baebaf", [:mix], [], "hexpm", "d225f453715d165ded7dcb287c45360a4d653ac4a6d3ff70b4acdd244c45fa84"}, + "membrane_rtp_format": {:git, "https://github.com/membraneframework/membrane_rtp_format.git", "6382ea4089b8f9fbcfe71a71b9f80b6dec214dda", []}, "membrane_rtp_h264_plugin": {:hex, :membrane_rtp_h264_plugin, "0.9.0", "42f18f2d558176cc009099d7af1daaf0a9ebb73806e3980cc9baa069a3105b03", [:mix], [{:bunch, "~> 1.3", [hex: :bunch, repo: "hexpm", optional: false]}, {:membrane_core, "~> 0.9.0", [hex: :membrane_core, repo: "hexpm", optional: false]}, {:membrane_h264_format, "~> 0.3.0", [hex: :membrane_h264_format, repo: "hexpm", optional: false]}, {:membrane_rtp_format, "~> 0.3.0", [hex: :membrane_rtp_format, repo: "hexpm", optional: false]}], "hexpm", "2fb3af1328f8656b0cb887ea6633adadbbc74c76eec6ab26b827d0a20e12eab8"}, "membrane_rtp_mpegaudio_plugin": {:hex, :membrane_rtp_mpegaudio_plugin, "0.8.0", "8909d8a3a5ec3abad4f967007c047cf4b5b57b6f741381c80e7cc55d308f7c4d", [:mix], [{:membrane_caps_audio_mpeg, "~> 0.2.0", [hex: :membrane_caps_audio_mpeg, repo: "hexpm", optional: false]}, {:membrane_core, "~> 0.9.0", [hex: :membrane_core, repo: "hexpm", optional: false]}, {:membrane_rtp_format, "~> 0.3.0", [hex: :membrane_rtp_format, repo: "hexpm", optional: false]}], "hexpm", "eaf451f7b65652c2b89a0ab21d46067bdaffe65423ecc11cc0949fb71d8f709e"}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},