Skip to content

Commit

Permalink
Change warn logs to debug. Replace Handshake.Event with `SRTP.Keyin…
Browse files Browse the repository at this point in the history
…gMaterialEvent` (#99)
  • Loading branch information
mickel8 authored May 4, 2022
1 parent 22d181d commit aed8fc5
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 38 deletions.
2 changes: 1 addition & 1 deletion lib/membrane/rtcp/packet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/membrane/rtcp/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions lib/membrane/rtcp/transport_feedback_packet/twcc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down Expand Up @@ -236,14 +236,14 @@ defmodule Membrane.RTCP.TransportFeedbackPacket.TWCC do
<<scaled_delta::8>>

:large_or_negative_delta ->
Membrane.Logger.warn(
Membrane.Logger.debug(
"Reporting a packet with large or negative delta: (#{inspect(scaled_delta / 4)}ms)"
)

<<cap_delta(scaled_delta)::16>>

:not_received ->
Membrane.Logger.warn("Reporting a non-received packet")
Membrane.Logger.debug("Reporting a non-received packet")
<<>>
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/membrane/rtp/jitter_buffer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/membrane/rtp/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/membrane/rtp/session/sender_report.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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, ", ")}"
)

Expand Down
14 changes: 7 additions & 7 deletions lib/membrane/rtp/ssrc_router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 """
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions lib/membrane/srtcp/decryptor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down
19 changes: 13 additions & 6 deletions lib/membrane/srtp/decryptor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if Code.ensure_loaded?(ExLibSRTP) do

alias Membrane.Buffer
alias Membrane.RTP.Utils
alias Membrane.SRTP

require Membrane.Logger

Expand Down Expand Up @@ -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
}
Expand All @@ -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)

Expand Down Expand Up @@ -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.
Expand Down
19 changes: 11 additions & 8 deletions lib/membrane/srtp/encryptor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand All @@ -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])}
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down

0 comments on commit aed8fc5

Please sign in to comment.