-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add payload-specific PLI feedback packet type
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
defmodule ExRTCP.Packet.PayloadFeedback.PLI do | ||
@moduledoc """ | ||
Payload-specific Picture Loss Indication (PLI) | ||
packet type (`RFC 4585`, sec. 6.3.1). | ||
""" | ||
|
||
alias ExRTCP.Packet | ||
|
||
@behaviour ExRTCP.PacketTranscoder | ||
|
||
@packet_type 206 | ||
@feedback_type 1 | ||
|
||
@typedoc """ | ||
Struct representing Payload-specific PLI feedback RTCP message. | ||
""" | ||
@type t() :: %__MODULE__{ | ||
sender_ssrc: Packet.uint32(), | ||
media_ssrc: Packet.uint32() | ||
} | ||
|
||
@enforce_keys [:sender_ssrc, :media_ssrc] | ||
defstruct @enforce_keys | ||
|
||
@impl true | ||
def encode(packet) do | ||
%__MODULE__{ | ||
sender_ssrc: sender_ssrc, | ||
media_ssrc: media_ssrc | ||
} = packet | ||
|
||
encoded = <<sender_ssrc::32, media_ssrc::32>> | ||
|
||
{encoded, @feedback_type, @packet_type} | ||
end | ||
|
||
@impl true | ||
def decode(<<sender_ssrc::32, media_ssrc::32>>, _count) do | ||
packet = %__MODULE__{ | ||
sender_ssrc: sender_ssrc, | ||
media_ssrc: media_ssrc | ||
} | ||
|
||
{:ok, packet} | ||
end | ||
|
||
def decode(_raw, _count), do: {:error, :invalid_packet} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
defmodule ExRTCP.Packet.PayloadFeedback.PLITest do | ||
use ExUnit.Case, async: true | ||
|
||
alias ExRTCP.Packet.PayloadFeedback.PLI | ||
|
||
@sender_ssrc 123_321 | ||
@media_ssrc 112_231 | ||
|
||
test "encode/1" do | ||
packet = %PLI{ | ||
sender_ssrc: @sender_ssrc, | ||
media_ssrc: @media_ssrc | ||
} | ||
|
||
assert {encoded, 1, 206} = PLI.encode(packet) | ||
|
||
assert <<@sender_ssrc::32, @media_ssrc::32>> == encoded | ||
end | ||
|
||
describe "decode/2" do | ||
test "valid_packet" do | ||
raw_packet = <<@sender_ssrc::32, @media_ssrc::32>> | ||
|
||
assert {:ok, packet} = PLI.decode(raw_packet, 1) | ||
|
||
assert %PLI{ | ||
sender_ssrc: @sender_ssrc, | ||
media_ssrc: @media_ssrc | ||
} = packet | ||
end | ||
|
||
test "invalid_packet" do | ||
# packet cut short | ||
raw_packet = <<@sender_ssrc::32, @media_ssrc::16>> | ||
|
||
assert {:error, :invalid_packet} = PLI.decode(raw_packet, 1) | ||
end | ||
end | ||
end |